mirror of
https://github.com/revanced/revanced-cli.git
synced 2024-12-05 01:42:54 +01:00
feat: Add progress bar
This commit is contained in:
parent
bea8b829c7
commit
8d96ec83cb
@ -28,6 +28,7 @@ dependencies {
|
|||||||
implementation(patchesDependency)
|
implementation(patchesDependency)
|
||||||
|
|
||||||
implementation("com.google.code.gson:gson:2.9.0")
|
implementation("com.google.code.gson:gson:2.9.0")
|
||||||
|
implementation("me.tongfei:progressbar:0.9.3")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
|
@ -5,9 +5,12 @@ import app.revanced.cli.utils.Patches
|
|||||||
import app.revanced.cli.utils.Preconditions
|
import app.revanced.cli.utils.Preconditions
|
||||||
import app.revanced.cli.utils.SignatureParser
|
import app.revanced.cli.utils.SignatureParser
|
||||||
import app.revanced.patcher.Patcher
|
import app.revanced.patcher.Patcher
|
||||||
|
import app.revanced.patcher.patch.PatchResult
|
||||||
import kotlinx.cli.ArgParser
|
import kotlinx.cli.ArgParser
|
||||||
import kotlinx.cli.ArgType
|
import kotlinx.cli.ArgType
|
||||||
import kotlinx.cli.required
|
import kotlinx.cli.required
|
||||||
|
import me.tongfei.progressbar.ProgressBarBuilder
|
||||||
|
import me.tongfei.progressbar.ProgressBarStyle
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
|
|
||||||
@ -23,35 +26,71 @@ class Main {
|
|||||||
inIntegrations: String?,
|
inIntegrations: String?,
|
||||||
inOutput: String,
|
inOutput: String,
|
||||||
) {
|
) {
|
||||||
|
val bar = ProgressBarBuilder()
|
||||||
|
.setTaskName("Working..")
|
||||||
|
.setUpdateIntervalMillis(25)
|
||||||
|
.continuousUpdate()
|
||||||
|
.setStyle(ProgressBarStyle.ASCII)
|
||||||
|
.build()
|
||||||
|
.maxHint(1)
|
||||||
|
.setExtraMessage("Initializing")
|
||||||
val apk = Preconditions.isFile(inApk)
|
val apk = Preconditions.isFile(inApk)
|
||||||
val signatures = Preconditions.isFile(inSignatures)
|
val signatures = Preconditions.isFile(inSignatures)
|
||||||
val patchesFile = Preconditions.isFile(inPatches)
|
val patchesFile = Preconditions.isFile(inPatches)
|
||||||
val output = Preconditions.isDirectory(inOutput)
|
val output = Preconditions.isDirectory(inOutput)
|
||||||
|
bar.step()
|
||||||
|
|
||||||
val patcher = Patcher(
|
val patcher = Patcher(
|
||||||
apk,
|
apk,
|
||||||
SignatureParser
|
SignatureParser.parse(signatures.readText(), bar)
|
||||||
.parse(signatures.readText())
|
|
||||||
.toTypedArray()
|
|
||||||
)
|
)
|
||||||
|
|
||||||
inIntegrations?.let {
|
inIntegrations?.let {
|
||||||
|
bar.reset().maxHint(1)
|
||||||
|
.extraMessage = "Merging integrations"
|
||||||
val integrations = Preconditions.isFile(it)
|
val integrations = Preconditions.isFile(it)
|
||||||
patcher.addFiles(integrations)
|
patcher.addFiles(integrations)
|
||||||
|
bar.step()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bar.reset().maxHint(1)
|
||||||
|
.extraMessage = "Loading patches"
|
||||||
PatchLoader.injectPatches(patchesFile)
|
PatchLoader.injectPatches(patchesFile)
|
||||||
val patches = Patches.loadPatches()
|
bar.step()
|
||||||
patcher.addPatches(*patches.map { it() }.toTypedArray())
|
|
||||||
|
|
||||||
val results = patcher.applyPatches()
|
val patches = Patches.loadPatches().map { it() }
|
||||||
for ((name, result) in results) {
|
patcher.addPatches(patches)
|
||||||
println("$name: $result")
|
|
||||||
|
val amount = patches.size.toLong()
|
||||||
|
bar.reset().maxHint(amount)
|
||||||
|
.extraMessage = "Applying patches"
|
||||||
|
val results = patcher.applyPatches {
|
||||||
|
bar.step().extraMessage = "Applying $it"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bar.reset().maxHint(-1)
|
||||||
|
.extraMessage = "Generating dex files"
|
||||||
val dexFiles = patcher.save()
|
val dexFiles = patcher.save()
|
||||||
|
bar.reset().maxHint(dexFiles.size.toLong())
|
||||||
|
.extraMessage = "Saving dex files"
|
||||||
dexFiles.forEach { (dexName, dexData) ->
|
dexFiles.forEach { (dexName, dexData) ->
|
||||||
Files.write(File(output, dexName).toPath(), dexData.buffer)
|
Files.write(File(output, dexName).toPath(), dexData.buffer)
|
||||||
|
bar.step()
|
||||||
|
}
|
||||||
|
bar.close()
|
||||||
|
|
||||||
|
println("All done!")
|
||||||
|
printResults(results)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun printResults(results: Map<String, Result<PatchResult>>) {
|
||||||
|
for ((name, result) in results) {
|
||||||
|
if (result.isSuccess) {
|
||||||
|
println("Patch $name was applied successfully!")
|
||||||
|
} else {
|
||||||
|
println("Patch $name failed to apply! Cause:")
|
||||||
|
result.exceptionOrNull()!!.printStackTrace()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,13 +2,17 @@ package app.revanced.cli.utils
|
|||||||
|
|
||||||
import app.revanced.patcher.signature.MethodSignature
|
import app.revanced.patcher.signature.MethodSignature
|
||||||
import com.google.gson.JsonParser
|
import com.google.gson.JsonParser
|
||||||
|
import me.tongfei.progressbar.ProgressBar
|
||||||
import org.jf.dexlib2.AccessFlags
|
import org.jf.dexlib2.AccessFlags
|
||||||
import org.jf.dexlib2.Opcodes
|
import org.jf.dexlib2.Opcodes
|
||||||
|
|
||||||
class SignatureParser {
|
class SignatureParser {
|
||||||
companion object {
|
companion object {
|
||||||
fun parse(json: String): List<MethodSignature> {
|
fun parse(json: String, bar: ProgressBar): List<MethodSignature> {
|
||||||
val signatures = JsonParser.parseString(json).asJsonObject.get("signatures").asJsonArray.map { sig ->
|
val tmp = JsonParser.parseString(json).asJsonObject.get("signatures").asJsonArray
|
||||||
|
bar.reset().maxHint(tmp.size().toLong())
|
||||||
|
.extraMessage = "Parsing signatures"
|
||||||
|
val signatures = tmp.map { sig ->
|
||||||
val signature = sig.asJsonObject
|
val signature = sig.asJsonObject
|
||||||
val returnType = signature.get("returns").asString
|
val returnType = signature.get("returns").asString
|
||||||
|
|
||||||
@ -19,21 +23,21 @@ class SignatureParser {
|
|||||||
|
|
||||||
val parameters = signature.get("parameters").asJsonArray
|
val parameters = signature.get("parameters").asJsonArray
|
||||||
.map { it.asString }
|
.map { it.asString }
|
||||||
.toTypedArray()
|
|
||||||
|
|
||||||
val opcodes = signature.get("opcodes").asJsonArray
|
val opcodes = signature.get("opcodes").asJsonArray
|
||||||
.map { Opcodes.getDefault().getOpcodeByName(it.asString)!! }
|
.map { Opcodes.getDefault().getOpcodeByName(it.asString)!! }
|
||||||
.toTypedArray()
|
|
||||||
|
|
||||||
|
val name = signature.get("name").asString
|
||||||
|
bar.step()
|
||||||
|
.extraMessage = "Parsing $name"
|
||||||
MethodSignature(
|
MethodSignature(
|
||||||
signature.get("name").asString,
|
name,
|
||||||
returnType,
|
returnType,
|
||||||
accessFlags,
|
accessFlags,
|
||||||
parameters,
|
parameters,
|
||||||
opcodes
|
opcodes
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return signatures
|
return signatures
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user