Skip to content

Commit 00ab48e

Browse files
committed
Change variable names to allow for modularity.
Given the addition of renaming expressions, it didn't make sense to just have one prompt. This has been changed to be more meaningful.
1 parent a154d46 commit 00ab48e

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

src/agent.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from binaryninja.function import Function
1010
from binaryninja.lowlevelil import LowLevelILFunction
1111
from binaryninja.mediumlevelil import MediumLevelILFunction
12-
from binaryninja.highlevelil import HighLevelILFunction
12+
from binaryninja.highlevelil import HighLevelILFunction, HighLevelILInstruction
1313
from binaryninja.settings import Settings
1414
from binaryninja import log, BinaryView
1515

@@ -19,11 +19,16 @@
1919

2020
class Agent:
2121

22-
question: str = '''
22+
function_question: str = '''
2323
This is a function that was decompiled with Binary Ninja.
2424
It is in IL_FORM. What does this function do?
2525
'''
2626

27+
rename_variable_question: str = '''
28+
In one word, what should the variable name be for the variable that is
29+
assigned to the result of the C expression:\n
30+
'''
31+
2732
# A mapping of IL forms to their names.
2833
il_name: dict[type, str] = {
2934
LowLevelILFunction: 'Low Level Intermediate Language',
@@ -140,18 +145,25 @@ def generate_query(self, function: Union[Function,
140145
LowLevelILFunction,
141146
MediumLevelILFunction,
142147
HighLevelILFunction]) -> str:
143-
'''Generates a query string given a BNIL function. Reads the file
144-
prompt.txt and replaces the IL form with the name of the IL form.
148+
'''Generates a query string given a BNIL function. Returns the query as
149+
a string.
145150
'''
146-
prompt: str = self.question
151+
prompt: str = self.function_question
147152
# Read the prompt from the text file.
148-
prompt = self.question.replace('IL_FORM', self.il_name[type(function)])
153+
prompt = prompt.replace('IL_FORM', self.il_name[type(function)])
149154
# Add some new lines. Maybe not necessary.
150155
prompt += '\n\n'
151156
# Add the instructions to the prompt.
152157
prompt += '\n'.join(self.instruction_list(function))
153158
return prompt
154159

160+
def generate_rename_expression_query(
161+
instruction: HighLevelILInstruction) -> str:
162+
'''Generates a query string given a BNIL instruction. Returns the query
163+
as a string.
164+
'''
165+
pass
166+
155167
def send_query(self, query: str) -> None:
156168
'''Sends a query to the engine and prints the response.'''
157169
query = Query(query_string=query,

src/entry.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@ def check_function(bv: BinaryView, func: Function) -> bool:
1414
agent.send_query(query)
1515

1616
def rename_expression(bv: BinaryView, instruction: HighLevelILInstruction) -> bool:
17-
pass
17+
agent: Agent = Agent(
18+
bv=bv,
19+
path_to_api_key=API_KEY_PATH
20+
)
21+
query: str = agent.generate_rename_expression_query(instruction)

0 commit comments

Comments
 (0)