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 {
|
repositories {
|
||||||
mavenCentral()
|
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 {
|
dependencies {
|
||||||
implementation(kotlin("stdlib"))
|
implementation(kotlin("stdlib"))
|
||||||
|
|
||||||
implementation("com.github.lanchon.dexpatcher:multidexlib2:2.3.4.r2")
|
implementation("app.revanced:multidexlib2:2.5.2")
|
||||||
implementation("org.smali:smali:2.3.4")
|
@Suppress("GradlePackageUpdate")
|
||||||
|
implementation("org.smali:smali:2.5.2")
|
||||||
|
|
||||||
testImplementation(kotlin("test"))
|
testImplementation(kotlin("test"))
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import lanchon.multidexlib2.MultiDexIO
|
|||||||
import org.jf.dexlib2.Opcodes
|
import org.jf.dexlib2.Opcodes
|
||||||
import org.jf.dexlib2.iface.ClassDef
|
import org.jf.dexlib2.iface.ClassDef
|
||||||
import org.jf.dexlib2.iface.DexFile
|
import org.jf.dexlib2.iface.DexFile
|
||||||
|
import org.jf.dexlib2.writer.io.MemoryDataStore
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
val NAMER = BasicDexFileNamer()
|
val NAMER = BasicDexFileNamer()
|
||||||
@ -19,12 +20,10 @@ val NAMER = BasicDexFileNamer()
|
|||||||
/**
|
/**
|
||||||
* ReVanced Patcher.
|
* ReVanced Patcher.
|
||||||
* @param input The input file (an apk or any other multi dex container).
|
* @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
|
* @param signatures An array of method signatures for the patches
|
||||||
*/
|
*/
|
||||||
class Patcher(
|
class Patcher(
|
||||||
input: File,
|
input: File,
|
||||||
private val output: File,
|
|
||||||
signatures: Array<MethodSignature>,
|
signatures: Array<MethodSignature>,
|
||||||
) {
|
) {
|
||||||
private val cache: Cache
|
private val cache: Cache
|
||||||
@ -57,7 +56,7 @@ class Patcher(
|
|||||||
/**
|
/**
|
||||||
* Save the patched dex file.
|
* Save the patched dex file.
|
||||||
*/
|
*/
|
||||||
fun save() {
|
fun save(): List<MemoryDataStore> {
|
||||||
val newDexFile = object : DexFile {
|
val newDexFile = object : DexFile {
|
||||||
override fun getClasses(): Set<ClassDef> {
|
override fun getClasses(): Set<ClassDef> {
|
||||||
// this is a slow workaround for now
|
// this is a slow workaround for now
|
||||||
@ -77,12 +76,14 @@ class Patcher(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val list = mutableListOf<MemoryDataStore>()
|
||||||
MultiDexIO.writeDexFile(
|
MultiDexIO.writeDexFile(
|
||||||
true, -1, // core count
|
true, -1, // core count
|
||||||
output, NAMER, newDexFile,
|
list, NAMER, newDexFile,
|
||||||
DexIO.DEFAULT_MAX_DEX_POOL_SIZE,
|
DexIO.DEFAULT_MAX_DEX_POOL_SIZE,
|
||||||
null
|
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.MutableAnnotation.Companion.toMutable
|
||||||
import app.revanced.patcher.proxy.mutableTypes.MutableEncodedValue.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.base.reference.BaseFieldReference
|
||||||
import org.jf.dexlib2.iface.Field
|
import org.jf.dexlib2.iface.Field
|
||||||
|
|
||||||
@ -12,6 +13,7 @@ class MutableField(field: Field) : Field, BaseFieldReference() {
|
|||||||
private var accessFlags = field.accessFlags
|
private var accessFlags = field.accessFlags
|
||||||
private var initialValue = field.initialValue?.toMutable()
|
private var initialValue = field.initialValue?.toMutable()
|
||||||
private val _annotations by lazy { field.annotations.map { annotation -> annotation.toMutable() }.toMutableSet() }
|
private val _annotations by lazy { field.annotations.map { annotation -> annotation.toMutable() }.toMutableSet() }
|
||||||
|
private val _hiddenApiRestrictions by lazy { field.hiddenApiRestrictions }
|
||||||
|
|
||||||
fun setDefiningClass(definingClass: String) {
|
fun setDefiningClass(definingClass: String) {
|
||||||
this.definingClass = definingClass
|
this.definingClass = definingClass
|
||||||
@ -53,6 +55,10 @@ class MutableField(field: Field) : Field, BaseFieldReference() {
|
|||||||
return this.accessFlags
|
return this.accessFlags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getHiddenApiRestrictions(): MutableSet<HiddenApiRestriction> {
|
||||||
|
return this._hiddenApiRestrictions
|
||||||
|
}
|
||||||
|
|
||||||
override fun getInitialValue(): MutableEncodedValue? {
|
override fun getInitialValue(): MutableEncodedValue? {
|
||||||
return this.initialValue
|
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.MutableAnnotation.Companion.toMutable
|
||||||
import app.revanced.patcher.proxy.mutableTypes.MutableMethodParameter.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.base.reference.BaseMethodReference
|
||||||
import org.jf.dexlib2.builder.MutableMethodImplementation
|
import org.jf.dexlib2.builder.MutableMethodImplementation
|
||||||
import org.jf.dexlib2.iface.Method
|
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 _annotations by lazy { method.annotations.map { annotation -> annotation.toMutable() }.toMutableSet() }
|
||||||
private val _parameters by lazy { method.parameters.map { parameter -> parameter.toMutable() }.toMutableList() }
|
private val _parameters by lazy { method.parameters.map { parameter -> parameter.toMutable() }.toMutableList() }
|
||||||
private val _parameterTypes by lazy { method.parameterTypes.toMutableList() }
|
private val _parameterTypes by lazy { method.parameterTypes.toMutableList() }
|
||||||
|
private val _hiddenApiRestrictions by lazy { method.hiddenApiRestrictions }
|
||||||
|
|
||||||
override fun getDefiningClass(): String {
|
override fun getDefiningClass(): String {
|
||||||
return this.definingClass
|
return definingClass
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getName(): String {
|
override fun getName(): String {
|
||||||
@ -42,6 +44,10 @@ class MutableMethod(method: Method) : Method, BaseMethodReference() {
|
|||||||
return accessFlags
|
return accessFlags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getHiddenApiRestrictions(): MutableSet<HiddenApiRestriction> {
|
||||||
|
return _hiddenApiRestrictions
|
||||||
|
}
|
||||||
|
|
||||||
override fun getParameters(): MutableList<MutableMethodParameter> {
|
override fun getParameters(): MutableList<MutableMethodParameter> {
|
||||||
return _parameters
|
return _parameters
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import org.jf.dexlib2.immutable.ImmutableMethodImplementation
|
|||||||
import org.jf.dexlib2.immutable.reference.ImmutableStringReference
|
import org.jf.dexlib2.immutable.reference.ImmutableStringReference
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
internal class PatcherTest {
|
internal class PatcherTest {
|
||||||
companion object {
|
companion object {
|
||||||
@ -41,7 +42,6 @@ internal class PatcherTest {
|
|||||||
fun testPatcher() {
|
fun testPatcher() {
|
||||||
val patcher = Patcher(
|
val patcher = Patcher(
|
||||||
File(PatcherTest::class.java.getResource("/test1.dex")!!.toURI()),
|
File(PatcherTest::class.java.getResource("/test1.dex")!!.toURI()),
|
||||||
File("."),
|
|
||||||
testSignatures
|
testSignatures
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -90,6 +90,7 @@ internal class PatcherTest {
|
|||||||
"Ljava/lang/String;",
|
"Ljava/lang/String;",
|
||||||
AccessFlags.PRIVATE or AccessFlags.STATIC,
|
AccessFlags.PRIVATE or AccessFlags.STATIC,
|
||||||
null,
|
null,
|
||||||
|
null,
|
||||||
ImmutableMethodImplementation(
|
ImmutableMethodImplementation(
|
||||||
1,
|
1,
|
||||||
ImmutableList.of(
|
ImmutableList.of(
|
||||||
@ -156,17 +157,7 @@ internal class PatcherTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
patcher.save()
|
val out = patcher.save()
|
||||||
}
|
assertTrue(out.isNotEmpty(), "Expected the output of Patcher#save() to not be empty.")
|
||||||
|
|
||||||
@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())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user