Question: The language is Python 3.6. I need to open a file using try: with open. I will be using import struct to unpack the binary
The language is Python 3.6. I need to open a file using
try:
with open.
I will be using import struct to unpack the binary contents of the file. I need to be able to parse a portion of the master boot record. the mbr information is in my file that i need to open.I need to print out the status byte, which is one byte at the starting address. I need to print out the partition type, which is one byte located at the address 1BE+4 and lastly I need to print out the address of the first sector in the partition 1BE+8. Please note that all master boot record information is in Wiki if you need it.
The first partition entry is located at 1BE Hex.
Here is a partial strat to the program. Thank you
# imports the struct library import struct
fileName = raw_input("Enter file, which is block.dd to process as MBR: ") print (" Attempting to open file: ", fileName) try: with open(fileName, 'rb') as mbr: block = mbr.read(1024) print ("Read Successfull ") except Exception as msg: print "File I/O Error: ", str(msg) print "Script Exit" quit() ''' Key offsets of the Master Boot Record ''' statusOff = 0x1be # Offset to Partion Entry One # This is a one byte value print "Extracting Status" pStatus = struct.unpack("B", block[statusOff]) print "Partition Status: ", '{:02x}'.format(pStatus[0]) print "Done" For some reason this partial program doesnt work for me please help finish.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
