示例#1
0
    def print_inst(self, i, tab=0, prefix=""):
        def get_inst_str():
            nonlocal i
            return "%s %s" % (i.mnemonic, i.op_str)

        if i.address in self.ctx.dis.previous_comments:
            for comm in self.ctx.dis.previous_comments[i.address]:
                print_tabbed(color_intern_comment("; %s" % comm), tab)

        if prefix == "# ":
            if self.ctx.comments:
                if i.address in self.ctx.labels:
                    print_label(i.address, tab)
                    print()
                print_comment_no_end(prefix, tab)
                print_addr(i.address)
                self.print_bytes(i, True)
                print_comment(get_inst_str())
            return

        if i.address in self.ctx.all_fused_inst:
            return

        if self.is_symbol(i.address):
            print_tabbed_no_end("", tab)
            self.print_symbol(i.address)
            print()

        print_label_and_addr(i.address, tab)

        self.print_bytes(i)

        if is_ret(i):
            print(color_retcall(get_inst_str()))
            return

        if is_call(i):
            print_no_end(color_retcall(i.mnemonic) + " ")
            modified = self.print_operand(i, 0, hexa=True)
            if modified and self.ctx.comments:
                print_comment_no_end(" # " + get_inst_str())
            print()
            return

        # Here we can have conditional jump with the option --dump
        if is_jump(i):
            print_no_end(i.mnemonic + " ")
            if i.operands[0].type != ARM_OP_IMM:
                print_no_end(i.op_str)
                if is_uncond_jump(i) and self.ctx.comments and not self.ctx.dump \
                        and not i.address in self.ctx.dis.jmptables:
                    print_comment_no_end(" # STOPPED")
                print()
                return
            addr = i.operands[0].value.imm
            if addr in self.ctx.addr_color:
                print_label_or_addr(addr, -1, False)
            else:
                print_no_end(hex(addr))
            print()
            return


        modified = False

        if i.id in LDR_CHECK:
            self.print_operand(i, 0)
            print_no_end(" = (")
            print_no_end(color_type(LDR_TYPE[i.id]))
            print_no_end(") ")
            self.print_operand(i, 1)
            modified = True

        elif i.id in STR_CHECK:
            self.print_operand(i, 1)
            print_no_end(" = (")
            print_no_end(color_type(STR_TYPE[i.id]))
            print_no_end(") ")
            self.print_operand(i, 0)
            modified = True

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

            if i.id == ARM_INS_CMP:
                print_no_end(" " + inst_symbol(i) + " ")
                self.print_operand(i, 1)

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

            modified = True

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

        if i.update_flags and i.id != ARM_INS_CMP and i.id != ARM_INS_TST:
            print_no_end(color_type(" (FLAGS)"))

        if i.address in self.ctx.dis.inline_comments:
            print_no_end(color_intern_comment(" ; "))
            print_no_end(color_intern_comment(self.ctx.dis.inline_comments[i.address]))

        if modified and self.ctx.comments:
            print_comment_no_end(" # " + get_inst_str())

        print()
示例#2
0
文件: output.py 项目: espreto/reverse
    def print_inst(self, i, tab=0, prefix=""):
        def get_inst_str():
            nonlocal i
            return "%s %s" % (i.mnemonic, i.op_str)

        if prefix == "# ":
            if self.ctx.comments:
                print_comment_no_end(prefix, tab)
                print_no_end(color_addr(i.address))
                print_comment(get_inst_str())
            return

        if i.address in self.ctx.all_fused_inst:
            return

        if i.address != self.ctx.addr and \
                i.address in self.ctx.dis.binary.reverse_symbols:
            print_tabbed_no_end("", tab)
            self.print_symbol(i.address)
            print()

        print_tabbed_no_end(color_addr(i.address), tab)

        if is_ret(i):
            print(color_retcall(get_inst_str()))
            return

        if is_call(i):
            print_no_end(color_retcall(i.mnemonic) + " ")
            self.print_operand(i, 0, hexa=True)
            print()
            return

        # Here we can have conditional jump with the option --dump
        if is_jump(i):
            if i.operands[0].type != ARM_OP_IMM:
                print_no_end(i.mnemonic + " ")
                print_no_end(i.op_str)
                if is_uncond_jump(i) and self.ctx.comments:
                    print_comment_no_end(" # STOPPED")
                print()
                return
            try:
                addr = i.operands[0].value.imm
                print(i.mnemonic + " " + color(hex(addr), self.ctx.addr_color[addr]))
            except KeyError:
                print(i.mnemonic + " " + hex(addr))
            return

        modified = False

        if i.id in LDR_CHECK:
            self.print_operand(i, 0)
            print_no_end(" = (")
            print_no_end(color_type(LDR_TYPE[i.id]))
            print_no_end(") ")
            self.print_operand(i, 1)
            modified = True

        elif i.id in STR_CHECK:
            self.print_operand(i, 1)
            print_no_end(" = (")
            print_no_end(color_type(STR_TYPE[i.id]))
            print_no_end(") ")
            self.print_operand(i, 0)
            modified = True

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

            if i.id == ARM_INS_CMP:
                print_no_end(" " + inst_symbol(i) + " ")
                self.print_operand(i, 1)

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

            modified = True

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

        if i.update_flags and i.id != ARM_INS_CMP and i.id != ARM_INS_TST:
            print_no_end(color_type(" (FLAGS)"))

        if modified and self.ctx.comments:
            print_comment_no_end(" # " + get_inst_str())

        print()
