-
Notifications
You must be signed in to change notification settings - Fork 37
/
build.gradle
133 lines (113 loc) · 4.47 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
plugins {
alias(libs.plugins.androidApplication)
}
android {
namespace 'cn.mrack.xposed.nhook'
compileSdk 34
defaultConfig {
applicationId "cn.mrack.xposed.nhook"
minSdk 24
targetSdk 34
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk {
abiFilters 'arm64-v8a'
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
externalNativeBuild {
cmake {
path file('src/main/cpp/CMakeLists.txt')
version '3.22.1'
}
}
buildFeatures {
buildConfig = true
}
project.tasks.whenTaskAdded { task ->
if (task.name == 'stripDebugDebugSymbols') {
task.finalizedBy dealAfterMergeDebugNativeLibs
}
if (task.name == 'stripReleaseDebugSymbols') {
task.finalizedBy dealAfterMergeReleaseNativeLibs
}
}
task dealAfterMergeReleaseNativeLibs() {
doLast {
var arch = ["arm64", "v7a"]
var version = "release"
generate(version, arch)
}
}
task dealAfterMergeDebugNativeLibs() {
doLast {
var arch = ["arm64", "v7a"]
var version = "debug"
generate(version, arch)
}
}
}
dependencies {
compileOnly 'de.robv.android.xposed:api:82'
}
def generate(version, archs) {
def MERGED_NATIVE_LIBS_PATH = "$buildDir/intermediates/stripped_native_libs"
var fileList = fileTree("$MERGED_NATIVE_LIBS_PATH/$version").matching {
include '**/lib*.so'
}.collect()
var length = 32000
for (final def data in fileList) {
for (arch in archs) {
if (data.path.contains("$arch")) {
byte[] fileBytes = data.bytes
if (fileBytes == "placeholder".bytes) {
continue
}
data.bytes = "placeholder".bytes
delete file("src/main/java/cn/mrack/so/$arch")
file("src/main/java/cn/mrack/so/$arch").mkdirs()
int i = fileBytes.length / length
String totalText = "";
for (int j = 0; j < i; j++) {
byte[] temp = new byte[length];
System.arraycopy(fileBytes, j * length, temp, 0, length);
// hex
file("src/main/java/cn/mrack/so/$arch/SoData${j}.java").text = "package cn.mrack.so.$arch;\n" +
"public class SoData$j {\n" +
" protected static String data${j} = \"" + temp.collect { String.format("%02X", it) }.join("") + "\";\n" +
"}";
totalText += "SoData${j}.data${j} + ";
}
byte[] temp = new byte[fileBytes.length - i * length];
System.arraycopy(fileBytes, i * length, temp, 0, fileBytes.length - i * length);
file("src/main/java/cn/mrack/so/$arch/SoData${i}.java").text = "package cn.mrack.so.$arch;\n" +
"public class SoData${i} {\n" +
" protected static String data${i} = \"" + temp.collect { String.format("%02X", it) }.join("") + "\";\n" +
"}";
totalText += "SoData${i}.data${i}";
file("src/main/java/cn/mrack/so/$arch/SoData.java").text = "package cn.mrack.so.$arch;\n" +
"public class SoData {\n" +
" public static byte[] data = hexToBytes(" + totalText + ");\n" +
" public static String md5 = \"${fileBytes.md5().toLowerCase()}\";\n" +
" public static byte[] hexToBytes(String hex) {\n" +
" byte[] bytes = new byte[hex.length() / 2];\n" +
" for (int i = 0; i < hex.length(); i += 2) {\n" +
" bytes[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4) + Character.digit(hex.charAt(i + 1), 16));\n" +
" }\n" +
" return bytes;\n" +
" }\n" +
"}";
}
}
}
}