text
stringlengths 1
93.6k
|
|---|
"""
|
def __init__(self, client, bv, inst):
|
"""
|
Initialize the RenameVariable task.
|
Args:
|
client (OllamaClient): The Ollama client instance.
|
bv (BinaryView): The current BinaryView instance.
|
inst (Instruction): The instruction containing the variable to be renamed.
|
"""
|
super().__init__("Starting renaming task...", True)
|
self.inst = inst
|
self.bv = bv
|
self.client = client
|
def run(self):
|
"""
|
Execute the task to rename the variable in the BinaryView.
|
"""
|
self.bv.begin_undo_actions()
|
func = self.bv.get_functions_containing(self.inst.address)[0]
|
function_hlil = "\n".join([str(instr) for instr in func.hlil.instructions])
|
unique_vars = list(set(self.inst.vars))
|
for var in unique_vars:
|
name = self.client.get_variable_name(var, function_hlil)
|
if name:
|
self.progress = f'Renamed {var.name} to {name}'
|
log_info(f'Renamed {var.name} to {name}')
|
var.name = name
|
else:
|
self.progress = f"Failed to generate a valid name for {var.name}"
|
log_info(f"Failed to generate a valid name for {var.name}")
|
self.bv.commit_undo_actions()
|
class ExplainFunction(BackgroundTaskThread):
|
"""
|
A background task to get an explanation of a function or code block.
|
Attributes:
|
client (OllamaClient): The Ollama client instance.
|
bv (BinaryView): The current BinaryView instance.
|
hlil (HighLevelILFunction): The HighLevelIL representation of the function.
|
"""
|
def __init__(self, client, bv, hlil):
|
super().__init__("Starting explanation task...", True)
|
self.hlil = hlil
|
self.bv = bv
|
self.client = client
|
def run(self):
|
"""
|
Execute the task to explain the function in the BinaryView.
|
"""
|
function_hlil = "\n".join([str(instr) for instr in self.hlil.instructions])
|
explanation = self.client.get_function_explanation(function_hlil)
|
if explanation:
|
self.progress = "Function explanation generated"
|
else:
|
self.progress = "Failed to generate function explanation"
|
class AnalyzeVulnerabilities(BackgroundTaskThread):
|
"""
|
A background task to analyze a function or code block for vulnerabilities.
|
Attributes:
|
client (OllamaClient): The Ollama client instance.
|
bv (BinaryView): The current BinaryView instance.
|
hlil (HighLevelILFunction): The HighLevelIL representation of the function.
|
"""
|
def __init__(self, client, bv, hlil):
|
super().__init__("Starting vulnerability analysis...", True)
|
self.hlil = hlil
|
self.bv = bv
|
self.client = client
|
def run(self):
|
"""
|
Execute the task to analyze the function for vulnerabilities.
|
"""
|
function_hlil = "\n".join([str(instr) for instr in self.hlil.instructions])
|
analysis = self.client.analyze_vulnerabilities(function_hlil)
|
if analysis:
|
self.progress = "Vulnerability analysis completed"
|
else:
|
self.progress = "Failed to generate vulnerability analysis"
|
# <FILESEP>
|
#!/usr/bin/env python3
|
import sys
|
import logging
|
class Functions:
|
# Exception safe max and min (attention, not working with dictionaries)
|
# another option: res = [i for i in test_list if i is not None]
|
def _max(self, x):
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.