forked from ReVanced/revanced-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainCommand.kt
96 lines (75 loc) 路 3.3 KB
/
MainCommand.kt
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
package app.revanced.cli
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.extensions.findAnnotationRecursively
import app.revanced.patcher.util.patch.implementation.JarPatchBundle
import app.revanced.utils.adb.Adb
import app.revanced.utils.patcher.addPatchesFiltered
import app.revanced.utils.signature.Signature
import picocli.CommandLine.*
import java.io.File
@Command(
name = "ReVanced-CLI", version = ["1.0.0"], mixinStandardHelpOptions = true
)
internal object MainCommand : Runnable {
@Parameters(
paramLabel = "INCLUDE",
description = ["Which patches to include. If none is specified, all compatible patches will be included"]
)
internal var includedPatches = arrayOf<String>()
@Option(names = ["-p", "--patches"], description = ["One or more bundles of patches"])
internal var patchBundles = arrayOf<String>()
@Option(names = ["-t", "--temp-dir"], description = ["Temporal resource cache directory"], required = true)
internal lateinit var cacheDirectory: String
@Option(names = ["-r", "--resource-patcher"], description = ["Enable patching resources"])
internal var patchResources: Boolean = false
@Option(
names = ["-c", "--clean"],
description = ["Clean the temporal resource cache directory. This will be done anyways when running the patcher"]
)
internal var clean: Boolean = false
@Option(names = ["-l", "--list"], description = ["List patches only"])
internal var listOnly: Boolean = false
@Option(names = ["-s", "--signature-checker"], description = ["Check signatures of all patches"])
internal var signatureCheck: Boolean = false
@Option(names = ["-m", "--merge"], description = ["One or more dex file containers to merge"])
internal var mergeFiles = listOf<File>()
@Option(names = ["-a", "--apk"], description = ["Input file to be patched"], required = true)
internal lateinit var inputFile: File
@Option(names = ["-o", "--out"], description = ["Output file path"], required = true)
internal lateinit var outputPath: String
@Option(names = ["-d", "--deploy-on"], description = ["If specified, deploy to adb device with given name"])
internal var deploy: String? = null
override fun run() {
if (listOnly) {
for (patchBundlePath in patchBundles)
for (it in JarPatchBundle(patchBundlePath).loadPatches())
println(
"[available] ${
it.javaClass.findAnnotationRecursively(
Name::class.java
)?.name ?: Name::class.java.name
}"
)
return
}
val patcher = app.revanced.patcher.Patcher(
inputFile, cacheDirectory, patchResources
)
if (signatureCheck) {
patcher.addPatchesFiltered()
Signature.checkSignatures(patcher)
return
}
val outputFile = File(outputPath)
var adb: Adb? = null
deploy?.let {
adb = Adb(
outputFile, patcher.packageName, deploy!!
)
}
Patcher.start(patcher)
if (clean) File(cacheDirectory).deleteRecursively()
adb?.deploy()
if (clean) outputFile.delete()
}
}