示例#3
0
    def print_inst(self, i, tab=0, prefix=""):
        def get_inst_str():
            nonlocal i
            return "%s %s" % (i.mnemonic, i.op_str)

        if prefix == "# ":
            if self.ctx.comments:
                print_comment_no_end(prefix, tab)
                print_no_end(color_addr(i.address))
                self.print_bytes(i, True)
                print_comment(get_inst_str())
            return

        if i.address in self.ctx.all_fused_inst:
            return

        if self.is_symbol(i.address):
            print_tabbed_no_end("", tab)
            self.print_symbol(i.address)
            print()

        print_tabbed_no_end(color_addr(i.address), tab)

        self.print_bytes(i)

        if is_ret(i):
            print(color_retcall(get_inst_str()))
            return

        if is_call(i):
            print_no_end(color_retcall(i.mnemonic) + " ")
            self.print_operand(i, 0, hexa=True)
            print()
            return

        # Here we can have conditional jump with the option --dump
        if is_jump(i):
            if i.operands[0].type != ARM_OP_IMM:
                print_no_end(i.mnemonic + " ")
                print_no_end(i.op_str)
                if is_uncond_jump(
                        i) and self.ctx.comments and not self.ctx.dump:
                    print_comment_no_end(" # STOPPED")
                print()
                return
            try:
                addr = i.operands[0].value.imm
                print(i.mnemonic + " " +
                      color(hex(addr), self.ctx.addr_color[addr]))
            except KeyError:
                print(i.mnemonic + " " + hex(addr))
            return

        modified = False

        if i.id in LDR_CHECK:
            self.print_operand(i, 0)
            print_no_end(" = (")
            print_no_end(color_type(LDR_TYPE[i.id]))
            print_no_end(") ")
            self.print_operand(i, 1)
            modified = True

        elif i.id in STR_CHECK:
            self.print_operand(i, 1)
            print_no_end(" = (")
            print_no_end(color_type(STR_TYPE[i.id]))
            print_no_end(") ")
            self.print_operand(i, 0)
            modified = True

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

            if i.id == ARM_INS_CMP:
                print_no_end(" " + inst_symbol(i) + " ")
                self.print_operand(i, 1)

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

            modified = True

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

        if i.update_flags and i.id != ARM_INS_CMP and i.id != ARM_INS_TST:
            print_no_end(color_type(" (FLAGS)"))

        if modified and self.ctx.comments:
            print_comment_no_end(" # " + get_inst_str())

        print()
示例#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 not self.gctx.capstone_string: 
            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
示例#5
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 not self.gctx.capstone_string:
            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
示例#6
0
文件: output.py 项目: kxlcn/reverse
    def _sub_asm_inst(self, i, tab=0, prefix=""):
        self._label_and_address(i.address, tab)
        self._bytes(i)

        if is_ret(i):
            self._retcall(self.get_inst_str(i))
            return False

        if is_call(i):
            self._retcall(i.mnemonic)
            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 self.ctx.comments and not self.ctx.dump \
                        and not i.address in self.ctx.dis.jmptables:
                    self._add(" ")
                    self._comment("# STOPPED")
                return False

            addr = i.operands[0].value.imm

            if self.is_symbol(addr):
                self._symbol(addr)
            else:
                if addr in self.ctx.addr_color:
                    self._label_or_address(addr, -1, False)
                else:
                    self._add(hex(addr))
            return False


        modified = False

        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

        else:
            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
示例#7
0
    def _sub_asm_inst(self, i, tab=0, prefix=""):
        self._label_and_address(i.address, tab)
        self._bytes(i)

        if is_ret(i):
            self._retcall(self.get_inst_str(i))
            return False

        if is_call(i):
            self._retcall(i.mnemonic)
            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

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

            addr = i.operands[0].value.imm
            if addr in self.ctx.addr_color:
                self._label_or_address(addr, -1, False)
            else:
                self._add(hex(addr))
            return False

        modified = False

        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

        else:
            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