Ejemplo n.º 1
0
 def list(self, func_name, *args):
     print(utils.titlify('mappings'))
     h = [utils.white_bold_underline('path'),
          utils.white_bold_underline('address'),
          utils.white_bold_underline('length')]
     print('')
     print(tabulate(self.mappings, h, tablefmt="simple"))
     print('')
Ejemplo n.º 2
0
 def print_arm_registers(self):
     r0 = self.core_instance.get_emu_instance() \
         .reg_read(arm_const.UC_ARM_REG_R0)
     r1 = self.core_instance.get_emu_instance() \
         .reg_read(arm_const.UC_ARM_REG_R1)
     r2 = self.core_instance.get_emu_instance() \
         .reg_read(arm_const.UC_ARM_REG_R2)
     r3 = self.core_instance.get_emu_instance() \
         .reg_read(arm_const.UC_ARM_REG_R3)
     r4 = self.core_instance.get_emu_instance() \
         .reg_read(arm_const.UC_ARM_REG_R4)
     r5 = self.core_instance.get_emu_instance() \
         .reg_read(arm_const.UC_ARM_REG_R5)
     r6 = self.core_instance.get_emu_instance() \
         .reg_read(arm_const.UC_ARM_REG_R6)
     r7 = self.core_instance.get_emu_instance() \
         .reg_read(arm_const.UC_ARM_REG_R7)
     r8 = self.core_instance.get_emu_instance() \
         .reg_read(arm_const.UC_ARM_REG_R8)
     r9 = self.core_instance.get_emu_instance() \
         .reg_read(arm_const.UC_ARM_REG_R9)
     r10 = self.core_instance.get_emu_instance() \
         .reg_read(arm_const.UC_ARM_REG_R10)
     r11 = self.core_instance.get_emu_instance() \
         .reg_read(arm_const.UC_ARM_REG_R11)
     r12 = self.core_instance.get_emu_instance() \
         .reg_read(arm_const.UC_ARM_REG_R12)
     sp = self.core_instance.get_emu_instance() \
         .reg_read(arm_const.UC_ARM_REG_SP)
     pc = self.core_instance.get_emu_instance() \
         .reg_read(arm_const.UC_ARM_REG_PC)
     lr = self.core_instance.get_emu_instance() \
         .reg_read(arm_const.UC_ARM_REG_LR)
     r = [[utils.green_bold("r0"), hex(r0), r0],
          [utils.green_bold("r1"), hex(r1), r1],
          [utils.green_bold("r2"), hex(r2), r2],
          [utils.green_bold("r3"), hex(r3), r3],
          [utils.green_bold("r4"), hex(r4), r4],
          [utils.green_bold("r5"), hex(r5), r5],
          [utils.green_bold("r6"), hex(r6), r6],
          [utils.green_bold("r7"), hex(r7), r7],
          [utils.green_bold("r8"), hex(r8), r8],
          [utils.green_bold("r9"), hex(r9), r9],
          [utils.green_bold("r10"), hex(r10), r10],
          [utils.green_bold("r11"), hex(r11), r11],
          [utils.green_bold("r12"), hex(r12), r12],
          [utils.green_bold("sp"), hex(sp), sp],
          [utils.green_bold("pc"), hex(pc), pc],
          [utils.green_bold("lr"), hex(lr), lr]]
     h = [
         utils.white_bold_underline('register'),
         utils.white_bold_underline('hex'),
         utils.white_bold_underline('decimal')
     ]
     print(tabulate(r, h, tablefmt="simple"))
Ejemplo n.º 3
0
 def exec(self, func_name, *args):
     print(utils.titlify('help'))
     print(utils.green_bold('usage: ') + self.command_map['executors']['usage'])
     r = []
     for key, value in self.executors_map.items():
         id = value['id']
         cmd_count = str(len(value['cmd_list']))
         r.append([str(id), key, cmd_count])
     h = [utils.white_bold_underline('id'),
          utils.white_bold_underline('name'),
          utils.white_bold_underline('commands')]
     print(utils.titlify('executors'))
     print(tabulate(r, h, tablefmt="simple"))
Ejemplo n.º 4
0
 def registers(self, func_name, *args):
     print(utils.titlify('registers'))
     arch = self.core_instance.unicorndbg_instance.arch
     mode = self.core_instance.unicorndbg_instance.mode
     regtable = getRegStringTable(getArchString(arch, mode))
     r = []
     for regcode in regtable:
         r.append(self.reg(regtable[regcode], regcode))
     h = [
         utils.white_bold_underline('register'),
         utils.white_bold_underline('hex'),
         utils.white_bold_underline('decimal')
     ]
     print(tabulate(r, h, tablefmt="simple"))
Ejemplo n.º 5
0
    def configs(self, func_name, *args):
        r = []

        for key in self.configs_map:
            val = self.configs_map[key]
            if isinstance(val, int):
                val = hex(val)
            r.append([utils.green_bold(key), val])
        h = [
            utils.white_bold_underline('config'),
            utils.white_bold_underline('value')
        ]
        print('')
        print(tabulate(r, h, tablefmt="simple"))
        print('')
Ejemplo n.º 6
0
    def read(self, func_name, *args):
        reg = str(args[0]).upper()
        value = self.read_register(reg)
        if value is None:
            raise Exception('register not found')

        r = [[utils.green_bold(reg), hex(value), str(value)]]
        h = [
            utils.white_bold_underline('register'),
            utils.white_bold_underline('hex'),
            utils.white_bold_underline('decimal')
        ]
        print('')
        print(tabulate(r, h, tablefmt="simple"))
        print('')
