Tool to generate wrappers for Linux libraries allowing for dlopen()ing them without writing any boilerplate

Overview

Dynload wrapper

This program will generate a wrapper to make it easy to dlopen() shared objects on Linux without writing a ton of boilerplate code.

This is useful when shipping binaries to users which may or may not have some optional dependencies installed. Particularly pulseaudio can be an issue as there are some Linux users vehemently against using it. Using this tool to generate pulse wrappers allows the program to gracefully fall back on a different sound library without requiring libpulse to be available on the users' system. (Note that the actual fallback code is the domain of the program, the wrapper generation cannot do this for you)

The program works by parsing the header file(s) related to the binary and figuring out what functions exist. It will then generate a header which #include's the orignal header, it renames all the function definitions in the orignal header to _dylibloader_orig_, generate it's own _dylibloader_wrap_ definitions, and finally renames the original function as well. This means that for the code using the functions there is no difference, but we won't clash with the 'real' symbols if they manage to be loaded by a different dependency somewhere. These function pointers will be resolved by dlsym() when calling the initialize_().

Generally speaking all that should be required is generating the header and c file, replacing the #includes of the normal library with the generated ones, and calling the initialize function before starting to use the library. There are some examples in the examples/ directory which show how to do this.

Caveats

Generally speaking this works fine, but if you link to libraries that themselves require the symbols of the dlopen()'d library you must call the initialize function first before using it. An example of this is alsa which on pulse-enabled systems will itself try to use pulse symbols. In this case you must initialize the pulse wrappers before using alsa.

Tested libraries

  • Xlib
  • Alsa
  • PulseAudio
  • Udev

Help

$ ./generate-wrapper.py --help
usage: generate-wrapper.py [-h] --include INCLUDE --sys-include SYS_INCLUDE --soname SONAME --init-name INIT_NAME --output-header OUTPUT_HEADER --output-implementation OUTPUT_IMPLEMENTATION [--omit-prefix OMIT_PREFIX]

A tool to generate wrappers for run-time dlopen()ing of libraries.

optional arguments:
  -h, --help            show this help message and exit
  --include INCLUDE     Include files to read (may appear more than once)
  --sys-include SYS_INCLUDE
                        Include as they appear inside a program (eg ) (may appear more than once)
  --soname SONAME       Soname of the wrapped library (eg libpulse.so.0)
  --init-name INIT_NAME
                        Name to use for the initialize function. This will generate an initialize_ function. (eg pulse)
  --output-header OUTPUT_HEADER
                        Filename of the header to output
  --output-implementation OUTPUT_IMPLEMENTATION
                        Filename of the C file to output
  --omit-prefix OMIT_PREFIX
                        Omit functions that start with this prefix (eg _pa_) (may appear more than once)

Example usage for wrapping pulse:
generate-wrapper.py --include /usr/include/pulse/pulseaudio.h --sys-include '' --soname libpulse.so.0 --omit-prefix _pa_ --init-name pulse --output-header pulse.h --output-implementation pulse.c

Example usage for wrapping X:
generate-wrapper.py --include /usr/include/X11/Xlib.h --include /usr/include/X11/Xutil.h --include /usr/include/X11/XKBlib.h  --sys-include '' --sys-include '' --sys-include '' --soname libX11.so.6 --init-name xlib --omit-prefix XkbGetDeviceIndicatorState --omit-prefix XkbAddSymInterpret --output-header xlib.h --output-implementation xlib.c
You might also like...
NotesToCommands - a fully customizable notes / command template program, allowing users to instantly execute terminal commands

NotesToCommands is a fully customizable notes / command template program, allowing users to instantly execute terminal commands with dynamic arguments grouped into sections in their notes/files. It was originally created for pentesting uses, to avoid the needed remembrance and retyping of sets of commands for various attacks.

Just some mtk tool for exploitation, reading/writing flash and doing crazy stuff

Just some mtk tool for exploitation, reading/writing flash and doing crazy stuff. For linux, a patched kernel is needed (see Setup folder) (except for read/write flash). For windows, you need to install zadig driver and replace pid 0003 / pid 2000 driver.

a simple proof system I made to learn math without any mistakes

math_up a simple proof system I made to learn math without any mistakes 0. Short Introduction test yourself, enjoy your math! math_up is an NBG-based,

