Seregon/PkgToolBox

Toolbox for analyzing and editing pkg application files for psp,ps3, ps4 and ps5, includes the most useful functions you might need.

Python/57.3 KB/No license
file_operations/inject.py
1import os
2 
3 
4def inject_file(pkg_file, file_info, input_file):
5 with open(input_file, 'rb') as f:
6 data = f.read()
7
8 with open(pkg_file, 'r+b') as f:
9 # Check if the file already exists and if it needs to be overwritten
10 if file_info['size'] != len(data):
11 raise ValueError("The injected file size does not match the original size.")
12
13 f.seek(file_info['offset'])
14 f.write(data)
15
16 return len(data)