diff options
author | Jan200101 <sentrycraft123@gmail.com> | 2023-09-04 18:21:18 +0200 |
---|---|---|
committer | Jan200101 <sentrycraft123@gmail.com> | 2023-09-04 18:21:18 +0200 |
commit | 1e487eca2304936919e777f8ad06a99f28c7528d (patch) | |
tree | 540437871b2d6a0fda7e58e000f1325592c8c7ec | |
parent | ad0ebfa7c2b9149311142db7717416538dd1fc9b (diff) | |
download | inject_so-master.tar.gz inject_so-master.zip |
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | example/CMakeLists.txt | 14 | ||||
-rw-r--r-- | example/lib.c | 7 | ||||
-rw-r--r-- | example/target.c | 14 | ||||
-rw-r--r-- | src/inject.c | 2 |
5 files changed, 37 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 288ba2d..11ff281 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,4 +13,5 @@ project(inject_so VERSION 0.0.0 LANGUAGES C) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) +add_subdirectory(example) add_subdirectory(src) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt new file mode 100644 index 0000000..ea5871c --- /dev/null +++ b/example/CMakeLists.txt @@ -0,0 +1,14 @@ + +set(LIB_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/lib.c) +set(TARGET_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/target.c) + +set(CMAKE_SHARED_LIBRARY_PREFIX "") +add_library(lib SHARED ${LIB_SOURCE}) +add_executable(target ${TARGET_SOURCE}) + +if(CMAKE_SIZEOF_VOID_P EQUAL 8) + add_library(lib32 SHARED ${LIB_SOURCE}) + set_target_properties(lib32 PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32") + add_executable(target32 ${TARGET_SOURCE}) + set_target_properties(target32 PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32") +endif()
\ No newline at end of file diff --git a/example/lib.c b/example/lib.c new file mode 100644 index 0000000..6622e56 --- /dev/null +++ b/example/lib.c @@ -0,0 +1,7 @@ +#include <unistd.h> +#include <stdio.h> + +void __attribute__((constructor)) lib_entry() +{ + printf("Injected into %li\n", getpid()); +} diff --git a/example/target.c b/example/target.c new file mode 100644 index 0000000..fc34b9d --- /dev/null +++ b/example/target.c @@ -0,0 +1,14 @@ +#include <stdio.h> +#include <unistd.h> + +int main() +{ + printf("pid %li\n", getpid()); + while (1) + { + printf("waiting...\n"); + sleep(2); + } + + return 1; +}
\ No newline at end of file diff --git a/src/inject.c b/src/inject.c index 96012b6..58b05c2 100644 --- a/src/inject.c +++ b/src/inject.c @@ -284,7 +284,7 @@ int load_library(pid_t pid, char* lib_path) if (lib_mod.size) return 1; - struct module_s libc_ex = getModule(pid, "libshim.so"); + struct module_s libc_ex = getModule(pid, "libc.so"); uintptr_t offset = getSymbolOffset(libc_ex.path, "dlopen"); // fallback |