#!/usr/bin/env python3 """Generate targets_generated.h from a resolved target table. The header holds each target's RVA, length and 20-byte FNV-1a fingerprint as a named struct field, plus the build's version. The hook library checks the fingerprint against the running libil2cpp.so before arming, so a table can only ever be applied to the build it was resolved from. Usage: gen_targets_header.py """ import json import sys from pathlib import Path def main(): if len(sys.argv) != 3: raise SystemExit("usage: gen_targets_header.py ") table = json.loads(Path(sys.argv[1]).read_text(encoding="utf-8")) ids = list(table["targets"].keys()) lines = [ "// Generated by scripts/gen_targets_header.py -- do not edit.", f"// Build {table['versionName']} / versionCode {table['versionCode']}", f"// libil2cpp.so sha256 {table['il2cppSha256']}", "#ifndef DORKNET_QUEST_TARGETS_GENERATED_H", "#define DORKNET_QUEST_TARGETS_GENERATED_H", "#include ", "", f'#define DN_TARGET_VERSION_NAME "{table["versionName"]}"', f'#define DN_TARGET_VERSION_CODE "{table["versionCode"]}"', f"#define DN_HOOK_BYTES {table['hookBytes']}", "", "typedef struct { const char *id; uint32_t rva; uint64_t fingerprint; uint32_t length; } DnTarget;", "", "typedef struct {", ] for tid in ids: lines.append(f" DnTarget {tid};") lines.append("} DnTargets;") lines.append("") lines.append("static const DnTargets dn_targets = {") for tid in ids: e = table["targets"][tid] length = e["length"] if e["length"] is not None else 0 lines.append( f' .{tid} = {{ "{tid}", {e["rva"]:#x}u, {e["fingerprint"]}ull, {length}u }},') lines.append("};") lines.append("") lines.append("#endif") Path(sys.argv[2]).write_text("\n".join(lines) + "\n", encoding="utf-8") print(f"wrote {sys.argv[2]} ({len(ids)} targets)") if __name__ == "__main__": main()