Re: Suggest a tool for decoding binary data
On Sat, Feb 01, 2014 at 05:36:19PM -0800, Kevin O'Gorman wrote: I'm about to tackle GPT partitioned disks, and want to decode the label. The data is little-endian, but I want my code to work on little- or big-endian machines. I want it to be a script -- nothing compiled. I've figured out that on my little-endian machines, I can use bash with something like otherlabel=$(($(dd if=label bs=1 skip=32 count=8 | od -An -t d8) )) I am not quit understand why need dump the label, but it can be done easily by script language, say, Python. # - begin -- #!/usr/bin/env python # -*- coding: utf-8 -*- import sys from struct import unpack skip = 32 count = 8 fp = open(path_to_dd_image, 'rb').read(skip + count) data_of_interest = fp[skip:] if sys.byteorder == 'little': #assuming the label is a 8 bytes unsigned integer label = unpack('Q', data_of_interest)[0] else: label = unpack('Q', data_of_interest)[0] # - end -- -- Chen Wei -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/20140202092853.GM25217@localhost
Re: Suggest a tool for decoding binary data
On Sun, Feb 2, 2014 at 1:28 AM, Chen Wei weichen...@icloud.com wrote: On Sat, Feb 01, 2014 at 05:36:19PM -0800, Kevin O'Gorman wrote: I'm about to tackle GPT partitioned disks, and want to decode the label. The data is little-endian, but I want my code to work on little- or big-endian machines. I want it to be a script -- nothing compiled. I've figured out that on my little-endian machines, I can use bash with something like otherlabel=$(($(dd if=label bs=1 skip=32 count=8 | od -An -t d8) )) I am not quit understand why need dump the label, but it can be done easily by script language, say, Python. # - begin -- #!/usr/bin/env python # -*- coding: utf-8 -*- import sys from struct import unpack skip = 32 count = 8 fp = open(path_to_dd_image, 'rb').read(skip + count) data_of_interest = fp[skip:] if sys.byteorder == 'little': #assuming the label is a 8 bytes unsigned integer label = unpack('Q', data_of_interest)[0] else: label = unpack('Q', data_of_interest)[0] # - end -- Ah, thank you, that is a nice start. I'll remove the test for system byteorder because the data is always little-endian. It's the sytem I was worred about and the '' is the ticket. -- Kevin O'Gorman programmer, n. an organism that transmutes caffeine into software. Please consider the environment before printing this email. -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/CAGVXcSYYcN45B8S5vmTggYTGgaDbTpARZs=gvlbmsejjyqp...@mail.gmail.com
Re: Suggest a tool for decoding binary data
On 02/02/14 12:36, Kevin O'Gorman wrote: I've been working on homegrown backups for a while. I like using standard UNIX tools because the backups are usable on any *NIX system. I'm about to tackle GPT partitioned disks, and want to decode the label. I need it because i like to take dd-style dumps of the partition info, including the stuff at the end of the disk. Since the label contains info about variable areas (the two partition lists) I need to decode these. The data is little-endian, but I want my code to work on little- or big-endian machines. I want it to be a script -- nothing compiled. I've figured out that on my little-endian machines, I can use bash with something like otherlabel=$(($(dd if=label bs=1 skip=32 count=8 | od -An -t d8) )) and I get the right answer, but only because the endianness of the data and of my machine are the same. I want something that will also work on a big-endian machine, and I want it to be reasonably simple. Any ideas? Maybe you could just grab the secondary GPT header and table? 16 KiB before the last logical sector of the disk and last 512 bytes I'm not sure why you need to decode the data. gfdisk will allow you to grab the labels, but I don't know if you can run it from a script (xdotool?). Kind regards -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/52edaadf.3000...@gmail.com