Skip to content

armgit / kong

Public Imported from GitHub
0

The world's first agentic reverse engineer.

feat: add decompilation cache to avoid redundant Ghidra calls

Amruthee85f2c29f67
diff --git a/kong/agent/supervisor.py b/kong/agent/supervisor.py
index c45df49..e998155 100644
--- a/kong/agent/supervisor.py
+++ b/kong/agent/supervisor.py
@@ -67,6 +67,12 @@ class Supervisor:
self._synthesis_result: SynthesisResult | None = None
self._listeners: list[EventCallback] = []
self._paused: bool = False
+ self._decompilation_cache: dict[int, str] = {}
+
+ def _get_decompilation(self, addr: int) -> str:
+ if addr not in self._decompilation_cache:
+ self._decompilation_cache[addr] = self.client.get_decompilation(addr)
+ return self._decompilation_cache[addr]
def on_event(self, callback: EventCallback) -> None:
"""Register an event listener."""
@@ -239,7 +245,7 @@ class Supervisor:
completed_count += 1
continue
- decompilation = self.client.get_decompilation(func.address)
+ decompilation = self._get_decompilation(func.address)
techniques = classify_obfuscation(decompilation)
if techniques:
@@ -635,7 +641,7 @@ class Supervisor:
for addr, result in self.results.items():
if result.skipped or result.error:
continue
- decomp = self.client.get_decompilation(addr)
+ decomp = self._get_decompilation(addr)
if decomp:
decompilations[addr] = normalize(decomp)
@@ -722,7 +728,7 @@ class Supervisor:
]
decompilations: dict[int, str] = {}
for addr in exportable_addrs:
- decomp = self.client.get_decompilation(addr)
+ decomp = self._get_decompilation(addr)
if decomp:
decompilations[addr] = normalize(decomp)
diff --git a/tests/test_agent_supervisor.py b/tests/test_agent_supervisor.py
index dfdb981..37a30e5 100644
--- a/tests/test_agent_supervisor.py
+++ b/tests/test_agent_supervisor.py
@@ -358,3 +358,26 @@ class TestSupervisorSynthesis:
]
assert len(synthesis_completes) == 1
assert "skipped" in synthesis_completes[0].message.lower()
+
+
+class TestDecompilationCache:
+ def test_cached_decompilation_avoids_redundant_ghidra_calls(self, tmp_path):
+ client = _make_client(functions=[_func(0x1000, "FUN_1000")])
+ config = KongConfig(output=OutputConfig(directory=tmp_path / "out"))
+ sup = Supervisor(client, config)
+ sup._decompilation_cache[0x1000] = "cached code"
+
+ result = sup._get_decompilation(0x1000)
+ assert result == "cached code"
+ client.get_decompilation.assert_not_called()
+
+ def test_uncached_decompilation_calls_ghidra_and_caches(self, tmp_path):
+ client = _make_client(functions=[_func(0x1000, "FUN_1000")])
+ client.get_decompilation.return_value = "void foo(void) {}"
+ config = KongConfig(output=OutputConfig(directory=tmp_path / "out"))
+ sup = Supervisor(client, config)
+
+ result = sup._get_decompilation(0x1000)
+ assert result == "void foo(void) {}"
+ assert 0x1000 in sup._decompilation_cache
+ client.get_decompilation.assert_called_once_with(0x1000)