Skip to content

armgit / kong

Public Imported from GitHub
0

The world's first agentic reverse engineer.

feat: add BATCH_SYSTEM_PROMPT and BATCH_OUTPUT_SCHEMA for multi-function analysis

Amruthea229349ae84
diff --git a/kong/agent/prompts.py b/kong/agent/prompts.py
index 8a06fe4..e5505ac 100644
--- a/kong/agent/prompts.py
+++ b/kong/agent/prompts.py
@@ -87,3 +87,65 @@ Confidence guidelines:
struct_proposals: Only include when you see a pointer parameter accessed at \
multiple fixed offsets. Omit entirely if there are no struct patterns."""
+
+
+BATCH_SYSTEM_PROMPT = """\
+You are an expert reverse engineer analyzing stripped binaries. You are given \
+multiple decompiled C functions from Ghidra and must determine what each function does.
+
+Your analysis must be precise:
+- Name functions based on what they actually do, not what they might do
+- Use standard naming conventions (snake_case for C, camelCase only if the binary is C++)
+- If you cannot determine a function's purpose, say so — do not guess
+- Confidence reflects how certain you are, not how important the function is
+
+Type recovery:
+- When a parameter is a pointer and the function accesses it at multiple fixed \
+offsets (e.g. *(param + 0x10), param[3], param->field_0x8), propose a struct layout
+- Only propose structs when there are at least 2 distinct field accesses at \
+concrete offsets — do not propose structs for single-field or ambiguous accesses
+- Name struct fields based on how they are used in the function
+
+You respond only with a JSON array, one element per function. No prose before or after."""
+
+
+BATCH_OUTPUT_SCHEMA = """\
+Respond with exactly one JSON array, one object per function:
+```json
+[
+ {
+ "address": "0x00401000",
+ "name": "descriptive_function_name",
+ "signature": "return_type name(param_type param_name, ...)",
+ "confidence": <0-100>,
+ "classification": "<category>",
+ "comments": "Brief description of what the function does",
+ "reasoning": "Why you chose this name and classification",
+ "variables": [{"old_name": "local_10", "new_name": "buffer"}],
+ "struct_proposals": [
+ {
+ "name": "struct_name",
+ "total_size": 32,
+ "fields": [
+ {"name": "field_name", "data_type": "int", "offset": 0, "size": 4},
+ {"name": "another_field", "data_type": "char *", "offset": 8, "size": 8}
+ ],
+ "used_by_param": "param_1"
+ }
+ ]
+ }
+]
+```
+
+Classification must be one of: crypto, networking, io, memory, string, math, \
+init, cleanup, handler, parser, utility, unknown.
+
+Confidence guidelines:
+- 90-100: You recognize this exact algorithm or pattern (e.g., RC4, quicksort)
+- 70-89: Strong structural evidence for the name (clear string refs, API calls)
+- 50-69: Reasonable inference from context but multiple interpretations possible
+- 30-49: Educated guess based on limited evidence
+- 0-29: Very uncertain, minimal evidence
+
+struct_proposals: Only include when you see a pointer parameter accessed at \
+multiple fixed offsets. Omit entirely if there are no struct patterns."""
diff --git a/tests/test_agent_prompts.py b/tests/test_agent_prompts.py
index 335a12e..c2e8d51 100644
--- a/tests/test_agent_prompts.py
+++ b/tests/test_agent_prompts.py
@@ -2,7 +2,7 @@
from __future__ import annotations
-from kong.agent.prompts import OUTPUT_SCHEMA, SYSTEM_PROMPT
+from kong.agent.prompts import BATCH_OUTPUT_SCHEMA, BATCH_SYSTEM_PROMPT, OUTPUT_SCHEMA, SYSTEM_PROMPT
class TestPrompts:
@@ -23,3 +23,12 @@ class TestPrompts:
def test_output_schema_has_confidence_guidelines(self):
assert "90-100" in OUTPUT_SCHEMA
assert "0-29" in OUTPUT_SCHEMA
+
+
+class TestBatchPrompts:
+ def test_batch_output_schema_is_json_array(self) -> None:
+ assert '"address"' in BATCH_OUTPUT_SCHEMA
+ assert "[" in BATCH_OUTPUT_SCHEMA
+
+ def test_batch_system_prompt_mentions_multiple(self) -> None:
+ assert "multiple" in BATCH_SYSTEM_PROMPT.lower() or "batch" in BATCH_SYSTEM_PROMPT.lower()