Files
WoW-Hybrid-gateway/ops/prepare_client_update_glue.py

42 lines
1.6 KiB
Python

#!/usr/bin/env python3
"""Append the owned updater UI to an extracted, selected GlueParent payload.
No store writes. Feed the output through the existing content composition pipeline.
"""
import argparse
import hashlib
import json
from pathlib import Path
BEGIN = b'-- BEGIN OCTO UPDATE UI 71\n'
END = b'-- END OCTO UPDATE UI 71\n'
def compose(original, addition):
if BEGIN in original or END in original:
raise ValueError('Updater block already present: use its recorded original preimage')
return original + b'\n' + BEGIN + addition + b'\n' + END
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('input', type=Path)
parser.add_argument('output', type=Path)
args = parser.parse_args()
if args.input.resolve() == args.output.resolve():
parser.error('Input must remain an untouched rollback preimage')
addition = Path(__file__).resolve().parents[1] / 'compat/glue/octo_update.lua'
before = args.input.read_bytes()
after = compose(before, addition.read_bytes())
args.output.parent.mkdir(parents=True, exist_ok=True)
args.output.write_bytes(after)
receipt = dict(fdid=5612385, before_sha256=hashlib.sha256(before).hexdigest(),
after_sha256=hashlib.sha256(after).hexdigest(),
addition_sha256=hashlib.sha256(addition.read_bytes()).hexdigest(),
before_bytes=len(before), after_bytes=len(after))
args.output.with_suffix(args.output.suffix + '.json').write_text(json.dumps(receipt, indent=2)+'\n')
if __name__ == '__main__':
main()