Skip to content

Add files via upload #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
[![Discord](https://img.shields.io/discord/720937884814671923?color=%237289DA&logo=discord&logoColor=%23fff&style=for-the-badge)](https://discord.gg/bmRF2ac)
![Size](https://img.shields.io/github/repo-size/Octowolve/Hooking-Template-With-Mod-Menu?style=for-the-badge)

This is a simple template for the usage of Cydia Substrate and And64InlineHook with a Mod Menu written in Java.

### Implementation:
* https://piin.dev/android-mod-menu-implementation/
* Read this tutorial carefully
This is a simple template for the usage of Dobby with a Mod Menu written in Java.

### Tutorial:
* https://guidedhacking.com/threads/function-pointers-and-a-tutorial-for-my-hooking-template.14771/#post-90490
Expand All @@ -24,5 +20,4 @@ This is how the menu looks like when you simply build and run it
</details>

### Credits:
This template should support x64 hooking now thanks to this repo:
https://github.com/Rprop/And64InlineHook
https://github.com/jmpews/Dobby
31 changes: 10 additions & 21 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
apply plugin: 'com.android.application'

def build_ndk = "NDK"
def build_cmake = "CMAKE"
def build_method = build_cmake

android {
compileSdkVersion 28
buildToolsVersion "29.0.3"
Expand All @@ -14,15 +10,15 @@ android {
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
if (build_method == build_cmake) {
externalNativeBuild {
cmake {
arguments "-DANDROID_NATIVE_API_LEVEL=" + String.valueOf(minSdkVersion)
arguments "-DANDROID_LD=lld"
arguments "-DANDROID_STL=c++_shared"
}

externalNativeBuild {
cmake {
arguments "-DANDROID_NATIVE_API_LEVEL=" + String.valueOf(minSdkVersion)
arguments "-DANDROID_LD=lld"
arguments "-DANDROID_STL=c++_shared"
}
}

ndk {
abiFilters 'armeabi-v7a', 'x86', 'arm64-v8a'
}
Expand All @@ -35,16 +31,9 @@ android {
}
}
externalNativeBuild {
if (build_method == build_cmake) {
cmake {
path "src/main/cpp/CMakeLists.txt"
version "3.10.2"
}
}
else if (build_method == build_ndk) {
ndkBuild {
path file('src/main/cpp/Android.mk')
}
cmake {
path "src/main/cpp/CMakeLists.txt"
version "3.10.2"
}
}
compileOptions {
Expand Down
21 changes: 0 additions & 21 deletions app/src/main/cpp/Android.mk

This file was deleted.

15 changes: 0 additions & 15 deletions app/src/main/cpp/Application.mk

This file was deleted.

10 changes: 5 additions & 5 deletions app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@ target_sources(${PROJECT_NAME}

main.cpp
Patching/Patch.cpp
Substrate/hde64.c
Substrate/SubstrateDebug.cpp
Substrate/SubstrateHook.cpp
Substrate/SubstratePosixMemory.cpp
X64Hook/And64InlineHook.cpp
)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/Dobby/include)

set_target_properties(${PROJECT_NAME}
PROPERTIES

Expand Down Expand Up @@ -94,6 +91,9 @@ find_library(
log
)

set(DOBBY_LIB ${CMAKE_CURRENT_SOURCE_DIR}/Dobby/${CMAKE_ANDROID_ARCH_ABI}/libdobby.a)

target_link_libraries(${PROJECT_NAME}
${log-lib}
${DOBBY_LIB}
)
Binary file added app/src/main/cpp/Dobby/arm64-v8a/libdobby.a
Binary file not shown.
Binary file added app/src/main/cpp/Dobby/armeabi-v7a/libdobby.a
Binary file not shown.
190 changes: 190 additions & 0 deletions app/src/main/cpp/Dobby/include/dobby.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
#ifndef dobby_h
#define dobby_h

// obfuscated interface
#if 0
#define DobbyBuildVersion c343f74888dffad84d9ad08d9c433456
#define DobbyHook c8dc3ffa44f22dbd10ccae213dd8b1f8
#define DobbyInstrument b71e27bca2c362de90c1034f19d839f9
#endif

#ifdef __cplusplus
extern "C" {
#endif

#include <stdbool.h>
#include <stdint.h>

void log_set_level(int level);
void log_switch_to_syslog();
void log_switch_to_file(const char *path);

typedef enum {
kMemoryOperationSuccess,
kMemoryOperationError,
kNotSupportAllocateExecutableMemory,
kNotEnough,
kNone
} MemoryOperationError;

#define PLATFORM_INTERFACE_CODE_PATCH_TOOL_H
MemoryOperationError CodePatch(void *address, uint8_t *buffer, uint32_t buffer_size);

typedef uintptr_t addr_t;
typedef uint32_t addr32_t;
typedef uint64_t addr64_t;

#if defined(__arm64__) || defined(__aarch64__)

#define ARM64_TMP_REG_NDX_0 17

// float register
typedef union _FPReg {
__int128_t q;
struct {
double d1;
double d2;
} d;
struct {
float f1;
float f2;
float f3;
float f4;
} f;
} FPReg;

// register context
typedef struct _RegisterContext {
uint64_t dmmpy_0; // dummy placeholder
uint64_t sp;

uint64_t dmmpy_1; // dummy placeholder
union {
uint64_t x[29];
struct {
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,
x23, x24, x25, x26, x27, x28;
} regs;
} general;

uint64_t fp;
uint64_t lr;

union {
FPReg q[32];
struct {
FPReg q0, q1, q2, q3, q4, q5, q6, q7;
// [!!! READ ME !!!]
// for Arm64, can't access q8 - q31, unless you enable full floating-point register pack
FPReg q8, q9, q10, q11, q12, q13, q14, q15, q16, q17, q18, q19, q20, q21, q22, q23, q24, q25, q26, q27, q28, q29,
q30, q31;
} regs;
} floating;
} RegisterContext;
#elif defined(__arm__)
typedef struct _RegisterContext {
uint32_t dummy_0;
uint32_t dummy_1;

uint32_t dummy_2;
uint32_t sp;

union {
uint32_t r[13];
struct {
uint32_t r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12;
} regs;
} general;

uint32_t lr;
} RegisterContext;
#elif defined(_M_IX86) || defined(__i386__)
typedef struct _RegisterContext {
uint32_t dummy_0;
uint32_t esp;

uint32_t dummy_1;
uint32_t flags;

union {
struct {
uint32_t eax, ebx, ecx, edx, ebp, esp, edi, esi;
} regs;
} general;

} RegisterContext;
#elif defined(_M_X64) || defined(__x86_64__)
typedef struct _RegisterContext {
uint64_t dummy_0;
uint64_t rsp;

union {
struct {
uint64_t rax, rbx, rcx, rdx, rbp, rsp, rdi, rsi, r8, r9, r10, r11, r12, r13, r14, r15;
} regs;
} general;

uint64_t dummy_1;
uint64_t flags;
} RegisterContext;
#endif

#define RT_FAILED -1
#define RT_SUCCESS 0
typedef enum _RetStatus { RS_FAILED = -1, RS_SUCCESS = 0 } RetStatus;

typedef struct _HookEntryInfo {
int hook_id;
union {
void *target_address;
void *function_address;
void *instruction_address;
};
} HookEntryInfo;

// DobbyWrap <==> DobbyInstrument, so use DobbyInstrument instead of DobbyWrap
#if 0
// wrap function with pre_call and post_call
typedef void (*PreCallTy)(RegisterContext *ctx, const HookEntryInfo *info);
typedef void (*PostCallTy)(RegisterContext *ctx, const HookEntryInfo *info);
int DobbyWrap(void *function_address, PreCallTy pre_call, PostCallTy post_call);
#endif

// return dobby build date
const char *DobbyBuildVersion();

// replace function
int DobbyHook(void *address, void *replace_call, void **origin_call);

// dynamic binary instrument for instruction
// [!!! READ ME !!!]
// for Arm64, can't access q8 - q31, unless you enable full floating-point register pack
typedef void (*DBICallTy)(RegisterContext *ctx, const HookEntryInfo *info);
int DobbyInstrument(void *address, DBICallTy dbi_call);

// destory and restore hook
int DobbyDestroy(void *address);

// iterate symbol table and find symbol
void *DobbySymbolResolver(const char *image_name, const char *symbol_name);

// global offset table
int DobbyGlobalOffsetTableReplace(char *image_name, char *symbol_name, void *fake_func, void **orig_func);

// [!!! READ ME !!!]
// for arm, Arm64, dobby will use b xxx instead of ldr absolute indirect branch
// for x64, dobby always use absolute indirect jump
#if defined(__arm__) || defined(__arm64__) || defined(__aarch64__) || defined(_M_X64) || defined(__x86_64__)
void dobby_enable_near_branch_trampoline();
void dobby_disable_near_branch_trampoline();
#endif

// register linker load image callback
typedef void (*linker_load_callback_t)(const char *image_name, void *handle);
void dobby_register_image_load_callback(linker_load_callback_t func);

#ifdef __cplusplus
}
#endif

#endif
Binary file added app/src/main/cpp/Dobby/x86/libdobby.a
Binary file not shown.
Binary file added app/src/main/cpp/Dobby/x86_64/libdobby.a
Binary file not shown.
Loading