metalx1000

Reverse Engineer Firmware

Jun 8th, 2020
1,894
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #MIPS Camera Device Reverse Engineer Firmwar
  2. #Video https://www.youtube.com/watch?v=hV8W4o-Mu2o
  3.  
  4. #!/usr/bin/env python3
  5.  
  6. import sys
  7.  
  8. class FirmwarePart:
  9.     def __init__(self, name, offset, size):
  10.         self.name = name
  11.         self.offset = offset
  12.         self.size = size
  13.  
  14. firmware_parts = [
  15.     FirmwarePart("uimage_header", 0x0, 0x40),
  16.     FirmwarePart("uimage_kernel", 0x40, 0x200000),
  17.     FirmwarePart("squashfs_1", 0x200040, 0x350000),
  18.     FirmwarePart("squashfs_2", 0x550040, 0xa0000),
  19.     FirmwarePart("jffs2", 0x5f0040, 11075648-0x5f0040)
  20. ]
  21.  
  22. if sys.argv[1] == "unpack":
  23.     f = open(sys.argv[2], "rb")
  24.     for part in firmware_parts:
  25.         outfile = open(part.name, "wb")
  26.         f.seek(part.offset, 0)
  27.         data = f.read(part.size)
  28.         outfile.write(data)
  29.         outfile.close()
  30.         print(f"Wrote {part.name} - {hex(len(data))} bytes")
  31. elif sys.argv[1] == "pack":
  32.     f = open(sys.argv[2], "wb")
  33.     for part in firmware_parts[1:]:
  34.         i = open(part.name, "rb")
  35.         data = i.read()
  36.         f.write(data)
  37.         padding = (part.size - len(data))
  38.         print(f"Wrote {part.name} - {hex(len(data))} bytes")
  39.         print(f"Padding: {hex(padding)}")
  40.         f.write(b'\x00' * padding)
RAW Paste Data