From 6de4900db74a341fddfda46f7cb4342fdc31f8e0 Mon Sep 17 00:00:00 2001 From: Peter LaFosse Date: Wed, 23 Jun 2021 09:31:22 -0400 Subject: Refactor Variable class The Variable class is now broken into 3 separate classes with helper methods to convert between them. CoreVariable is implemented as a frozen dataclass and is analogous to BNVariable VariableNameAndType is analogous to BNVariableNameAndType Bothe the above are passive objects and can not be changed directly The new and improved Variable object is now an active object which can be operated on directly and changes will take effect immediately --- python/callingconvention.py | 60 ++++++++++++++++----------------------------- 1 file changed, 21 insertions(+), 39 deletions(-) (limited to 'python/callingconvention.py') diff --git a/python/callingconvention.py b/python/callingconvention.py index 096a6b73..44573503 100644 --- a/python/callingconvention.py +++ b/python/callingconvention.py @@ -372,7 +372,7 @@ class CallingConvention(object): func_obj = None else: func_obj = function.Function(handle = core.BNNewFunctionReference(func)) - in_var_obj = variable.Variable(func_obj, in_var[0].type, in_var[0].index, in_var[0].storage) + in_var_obj = variable.CoreVariable.from_BNVariable(in_var[0]) out_var = self.perform_get_incoming_var_for_parameter_var(in_var_obj, func_obj) result[0].type = out_var.source_type result[0].index = out_var.index @@ -389,7 +389,7 @@ class CallingConvention(object): func_obj = None else: func_obj = function.Function(handle = core.BNNewFunctionReference(func)) - in_var_obj = variable.Variable(func_obj, in_var[0].type, in_var[0].index, in_var[0].storage) + in_var_obj = variable.CoreVariable.from_BNVariable(in_var[0]) out_var = self.perform_get_parameter_var_for_incoming_var(in_var_obj, func_obj) result[0].type = out_var.source_type result[0].index = out_var.index @@ -408,28 +408,19 @@ class CallingConvention(object): return variable.RegisterValue() def perform_get_incoming_flag_value(self, reg, func): - return variable.RegisterValue() + return variable.Undetermined() + + def perform_get_incoming_var_for_parameter_var(self, in_var:'variable.CoreVariable', + func:Optional['function.Function']=None): + out_var = core.BNGetDefaultIncomingVariableForParameterVariable(self.handle, in_var.to_BNVariable()) + return variable.CoreVariable.from_BNVariable(out_var) - def perform_get_incoming_var_for_parameter_var(self, in_var, func): - in_buf = core.BNVariable() - in_buf.type = in_var.source_type - in_buf.index = in_var.index - in_buf.storage = in_var.storage - out_var = core.BNGetDefaultIncomingVariableForParameterVariable(self.handle, in_buf) - name = None - if (func is not None) and (out_var.type == VariableSourceType.RegisterVariableSourceType): - name = func.arch.get_reg_name(out_var.storage) - return variable.Variable(func, out_var.type, out_var.index, out_var.storage, name) - - def perform_get_parameter_var_for_incoming_var(self, in_var, func): - in_buf = core.BNVariable() - in_buf.type = in_var.source_type - in_buf.index = in_var.index - in_buf.storage = in_var.storage - out_var = core.BNGetDefaultParameterVariableForIncomingVariable(self.handle, in_buf) - return variable.Variable(func, out_var.type, out_var.index, out_var.storage) - - def with_confidence(self, confidence): + def perform_get_parameter_var_for_incoming_var(self, in_var:'variable.CoreVariable', + func:Optional['function.Function']=None): + out_var = core.BNGetDefaultParameterVariableForIncomingVariable(self.handle, in_var.to_BNVariable()) + return variable.CoreVariable.from_BNVariable(out_var) + + def with_confidence(self, confidence:int): return CallingConvention(self.arch, handle = core.BNNewCallingConventionReference(self.handle), confidence = confidence) @@ -447,32 +438,23 @@ class CallingConvention(object): func_handle = func.handle return variable.RegisterValue(self.arch, core.BNGetIncomingFlagValue(self.handle, reg_num, func_handle)) - def get_incoming_var_for_parameter_var(self, in_var, func): - in_buf = core.BNVariable() - in_buf.type = in_var.source_type - in_buf.index = in_var.index - in_buf.storage = in_var.storage + def get_incoming_var_for_parameter_var(self, in_var:'variable.CoreVariable', func:'function.Function'): + in_buf = in_var.to_BNVariable() if func is None: func_obj = None else: func_obj = func.handle out_var = core.BNGetIncomingVariableForParameterVariable(self.handle, in_buf, func_obj) - name = None - if (func is not None) and (out_var.type == VariableSourceType.RegisterVariableSourceType): - name = func.arch.get_reg_name(out_var.storage) - return variable.Variable(func, out_var.type, out_var.index, out_var.storage, name) - - def get_parameter_var_for_incoming_var(self, in_var, func): - in_buf = core.BNVariable() - in_buf.type = in_var.source_type - in_buf.index = in_var.index - in_buf.storage = in_var.storage + return variable.Variable.from_BNVariable(func, out_var) + + def get_parameter_var_for_incoming_var(self, in_var:'variable.CoreVariable', func:'function.Function'): + in_buf = in_var.to_BNVariable() if func is None: func_obj = None else: func_obj = func.handle out_var = core.BNGetParameterVariableForIncomingVariable(self.handle, in_buf, func_obj) - return variable.Variable(func, out_var.type, out_var.index, out_var.storage) + return variable.Variable.from_BNVariable(func, out_var) @property def arch(self): -- cgit v1.3.1