"""Offline evidence-validator tests. Uses PE files, never a process or plugin."""
import copy
import importlib.util
import json
from pathlib import Path
import unittest
root = Path('artifacts/galaxy-client-compatibility')
spec = importlib.util.spec_from_file_location('mapping', Path(__file__).with_name('Prepare-GalaxyClientMapping.py'))
mapping = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mapping)
class EvidenceTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.path = root / 'galaxy-mapping.json'
cls.original = json.loads(cls.path.read_text(encoding='utf8'))
def check_rejected(self, name, mutate, message):
evidence = copy.deepcopy(self.original)
mutate(evidence)
path = root / ('invalid-fixture-' + name + '.json')
path.write_text(json.dumps(evidence, indent=2), encoding='utf8')
with self.assertRaisesRegex(ValueError, message):
mapping.verify(path)
def test_original_verifies_without_runtime_approval(self):
result = mapping.verify(self.path)
self.assertGreater(result['verifiedMappings'], 200)
self.assertEqual(result['verifiedCsmStrings'], 48)
self.assertGreaterEqual(result['sourceRvasAccounted'], 248)
self.assertFalse(result['canInstallHooks'])
self.assertFalse(result['runtimeValidated'])
def test_wrong_code_rva_rejected(self):
def mutate(profile):
row = next(x for x in profile['mappings'] if x['kind'] == 'code')
row['newRva'] = hex(int(row['newRva'], 16) + 16)
self.check_rejected('code-rva', mutate, 'reference evidence|Recorded bytes')
def test_wrong_zero_fill_global_rejected(self):
def mutate(profile):
row = next(x for x in profile['mappings'] if x['kind'] == 'data' and x['storage'].startswith('zero-fill'))
row['newRva'] = hex(int(row['newRva'], 16) + 4)
self.check_rejected('bss-rva', mutate, 'reference evidence')
def test_wrong_new_image_hash_rejected(self):
self.check_rejected('image-hash', lambda p: p['newImage'].update(sha256='0' * 64), 'hash mismatch')
def test_cannot_turn_evidence_into_hook_approval(self):
self.check_rejected('hook-approval', lambda p: p.update(canInstallHooks=True), 'runtime-neutral')
def test_changed_csm_literal_rejected(self):
self.check_rejected('csm-literal', lambda p: p['csmStrings'][0].update(newText='InGameX'), 'CSM state literal')
def test_changed_foundation_slot_rejected(self):
def mutate(profile):
profile['foundationSlots'][0]['newFunction'] = '0x1'
self.check_rejected('foundation-slot', mutate, 'Foundation slot changed')
def test_changed_registration_global_rejected(self):
def mutate(profile):
row = profile['componentBindings'][0]
row['newTypeIdGlobal'] = hex(int(row['newTypeIdGlobal'], 16) + 4)
self.check_rejected('registration-global', mutate, 'Registration type-ID global changed')
def test_missing_current_galaxy_address_rejected(self):
def mutate(profile):
profile['mappings'] = [row for row in profile['mappings'] if row['oldRva'] != '0x3c331e0']
self.check_rejected('missing-galaxy-rva', mutate, 'uninventoried addresses')
def test_later_published_global_requires_original_operand_binding(self):
def mutate(profile):
row = next(x for x in profile['mappings'] if x['oldRva'] == '0x5fdb275')
row['newRva'] = '0x5fdb276'
self.check_rejected('published-global', mutate, 'reference evidence')
def test_later_published_camera_getter_cannot_be_omitted(self):
def mutate(profile):
profile['mappings'] = [row for row in profile['mappings'] if row['oldRva'] != '0x56fd10']
self.check_rejected('published-getter', mutate, 'uninventoried addresses')
def test_mission_interface_requires_its_original_constructor(self):
def mutate(profile):
row = next(x for x in profile['mappings'] if x['oldRva'] == '0x5260a48')
row['newRva'] = '0x5260a48'
self.check_rejected('mission-interface', mutate, 'reference evidence')
def test_ambiguous_cg_body_cannot_replace_the_independently_bound_sender(self):
def mutate(profile):
row = next(x for x in profile['mappings'] if x['oldRva'] == '0x3433090')
# The other normalized body calls a different send helper.
row['newRva'] = '0x3440de0'
self.check_rejected('cg-other-sender', mutate, 'reference evidence')
def test_cg_sender_source_inventory_cannot_be_skipped(self):
def mutate(profile):
profile['mappings'] = [row for row in profile['mappings'] if row['oldRva'] != '0x3433090']
self.check_rejected('cg-missing-sender', mutate, 'uninventoried addresses')
if __name__ == '__main__':
unittest.main(verbosity=2)
"""Offline evidence-validator tests. Uses PE files, never a process or plugin."""
import copy
import importlib.util
import json
from pathlib import Path
import unittest
root = Path('artifacts/galaxy-client-compatibility')
spec = importlib.util.spec_from_file_location('mapping', Path(__file__).with_name('Prepare-GalaxyClientMapping.py'))
mapping = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mapping)
class EvidenceTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.path = root / 'galaxy-mapping.json'
cls.original = json.loads(cls.path.read_text(encoding='utf8'))
def check_rejected(self, name, mutate, message):
evidence = copy.deepcopy(self.original)
mutate(evidence)
path = root / ('invalid-fixture-' + name + '.json')
path.write_text(json.dumps(evidence, indent=2), encoding='utf8')
with self.assertRaisesRegex(ValueError, message):
mapping.verify(path)
def test_original_verifies_without_runtime_approval(self):
result = mapping.verify(self.path)
self.assertGreater(result['verifiedMappings'], 200)
self.assertEqual(result['verifiedCsmStrings'], 48)
self.assertGreaterEqual(result['sourceRvasAccounted'], 248)
self.assertFalse(result['canInstallHooks'])
self.assertFalse(result['runtimeValidated'])
def test_wrong_code_rva_rejected(self):
def mutate(profile):
row = next(x for x in profile['mappings'] if x['kind'] == 'code')
row['newRva'] = hex(int(row['newRva'], 16) + 16)
self.check_rejected('code-rva', mutate, 'reference evidence|Recorded bytes')
def test_wrong_zero_fill_global_rejected(self):
def mutate(profile):
row = next(x for x in profile['mappings'] if x['kind'] == 'data' and x['storage'].startswith('zero-fill'))
row['newRva'] = hex(int(row['newRva'], 16) + 4)
self.check_rejected('bss-rva', mutate, 'reference evidence')
def test_wrong_new_image_hash_rejected(self):
self.check_rejected('image-hash', lambda p: p['newImage'].update(sha256='0' * 64), 'hash mismatch')
def test_cannot_turn_evidence_into_hook_approval(self):
self.check_rejected('hook-approval', lambda p: p.update(canInstallHooks=True), 'runtime-neutral')
def test_changed_csm_literal_rejected(self):
self.check_rejected('csm-literal', lambda p: p['csmStrings'][0].update(newText='InGameX'), 'CSM state literal')
def test_changed_foundation_slot_rejected(self):
def mutate(profile):
profile['foundationSlots'][0]['newFunction'] = '0x1'
self.check_rejected('foundation-slot', mutate, 'Foundation slot changed')
def test_changed_registration_global_rejected(self):
def mutate(profile):
row = profile['componentBindings'][0]
row['newTypeIdGlobal'] = hex(int(row['newTypeIdGlobal'], 16) + 4)
self.check_rejected('registration-global', mutate, 'Registration type-ID global changed')
def test_missing_current_galaxy_address_rejected(self):
def mutate(profile):
profile['mappings'] = [row for row in profile['mappings'] if row['oldRva'] != '0x3c331e0']
self.check_rejected('missing-galaxy-rva', mutate, 'uninventoried addresses')
def test_later_published_global_requires_original_operand_binding(self):
def mutate(profile):
row = next(x for x in profile['mappings'] if x['oldRva'] == '0x5fdb275')
row['newRva'] = '0x5fdb276'
self.check_rejected('published-global', mutate, 'reference evidence')
def test_later_published_camera_getter_cannot_be_omitted(self):
def mutate(profile):
profile['mappings'] = [row for row in profile['mappings'] if row['oldRva'] != '0x56fd10']
self.check_rejected('published-getter', mutate, 'uninventoried addresses')
def test_mission_interface_requires_its_original_constructor(self):
def mutate(profile):
row = next(x for x in profile['mappings'] if x['oldRva'] == '0x5260a48')
row['newRva'] = '0x5260a48'
self.check_rejected('mission-interface', mutate, 'reference evidence')
def test_ambiguous_cg_body_cannot_replace_the_independently_bound_sender(self):
def mutate(profile):
row = next(x for x in profile['mappings'] if x['oldRva'] == '0x3433090')
# The other normalized body calls a different send helper.
row['newRva'] = '0x3440de0'
self.check_rejected('cg-other-sender', mutate, 'reference evidence')
def test_cg_sender_source_inventory_cannot_be_skipped(self):
def mutate(profile):
profile['mappings'] = [row for row in profile['mappings'] if row['oldRva'] != '0x3433090']
self.check_rejected('cg-missing-sender', mutate, 'uninventoried addresses')
if __name__ == '__main__':
unittest.main(verbosity=2)