import struct chunk = bytearray() src = raw_input("Path to source image file: ") #with open("block.dd", "rb") as raw_file: with open(src, "rb") as raw_file: chunk = raw_file.read(1024) #byte1 = struct.unpack("<i", chunk[0x1AA:0x1AE]) chs_sector_1 = struct.unpack("<B", chunk[0x1BE]) part_type_1 = struct.unpack("<B", chunk[0x1BE + 4]) part_no_1 = struct.unpack("<BBBBBBBBBBBBBBBB", chunk[0x000 + 446:0x000 + 462]) # 16 bytes of Partition No.1 lba_sector_1 = struct.unpack("<B", chunk[0x000 + 446 + 8]) # Partition No.1's LBA Sector. Equivalent to '0x1BE + 8'. part_no_2 = struct.unpack("<BBBBBBBBBBBBBBBB", chunk[0x000 + 462:0x000 + 478]) # 16 bytes of Partition No.2 lba_sector_2 = struct.unpack("<B", chunk[0x000 + 446 + 24]) # Partition No.1's LBA Sector. Equivalent to '0x1CE + 8'. part_no_3 = struct.unpack("<BBBBBBBBBBBBBBBB", chunk[0x000 + 478:0x000 + 494]) # 16 bytes of Partition No.3 lba_sector_3 = struct.unpack("<B", chunk[0x000 + 446 + 40]) # Partition No.1's LBA Sector. Equivalent to '0x1DE + 8'. part_no_4 = struct.unpack("<BBBBBBBBBBBBBBBB", chunk[0x000 + 494:0x000 + 510]) # 16 bytes of Partition No.4 lba_sector_4 = struct.unpack("<B", chunk[0x000 + 446 + 56]) # Partition No.1's LBA Sector. Equivalent to '0x1EE + 8'. sig_lend1 = struct.unpack("<BB", chunk[0x000 + 510:0x000 + 512]) # Boot Signature - Little Endian = 0xaa55 w/Unsigned \ # Short Format (<H). Equivalent to '0x1FE' = '55' and # '0x1FE + 1' = 'aa' #hexresult = binascii.hexlify(chs_sector_1) print hex(chs_sector_1[0]) print hex(part_type_1[0]) print 'Partition No.1 Hex Portion:', hex(part_no_1[0]), hex(part_no_1[1]), hex(part_no_1[2]), hex(part_no_1[3]), \ hex(part_no_1[4]), hex(part_no_1[5]), hex(part_no_1[6]), hex(part_no_1[7]), hex(part_no_1[8]), hex(part_no_1[9]), \ hex(part_no_1[10]), hex(part_no_1[11]), hex(part_no_1[12]), hex(part_no_1[13]), hex(part_no_1[14]), \ hex(part_no_1[15]) print 'Partition No.1 LBA Sector:', hex(lba_sector_1[0]) print 'Partition No.2 Hex Portion:', hex(part_no_2[0]), hex(part_no_2[1]), hex(part_no_2[2]), hex(part_no_2[3]), \ hex(part_no_2[4]), hex(part_no_2[5]), hex(part_no_2[6]), hex(part_no_2[7]), hex(part_no_2[8]), hex(part_no_2[9]), \ hex(part_no_2[10]), hex(part_no_2[11]), hex(part_no_2[12]), hex(part_no_2[13]), hex(part_no_2[14]), \ hex(part_no_2[15]) print 'Partition No.2 LBA Sector:', hex(lba_sector_2[0]) print 'Partition No.3 Hex Portion:', hex(part_no_3[0]), hex(part_no_3[1]), hex(part_no_3[2]), hex(part_no_3[3]), \ hex(part_no_3[4]), hex(part_no_3[5]), hex(part_no_3[6]), hex(part_no_3[7]), hex(part_no_3[8]), hex(part_no_3[9]), \ hex(part_no_3[10]), hex(part_no_3[11]), hex(part_no_3[12]), hex(part_no_3[13]), hex(part_no_3[14]), \ hex(part_no_3[15]) print 'Partition No.3 LBA Sector:', hex(lba_sector_3[0]) print 'Partition No.4 Hex Portion:', hex(part_no_4[0]), hex(part_no_4[1]), hex(part_no_4[2]), hex(part_no_4[3]), \ hex(part_no_4[4]), hex(part_no_4[5]), hex(part_no_4[6]), hex(part_no_4[7]), hex(part_no_4[8]), hex(part_no_4[9]), \ hex(part_no_4[10]), hex(part_no_4[11]), hex(part_no_4[12]), hex(part_no_4[13]), hex(part_no_4[14]), \ hex(part_no_4[15]) print 'Partition No.4 LBA Sector:', hex(lba_sector_4[0]) print 'Boot Signature:', hex(sig_lend1[0]), hex(sig_lend1[1])
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question