Exemplo n.º 1
0
 def generateData(self):
     return [
         {
             "expected": F.Multiplication(F.Variable('x'), F.Constant(2)),
             "f": F.Power(F.Variable('x'), F.Constant(2)),
             "rng": [(1, 100)],
             "N": 1_000
         },
     ]
Exemplo n.º 2
0
 def parameters(self):
     """Type parameters list (read-only)"""
     count = ctypes.c_ulonglong()
     params = core.BNGetTypeParameters(self.handle, count)
     result = []
     for i in xrange(0, count.value):
         param_type = Type(core.BNNewTypeReference(params[i].type),
                           platform=self.platform,
                           confidence=params[i].typeConfidence)
         if params[i].defaultLocation:
             param_location = None
         else:
             name = params[i].name
             if (params[i].location.type
                     == VariableSourceType.RegisterVariableSourceType) and (
                         self.platform is not None):
                 name = self.platform.arch.get_reg_name(
                     params[i].location.storage)
             elif params[
                     i].location.type == VariableSourceType.StackVariableSourceType:
                 name = "arg_%x" % params[i].location.storage
             param_location = function.Variable(None,
                                                params[i].location.type,
                                                params[i].location.index,
                                                params[i].location.storage,
                                                name, param_type)
         result.append(
             FunctionParameter(param_type, params[i].name, param_location))
     core.BNFreeTypeParameterList(params, count.value)
     return result
Exemplo n.º 3
0
 def generateData(self):
     return [
         {
             "expected": F.Addition(F.Constant(1), F.Constant(1)),
             "f": F.Addition(F.Variable('x'), F.Variable('x'))
         },
         {
             "expected": F.Identity(F.Constant(1)),
             "f": F.Identity(F.Variable('x'))
         },
         {
             "expected":
             F.Multiplication(
                 F.Power(F.Variable('x'), F.Constant(2)),
                 F.Addition(
                     F.Division(
                         F.Multiplication(F.Constant(1), F.Constant(2)),
                         F.Variable('x')),
                     F.Multiplication(
                         F.Logarithm(F.Variable('x'), F.Constant(2.718)),
                         F.Constant(0)))),
             "f":
             F.Power(F.Variable('x'), F.Constant(2))
         },
     ]
Exemplo n.º 4
0
 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 function.Variable(func, out_var.type, out_var.index,
                              out_var.storage)
Exemplo n.º 5
0
 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
     if func is None:
         func_obj = None
     else:
         func_obj = func.handle
     out_var = core.BNGetParameterVariableForIncomingVariable(
         self.handle, in_buf, func_obj)
     return function.Variable(func, out_var.type, out_var.index,
                              out_var.storage)
Exemplo n.º 6
0
 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 function.Variable(func, out_var.type, out_var.index,
                              out_var.storage, name)
Exemplo n.º 7
0
 def _get_parameter_var_for_incoming_var(self, ctxt, in_var, func, result):
     try:
         if func is None:
             func_obj = None
         else:
             func_obj = function.Function(
                 binaryview.BinaryView(handle=core.BNGetFunctionData(func)),
                 core.BNNewFunctionReference(func))
         in_var_obj = function.Variable(func_obj, in_var[0].type,
                                        in_var[0].index, in_var[0].storage)
         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
         result[0].storage = out_var.storage
     except:
         log.log_error(traceback.format_exc())
         result[0].type = in_var[0].type
         result[0].index = in_var[0].index
         result[0].storage = in_var[0].storage
Exemplo n.º 8
0
def parseUnit(element):
  if isNumber(element):
    return F.Constant(float(element))
  elif isVariable(element):
    return F.Variable(name=element)
Exemplo n.º 9
0
 def get_var_for_stack_location(self, offset):
     result = core.BNGetMediumLevelILVariableForStackLocationAtInstruction(
         self.function.handle, offset, self.instr_index)
     return function.Variable(self.function.source_function, result.type,
                              result.index, result.storage)
Exemplo n.º 10
0
 def get_var_for_flag(self, flag):
     flag = self.function.arch.get_flag_index(flag)
     result = core.BNGetMediumLevelILVariableForFlagAtInstruction(
         self.function.handle, flag, self.instr_index)
     return function.Variable(self.function.source_function, result.type,
                              result.index, result.storage)
Exemplo n.º 11
0
 def get_var_for_reg(self, reg):
     reg = self.function.arch.get_reg_index(reg)
     result = core.BNGetMediumLevelILVariableForRegisterAtInstruction(
         self.function.handle, reg, self.instr_index)
     return function.Variable(self.function.source_function, result.type,
                              result.index, result.storage)