Skip to content

Commit

Permalink
Update docs and version number.
Browse files Browse the repository at this point in the history
  • Loading branch information
caikelun committed Dec 27, 2021
1 parent 227a29c commit 16612f1
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 21 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# bhook

![](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)
![](https://img.shields.io/badge/release-1.0.3-red.svg?style=flat)
![](https://img.shields.io/badge/release-1.0.4-red.svg?style=flat)
![](https://img.shields.io/badge/Android-4.1%20--%2012-blue.svg?style=flat)
![](https://img.shields.io/badge/arch-armeabi--v7a%20%7C%20arm64--v8a%20%7C%20x86%20%7C%20x86__64-blue.svg?style=flat)

[README 中文版](README.zh-CN.md)

ByteHook(aka bhook) is a PLT hook framework for Android app. It provides an overall solution for using PLT hook in Android app, not just replacing addresses.
ByteHook(aka bhook) is a PLT hook framework for Android app. It provides an overall solution for using PLT hook in Android app.

Most of ByteDance's Android apps(including Douyin, Toutiao, Xigua Video) use ByteHook as the PLT hook solution in production.

Expand Down Expand Up @@ -53,7 +53,7 @@ android {
}
dependencies {
implementation 'com.bytedance:bytehook:1.0.3'
implementation 'com.bytedance:bytehook:1.0.4'
}
```

Expand Down
6 changes: 3 additions & 3 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# bhook

![](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)
![](https://img.shields.io/badge/release-1.0.3-red.svg?style=flat)
![](https://img.shields.io/badge/release-1.0.4-red.svg?style=flat)
![](https://img.shields.io/badge/Android-4.1%20--%2012-blue.svg?style=flat)
![](https://img.shields.io/badge/arch-armeabi--v7a%20%7C%20arm64--v8a%20%7C%20x86%20%7C%20x86__64-blue.svg?style=flat)

[README English Version](README.md)

ByteHook(aka bhook) 是一个针对 Android app 的 PLT hook 框架。它提供了一套 Android app 使用 PLT hook 的整体方案,而不仅仅是替换地址
ByteHook(aka bhook) 是一个针对 Android app 的 PLT hook 框架。它提供了一套 Android app 使用 PLT hook 的整体方案。

字节跳动的大多数 Android app(包括抖音,今日头条,西瓜视频)在线上环境中使用了 ByteHook 作为 PLT hook 方案。

Expand Down Expand Up @@ -53,7 +53,7 @@ android {
}
dependencies {
implementation 'com.bytedance:bytehook:1.0.3'
implementation 'com.bytedance:bytehook:1.0.4'
}
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ext {

POM_GROUP_ID = "com.bytedance"
POM_ARTIFACT_ID = "bytehook"
POM_VERSION_NAME = "1.0.3"
POM_VERSION_NAME = "1.0.4"

POM_NAME = "bytehook"
POM_DESCRIPTION = "ByteHook is a PLT hook framework for Android app."
Expand Down
6 changes: 3 additions & 3 deletions bytehook_sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ android {
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'

if (rootProject.ext.dependencyOnLocalLibrary) {
implementation project(':bytehook')
} else {
implementation 'com.bytedance:bytehook:1.0.3'
implementation 'com.bytedance:bytehook:1.0.4'
}
}

Expand Down
44 changes: 33 additions & 11 deletions doc/records.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,23 @@
```C
#include "bytehook.h"

char *bytehook_get_records(void);
void bytehook_dump_records(int fd);
#define BYTEHOOK_RECORD_ITEM_ALL 0xFF // 0b11111111
#define BYTEHOOK_RECORD_ITEM_TIMESTAMP (1 << 0)
#define BYTEHOOK_RECORD_ITEM_CALLER_LIB_NAME (1 << 1)
#define BYTEHOOK_RECORD_ITEM_OP (1 << 2)
#define BYTEHOOK_RECORD_ITEM_LIB_NAME (1 << 3)
#define BYTEHOOK_RECORD_ITEM_SYM_NAME (1 << 4)
#define BYTEHOOK_RECORD_ITEM_NEW_ADDR (1 << 5)
#define BYTEHOOK_RECORD_ITEM_ERRNO (1 << 6)
#define BYTEHOOK_RECORD_ITEM_STUB (1 << 7)

char *bytehook_get_records(uint32_t item_flags);
void bytehook_dump_records(int fd, uint32_t item_flags);
```
* `bytehook_get_records` 返回一个用 `malloc` 分配的 buffer,其中包含操作记录。你需要自己调用 `free` 来释放这块内存。失败是返回 `NULL`。
* `bytehook_dump_records` 将操作记录写入参数 FD 指向的文件描述符中。此接口是异步信号安全的。
* 可以使用 `item_flags` 参数来控制需要输出哪些数据项。
## java 层 API
Expand All @@ -24,10 +35,22 @@ package com.bytedance.android.bytehook;
public class ByteHook
public static String getRecords()
public enum RecordItem {
TIMESTAMP,
CALLER_LIB_NAME,
OP,
LIB_NAME,
SYM_NAME,
NEW_ADDR,
ERRNO,
STUB
}
public static String getRecords(RecordItem... recordItems)
```

* `getRecords` 直接调用了 native 层的 `bytehook_get_records` 函数,返回操作记录。
* 可以使用 `recordItems` 参数来控制需要输出哪些数据项。

## 操作记录格式

Expand All @@ -41,8 +64,8 @@ public static String getRecords()
### 操作记录举例

```
2021-11-05T15:20:27.767+08:00,libbytehooksystest.so,hook,0,76891de8a0,78ace73fb0,75afdd31a4,writev,/system/lib64/libappfuse.so
2021-11-05T15:21:40.226+08:00,libbytehooksystest.so,unhook,0,76891db690,/system/lib64/libappfuse.so
2021-11-05T15:20:27.767+08:00,libbytehooksystest.so,hook,libappfuse.so,writev,78ace73fb0,0,76891db690
2021-11-05T15:21:40.226+08:00,libbytehooksystest.so,unhook,0,76891db690
9999-99-99T00:00:00.000+00:00,error,error,0,0
```

Expand All @@ -53,9 +76,8 @@ public static String getRecords()
| 1 | 时间戳 | 格式:YYYY-MM-DDThh:mm:ss.sss+hh:mm |
| 2 | 操作调用者动态库名称 | basename |
| 3 | 操作类型 | hook / unhook / error |
| 4 | 错误码 | |
| 5 | stub 值 | 是个指针类型的数值,hook / unhook 可以通过这个值来配对 |
| 6 | hook 时,目标函数的地址 | (unhook记录中无此项) |
| 7 | hook 时,proxy函数的地址 | (unhook记录中无此项) |
| 8 | hook 时,目标函数的名称 | (unhook记录中无此项) |
| 9 | hook 时或 unhook 时,目标函数所在的动态库的 pathname | 注意,这个 pathname 是通过 `dl_iterate_phdr` 获取的,在 Android 5.x 上只能获取到 basename(不包含文件路径) |
| 4 | hook 时,调用者动态库名称 | basename。unhook记录中无此项 |
| 5 | hook 时,目标函数的名称 | unhook记录中无此项 |
| 6 | hook 时,proxy函数的地址 | unhook记录中无此项 |
| 7 | 错误码 | |
| 8 | stub 值 | 是个指针类型的数值,hook / unhook 可以通过这个值来配对 |

0 comments on commit 16612f1

Please sign in to comment.