-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
112 changed files
with
5,304 additions
and
3,539 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# ByteHook | ||
|
||
 | ||
 | ||
 | ||
 | ||
 | ||
|
||
|
@@ -47,7 +47,7 @@ android { | |
} | ||
dependencies { | ||
implementation 'com.bytedance:bytehook:1.0.10' | ||
implementation 'com.bytedance:bytehook:1.1.0' | ||
} | ||
``` | ||
|
||
|
@@ -114,6 +114,12 @@ android { | |
} | ||
``` | ||
|
||
Note: If you use prefab dependency bytehook under x86 and x86_64 architectures, you need to add [prefab_bypass.gradle](gradle/prefab_bypass.gradle) to the module's build.gradle. | ||
|
||
```Gradle | ||
apply from: rootProject.file('gradle/prefab_bypass.gradle') | ||
``` | ||
|
||
### 5. Initialize | ||
|
||
```Java | ||
|
@@ -184,9 +190,6 @@ ByteHook uses the following third-party source code or libraries: | |
* [queue.h](bytehook/src/main/cpp/third_party/bsd/queue.h) | ||
BSD 3-Clause License | ||
Copyright (c) 1991, 1993 The Regents of the University of California. | ||
* [tree.h](bytehook/src/main/cpp/third_party/bsd/tree.h) | ||
BSD 2-Clause License | ||
Copyright (c) 2002 Niels Provos <[email protected]> | ||
* [linux-syscall-support](https://chromium.googlesource.com/linux-syscall-support/) | ||
BSD 3-Clause License | ||
Copyright (c) 2005-2011 Google Inc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# ByteHook | ||
|
||
 | ||
 | ||
 | ||
 | ||
 | ||
|
||
|
@@ -47,7 +47,7 @@ android { | |
} | ||
dependencies { | ||
implementation 'com.bytedance:bytehook:1.0.10' | ||
implementation 'com.bytedance:bytehook:1.1.0' | ||
} | ||
``` | ||
|
||
|
@@ -114,6 +114,12 @@ android { | |
} | ||
``` | ||
|
||
注意:如果在 x86 和 x86_64 架构下使用 prefab 依赖 bytehook 时需要在模块的 build.gradle 中添加 [prefab_bypass.gradle](gradle/prefab_bypass.gradle) 。 | ||
|
||
```Gradle | ||
apply from: rootProject.file('gradle/prefab_bypass.gradle') | ||
``` | ||
|
||
### 5. 初始化 | ||
|
||
```Java | ||
|
@@ -184,9 +190,6 @@ ByteHook 使用了以下第三方源码或库: | |
* [queue.h](bytehook/src/main/cpp/third_party/bsd/queue.h) | ||
BSD 3-Clause License | ||
Copyright (c) 1991, 1993 The Regents of the University of California. | ||
* [tree.h](bytehook/src/main/cpp/third_party/bsd/tree.h) | ||
BSD 2-Clause License | ||
Copyright (c) 2002 Niels Provos <[email protected]> | ||
* [linux-syscall-support](https://chromium.googlesource.com/linux-syscall-support/) | ||
BSD 3-Clause License | ||
Copyright (c) 2005-2011 Google Inc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# We found that AGP could not generate the correct cmake configuration | ||
# when relying on a prefab package generated by another local project. | ||
# We had to write one ourselves. | ||
# | ||
# Use it like this: | ||
# | ||
# if(DEPENDENCY_ON_LOCAL_LIBRARY) | ||
# include(${CMAKE_CURRENT_SOURCE_DIR}/../../../../bytehook/local_dependency.cmake) | ||
# else() | ||
# find_package(bytehook REQUIRED CONFIG) | ||
# endif() | ||
# | ||
# target_link_libraries(myapp bytehook::bytehook) | ||
# | ||
|
||
string(TOLOWER ${CMAKE_BUILD_TYPE} BYTEHOOK_BUILD_TYPE_DIRNAME) | ||
if(${BYTEHOOK_BUILD_TYPE_DIRNAME} STREQUAL "relwithdebinfo") | ||
set(BYTEHOOK_BUILD_TYPE_DIRNAME "release") | ||
endif() | ||
|
||
set(BYTEHOOK_BASE ${CMAKE_CURRENT_SOURCE_DIR}/../../../../bytehook) | ||
|
||
add_library(bytehook::bytehook SHARED IMPORTED) | ||
set_target_properties(bytehook::bytehook PROPERTIES | ||
IMPORTED_LOCATION "${BYTEHOOK_BASE}/build/intermediates/cmake/${BYTEHOOK_BUILD_TYPE_DIRNAME}/obj/${ANDROID_ABI}/libbytehook.so" | ||
INTERFACE_INCLUDE_DIRECTORIES "${BYTEHOOK_BASE}/src/main/cpp/include" | ||
INTERFACE_LINK_LIBRARIES "" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) 2020-2024 ByteDance, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
// | ||
|
||
// Created by Kelun Cai ([email protected]) on 2024-09-24. | ||
|
||
#include "bh_array.h" | ||
|
||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
int bh_array_push(bh_array_t *self, uintptr_t value) { | ||
if (__predict_false(self->count >= self->cap)) { | ||
self->cap *= 2; | ||
uintptr_t *heap = NULL; | ||
if (self->data == self->stack) { | ||
heap = malloc(sizeof(uintptr_t) * self->cap); | ||
if (NULL == heap) return -1; | ||
memcpy(heap, self->stack, sizeof(self->stack)); | ||
} else { | ||
heap = realloc(self->data, sizeof(uintptr_t) * self->cap); | ||
if (NULL == heap) { | ||
free(self->data); | ||
return -1; | ||
} | ||
} | ||
self->data = heap; | ||
} | ||
|
||
self->data[self->count] = value; | ||
self->count++; | ||
return 0; | ||
} | ||
|
||
void bh_array_free(bh_array_t *self) { | ||
if (__predict_false(self->data != self->stack)) free(self->data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) 2020-2024 ByteDance, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
// | ||
|
||
// Created by Kelun Cai ([email protected]) on 2024-09-24. | ||
|
||
#pragma once | ||
|
||
#include <stdint.h> | ||
|
||
#define BH_ARRAY_STACK_CAP 8 | ||
|
||
typedef struct { | ||
uintptr_t *data; | ||
size_t count; | ||
size_t cap; | ||
uintptr_t stack[BH_ARRAY_STACK_CAP]; | ||
} bh_array_t; | ||
|
||
#define BH_ARRAY_INITIALIZER(self) {.data = (self)->stack, .count = 0, .cap = BH_ARRAY_STACK_CAP} | ||
|
||
int bh_array_push(bh_array_t *self, uintptr_t value); | ||
void bh_array_free(bh_array_t *self); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) 2020-2024 ByteDance Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
// | ||
|
||
// Created by Kelun Cai ([email protected]) on 2024-09-12. | ||
|
||
#pragma once | ||
|
||
// Global debugging. | ||
// | ||
// Note that in some cases these logs themselves can cause a crash. | ||
// | ||
// #define BH_CONFIG_DEBUG | ||
|
||
// Operation record of hook and unhook. | ||
// | ||
// Disabling it can reduce hook/unhook latency, memory footprint and file size. | ||
// | ||
#define BH_CONFIG_OPERATION_RECORDS | ||
|
||
// Crash signal protection. | ||
// | ||
// Do not disable it in a production environment. | ||
// | ||
#define BH_CONFIG_SIG_PROT |
Oops, something went wrong.