Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/XMDS/GlossHook
Browse files Browse the repository at this point in the history
  • Loading branch information
XMDS committed Jul 12, 2023
2 parents b2689b6 + dcc674e commit f8eff83
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
17 changes: 9 additions & 8 deletions GlossHook/Gloss.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extern "C" {

#include <stdint.h>
#include <stdbool.h>
#include <unistd.h> //lseek PAGE_SIZE
#include <unistd.h>

#ifdef __arm__
#define GET_INST_SET(addr) (addr & 1 ? i_set::$THUMB : i_set::$ARM)
Expand All @@ -42,7 +42,7 @@ extern "C" {
#ifdef __arm__
enum e_reg { R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13, SP = R13, R14, LR = R14, R15, PC = R15, CPSR };

int32_t reg[17];
uint32_t reg[17];
struct { uint32_t r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, sp, lr, pc, cprs; } regs;
#elif __aarch64__
enum e_reg {
Expand All @@ -51,16 +51,16 @@ extern "C" {
X30, LR = X30, X31, SP = X31, PC, CPSR
};

int64_t reg[66];
uint64_t reg[66];
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, x29,
q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13, q14, q15, q16, q17, q18, q19, q20, q21, q22, q23, q24, q25, q26, q27, q28, q29, q30, q31,
lr, sp, pc, cprs;
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, x29;
double q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13, q14, q15, q16, q17, q18, q19, q20, q21, q22, q23, q24, q25, q26, q27, q28, q29, q30, q31;
uint64_t lr, sp, pc, cprs;
} regs;
#endif // __arm__
};

//func
// library
uintptr_t GlossGetLibBase(const char* libName, pid_t pid = -1);

size_t GlossGetLibLength(const char* libName, pid_t pid = -1);
Expand All @@ -78,7 +78,7 @@ extern "C" {
uintptr_t GlossSymbolEx(uintptr_t libAddr, const char* name, size_t* sym_size);
const char* GlossAddrInfo(uintptr_t sym_addr, size_t* sym_size);

//memory
// memory
bool SetMemoryPermission(uintptr_t addr, size_t len, p_flag* type);
inline bool Unprotect(uintptr_t addr, size_t len = PAGE_SIZE)
{
Expand All @@ -97,6 +97,7 @@ extern "C" {
void* ReadMemory(void* addr, void* data, size_t size, bool vp = true);
void MemoryFill(void* addr, uint8_t value, size_t size, bool vp = true);

// hook
void* GlossHookSym(void* sym_addr, void* new_func, void** old_func);
void* GlossHookAddr(void* func_addr, void* new_func, void** old_func, bool is_short_func, INST_SET);

Expand Down
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
A simple Android arm Hook library.

## 中文说明
一个简易、功能强大的安卓arm Hook库.
GlossHook仍然处于早期版本,虽然时间少,但尽量更新,更加完善和稳定.
一个简易、功能多的安卓arm hook库.
GlossHook目前只是一个arm的分支版本,待以后更新(目前稳定性不敢保证),但基本上可以使用.

### 特性
* 支持thumb/arm的InlineHook(arm64待更新)
* 目前仅支持对整个函数hook,对函数替换、注入等
* 支持对同一个函数多次hook.
* 同一个函数有多个hook时,
支持通过hook指针和hook地址,取消/恢复/删除任意一个或全部的hook.
取消任意1个hook时,对其它hook不影响.
* 提供常用的库查找、获取符号地址、读写内存、解除内存等API函数
* 其它待更新ing…
* 支持thumb/arm/arm64的InlineHook和GotHook(不是PLT Hook).
* 支持对单个分支指令(B BL BLX)调用函数的hook,有时候你可能只需要hook其中一处调用点,而不是函数的全部调用点.
* 支持短函数Hook(最短4字节函数).
* 支持对函数代码内任意位置地址的hook patch,在用户函数中可读写hook位置的寄存器、栈、调用任何类型的函数.
* hook后,可回调原函数,也可不回调直接替换函数.
* 支持对同一个函数的多次hook.
* 同一个函数有多个hook时, 支持通过hook指针和hook位置,开启/关闭/删除任意一个或全部的hook. 开启/关闭/删除任意1个hook时,对同位置其它hook不影响.
* 如果多个使用方使用GlossHook对同一个位置hook,任意一个使用方可以通过地址开启/关闭/删除其它的hook.
* 提供了函数获取一个位置被hook的数量.
* 支持替换已经正在hook的用户函数
* 提供常用的库查找、库信息、获取符号地址、读写内存、解除内存权限等API函数.
* 其它待更新ing

0 comments on commit f8eff83

Please sign in to comment.