Skip to content

Instantly share code, notes, and snippets.

@TheRadziu
Last active September 5, 2018 01:21
Show Gist options
  • Save TheRadziu/7eacf9fcfdfe25ab8f1d34720529b780 to your computer and use it in GitHub Desktop.
Save TheRadziu/7eacf9fcfdfe25ab8f1d34720529b780 to your computer and use it in GitHub Desktop.
FSELF all ELF FAGdec files at once
###### SETTINGS ######
make_self_path = "C:\Path\to\make_fself.exe" # Set full path to make_fself.exe file. Must be quoted.
deletion = True # If deletion is enabled, it will remove all unnecessary files(.elf, .sha256, self_auth.bin) [True/False]
######################
import os
import subprocess
master_dir = os.path.dirname(os.path.abspath(__file__))
global_err_num = 0
global_at_least_one_succ = False
if not os.path.isfile(make_self_path):
print('ERROR! Specified \'make_self_path\' is not valid. Please edit this script file and check the supplied path.')
quit()
for dirpath, subdirs, filenames in os.walk(master_dir):
for file in filenames:
if file == "self_auth.bin":
the_auth = os.path.join(dirpath, file)
global_auth_del = True
try:
with open(the_auth, "r+b") as auth:
auth_data = auth.read()
for dirpath, subdirs, filenames in os.walk(dirpath):
for file in filenames:
if file.endswith(".elf"):
current_elf_file = os.path.join(dirpath, file)
try:
print('Processing ' + current_elf_file, end='\r')
subprocess.check_call([make_self_path, '-e', '-c', current_elf_file, current_elf_file[:-4]], stderr=subprocess.STDOUT)
try:
print('Injecting Auth into FSELF: ' + file[:-4], end='\r')
with open(current_elf_file[:-4], "r+b") as self:
self.seek(128)
self.write(auth_data)
global_at_least_one_succ = True
print('SUCCESS! FSELFing file: ' + current_elf_file[:-4])
if deletion == True:
os.remove(current_elf_file)
os.remove(current_elf_file + '.sha256')
except Exception as auth_injection_error:
print('ERROR! Can\'t inject the auth into ' + current_elf_file)
global_err_num += 1
global_auth_del = False
except Exception as elf_error:
print('ERROR! Can\'t process ' + file)
global_err_num += 1
except Exception as auth_error:
print('ERROR! handling auth in: ' + the_auth)
global_err_num += 1
if deletion is True and global_auth_del is True:
os.remove(the_auth)
if global_at_least_one_succ is not False:
print('Finished with ' + str(global_err_num) + ' errors!')
else:
print('ERROR! No .elf files detected in this directory or it\'s subdirectories.')
@dots-tb
Copy link

dots-tb commented Sep 5, 2018

use vita-elf-inject

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