Last active
September 14, 2023 00:40
-
-
Save SocraticBliss/37f913dd29969c11550d3fc6c46e2951 to your computer and use it in GitHub Desktop.
PS4 MONO binaries to IL MONO binaries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
''' | |
PS4 MONO binaries to IL MONO binaries by SocraticBliss (R) | |
The script recursively searches the directories for PS4 MONO DLL and EXE files, | |
finds the scekrit magic for them and then spits them out in the same directory... | |
1) Place this script in the top-most directory | |
2) python ps4_mono_to_il.py | |
Thanks to zecoxao, ChendoChap, samsepi0l and flatz <3 | |
''' | |
import os | |
import re | |
import struct | |
def unpack_file(file, format, begin, end): | |
return struct.unpack(format, file[begin:end])[0] | |
def read_file(input, pattern): | |
with open(input, 'rb') as INPUT: | |
file = INPUT.read()[0x1000:] | |
match = re.search(pattern, file) | |
begin = match.start() | |
#print('Begin: %#x' % begin) | |
sections = unpack_file(file, '<H', begin + 0x86, begin + 0x88) | |
#print('Section Count: %i' % sections) | |
size = unpack_file(file, '<I', | |
begin + 0x188 + ((sections - 1) * 0x28), | |
begin + 0x18C + ((sections - 1) * 0x28)) | |
size += unpack_file(file, '<I', | |
begin + 0x18C + ((sections - 1) * 0x28), | |
begin + 0x190 + ((sections - 1) * 0x28)) | |
#print('Total Size: %#x' % size) | |
return file, begin, begin + size | |
def write_file(output, content): | |
with open(output, 'wb') as OUTPUT: | |
OUTPUT.write(content) | |
if __name__ == '__main__': | |
try: | |
# Find those binaries... | |
for root, _, files in os.walk('.'): | |
for file in [f for f in files if f.endswith(('.dll.sprx', '.exe.sprx', '.sdll', '.sexe'))]: | |
input = os.path.join(root, file) | |
# Search for the magic pattern | |
print('Parsing: %s' % input) | |
output, begin, end = read_file(input, b'\x4D\x5A\x90\x00') | |
if file[-3:] in ['dll', 'exe']: | |
filename = file[:-5] | |
extension = file[-3:] | |
else: | |
filename = file[:-9] | |
extension = file[-8:-5] | |
#print('Filename: %s' % filename) | |
#print('Extension: %s' % extension) | |
# Save the .exe or .dll | |
write_file('%s/%s.%s' % (root, filename, extension), output[begin:end]) | |
except Exception as e: | |
print(e) | |
raise SystemExit('\nError: Unable to parse the PS4 MONO binaries!') | |
print('\nDone!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment