All Projects → quarkslab → QBDL

quarkslab / QBDL

Licence: Apache-2.0 License
QuarkslaB Dynamic Linker library

Programming Languages

C++
36643 projects - #6 most used programming language
python
139335 projects - #7 most used programming language
CMake
9771 projects
Dockerfile
14818 projects
shell
77523 projects

QuarkslaB Dynamic Loader

The QuarkslaB Dynamic Linker (QBDL) library aims at providing a modular and portable way to dynamically load and link binaries.

Documentation

See here.

Quick example

Here is a quick example using the Python API to run simple MachO binaries under Linux:

import pyqbdl
import lief
import sys
import ctypes

class TargetSystem(pyqbdl.engines.Native.TargetSystem):
    def __init__(self):
        super().__init__(pyqbdl.engines.Native.memory())
        self.libc = ctypes.CDLL("libc.so.6")

    def symlink(self, loader: pyqbdl.Loader, sym: lief.Symbol) -> int:
        if not sym.name.startswith("_"):
            return 0
        ptr = getattr(self.libc, sym.name[1:], 0)
        if ptr != 0:
            ptr = ctypes.cast(ptr, ctypes.c_void_p).value
        return ptr

loader = pyqbdl.loaders.MachO.from_file(sys.argv[1], pyqbdl.engines.Native.arch(), TargetSystem(),
                                        pyqbdl.Loader.BIND.NOW)
main_type = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_int, ctypes.c_voidp)
main_ptr = main_type(loader.entrypoint)
main_ptr(0, ctypes.c_void_p(0))

For more detailed use cases, please refer to the documentation.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].