def section_collect(self):
        def secmapper(l):
            items = l.split()
            return Types.Section(items[0], int(items[1], 16),
                                 int(items[3], 16))

        lines = read_file('sections.info')
        self.sec = map(secmapper, lines)[::-1]
        self.text_mem_addrs = map(str.strip, read_file('text_mem.info'))
    def text_sec_collect(self):
        def secmapper(l):
            items = l.split()
            return (int(items[1], 16), int(items[3], 16))

        lines = read_file('text_sec.info')
        self.text_secs = map(secmapper, lines)[::-1]
        lines = read_file('text_mem.info')
        self.text_mem_addrs = map(lambda l: int(l.strip().rstrip(':'), 16),
                                  lines)
        self.text_mem_arr = list(self.text_mem_addrs)
    def disassemble(filepath, funcs, secs):
        ailpar = AilParser()
        re = reassemble()
        dis_valid = dis_validator()
        il = []
        fl = []
        total = 0.0
        cond = False
        while not cond and total < 600.0:
            once = TR.get_utime()
            ailpar.set_funcs(funcs)
            ailpar.set_secs(secs)
            ailpar.processInstrs(read_file('instrs.info'))
            fl = ailpar.get_funcs()
            print "2: disassembly validates"

            il = re.visit_heuristic_analysis(ailpar.get_instrs())
            il = re.adjust_loclabel(il)
            il = re.adjust_jmpref(il)
            il = re.add_func_label(Disam.get_userfuncs(fl), il)
            il = dis_valid.visit(il)

            adjust_list = dis_valid.trim_results()
            if len(adjust_list) != 0:
                print "     disassembly error found!"
                Disam.disasm_skip(filepath, adjust_list[0][0],
                                  adjust_list[0][1])
                total += TR.elapsed(once)
            else:
                cond = True

        print "     no disassembly error detected"
        return (il, fl, re)
    def set_datas(self, funcs):
        self.section_collect()
        self.data_collect()

        self.data_list = self.data_trans(self.data)
        self.rodata_list = self.data_trans(self.rodata)
        self.got_list = self.data_trans(self.got)
        self.bss_list = self.data_trans(self.bss)
        self.locations = self.label_locate()

        fl = sorted(funcs,
                    cmp=lambda f1, f2: f1.func_begin_addr - f2.func_begin_addr)
        self.fl_sort = map(
            lambda f: ft(f.func_name, f.func_begin_addr, f.func_end_addr), fl)

        self.text_mem_addrs = map(lambda a: int(a.strip().rstrip(':'), 16),
                                  read_file('text_mem.info'))
        self.text_mem_arr = self.text_mem_addrs

        self.label_mem_arr = sorted(self.label_mem_addrs)
        self.set_assumption_flag()

        self.begin_addrs = map(lambda f: f.func_begin_addr, funcs)
        if ELF_utils.elf_32(): self.data_refer_solve(funcs)
        else: self.data_refer_solve_64(funcs)
 def plt_collect(self):
     lines = read_file('plts.info')
     for l in lines:
         items = l.split()
         addr = int(items[0][1:], 16)
         name = items[1].split('@')[0][1:]
         reassemble.plt_hash[addr] = name
예제 #6
0
    def global_bss():
        lines = read_file('globalbss.info')

        def mapper(l):
            items = l.strip().split()
            return (items[1:], items[1])

        return map(mapper, lines)
 def plt_sec_collect(self):
     lines = read_file('plt_sec.info')
     for l in lines:
         items = l.split()
         self.plt_sec = (int(items[1], 16), int(items[3], 16))
 def pic_collect(self):
     lines = read_file('pic_secs.info')
     for l in lines:
         items = l.split()
         reassemble.pic_hash[items[0]] = (int(items[1],
                                              16), int(items[3], 16))
 def collect(self, name):
     if os.path.isfile(name):
         return map(str.strip, read_file(name))
     return []
예제 #10
0
 def funcaddr_from_file(self):
     self.func_begins = map(lambda a: int(a, 16), read_file('faddr.txt'))