Giter Site home page Giter Site logo

libshim's Introduction

libshim

Shim library to resolve undefined runtime symbols

Usage

This library allows to make re-export of undefined symbols to solve runtime errors. In some cases linker can't find symbols in runtime. It can be solved through extern "C" void symbol() but isn't suitable when binary file contains ton of classes and looks ugly.

The point of view is to generate proxies for unresolved symbols. This library can be statically linked with cmake project and provide SYMBOLS_SHIM_PATH variable, which is wrapper around assembler macro.

Example CMakeLists.txt

cmake_minimum_required(VERSION 3.11)
project(injector)

set(CMAKE_CXX_STANDARD 11)

#libshim
include(FetchContent)

set(LIBSHIM_BUILD_TYPE "STATIC" CACHE INTERNAL "")
set(SYMBOLS_SHIM_PATH "${PROJECT_SOURCE_DIR}/shim_demo" CACHE INTERNAL "")
FetchContent_Declare(shim
    GIT_REPOSITORY https://github.com/Frago9876543210/libshim
    GIT_TAG 1.0.0)
FetchContent_MakeAvailable(shim)

add_library(injector SHARED injector.cpp)
target_link_libraries(injector PRIVATE shim)

shim_demo file looks like that: (It can be specified using SYMBOLS_SHIM_PATH variable)

//This file is included into `shim.S` and actually is assembly language
//but it's assumed that only symbol_shim <undefined_symbol> <actual_symbol> macro used
symbol_shim _ZN14string_wrapperC1EPcm _ZN14string_wrapperC2EPcm
symbol_shim _ZN14string_wrapperD1Ev _ZN14string_wrapperD2Ev

Macro define undefined_symbol and put jmp actual_symbol@PLT into it's code. Here's an example c-like macro to better explain:

#define symbol_shim(undefined_symbol, actual_symbol)  \
__asm {                                               \
    undefined_symbol: #create label                   \
        jmp actual_symbol@PLT #jump to defined symbol \
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.