def test_x86_64_elf_parse(self): """Test parsing of x86-64 elf header.""" dyn_nexe = os.path.join(DATA_DIR, 'test_dynamic_x86_64.nexe') static_nexe = os.path.join(DATA_DIR, 'test_static_x86_64.nexe') arch, dynamic = elf.ParseElfHeader(dyn_nexe) self.assertEqual(arch, 'x86-64') self.assertTrue(dynamic) arch, dynamic = elf.ParseElfHeader(static_nexe) self.assertEqual(arch, 'x86-64') self.assertFalse(dynamic)
def GetNeeded(main_files, objdump, lib_path): '''Collect the list of dependencies for the main_files Args: main_files: A list of files to find dependencies of. objdump: Path to the objdump executable. lib_path: A list of paths to search for shared libraries. Returns: A dict with key=filename and value=architecture. The architecture will be one of ('x86_32', 'x86_64', 'arm'). ''' dynamic = any(elf.ParseElfHeader(f)[1] for f in main_files) if dynamic: return _GetNeededDynamic(main_files, objdump, lib_path) else: return _GetNeededStatic(main_files)
def _GetNeededStatic(main_files): needed = {} for filename in main_files: arch = elf.ParseElfHeader(filename)[0] needed[filename] = arch return needed
def ParseElfHeader(path): """Wrap elf.ParseElfHeader to return raise this module's Error on failure.""" try: return elf.ParseElfHeader(path) except elf.Error, e: raise Error(str(e))
def test_arm_elf_parse(self): """Test parsing of ARM elf header.""" static_nexe = os.path.join(DATA_DIR, 'test_static_arm.nexe') arch, dynamic = elf.ParseElfHeader(static_nexe) self.assertEqual(arch, 'arm') self.assertFalse(dynamic)