Skip to content

Commit 12a4858

Browse files
committed
нобдод када раст
1 parent 1610a11 commit 12a4858

File tree

438 files changed

+297
-1325
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

438 files changed

+297
-1325
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
build
2+
out
3+
super_secret_folder_with_galaxium
4+
.vscode

Build.bat

-23
This file was deleted.

CMakeLists.txt

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
cmake_minimum_required(VERSION 3.21.3)
2+
3+
set(CMAKE_CXX_STANDARD 20)
4+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
5+
set(CMAKE_CXX_EXTENSIONS OFF)
6+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/out)
7+
set(CMAKE_SYSTEM_NAME Android)
8+
set(CMAKE_SYSTEM_VERSION 21)
9+
set(CMAKE_ANDROID_ARCH_ABI armeabi-v7a) # armeabi-v7a / x86 (untested)
10+
set(CMAKE_ANDROID_STL_TYPE c++_static)
11+
set(MODNAME gdmod)
12+
13+
project(${MODNAME} VERSION 1.0.0)
14+
15+
add_library(${MODNAME} SHARED
16+
src/main.cpp
17+
)
18+
19+
target_include_directories(${MODNAME} PRIVATE
20+
${CMAKE_CURRENT_SOURCE_DIR}/include
21+
${CMAKE_CURRENT_SOURCE_DIR}/include/gd
22+
${CMAKE_CURRENT_SOURCE_DIR}/include/cocos2dx
23+
${CMAKE_CURRENT_SOURCE_DIR}/include/cocos2dx/include
24+
${CMAKE_CURRENT_SOURCE_DIR}/include/cocos2dx/kazmath/include
25+
${CMAKE_CURRENT_SOURCE_DIR}/include/cocos2dx/platform/android
26+
${CMAKE_CURRENT_SOURCE_DIR}/include/extensions
27+
)
28+
29+
target_link_libraries(${MODNAME} ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_ANDROID_ARCH_ABI}/libcocos2dcpp.so)
30+
target_link_libraries(${MODNAME} ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_ANDROID_ARCH_ABI}/libdobby.a)
31+
32+
install(TARGETS ${MODNAME} LIBRARY)

README.md

+17-18

build.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
mkdir build
2+
cd build
3+
cmake .. -DCMAKE_ANDROID_NDK=$NDK
4+
cmake --build .
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

include/dobby.h

