"""Immutable original streamer/descriptor evidence; no original code execution.""" import importlib.util from pathlib import Path import unittest ROOT = Path(__file__).resolve().parents[1] spec = importlib.util.spec_from_file_location('retained_streamer', ROOT / 'tools/binary/retained_streamer.py') streamer = importlib.util.module_from_spec(spec) spec.loader.exec_module(streamer) class RetainedStreamerTests(unittest.TestCase): @classmethod def setUpClass(cls): cls.evidence = streamer.collect(ROOT.parent / 'Original') def test_import_export_and_receiver_dispatch(self): r = self.evidence self.assertTrue(r['known_binary']) self.assertTrue(r['import_export_matches']) self.assertEqual(r['extraction_export']['va'], '0x10073e00') self.assertTrue(all(s['matches'] for s in r['sites']), r['sites']) self.assertEqual(len(r['sites']), 20) self.assertEqual(len(r['vtables']), 6) self.assertTrue(all(t['matches'] for t in r['vtables'])) self.assertEqual({t['target'] for t in r['vtables'] if t['slot'] == '0x4'}, {'0x473b30'}) def test_entire_reader_lookup_bodies_and_direct_field_destinations(self): r = self.evidence self.assertEqual(len(r['functions']), 2) self.assertTrue(all(f['matches'] for f in r['functions'])) self.assertEqual(len(r['descriptors']), 20) self.assertTrue(all(d['matches'] for d in r['descriptors']), r['descriptors']) fields = {d['name']: int(d['interface_offset'], 16) for d in r['descriptors']} self.assertEqual([fields[n] for n in ('PositionX', 'PositionY', 'PositionZ')], [0xEC, 0xF0, 0xF4]) self.assertEqual([fields[n] for n in ('RotationX', 'RotationY', 'RotationZ')], [0xFC, 0x100, 0x104]) self.assertEqual(fields['StartPoint'], 0x664) self.assertTrue(set(fields.values()).isdisjoint({0x704, 0x728, 0x1A4, 0x274, 0x288}), 'Mode/jump/live body vectors are not these GAM descriptor destinations') def test_route_properties_are_exact_registered_subset_without_runtime_fields(self): r = self.evidence self.assertEqual([s['code'] for s in r['route']], ['LV1B', 'VR04', 'LEV1']) self.assertTrue(all(s['exact_descriptor_set'] for s in r['route'])) names = sorted(d['name'] for d in r['descriptors']) for scene in r['route']: self.assertEqual(scene['player_properties'], names) self.assertEqual(len(scene['player_properties']), 20) if __name__ == '__main__': unittest.main()