Ejemplo n.º 7
0
Archivo: udbg.py Proyecto: zbx911/uDdbg
    def start(self):
        """
        main start function, here we handle the command get loop and unicorn istance creation
       :return:
        """

        if not self.emu_instance:
            self.initialize()

        utils.clear_terminal()
        print(utils.get_banner())
        print('\n\n\t' + utils.white_bold('Contribute ') +
              'https://github.com/iGio90/uDdbg\n')
        print('\t' + 'Type ' + utils.white_bold_underline('help') +
              ' to begin.\n')

        main_apix = colored(MENU_APPENDIX + " ", 'red', attrs=['bold', 'dark'])
        print()
        while True:
            print(main_apix, end='', flush=True)
            text = prompt('',
                          history=self.history,
                          auto_suggest=AutoSuggestFromHistory())

            # only grant the use of empty command to replicate the last command while in cli. No executors
            if len(text) == 0 and self.last_command is not None:
                self.functions_instance.parse_command(self.last_command)
                continue

            self.last_command = text

            # send command to the parser
            self.functions_instance.parse_command(text)
Ejemplo n.º 8
0
Archivo: main.py Proyecto: heruix/uDdbg
    def start(self, arch=None, mode=None):
        """
        main start function, here we handle the command get loop and unicorn istance creation
        :param arch: unicorn arch int costant
        :param mode: unicorn mode int costant
        :return:
        """

        # if no arch or mode are sets in param, prompt for them
        if not arch:
            arch = utils.prompt_arch()
        if not mode:
            mode = utils.prompt_mode()

        self.arch = getattr(unicorn_const, arch)
        self.mode = getattr(unicorn_const, mode)

        self.emu_instance = Uc(self.arch, self.mode)

        if self.mode == UC_MODE_THUMB:
            self.is_thumb = True

        # add hooks
        self.emu_instance.hook_add(UC_HOOK_CODE, self.dbg_hook_code)
        self.emu_instance.hook_add(UC_HOOK_MEM_WRITE, self.dbg_hook_mem_access)
        self.emu_instance.hook_add(UC_HOOK_MEM_INVALID,
                                   self.dbg_hook_mem_invalid)

        utils.clear_terminal()
        print(utils.get_banner())
        print('\n\n\t' + utils.white_bold('Contribute ') +
              'https://github.com/iGio90/uDdbg\n')
        print('\t' + 'Type ' + utils.white_bold_underline('help') +
              ' to begin.\n')

        main_apix = colored(MENU_APPENDIX + " ", 'red', attrs=['bold', 'dark'])
        print()
        while True:
            print(main_apix, end='', flush=True)
            text = prompt('',
                          history=self.history,
                          auto_suggest=AutoSuggestFromHistory())

            # only grant the use of empty command to replicate the last command while in cli. No executors
            if len(text) == 0 and self.last_command is not None:
                self.functions_instance.parse_command(self.last_command)
                continue

            self.last_command = text

            # send command to the parser
            self.functions_instance.parse_command(text)
Ejemplo n.º 9
0
    def print_command_list(self, com_obj):
        """
        print the command list of the com_obj reference passed (could be root or even a sub_command reference)
        :param com_obj: command object reference
        :return:
        """
        try:
            com_array = []
            for com in com_obj:
                # if a short reference is present print (short)
                # if the command is a ref, ignore it
                if "ref" not in com_obj[com]:
                    com_array.append(com)

            # sort the list of commands and print it
            com_array.sort()
            command_table_arr = []
            for com in com_array:
                com_t = [utils.green_bold(com)]
                have_shorts = "short" in com_obj[com]
                if have_shorts:
                    com_t.append(com_obj[com]["short"])
                else:
                    com_t.append('')

                com_t.append(self.print_usage(com_obj[com], only_get=True))
                command_table_arr.append(com_t)

            print(utils.titlify('help'))
            print(
                tabulate(command_table_arr, [
                    utils.white_bold_underline('command'),
                    utils.white_bold_underline('short'),
                    utils.white_bold_underline('usage')
                ],
                         tablefmt="simple"))

        except Exception as e:
            print(utils.error_format('print_command_list', str(e)))
Ejemplo n.º 10
0
Archivo: find.py Proyecto: zbx911/uDdbg
    def find(self, func_name, *args):
        where = utils.u_eval(self.core_instance, args[0])

        what = bytes.fromhex(args[1])
        match = re.compile(what)

        result = []
        map_start = 0
        start = 0
        size = 0
        mappings = self.core_instance.get_module(
            'mappings_module').get_mappings()

        if isinstance(where, str):
            for map in mappings:
                if map[0] == where:
                    start = int(map[1], 16)
                    map_start = start
                    size = map[2]
        else:
            for map in mappings:
                if int(map[1], 16) <= where < (int(map[1], 16) + map[2]):
                    map_start = int(map[1], 16)
                    start = where
                    size = map[2]

        b = self.core_instance.get_emu_instance().mem_read(
            start, size - (map_start - start))
        for match_obj in match.finditer(b):
            offset = match_obj.start() + map_start
            result.append([hex(offset)])

        print(utils.titlify('find'))
        if len(result) == 0:
            print('Nothing found.')
        else:
            h = [utils.white_bold_underline('offset')]
            print('')
            print(tabulate(result, h, tablefmt="simple"))
            print('')