miniminater

Untitled

Jun 20th, 2023 (edited)
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. import struct
  2.  
  3. file_path = 'rom.bin'
  4.  
  5. # Get the length of the file
  6. with open(file_path, 'rb') as file:
  7. file_length = len(file.read())
  8.  
  9. # Subtract 1 from the file length
  10. file_length -= 1
  11.  
  12. # Convert the file length to a 32-bit binary representation
  13. binary_length = struct.pack('<I', file_length)
  14.  
  15. # Open the file in write mode and seek to the desired location (0x1A4)
  16. with open(file_path, 'r+b') as file:
  17. file.seek(0x1A4)
  18.  
  19. # Write the binary length to the file
  20. file.write(binary_length)
  21.  
Advertisement
Add Comment
Please, Sign In to add comment