Skip to content

Commit

Permalink
Minor changes. Release 1.0.8.
Browse files Browse the repository at this point in the history
  • Loading branch information
caikelun committed May 16, 2023
1 parent 47b856c commit 4d07fb8
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 56 deletions.
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ByteHook

![](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)
![](https://img.shields.io/badge/release-1.0.7-red.svg?style=flat)
![](https://img.shields.io/badge/release-1.0.8-red.svg?style=flat)
![](https://img.shields.io/badge/Android-4.1%20--%2013-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)

Expand Down Expand Up @@ -39,14 +39,6 @@ There is a sample app in the [bytehook-sample](bytehook_sample) you can refer to

ByteHook is published on [Maven Central](https://search.maven.org/), and uses [Prefab](https://google.github.io/prefab/) package format for [native dependencies](https://developer.android.com/studio/build/native-dependencies), which is supported by [Android Gradle Plugin 4.0+](https://developer.android.com/studio/releases/gradle-plugin?buildsystem=cmake#native-dependencies).

```Gradle
allprojects {
repositories {
mavenCentral()
}
}
```

```Gradle
android {
buildFeatures {
Expand All @@ -55,10 +47,16 @@ android {
}
dependencies {
implementation 'com.bytedance:bytehook:1.0.7'
implementation 'com.bytedance:bytehook:1.0.8'
}
```

**Note**: ByteHook uses the [prefab package schema v2](https://github.com/google/prefab/releases/tag/v2.0.0), which is configured by default since [Android Gradle Plugin 7.1.0](https://developer.android.com/studio/releases/gradle-plugin?buildsystem=cmake#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
Expand Down
18 changes: 8 additions & 10 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ByteHook

![](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)
![](https://img.shields.io/badge/release-1.0.7-red.svg?style=flat)
![](https://img.shields.io/badge/release-1.0.8-red.svg?style=flat)
![](https://img.shields.io/badge/Android-4.1%20--%2013-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)

Expand Down Expand Up @@ -39,14 +39,6 @@ ByteHook 现在被用于 TikTok,抖音,今日头条,西瓜视频,飞书

ByteHook 发布在 [Maven Central](https://search.maven.org/) 上。为了使用 [native 依赖项](https://developer.android.com/studio/build/native-dependencies),ByteHook 使用了从 [Android Gradle Plugin 4.0+](https://developer.android.com/studio/releases/gradle-plugin?buildsystem=cmake#native-dependencies) 开始支持的 [Prefab](https://google.github.io/prefab/) 包格式。

```Gradle
allprojects {
repositories {
mavenCentral()
}
}
```

```Gradle
android {
buildFeatures {
Expand All @@ -55,10 +47,16 @@ android {
}
dependencies {
implementation 'com.bytedance:bytehook:1.0.7'
implementation 'com.bytedance:bytehook:1.0.8'
}
```

**注意**:ByteHook 使用 [prefab package schema v2](https://github.com/google/prefab/releases/tag/v2.0.0),它是从 [Android Gradle Plugin 7.1.0](https://developer.android.com/studio/releases/gradle-plugin?buildsystem=cmake#7-1-0) 开始作为默认配置的。如果你使用的是 Android Gradle Plugin 7.1.0 之前的版本,请在 `gradle.properties` 中加入以下配置:

```
android.prefabVersion=2.0.0
```

### 2. 在 CMakeLists.txt 或 Android.mk 中增加依赖

> CMakeLists.txt
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'com.android.application' version '7.2.2' apply false
id 'com.android.library' version '7.2.2' apply false
id 'com.android.application' version '7.4.2' apply false
id 'com.android.library' version '7.4.2' apply false
}

task clean(type: Delete) {
Expand All @@ -21,7 +21,7 @@ ext {

POM_GROUP_ID = "com.bytedance"
POM_ARTIFACT_ID = "bytehook"
POM_VERSION_NAME = "1.0.7"
POM_VERSION_NAME = "1.0.8"

POM_NAME = "bytehook"
POM_DESCRIPTION = "ByteHook is an Android PLT hook library which supports armeabi-v7a, arm64-v8a, x86 and x86_64."
Expand Down
7 changes: 7 additions & 0 deletions bytehook/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
}

android {
namespace 'com.bytedance.android.bytehook'
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
ndkVersion rootProject.ext.ndkVersion
Expand Down Expand Up @@ -48,6 +49,12 @@ android {
headers "src/main/cpp/include"
}
}
publishing {
singleVariant('release') {
withSourcesJar()
withJavadocJar()
}
}
}

apply from: rootProject.file('gradle/check.gradle')
Expand Down
3 changes: 1 addition & 2 deletions bytehook/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bytedance.android.bytehook">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
6 changes: 4 additions & 2 deletions bytehook/src/main/cpp/bh_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ bh_core_t *bh_core_global(void) {
int bh_core_init(int mode, bool debug) {
// Do not repeat the initialization.
if (BYTEHOOK_STATUS_CODE_UNINIT != bh_core.init_status) {
BH_LOG_SHOW("bytehook already inited, return %d", bh_core.init_status);
BH_LOG_SHOW("bytehook already inited, return: %d", bh_core.init_status);
return bh_core.init_status;
}

Expand Down Expand Up @@ -106,7 +106,9 @@ int bh_core_init(int mode, bool debug) {
}
pthread_mutex_unlock(&lock);

BH_LOG_SHOW("bytehook init, mode %d, debug %d, return %d", mode, debug ? 1 : 0, bh_core.init_status);
BH_LOG_SHOW("%s: bytehook init(mode: %s, debug: %s), return: %d", bytehook_get_version(),
BYTEHOOK_MODE_AUTOMATIC == mode ? "AUTOMATIC" : "MANUAL", debug ? "true" : "false",
bh_core.init_status);
return bh_core.init_status;
}

Expand Down
8 changes: 7 additions & 1 deletion bytehook/src/main/cpp/bh_jni.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
#define BH_JNI_VERSION JNI_VERSION_1_6
#define BH_JNI_CLASS_NAME "com/bytedance/android/bytehook/ByteHook"

static jstring bh_jni_get_version(JNIEnv *env, jobject thiz) {
(void)thiz;
return (*env)->NewStringUTF(env, bytehook_get_version());
}

static jint bh_jni_init(JNIEnv *env, jobject thiz, jint mode, jboolean debug) {
(void)env;
(void)thiz;
Expand Down Expand Up @@ -125,7 +130,8 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
jclass cls;
if (__predict_false(NULL == (cls = (*env)->FindClass(env, BH_JNI_CLASS_NAME)))) return JNI_ERR;

JNINativeMethod m[] = {{"nativeInit", "(IZ)I", (void *)bh_jni_init},
JNINativeMethod m[] = {{"nativeGetVersion", "()Ljava/lang/String;", (void *)bh_jni_get_version},
{"nativeInit", "(IZ)I", (void *)bh_jni_init},
{"nativeAddIgnore", "(Ljava/lang/String;)I", (void *)bh_jni_add_ignore},
{"nativeGetMode", "()I", (void *)bh_jni_get_mode},
{"nativeGetDebug", "()Z", (void *)bh_jni_get_debug},
Expand Down
4 changes: 4 additions & 0 deletions bytehook/src/main/cpp/bytehook.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
#include "bh_core.h"
#include "bh_recorder.h"

const char *bytehook_get_version(void) {
return "bytehook version " BYTEHOOK_VERSION;
}

int bytehook_init(int mode, bool debug) {
return bh_core_init(mode, debug);
}
Expand Down
1 change: 1 addition & 0 deletions bytehook/src/main/cpp/bytehook.map.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
global:
JNI_OnLoad;
bytehook_get_version;
bytehook_init;
bytehook_hook_single;
bytehook_hook_all;
Expand Down
4 changes: 4 additions & 0 deletions bytehook/src/main/cpp/include/bytehook.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
#include <stdbool.h>
#include <stdint.h>

#define BYTEHOOK_VERSION "1.0.8"

#define BYTEHOOK_STATUS_CODE_OK 0
#define BYTEHOOK_STATUS_CODE_UNINIT 1
#define BYTEHOOK_STATUS_CODE_INITERR_INVALID_ARG 2
Expand Down Expand Up @@ -83,6 +85,8 @@
extern "C" {
#endif

const char *bytehook_get_version(void);

typedef void *bytehook_stub_t;

typedef void (*bytehook_hooked_t)(bytehook_stub_t task_stub, int status_code, const char *caller_path_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public class ByteHook {
private static final boolean defaultDebug = false;
private static final boolean defaultRecordable = false;

public static String getVersion() {
return nativeGetVersion();
}

public static int init() {
return init(null);
}
Expand Down Expand Up @@ -302,6 +306,7 @@ public enum RecordItem {
STUB
}

private static native String nativeGetVersion();
private static native int nativeInit(int mode, boolean debug);
private static native int nativeAddIgnore(String callerPathName);
private static native int nativeGetMode();
Expand Down
7 changes: 4 additions & 3 deletions bytehook_sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
}

android {
namespace 'com.bytedance.android.bytehook.sample'
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
ndkVersion rootProject.ext.ndkVersion
Expand Down Expand Up @@ -53,14 +54,14 @@ android {
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

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

Expand Down
3 changes: 1 addition & 2 deletions bytehook_sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bytedance.android.bytehook.sample">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:name=".MyCustomApplication"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected void attachBaseContext(Context base) {
.setMode(ByteHook.Mode.AUTOMATIC)
// .setMode(ByteHook.Mode.MANUAL)
.setDebug(true)
// .setRecordable(true)
.setRecordable(true)
.build());
Log.i(TAG, "bytehook init, return: " + r);

Expand Down
8 changes: 7 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app"s APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
android.useAndroidX=true
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
#android.prefabVersion=2.0.0
android.disableAutomaticComponentCreation=true
22 changes: 2 additions & 20 deletions gradle/publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,14 @@ if (secretPropsFile.exists()) {
ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD')
}

task sourcesJar(type: Jar) {
archiveClassifier.set("sources")
from android.sourceSets.main.java.srcDirs
}

task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.sourceFiles
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

task javadocJar(type: Jar, dependsOn: javadoc) {
archiveClassifier.set("javadoc")
from javadoc.destinationDir
}

project.afterEvaluate {
publishing {
publications {
release(MavenPublication) {
from components.release

artifact sourcesJar
artifact javadocJar

artifactId POM_ARTIFACT_ID
groupId POM_GROUP_ID
artifactId POM_ARTIFACT_ID
version POM_VERSION_NAME

pom {
Expand Down Expand Up @@ -86,7 +68,7 @@ project.afterEvaluate {

def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
url = POM_VERSION_NAME.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl

credentials {
username ossrhUsername
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip

0 comments on commit 4d07fb8

Please sign in to comment.