Skip to content
This repository was archived by the owner on Sep 25, 2022. It is now read-only.

Commit 60d435e

Browse files
committed
update submodule and update README
1 parent e105c09 commit 60d435e

File tree

4 files changed

+135
-5
lines changed

4 files changed

+135
-5
lines changed

README.md

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,79 @@ android {
4747

4848
You can use `find_package` in `CMakeLists.txt`:
4949

50-
```
50+
```cmake
5151
add_library(mylib SHARED main.cpp)
5252
5353
# Add two lines below
5454
find_package(dexkit REQUIRED CONFIG)
5555
target_link_libraries(mylib dexkit::dex_kit_static z)
5656
```
5757

58+
At the same time, we also provide [DexKitJniHelper.h](https://github.com/LuckyPray/DexKit/blob/master/include/DexKitJniHelper.h)
59+
for the conversion of complex objects between java and c++. For example: `HashMap<String, HashSet<String>>` -> `std::map<std::string, std::set<std::string>>`
60+
61+
```c++
62+
#include<DexKitJniHelper.h>
63+
64+
extern "C"
65+
JNIEXPORT jlong JNICALL
66+
Java_me_xxx_dexkit_DexKitHelper_initDexKit(JNIEnv *env, jobject thiz,
67+
jstring apkPath) {
68+
const char *cStr = env->GetStringUTFChars(apkPath, nullptr);
69+
std::string filePathStr(cStr);
70+
auto dexkit = new dexkit::DexKit(hostApkPath);
71+
env->ReleaseStringUTFChars(apkPath, cStr);
72+
return (jlong) dexkit;
73+
}
74+
75+
extern "C"
76+
JNIEXPORT void JNICALL
77+
Java_me_xxx_dexkit_DexKitHelper_release(JNIEnv *env, jobject thiz, jlong token) {
78+
ReleaseDexKitInstance(env, token);
79+
}
80+
81+
extern "C"
82+
JNIEXPORT jobject JNICALL
83+
Java_me_xxx_dexkit_DexKitHelper_batchFindClassUsedString(JNIEnv *env,
84+
jobject thiz,
85+
jlong token,
86+
jobject map,
87+
jboolean advanced_match) {
88+
// this function is declared in DexKitJniHelper.h
89+
// For more help methods, please check the source code: https://github.com/LuckyPray/DexKit/blob/master/include/DexKitJniHelper.h
90+
return LocationClasses(env, token, map, advanced_match);
91+
}
92+
```
93+
94+
DexKitHelper.kt
95+
```kotlin
96+
class DexKitHelper(
97+
classLoader: ClassLoader
98+
) {
99+
100+
private var token: Long = 0
101+
102+
init {
103+
token = initDexKit(classLoader)
104+
}
105+
106+
private external fun initDexKit(apkPath: String): Long
107+
108+
/**
109+
* free space allocated by c++
110+
*/
111+
private external fun release(token: Long)
112+
113+
private external fun batchFindClassUsedString(
114+
token: Long,
115+
map: Map<String, Set<String>>,
116+
advancedMatch: Boolean = false,
117+
): Map<String, Array<String>>
118+
119+
// omit...
120+
}
121+
```
122+
58123
## Example
59124

60125
- [main.cpp](https://github.com/LuckyPray/DexKit/blob/master/main.cpp)

README_zh.md

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,80 @@ android {
4747

4848
你可以直接在 `CMakeLists.txt` 中使用 `find_package` 来使用 DexKit:
4949

50-
```
51-
# 假设你的 library 名字为 mylib
50+
```cmake
5251
add_library(mylib SHARED main.cpp)
5352
5453
# 添加如下两行,注意必须添加 libz,如果你有其他依赖可以放在后面
5554
find_package(dexkit REQUIRED CONFIG)
5655
target_link_libraries(mylib dexkit::dex_kit_static z)
5756
```
5857

58+
同时,我们提供了 [DexKitJniHelper.h](https://github.com/LuckyPray/DexKit/blob/master/include/DexKitJniHelper.h)
59+
用于java与c++之间复杂对象的转换,例如:`HashMap<String, HashSet<String>>` -> `std::map<std::string, std::set<std::string>>`
60+
61+
dexkit.cpp
62+
```c++
63+
#include<DexKitJniHelper.h>
64+
65+
extern "C"
66+
JNIEXPORT jlong JNICALL
67+
Java_me_xxx_dexkit_DexKitHelper_initDexKit(JNIEnv *env, jobject thiz,
68+
jstring apkPath) {
69+
const char *cStr = env->GetStringUTFChars(apkPath, nullptr);
70+
std::string filePathStr(cStr);
71+
auto dexkit = new dexkit::DexKit(hostApkPath);
72+
env->ReleaseStringUTFChars(apkPath, cStr);
73+
return (jlong) dexkit;
74+
}
75+
76+
extern "C"
77+
JNIEXPORT void JNICALL
78+
Java_me_xxx_dexkit_DexKitHelper_release(JNIEnv *env, jobject thiz, jlong token) {
79+
ReleaseDexKitInstance(env, token);
80+
}
81+
82+
extern "C"
83+
JNIEXPORT jobject JNICALL
84+
Java_me_xxx_dexkit_DexKitHelper_batchFindClassUsedString(JNIEnv *env,
85+
jobject thiz,
86+
jlong token,
87+
jobject map,
88+
jboolean advanced_match) {
89+
// 该方法定义于 DexKitJniHelper.h
90+
// 获取更多辅助方法请参阅源码:https://github.com/LuckyPray/DexKit/blob/master/include/DexKitJniHelper.h
91+
return LocationClasses(env, token, map, advanced_match);
92+
}
93+
```
94+
95+
DexKitHelper.kt
96+
```kotlin
97+
class DexKitHelper(
98+
classLoader: ClassLoader
99+
) {
100+
101+
private var token: Long = 0
102+
103+
init {
104+
token = initDexKit(classLoader)
105+
}
106+
107+
private external fun initDexKit(apkPath: String): Long
108+
109+
/**
110+
* 释放c++分配的空间
111+
*/
112+
private external fun release(token: Long)
113+
114+
private external fun batchFindClassUsedString(
115+
token: Long,
116+
map: Map<String, Set<String>>,
117+
advancedMatch: Boolean = false,
118+
): Map<String, Array<String>>
119+
120+
// 省略... omit...
121+
}
122+
```
123+
59124
## 使用示例
60125

61126
- [main.cpp](https://github.com/LuckyPray/DexKit/blob/master/main.cpp)

dexkit/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ afterEvaluate {
5050
from components.release
5151

5252
// You can then customize attributes of the publication as shown below.
53-
groupId = 'me.teble'
53+
groupId = 'io.luckypray'
5454
artifactId = 'dexkit'
5555
version = '1.0'
5656
}

dexkit/src/main/DexKit

0 commit comments

Comments
 (0)