Skip to content

Commit

Permalink
feat: remaining mutable EncodedValue classes
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Apr 12, 2022
1 parent 5f71a34 commit 7d38bb0
Show file tree
Hide file tree
Showing 24 changed files with 469 additions and 32 deletions.
9 changes: 7 additions & 2 deletions src/main/kotlin/app/revanced/patcher/Patcher.kt
Expand Up @@ -4,8 +4,8 @@ import app.revanced.patcher.cache.Cache
import app.revanced.patcher.cache.findIndexed
import app.revanced.patcher.patch.Patch
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.signature.resolver.SignatureResolver
import app.revanced.patcher.signature.MethodSignature
import app.revanced.patcher.signature.resolver.SignatureResolver
import app.revanced.patcher.util.ListBackedSet
import lanchon.multidexlib2.BasicDexFileNamer
import lanchon.multidexlib2.DexIO
Expand Down Expand Up @@ -37,6 +37,7 @@ class Patcher(
opcodes = dexFile.opcodes
cache = Cache(dexFile.classes.toMutableList())
}

/**
* Add additional dex file container to the patcher.
* @param files The dex file containers to add to the patcher.
Expand Down Expand Up @@ -66,6 +67,7 @@ class Patcher(
}
}
}

/**
* Save the patched dex file.
*/
Expand Down Expand Up @@ -113,7 +115,10 @@ class Patcher(
* PatchResultSuccess will always be returned in the wrapping Result object.
* If the patch failed to apply, an Exception will always be returned in the wrapping Result object.
*/
fun applyPatches(stopOnError: Boolean = false, callback: (String) -> Unit = {}): Map<String, Result<PatchResultSuccess>> {
fun applyPatches(
stopOnError: Boolean = false,
callback: (String) -> Unit = {}
): Map<String, Result<PatchResultSuccess>> {
if (!sigsResolved) {
SignatureResolver(cache.classes, signatures).resolve(cache.methodMap)
sigsResolved = true
Expand Down
@@ -1,6 +1,7 @@
package app.revanced.patcher.proxy.mutableTypes

import app.revanced.patcher.proxy.mutableTypes.MutableEncodedValue.Companion.toMutable
import app.revanced.patcher.proxy.mutableTypes.encodedValue.MutableEncodedValue
import app.revanced.patcher.proxy.mutableTypes.encodedValue.MutableEncodedValue.Companion.toMutable
import org.jf.dexlib2.base.BaseAnnotationElement
import org.jf.dexlib2.iface.AnnotationElement
import org.jf.dexlib2.iface.value.EncodedValue
Expand Down
Expand Up @@ -94,4 +94,10 @@ class MutableClass(classDef: ClassDef) : ClassDef, BaseTypeReference() {
override fun getMethods(): MutableSet<MutableMethod> {
return _methods
}

companion object {
fun ClassDef.toMutable(): MutableClass {
return MutableClass(this)
}
}
}

This file was deleted.

@@ -1,7 +1,8 @@
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 app.revanced.patcher.proxy.mutableTypes.encodedValue.MutableEncodedValue
import app.revanced.patcher.proxy.mutableTypes.encodedValue.MutableEncodedValue.Companion.toMutable
import org.jf.dexlib2.HiddenApiRestriction
import org.jf.dexlib2.base.reference.BaseFieldReference
import org.jf.dexlib2.iface.Field
Expand All @@ -11,6 +12,7 @@ class MutableField(field: Field) : Field, BaseFieldReference() {
private var name = field.name
private var type = field.type
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 }
Expand Down
@@ -0,0 +1,33 @@
package app.revanced.patcher.proxy.mutableTypes.encodedValue

import app.revanced.patcher.proxy.mutableTypes.MutableAnnotationElement.Companion.toMutable
import org.jf.dexlib2.base.value.BaseAnnotationEncodedValue
import org.jf.dexlib2.iface.AnnotationElement
import org.jf.dexlib2.iface.value.AnnotationEncodedValue

class MutableAnnotationEncodedValue(annotationEncodedValue: AnnotationEncodedValue) : BaseAnnotationEncodedValue(),
MutableEncodedValue {
private var type = annotationEncodedValue.type

private val _elements by lazy {
annotationEncodedValue.elements.map { annotationElement -> annotationElement.toMutable() }.toMutableSet()
}

override fun getType(): String {
return this.type
}

fun setType(type: String) {
this.type = type
}

override fun getElements(): MutableSet<out AnnotationElement> {
return _elements
}

companion object {
fun AnnotationEncodedValue.toMutable(): MutableAnnotationEncodedValue {
return MutableAnnotationEncodedValue(this)
}
}
}
@@ -0,0 +1,22 @@
package app.revanced.patcher.proxy.mutableTypes.encodedValue

import app.revanced.patcher.proxy.mutableTypes.encodedValue.MutableEncodedValue.Companion.toMutable
import org.jf.dexlib2.base.value.BaseArrayEncodedValue
import org.jf.dexlib2.iface.value.ArrayEncodedValue
import org.jf.dexlib2.iface.value.EncodedValue

class MutableArrayEncodedValue(arrayEncodedValue: ArrayEncodedValue) : BaseArrayEncodedValue(), MutableEncodedValue {
private val _value by lazy {
arrayEncodedValue.value.map { encodedValue -> encodedValue.toMutable() }.toMutableList()
}

override fun getValue(): MutableList<out EncodedValue> {
return _value
}

companion object {
fun ArrayEncodedValue.toMutable(): MutableArrayEncodedValue {
return MutableArrayEncodedValue(this)
}
}
}
@@ -0,0 +1,23 @@
package app.revanced.patcher.proxy.mutableTypes.encodedValue

import org.jf.dexlib2.base.value.BaseBooleanEncodedValue
import org.jf.dexlib2.iface.value.BooleanEncodedValue

class MutableBooleanEncodedValue(booleanEncodedValue: BooleanEncodedValue) : BaseBooleanEncodedValue(),
MutableEncodedValue {
private var value = booleanEncodedValue.value

override fun getValue(): Boolean {
return this.value
}

fun setValue(value: Boolean) {
this.value = value
}

companion object {
fun BooleanEncodedValue.toMutable(): MutableBooleanEncodedValue {
return MutableBooleanEncodedValue(this)
}
}
}
@@ -0,0 +1,22 @@
package app.revanced.patcher.proxy.mutableTypes.encodedValue

import org.jf.dexlib2.base.value.BaseByteEncodedValue
import org.jf.dexlib2.iface.value.ByteEncodedValue

class MutableByteEncodedValue(byteEncodedValue: ByteEncodedValue) : BaseByteEncodedValue(), MutableEncodedValue {
private var value = byteEncodedValue.value

override fun getValue(): Byte {
return this.value
}

fun setValue(value: Byte) {
this.value = value
}

companion object {
fun ByteEncodedValue.toMutable(): MutableByteEncodedValue {
return MutableByteEncodedValue(this)
}
}
}
@@ -0,0 +1,22 @@
package app.revanced.patcher.proxy.mutableTypes.encodedValue

import org.jf.dexlib2.base.value.BaseCharEncodedValue
import org.jf.dexlib2.iface.value.CharEncodedValue

class MutableCharEncodedValue(charEncodedValue: CharEncodedValue) : BaseCharEncodedValue(), MutableEncodedValue {
private var value = charEncodedValue.value

override fun getValue(): Char {
return this.value
}

fun setValue(value: Char) {
this.value = value
}

companion object {
fun CharEncodedValue.toMutable(): MutableCharEncodedValue {
return MutableCharEncodedValue(this)
}
}
}
@@ -0,0 +1,23 @@
package app.revanced.patcher.proxy.mutableTypes.encodedValue

import org.jf.dexlib2.base.value.BaseDoubleEncodedValue
import org.jf.dexlib2.iface.value.DoubleEncodedValue

class MutableDoubleEncodedValue(doubleEncodedValue: DoubleEncodedValue) : BaseDoubleEncodedValue(),
MutableEncodedValue {
private var value = doubleEncodedValue.value

override fun getValue(): Double {
return this.value
}

fun setValue(value: Double) {
this.value = value
}

companion object {
fun DoubleEncodedValue.toMutable(): MutableDoubleEncodedValue {
return MutableDoubleEncodedValue(this)
}
}
}
@@ -0,0 +1,32 @@
package app.revanced.patcher.proxy.mutableTypes.encodedValue

import org.jf.dexlib2.ValueType
import org.jf.dexlib2.iface.value.*

interface MutableEncodedValue : EncodedValue {
companion object {
fun EncodedValue.toMutable(): MutableEncodedValue {
return when (this.valueType) {
ValueType.TYPE -> MutableTypeEncodedValue(this as TypeEncodedValue)
ValueType.FIELD -> MutableFieldEncodedValue(this as FieldEncodedValue)
ValueType.METHOD -> MutableMethodEncodedValue(this as MethodEncodedValue)
ValueType.ENUM -> MutableEnumEncodedValue(this as EnumEncodedValue)
ValueType.ARRAY -> MutableArrayEncodedValue(this as ArrayEncodedValue)
ValueType.ANNOTATION -> MutableAnnotationEncodedValue(this as AnnotationEncodedValue)
ValueType.BYTE -> MutableByteEncodedValue(this as ByteEncodedValue)
ValueType.SHORT -> MutableShortEncodedValue(this as ShortEncodedValue)
ValueType.CHAR -> MutableCharEncodedValue(this as CharEncodedValue)
ValueType.INT -> MutableIntEncodedValue(this as IntEncodedValue)
ValueType.LONG -> MutableLongEncodedValue(this as LongEncodedValue)
ValueType.FLOAT -> MutableFloatEncodedValue(this as FloatEncodedValue)
ValueType.DOUBLE -> MutableDoubleEncodedValue(this as DoubleEncodedValue)
ValueType.METHOD_TYPE -> MutableMethodTypeEncodedValue(this as MethodTypeEncodedValue)
ValueType.METHOD_HANDLE -> MutableMethodHandleEncodedValue(this as MethodHandleEncodedValue)
ValueType.STRING -> MutableStringEncodedValue(this as StringEncodedValue)
ValueType.BOOLEAN -> MutableBooleanEncodedValue(this as BooleanEncodedValue)
ValueType.NULL -> MutableNullEncodedValue()
else -> this as MutableEncodedValue
}
}
}
}
@@ -0,0 +1,23 @@
package app.revanced.patcher.proxy.mutableTypes.encodedValue

import org.jf.dexlib2.base.value.BaseEnumEncodedValue
import org.jf.dexlib2.iface.reference.FieldReference
import org.jf.dexlib2.iface.value.EnumEncodedValue

class MutableEnumEncodedValue(enumEncodedValue: EnumEncodedValue) : BaseEnumEncodedValue(), MutableEncodedValue {
private var value = enumEncodedValue.value

override fun getValue(): FieldReference {
return this.value
}

fun setValue(value: FieldReference) {
this.value = value
}

companion object {
fun EnumEncodedValue.toMutable(): MutableEnumEncodedValue {
return MutableEnumEncodedValue(this)
}
}
}
@@ -0,0 +1,28 @@
package app.revanced.patcher.proxy.mutableTypes.encodedValue

import org.jf.dexlib2.ValueType
import org.jf.dexlib2.base.value.BaseFieldEncodedValue
import org.jf.dexlib2.iface.reference.FieldReference
import org.jf.dexlib2.iface.value.FieldEncodedValue

class MutableFieldEncodedValue(fieldEncodedValue: FieldEncodedValue) : BaseFieldEncodedValue(), MutableEncodedValue {
private var value = fieldEncodedValue.value

override fun getValueType(): Int {
return ValueType.FIELD
}

override fun getValue(): FieldReference {
return this.value
}

fun setValue(value: FieldReference) {
this.value = value
}

companion object {
fun FieldEncodedValue.toMutable(): MutableFieldEncodedValue {
return MutableFieldEncodedValue(this)
}
}
}
@@ -0,0 +1,22 @@
package app.revanced.patcher.proxy.mutableTypes.encodedValue

import org.jf.dexlib2.base.value.BaseFloatEncodedValue
import org.jf.dexlib2.iface.value.FloatEncodedValue

class MutableFloatEncodedValue(floatEncodedValue: FloatEncodedValue) : BaseFloatEncodedValue(), MutableEncodedValue {
private var value = floatEncodedValue.value

override fun getValue(): Float {
return this.value
}

fun setValue(value: Float) {
this.value = value
}

companion object {
fun FloatEncodedValue.toMutable(): MutableFloatEncodedValue {
return MutableFloatEncodedValue(this)
}
}
}
@@ -0,0 +1,22 @@
package app.revanced.patcher.proxy.mutableTypes.encodedValue

import org.jf.dexlib2.base.value.BaseIntEncodedValue
import org.jf.dexlib2.iface.value.IntEncodedValue

class MutableIntEncodedValue(intEncodedValue: IntEncodedValue) : BaseIntEncodedValue(), MutableEncodedValue {
private var value = intEncodedValue.value

override fun getValue(): Int {
return this.value
}

fun setValue(value: Int) {
this.value = value
}

companion object {
fun IntEncodedValue.toMutable(): MutableIntEncodedValue {
return MutableIntEncodedValue(this)
}
}
}

0 comments on commit 7d38bb0

Please sign in to comment.