mirror of
https://github.com/revanced/revanced-patcher.git
synced 2025-05-01 05:44:24 +02:00
refactor: bump multidexlib2, dexlib2 and smali
This commit is contained in:
parent
08253ee010
commit
94dbb573cf
@ -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"))
|
||||
}
|
||||
|
@ -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<MethodSignature>,
|
||||
) {
|
||||
private val cache: Cache
|
||||
@ -57,7 +56,7 @@ class Patcher(
|
||||
/**
|
||||
* Save the patched dex file.
|
||||
*/
|
||||
fun save() {
|
||||
fun save(): List<MemoryDataStore> {
|
||||
val newDexFile = object : DexFile {
|
||||
override fun getClasses(): Set<ClassDef> {
|
||||
// this is a slow workaround for now
|
||||
@ -77,12 +76,14 @@ class Patcher(
|
||||
}
|
||||
}
|
||||
|
||||
val list = mutableListOf<MemoryDataStore>()
|
||||
MultiDexIO.writeDexFile(
|
||||
true, -1, // core count
|
||||
output, NAMER, newDexFile,
|
||||
list, NAMER, newDexFile,
|
||||
DexIO.DEFAULT_MAX_DEX_POOL_SIZE,
|
||||
null
|
||||
)
|
||||
return list
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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<HiddenApiRestriction> {
|
||||
return this._hiddenApiRestrictions
|
||||
}
|
||||
|
||||
override fun getInitialValue(): MutableEncodedValue? {
|
||||
return this.initialValue
|
||||
}
|
||||
|
@ -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<HiddenApiRestriction> {
|
||||
return _hiddenApiRestrictions
|
||||
}
|
||||
|
||||
override fun getParameters(): MutableList<MutableMethodParameter> {
|
||||
return _parameters
|
||||
}
|
||||
|
@ -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.")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user