fix application directory

This commit is contained in:
qimiko committed 2022-05-27 21:20:07 -07:00
1 parent 332069bc92
commit 3cba74c4bc
8 files changed
+136 -1

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
cmake_minimum_required(VERSION 3.18.1)
project(launcherfix)
add_library(launcherfix SHARED launcher-fix.cpp)
find_library(log-lib log)
target_link_libraries(launcherfix ${log-lib})
include(FetchContent)
FetchContent_Declare(dobby
GIT_REPOSITORY https://github.com/jmpews/Dobby
GIT_TAG 223aabced0431525c7d45196f9409fc505d58ac8)
FetchContent_GetProperties(dobby)
if(NOT dobby_POPULATED)
FetchContent_Populate(dobby)
set(DOBBY_DEBUG OFF CACHE INTERNAL "" FORCE)
set(DOBBY_GENERATE_SHARED OFF CACHE INTERNAL "" FORCE)
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)
endif()
+71
View File
@@ -0,0 +1,71 @@
#include <dlfcn.h>
#include <android/log.h>
#include <string>
#include <dobby.h>
#include <jni.h>
class DataPaths {
public:
std::string original_data_path;
std::string data_path;
static DataPaths& get_instance() {
static auto paths_instance = DataPaths();
return paths_instance;
}
private:
DataPaths() : original_data_path(), data_path() {}
};
extern "C"
JNIEXPORT void JNICALL Java_dev_xyze_geodelauncher_LauncherFix_setDataPath(
JNIEnv *env,
jobject,
jstring data_path
) {
auto is_copy = jboolean();
auto data_path_str = env->GetStringUTFChars(data_path, &is_copy);
DataPaths::get_instance().data_path = std::string(data_path_str);
}
extern "C"
JNIEXPORT void JNICALL Java_dev_xyze_geodelauncher_LauncherFix_setOriginalDataPath(
JNIEnv *env,
jobject,
jstring data_path
) {
auto is_copy = jboolean();
auto data_path_str = env->GetStringUTFChars(data_path, &is_copy);
DataPaths::get_instance().original_data_path = std::string(data_path_str);
}
FILE* (*fopen_original)(const char *pathname, const char *mode);
FILE* fopen_hook(const char* pathname, const char* mode) {
auto data_path = DataPaths::get_instance().data_path;
auto original_data_path = DataPaths::get_instance().original_data_path;
if (!data_path.empty() && !original_data_path.empty()) {
auto path_str = std::string(pathname);
auto pos = path_str.find(original_data_path);
if (pos != std::string::npos) {
path_str.replace(pos, original_data_path.length(), data_path);
}
return fopen_original(path_str.c_str(), mode);
}
return fopen_original(pathname, mode);
}
[[gnu::constructor]] [[gnu::used]] void setup_hooks() {
auto fopen_addr = dlsym(RTLD_NEXT, "fopen");
DobbyHook(
fopen_addr,
reinterpret_cast<void*>(&fopen_hook),
reinterpret_cast<void**>(&fopen_original)
);
}