Skip to content

Commit

Permalink
cleanup, minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
patois authored Jun 4, 2020
1 parent 70e6f44 commit ab3bb43
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions abyss_filters/lvars_alias.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from abyss import abyss_filter_t
import ida_lines, ida_hexrays, ida_name
import ida_lines, ida_name, ida_hexrays as hr

VAR_ASG_VAR_SUFFIX = "_"
VAR_ASG_CALL_PREFIX = "result_"
Expand Down Expand Up @@ -50,37 +50,45 @@ def set_unique_name(var_x, new_name, lvars):
var_x.set_user_name()
return new_name

class asg_visitor_t(ida_hexrays.ctree_visitor_t):
class asg_visitor_t(hr.ctree_visitor_t):

def __init__(self, cfunc):
ida_hexrays.ctree_visitor_t.__init__(self, ida_hexrays.CV_FAST)
hr.ctree_visitor_t.__init__(self, hr.CV_FAST)
self.cfunc = cfunc
self.lvars = cfunc.get_lvars()
debug_lvars(self.lvars)

def visit_expr(self, e):
if e.op == ida_hexrays.cot_asg:
if e.op == hr.cot_asg:
# is x a var?
if e.x.op == ida_hexrays.cot_var:
if e.x.op == hr.cot_var:
# handle "x = y" types of assignments
if e.y.op == ida_hexrays.cot_var:
if e.y.op == hr.cot_var:
# get variable indexes
x_idx = e.x.v.idx
y_idx = e.y.v.idx
# get lvar_t
var_x = self.lvars[x_idx]
var_y = self.lvars[y_idx]
#debug("Found: %s (user: %s, nice: %s) = %s (user: %s, nice: %s)" % (var_x.name, var_x.has_user_name, var_x.has_nice_name, var_y.name, var_y.has_user_name, var_y.has_nice_name))
"""
debug("Found: %s (user: %s, nice: %s) = %s (user: %s, nice: %s)" % (
var_x.name,
var_x.has_user_name,
var_x.has_nice_name,
var_y.name,
var_y.has_user_name,
var_y.has_nice_name))
"""
# if x has an autogenerated name and y has a custom name
if not var_x.has_user_name and var_y.has_user_name:
# rename x
set_var_unique_name(var_x, var_y, self.lvars)
else:
debug("Skipped: %s = %s " % (var_x.name, var_y.name))
# handle "x = y()" types of assignments
elif e.y.op == ida_hexrays.cot_call:
elif e.y.op == hr.cot_call and e.y.x.op == hr.cot_obj:
# get name of called function
func_name = ida_lines.tag_remove(e.y.x.print1(None))
func_name = ida_name.get_ea_name(e.y.x.obj_ea)
# get var index and lvar_t
x_idx = e.x.v.idx
var_x = self.lvars[x_idx]
Expand All @@ -98,7 +106,7 @@ class lvars_alias_t(abyss_filter_t):
examples:
'v11 = buf' becomes 'buf_ = buf'
'v69 = strstr(a,b)' becomes 'result_strstr = strstr(a, b)'"""
'v69 = strstr(a, b)' becomes 'result_strstr = strstr(a, b)'"""

def __init__(self):
abyss_filter_t.__init__(self)
Expand Down

0 comments on commit ab3bb43

Please sign in to comment.