From 320df57155120147c23e815b379619ab6843e352 Mon Sep 17 00:00:00 2001 From: r0ny123 <49360849+r0ny123@users.noreply.github.com> Date: Mon, 16 Nov 2026 17:36:20 +0000 Subject: [PATCH] apply ApiScout DB aslr_offset in WinApiResolver DBs built with ASLR offsets (apiscout's Windows 10 1803 x64 DB) were mapped to the file ImageBase of each DLL, where most 64-bit system DLLs collide at 0x180000000. Apply the offset as ApiScout does; DBs without one load as before. --- CHANGELOG.md | 6 +++ .../common/labelprovider/WinApiResolver.py | 2 +- tests/testPeSymbolProvider.py | 39 +++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28fd4190..c9b85135 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -79,6 +79,12 @@ past roughly six lines it belongs in the PR the entry links. ### Removed ### Fixed +- **(labels)** Apply the per-DLL `aslr_offset` of an ApiScout DB in `WinApiResolver`, as ApiScout does. The + offset was ignored, so a DB built with ASLR offsets mapped every rebased DLL to its file ImageBase, where most + 64-bit system DLLs collide at `0x180000000`. *Measured on apiscout's `win10_prof_1803_example.json` (`668c981`):* + 5,706 of 86,703 resolver addresses matched ApiScout's before, all 97,516 after. Cost: none, DBs without offsets + (the bundled Win7 and XP ones) load bit-identical. *Not bundled; the behaviour is covered by + `test_win_api_resolver_applies_aslr_offsets_of_the_database`.* ### Security diff --git a/src/smda/common/labelprovider/WinApiResolver.py b/src/smda/common/labelprovider/WinApiResolver.py index 6f1131d5..1f3bb5ae 100644 --- a/src/smda/common/labelprovider/WinApiResolver.py +++ b/src/smda/common/labelprovider/WinApiResolver.py @@ -100,7 +100,7 @@ def _loadDbFile(self, os_name, db_filepath): dll = api_db["dlls"][dll_entry] dll_name = "_".join(dll_entry.split("_")[2:]) has_64bit |= dll["bitness"] == 64 - base_address = dll["base_address"] + base_address = dll["base_address"] - dll.get("aslr_offset", 0) for export in dll["exports"]: num_apis_loaded += 1 api_name = str(export["name"]) diff --git a/tests/testPeSymbolProvider.py b/tests/testPeSymbolProvider.py index 37b2ff57..5751b962 100644 --- a/tests/testPeSymbolProvider.py +++ b/tests/testPeSymbolProvider.py @@ -171,6 +171,45 @@ def test_win_api_resolver_defers_parsing_uncached_databases(self): self.assertEqual(resolver._os_name, "testos") self.assertIsNone(resolver._deferred_dbs) + def test_win_api_resolver_applies_aslr_offsets_of_the_database(self): + api_db = { + "os_name": "testos", + "aslr_offsets": True, + "dlls": { + "64_10.0.17134.1_first.dll_0x180000000": { + "bitness": 64, + "base_address": 0x180000000, + "aslr_offset": 0x180000000 - 0x7FF8D5930000, + "exports": [{"name": "FirstApi", "address": 0x1000, "ordinal": 1}], + }, + "64_10.0.17134.1_second.dll_0x180000000": { + "bitness": 64, + "base_address": 0x180000000, + "aslr_offset": 0x180000000 - 0x7FF8D7520000, + "exports": [{"name": "SecondApi", "address": 0x1000, "ordinal": 1}], + }, + "64_10.0.17134.1_unrebased.dll_0x10000000": { + "bitness": 64, + "base_address": 0x10000000, + "aslr_offset": 0, + "exports": [{"name": "UnrebasedApi", "address": 0x1000, "ordinal": 1}], + }, + }, + } + with tempfile.TemporaryDirectory() as tmp_dir: + db_path = os.path.join(tmp_dir, "apiscout_aslr.json") + with open(db_path, "w", encoding="utf-8") as f_json: + json.dump(api_db, f_json) + config = SimpleNamespace(API_COLLECTION_FILES={"testos": db_path}) + with mock.patch.object(WinApiResolver, "_db_cache", {}): + resolver = WinApiResolver(config) + resolver.update(SimpleNamespace(is_buffer=True)) + + self.assertEqual(resolver.getApi(0, 0x7FF8D5931000), ("first.dll_0x180000000", "FirstApi")) + self.assertEqual(resolver.getApi(0, 0x7FF8D7521000), ("second.dll_0x180000000", "SecondApi")) + self.assertEqual(resolver.getApi(0, 0x10001000), ("unrebased.dll_0x10000000", "UnrebasedApi")) + self.assertEqual(resolver.getApi(0, 0x180001000), (None, None)) + def test_win_api_resolver_keeps_an_explicit_os_name_across_deferred_loading(self): api_db = { "os_name": "present",