Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Wednesday, April 22, 2009

bmpfs

This is really cool! File systems you can SEE!

Python code:
#!/usr/bin/python
# create_image.py
import Image
im = Image.new('RGB', (8192,8192),(255,255,255))
im.save('new.bmp', 'BMP')


Put the above in a file and run:
python create_image.py

This creates a blank, white bitmap. Nothing special yet.

Next do this:
sudo losetup /dev/loop0 new.bmp -o 100
sudo mkfs.ext2 /dev/loop0
sudo losetup /dev/loop0 -d


Now look at the bitmap. There's a thin bar along the bottom. That's your file allocation table! You now have an ~190 MB combination disk image-bitmap image!

Now lets stick something in our new "disk image":
mkdir temp
sudo mount -o loop,offset=100,user new.bmp temp
sudo chown 1000:1000 temp
# replace 1000 with you user and group id respectively

Now copy something respectably sized into temp. I copied a 32mb video into there.

Unmount the image and you can look at it:

sudo umount temp
eog new.bmp


also try this (imagemagick required):

convert new.bmp new.png

Note the size of the file(s) you put in there. I put a 33799296 byte video in there and the png came out to 33939231 bytes. (Videos are basically not compressible.) Not bad. Since png uses lossless compression, you can convert back and the bitmap still mounts! Try it!

Tuesday, April 21, 2009

Why are windows executables so big?

So I found a cool search tool by Didier Stevens: http://blog.didierstevens.com/programs/xorsearch/

I goes through a file and searches for a string, and also several common transpositions of that word. It included a windows executable :-(, but it built fine with gcc and appears to work! :-) I will definitely use this.

But, it got me thinking. I could use my new tool! I could look at the difference gross between a Windows a Linux executable with bin2bmp. (Cut me some slack, I like pictures...) Here are the results:

Linux Binary (gcc (Ubuntu 4.3.3-5ubuntu4) 4.3.3):




Windows Binary (Borland C++ - Copyright 1999 Inprise Corporation):








To be fair, his windows binary is digitally signed, but that can't be all the difference? Is it statically linked maybe?

Linux Statically Linked Binary (gcc (Ubuntu 4.3.3-5ubuntu4) 4.3.3):










Maybe not. I don't have a way to generate a Windows statically linked binary for comparison though... anyway this was mostly just an excuse to play with my new tool. But I am curious.

BTW, Latest version of bin2bmp here: http://sourceforge.net/projects/bin2bmp/