Skip to content

Commit

Permalink
fix bug, minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
patois authored Jun 6, 2020
1 parent 3636008 commit 8689439
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
3 changes: 3 additions & 0 deletions abyss.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ida_kernwin as kw
import ida_hexrays as hr
import ida_diskio, ida_idaapi
from ida_auto import auto_wait
import os, sys

__author__ = "https://github.com/patois"
Expand Down Expand Up @@ -135,13 +136,15 @@ def init(self):

def run(self, arg):
load_filters(reload=True)
return

def term(self):
try:
self.ui_hooks.unhook()
self.hr_hooks.unhook()
except:
pass
return

def PLUGIN_ENTRY():
return abyss_plugin_t()
19 changes: 10 additions & 9 deletions abyss_filters/lvars_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
import ida_lines, ida_name, ida_hexrays as hr

VAR_ASG_VAR_SUFFIX = "_"
VAR_ASG_CALL_PREFIX = "result_"
VAR_ASG_CALL_PREFIX = "res_"

# mapping a type string representation to a deterministic name to use
VAR_ASG_CALL_DETERMINISTIC = {
"NTSTATUS": "status",
}

fDebug = False
def debug(msg):
def debug_print(msg):
if fDebug:
print(msg)
print("%s" % msg)
return

def debug_lvars(lvars):
Expand All @@ -27,7 +27,7 @@ def set_var_unique_name(var_x, var_y, lvars):
old_name = var_x.name
new_name = var_y.name + VAR_ASG_VAR_SUFFIX
new_name = set_unique_name(var_x, new_name, lvars)
debug("Renamed: %s (%s) = %s " % (old_name, new_name, var_y.name))
debug_print("Renamed: %s (%s) = %s " % (old_name, new_name, var_y.name))
return

def set_func_unique_name(var_x, func_name, lvars):
Expand All @@ -38,7 +38,7 @@ def set_func_unique_name(var_x, func_name, lvars):
else:
new_name = VAR_ASG_CALL_PREFIX + func_name
new_name = set_unique_name(var_x, new_name, lvars)
debug("Renamed: %s (%s) = %s(...) " % (old_name, new_name, func_name))
debug_print("Renamed: %s (%s) = %s(...) " % (old_name, new_name, func_name))
return

def set_unique_name(var_x, new_name, lvars):
Expand Down Expand Up @@ -76,7 +76,7 @@ def visit_expr(self, e):
var_x = self.lvars[x_idx]
var_y = self.lvars[y_idx]
"""
debug("Found: %s (user: %s, nice: %s) = %s (user: %s, nice: %s)" % (
debug_print("Found: %s (user: %s, nice: %s) = %s (user: %s, nice: %s)" % (
var_x.name,
var_x.has_user_name,
var_x.has_nice_name,
Expand All @@ -89,7 +89,7 @@ def visit_expr(self, e):
# rename x
set_var_unique_name(var_x, var_y, self.lvars)
else:
debug("Skipped: %s = %s " % (var_x.name, var_y.name))
debug_print("Skipped: %s = %s " % (var_x.name, var_y.name))
# handle "x = y()" types of assignments
elif e.y.op in [hr.cot_call, hr.cot_cast]:
if e.y.op == hr.cot_call:
Expand All @@ -100,15 +100,16 @@ def visit_expr(self, e):
tmp_y = None
if tmp_y and tmp_y.x.op == hr.cot_obj:
# get name of called function
func_name = ida_name.get_ea_name(tmp_y.x.obj_ea)
func_name = ida_name.get_ea_name(tmp_y.x.obj_ea,
ida_name.GN_VISIBLE | ida_name.GN_LOCAL)
# get var index and lvar_t
x_idx = e.x.v.idx
var_x = self.lvars[x_idx]
if not var_x.has_user_name:
# rename x
set_func_unique_name(var_x, func_name, self.lvars)
else:
debug("Skipped: %s = %s(...) " % (var_x.name, func_name))
debug_print("Skipped: %s = %s(...) " % (var_x.name, func_name))
return 0


Expand Down

0 comments on commit 8689439

Please sign in to comment.