Last active
August 22, 2018 13:45
-
-
Save SocraticBliss/d799dc50204f616893ed4c529efe6107 to your computer and use it in GitHub Desktop.
ps4libdoc NID updating
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
# A script for updating your ps4libdoc json files with additional names... | |
# SocraticBliss (R) | |
import json | |
import os | |
import re | |
import subprocess | |
import sys | |
def get_null_NIDs(): | |
with open('null_NIDs.txt', 'w') as list: | |
NIDs = [] | |
# Walk the directories searching the ps4libdoc json files | |
for root, dirs, files in os.walk('.'): | |
for file in [f for f in files if f.endswith('.json')]: | |
with open(os.path.join(root, file), 'r') as file: | |
data = json.load(file) | |
# Iterate through all the libraries in the module | |
for libraries in data['modules']: | |
# Iterate through all the symbols in the library | |
for symbols in libraries['libraries'][0]['symbols']: | |
obfuscated = symbols['encoded_id'] | |
symbol = symbols['name'] | |
# Save the unique null entries | |
if obfuscated not in NIDs and symbol is None: | |
list.write('%s\n' % obfuscated) | |
NIDs.append(obfuscated) | |
def update_ps4libdocs(): | |
updates = {} | |
with open('updates.txt', 'r') as dict: | |
for line in dict: | |
key,value = line.split(':') | |
updates[key] = value.rstrip() | |
# Walk the directories searching for ps4libdoc json files | |
for root, dirs, files in os.walk('.'): | |
for file in [f for f in files if f.endswith('.json')]: | |
# Iterate through the input python dictionary for each ps4libdoc json file | |
for key,value in updates.iteritems(): | |
with open(os.path.join(root, file), 'r+b') as ps4libfile: | |
result, matches = re.subn(ur'("encoded_id": "%s",\n.*"name": )(null)' % re.escape(key), | |
u"\\1\"%s\"" % value, | |
ps4libfile.read(), | |
re.M) | |
# If a match was found, update the ps4libdoc json file name (null) with the new name | |
if matches > 0: | |
print('%s was updated!' % file) | |
ps4libfile.seek(0) | |
ps4libfile.write(result) | |
ps4libfile.truncate() | |
def main(): | |
if not os.path.isfile('known_names.txt'): | |
print('Error: known_names.txt file not found!') | |
return 1 | |
# 1) Get the null NIDs from ps4libdocs | |
print('Saving null NIDs to null_NIDs.txt...') | |
get_null_NIDs() | |
# Are there any null NIDs? | |
if os.stat("null_NIDs.txt").st_size == 0: | |
print('No null NIDs found :)') | |
return 1 | |
# 2) Run hashcat and get a list of newly found names | |
print('Using hashcat to bruteforce NIDs...') | |
if os.path.isfile('hashcat.exe'): | |
subprocess.call(['cmd', '/c hashcat.exe --force --potfile-disable -m 16111 -a 0 null_NIDs.txt known_names.txt -o updates.txt > nul 2>&1']) | |
elif os.path.isfile('hashcat64.exe'): | |
subprocess.call(['cmd', '/c hashcat64.exe --force --potfile-disable -m 16111 -a 0 null_NIDs.txt known_names.txt -o updates.txt > nul 2>&1']) | |
else: | |
print('Error: hashcat not found!') | |
return 1 | |
# Are there any name updates? | |
if not os.path.isfile('updates.txt'): | |
print('No new names found :(') | |
return 1 | |
# 3) Update ps4libdocs with the newly found names | |
print('Updating ps4libdocs with new names...') | |
update_ps4libdocs() | |
# 4) ??? Profit! | |
print('Complete!') | |
if __name__=='__main__': | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment