This repository has been archived on 2024-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
RustedIronRing/scripts/patch.py
dece eff19f5551 scripts: add dir
Add 2 scripts that I just used, could be useful.
2020-05-26 01:04:57 +02:00

29 lines
867 B
Python
Executable file

#!/usr/bin/env python3
"""Patch a file with another file at offset. Useful for dirty DAT patching."""
import argparse
def main():
argparser = argparse.ArgumentParser()
argparser.add_argument("archive", help="File to be modified")
argparser.add_argument("file", help="File to patch in archive")
argparser.add_argument("offset", help="Offset as hex")
args = argparser.parse_args()
archive_path, input_file_path = args.archive, args.file
ofs = int(args.offset.lstrip("0x").rstrip("h"), 16)
patch(archive_path, input_file_path, ofs)
def patch(archive_path, input_file_path, ofs):
with open(input_file_path, "rb") as input_file:
input_data = input_file.read()
with open(archive_path, "rb+") as archive_file:
archive_file.seek(ofs)
archive_file.write(input_data)
if __name__ == "__main__":
main()