Skip to content

Commit e8050fc

Browse files
authored
Merge pull request #3 from wukaicheng/main
Real Support APK
2 parents 2d2bd94 + 376dc90 commit e8050fc

File tree

6 files changed

+84
-6
lines changed

6 files changed

+84
-6
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
> BlackObfuscator GUI 工具
44
55
需要打包成jar包,然后将BlackObfuscator下载到本地,然后重命名成dex-tools
6+
> 可直接在release界面下载解压运行
7+
> 虽然目前只提供了Windows的Release包,但是我觉得能够在所有平台上面运行,毕竟是jar
68
79
1.前往BlackObfuscator Release界面下载最新的工具
810
> https://github.com/CodingGay/BlackObfuscator/releases
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package cn.kaicity.common.repository
2+
3+
import cn.kaicity.common.bean.InputBean
4+
import net.lingala.zip4j.ZipFile
5+
import java.io.File
6+
7+
object ApkObf {
8+
9+
suspend fun run(inputBean: InputBean, logCallback: (log: String) -> Unit) {
10+
val workDir = File(File(inputBean.output).parentFile, "temp")
11+
try {
12+
val originApk = File(inputBean.input)
13+
if (!originApk.exists()) {
14+
logCallback.invoke("Apk not Exists")
15+
return
16+
}
17+
18+
val targetApk = File(inputBean.output)
19+
if (targetApk.exists()) {
20+
targetApk.delete()
21+
}
22+
23+
logCallback.invoke("Start Unzip Apk")
24+
25+
unzip(originApk.absolutePath, workDir.absolutePath)
26+
27+
val dexList = workDir.listFiles { name ->
28+
name.extension == "dex"
29+
}
30+
dexList?.forEach {
31+
logCallback.invoke("Start Obfuscator ${it.name}")
32+
val dexInputBean =
33+
InputBean(it.absolutePath, workDir.absolutePath + "/" + it.name, inputBean.depth, inputBean.rule)
34+
DexObf.run(dexInputBean, logCallback)
35+
}
36+
37+
logCallback.invoke("Start Package Apk")
38+
39+
zip(workDir.absolutePath, originApk, targetApk)
40+
41+
} catch (e: Exception) {
42+
logCallback.invoke("Error!!!")
43+
logCallback.invoke(e.message.toString())
44+
} finally {
45+
removeFile(workDir)
46+
}
47+
48+
}
49+
50+
private fun removeFile(file: File) {
51+
if (file.isFile) {
52+
file.delete()
53+
} else if (file.isDirectory) {
54+
file.listFiles()?.forEach(::removeFile)
55+
file.delete()
56+
}
57+
}
58+
59+
private fun zip(path: String, origin: File, targetApk: File) {
60+
val dexList = File(path).listFiles { name ->
61+
name.extension == "dex"
62+
}?.toList()
63+
64+
origin.copyTo(targetApk)
65+
ZipFile(targetApk).use {
66+
it.addFiles(dexList)
67+
}
68+
69+
}
70+
71+
72+
private fun unzip(apk: String, path: String) {
73+
ZipFile(apk).use {
74+
it.extractAll(path)
75+
}
76+
}
77+
78+
}

common/src/commonMain/kotlin/cn/kaicity/common/widget/MainView.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,11 @@ fun MainView(modifier: Modifier, btnClick: (InputBean) -> Unit) {
121121
depthIsError = depth.isEmpty()
122122
//pkgIsError do not need check
123123

124+
124125
if (inputIsError || outputIsError || depthIsError) {
125126
return@Button
126127
}
128+
127129
btnClick.invoke(InputBean(input, output, depth, rule))
128130
}) {
129131
Text("Obfuscator")

common/src/desktopMain/kotlin/cn/kaicity/common/platform/IFileHelper.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,3 @@ actual fun saveFile(callback:(String)->Unit) {
2222
}
2323
return callback(fileDialog.directory + fileDialog.file)
2424
}
25-

desktop/build.gradle.kts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ compose.desktop {
3232
mainClass = "MainKt"
3333
nativeDistributions {
3434
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
35-
packageName = "jvm"
35+
packageName = "BlackObfuscator"
3636
packageVersion = "1.0.0"
37-
38-
appResourcesRootDir.set(project.layout.projectDirectory.dir("lib"))
3937
}
4038
}
4139
}

settings.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ pluginManagement {
66
mavenCentral()
77
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
88
}
9-
9+
1010
}
1111
rootProject.name = "BlackObfuscator-GUI"
1212

1313

1414
include(":android")
1515
include(":desktop")
1616
include(":common")
17-

0 commit comments

Comments
 (0)