示例#1
0
    def resume_emulation(self, address=0x0, skip_bp=0):
        if address > 0x0:
            self.current_address = address

        self.skip_bp_count = skip_bp

        if self.exit_point > 0x0:
            print(utils.white_bold("emulation") + " started at " + utils.green_bold(hex(self.current_address)))

            if len(self.entry_context) == 0:
                # store the initial memory context for the restart
                self.entry_context = {
                    'memory': {},
                    'regs': {}
                }
                map_list = self.get_module('mappings_module').get_mappings()
                for map in map_list:
                    map_address = int(map[1], 16)
                    map_len = map[2]
                    self.entry_context['memory'][map_address] = bytes(self.emu_instance.mem_read(map_address, map_len))
                # registers
                const = utils.get_arch_consts(self.arch)
                regs = [k for k, v in const.__dict__.items() if
                        not k.startswith("__") and k.index("_REG_") > 0]
                for r in regs:
                    self.entry_context['regs'][r] = \
                        self.emu_instance.reg_read(getattr(const, r))

            start_addr = self.current_address
            if self.is_thumb:
                start_addr = start_addr | 1
            self.emu_instance.emu_start(start_addr, self.exit_point)
        else:
            print('please use \'set exit_point *offset\' to define an exit point')
示例#2
0
文件: registers.py 项目: zbx911/uDdbg
 def read_register(self, reg):
     arch = self.core_instance.unicorndbg_instance.get_arch()
     try:
         register = getattr(utils.get_arch_consts(arch),
                            utils.get_reg_tag(arch) + reg)
     except Exception as e:
         return None
     return self.core_instance.get_emu_instance().reg_read(register)
示例#3
0
 def restore(self):
     self.current_address = self.entry_point
     for addr in self.entry_context['memory']:
         m = self.entry_context['memory'][addr]
         self.emu_instance.mem_write(addr, m)
     print('restored ' + str(len(self.entry_context['memory'])) + ' memory regions.')
     const = utils.get_arch_consts(self.arch)
     for r in self.entry_context['regs']:
         self.emu_instance.reg_write(getattr(const, r), self.entry_context['regs'][r])
     print('restored ' + str(len(self.entry_context['regs'])) + ' registers.')
     print('emulator at ' + utils.green_bold(hex(self.current_address)))
示例#4
0
文件: registers.py 项目: zbx911/uDdbg
    def write(self, func_name, *args):
        arch = self.core_instance.unicorndbg_instance.get_arch()
        try:
            register = getattr(utils.get_arch_consts(arch),
                               utils.get_reg_tag(arch) + str(args[0]).upper())
        except Exception as e:
            raise Exception('register not found')

        value = utils.u_eval(self.core_instance, args[1])
        self.core_instance.get_emu_instance().reg_write(register, value)
        print(hex(value) + ' written into ' + str(args[0]).upper())
示例#5
0
文件: udbg.py 项目: zbx911/uDdbg
    def resume_emulation(self, address=None, skip_bp=0):
        if address is not None:
            self.current_address = address

        self.skip_bp_count = skip_bp

        if self.exit_point is not None:
            print(
                utils.white_bold("emulation") + " started at " +
                utils.green_bold(hex(self.current_address)))

            if len(self.entry_context) == 0:
                # store the initial memory context for the restart
                self.entry_context = {'memory': {}, 'regs': {}}
                map_list = self.get_module('mappings_module').get_mappings()
                for map in map_list:
                    map_address = int(map[1], 16)
                    map_len = map[2]
                    self.entry_context['memory'][map_address] = bytes(
                        self.emu_instance.mem_read(map_address, map_len))
                # registers
                const = utils.get_arch_consts(self.arch)
                regs = [
                    k for k, v in const.__dict__.items()
                    if not k.startswith("__") and "_REG_" in k
                    and not "INVALID" in k
                ]
                for r in regs:
                    try:
                        self.entry_context['regs'][
                            r] = self.emu_instance.reg_read(getattr(const, r))
                    except Exception as ex:
                        pass
                        # print("Ignoring reg: {} ({})".format(r, ex)) -> Ignored UC_X86_REG_MSR

            start_addr = self.current_address
            if self.is_thumb:
                start_addr = start_addr | 1
            self.emu_instance.emu_start(start_addr, self.exit_point)
        else:
            print(
                'please use \'set exit_point *offset\' to define an exit point'
            )