text
stringlengths 1
93.6k
|
|---|
A background task to rename a function in the current BinaryView.
|
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):
|
"""
|
Initialize the RenameFunction task.
|
Args:
|
client (OllamaClient): The Ollama client instance.
|
bv (BinaryView): The current BinaryView instance.
|
hlil (HighLevelILFunction): The HighLevelIL representation of the function.
|
"""
|
super().__init__("Starting renaming task...", True)
|
self.hlil = hlil
|
self.bv = bv
|
self.client = client
|
def run(self):
|
"""
|
Execute the task to rename the function in the BinaryView.
|
"""
|
self.bv.begin_undo_actions()
|
function_hlil = "\n".join([str(instr) for instr in self.hlil.instructions])
|
new_name = self.client.get_function_name(function_hlil)
|
if new_name:
|
self.progress = f"Renamed function to {new_name}"
|
log_info(f"Renamed function to {new_name}")
|
self.hlil.source_function.name = new_name
|
else:
|
self.progress = f"Failed to generate a valid name"
|
log_info(f"Failed to generate a valid name")
|
self.bv.commit_undo_actions()
|
class RenameFunctionVariables(BackgroundTaskThread):
|
"""
|
A background task to rename variables in a function in the current BinaryView.
|
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):
|
"""
|
Initialize the RenameFunctionVariables task.
|
Args:
|
client (OllamaClient): The Ollama client instance.
|
bv (BinaryView): The current BinaryView instance.
|
hlil (HighLevelILFunction): The HighLevelIL representation of the function.
|
"""
|
super().__init__("Starting renaming task...", True)
|
self.hlil = hlil
|
self.bv = bv
|
self.client = client
|
def run(self):
|
"""
|
Execute the task to rename variables in the function in the BinaryView.
|
"""
|
self.bv.begin_undo_actions()
|
function_hlil = "\n".join([str(instr) for instr in self.hlil.instructions])
|
vars = []
|
for inst in self.hlil.instructions:
|
for var in inst.vars:
|
vars.append(var)
|
unique_vars = list(set(vars))
|
name_counter = {}
|
for var in unique_vars:
|
name = self.client.get_variable_name(var, function_hlil)
|
if name:
|
if name in name_counter:
|
name_counter[name] += 1
|
name = f"{name}_{name_counter[name]}"
|
else:
|
name_counter[name] = 1
|
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 RenameVariable(BackgroundTaskThread):
|
"""
|
A background task to rename a specific variable in the current BinaryView.
|
Attributes:
|
client (OllamaClient): The Ollama client instance.
|
bv (BinaryView): The current BinaryView instance.
|
inst (Instruction): The instruction containing the variable to be renamed.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.