Create or join a private chatroom without any third-party middlemen in less than 30 seconds, available through an AES encrypted password protected link.
Create or join a private chatroom without any third-party middlemen in less than 30 seconds, available through an AES encrypted password protected link.

PY-CHAT Create or join a private chatroom without any third-party middlemen in less than 30 seconds, available through an AES encrypted password prote

Manually Install Python 2.7 pip without any problem !

Python2.7_install_pip Manually Install Python 2.7 pip without any problem ! Download installPip.py to your system and Run the code using this Command

Hacktoberfest2021 🥳- Contribute Any Pattern In Any Language😎 Every PR will be accepted Pls contribute
Hacktoberfest2021 🥳- Contribute Any Pattern In Any Language😎 Every PR will be accepted Pls contribute

✨ Hacktober Fest 2021 ✨ 🙂 All Contributors are requested to star this repo and follow me for a successful merge of pull request. 🙂 👉 Add any patter

Generate a wordlist to fuzz amounts or any other numerical values.
Generate a wordlist to fuzz amounts or any other numerical values.

Generate a wordlist to fuzz amounts or any other numerical values. Based on Common Security Issues in Financially-Oriented Web Applications.

Paprika is a python library that reduces boilerplate. Heavily inspired by Project Lombok.
Paprika is a python library that reduces boilerplate. Heavily inspired by Project Lombok.

Image courtesy of Anna Quaglia (Photographer) Paprika Paprika is a python library that reduces boilerplate. It is heavily inspired by Project Lombok.

Automate the boilerplate while initializing your Python project
Automate the boilerplate while initializing your Python project

Rubric Automate the boilerplate while initializing your Python project Preface Rubric is an opinionated project initializer for Python. It assum

Owner
Hein-Pieter van Braam
Hein-Pieter van Braam
Python Classes Without Boilerplate

attrs is the Python package that will bring back the joy of writing classes by relieving you from the drudgery of implementing object protocols (aka d

The attrs Cabal 4.6k Jan 2, 2023
Cirq is a Python library for writing, manipulating, and optimizing quantum circuits and running them against quantum computers and simulators

Cirq is a Python library for writing, manipulating, and optimizing quantum circuits and running them against quantum computers and simulators. Install

quantumlib 3.6k Jan 7, 2023
Viewflow is an Airflow-based framework that allows data scientists to create data models without writing Airflow code.

Viewflow Viewflow is a framework built on the top of Airflow that enables data scientists to create materialized views. It allows data scientists to f

DataCamp 114 Oct 12, 2022
A Python module for decorators, wrappers and monkey patching.

wrapt The aim of the wrapt module is to provide a transparent object proxy for Python, which can be used as the basis for the construction of function

Graham Dumpleton 1.8k Jan 6, 2023
Wrappers around the most common maya.cmds and maya.api use cases

Maya FunctionSet (maya_fn) A package that decompose core maya.cmds and maya.api features to a set of simple functions. Tests The recommended approach

Ryan Porter 9 Mar 12, 2022
A tool to flash .ofp files in bootloader mode without needing MSM Tool, an alternative to official realme tool

Oppo/Realme Flash .OFP File on Bootloader A tool to flash .ofp files in bootloader mode without needing MSM Tool, an alternative to official realme to

Italo Almeida 70 Jan 2, 2023
a bit of my project :) and I use some of them for my school lesson or study for an exam! but some of them just for myself.

Handy Project a bit of my project :) and I use some of them for my school lesson or study for an exam! but some of them just for myself. the handy pro

amirkasra esmaeilian 13 Jul 5, 2021
LSO, also known as Linux Swap Operator, is a software with both GUI and terminal versions that you can manage the Swap area for Linux operating systems.

LSO - Linux Swap Operator Türkçe - LSO Nedir? LSO, diğer adıyla Linux Swap Operator Linux işletim sistemleri için Swap alanını yönetebileceğiniz hem G

Eren İnce 4 Feb 9, 2022
List of Linux Tools I put on almost every linux / Debian host

Linux-Tools List of Linux Tools I put on almost every Linux / Debian host Installed: geany --> GUI editor/ notepad++ like chkservice --> TUI Linux ser

Stew Alexander 20 Jan 2, 2023
Organize seu linux - organize your linux

OrganizeLinux Organize seu linux - organize your linux Organize seu linux Uma forma rápida de separar arquivos dispersos em pastas. formatos a serem c

Marcus Vinícius Ribeiro Andrade 1 Nov 30, 2021