Esempio n. 1
0
def assign_colors(ctx, ast):
    if isinstance(ast, Ast_Branch):
        for n in ast.nodes:
            if isinstance(n, list):
                if is_uncond_jump(n[0]) and n[0].operands[0].type == ARM_OP_IMM and \
                        n[0].address in ctx.gph.link_out:
                    nxt = ctx.gph.link_out[n[0].address][BRANCH_NEXT]
                    pick_color(nxt)
            else:  # ast
                assign_colors(ctx, n)

    elif isinstance(ast, Ast_IfGoto) or isinstance(ast, Ast_Goto):
        pick_color(ast.addr_jump)

    elif isinstance(ast, Ast_Ifelse):
        assign_colors(ctx, ast.br_next_jump)
        assign_colors(ctx, ast.br_next)

    elif isinstance(ast, Ast_Loop):
        assign_colors(ctx, ast.branch)

    elif isinstance(ast, Ast_If_cond):
        assign_colors(ctx, ast.br)
Esempio n. 2
0
def assign_colors(ctx, ast):
    if isinstance(ast, Ast_Branch):
        for n in ast.nodes:
            if isinstance(n, list):
                if is_uncond_jump(n[0]) and n[0].operands[0].type == ARM_OP_IMM and \
                        n[0].address in ctx.gph.link_out:
                    nxt = ctx.gph.link_out[n[0].address][BRANCH_NEXT]
                    pick_color(nxt)
            else: # ast
                assign_colors(ctx, n)

    elif isinstance(ast, Ast_IfGoto) or isinstance(ast, Ast_Goto):
        pick_color(ast.addr_jump)

    elif isinstance(ast, Ast_Ifelse):
        assign_colors(ctx, ast.br_next_jump)
        assign_colors(ctx, ast.br_next)

    elif isinstance(ast, Ast_Loop):
        assign_colors(ctx, ast.branch)

    elif isinstance(ast, Ast_If_cond):
        assign_colors(ctx, ast.br)
Esempio n. 3
0
    def _sub_asm_inst(self, i, tab=0, prefix=""):
        if is_ret(i):
            self._retcall(self.get_inst_str(i))
            return False

        if is_call(i):
            self._retcall(i.mnemonic)
            self._add(" ")

            if self.gctx.sectionsname:
                op = i.operands[0]
                if op.type == ARM_OP_IMM:
                    s = self._binary.get_section(op.value.imm)
                    if s is not None:
                        self._add("(")
                        self._section(s.name)
                        self._add(") ")

            self._operand(i, 0, hexa=True, force_dont_print_data=True)
            return False

        # Here we can have conditional jump with the option --dump
        if is_jump(i):
            if len(i.operands) == 0:
                self._add(i.mnemonic)
                return False

            self._add(i.mnemonic + " ")

            if i.operands[0].type != ARM_OP_IMM:
                self._operand(i, 0, force_dont_print_data=True)
                self.inst_end_here()
                if is_uncond_jump(i) and not self.ctx.is_dump \
                        and not i.address in self._dis.jmptables:
                    self._add(" ")
                    self._comment("# STOPPED")
                return False

            self._operand(i, 0, hexa=True, force_dont_print_data=True)
            return False


        modified = False

        if self.gctx.capstone_string == 0:
            if i.id in LDR_CHECK:
                self._operand(i, 0)
                self._add(" = (")
                self._type(LDR_TYPE[i.id])
                self._add(") ")
                self._operand(i, 1)
                modified = True

            elif i.id in STR_CHECK:
                self._operand(i, 1)
                self._add(" = (")
                self._type(STR_TYPE[i.id])
                self._add(") ")
                self._operand(i, 0)
                modified = True

            elif i.id in INST_CHECK:
                self._operand(i, 0)

                if i.id == ARM_INS_CMP:
                    self._add(" " + inst_symbol(i) + " ")
                    self._operand(i, 1)

                else:
                    self._add(" = ")
                    self._operand(i, 1)
                    if len(i.operands) == 3:
                        self._add(" " + inst_symbol(i) + " ")
                        self._operand(i, 2)

                modified = True

        if not modified:
            self._add("%s " % i.mnemonic)
            if len(i.operands) > 0:
                modified = self._operand(i, 0)
                k = 1
                while k < len(i.operands):
                    self._add(", ")
                    modified |= self._operand(i, k)
                    k += 1

        if i.update_flags and i.id != ARM_INS_CMP and i.id != ARM_INS_TST:
            self._add(" ")
            self._type("(FLAGS)")

        return modified
Esempio n. 4
0
    def _sub_asm_inst(self, i, tab=0, prefix=""):
        if is_ret(i):
            self._retcall(self.get_inst_str(i))
            return False

        if is_call(i):
            self._retcall(i.mnemonic)
            self._add(" ")

            if self.gctx.sectionsname:
                op = i.operands[0]
                if op.type == ARM_OP_IMM:
                    s = self._binary.get_section(op.value.imm)
                    if s is not None:
                        self._add("(")
                        self._section(s.name)
                        self._add(") ")

            self._operand(i, 0, hexa=True, force_dont_print_data=True)
            return False

        # Here we can have conditional jump with the option --dump
        if is_jump(i):
            if len(i.operands) == 0:
                self._add(i.mnemonic)
                return False

            self._add(i.mnemonic + " ")

            if i.operands[0].type != ARM_OP_IMM:
                self._operand(i, 0, force_dont_print_data=True)
                self.inst_end_here()
                if is_uncond_jump(i) and not self.ctx.is_dump \
                        and not i.address in self._dis.jmptables:
                    self._add(" ")
                    self._comment("# STOPPED")
                return False

            self._operand(i, 0, hexa=True, force_dont_print_data=True)
            return False

        modified = False

        if self.gctx.capstone_string == 0:
            if i.id in LDR_CHECK:
                self._operand(i, 0)
                self._add(" = (")
                self._type(LDR_TYPE[i.id])
                self._add(") ")
                self._operand(i, 1)
                modified = True

            elif i.id in STR_CHECK:
                self._operand(i, 1)
                self._add(" = (")
                self._type(STR_TYPE[i.id])
                self._add(") ")
                self._operand(i, 0)
                modified = True

            elif i.id in INST_CHECK:
                self._operand(i, 0)

                if i.id == ARM_INS_CMP:
                    self._add(" " + inst_symbol(i) + " ")
                    self._operand(i, 1)

                else:
                    self._add(" = ")
                    self._operand(i, 1)
                    if len(i.operands) == 3:
                        self._add(" " + inst_symbol(i) + " ")
                        self._operand(i, 2)

                modified = True

        if not modified:
            self._add("%s " % i.mnemonic)
            if len(i.operands) > 0:
                modified = self._operand(i, 0)
                k = 1
                while k < len(i.operands):
                    self._add(", ")
                    modified |= self._operand(i, k)
                    k += 1

        if i.update_flags and i.id != ARM_INS_CMP and i.id != ARM_INS_TST:
            self._add(" ")
            self._type("(FLAGS)")

        return modified