コード例 #1
0
    def test_rewrite_apex_modules(self):
        graph = ELFLinker()

        libfoo = graph.add_lib(PT_SYSTEM, '/system/apex/foo/lib/libfoo.so',
                               ELF(ELF.ELFCLASS32, ELF.ELFDATA2LSB))
        libbar = graph.add_lib(PT_SYSTEM, '/system/apex/bar/lib/libbar.so',
                               ELF(ELF.ELFCLASS32, ELF.ELFDATA2LSB))

        graph.rewrite_apex_modules()

        self.assertEqual(libfoo.path, '/apex/foo/lib/libfoo.so')
        self.assertEqual(libbar.path, '/apex/bar/lib/libbar.so')
コード例 #2
0
    def test_rewrite_apex_modules(self):
        graph = ELFLinker()

        libfoo = graph.add_lib(PT_SYSTEM, '/system/apex/foo/lib/libfoo.so',
                               ELF(ELF.ELFCLASS32, ELF.ELFDATA2LSB))
        libbar = graph.add_lib(PT_SYSTEM, '/system/apex/bar/lib/libbar.so',
                               ELF(ELF.ELFCLASS32, ELF.ELFDATA2LSB))

        graph.rewrite_apex_modules()

        self.assertEqual(libfoo.path, '/apex/foo/lib/libfoo.so')
        self.assertEqual(libbar.path, '/apex/bar/lib/libbar.so')
コード例 #3
0
    def test_link_apex_modules(self):
        graph = ELFLinker()

        libfoo = graph.add_lib(PT_SYSTEM, '/system/apex/foo/lib/libfoo.so',
                               ELF(ELF.ELFCLASS32, ELF.ELFDATA2LSB))
        libbar = graph.add_lib(
            PT_SYSTEM, '/system/lib/libbar.so',
            ELF(ELF.ELFCLASS32, ELF.ELFDATA2LSB, dt_needed=['libfoo.so']))

        graph.rewrite_apex_modules()
        graph.resolve_deps()

        self.assertIn(libfoo, libbar.deps_all)
コード例 #4
0
    def test_link_apex_modules(self):
        graph = ELFLinker()

        libfoo = graph.add_lib(PT_SYSTEM, '/system/apex/foo/lib/libfoo.so',
                               ELF(ELF.ELFCLASS32, ELF.ELFDATA2LSB))
        libbar = graph.add_lib(PT_SYSTEM, '/system/lib/libbar.so',
                               ELF(ELF.ELFCLASS32, ELF.ELFDATA2LSB,
                                   dt_needed=['libfoo.so']))

        graph.rewrite_apex_modules()
        graph.resolve_deps()

        self.assertIn(libfoo, libbar.deps_all)
コード例 #5
0
    def test_link_apex_bionic(self):
        graph = ELFLinker()

        libc = graph.add_lib(
            PT_SYSTEM, '/system/apex/com.android.runtime/lib/bionic/libc.so',
            ELF(ELF.ELFCLASS32, ELF.ELFDATA2LSB))
        libbar = graph.add_lib(
            PT_SYSTEM, '/system/lib/libbar.so',
            ELF(ELF.ELFCLASS32, ELF.ELFDATA2LSB, dt_needed=['libc.so']))

        graph.rewrite_apex_modules()
        graph.resolve_deps()

        self.assertIn(libc, libbar.deps_all)
コード例 #6
0
    def test_link_apex_bionic(self):
        graph = ELFLinker()

        libc = graph.add_lib(
            PT_SYSTEM, '/system/apex/com.android.runtime/lib/bionic/libc.so',
            ELF(ELF.ELFCLASS32, ELF.ELFDATA2LSB))
        libbar = graph.add_lib(
            PT_SYSTEM, '/system/lib/libbar.so',
            ELF(ELF.ELFCLASS32, ELF.ELFDATA2LSB, dt_needed=['libc.so']))

        graph.rewrite_apex_modules()
        graph.resolve_deps()

        self.assertIn(libc, libbar.deps_all)
コード例 #7
0
class GraphBuilder(object):
    _PARTITION_NAMES = {
        PT_SYSTEM: 'system',
        PT_VENDOR: 'vendor',
    }

    _LIB_DIRS = {
        ELF.ELFCLASS32: 'lib',
        ELF.ELFCLASS64: 'lib64',
    }

    def __init__(self):
        self.graph = ELFLinker()

    def add_lib(self,
                partition,
                klass,
                name,
                dt_needed=[],
                exported_symbols=set(),
                imported_symbols=set(),
                extra_dir=None):
        """Create and add a shared library to ELFLinker."""

        lib_dir = os.path.join('/', self._PARTITION_NAMES[partition],
                               self._LIB_DIRS[klass])
        if extra_dir:
            lib_dir = os.path.join(lib_dir, extra_dir)

        path = os.path.join(lib_dir, name + '.so')

        elf = ELF(klass,
                  ELF.ELFDATA2LSB,
                  dt_needed=dt_needed,
                  exported_symbols=exported_symbols,
                  imported_symbols=imported_symbols)

        node = self.graph.add_lib(partition, path, elf)
        setattr(self, name + '_' + elf.elf_class_name, node)
        return node

    def add_multilib(self,
                     partition,
                     name,
                     dt_needed=[],
                     exported_symbols=set(),
                     imported_symbols=set(),
                     extra_dir=None):
        """Add 32-bit / 64-bit shared libraries to ELFLinker."""
        return (self.add_lib(partition, ELF.ELFCLASS32, name, dt_needed,
                             exported_symbols, imported_symbols, extra_dir),
                self.add_lib(partition, ELF.ELFCLASS64, name, dt_needed,
                             exported_symbols, imported_symbols, extra_dir))

    def resolve(self):
        self.graph.resolve_deps()
コード例 #8
0
class GraphBuilder(object):
    _PARTITION_NAMES = {
        PT_SYSTEM: 'system',
        PT_VENDOR: 'vendor',
    }

    _LIB_DIRS = {
        ELF.ELFCLASS32: 'lib',
        ELF.ELFCLASS64: 'lib64',
    }

    def __init__(self):
        self.graph = ELFLinker()

    def add_lib(self, partition, klass, name, dt_needed=[],
                exported_symbols=set(), imported_symbols=set(),
                extra_dir=None):
        """Create and add a shared library to ELFLinker."""

        lib_dir = os.path.join('/', self._PARTITION_NAMES[partition],
                               self._LIB_DIRS[klass])
        if extra_dir:
            lib_dir = os.path.join(lib_dir, extra_dir)

        path = os.path.join(lib_dir, name + '.so')

        elf = ELF(klass, ELF.ELFDATA2LSB, dt_needed=dt_needed,
                  exported_symbols=exported_symbols,
                  imported_symbols=imported_symbols)

        node = self.graph.add_lib(partition, path, elf)
        setattr(self, name + '_' + elf.elf_class_name, node)
        return node

    def add_multilib(self, partition, name, dt_needed=[],
                     exported_symbols=set(), imported_symbols=set(),
                     extra_dir=None):
        """Add 32-bit / 64-bit shared libraries to ELFLinker."""
        return (
            self.add_lib(partition, ELF.ELFCLASS32, name, dt_needed,
                         exported_symbols, imported_symbols, extra_dir),
            self.add_lib(partition, ELF.ELFCLASS64, name, dt_needed,
                         exported_symbols, imported_symbols, extra_dir)
        )

    def resolve(self):
        self.graph.resolve_deps()