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
Reply to: