Example #1
0
 def loadPickle(self, name):
     somap_file = os.path.join('./', name, self.cell_name, 'soMap.pickle')
     if os.path.isfile(somap_file):
         self.lgr.debug('SOMap pickle from %s' % somap_file)
         so_pickle = pickle.load( open(somap_file, 'rb') ) 
         #print('start %s' % str(so_pickle['text_start']))
         self.so_addr_map = so_pickle['so_addr_map']
         self.so_file_map = so_pickle['so_file_map']
         self.text_prog = so_pickle['text_prog']
         ''' backward compatability '''
         if 'prog_start' in so_pickle:
             self.prog_start = so_pickle['prog_start']
             self.prog_end = so_pickle['prog_end']
         else:
             self.lgr.debug('soMap loadPickle old format, find text info')
             self.prog_start = so_pickle['text_start']
             self.prog_end = so_pickle['text_end']
             for pid in self.so_file_map:
                 if pid in self.text_prog:
                     full_path = self.targetFS.getFull(self.text_prog[pid], lgr=self.lgr)
                     self.lgr.debug('soMap loadPickle pid in text_prog %d full is %s' % (pid, full_path))
                     elf_info = elfText.getText(full_path, self.lgr)
                     if elf_info.text_start is not None:
                         self.prog_text_start[pid] = elf_info.text_start        
                         self.prog_text_end[pid] = elf_info.text_start + elf_info.text_size 
                         self.prog_text_offset[pid] = elf_info.text_offset        
                         break
         ''' really old backward compatibility '''
         if self.prog_start is None:
             self.lgr.debug('soMap loadPickle text_start is none')
             self.prog_start = {}
             self.prog_end = {}
             self.text_prog = {}
Example #2
0
    def addSO(self, pid_in, fpath, addr, count):
        pid = self.getThreadPid(pid_in, quiet=True)
        if pid is None:
            pid = pid_in
        if pid in self.so_addr_map and fpath in self.so_addr_map[pid]:
            ''' multiple mmap calls for one so file.  assume continguous and adjust
                address to lowest '''
            if self.so_addr_map[pid][fpath].address > addr:
                self.so_addr_map[pid][fpath].address = addr
                # TBD?
                #if self.ida_funs is not None:
                #    self.ida_funs.adjust(full_path, addr))
        else:
            if pid not in self.so_addr_map:
                self.so_addr_map[pid] = {}
                self.so_file_map[pid] = {}

            full_path = self.targetFS.getFull(fpath, lgr=self.lgr)
            text_seg = elfText.getText(full_path, self.lgr)
            if text_seg is None:
                self.lgr.debug('SOMap addSO, no file at %s' % full_path)
                return
       
            text_seg.locate = addr
            #text_seg.size = count

            self.so_addr_map[pid][fpath] = text_seg
            self.so_file_map[pid][text_seg] = fpath
            self.lgr.debug('soMap addSO pid:%d, full: %s size: 0x%x given count: 0x%x, locate: 0x%x addr: 0x%x off 0x%x  len so_map %d' % (pid, 
                   full_path, text_seg.size, count, addr, text_seg.address, text_seg.offset, len(self.so_addr_map[pid])))

            start = text_seg.locate
            if self.ida_funs is not None:
                self.ida_funs.add(full_path, start)
Example #3
0
    def addSO(self, pid_in, fpath, addr, count):
        pid = self.getThreadPid(pid_in, quiet=True)
        if pid is None:
            pid = pid_in
        if pid not in self.so_addr_map:
            self.so_addr_map[pid] = {}
            self.so_file_map[pid] = {}

        full_path = self.targetFS.getFull(fpath, lgr=self.lgr)
        text_seg = elfText.getText(full_path, self.lgr)
        if text_seg is None:
            self.lgr.debug('SOMap addSO, no file at %s' % full_path)
            return
       
        text_seg.locate = addr
        #text_seg.size = count

        self.so_addr_map[pid][fpath] = text_seg
        self.so_file_map[pid][text_seg] = fpath
        self.lgr.debug('soMap addSO pid:%d, full: %s size: 0x%x given count: 0x%x, locate: 0x%x addr: 0x%x off 0x%x  len so_map %d' % (pid, 
               full_path, text_seg.size, count, addr, text_seg.address, text_seg.offset, len(self.so_addr_map[pid])))

        start = text_seg.locate
        if self.ida_funs is not None:
            self.ida_funs.add(full_path, start)
Example #4
0
    def addSO(self, pid, fpath, addr, count):
        if pid not in self.so_addr_map:
            self.so_addr_map[pid] = {}
            self.so_file_map[pid] = {}

        full_path = self.targetFS.getFull(fpath)
        self.lgr.debug('soMap addSO, fpath is %s  full: %s' % (fpath, full_path))
        text_seg = elfText.getText(full_path)
        if text_seg is None:
            self.lgr.debug('SOMap addSO, no file at %s' % full_path)
            return
        text_seg.start = addr
        text_seg.size = count

        self.so_addr_map[pid][fpath] = text_seg
        self.so_file_map[pid][text_seg] = fpath
Example #5
0
 def addText(self, path, prog, pid_in):
     elf_info = elfText.getText(path, self.lgr)
     ''' First check that SO not already loaded from a snapshot '''
     pid = self.getThreadPid(pid_in, quiet=True)
     if pid is None:
         pid = pid_in
     if pid in self.prog_start:
         self.lgr.debug('soMap addText pid %d already in map len of so_addr_map %d' % (pid, len(self.so_file_map)))
     else:
         self.lgr.debug('soMap addText, prog %s pid:%d' % (prog, pid))
         self.prog_start[pid] = elf_info.address
         self.prog_end[pid] = elf_info.address+elf_info.size
         if elf_info.text_start is not None:
             self.prog_text_start[pid] = elf_info.text_start
             self.prog_text_end[pid] = elf_info.text_start + elf_info.text_size
             self.prog_text_offset[pid] = elf_info.text_offset
         self.text_prog[pid] = prog
         if pid not in self.so_addr_map:
             self.so_addr_map[pid] = {}
             self.so_file_map[pid] = {}
     return elf_info