+190
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
#ifndef dobby_h
2+
#define dobby_h
3+
4+
// obfuscated interface
5+
#if 0
6+
#define DobbyBuildVersion c343f74888dffad84d9ad08d9c433456
7+
#define DobbyHook c8dc3ffa44f22dbd10ccae213dd8b1f8
8+
#define DobbyInstrument b71e27bca2c362de90c1034f19d839f9
9+
#endif
10+
11+
#ifdef __cplusplus
12+
extern "C" {
13+
#endif
14+
15+
#include <stdbool.h>
16+
#include <stdint.h>
17+
18+
void log_set_level(int level);
19+
void log_switch_to_syslog();
20+
void log_switch_to_file(const char *path);
21+
22+
typedef enum {
23+
kMemoryOperationSuccess,
24+
kMemoryOperationError,
25+
kNotSupportAllocateExecutableMemory,
26+
kNotEnough,
27+
kNone
28+
} MemoryOperationError;
29+
30+
#define PLATFORM_INTERFACE_CODE_PATCH_TOOL_H
31+
MemoryOperationError CodePatch(void *address, uint8_t *buffer, uint32_t buffer_size);
32+
33+
typedef uintptr_t addr_t;
34+
typedef uint32_t addr32_t;
35+
typedef uint64_t addr64_t;
36+
37+
#if defined(__arm64__) || defined(__aarch64__)
38+
39+
#define ARM64_TMP_REG_NDX_0 17
40+
41+
// float register
42+
typedef union _FPReg {
43+
__int128_t q;
44+
struct {
45+
double d1;
46+
double d2;
47+
} d;
48+
struct {
49+
float f1;
50+
float f2;
51+
float f3;
52+
float f4;
53+
} f;
54+
} FPReg;
55+
56+
// register context
57+
typedef struct _RegisterContext {
58+
uint64_t dmmpy_0; // dummy placeholder
59+
uint64_t sp;
60+
61+
uint64_t dmmpy_1; // dummy placeholder
62+
union {
63+
uint64_t x[29];
64+
struct {
65+
uint64_t x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20, x21, x22,
66+
x23, x24, x25, x26, x27, x28;
67+
} regs;
68+
} general;
69+
70+
uint64_t fp;
71+
uint64_t lr;
72+
73+
union {
74+
FPReg q[32];
75+
struct {
76+
FPReg q0, q1, q2, q3, q4, q5, q6, q7;
77+
// [!!! READ ME !!!]
78+
// for Arm64, can't access q8 - q31, unless you enable full floating-point register pack
79+
FPReg q8, q9, q10, q11, q12, q13, q14, q15, q16, q17, q18, q19, q20, q21, q22, q23, q24, q25, q26, q27, q28, q29,
80+
q30, q31;
81+
} regs;
82+
} floating;
83+
} RegisterContext;
84+
#elif defined(__arm__)
85+
typedef struct _RegisterContext {
86+
uint32_t dummy_0;
87+
uint32_t dummy_1;
88+
89+
uint32_t dummy_2;
90+
uint32_t sp;
91+
92+
union {
93+
uint32_t r[13];
94+
struct {
95+
uint32_t r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12;
96+
} regs;
97+
} general;
98+
99+
uint32_t lr;
100+
} RegisterContext;
101+
#elif defined(_M_IX86) || defined(__i386__)
102+
typedef struct _RegisterContext {
103+
uint32_t dummy_0;
104+
uint32_t esp;
105+
106+
uint32_t dummy_1;
107+
uint32_t flags;
108+
109+
union {
110+
struct {
111+
uint32_t eax, ebx, ecx, edx, ebp, esp, edi, esi;
112+
} regs;
113+
} general;
114+
115+
} RegisterContext;
116+
#elif defined(_M_X64) || defined(__x86_64__)
117+
typedef struct _RegisterContext {
118+
uint64_t dummy_0;
119+
uint64_t rsp;
120+
121+
union {
122+
struct {
123+
uint64_t rax, rbx, rcx, rdx, rbp, rsp, rdi, rsi, r8, r9, r10, r11, r12, r13, r14, r15;
124+
} regs;
125+
} general;
126+
127+
uint64_t dummy_1;
128+
uint64_t flags;
129+
} RegisterContext;
130+
#endif
131+
132+
#define RT_FAILED -1
133+
#define RT_SUCCESS 0
134+
typedef enum _RetStatus { RS_FAILED = -1, RS_SUCCESS = 0 } RetStatus;
135+
136+
typedef struct _HookEntryInfo {
137+
int hook_id;
138+
union {
139+
void *target_address;
140+
void *function_address;
141+
void *instruction_address;
142+
};
143+
} HookEntryInfo;
144+
145+
// DobbyWrap <==> DobbyInstrument, so use DobbyInstrument instead of DobbyWrap
146+
#if 0
147+
// wrap function with pre_call and post_call
148+
typedef void (*PreCallTy)(RegisterContext *ctx, const HookEntryInfo *info);
149+
typedef void (*PostCallTy)(RegisterContext *ctx, const HookEntryInfo *info);
150+
int DobbyWrap(void *function_address, PreCallTy pre_call, PostCallTy post_call);
151+
#endif
152+
153+
// return dobby build date
154+
const char *DobbyBuildVersion();
155+
156+
// replace function
157+
int DobbyHook(void *address, void *replace_call, void **origin_call);
158+
159+
// dynamic binary instrument for instruction
160+
// [!!! READ ME !!!]
161+
// for Arm64, can't access q8 - q31, unless you enable full floating-point register pack
162+
typedef void (*DBICallTy)(RegisterContext *ctx, const HookEntryInfo *info);
163+
int DobbyInstrument(void *address, DBICallTy dbi_call);
164+
165+
// destory and restore hook
166+
int DobbyDestroy(void *address);
167+
168+
// iterate symbol table and find symbol
169+
void *DobbySymbolResolver(const char *image_name, const char *symbol_name);
170+
171+
// global offset table
172+
int DobbyGlobalOffsetTableReplace(char *image_name, char *symbol_name, void *fake_func, void **orig_func);
173+
174+
// [!!! READ ME !!!]
175+
// for arm, Arm64, dobby will use b xxx instead of ldr absolute indirect branch
176+
// for x64, dobby always use absolute indirect jump
177+
#if defined(__arm__) || defined(__arm64__) || defined(__aarch64__) || defined(_M_X64) || defined(__x86_64__)
178+
void dobby_enable_near_branch_trampoline();
179+
void dobby_disable_near_branch_trampoline();
180+
#endif
181+
182+
// register linker load image callback
183+
typedef void (*linker_load_callback_t)(const char *image_name, void *handle);
184+
void dobby_register_image_load_callback(linker_load_callback_t func);
185+
186+
#ifdef __cplusplus
187+
}
188+
#endif
189+
190+
#endif

0 commit comments

Comments
 (0)