forked from geode-sdk/android-launcher
option to swap hooking libraries
This commit is contained in:
3 files changed
+86
-20
No files matched your search
+1
-1
@@ -19,7 +19,7 @@ android {
|
||||
}
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
arguments "-DDOBBY_DEBUG=OFF"
|
||||
arguments "-DUSE_TULIPHOOK:BOOL=OFF"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,14 +4,32 @@ project(launcherfix)
|
||||
|
||||
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)
|
||||
|
||||
FetchContent_Declare(dobby
|
||||
GIT_REPOSITORY https://github.com/jmpews/Dobby
|
||||
GIT_TAG 6a80a61ea062424d1595613058a174c64454fa57)
|
||||
option(USE_TULIPHOOK "enables choice of hooking library" OFF)
|
||||
if (USE_TULIPHOOK)
|
||||
FetchContent_Declare(TulipHook
|
||||
GIT_REPOSITORY https://github.com/geode-sdk/TulipHook.git
|
||||
GIT_TAG 70122be72da7787dc42813ba0a992f3612e7871e
|
||||
)
|
||||
|
||||
FetchContent_GetProperties(dobby)
|
||||
if(NOT dobby_POPULATED)
|
||||
set(TULIP_LINK_SOURCE ON CACHE INTERNAL "")
|
||||
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)
|
||||
|
||||
# fixes Dobby build
|
||||
@@ -21,5 +39,8 @@ if(NOT dobby_POPULATED)
|
||||
|
||||
add_subdirectory("${dobby_SOURCE_DIR}" ${dobby_BINARY_DIR} EXCLUDE_FROM_ALL)
|
||||
target_include_directories(launcherfix PRIVATE ${dobby_SOURCE_DIR}/include)
|
||||
target_link_libraries(launcherfix dobby)
|
||||
target_link_libraries(launcherfix PRIVATE dobby)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
target_link_libraries(launcherfix PRIVATE log)
|
||||
@@ -1,11 +1,18 @@
|
||||
#include <dlfcn.h>
|
||||
#include <jni.h>
|
||||
#include <string>
|
||||
#include <android/log.h>
|
||||
|
||||
#ifndef DISABLE_LAUNCHER_FIX
|
||||
|
||||
#ifdef USE_TULIPHOOK
|
||||
#include <tulip/TulipHook.hpp>
|
||||
#else
|
||||
#include <dobby.h>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
class DataPaths {
|
||||
public:
|
||||
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());
|
||||
}
|
||||
|
||||
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() {
|
||||
#ifndef DISABLE_LAUNCHER_FIX
|
||||
auto fopen_addr = dlsym(RTLD_NEXT, "fopen");
|
||||
hook_function(fopen_addr, &fopen_hook, &fopen_original);
|
||||
|
||||
auto rename_addr = dlsym(RTLD_NEXT, "rename");
|
||||
|
||||
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)
|
||||
);
|
||||
|
||||
hook_function(rename_addr, &rename_hook, &rename_original);
|
||||
#endif
|
||||
}
|
||||
Reference in new issue
Block a user