Skip to content

Commit

Permalink
chore: migrate to new changes from the patcher
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Oct 5, 2022
1 parent 839854d commit e035d93
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repositories {
dependencies {
implementation(kotlin("reflect"))

implementation("app.revanced:revanced-patcher:5.1.2")
implementation("app.revanced:revanced-patcher:6.0.0")
implementation("info.picocli:picocli:4.6.3")
implementation("com.android.tools.build:apksig:7.2.1")
implementation("com.github.revanced:jadb:master-SNAPSHOT") // updated fork
Expand Down
11 changes: 6 additions & 5 deletions src/main/kotlin/app/revanced/cli/command/MainCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import app.revanced.patcher.PatcherOptions
import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages
import app.revanced.patcher.extensions.PatchExtensions.description
import app.revanced.patcher.extensions.PatchExtensions.patchName
import app.revanced.patcher.util.patch.impl.JarPatchBundle
import app.revanced.patcher.util.patch.PatchBundle
import app.revanced.utils.OptionsLoader
import app.revanced.utils.adb.Adb
import picocli.CommandLine.*
Expand Down Expand Up @@ -131,7 +131,7 @@ internal object MainCommand : Runnable {
val outputFile = File(pArgs.outputPath) // the file to write to

val allPatches = args.patchArgs!!.patchBundles.flatMap { bundle ->
JarPatchBundle(bundle).loadPatches()
PatchBundle.Jar(bundle).loadPatches()
}

OptionsLoader.init(args.patchArgs!!.options, allPatches)
Expand All @@ -148,7 +148,7 @@ internal object MainCommand : Runnable {

// prepare adb
val adb: Adb? = args.deploy?.let {
Adb(outputFile, patcher.data.packageMetadata.packageName, args.deploy!!, !pArgs.mount)
Adb(outputFile, patcher.context.packageMetadata.packageName, args.deploy!!, !pArgs.mount)
}

val patchedFile = File(pArgs.cacheDirectory).resolve("${outputFile.nameWithoutExtension}_raw.apk")
Expand Down Expand Up @@ -209,7 +209,7 @@ internal object MainCommand : Runnable {
val adb: Adb? = args.deploy?.let {
Adb(
File("placeholder_file"),
app.revanced.patcher.Patcher(PatcherOptions(args.inputFile, "")).data.packageMetadata.packageName,
app.revanced.patcher.Patcher(PatcherOptions(args.inputFile, "")).context.packageMetadata.packageName,
args.deploy!!,
false
)
Expand All @@ -219,7 +219,8 @@ internal object MainCommand : Runnable {

private fun printListOfPatches() {
val logged = mutableListOf<String>()
for (patchBundlePath in args.patchArgs?.patchBundles!!) for (patch in JarPatchBundle(patchBundlePath).loadPatches()) {
for (patchBundlePath in args.patchArgs?.patchBundles!!) for (patch in PatchBundle.Jar(patchBundlePath)
.loadPatches()) {
if (patch.patchName in logged) continue
for (compatiblePackage in patch.compatiblePackages!!) {
val packageEntryStr = buildString {
Expand Down
8 changes: 6 additions & 2 deletions src/main/kotlin/app/revanced/cli/patcher/Patcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app.revanced.cli.patcher

import app.revanced.cli.command.MainCommand.args
import app.revanced.cli.command.MainCommand.logger
import app.revanced.patcher.data.Data
import app.revanced.patcher.data.Context
import app.revanced.patcher.patch.Patch
import app.revanced.utils.filesystem.ZipFileSystemUtils
import app.revanced.utils.patcher.addPatchesFiltered
Expand All @@ -12,7 +12,11 @@ import java.io.File
import java.nio.file.Files

internal object Patcher {
internal fun start(patcher: app.revanced.patcher.Patcher, output: File, allPatches: List<Class<out Patch<Data>>>) {
internal fun start(
patcher: app.revanced.patcher.Patcher,
output: File,
allPatches: List<Class<out Patch<Context>>>
) {
val inputFile = args.inputFile

// merge files like necessary integrations
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/app/revanced/utils/OptionsLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app.revanced.utils

import app.revanced.cli.command.MainCommand.logger
import app.revanced.patcher.Patcher
import app.revanced.patcher.data.Data
import app.revanced.patcher.data.Context
import app.revanced.patcher.extensions.PatchExtensions.options
import app.revanced.patcher.extensions.PatchExtensions.patchName
import app.revanced.patcher.patch.Patch
Expand All @@ -12,7 +12,7 @@ import cc.ekblad.toml.serialization.from
import cc.ekblad.toml.tomlMapper
import java.io.File

private typealias PatchList = List<Class<out Patch<Data>>>
private typealias PatchList = List<Class<out Patch<Context>>>
private typealias OptionsMap = MutableMap<String, MutableMap<String, Any>>

object OptionsLoader {
Expand Down
12 changes: 6 additions & 6 deletions src/main/kotlin/app/revanced/utils/patcher/Patcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import app.revanced.cli.command.MainCommand
import app.revanced.cli.command.MainCommand.args
import app.revanced.cli.command.MainCommand.logger
import app.revanced.patcher.Patcher
import app.revanced.patcher.data.Data
import app.revanced.patcher.data.Context
import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages
import app.revanced.patcher.extensions.PatchExtensions.deprecated
import app.revanced.patcher.extensions.PatchExtensions.include
import app.revanced.patcher.extensions.PatchExtensions.patchName
import app.revanced.patcher.patch.Patch

fun Patcher.addPatchesFiltered(allPatches: List<Class<out Patch<Data>>>) {
val packageName = this.data.packageMetadata.packageName
val packageVersion = this.data.packageMetadata.packageVersion
fun Patcher.addPatchesFiltered(allPatches: List<Class<out Patch<Context>>>) {
val packageName = this.context.packageMetadata.packageName
val packageVersion = this.context.packageMetadata.packageVersion

val includedPatches = mutableListOf<Class<out Patch<Data>>>()
val includedPatches = mutableListOf<Class<out Patch<Context>>>()
allPatches.forEach patchLoop@{ patch ->
val compatiblePackages = patch.compatiblePackages
val patchName = patch.patchName
Expand Down Expand Up @@ -66,7 +66,7 @@ fun Patcher.addPatchesFiltered(allPatches: List<Class<out Patch<Data>>>) {
}

fun Patcher.applyPatchesVerbose() {
this.applyPatches().forEach { (patch, result) ->
this.executePatches().forEach { (patch, result) ->
if (result.isSuccess) {
logger.info("$patch succeeded")
return@forEach
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package app.revanced.utils.signing.align.zip.structures

import app.revanced.utils.signing.align.zip.getUShort
import app.revanced.utils.signing.align.zip.putUInt
import app.revanced.utils.signing.align.zip.putUShort
import app.revanced.utils.signing.align.zip.readUIntLE
import app.revanced.utils.signing.align.zip.readUShortLE
import app.revanced.utils.signing.align.zip.*
import java.io.DataInput
import java.nio.ByteBuffer
import java.nio.ByteOrder
Expand Down

0 comments on commit e035d93

Please sign in to comment.