Skip to content

A lib to help you override symbols that loaded by dlsym

License

Notifications You must be signed in to change notification settings

edimetia3d/power_override

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PowerOverride

PowerOverride is a lib to help you override symbols that loaded by dlsym

Just compile to a shared lib, and use LD_PRELOAD.

Installation

Just add_subdirectory().

Note: this project's CMakeLists is organized by target_xxx API. i.e. target_foo must link poweroverride to let src files in target_foo access header files of poweroverride

Quick Start

  1. Only override functions loaded by dlsym in libfoo.so. Just define a function by using POWER_OVERRIDE
#include
"poweroverride/power_override.hpp"

POWER_OVERRIDE(void, foo, (int a, int b), "libfoo.so") { // the filename rule is same as `dlopen`
  auto raw = RawFn();
  do_sth();
}
  1. If libfoo.so is also linked by some part of your code, you may want to add a normal function to override these linked symbol. Because PowerOverride will not override symbols that are resloved by dynamic linker.
extern "C"{
void foo(int a, int b){
  auto raw = dlsym(RTLD_NEXT, "foo");
  do_sth();
}
}
  1. If you dlopend many lib that contains same symbol, e.g. color() in libapple.so and liborange.so You may want to add more POWER_OVERRIDE, to override other libs. because POWER_OVERRIDE only override one shared obj.
#include
"poweroverride/power_override.hpp"

POWER_OVERRIDE(void, foo, (int a, int b), "libbar.so") {
 auto raw = RawFn(); // Note, this RawFn() will return raw function pointer from "libbar.so" , not "libfoo.so"
 do_sth();
}
  1. All override are under your control. If you want to share some code, you could abstract a do_sth() just like previous example. If Not, just implement function as you want.

About

A lib to help you override symbols that loaded by dlsym

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published