-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtouch.cpp
More file actions
57 lines (42 loc) · 1.64 KB
/
touch.cpp
File metadata and controls
57 lines (42 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// Created by mrjar on 12/1/2025.
//
#include "touch.h"
#include "imgui/imgui.h"
#include "imgui/backends/imgui_impl_android.h"
#include <android/input.h>
#include <stdio.h>
extern "C" {
#include "inlinehook.h"
#include "dynlib.h"
}
typedef int32_t (*new_input_t)(void*, void*, bool, long, void*, void**);
static new_input_t orig_new_input = nullptr;
static int32_t hook_new_input(void* instanceThiz, void* param1, bool param2, long param3, void* param4, void** thiz_ptr) {
printf("[Touch] hook_new_input: called (instance=%p param2=%d param3=%ld)\n",
instanceThiz, param2, param3);
int32_t result = orig_new_input(instanceThiz, param1, param2, param3, param4, thiz_ptr);
if (thiz_ptr && *thiz_ptr) {
printf("[Touch] Forwarding touch event to ImGui (AInputEvent=%p)\n", *thiz_ptr);
ImGui_ImplAndroid_HandleInputEvent((AInputEvent*)(*thiz_ptr));
} else {
printf("[Touch] No AInputEvent to forward.\n");
}
return result;
}
void hook_touch() {
printf("[HOOK] Installing touch hook...\n");
const char* consume_symbol =
"_ZN7android13InputConsumer7consumeEPNS_26InputEventFactoryInterfaceEblPjPPNS_10InputEventE";
void* touch_sym = gpwn_dlsym("libinput.so", consume_symbol);
if (touch_sym) {
printf("[HOOK] Found InputConsumer::consume @ %p\n", touch_sym);
hook_addr(touch_sym,
(void*)hook_new_input,
(void**)&orig_new_input,
GPWN_AARCH64_LEGACYHOOK);
printf("[HOOK] Touch hook successfully installed.\n");
} else {
printf("[HOOK] ERROR: Failed to find InputConsumer::consume symbol!\n");
}
}