#!/usr/bin/env python3 """Read-only Bubble gadget contract and bounded source-state projections. REA inspected generated EXE copies; these projections are not original execution. """ from __future__ import annotations import argparse from dataclasses import dataclass, replace import hashlib import json import math from pathlib import Path import struct from checkpoint_script_state import EXE_SHA256, find_case, read_va from pe_inspect import PE BODIES = ( ('constructor', 0x410840, 0x410a0f, '60f84d3037031e7bdb4eff676c99b8f14337114086812d90f9cdf6cc512e3c52'), ('bind', 0x410a80, 0x410ad1, '568468bd5cbd82fe5f4c3d54919b27c3cf6f4c472467102bcd0aae4f97f33f92'), ('animate', 0x410ae0, 0x410c9e, '2d2fce6259a34254dec6b9e6a6302150f58c79d19771861fcadb26e8eda38c60'), ('start', 0x410ca0, 0x410cf3, '238c7652a9d6237c6897a74e1c9757b15a063abf017f6e5225d25a75798b0fa3'), ('stop', 0x410d00, 0x410d16, 'a551ba8c995dfd11db00c5d25f8502101a7bd05928a22781b0fd9f45e0d799c8'), ('equip', 0x428f61, 0x4290b7, '0d56551646c616094d7550de24600475b2593160234111bb76fe2a434893862c'), ('cleanup', 0x427ff0, 0x4280cc, 'd81b941f45247d8fc3c7652bc64d06e9c503d699d1a1820c5fab4ffad4e56bf9'), ('active_input', 0x426264, 0x4263ef, '77de32b45f3808ccd7ec76304d74c82b09cc7ee831a6b7553e3fe68c72296715'), ('ordinary_fire_gate', 0x42668f, 0x4266b9, 'd88cb837b49acc11f3a779f71b3f361ed27c634532aa3808081cf4a2438ee6b3'), ('effect_callbacks', 0x42a870, 0x42a91a, 'eb20ec6524bf2a54bf45ea781f0cb0d6bc03f3c729f5dbd4097810d5c9b21fa2'), ('supported_radius', 0x42469b, 0x4246e9, '40e025e4bdc8bcdbcb24651e3d81908a5b7a9e2cc8de81d733da7490ea76c1d4'), ('movement_dispatch', 0x438b1e, 0x438ba4, 'a18e41a473e0975ae79c2d328ec323d7c87d77722a6a43a785bbc3fe92a58743'), ) SITES = ( ('owned_bubble_ctor', 0x42232c, 5), ('owned_bubble_field', 0x42233c, 6), ('sprite_archive', 0x410919, 5), ('sprite_canvas1', 0x41094a, 7), ('radius160', 0x429049, 13), ('factor0415', 0x429058, 13), ('mode0', 0x429065, 7), ('movement2', 0x429072, 9), ('max1350', 0x42907b, 10), ('start_effect', 0x429085, 5), ('loop_sound2', 0x429093, 11), ('practice_vr01', 0x428fca, 5), ('energy_gate', 0x428fda, 25), ('exempt_flag', 0x428fed, 8), ('active_guard', 0x429013, 14), ('collapse_guard', 0x429021, 14), ('expand_guard', 0x42902f, 14), ('cleanup_mode0', 0x428030, 7), ('cleanup_timer05', 0x428045, 10), ('cleanup_movement0', 0x42804f, 7), ('cleanup_max650', 0x428056, 10), ('cleanup_stop', 0x428060, 5), ('cleanup_clear_expand', 0x42806b, 6), ('cleanup_stop_loop', 0x42807c, 7), ('cleanup_radius60', 0x42809c, 13), ('cleanup_factor1265', 0x4280ab, 13), ('cleanup_mode_minus1', 0x4280bb, 9), ('input_mode2', 0x426264, 14), ('input_drain', 0x426272, 19), ('input_empty_cleanup', 0x426285, 32), ('position_y100', 0x4262f2, 6), ('position_distance80', 0x42637a, 6), ('position_y50', 0x426399, 6), ('fire_mode0_reject', 0x4266ac, 13), ('effect_pulse30', 0x410b5a, 6), ('expand_strict1', 0x410b95, 29), ('collapse_strict0', 0x410c1e, 13), ) VTABLES = ((0x4a3bdc, 0x174, 0x428d50), (0x4a3bdc, 0x178, 0x427ff0), (0x49250c, 0x3c4, 0x410ae0), (0x49250c, 0x110, 0x471240), (0x49250c, 0x100, 0x4711e0), (0x4a3bdc, 0x128, 0x439900)) def collect(original: Path | str): pe = PE(find_case(Path(original), 'Neutron.exe')) digest = hashlib.sha256(pe.data).hexdigest() if digest != EXE_SHA256: raise ValueError('Unexpected original EXE identity') bodies = [] for name, start, end, expected in BODIES: actual = hashlib.sha256(read_va(pe, start, end-start)).hexdigest() if actual != expected: raise ValueError(f'Changed source span {name}') bodies.append(dict(name=name, va=hex(start), file_offset=hex(pe.offset(start-pe.base)), length=end-start, sha256=actual)) sites = [dict(name=name, va=hex(va), file_offset=hex(pe.offset(va-pe.base)), bytes=read_va(pe, va, length).hex()) for name, va, length in SITES] for base, slot, expected in VTABLES: if struct.unpack('1. else timer return replace(state,scalar=scalar,active=timer>1.,expanding=timer<=1.,rgba=(scalar,)*4) if state.collapsing: scalar=f32(1.-timer) return replace(state,scalar=max(0.,scalar),collapsing=scalar>=0., hidden=state.hidden or scalar<0.,rgba=(max(0.,scalar),)*4) return state if __name__ == '__main__': cli=argparse.ArgumentParser(description=__doc__) cli.add_argument('original',type=Path) print(json.dumps(collect(cli.parse_args().original),indent=2))