option to swap hooking libraries

This commit is contained in:
qimiko committed 2024-01-12 16:18:00 -07:00
1 parent 2de883d100
commit de48c6ecd6
3 files changed
+86 -20

No files matched your search

+1 -1
View File
@@ -19,7 +19,7 @@ android {
} }
externalNativeBuild { externalNativeBuild {
cmake { cmake {
arguments "-DDOBBY_DEBUG=OFF" arguments "-DUSE_TULIPHOOK:BOOL=OFF"
} }
} }
+27 -6
View File
@@ -4,14 +4,32 @@ project(launcherfix)
add_library(launcherfix SHARED launcher-fix.cpp) add_library(launcherfix SHARED launcher-fix.cpp)
target_compile_features(launcherfix PUBLIC cxx_std_20)
set_target_properties(launcherfix PROPERTIES CXX_EXTENSIONS OFF)
include(FetchContent) include(FetchContent)
FetchContent_Declare(dobby option(USE_TULIPHOOK "enables choice of hooking library" OFF)
GIT_REPOSITORY https://github.com/jmpews/Dobby if (USE_TULIPHOOK)
GIT_TAG 6a80a61ea062424d1595613058a174c64454fa57) FetchContent_Declare(TulipHook
GIT_REPOSITORY https://github.com/geode-sdk/TulipHook.git
GIT_TAG 70122be72da7787dc42813ba0a992f3612e7871e
)
FetchContent_GetProperties(dobby) set(TULIP_LINK_SOURCE ON CACHE INTERNAL "")
if(NOT dobby_POPULATED) FetchContent_MakeAvailable(TulipHook)
target_compile_definitions(launcherfix PRIVATE -DUSE_TULIPHOOK=1)
target_link_libraries(launcherfix PRIVATE TulipHook TulipHookInclude)
else()
FetchContent_Declare(dobby
GIT_REPOSITORY https://github.com/jmpews/Dobby
GIT_TAG 6a80a61ea062424d1595613058a174c64454fa57
)
FetchContent_GetProperties(dobby)
if(NOT dobby_POPULATED)
FetchContent_Populate(dobby) FetchContent_Populate(dobby)
# fixes Dobby build # fixes Dobby build
@@ -21,5 +39,8 @@ if(NOT dobby_POPULATED)
add_subdirectory("${dobby_SOURCE_DIR}" ${dobby_BINARY_DIR} EXCLUDE_FROM_ALL) add_subdirectory("${dobby_SOURCE_DIR}" ${dobby_BINARY_DIR} EXCLUDE_FROM_ALL)
target_include_directories(launcherfix PRIVATE ${dobby_SOURCE_DIR}/include) target_include_directories(launcherfix PRIVATE ${dobby_SOURCE_DIR}/include)
target_link_libraries(launcherfix dobby) target_link_libraries(launcherfix PRIVATE dobby)
endif()
endif() endif()
target_link_libraries(launcherfix PRIVATE log)
+58 -13
View File
@@ -1,11 +1,18 @@
#include <dlfcn.h> #include <dlfcn.h>
#include <jni.h> #include <jni.h>
#include <string> #include <string>
#include <android/log.h>
#ifndef DISABLE_LAUNCHER_FIX #ifndef DISABLE_LAUNCHER_FIX
#ifdef USE_TULIPHOOK
#include <tulip/TulipHook.hpp>
#else
#include <dobby.h> #include <dobby.h>
#endif #endif
#endif
class DataPaths { class DataPaths {
public: public:
std::string original_data_path; std::string original_data_path;
@@ -79,22 +86,60 @@ int rename_hook(const char* old_path, const char* new_path) {
return rename_original(old_path_str.c_str(), new_path_str.c_str()); return rename_original(old_path_str.c_str(), new_path_str.c_str());
} }
bool hook_function(void* addr, auto* hook, auto** orig) {
#ifdef USE_TULIPHOOK
using namespace tulip::hook;
HandlerMetadata metadata = {
std::make_shared<PlatformConvention>(),
AbstractFunction::from(hook)
};
auto handler_result = createHandler(addr, metadata);
if (!handler_result) {
__android_log_print(ANDROID_LOG_WARN, "GeodeLauncher-Fix",
"failed to create handler: %s\n", handler_result.unwrapErr().c_str());
return false;
}
auto handler = *handler_result;
HookMetadata hook_metadata = {0};
createHook(handler, reinterpret_cast<void*>(hook), hook_metadata);
WrapperMetadata wrapper_metadata = {
std::make_unique<PlatformConvention>(),
AbstractFunction::from(hook)
};
auto wrapper = createWrapper(addr, std::move(wrapper_metadata));
if (!wrapper) {
__android_log_print(ANDROID_LOG_WARN, "GeodeLauncher-Fix",
"failed to create wrapper: %s\n", wrapper.unwrapErr().c_str());
return false;
}
*reinterpret_cast<void**>(orig) = *wrapper;
return true;
#else
DobbyHook(
addr,
reinterpret_cast<dobby_dummy_func_t>(hook),
reinterpret_cast<dobby_dummy_func_t*>(orig)
);
return true;
#endif
}
[[gnu::constructor]] [[gnu::used]] void setup_hooks() { [[gnu::constructor]] [[gnu::used]] void setup_hooks() {
#ifndef DISABLE_LAUNCHER_FIX #ifndef DISABLE_LAUNCHER_FIX
auto fopen_addr = dlsym(RTLD_NEXT, "fopen"); auto fopen_addr = dlsym(RTLD_NEXT, "fopen");
hook_function(fopen_addr, &fopen_hook, &fopen_original);
auto rename_addr = dlsym(RTLD_NEXT, "rename"); auto rename_addr = dlsym(RTLD_NEXT, "rename");
hook_function(rename_addr, &rename_hook, &rename_original);
DobbyHook(
fopen_addr,
reinterpret_cast<dobby_dummy_func_t>(&fopen_hook),
reinterpret_cast<dobby_dummy_func_t*>(&fopen_original)
);
DobbyHook(
rename_addr,
reinterpret_cast<dobby_dummy_func_t>(&rename_hook),
reinterpret_cast<dobby_dummy_func_t*>(&rename_original)
);
#endif #endif
} }