Skip to content

Instantly share code, notes, and snippets.

@handsomematt
Last active August 20, 2017 00:54
Show Gist options
  • Save handsomematt/35e747f4d56bf2b447ad1cd739afc74d to your computer and use it in GitHub Desktop.
Save handsomematt/35e747f4d56bf2b447ad1cd739afc74d to your computer and use it in GitHub Desktop.
Simple tool to split and decrypt fcore files into their respective sections
#!/usr/bin/env python
# Requires Python >= 3.2 or >= 2.7
# Simple tool to split and decrypt fcore files into their respective sections
import argparse
from struct import *
from binascii import *
permutation_key = bytearray.fromhex("00C001C104C405C506C607C70ACA0BCB0CCC0DCD08C809C902C203C30ECE0FCF10D011D114D415D516D617D71ADA1BDB1CDC1DDD18D819D912D213D31EDE1FDF4080418144844585468647874A8A4B8B4C8C4D8D48884989428243834E8E4F8F5090519154945595569657975A9A5B9B5C9C5D9D58985999529253935E9E5F9F6020612164246525662667276A2A6B2B6C2C6D2D68286929622263236E2E6F2F7030713174347535763677377A3A7B3B7C3C7D3D78387939723273337E3E7F3FA0E0A1E1A4E4A5E5A6E6A7E7AAEAABEBACECADEDA8E8A9E9A2E2A3E3AEEEAFEFB0F0B1F1B4F4B5F5B6F6B7F7BAFABBFBBCFCBDFDB8F8B9F9B2F2B3F3BEFEBFFF")
def main(args=None):
parser = argparse.ArgumentParser(prog="fcore_tool", description="Tool for F_CORE.DAT M3i Zero files.")
parser.add_argument("in_fcore", type=argparse.FileType("rb"))
parser.add_argument("out_1", type=argparse.FileType("wb+"), default="m3i.nds", nargs="?")
parser.add_argument("out_2", type=argparse.FileType("wb+"), default="gmpz003.nds", nargs="?")
parser.add_argument("out_3", type=argparse.FileType("wb+"), default="filler.bin", nargs="?")
args = parser.parse_args()
fcoreData = bytearray(args.in_fcore.read())
section_1 = fcoreData[0:0x200000] # m3izero
section_2 = fcoreData[0x200000:0x400000] # m3izero gmp-z003
section_3 = fcoreData[0x400000:] # always filler?
# decrypt the 0:0x200000 data
for i, data in enumerate(section_1):
section_1[i] = permutation_key[data]
args.out_1.write(section_1)
args.out_2.write(section_2)
args.out_3.write(section_3)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment