give me eglswapbuffer imgui hook for android game
생성일: 2025년 8월 18일
생성일: 2025년 8월 18일
give me eglswapbuffer imgui hook for android game
Hooking into eglSwapBuffers for an Android game to implement an ImGui overlay is a technique commonly used in game modding and reverse engineering. However, it requires low-level access, and it may violate the terms of service of the game or platform. Proceed only if you have legal permission to do so.
That said, here’s a general approach to hooking eglSwapBuffers and integrating ImGui on Android (especially via an injected shared library):
LD_PRELOAD injectionBelow is a simplified example using inline hooking via MHook, PLT hooking, or Dobby (alternatively use dlsym if you’re not using a hooking framework).
cpp#include <EGL/egl.h> #include <GLES2/gl2.h> #include <dlfcn.h> typedef EGLBoolean (*eglSwapBuffers_t)(EGLDisplay display, EGLSurface surface); eglSwapBuffers_t orig_eglSwapBuffers = nullptr; EGLBoolean hooked_eglSwapBuffers(EGLDisplay display, EGLSurface surface) { static bool initialized = false; if (!initialized) { // Setup ImGui and OpenGL state here ImGui_ImplAndroid_Init(); ImGui_ImplOpenGL3_Init("#version 100"); initialized = true; } // Start new frame ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplAndroid_NewFrame(); ImGui::NewFrame(); // Your overlay UI here ImGui::Begin("Injected Overlay"); ImGui::Text("Hello from ImGui!"); ImGui::End(); // Render UI ImGui::Render(); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); // Call the original function return orig_eglSwapBuffers(display, surface); } __attribute__((constructor)) void lib_main() { void* handle = dlopen("libEGL.so", RTLD_LAZY); void* sym = dlsym(handle, "eglSwapBuffers"); if (sym) { orig_eglSwapBuffers = (eglSwapBuffers_t)sym; // Replace with a hooking framework of choice hook_function(sym, (void*)hooked_eglSwapBuffers, (void**)&orig_eglSwapBuffers); } }
imgui + imgui_impl_android.cpp + imgui_impl_opengl3.cpp backend.eglSwapBuffers call.libEGL.so) can break apps or crash games if not handled carefully.If you want a full project template (CMake + JNI + ImGui + hook setup), let me know — I can generate a boilerplate setup.
Do you have any of the following already set up?
Let me know and I can tailor the solution.
use lsposed for hooking
Using LSPosed (based on Riru or Zygisk) to hook eglSwapBuffers and render ImGui overlays in an Android game is a powerful approach. Here's a full guide and code template to get you started.
You're going to:
eglSwapBuffers() using inline or PLT hooking.textlsposed-imgui-overlay/ ├── module/ │ ├── Android.mk / CMakeLists.txt │ ├── entry.cpp <-- LSPosed hook entry │ ├── imgui/ <-- ImGui sources │ ├── hooks/ │ │ └── egl_hook.cpp <-- eglSwapBuffers hook │ └── include/
This is the entry point for your LSPosed module:
cpp#include <xhook.h> #include <jni.h> #include <unistd.h> #include "hooks/egl_hook.h" extern "C" void onLoad() { // Hook eglSwapBuffers from libEGL xhook_register(".*libEGL.so$", "eglSwapBuffers", (void*)hooked_eglSwapBuffers, (void**)&orig_eglSwapBuffers); xhook_refresh(0); } extern "C" __attribute__((visibility("default"))) JNIEXPORT void JNICALL Java_com_example_lsposed_Overlay_init(JNIEnv* env, jobject clazz) { onLoad(); }
cpp#include <EGL/egl.h> #include <GLES2/gl2.h> #include "imgui.h" #include "backends/imgui_impl_android.h" #include "backends/imgui_impl_opengl3.h" typedef EGLBoolean (*eglSwapBuffers_t)(EGLDisplay display, EGLSurface surface); eglSwapBuffers_t orig_eglSwapBuffers = nullptr; EGLBoolean hooked_eglSwapBuffers(EGLDisplay display, EGLSurface surface) { static bool initialized = false; if (!initialized) { ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); io.DisplaySize = ImVec2(1080, 1920); // Customize based on resolution ImGui_ImplAndroid_Init(nullptr); // Pass JNIEnv + Surface if needed ImGui_ImplOpenGL3_Init("#version 100"); initialized = true; } ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplAndroid_NewFrame(); ImGui::NewFrame(); ImGui::Begin("LSPosed Overlay"); ImGui::Text("Hello from ImGui LSPosed!"); ImGui::End(); ImGui::Render(); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); return orig_eglSwapBuffers(display, surface); }
cmakecmake_minimum_required(VERSION 3.6) project(lsposed_imgui) add_library(lsposed_imgui SHARED entry.cpp hooks/egl_hook.cpp imgui/imgui.cpp imgui/imgui_draw.cpp imgui/imgui_widgets.cpp imgui/backends/imgui_impl_android.cpp imgui/backends/imgui_impl_opengl3.cpp ) find_library(log-lib log) target_link_libraries(lsposed_imgui ${log-lib} EGL GLESv2)
Create a file module.prop:
textid=imgui.overlay name=ImGui Overlay version=1.0 author=you description=ImGui overlay for Android games via LSPosed
ImGui_ImplAndroid_Init() gets the proper ANativeWindow if rendering fails.xhook (or Dobby, or PLTHook) to reliably hook symbols.eglMakeCurrent is called before rendering ImGui, or your overlay will not show.glGetIntegerv() or JNI window access.Would you like me to generate a full zip of this LSPosed module ready to build, or help with a specific hooking method (e.g., Dobby instead of xhook)?