def __init__(self, path, basedir='', buffer=''): Magic.__init__(self, path, basedir) fullpath = basedir+path self.contents['stripped'] = elf.stripped(fullpath) if self.__class__ is ELF: # ar doesn't deal with hasDebug or RPATH try: self.contents['hasDebug'] = elf.hasDebug(fullpath) except elf.error: pass try: self.contents['RPATH'] = elf.getRPATH(fullpath) except elf.error: pass try: self.contents['Type'] = elf.getType(fullpath) except elf.error: pass try: requires, provides = elf.inspect(fullpath) # Filter None abi flags requires = [ x for x in requires if x[0] != 'abi' or x[2][0] is not None ] self.contents['requires'] = requires self.contents['provides'] = provides for req in requires: if req[0] == 'abi': self.contents['abi'] = req[1:] self.contents['isnset'] = req[2][1] for prov in provides: if prov[0] == 'soname': self.contents['soname'] = prov[1] except elf.error: pass
def __init__(self, path, basedir='', buffer=''): Magic.__init__(self, path, basedir) fullpath = basedir + path self.contents['stripped'] = elf.stripped(fullpath) if self.__class__ is ELF: # ar doesn't deal with hasDebug or RPATH try: self.contents['hasDebug'] = elf.hasDebug(fullpath) except elf.error: pass try: self.contents['RPATH'] = elf.getRPATH(fullpath) except elf.error: pass try: self.contents['Type'] = elf.getType(fullpath) except elf.error: pass try: requires, provides = elf.inspect(fullpath) # Filter None abi flags requires = [ x for x in requires if x[0] != 'abi' or x[2][0] is not None ] self.contents['requires'] = requires self.contents['provides'] = provides for req in requires: if req[0] == 'abi': self.contents['abi'] = req[1:] self.contents['isnset'] = req[2][1] for prov in provides: if prov[0] == 'soname': self.contents['soname'] = prov[1] except elf.error: pass
def testGetRPATH(self): d = tempfile.mkdtemp() cwd = os.getcwd() try: os.chdir(d) # write a simple C program... f = open('foo.c', 'w') f.write('int main(void) { return 0; }\n') f.close() # test to make sure that setting a -rpath gives us the right # answer subprocess.call(('gcc', '-o', 'foo', 'foo.c', '-Wl,-rpath,/foo')) assert (elf.getRPATH('foo') == '/foo') # check multiple -rpath command line entries (this basically # tests to make sure the linker behaves as we expect) subprocess.call(('gcc', '-o', 'foo', 'foo.c', '-Wl,-rpath,/foo', '-Wl,-rpath,/bar')) assert (elf.getRPATH('foo') == '/foo:/bar') # test to make sure that the new RUNPATH tag gets parsed correctly subprocess.call(('gcc', '-o', 'foo', 'foo.c', '-Wl,-rpath,/foo', '-Wl,--enable-new-dtags')) assert (elf.getRPATH('foo') == '/foo') # empty rpath (makes sure that an empty string can be returned) subprocess.call(('gcc', '-o', 'foo', 'foo.c', '-Wl,-rpath,')) assert (elf.getRPATH('foo') == '') # test attempting to get an RPATH from an .a archive subprocess.call(('gcc', '-c', '-o', 'foo.o', 'foo.c')) null = open('/dev/null', 'w') p = subprocess.Popen(('ar', 'q', 'foo.a', 'foo.o'), stdout=null, stderr=null) os.waitpid(p.pid, 0) assert (elf.getRPATH('foo.a') == None) # test no rpath set subprocess.call(('gcc', '-o', 'foo', 'foo.c')) assert (elf.getRPATH('foo') == None) finally: os.chdir(cwd) shutil.rmtree(d)
def testGetRPATH(self): d = tempfile.mkdtemp() cwd = os.getcwd() try: os.chdir(d) # write a simple C program... f = open('foo.c', 'w') f.write('int main(void) { return 0; }\n') f.close() # test to make sure that setting a -rpath gives us the right # answer subprocess.call(('gcc', '-o', 'foo', 'foo.c', '-Wl,-rpath,/foo')) assert(elf.getRPATH('foo') == '/foo') # check multiple -rpath command line entries (this basically # tests to make sure the linker behaves as we expect) subprocess.call(('gcc', '-o', 'foo', 'foo.c', '-Wl,-rpath,/foo', '-Wl,-rpath,/bar')) assert(elf.getRPATH('foo') == '/foo:/bar') # test to make sure that the new RUNPATH tag gets parsed correctly subprocess.call(('gcc', '-o', 'foo', 'foo.c', '-Wl,-rpath,/foo', '-Wl,--enable-new-dtags')) assert(elf.getRPATH('foo') == '/foo') # empty rpath (makes sure that an empty string can be returned) subprocess.call(('gcc', '-o', 'foo', 'foo.c', '-Wl,-rpath,')) assert(elf.getRPATH('foo') == '') # test attempting to get an RPATH from an .a archive subprocess.call(('gcc', '-c', '-o', 'foo.o', 'foo.c')) null = open('/dev/null', 'w') p = subprocess.Popen(('ar', 'q', 'foo.a', 'foo.o'), stdout=null, stderr=null) os.waitpid(p.pid, 0) assert(elf.getRPATH('foo.a') == None) # test no rpath set subprocess.call(('gcc', '-o', 'foo', 'foo.c')) assert(elf.getRPATH('foo') == None) finally: os.chdir(cwd) shutil.rmtree(d)