0

I am trying to find out, from a provided disc image things like, how many bytes does the boot block occupy, how many bytes are there in each sector, and how many sectors are there in each cluster(each allocation unit)?

I need to write code in python that will tell me these things and I have been searching for a library of python commands that might help me, namely one being the

import os

If anyone has any suggestions to other libraries i'd greatly appreciate or any hints to start with, I am completely lost.

user3358064
  • 7
  • 2
  • 7
  • Your first problem will be getting access to the raw disk blocks, most Python I/O occurs through the file system. Which OS are you using? – Mark Ransom Nov 03 '17 at 22:45
  • I am using windows and trying to write the code in visual studio code. I mounted the disc image in PowerISO for windows. I figure something along the lines of just getting the file open would be c = open("image.img", "rb") I'm not sure if mounting the image helps me any with this information though. – user3358064 Nov 03 '17 at 22:47
  • 1
    So the image is already packaged as a file? That makes things easier, you just need to know the layout of a FAT disk. You can read blocks directly from the file by opening it in binary mode: `f = open(filename, 'rb')` `block = f.read(512)` – Mark Ransom Nov 03 '17 at 22:50
  • To present it in a readable form then i should convert it from binary and write it to a text file for example? – user3358064 Nov 03 '17 at 22:51
  • You will probably want to use the `struct` module to decode binary bytes into values you can work with. The structure of FAT16 is relatively simple and I'm sure Google can find references to it. – Mark Ransom Nov 03 '17 at 22:54
  • Ah okay thank you for the help! I will try out the binascii library first and use a hex editor to see if i can make anything of it since i don't know much about the struct module. I will definitely look that up though thank you! – user3358064 Nov 03 '17 at 23:01
  • One more quick question, 512 would be the value of the field that provides the bytes per sector correct? – user3358064 Nov 03 '17 at 23:27
  • No, you _don't_ want to mount the disk image in order to get to the bytes you want. BTW, you can do this sort of thing in Python 2 or Python 3, but IMHO it's less confusing in Python 3, since it makes a clear distinction between text and bytes; also, the Python 3 `bytes` type has several useful methods that are more convenient than using `binascii`. – PM 2Ring Nov 04 '17 at 00:18

0 Answers0