seguramente tiene que ver con la línea 9 la función read_dword; ya he buscado pero no encuentro una solucion, segun este post https://stackoverflow.com/questions/64865868/unpacking-4-byte-unsigned-integers-from-binary-file-gives-struct-error-unpack-r el tamaño de la cadena debe coincidir con el del buffer pero no logro entender es como hacerlo, si alguno fuera tana amable y me hechara un cable con esto?
Código:
HEADER_SIZE = 1024
BLOCK_SIZE = 512
DWORD_SIZE = struct.calcsize("I")
IMAGE_NAME_LEN = 24
def read_dword(f):
return struct.unpack("<I", f.read(DWORD_SIZE))[0]
def main():
if len(sys.argv) != 3:
print("USAGE: <BOOT_IMAGE> UNPACK_DIR")
return
script_name, boot_path, unpack_dir = sys.argv
boot_file = open(boot_path, "rb")
num_images = read_dword(boot_file)
images = []
for i in range(0, num_images):
image_name = boot_file.read(IMAGE_NAME_LEN).rstrip(b'\x00')
start_off = read_dword(boot_file) * BLOCK_SIZE + HEADER_SIZE
end_off = (read_dword(boot_file) + 1) * BLOCK_SIZE + HEADER_SIZE - 1
print("[+] Detected image: %s [0x%08X - 0x%08X]" % (image_name, start_off, end_off))
images.append((image_name, start_off, end_off))
for(image_name, start_off, end_off) in images:
print("[+] Dumping image: %s" % image_name)
boot_file.seek(start_off, os.SEEK_SET)
image_file = open(os.path.join(unpack_dir, image_name), 'wb')
image_file.write(boot_file.read(end_off - start_off +1))
image_file.close()
boot_file.close()
if __name__ == "__main__":
main()