mirror of
https://github.com/0O0o0oOoO00/Alas.git
synced 2026-05-17 01:59:28 +08:00
104 lines
3.2 KiB
C++
104 lines
3.2 KiB
C++
#include <spdlog/spdlog.h>
|
|
#include <android/input.h>
|
|
#include <dlfcn.h>
|
|
#include <EGL/egl.h>
|
|
|
|
#include "hook.hpp"
|
|
#include "dobby.h"
|
|
#include "ui.hpp"
|
|
#include "imgui/imgui.h"
|
|
#include "imgui/imgui_impl_android.h"
|
|
#include "imgui/imgui_impl_opengl3.h"
|
|
|
|
using eglSwapBuffers_fnT = EGLBoolean(EGLDisplay dpy, EGLSurface surface);
|
|
eglSwapBuffers_fnT* old_eglSwapBuffers = nullptr;
|
|
|
|
EGLBoolean my_eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) {
|
|
ui_eglSwapBuffers(dpy, surface);
|
|
return old_eglSwapBuffers(dpy, surface);
|
|
}
|
|
|
|
#ifdef USE_32
|
|
using Input_fnT = int32_t(void* thiz, void* ex_ab, void* ex_ac);
|
|
#endif
|
|
#ifdef USE_64
|
|
using Input_fnT = int64_t(void* thiz, void* ex_ab, void* ex_ac);
|
|
#endif
|
|
Input_fnT* old_Input = nullptr;
|
|
|
|
#ifdef USE_32
|
|
int32_t my_Input(void* thiz, void* ex_ab, void* ex_ac)
|
|
#endif
|
|
#ifdef USE_64
|
|
int64_t my_Input(void* thiz, void* ex_ab, void* ex_ac)
|
|
#endif
|
|
{
|
|
auto ret = old_Input(thiz, ex_ab, ex_ac);
|
|
ImGui_ImplAndroid_HandleInputEvent((AInputEvent *) thiz);
|
|
return ret;
|
|
}
|
|
|
|
#ifdef USE_32
|
|
using Consume_fnT = int32_t(void* thiz, void* arg1, bool arg2, long arg3, uint32_t* arg4, AInputEvent** input_event);
|
|
#endif
|
|
#ifdef USE_64
|
|
using Consume_fnT = int64_t(void* thiz, int64_t arg1, char arg2, int64_t arg3, uint32_t* arg4, AInputEvent** input_event);
|
|
#endif
|
|
Consume_fnT* old_Consume = nullptr;
|
|
|
|
#ifdef USE_32
|
|
int32_t my_Consume(void* thiz, void* arg1, bool arg2, long arg3, uint32_t* arg4, AInputEvent** input_event)
|
|
#endif
|
|
#ifdef USE_64
|
|
int64_t my_Consume(void* thiz, int64_t arg1, char arg2, int64_t arg3, uint32_t* arg4, AInputEvent** input_event)
|
|
#endif
|
|
{
|
|
SPDLOG_INFO("my_Consume Called");
|
|
auto result = old_Consume(thiz, arg1, arg2, arg3, arg4, input_event);
|
|
if(result != 0 || *input_event == nullptr)
|
|
return result;
|
|
ImGui_ImplAndroid_HandleInputEvent(*input_event);
|
|
return result;
|
|
}
|
|
|
|
bool has_hooked = false;
|
|
|
|
#ifdef USE_32
|
|
#define INPUT_SO "/system/lib/libinput.so"
|
|
#endif
|
|
#ifdef USE_64
|
|
#define INPUT_SO "/system/lib64/libinput.so"
|
|
#endif
|
|
|
|
#ifdef USE_32
|
|
#define EGL_SO "/system/lib/libEGL.so"
|
|
#endif
|
|
#ifdef USE_64
|
|
#define EGL_SO "/system/lib64/libEGL.so"
|
|
#endif
|
|
|
|
#define android_InputConsumer_initializeMotionEvent "_ZN7android13InputConsumer21initializeMotionEventEPNS_11MotionEventEPKNS_12InputMessageE"
|
|
#define android_InputConsumer_consume "_ZN7android13InputConsumer7consumeEPNS_26InputEventFactoryInterfaceEblPjPPNS_10InputEventE"
|
|
|
|
void do_hook() {
|
|
if (has_hooked) {
|
|
return;
|
|
}
|
|
|
|
auto eglhandle = dlopen(EGL_SO, RTLD_LAZY);
|
|
auto sym_eglSwapBuffers = dlsym(eglhandle, "eglSwapBuffers");
|
|
DobbyHook(reinterpret_cast<void*>(sym_eglSwapBuffers), reinterpret_cast<void*>(my_eglSwapBuffers), reinterpret_cast<void **>(&old_eglSwapBuffers));
|
|
|
|
void* sym_input = DobbySymbolResolver(INPUT_SO, android_InputConsumer_initializeMotionEvent);
|
|
if(sym_input != nullptr) {
|
|
DobbyHook(sym_input, reinterpret_cast<void*>(my_Input), reinterpret_cast<void **>(&old_Input));
|
|
} else {
|
|
sym_input = DobbySymbolResolver(INPUT_SO, android_InputConsumer_consume);
|
|
if(sym_input != nullptr) {
|
|
DobbyHook(sym_input, reinterpret_cast<void*>(my_Consume), reinterpret_cast<void **>(&old_Consume));
|
|
}
|
|
}
|
|
has_hooked = true;
|
|
SPDLOG_INFO("Hook done!");
|
|
}
|