Perl Programming: Pack()..bit of hex
hi,
I am trying to learn more about binary formats and their lay-outs, so I can become a better coder, more advanced in just programming 'hello worlds' and simple programs. So I started to write some small scripts just for this purpose (rather to be called small pieces of junk code to achieve my goals), to examine my compiled hello world binaries. I have some minor C and Perl programming experience, but for this I prefer perl, because well... its easier for me to understand at this point.
I am able to read in my "binary" file, using, true normal I/O (open FILE), read it and print this information using a formatted string (printf '%#x', $myFile) to give a hexadecimal representation. Now with that script I am able to direct my binary file to an output file (which works quite fast) by doing something like this:
$ perl myn00bscript -f myhelloworld.bin > hexadecimal.txt
The output I have is like:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0x2c 0x9 0 0x2 0 0 0 0x2 0x8ae 0x8ae 0x8ae 0x8ae 0x8ae 0x8ae 0x8ae 0x8ae 0x8ae 0x8ae 0x8ae 0x8ae 0x16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 <and so on>
Now here comes my n00bish question. If I want to convert this file back to binary, how can I do this using split, hex and pack? Or are there better ways? Please do elaborate with some code snippets, I have Googled and found many, many usefull resources only I lack programming experience to tackle this. I thank you!
Ofcourse I can just use a hex-editor, but as I told before, it's about learning here.
-Jason
|