Пример #1
0
def main():
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)

    parser.add_argument('apk', help='Input APK file path.')

    parser.add_argument('--format',
                        help='Select output format',
                        default='default',
                        choices=['default', 'python'])

    args = parser.parse_args()

    apk_reader = apk_native_libs.ApkReader(args.apk)
    lib_map = apk_native_libs.ApkNativeLibraries(apk_reader)
    for lib_path, file_offset, file_size in lib_map.GetDumpList():
        if args.format == 'python':
            print('(0x%08x, 0x%08x, 0x%08x, \'%s\'),' %
                  (file_offset, file_offset + file_size, file_size, lib_path))
        else:
            print('0x%08x 0x%08x 0x%08x %s' %
                  (file_offset, file_offset + file_size, file_size, lib_path))

    return 0
Пример #2
0
 def testEmptyApk(self):
     with MockApkReader() as reader:
         libs_map = apk_native_libs.ApkNativeLibraries(reader)
         self.assertTrue(libs_map.IsEmpty())
         self.assertEqual(len(libs_map.GetLibraries()), 0)
         lib_path, lib_offset = libs_map.FindLibraryByOffset(0)
         self.assertIsNone(lib_path)
         self.assertEqual(lib_offset, 0)
Пример #3
0
    def testSimpleApk(self):
        with MockApkReader() as reader:
            _MOCK_ENTRIES = [
                # Top-level library should be ignored.
                ('libfoo.so', 1000, 1000, MOCK_ELF_DATA, False),
                # Library not under lib/ should be ignored.
                ('badlib/test-abi/libfoo2.so', 1001, 1001, MOCK_ELF_DATA, False
                 ),
                # Library under lib/<abi>/ but without .so extension should be ignored.
                ('lib/test-abi/libfoo4.so.1', 1003, 1003, MOCK_ELF_DATA, False
                 ),
                # Library under lib/<abi>/ with .so suffix, but compressed -> ignored.
                ('lib/test-abi/libfoo5.so', 1004, 1003, MOCK_ELF_DATA, False),
                # First correct library
                ('lib/test-abi/libgood1.so', 1005, 1005, MOCK_ELF_DATA, True),
                # Second correct library: support sub-directories
                ('lib/test-abi/subdir/libgood2.so', 1006, 1006, MOCK_ELF_DATA,
                 True),
                # Third correct library, no lib prefix required
                ('lib/test-abi/crazy.libgood3.so', 1007, 1007, MOCK_ELF_DATA,
                 True),
            ]
            file_offsets = []
            prev_offset = 0
            for ent in _MOCK_ENTRIES:
                reader.AddTestEntry(ent[0], ent[1], ent[2], ent[3])
                file_offsets.append(prev_offset)
                prev_offset += ent[2]

            libs_map = apk_native_libs.ApkNativeLibraries(reader)
            self.assertFalse(libs_map.IsEmpty())
            self.assertEqual(libs_map.GetLibraries(), [
                'lib/test-abi/crazy.libgood3.so',
                'lib/test-abi/libgood1.so',
                'lib/test-abi/subdir/libgood2.so',
            ])

            BIAS = 10
            for mock_ent, file_offset in zip(_MOCK_ENTRIES, file_offsets):
                if mock_ent[4]:
                    lib_path, lib_offset = libs_map.FindLibraryByOffset(
                        file_offset + BIAS)
                    self.assertEqual(lib_path, mock_ent[0])
                    self.assertEqual(lib_offset, BIAS)
Пример #4
0
    def testMultiAbiApk(self):
        with MockApkReader() as reader:
            _MOCK_ENTRIES = [
                ('lib/abi1/libfoo.so', 1000, 1000, MOCK_ELF_DATA),
                ('lib/abi2/libfoo.so', 1000, 1000, MOCK_ELF_DATA),
            ]
            for ent in _MOCK_ENTRIES:
                reader.AddTestEntry(ent[0], ent[1], ent[2], ent[3])

            libs_map = apk_native_libs.ApkNativeLibraries(reader)
            self.assertFalse(libs_map.IsEmpty())
            self.assertEqual(libs_map.GetLibraries(),
                             ['lib/abi1/libfoo.so', 'lib/abi2/libfoo.so'])

            lib1_name, lib1_offset = libs_map.FindLibraryByOffset(10)
            self.assertEqual(lib1_name, 'lib/abi1/libfoo.so')
            self.assertEqual(lib1_offset, 10)

            lib2_name, lib2_offset = libs_map.FindLibraryByOffset(1000)
            self.assertEqual(lib2_name, 'lib/abi2/libfoo.so')
            self.assertEqual(lib2_offset, 0)