#!/usr/bin/env python3 """Read-only GAM retained-object property-stream callback and descriptor evidence.""" from __future__ import annotations import argparse import hashlib import json from pathlib import Path import struct import sys sys.path.insert(0, str(Path(__file__).resolve().parent)) from checkpoint_script_state import EXE_SHA256, find_case, read_va from pe_inspect import PE sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'levels')) import gam DLL_SHA256 = '3ec41ead011adf56387a6dbd4580e5b5a9721b5f8020c8a56420f42824354943' EXTRACTION_NAME = '??5OMediaStreamOperators@@QAEAAV0@PAVOMediaClassStreamer@@@Z' # (name, pointer argument LEA VA, exact LEA, interface offset, wire type, # property-name literal VA, push-name VA). These are Jimmy's actual registered # destinations, not inferred destinations from GAM key spelling. DESCRIPTORS = ( ('ObjectTag', 0x470403, '8d8ea0030000', 0x3A0, 1, 0x4F6044, 0x47040C), ('RotateToDest', 0x470427, '8d460a', 0xA, 2, 0x4F6034, 0x47042D), ('ObjectID', 0x47043E, '8d8604040000', 0x404, 6, 0x4F6028, 0x470447), ('PositionX', 0x470458, '8d86ec000000', 0xEC, 3, 0x4F601C, 0x470461), ('PositionY', 0x470472, '8d86f0000000', 0xF0, 3, 0x4F6010, 0x47047B), ('PositionZ', 0x47048C, '8d86f4000000', 0xF4, 3, 0x4F6004, 0x470495), ('RotationX', 0x4704A6, '8d86fc000000', 0xFC, 3, 0x4F5FF8, 0x4704AF), ('RotationY', 0x4704C0, '8d8600010000', 0x100, 3, 0x4F5FEC, 0x4704C9), ('RotationZ', 0x4704DA, '8d8604010000', 0x104, 3, 0x4F5FE0, 0x4704E3), ('TaskName', 0x45883F, '8d8630040000', 0x430, 1, 0x4F2870, 0x458848), ('Debug', 0x458859, '8d86a4040000', 0x4A4, 6, 0x4F2868, 0x458862), ('RequiredLevel', 0x40D3CC, '8d8e78050000', 0x578, 6, 0x4ED294, 0x40D3D5), ('ExactLevel', 0x40D3E6, '8d867c050000', 0x57C, 6, 0x4ED288, 0x40D3EF), ('RemoveLevel', 0x40D400, '8d8680050000', 0x580, 6, 0x4ED27C, 0x40D409), ('HasCollision', 0x40D41A, '8d8684050000', 0x584, 6, 0x4ED26C, 0x40D423), ('InitiallyVisible', 0x40D434, '8d8688050000', 0x588, 6, 0x4ED258, 0x40D43D), ('CanMove', 0x40D44E, '8d868c050000', 0x58C, 6, 0x4ED250, 0x40D457), ('SecondPass', 0x40D468, '8d8690050000', 0x590, 6, 0x4ED244, 0x40D471), ('PickupLink', 0x40D482, '8d8695050000', 0x595, 1, 0x4ED238, 0x40D48B), ('StartPoint', 0x43784F, '8d8664060000', 0x664, 1, 0x4EFB3C, 0x437858), ) SITES = ( ('loader_extraction_import', 0x46E3CB, '8b1d90d14800'), ('loader_property_call', 0x46E3FC, '56ffd3'), ('jimmy_ctor_property_registration', 0x422245, 'e876080000'), ('jimmy_properties_parent', 0x422AD7, 'e8544d0100'), ('player_properties_parent', 0x437846, 'e8755bfdff'), ('actor_properties_parent', 0x40D3C3, 'e8784f0500'), ('shape_properties_parent', 0x462356, 'e8c564ffff'), ('task_properties_parent', 0x458836, 'e8757b0100'), ('reader_name_read', 0x473B94, 'ff1508d24800'), ('reader_lookup', 0x473BA3, 'ff9000040000'), ('reader_wire_type_metadata', 0x473BC0, '894704'), ('reader_type_jump', 0x473BD0, 'ff2485783e4700'), ('reader_string_destination', 0x473BEE, '8b47488bce50ff1508d24800'), ('reader_int_destination', 0x473C43, '8b57488b4424348902'), ('reader_float_destination', 0x473C5F, '8b47488bce50ff15e4d34800'), ('reader_long_destination', 0x473CA7, '8b4f48518bceffd3'), ('reader_finish_returns', 0x473E6F, '81c4e8000000c20400'), ('lookup_returns_descriptor', 0x473F8F, '8b43085f5e5d5b81c408010000c20400'), ('register_destination_pointer', 0x473FFA, '8b4c241c894b48'), ) FUNCTIONS = ( ('registered-property reader', 0x473B30, 0x473E78, '31d5e0051c36501b2251d136338650d0f1786238c844aea30916c4f9fc976ffb'), ('registered-property lookup', 0x473EB0, 0x473F9F, 'ee1435c3eb5d2728f10c70c900560afd459585b392e78c9248017ff49908c211'), ) def site(pe, name, va, expected): actual = read_va(pe, va, len(bytes.fromhex(expected))).hex() return dict(name=name, va=hex(va), file_offset=hex(pe.offset(va-pe.base)), expected=expected, actual=actual, matches=actual == expected) def collect(root: Path): pe = PE(find_case(root, 'Neutron.exe')) dll = PE(find_case(root, 'OMT2.dll')) exe_hash = hashlib.sha256(pe.data).hexdigest() dll_hash = hashlib.sha256(dll.data).hexdigest() sites = [site(pe, *s) for s in SITES] sites.append(site(dll, 'DLL extraction receiver slot4', 0x10073E00, '568bf18b4c2408568b01ff50048bc65ec20400')) tables = [] for name, table in (('Jimmy', 0x4A373C), ('fire', 0x4A3160), ('Goddard', 0x49F480)): for slot, expected in ((4, 0x473B30), (0x400, 0x473EB0)): actual = struct.unpack('