The other day, I imaged a USB disk to do a linux install. The image was only a few hundred megabytes. When I was done, I couldn't get the USB drive to reformat to anything other than the size of the image. (thus wasting a large portion of the disk).
Killdisk (http://www.killdisk.com/) was a tool I found that pretty much writes the usb drive with zeros. I believe you only need to do so for a few minutes to overwrite the table which holds the partitions and then cancel it and upon reformatting it in windows, you'll discover that you've got all your space back!
Wednesday, July 22, 2009
Wednesday, July 15, 2009
Wednesday, June 24, 2009
Byte ordering endianness mayhem! Aahh!
Working with (binary) data structures written to files can be difficult due to the fact that a hexdump of a binary file may appear to be out of order.
The following example may illustrate the source of confusion. This simple python script will create three binary files. To each file we will write 01 02 03 04 split up in different ways.
These examples were run on a regular run-of-the-mill 32-bit Intel machine. These machines have a 16-bit word size (weird, yeah, I know) and use little-endian byte ordering. Little endian byte ordering means that the lest sigificant byte of any given data type, will go in the lowest-addressed memory space (or slot in a file on disk).
The least significant byte of the long 0x01020304 is the "04". Why doesn't it appear on the far left in the hexdump such as this: 04 03 02 01?
.... Need to finish writing in here ....
Diagram that I drew showing how reordering address so they increase from right to left can help understand little-endian byte ordering:


After googling around a bit, I found a thread which talks about how to reformat your hexdump so it is in big endian format (I believe). It's quite useful:
$ od -tx1 -w16 -Ax 1long.bin
000000 04 03 02 01
000004
$ od -tx1 -w16 -Ax 2short.bin
000000 02 01 04 03
000004
$ od -tx1 -w16 -Ax 4char.bin
000000 01 02 03 04
000004
The following example may illustrate the source of confusion. This simple python script will create three binary files. To each file we will write 01 02 03 04 split up in different ways.
from struct import *We can hexdump them to see their contents:
open('1long.bin','wb').write(pack('L', 0x01020304))
open('2short.bin','wb').write(pack('HH', 0x0102, 0x0304))
open('4char.bin','wb').write(pack('BBBB', 0x01, 0x02, 0x03, 0x04))
$ hexdump 1long.binBefore hexdumping, one might suspect that the outputs would be the same, but they're not. Each gave a diffent ordering.
0000000 0304 0102 (this is the long: 0x01020304)
0000004
$ hexdump 2short.bin
0000000 0102 0304 (these are the 2 shorts: 0x0102, 0x0304)
0000004
$ hexdump 4char.bin
0000000 0201 0403 (these are the 4 chars: 0x01, 0x02, 0x03, 0x04)
0000004
These examples were run on a regular run-of-the-mill 32-bit Intel machine. These machines have a 16-bit word size (weird, yeah, I know) and use little-endian byte ordering. Little endian byte ordering means that the lest sigificant byte of any given data type, will go in the lowest-addressed memory space (or slot in a file on disk).
The least significant byte of the long 0x01020304 is the "04". Why doesn't it appear on the far left in the hexdump such as this: 04 03 02 01?
.... Need to finish writing in here ....
Diagram that I drew showing how reordering address so they increase from right to left can help understand little-endian byte ordering:


After googling around a bit, I found a thread which talks about how to reformat your hexdump so it is in big endian format (I believe). It's quite useful:
$ od -tx1 -w16 -Ax 1long.bin
000000 04 03 02 01
000004
$ od -tx1 -w16 -Ax 2short.bin
000000 02 01 04 03
000004
$ od -tx1 -w16 -Ax 4char.bin
000000 01 02 03 04
000004
Friday, March 13, 2009
c++ runtime "symbol lookup error"
I was working on a c++ project. Everything linked and compiled fine. Upon running the executable, I got the following error:
Some cool commands in the debugging process:
./TestCppProgram: symbol lookup error: ./TestCppProgram: undefined symbol: _ZN12CppProgramC1EvI searched the internet. Two of the interesting links I found were the following:
- http://osdir.com/ml/gcc.g++.general/2005-02/msg00061.html
- http://www.linuxquestions.org/questions/linux-software-2/undefined-symbol-cout-263568/
Some cool commands in the debugging process:
- ldd TestCppProgram (Shows you where your program is getting it's libraries from. An early-on careful inspection of this would've quickly let me to my problem!)
- ldd -d -r TestCppProgram (Shows you any undefined symbols. There shouldn't be any undefined symbols for an executable, but there will be for a shared lib if it depends on another shared lib. Somebody please correct me if I'm wrong)
- nm TestCppProgram | c++filt (displays unmangled symbol information)
- nm TestCppProgram (Displays mangled symbol information. Ie: You should be able to find stuff like ZN12CppProgramC1Ev in here. In my problem above, I found which line number the undefined symbol in question was on, and then looked it up in the unmangled version to see what function it was trying to resolve. It let me know, but it didn't really help me find out what my problem was.)
- readelf -d TestCppProgram (Shows library dependencies. similar to ldd.)
Tuesday, March 10, 2009
Wednesday, January 07, 2009
Saturday, October 25, 2008
Subscribe to:
Posts (Atom)