<p align="center"><img src="https://github.com/iqiyi/xHook/blob/master/docs/xhooklogo.png?raw=true" alt="xhook" width="50%"></p>
# xHook
![](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)
![](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat)
![](https://img.shields.io/badge/release-1.2.0-red.svg?style=flat)
![](https://img.shields.io/badge/Android-4.0%20--%2010-blue.svg?style=flat)
![](https://img.shields.io/badge/arch-armeabi%20%7C%20armeabi--v7a%20%7C%20arm64--v8a%20%7C%20x86%20%7C%20x86__64-blue.svg?style=flat)
[README 中文版](README.zh-CN.md)
[Android PLT hook 概述 中文版](docs/overview/android_plt_hook_overview.zh-CN.md)
xHook is a PLT (Procedure Linkage Table) hook library for Android native ELF (executable and shared libraries).
xHook has been keeping optimized for stability and compatibility.
## Features
* Support Android 4.0 - 10 (API level 14 - 29).
* Support armeabi, armeabi-v7a, arm64-v8a, x86 and x86_64.
* Support **ELF HASH** and **GNU HASH** indexed symbols.
* Support **SLEB128** encoded relocation info.
* Support setting hook info via regular expressions.
* Do not require root permission or any system permissions.
* Do not depends on any third-party shared libraries.
## Build
* Download [Android NDK r16b](https://developer.android.com/ndk/downloads/revision_history.html), set environment PATH. (support for armeabi has been removed since r17)
* Build and install the native libraries.
```
./build_libs.sh
./install_libs.sh
```
## Demo
```
cd ./xhookwrapper/
./gradlew assembleDebug
adb install ./app/build/outputs/apk/debug/app-debug.apk
```
## API
External API header file: `libxhook/jni/xhook.h`
### 1. Register hook info
```c
int xhook_register(const char *pathname_regex_str,
const char *symbol,
void *new_func,
void **old_func);
```
In current process's memory space, in every loaded ELF which pathname matches regular expression `pathname_regex_str`, every PLT entries to `symbol` will be **replaced with** `new_func`. The original one will be saved in `old_func`.
The `new_func` **must** have the same function declaration as the original one.
Return zero if successful, non-zero otherwise.
The regular expression for `pathname_regex_str` only support **POSIX BRE (Basic Regular Expression)**.
### 2. Ignore some hook info
```c
int xhook_ignore(const char *pathname_regex_str,
const char *symbol);
```
Ignore some hook info according to `pathname_regex_str` and `symbol`, from registered hooks by `xhook_register`. If `symbol` is `NULL`, xhook will ignore all symbols from ELF which pathname matches `pathname_regex_str`.
Return zero if successful, non-zero otherwise.
The regular expression for `pathname_regex_str` only support **POSIX BRE**.
### 3. Do hook
```c
int xhook_refresh(int async);
```
Do the real hook operations according to the registered hook info.
Pass `1` to `async` for asynchronous hook. Pass `0` to `async` for synchronous hook.
Return zero if successful, non-zero otherwise.
xhook will keep a global cache for saving the last ELF loading info from `/proc/self/maps`. This cache will also be updated in `xhook_refresh`. With this cache, `xhook_refresh` can determine which ELF is newly loaded. We only need to do hook in these newly loaded ELF.
### 4. Clear cache
```c
void xhook_clear();
```
Clear all cache owned by xhook, reset all global flags to default value.
If you confirm that all PLT entries you want have been hooked, you could call this function to save some memory.
### 5. Enable/Disable debug info
```c
void xhook_enable_debug(int flag);
```
Pass `1` to `flag` for enable debug info. Pass `0` to `flag` for disable. (**disabled** by default)
Debug info will be sent to logcat with tag `xhook`.
### 6. Enable/Disable SFP (segmentation fault protection)
```c
void xhook_enable_sigsegv_protection(int flag);
```
Pass `1` to `flag` for enable SFP. Pass `0` to `flag` for disable. (**enabled** by default)
xhook is NOT a compliant business layer library. We have to calculate the value of some pointers directly. Reading or writing the memory pointed to by these pointers will cause a segmentation fault in some unusual situations and environment. The APP crash rate increased which caused by xhook is about one ten-millionth (0.0000001) according to our test. (The increased crash rate is also related to the ELFs and symbols you need to hook). Finally, we have to use some trick to prevent this harmless crashing. We called it SFP (segmentation fault protection) which consists of: `sigaction()`, `SIGSEGV`, `siglongjmp()` and `sigsetjmp()`.
**You should always enable SFP for release-APP, this will prevent your app from crashing. On the other hand, you should always disable SFP for debug-APP, so you can't miss any common coding mistakes that should be fixed.**
## Examples
```c
//detect memory leaks
xhook_register(".*\\.so$", "malloc", my_malloc, NULL);
xhook_register(".*\\.so$", "calloc", my_calloc, NULL);
xhook_register(".*\\.so$", "realloc", my_realloc, NULL);
xhook_register(".*\\.so$", "free", my_free, NULL);
//inspect sockets lifecycle
xhook_register(".*\\.so$", "getaddrinfo", my_getaddrinfo, NULL);
xhook_register(".*\\.so$", "socket", my_socket, NULL);
xhook_register(".*\\.so$", "setsockopt" my_setsockopt, NULL);
xhook_register(".*\\.so$", "bind", my_bind, NULL);
xhook_register(".*\\.so$", "listen", my_listen, NULL);
xhook_register(".*\\.so$", "connect", my_connect, NULL);
xhook_register(".*\\.so$", "shutdown", my_shutdown, NULL);
xhook_register(".*\\.so$", "close", my_close, NULL);
//filter off and save some android log to local file
xhook_register(".*\\.so$", "__android_log_write", my_log_write, NULL);
xhook_register(".*\\.so$", "__android_log_print", my_log_print, NULL);
xhook_register(".*\\.so$", "__android_log_vprint", my_log_vprint, NULL);
xhook_register(".*\\.so$", "__android_log_assert", my_log_assert, NULL);
//tracking (ignore linker and linker64)
xhook_register("^/system/.*$", "mmap", my_mmap, NULL);
xhook_register("^/vendor/.*$", "munmap", my_munmap, NULL);
xhook_ignore (".*/linker$", "mmap");
xhook_ignore (".*/linker$", "munmap");
xhook_ignore (".*/linker64$", "mmap");
xhook_ignore (".*/linker64$", "munmap");
//defense to some injection attacks
xhook_register(".*com\\.hacker.*\\.so$", "malloc", my_malloc_always_return_NULL, NULL);
xhook_register(".*/libhacker\\.so$", "connect", my_connect_with_recorder, NULL);
//fix some system bug
xhook_register(".*some_vendor.*/libvictim\\.so$", "bad_func", my_nice_func, NULL);
//ignore all hooks in libwebviewchromium.so
xhook_ignore(".*/libwebviewchromium.so$", NULL);
//hook now!
xhook_refresh(1);
```
## Support
1. Check the [xhook-sample](libbiz/jni).
2. Communicate on [GitHub issues](https://github.com/iqiyi/xHook/issues).
3. Mail: <a href="mailto:caikelun@gmail.com">caikelun@gmail.com</a>
4. QQ group: 603635869. QR code:
<p align="left"><img src="docs/qq_group.jpg" alt="qq group" width="300px"></p>
## Contributing
See [xHook Contributing Guide](CONTRIBUTING.md).
## License
xHook is MIT licensed, as found in the [LICENSE](LICENSE) file.
xHook documentation is Creative Commons licensed, as found in the [LICENSE-docs](LICENSE-docs) file.
没有合适的资源?快使用搜索试试~ 我知道了~
Magisk:Android 获取 Root 权限的工具 它可以快速、无痛地获得 Android 的超级用户权限
共723个文件
xml:255个
kt:126个
cpp:66个
5星 · 超过95%的资源 需积分: 13 4 下载量 30 浏览量
2023-01-06
18:32:47
上传
评论
收藏 11.39MB ZIP 举报
温馨提示
Magisk:Android 获取 Root 权限的工具。它可以快速、无痛地获得 Android 的超级用户权限,支持 Android 5.0 以上的设备。 介绍 Magisk是一套用于定制Android的开源软件,支持高于Android 5.0的设备。 一些突出特点: MagiskSU:为应用程序提供根访问权限 Magisk模块:通过安装模块修改只读分区 MagiskBoot:开箱和重新打包Android启动映像的最完整工具 Zygisk:在每个Android应用程序的进程中运行代码
资源推荐
资源详情
资源评论
收起资源包目录
Magisk:Android 获取 Root 权限的工具 它可以快速、无痛地获得 Android 的超级用户权限 (723个子文件)
libc.a 15.4MB
libc.a 12.86MB
libc.a 3.12MB
libc.a 2.95MB
libm.a 2.69MB
libm.a 2.44MB
libz.a 985KB
libm.a 973KB
libm.a 935KB
libz.a 892KB
libz.a 427KB
libz.a 338KB
libstdc++.a 188KB
libstdc++.a 178KB
libstdc++.a 28KB
libstdc++.a 28KB
IRootUtils.aidl 255B
gradlew.bat 3KB
bootctl 151KB
xh_elf.c 33KB
xz_dec_lzma2.c 33KB
xz_dec_stream.c 23KB
xh_core.c 19KB
xh_util.c 4KB
xh_version.c 2KB
xh_jni.c 2KB
xhook.c 2KB
xz_crc32.c 1KB
xh_log.c 1KB
loader.c 793B
preload.c 699B
pcre2_workaround.c 230B
bootimg.cpp 26KB
module.cpp 26KB
hook.cpp 25KB
compress.cpp 19KB
sepolicy.cpp 19KB
prop_area.cpp 14KB
dtb.cpp 14KB
files.cpp 13KB
entry.cpp 12KB
su_daemon.cpp 12KB
daemon.cpp 12KB
system_properties.cpp 12KB
db.cpp 12KB
utils.cpp 11KB
resetprop.cpp 11KB
bootstages.cpp 11KB
contexts_split.cpp 10KB
statement.cpp 10KB
rootdir.cpp 10KB
system_property_set.cpp 10KB
mount.cpp 9KB
package.cpp 9KB
ramdisk.cpp 9KB
getinfo.cpp 9KB
persist.cpp 9KB
rules.cpp 8KB
property_info_parser.cpp 8KB
policydb.cpp 7KB
cpio.cpp 7KB
ptrace.cpp 7KB
main.cpp 7KB
main.cpp 7KB
cert.cpp 6KB
pts.cpp 6KB
connect.cpp 6KB
stream.cpp 6KB
scripting.cpp 6KB
su.cpp 6KB
selinux.cpp 6KB
contexts_serialized.cpp 6KB
misc.cpp 5KB
system_property_api.cpp 5KB
magisk.cpp 5KB
socket.cpp 4KB
compat.cpp 4KB
cli.cpp 4KB
utils.cpp 4KB
main.cpp 4KB
logging.cpp 4KB
api.cpp 3KB
selinux.cpp 3KB
context_node.cpp 3KB
restorecon.cpp 3KB
format.cpp 3KB
init.cpp 3KB
thread.cpp 3KB
prop_info.cpp 2KB
logging.cpp 2KB
applets.cpp 2KB
pattern.cpp 2KB
twostage.cpp 1KB
hexpatch.cpp 1KB
revert.cpp 1KB
memory.cpp 881B
new.cpp 646B
applet_stub.cpp 290B
elf-cleaner.exe 149KB
futility 535KB
共 723 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
- 杏花朵朵2023-07-26它能够在无损的情况下给Android系统提供超级用户权限,这让我感到很安心。
- 柏傅美2023-07-26这个文件可以帮助Android用户加强设备的功能,并且不会对系统的稳定性产生负面影响。
- 优游的鱼2023-07-26Magisk工具为Android用户提供了一种高效的方式来掌控设备,对于喜欢个性化定制的用户来说非常方便。
- 大禹倒杯茶2023-07-26这个文件对于想要获取Android超级用户权限的用户来说是非常实用的。
- KateZeng2023-07-26使用Magisk工具,获取Root权限变得快速简单,不再需要复杂的步骤。
jysf98746
- 粉丝: 1210
- 资源: 149
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 原生微信小程序源码 - -滴滴公交-查公交
- 人工智能实验四 感知器算法的设计实现
- java小项目多线程多线程 复制文件 冒泡排序 群聊
- 四数之和(java代码).docx
- 701837906919458TapScanner v3.0.10 (Pro).apk
- 青岛大学人工智能实验二 利用α-β搜索的博弈树算法编写一字棋游戏
- ### 1、项目介绍 本项目Scrapy进行数据爬取,并使用Django框架+PyEcharts实现可视化大屏 效果如下:
- # 微信小程序-健康菜谱 基于微信小程序的一个查找检索菜谱的应用 ### 效果 !动态图(./res/gif/demo
- zabbix-get命令包资源
- 289ssm-mysql-jsp 计算机课程实验管理系统.zip(可运行源码+数据库文件+文档)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功