Toolbox for analyzing and editing pkg application files for psp,ps3, ps4 and ps5, includes the most useful functions you might need.
| 1 | import os |
| 2 | |
| 3 | |
| 4 | def 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) |