示例#1
0
 def ast(self,
         astree: AbstractSyntaxTree,
         iaddr: str,
         bytestring: str,
         xdata: InstrXData) -> List[ASTInstruction]:
     if xdata.has_call_target():
         calltarget = xdata.call_target(self.ixd)
         tgtname = calltarget.name
         tgtxpr = self.target_expr_ast(astree, xdata)
         (lhs, assigns) = self.lhs_ast(astree, iaddr, xdata)
         args = self.arguments(xdata)
         argxprs: List[ASTExpr] = []
         for arg in args:
             if XU.is_struct_field_address(arg, astree):
                 addr = XU.xxpr_to_struct_field_address_expr(arg, astree)
             elif arg.is_string_reference:
                 xpr = XU.xxpr_to_ast_expr(arg, astree)
                 cstr = arg.constant.string_reference()
                 saddr = hex(arg.constant.value)
                 argxprs.append(astree.mk_string_constant(xpr, cstr, saddr))
             elif arg.is_argument_value:
                 argindex = arg.argument_index()
                 funarg = astree.function_argument(argindex)
                 if funarg:
                     astxpr = astree.mk_register_variable_expr(
                         funarg.name, vtype=funarg.typ, parameter=argindex)
                     argxprs.append(astxpr)
                 else:
                     astxpr = XU.xxpr_to_ast_expr(arg, astree)
                     argxprs.append(astxpr)
             else:
                 astxpr = XU.xxpr_to_ast_expr(arg, astree)
                 argxprs.append(astxpr)
         if lhs.is_ignored:
             call: ASTInstruction = astree.mk_call(lhs, tgtxpr, argxprs)
             astree.add_instruction_span(call.id, iaddr, bytestring)
             return [call]
         else:
             call = cast(ASTInstruction, astree.mk_call(lhs, tgtxpr, argxprs))
             astree.add_instruction_span(call.id, iaddr, bytestring)
             for assign in assigns:
                 astree.add_instruction_span(assign.id, iaddr, bytestring)
             return [call] + assigns
     else:
         return []
    def ast_lvalue(
        self, astree: AbstractSyntaxTree
    ) -> Tuple[AST.ASTLval, List[AST.ASTInstruction],
               List[AST.ASTInstruction]]:
        offset = self.memory_offset.ast_rvalue(astree)
        if not self.is_add:
            offset = astree.mk_unary_op("minus", offset)
        xreg = astree.mk_register_variable_expr(self.register)
        xindex = astree.mk_binary_op("plus", xreg, offset)

        if self.is_write_back:
            reglv = astree.mk_variable_lval(self.register)
            assign = astree.mk_assign(reglv, xindex)
            if self.is_index:
                memexp = astree.mk_memref_lval(xindex)
                return (memexp, [], [assign])
            else:
                memexp = astree.mk_memref_lval(xreg)
                return (memexp, [], [assign])
        else:
            memexp = astree.mk_memref_lval(xindex)
            return (memexp, [], [])
 def ast_rvalue(self, astree: AbstractSyntaxTree) -> AST.ASTExpr:
     return astree.mk_register_variable_expr(self.register)
 def ast_rvalue(
     self, astree: AbstractSyntaxTree
 ) -> Tuple[AST.ASTExpr, List[AST.ASTInstruction],
            List[AST.ASTInstruction]]:
     return (astree.mk_register_variable_expr(self.register), [], [])