Skip to content

Commit 5b19289

Browse files
committed
Working query.
- TODO: send query to agent.
1 parent 176445a commit 5b19289

4 files changed

Lines changed: 9 additions & 6 deletions

File tree

__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from binaryninja import PluginCommand
22
from . src.entry import check_function
33

4-
PluginCommand.register_for_address("What Does this Function Do?",
4+
PluginCommand.register_for_high_level_il_function("What Does this Function Do?",
55
"Checks OpenAI to see what this function does." \
66
"Requires an internet connection and an API key "
77
"saved under the environment variable "

src/agent.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515

1616
class Agent:
1717

18+
question: str = '''
19+
This is a function that was decompiled with Binary Ninja.
20+
It is in Binary Ninja's IL_FORM. What does this function do?
21+
'''
22+
1823
# The maximum number of tokens that can be submitted to the engine.
1924
# See: https://beta.openai.com/docs/models/codex
2025
codex_limits: dict[str, int] = {
@@ -82,11 +87,9 @@ def generate_query(self, function: LowLevelILFunction |
8287
'''Generates a query string given a BNIL function. Reads the file
8388
prompt.txt and replaces the IL form with the name of the IL form.
8489
'''
85-
prompt: str = ''
90+
prompt: str = self.question
8691
# Read the prompt from the text file.
87-
with open('prompt.txt', 'r') as prompt_file:
88-
prompt = prompt_file.read()
89-
prompt.replace('\{IL FORM\}', self.il_name[type(function)])
92+
prompt = self.question.replace('IL_FORM', self.il_name[type(function)])
9093
# Add some new lines. Maybe not necessary.
9194
prompt += '\n\n'
9295
# Add the instructions to the prompt.

src/entry.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33

44
def check_function(bv: BinaryView, func: Function) -> bool:
55
agent = Agent(function=func, engine='code-davinci-002')
6+
print(agent.generate_query(func))

src/prompt.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
This is a function that was decompiled with Binary Ninja. It is in Binary Ninja's {IL FORM}. What does this function do?

0 commit comments

Comments
 (0)