tools/client/test_vendor_data.py (1622B)
1 """Check compact-switch data classification against the shipped ACE image.""" 2 3 import pathlib 4 import struct 5 6 import pefile 7 8 import standalone_text_data 9 10 11 root = pathlib.Path(__file__).resolve().parents[2] 12 13 14 def compact_switch_tables_are_data(): 15 pe = pefile.PE(str(root / "anarchy-runtime-14.9.1/ace.dll")) 16 pe.relocate_image(0x47000000) 17 pe.OPTIONAL_HEADER.ImageBase = 0x47000000 18 19 ranges, handlers, audit = standalone_text_data.extract( 20 pe, root / "client/vendor/ace/source") 21 22 assert audit["unresolved"] == [] 23 assert audit["retained_text_bytes"] == 10309 24 assert audit["exception_handlers"] == 847 25 assert [item["address"] for item in audit["classified"] 26 if item["kind"] == "range-checked-index" and item["overlaps_incidental_decode"]] == [ 27 0x470045a4, 0x470046fc] 28 pe.close() 29 30 31 def compact_switch_with_noncode_destination_is_rejected(): 32 pe = pefile.PE(str(root / "anarchy-runtime-14.9.1/ace.dll")) 33 pe.relocate_image(0x47000000) 34 pe.OPTIONAL_HEADER.ImageBase = 0x47000000 35 pe.set_bytes_at_rva(0x4590, struct.pack("<I", 0x470045a4)) 36 37 ranges, handlers, audit = standalone_text_data.extract( 38 pe, root / "client/vendor/ace/source") 39 40 assert any(item["instruction"] == 0x47004546 and item["address"] == 0x470045a4 41 and item["reason"] == "data overlaps discovered instructions" 42 for item in audit["unresolved"]) 43 pe.close() 44 45 46 compact_switch_tables_are_data() 47 compact_switch_with_noncode_destination_is_rejected() 48 print("Vendor data: compact switch tables accepted; invalid case destination rejected")