1
0
mirror of https://github.com/0O0o0oOoO00/Alas.git synced 2026-05-16 12:59:29 +08:00
Files
Alas/blcrack/cracker/ui/hook.cpp
2025-09-03 19:03:19 +08:00

61 lines
2.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);
}
using Input_fnT = void(void* thiz, void* ex_ab, void* ex_ac);
Input_fnT* old_Input = nullptr;
void my_Input(void* thiz, void* ex_ab, void* ex_ac) {
old_Input(thiz, ex_ab, ex_ac);
ImGui_ImplAndroid_HandleInputEvent((AInputEvent *) thiz);
}
using Consume_fnT = int32_t(void* thiz, void* arg1, bool arg2, long arg3, uint32_t* arg4, AInputEvent** input_event);
Consume_fnT* old_Consume = nullptr;
int32_t my_Consume(void* thiz, void* arg1, bool arg2, long arg3, uint32_t* arg4, AInputEvent** input_event) {
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;
void do_hook() {
if (has_hooked) {
return;
}
auto eglhandle = dlopen("libunity.so", RTLD_LAZY);
auto eglSwapBuffers = dlsym(eglhandle, "eglSwapBuffers");
DobbyHook(eglSwapBuffers, reinterpret_cast<void*>(my_eglSwapBuffers), reinterpret_cast<void **>(&old_eglSwapBuffers));
void* sym_input = DobbySymbolResolver("/system/lib/libinput.so", "_ZN7android13InputConsumer21initializeMotionEventEPNS_11MotionEventEPKNS_12InputMessageE");
if(sym_input != nullptr) {
DobbyHook(sym_input, reinterpret_cast<void*>(my_Input), reinterpret_cast<void **>(&old_Input));
} else {
sym_input = DobbySymbolResolver("/system/lib/libinput.so", "_ZN7android13InputConsumer7consumeEPNS_26InputEventFactoryInterfaceEblPjPPNS_10InputEventE");
if(sym_input != nullptr) {
DobbyHook(sym_input, reinterpret_cast<void*>(my_Consume), reinterpret_cast<void **>(&old_Consume));
}
}
has_hooked = true;
SPDLOG_INFO("Hook done!");
}