Пример #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('')
Пример #2
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('')
Пример #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"))
Пример #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"))
Пример #5
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('')
Пример #6
0
    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)
Пример #7
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)))
Пример #8
0
    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('')
Пример #9
0
    def start(self):
        # 开始函数: 命令获取和unicorn实例创建
        """
        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')

        print()
        while True:
            # prompt方法
            text = prompt(FormattedText([('ansired bold', MENU_APPENDIX + ' ')
                                         ]),
                          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)