示例#1
0
文件: binary.py 项目: unisunis/debin
    def modify_elf(self, binary_without_symtab=None):
        utils.write_progress('Preparing Output...', self)
        modify_elf = ctypes.cdll.LoadLibrary(
            self.config.MODIFY_ELF_LIB_PATH).modify_elf
        modify_elf.argtypes = [
            ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_char_p,
            ctypes.c_int, ctypes.c_char_p, ctypes.c_int, ctypes.c_char_p,
            ctypes.c_int, ctypes.c_char_p, ctypes.c_int, ctypes.c_int,
            ctypes.c_int, ctypes.c_char_p
        ]

        info = self.get_debug_info()
        abbrev = self.get_debug_abbrev()
        loc = self.debug_loc.content
        self.symbol_table.debug_info()
        strtab = self.string_table.content
        symtab = self.symbol_table.content
        symtab_info = self.symbol_table.num_entries

        if binary_without_symtab is not None:
            binary_path = binary_without_symtab.encode('ascii')
            len_symtab = len(symtab)
        else:
            binary_path = self.config.BINARY_PATH.encode('ascii')
            len_symtab = 0 if self.sections.has_sec(SYMTAB) else len(symtab)

        modify_elf(binary_path, self.config.OUTPUT_BINARY_PATH.encode('ascii'),
                   len(info), bytes(info), len(abbrev),
                   bytes(abbrev), len(loc), bytes(loc), len(strtab),
                   bytes(strtab), len_symtab,
                   self.config.ADDRESS_BYTE_SIZE * 2 + 8, symtab_info,
                   bytes(symtab))
        utils.write_progress('Output Prepared...', self)
示例#2
0
文件: binary.py 项目: unisunis/debin
 def set_test_result_from_server(self, clear=False):
     utils.write_progress('Making Prediction...', self)
     url = self.config.N2P_SERVER_URL
     params = self.to_json(clear)
     data = {
         'method': 'infer',
         'params': params,
         'jsonrpc': '2.0',
         'id': 0,
     }
     response = requests.post(url, data=json.dumps(data)).json()
     self.set_test_result(response['result'])
示例#3
0
    def initialize(self):
        self.binary.sections.init_dynsym_functions()

        if not self.binary.sections.has_sec(SYMTAB):
            syscalls(self)
            if self.binary.binary_type == 'ET_EXEC':
                infer_functions(self)

        regs = []
        offs = []

        for f in self.functions:
            if f.is_run_init:
                f.initialize()

            if self.binary.config.TWO_PASS:
                regs += list(f.regs.values())
                for off in f.indirect_offsets.values():
                    for indirect_offset in off.values():
                        offs.append(indirect_offset)

        utils.write_progress('Recovering Variables...', self.binary)
        if self.binary.config.TWO_PASS:
            TIMER.start_scope('1VAR')
            for i in regs + offs:
                predict(i, self.binary)
            TIMER.end_scope()
        utils.write_progress('Extracting Features...', self.binary)

        for f in self.functions:
            f.callees.clear()
            f.callers.clear()
            for callee in f.bap.callees:
                if callee in self.functions_by_tid:
                    f.add_callee(self.functions_by_tid[callee])
            for caller in f.bap.callers:
                if caller in self.functions_by_tid:
                    f.add_caller(self.functions_by_tid[caller])