def __getattribute__(self, name): if name == "fullname" and self.__dict__[name] is None: fn = demangle(name) self.__dict__["fullname"] = fn return fn else: return self.__dict__[name]
def loadSymbols(self): symAddrSet = set() syms = [] vtnRe = re.compile(r'(construction )?vtable for (.*)') readelf = subprocess.Popen(('readelf', '-sW', self.elf_filename), stdout=subprocess.PIPE) output = subprocess.check_output(('grep', '-iP', ' (_Z|_SD_Z|_SVT_Z)'), stdin=readelf.stdout) readelf.wait() try: for line in output.split('\n'): cols = line.split() try: if len(cols) < 8 or int(cols[6]) <= 0: continue except ValueError: continue addr = int(cols[1], 16) size = VTableExtractor.atoi(cols[2]) secId = int(cols[6]) if (addr, secId) in symAddrSet: continue name = cols[7] fullname = None isVtable = False isCons = False if any( map(name.startswith, ["_ZTV", "_ZTC", "_SD_ZTV", "_SD_ZTC"])): isVtable = True if name.startswith("_SD"): name = name[3:] fullname = demangle(name) m = vtnRe.match(fullname) fullname = m.group(2) isCons = m.group(1) is not None syms.append( Bunch(addr=addr, size=size, secId=secId, name=name, fullname=fullname, isCons=isCons, isVtable=isVtable)) symAddrSet.add((addr, secId)) return syms except Exception as e: print "while reading symbols: %s\n%s " % (e, line) sys.exit(-1)
def loadSymbols(self): symAddrSet = set() syms = [] vtnRe = re.compile(r'(construction )?vtable for (.*)') readelf = subprocess.Popen(('readelf', '-sW', self.elf_filename), stdout=subprocess.PIPE) output = subprocess.check_output(('grep', '-iP', ' (_Z|_SD_Z|_SVT_Z)'), stdin=readelf.stdout) readelf.wait() try: for line in output.split('\n'): cols = line.split() try: if len(cols) < 8 or int(cols[6]) <= 0: continue except ValueError: continue addr = int(cols[1],16) size = VTableExtractor.atoi(cols[2]) secId = int(cols[6]) if (addr,secId) in symAddrSet: continue name = cols[7] fullname = None isVtable = False isCons = False if any(map(name.startswith, ["_ZTV", "_ZTC", "_SD_ZTV", "_SD_ZTC"])): isVtable = True if name.startswith("_SD"): name = name[3:] fullname = demangle(name) m = vtnRe.match(fullname) fullname = m.group(2) isCons = m.group(1) is not None syms.append(Bunch(addr=addr, size=size, secId=secId, name=name, fullname=fullname, isCons=isCons, isVtable=isVtable)) symAddrSet.add((addr,secId)) return syms except Exception as e: print "while reading symbols: %s\n%s " % (e,line) sys.exit(-1)