Skip to content

Instantly share code, notes, and snippets.

@anpage
Last active December 23, 2023 13:31
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save anpage/b895a34efb0bf1e4a9a4f52228067fa8 to your computer and use it in GitHub Desktop.
Save anpage/b895a34efb0bf1e4a9a4f52228067fa8 to your computer and use it in GitHub Desktop.
Mega Man Legacy Collection ROM Extractor
#!/usr/bin/env python
# Program for extracting the NES roms of each game in the Mega Man Legacy
# Collection for PC
# iNES Headers for Mega Man 1-6
HEADERS = [b'\x4E\x45\x53\x1A\x08\x00\x21\x00\x00\x00\x00\x00\x00\x00\x00\x00',
b'\x4E\x45\x53\x1A\x10\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00',
b'\x4E\x45\x53\x1A\x10\x10\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00',
b'\x4E\x45\x53\x1A\x20\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00',
b'\x4E\x45\x53\x1A\x10\x20\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00',
b'\x4E\x45\x53\x1A\x20\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00']
# Offsets for each game's ROM in the .exe file
# v1.1.0.78 OFFSET SIZE OFFSET SIZE
OFFSETS = [{'PRG': [0x191F468, 0x20000], 'CHA': None},
{'PRG': [0x16FF468, 0x40000], 'CHA': None},
{'PRG': [0x175F468, 0x40000], 'CHA': [0x173F468, 0x20000]},
{'PRG': [0x179F468, 0x80000], 'CHA': None},
{'PRG': [0x181F468, 0x40000], 'CHA': [0x185F468, 0x40000]},
{'PRG': [0x189F468, 0x80000], 'CHA': None}]
if __name__ == '__main__':
# Read in entire .exe file
f = open("Proteus.exe", "rb")
try:
exe = f.read()
finally:
f.close()
for i, game in enumerate(HEADERS):
for section in ['PRG', 'CHA']:
if OFFSETS[i][section]:
start = OFFSETS[i][section][0]
size = OFFSETS[i][section][1]
end = start + size
game += exe[start:end]
out = open("Mega Man " + str(i+1) + ".nes", "wb")
try:
out.write(game)
finally:
out.close()
@anpage
Copy link
Author

anpage commented Aug 22, 2017

TODO

  • Search for offsets rather than use fixed ones
  • CLI Interface
  • Error handling
  • Make it more Pythonic I guess

@VideogameScrapbook
Copy link

VideogameScrapbook commented Mar 18, 2020

@anpage:
Your 2017 script version no longer works with the latest Steam EXE. I created a fork to update the offsets and also added the extraction of the Japanese ROMs. There seems to be no way to do a pull request for gists, so here's my fork that you can copy from into your repository:
https://gist.github.com/VideogameScrapbook/e1dc851234b0bdba97b0c73cf9f52aed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment