elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: AIO elhacker.NET 2021 Compilación herramientas análisis y desinfección malware


+  Foro de elhacker.net
|-+  Programación
| |-+  Scripting
| | |-+  error unpack requires a buffer of 4 bytes
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: error unpack requires a buffer of 4 bytes  (Leído 2,203 veces)
colcrt

Desconectado Desconectado

Mensajes: 86


Ver Perfil
error unpack requires a buffer of 4 bytes
« en: 20 Mayo 2022, 23:40 pm »

estoy leyendo una archivo .img en formato binario y lo que busco es volcar el contenido, sin embargo el código que estoy utilizando me arroja un error en la línea 23 "end_off = (read_dword(boot_file) + 1) * BLOCK_SIZE + HEADER_SIZE - 1" con el mensaje: struct.error: unpack requires a buffer of 4 bytes

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()


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Que error es este?? Fatal error: Allowed memory size of 8388608 bytes exhausted
PHP
XXXXXX 4 5,594 Último mensaje 19 Diciembre 2008, 00:56 am
por Unnamed
Error en Buffer Overflow « 1 2 3 4 »
Bugs y Exploits
Lodos76 34 19,489 Último mensaje 5 Marzo 2014, 13:54 pm
por Lodos76
jasperReport error: Byte no válido 1 de la secuencia UTF-8 de 1 bytes
Java
mgc 0 4,942 Último mensaje 14 Noviembre 2014, 13:47 pm
por mgc
Error con archivos de 0 bytes, luego de montar particiones de guindow$ en fstab
GNU/Linux
rub'n 2 1,604 Último mensaje 17 Noviembre 2015, 19:29 pm
por rub'n
Convertir Cadena Hex a Bytes y compararlos Con Bytes de un archivo
.NET (C#, VB.NET, ASP)
**Aincrad** 3 2,734 Último mensaje 14 Octubre 2018, 00:52 am
por Eleкtro
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines