mirror of
https://github.com/geode-sdk/android-launcher.git
synced 2026-10-21 00:18:18 +00:00
fix application directory
This commit is contained in:
8 files changed
+136
-1
No files matched your search
@@ -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()
|
||||
@@ -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)
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user