https://github.com/bytedance/bhook

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

https://github.com/bytedance/bhook

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.6%) to scientific vocabulary

Keywords

android androidgothook androidhook androidplthook bytedance got gothook hook hooking native ndk plt plthook
Last synced: 5 months ago · JSON representation

Repository

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

Basic Info
Statistics
  • Stars: 2,309
  • Watchers: 50
  • Forks: 361
  • Open Issues: 15
  • Releases: 13
Topics
android androidgothook androidhook androidplthook bytedance got gothook hook hooking native ndk plt plthook
Created over 4 years ago · Last pushed 12 months ago
Metadata Files
Readme Contributing License Code of conduct Security

README.md

ByteHook

简体中文

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

ByteHook is now used in TikTok, Douyin, Toutiao, Xigua Video, Lark.

If you need an Android inline hook library, please move to ShadowHook.

Features

  • Support Android 4.1 - 15 (API level 16 - 35).
  • 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+.

```Gradle android { buildFeatures { prefab true } }

dependencies { implementation 'com.bytedance:bytehook:1.1.1' } ```

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

```CMake find_package(bytehook REQUIRED CONFIG)

addlibrary(mylib SHARED mylib.c) targetlink_libraries(mylib bytehook::bytehook) ```

Android.mk

``` include $(CLEARVARS) LOCALMODULE := mylib LOCALSRCFILES := mylib.c LOCALSHAREDLIBRARIES += bytehook include $(BUILDSHAREDLIBRARY)

$(call import-module,prefab/bytehook) ```

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

Gradle 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.

Gradle 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.

Gradle 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.

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

5. Initialize

```Java import com.bytedance.android.bytehook.ByteHook;

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

6. Hook and Unhook

```C

include "bytehook.h"

```

```C bytehookstubt bytehookhooksingle( const char *callerpathname, const char *calleepathname, const char *symname, void *newfunc, bytehookhookedt hooked, void *hooked_arg);

bytehookstubt bytehookhookpartial( bytehookcallerallowfiltert callerallowfilter, void *callerallowfilterarg, const char *calleepathname, const char *symname, void *newfunc, bytehookhookedt hooked, void *hookedarg);

bytehookstubt bytehookhookall( const char *calleepathname, const char *symname, void *newfunc, bytehookhookedt hooked, void *hooked_arg);

int bytehookunhook(bytehookstub_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 by MIT License.

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

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

Owner

  • Name: Bytedance Inc.
  • Login: bytedance
  • Kind: organization
  • Location: Singapore

GitHub Events

Total
  • Create event: 2
  • Release event: 2
  • Issues event: 8
  • Watch event: 251
  • Issue comment event: 7
  • Push event: 7
  • Pull request event: 2
  • Fork event: 37
Last Year
  • Create event: 2
  • Release event: 2
  • Issues event: 8
  • Watch event: 251
  • Issue comment event: 7
  • Push event: 7
  • Pull request event: 2
  • Fork event: 37

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 93
  • Total Committers: 6
  • Avg Commits per committer: 15.5
  • Development Distribution Score (DDS): 0.108
Past Year
  • Commits: 7
  • Committers: 3
  • Avg Commits per committer: 2.333
  • Development Distribution Score (DDS): 0.571
Top Committers
Name Email Commits
caikelun c****n@g****m 83
xupengying x****y@g****m 4
Katana 1****a 3
dai jinlin d****n@z****m 1
chengjian.scj c****j@a****m 1
Andy Zhang T****g@s****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 62
  • Total pull requests: 8
  • Average time to close issues: about 2 months
  • Average time to close pull requests: 6 days
  • Total issue authors: 45
  • Total pull request authors: 6
  • Average comments per issue: 2.31
  • Average comments per pull request: 0.75
  • Merged pull requests: 5
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 8
  • Pull requests: 2
  • Average time to close issues: about 2 months
  • Average time to close pull requests: 6 days
  • Issue authors: 8
  • Pull request authors: 1
  • Average comments per issue: 0.5
  • Average comments per pull request: 1.0
  • Merged pull requests: 2
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • zqhGeek (4)
  • chongbo2013 (4)
  • Mr-JingShi (4)
  • fh2002 (3)
  • pxb1988 (2)
  • tyrionchen (2)
  • ndl1302732 (2)
  • flx413 (2)
  • zhaowq32 (2)
  • AriaLyy (2)
  • neervanbiqs (1)
  • 0x6666 (1)
  • yuanwofei (1)
  • eggfly (1)
  • maocanmao (1)
Pull Request Authors
  • Mr-JingShi (2)
  • OfficialKatana (2)
  • ChasonTang (1)
  • halx99 (1)
  • cmzy (1)
  • TestPlanB (1)
  • 5peak2me (1)
Top Labels
Issue Labels
bug (28) enhancement (11) invalid (9) help wanted (8) question (4) good first issue (1)
Pull Request Labels
invalid (1)

Packages

  • Total packages: 1
  • Total downloads: unknown
  • Total dependent packages: 4
  • Total dependent repositories: 7
  • Total versions: 13
repo1.maven.org: com.bytedance:bytehook

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

  • Versions: 13
  • Dependent Packages: 4
  • Dependent Repositories: 7
Rankings
Dependent repos count: 9.3%
Stargazers count: 9.7%
Average: 11.5%
Forks count: 13.1%
Dependent packages count: 13.9%
Last synced: 6 months ago

Dependencies

bytehook_sample/build.gradle maven
  • androidx.appcompat:appcompat 1.5.1 implementation
  • androidx.constraintlayout:constraintlayout 2.1.4 implementation
  • com.bytedance:bytehook 1.0.7 implementation
  • com.google.android.material:material 1.7.0 implementation
build.gradle maven
bytehook/build.gradle maven
bytehook_systest/build.gradle maven
  • com.bytedance:bytehook 1.1.0 implementation