MIT License

项目介绍

bytedance/bhook 是一个托管在 GitHub 上的开源项目,主要使用 C 编写,采用 MIT License 许可证,目前获得 2.6k 个 Star、407 次 Fork。

仓库全名
bytedance/bhook
开源许可证
MIT License
Star 数
2.6k
Fork 数
407
未关闭 Issue
18

README 摘要

ByteHook 简体中文 ByteHook is an Android PLT hook library. Its goals are: Stability - Can be stably used in production apps. Compatibility - Always maintains backward compatibility of API and ABI in new versions. Performance - Continuously reduces API call overhead and additional runtime overhead introduced by hooks. If you need an Android inline hook library, try shadowhook. Android OS Compatibility Android 4.1 - 17…

完整内容见 GitHub 原始 README 或本页 。

常见问题

bhook 用什么语言开发?

主要使用 C 编写,采用 MIT License 许可证,目前有 2.6k 个 Star。

bhook 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 bhook 的源码?

可以直接克隆仓库:git clone https://github.com/bytedance/bhook.git,默认分支为 main;安装与运行步骤见仓库 README。

bhook 最近还在维护吗?

仓库最近一次更新为 6月16日,当前有 18 个未关闭 Issue;Star 数为 2.6k,可作为社区活跃度的参考。

关于

GitHub 原始描述(英文)

:fire: ByteHook is an Android PLT hook library which supports armeabi-v7a, arm64-v8a, x86 and x86_64.

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

简要分析

热度分
3491
价值分
1701
活跃状态
活跃

语言占比

C
C++
CMake
Java
Python

Release

README

ByteHook

简体中文

ByteHook is an Android PLT hook library. Its goals are:

  • Stability - Can be stably used in production apps.
  • Compatibility - Always maintains backward compatibility of API and ABI in new versions.
  • Performance - Continuously reduces API call overhead and additional runtime overhead introduced by hooks.

If you need an Android inline hook library, try shadowhook.

Android OS Compatibility

Android 4.1 - 17 QPR1 Beta 4

We will test and support the latest Android OS Beta versions as promptly as possible, and list the supported Android OS versions here.

Features

  • Support Android 4.1 - 17 (API level 16 - 37).
  • Support armeabi-v7a, arm64-v8a, x86 and x86_64.
  • Multiple hooks and unhooks for the same function do not conflict with each other.
  • Hook a single, partial or all of the dynamic libraries in the process.
  • Hook the newly loaded dynamic libraries automatically.
  • Avoid recursive-calls and circular-calls between proxy functions automatically.
  • Support unwinding backtrace in proxy function.
  • MIT licensed.

Documentation

ByteHook Documentation

Quick Start

There is a sample app in the bytehook-sample you can refer to.

1. Add dependency in build.gradle

ByteHook is published on Maven Central, and uses Prefab package format for native dependencies, which is supported by Android Gradle Plugin 4.0+.

android {
    buildFeatures {
        prefab true
    }
}

dependencies {
    implementation 'com.bytedance:bytehook:x.y.z'
}

Replace x.y.z with the version number. It’s recommended to use the latest release version.

Note: ByteHook uses the prefab package schema v2, which is configured by default since Android Gradle Plugin 7.1.0. If you are using Android Gradle Plugin earlier than 7.1.0, please add the following configuration to gradle.properties:

android.prefabVersion=2.0.0

2. Add dependency in CMakeLists.txt or Android.mk

CMakeLists.txt

find_package(bytehook REQUIRED CONFIG)

add_library(mylib SHARED mylib.c)
target_link_libraries(mylib bytehook::bytehook)

Android.mk

include $(CLEAR_VARS)
LOCAL_MODULE           := mylib
LOCAL_SRC_FILES        := mylib.c
LOCAL_SHARED_LIBRARIES += bytehook
include $(BUILD_SHARED_LIBRARY)

$(call import-module,prefab/bytehook)

3. Specify one or more ABI(s) you need

android {
    defaultConfig {
        ndk {
            abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
        }
    }
}

4. Add packaging options

If you are using ByteHook in an SDK project, you may need to avoid packaging libbytehook.so into your AAR, so as not to encounter duplicate libbytehook.so file when packaging the app project.

android {
    packagingOptions {
        exclude '**/libbytehook.so'
    }
}

On the other hand, if you are using ByteHook in an APP project, you may need to add some options to deal with conflicts caused by duplicate libbytehook.so file.

android {
    packagingOptions {
        pickFirst '**/libbytehook.so'
    }
}

Note: If you use prefab dependency bytehook under x86 and x86_64 architectures, you need to add prefab_bypass.gradle to the module’s build.gradle.

apply from: rootProject.file('gradle/prefab_bypass.gradle')

5. Initialize

import com.bytedance.android.bytehook.ByteHook;

public class MySdk {
    public static synchronized void init() {
        ByteHook.init();
    }
}

6. Hook and Unhook

#include "bytehook.h"
bytehook_stub_t bytehook_hook_single(
    const char *caller_path_name,
    const char *callee_path_name,
    const char *sym_name,
    void *new_func,
    bytehook_hooked_t hooked,
    void *hooked_arg);

bytehook_stub_t bytehook_hook_partial(
    bytehook_caller_allow_filter_t caller_allow_filter,
    void *caller_allow_filter_arg,
    const char *callee_path_name,
    const char *sym_name,
    void *new_func,
    bytehook_hooked_t hooked,
    void *hooked_arg);

bytehook_stub_t bytehook_hook_all(
    const char *callee_path_name,
    const char *sym_name,
    void *new_func,
    bytehook_hooked_t hooked,
    void *hooked_arg);

int bytehook_unhook(bytehook_stub_t stub);

These three hook functions are used to hook single, partial, and all caller dynamic libraries in the process.

Notice:

  • If you need to call the original function in the proxy function, please always use the BYTEHOOK_CALL_PREV() macro.
  • Make sure to call BYTEHOOK_POP_STACK() macro before proxy function returning. In the CPP source file, you can also call BYTEHOOK_STACK_SCOPE() macro at the beginning of the proxy function instead.

Contributing

License

ByteHook is licensed under the MIT License.

ByteHook uses the following third-party source code or libraries:

  • queue.h
    BSD 3-Clause License
    Copyright © 1991, 1993 The Regents of the University of California.
  • linux-syscall-support
    BSD 3-Clause License
    Copyright © 2005-2011 Google Inc.

评论

暂无评论