diff --git a/build.gradle.kts b/build.gradle.kts index 32f6bc1..e678d1d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,13 +9,21 @@ group = "app.revanced" repositories { mavenCentral() + maven { + url = uri("https://maven.pkg.github.com/ReVancedTeam/multidexlib2") + credentials { + username = project.findProperty("gpr.user") as String? ?: System.getenv("GITHUB_ACTOR") // DO NOT CHANGE! + password = project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN") // DO NOT CHANGE! + } + } } dependencies { implementation(kotlin("stdlib")) - implementation("com.github.lanchon.dexpatcher:multidexlib2:2.3.4.r2") - implementation("org.smali:smali:2.3.4") + implementation("app.revanced:multidexlib2:2.5.2") + @Suppress("GradlePackageUpdate") + implementation("org.smali:smali:2.5.2") testImplementation(kotlin("test")) } diff --git a/src/main/kotlin/app/revanced/patcher/Patcher.kt b/src/main/kotlin/app/revanced/patcher/Patcher.kt index 87eba7d..d3b8910 100644 --- a/src/main/kotlin/app/revanced/patcher/Patcher.kt +++ b/src/main/kotlin/app/revanced/patcher/Patcher.kt @@ -12,6 +12,7 @@ import lanchon.multidexlib2.MultiDexIO import org.jf.dexlib2.Opcodes import org.jf.dexlib2.iface.ClassDef import org.jf.dexlib2.iface.DexFile +import org.jf.dexlib2.writer.io.MemoryDataStore import java.io.File val NAMER = BasicDexFileNamer() @@ -19,12 +20,10 @@ val NAMER = BasicDexFileNamer() /** * ReVanced Patcher. * @param input The input file (an apk or any other multi dex container). - * @param output The output folder. * @param signatures An array of method signatures for the patches */ class Patcher( input: File, - private val output: File, signatures: Array, ) { private val cache: Cache @@ -57,7 +56,7 @@ class Patcher( /** * Save the patched dex file. */ - fun save() { + fun save(): List { val newDexFile = object : DexFile { override fun getClasses(): Set { // this is a slow workaround for now @@ -77,12 +76,14 @@ class Patcher( } } + val list = mutableListOf() MultiDexIO.writeDexFile( true, -1, // core count - output, NAMER, newDexFile, + list, NAMER, newDexFile, DexIO.DEFAULT_MAX_DEX_POOL_SIZE, null ) + return list } /** diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableField.kt b/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableField.kt index fe8bedd..cfd755a 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableField.kt +++ b/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableField.kt @@ -2,6 +2,7 @@ package app.revanced.patcher.proxy.mutableTypes import app.revanced.patcher.proxy.mutableTypes.MutableAnnotation.Companion.toMutable import app.revanced.patcher.proxy.mutableTypes.MutableEncodedValue.Companion.toMutable +import org.jf.dexlib2.HiddenApiRestriction import org.jf.dexlib2.base.reference.BaseFieldReference import org.jf.dexlib2.iface.Field @@ -12,6 +13,7 @@ class MutableField(field: Field) : Field, BaseFieldReference() { private var accessFlags = field.accessFlags private var initialValue = field.initialValue?.toMutable() private val _annotations by lazy { field.annotations.map { annotation -> annotation.toMutable() }.toMutableSet() } + private val _hiddenApiRestrictions by lazy { field.hiddenApiRestrictions } fun setDefiningClass(definingClass: String) { this.definingClass = definingClass @@ -53,6 +55,10 @@ class MutableField(field: Field) : Field, BaseFieldReference() { return this.accessFlags } + override fun getHiddenApiRestrictions(): MutableSet { + return this._hiddenApiRestrictions + } + override fun getInitialValue(): MutableEncodedValue? { return this.initialValue } diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableMethod.kt b/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableMethod.kt index cf721e5..2a778a5 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableMethod.kt +++ b/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableMethod.kt @@ -2,6 +2,7 @@ package app.revanced.patcher.proxy.mutableTypes import app.revanced.patcher.proxy.mutableTypes.MutableAnnotation.Companion.toMutable import app.revanced.patcher.proxy.mutableTypes.MutableMethodParameter.Companion.toMutable +import org.jf.dexlib2.HiddenApiRestriction import org.jf.dexlib2.base.reference.BaseMethodReference import org.jf.dexlib2.builder.MutableMethodImplementation import org.jf.dexlib2.iface.Method @@ -17,9 +18,10 @@ class MutableMethod(method: Method) : Method, BaseMethodReference() { private val _annotations by lazy { method.annotations.map { annotation -> annotation.toMutable() }.toMutableSet() } private val _parameters by lazy { method.parameters.map { parameter -> parameter.toMutable() }.toMutableList() } private val _parameterTypes by lazy { method.parameterTypes.toMutableList() } + private val _hiddenApiRestrictions by lazy { method.hiddenApiRestrictions } override fun getDefiningClass(): String { - return this.definingClass + return definingClass } override fun getName(): String { @@ -42,6 +44,10 @@ class MutableMethod(method: Method) : Method, BaseMethodReference() { return accessFlags } + override fun getHiddenApiRestrictions(): MutableSet { + return _hiddenApiRestrictions + } + override fun getParameters(): MutableList { return _parameters } diff --git a/src/test/kotlin/app/revanced/patcher/PatcherTest.kt b/src/test/kotlin/app/revanced/patcher/PatcherTest.kt index f2b78b1..c2b3cb9 100644 --- a/src/test/kotlin/app/revanced/patcher/PatcherTest.kt +++ b/src/test/kotlin/app/revanced/patcher/PatcherTest.kt @@ -19,6 +19,7 @@ import org.jf.dexlib2.immutable.ImmutableMethodImplementation import org.jf.dexlib2.immutable.reference.ImmutableStringReference import org.junit.jupiter.api.Test import java.io.File +import kotlin.test.assertTrue internal class PatcherTest { companion object { @@ -41,7 +42,6 @@ internal class PatcherTest { fun testPatcher() { val patcher = Patcher( File(PatcherTest::class.java.getResource("/test1.dex")!!.toURI()), - File("."), testSignatures ) @@ -90,6 +90,7 @@ internal class PatcherTest { "Ljava/lang/String;", AccessFlags.PRIVATE or AccessFlags.STATIC, null, + null, ImmutableMethodImplementation( 1, ImmutableList.of( @@ -156,17 +157,7 @@ internal class PatcherTest { } } - patcher.save() - } - - @Test - fun `test patcher with no changes`() { - Patcher( - File(PatcherTest::class.java.getResource("/test1.dex")!!.toURI()), - File("."), - testSignatures - ).save() - // FIXME(Sculas): There seems to be a 1-byte difference, not sure what it is. - // assertEquals(available, out.size()) + val out = patcher.save() + assertTrue(out.isNotEmpty(), "Expected the output of Patcher#save() to not be empty.") } }