?) -> Boolean = { true },
) = PatchOption(
- key, default, values, title, description, required, "LongArray", validator
+ key,
+ default,
+ values,
+ title,
+ description,
+ required,
+ "LongArray",
+ validator,
).also { registerOption(it) }
private fun > P.registerOption(option: PatchOption<*>) = option.also { options.register(it) }
}
-}
\ No newline at end of file
+}
diff --git a/src/main/kotlin/app/revanced/patcher/patch/options/PatchOptionException.kt b/src/main/kotlin/app/revanced/patcher/patch/options/PatchOptionException.kt
index 676f6e1..4b5dd99 100644
--- a/src/main/kotlin/app/revanced/patcher/patch/options/PatchOptionException.kt
+++ b/src/main/kotlin/app/revanced/patcher/patch/options/PatchOptionException.kt
@@ -36,6 +36,6 @@ sealed class PatchOptionException(errorMessage: String) : Exception(errorMessage
*
* @param key The key of the [PatchOption].
*/
- class PatchOptionNotFoundException(key: String)
- : PatchOptionException("No option with key $key")
-}
\ No newline at end of file
+ class PatchOptionNotFoundException(key: String) :
+ PatchOptionException("No option with key $key")
+}
diff --git a/src/main/kotlin/app/revanced/patcher/patch/options/PatchOptions.kt b/src/main/kotlin/app/revanced/patcher/patch/options/PatchOptions.kt
index 481da72..69f30ea 100644
--- a/src/main/kotlin/app/revanced/patcher/patch/options/PatchOptions.kt
+++ b/src/main/kotlin/app/revanced/patcher/patch/options/PatchOptions.kt
@@ -1,13 +1,12 @@
package app.revanced.patcher.patch.options
-
/**
* A map of [PatchOption]s associated by their keys.
*
* @param options The [PatchOption]s to initialize with.
*/
class PatchOptions internal constructor(
- private val options: MutableMap> = mutableMapOf()
+ private val options: MutableMap> = mutableMapOf(),
) : MutableMap> by options {
/**
* Register a [PatchOption]. Acts like [MutableMap.put].
@@ -23,7 +22,10 @@ class PatchOptions internal constructor(
* @param value The value.
* @throws PatchOptionException.PatchOptionNotFoundException If the option does not exist.
*/
- operator fun set(key: String, value: T?) {
+ operator fun set(
+ key: String,
+ value: T?,
+ ) {
val option = this[key]
try {
@@ -40,6 +42,5 @@ class PatchOptions internal constructor(
/**
* Get an option.
*/
- override operator fun get(key: String) =
- options[key] ?: throw PatchOptionException.PatchOptionNotFoundException(key)
-}
\ No newline at end of file
+ override operator fun get(key: String) = options[key] ?: throw PatchOptionException.PatchOptionNotFoundException(key)
+}
diff --git a/src/main/kotlin/app/revanced/patcher/util/ClassMerger.kt b/src/main/kotlin/app/revanced/patcher/util/ClassMerger.kt
index 37fb9df..87789b1 100644
--- a/src/main/kotlin/app/revanced/patcher/util/ClassMerger.kt
+++ b/src/main/kotlin/app/revanced/patcher/util/ClassMerger.kt
@@ -34,9 +34,12 @@ internal object ClassMerger {
* @param context The context to traverse the class hierarchy in.
* @return The merged class or the original class if no merge was needed.
*/
- fun ClassDef.merge(otherClass: ClassDef, context: BytecodeContext) = this
- //.fixFieldAccess(otherClass)
- //.fixMethodAccess(otherClass)
+ fun ClassDef.merge(
+ otherClass: ClassDef,
+ context: BytecodeContext,
+ ) = this
+ // .fixFieldAccess(otherClass)
+ // .fixMethodAccess(otherClass)
.addMissingFields(otherClass)
.addMissingMethods(otherClass)
.publicize(otherClass, context)
@@ -47,13 +50,14 @@ internal object ClassMerger {
* @param fromClass The class to add missing methods from.
*/
private fun ClassDef.addMissingMethods(fromClass: ClassDef): ClassDef {
- val missingMethods = fromClass.methods.let { fromMethods ->
- methods.filterNot { method ->
- fromMethods.any { fromMethod ->
- MethodUtil.methodSignaturesMatch(fromMethod, method)
+ val missingMethods =
+ fromClass.methods.let { fromMethods ->
+ methods.filterNot { method ->
+ fromMethods.any { fromMethod ->
+ MethodUtil.methodSignaturesMatch(fromMethod, method)
+ }
}
}
- }
if (missingMethods.isEmpty()) return this
@@ -70,9 +74,10 @@ internal object ClassMerger {
* @param fromClass The class to add missing fields from.
*/
private fun ClassDef.addMissingFields(fromClass: ClassDef): ClassDef {
- val missingFields = fields.filterNotAny(fromClass.fields) { field, fromField ->
- fromField.name == field.name
- }
+ val missingFields =
+ fields.filterNotAny(fromClass.fields) { field, fromField ->
+ fromField.name == field.name
+ }
if (missingFields.isEmpty()) return this
@@ -88,18 +93,22 @@ internal object ClassMerger {
* @param reference The class to check the [AccessFlags] of.
* @param context The context to traverse the class hierarchy in.
*/
- private fun ClassDef.publicize(reference: ClassDef, context: BytecodeContext) =
- if (reference.accessFlags.isPublic() && !accessFlags.isPublic())
- this.asMutableClass().apply {
- context.traverseClassHierarchy(this) {
- if (accessFlags.isPublic()) return@traverseClassHierarchy
+ private fun ClassDef.publicize(
+ reference: ClassDef,
+ context: BytecodeContext,
+ ) = if (reference.accessFlags.isPublic() && !accessFlags.isPublic()) {
+ this.asMutableClass().apply {
+ context.traverseClassHierarchy(this) {
+ if (accessFlags.isPublic()) return@traverseClassHierarchy
- logger.fine("Publicizing ${this.type}")
+ logger.fine("Publicizing ${this.type}")
- accessFlags = accessFlags.toPublic()
- }
+ accessFlags = accessFlags.toPublic()
}
- else this
+ }
+ } else {
+ this
+ }
/**
* Publicize fields if they are public in [reference].
@@ -107,11 +116,12 @@ internal object ClassMerger {
* @param reference The class to check the [AccessFlags] of the fields in.
*/
private fun ClassDef.fixFieldAccess(reference: ClassDef): ClassDef {
- val brokenFields = fields.filterAny(reference.fields) { field, referenceField ->
- if (field.name != referenceField.name) return@filterAny false
+ val brokenFields =
+ fields.filterAny(reference.fields) { field, referenceField ->
+ if (field.name != referenceField.name) return@filterAny false
- referenceField.accessFlags.isPublic() && !field.accessFlags.isPublic()
- }
+ referenceField.accessFlags.isPublic() && !field.accessFlags.isPublic()
+ }
if (brokenFields.isEmpty()) return this
@@ -135,11 +145,12 @@ internal object ClassMerger {
* @param reference The class to check the [AccessFlags] of the methods in.
*/
private fun ClassDef.fixMethodAccess(reference: ClassDef): ClassDef {
- val brokenMethods = methods.filterAny(reference.methods) { method, referenceMethod ->
- if (!MethodUtil.methodSignaturesMatch(method, referenceMethod)) return@filterAny false
+ val brokenMethods =
+ methods.filterAny(reference.methods) { method, referenceMethod ->
+ if (!MethodUtil.methodSignaturesMatch(method, referenceMethod)) return@filterAny false
- referenceMethod.accessFlags.isPublic() && !method.accessFlags.isPublic()
- }
+ referenceMethod.accessFlags.isPublic() && !method.accessFlags.isPublic()
+ }
if (brokenMethods.isEmpty()) return this
@@ -164,7 +175,10 @@ internal object ClassMerger {
* @param targetClass the class to start traversing the class hierarchy from
* @param callback function that is called for every class in the hierarchy
*/
- fun BytecodeContext.traverseClassHierarchy(targetClass: MutableClass, callback: MutableClass.() -> Unit) {
+ fun BytecodeContext.traverseClassHierarchy(
+ targetClass: MutableClass,
+ callback: MutableClass.() -> Unit,
+ ) {
callback(targetClass)
this.findClass(targetClass.superclass ?: return)?.mutableClass?.let {
traverseClassHierarchy(it, callback)
@@ -195,7 +209,8 @@ internal object ClassMerger {
* @return The [this] filtered on [needles] matching the given [predicate].
*/
fun Iterable.filterAny(
- needles: Iterable, predicate: (HayType, NeedleType) -> Boolean
+ needles: Iterable,
+ predicate: (HayType, NeedleType) -> Boolean,
) = Iterable::filter.any(this, needles, predicate)
/**
@@ -206,17 +221,18 @@ internal object ClassMerger {
* @return The [this] filtered on [needles] not matching the given [predicate].
*/
fun Iterable.filterNotAny(
- needles: Iterable, predicate: (HayType, NeedleType) -> Boolean
+ needles: Iterable,
+ predicate: (HayType, NeedleType) -> Boolean,
) = Iterable::filterNot.any(this, needles, predicate)
fun KFunction2, (HayType) -> Boolean, List>.any(
haystack: Iterable,
needles: Iterable,
- predicate: (HayType, NeedleType) -> Boolean
+ predicate: (HayType, NeedleType) -> Boolean,
) = this(haystack) { hay ->
needles.any { needle ->
predicate(hay, needle)
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/kotlin/app/revanced/patcher/util/DomFileEditor.kt b/src/main/kotlin/app/revanced/patcher/util/DomFileEditor.kt
index b679dd9..4521afc 100644
--- a/src/main/kotlin/app/revanced/patcher/util/DomFileEditor.kt
+++ b/src/main/kotlin/app/revanced/patcher/util/DomFileEditor.kt
@@ -31,9 +31,9 @@ class DomFileEditor internal constructor(
/**
* The document of the xml file
*/
- val file: Document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream)
- .also(Document::normalize)
-
+ val file: Document =
+ DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream)
+ .also(Document::normalize)
// lazily open an output stream
// this is required because when constructing a DomFileEditor the output stream is created along with the input stream, which is not allowed
@@ -58,12 +58,13 @@ class DomFileEditor internal constructor(
outputStream?.let {
// prevent writing to same file, if it is being locked
// isLocked will be false if the editor was created through a stream
- val isLocked = filePath?.let { path ->
- val isLocked = locks[path]!! > 1
- // decrease the lock count if the editor was opened for a file
- locks.merge(path, -1, Integer::sum)
- isLocked
- } ?: false
+ val isLocked =
+ filePath?.let { path ->
+ val isLocked = locks[path]!! > 1
+ // decrease the lock count if the editor was opened for a file
+ locks.merge(path, -1, Integer::sum)
+ isLocked
+ } ?: false
// if unlocked, write back to the file
if (!isLocked) {
@@ -84,4 +85,4 @@ class DomFileEditor internal constructor(
// map of concurrent open files
val locks = mutableMapOf()
}
-}
\ No newline at end of file
+}
diff --git a/src/main/kotlin/app/revanced/patcher/util/ProxyClassList.kt b/src/main/kotlin/app/revanced/patcher/util/ProxyClassList.kt
index 681bc8f..a05b7b8 100644
--- a/src/main/kotlin/app/revanced/patcher/util/ProxyClassList.kt
+++ b/src/main/kotlin/app/revanced/patcher/util/ProxyClassList.kt
@@ -19,15 +19,16 @@ class ProxyClassList internal constructor(classes: MutableSet) : Mutab
/**
* Replace all classes with their mutated versions.
*/
- internal fun replaceClasses() = proxies.removeIf { proxy ->
- // If the proxy is unused, return false to keep it in the proxies list.
+ internal fun replaceClasses() =
+ proxies.removeIf { proxy ->
+ // If the proxy is unused, return false to keep it in the proxies list.
if (!proxy.resolved) return@removeIf false
- // If it has been used, replace the original class with the mutable class.
- remove(proxy.immutableClass)
- add(proxy.mutableClass)
+ // If it has been used, replace the original class with the mutable class.
+ remove(proxy.immutableClass)
+ add(proxy.mutableClass)
- // Return true to remove the proxy from the proxies list.
+ // Return true to remove the proxy from the proxies list.
return@removeIf true
}
-}
\ No newline at end of file
+}
diff --git a/src/main/kotlin/app/revanced/patcher/util/method/MethodWalker.kt b/src/main/kotlin/app/revanced/patcher/util/method/MethodWalker.kt
index a0d2ef0..0f27511 100644
--- a/src/main/kotlin/app/revanced/patcher/util/method/MethodWalker.kt
+++ b/src/main/kotlin/app/revanced/patcher/util/method/MethodWalker.kt
@@ -14,7 +14,7 @@ import com.android.tools.smali.dexlib2.util.MethodUtil
*/
class MethodWalker internal constructor(
private val bytecodeContext: BytecodeContext,
- private var currentMethod: Method
+ private var currentMethod: Method,
) {
/**
* Get the method which was walked last.
@@ -36,7 +36,10 @@ class MethodWalker internal constructor(
* @param walkMutable If this is true, the class of the method will be resolved mutably.
* @return The same [MethodWalker] instance with the method at [offset].
*/
- fun nextMethod(offset: Int, walkMutable: Boolean = false): MethodWalker {
+ fun nextMethod(
+ offset: Int,
+ walkMutable: Boolean = false,
+ ): MethodWalker {
currentMethod.implementation?.instructions?.let { instructions ->
val instruction = instructions.elementAt(offset)
@@ -44,13 +47,14 @@ class MethodWalker internal constructor(
val proxy = bytecodeContext.findClass(newMethod.definingClass)!!
val methods = if (walkMutable) proxy.mutableClass.methods else proxy.immutableClass.methods
- currentMethod = methods.first {
- return@first MethodUtil.methodSignaturesMatch(it, newMethod)
- }
+ currentMethod =
+ methods.first {
+ return@first MethodUtil.methodSignaturesMatch(it, newMethod)
+ }
return this
}
throw MethodNotFoundException("This method can not be walked at offset $offset inside the method ${currentMethod.name}")
}
internal class MethodNotFoundException(exception: String) : Exception(exception)
-}
\ No newline at end of file
+}
diff --git a/src/main/kotlin/app/revanced/patcher/util/proxy/ClassProxy.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/ClassProxy.kt
index 1c60185..b20c0b7 100644
--- a/src/main/kotlin/app/revanced/patcher/util/proxy/ClassProxy.kt
+++ b/src/main/kotlin/app/revanced/patcher/util/proxy/ClassProxy.kt
@@ -27,7 +27,8 @@ class ClassProxy internal constructor(
resolved = true
if (immutableClass is MutableClass) {
immutableClass
- } else
+ } else {
MutableClass(immutableClass)
+ }
}
-}
\ No newline at end of file
+}
diff --git a/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/MutableAnnotationElement.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/MutableAnnotationElement.kt
index f9e59dc..5bb8bfc 100644
--- a/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/MutableAnnotationElement.kt
+++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/MutableAnnotationElement.kt
@@ -31,4 +31,4 @@ class MutableAnnotationElement(annotationElement: AnnotationElement) : BaseAnnot
return MutableAnnotationElement(this)
}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/MutableClass.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/MutableClass.kt
index 5c0c022..19f5f1f 100644
--- a/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/MutableClass.kt
+++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/MutableClass.kt
@@ -3,11 +3,11 @@ package app.revanced.patcher.util.proxy.mutableTypes
import app.revanced.patcher.util.proxy.mutableTypes.MutableAnnotation.Companion.toMutable
import app.revanced.patcher.util.proxy.mutableTypes.MutableField.Companion.toMutable
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
-import com.google.common.collect.Iterables
import com.android.tools.smali.dexlib2.base.reference.BaseTypeReference
import com.android.tools.smali.dexlib2.iface.ClassDef
import com.android.tools.smali.dexlib2.util.FieldUtil
import com.android.tools.smali.dexlib2.util.MethodUtil
+import com.google.common.collect.Iterables
class MutableClass(classDef: ClassDef) : ClassDef, BaseTypeReference() {
// Class
@@ -100,4 +100,4 @@ class MutableClass(classDef: ClassDef) : ClassDef, BaseTypeReference() {
return MutableClass(this)
}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/MutableMethod.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/MutableMethod.kt
index c026956..5d29be7 100644
--- a/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/MutableMethod.kt
+++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/MutableMethod.kt
@@ -77,4 +77,4 @@ class MutableMethod(method: Method) : Method, BaseMethodReference() {
return MutableMethod(this)
}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableAnnotationEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableAnnotationEncodedValue.kt
index 1609385..1993115 100644
--- a/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableAnnotationEncodedValue.kt
+++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableAnnotationEncodedValue.kt
@@ -5,7 +5,8 @@ import com.android.tools.smali.dexlib2.base.value.BaseAnnotationEncodedValue
import com.android.tools.smali.dexlib2.iface.AnnotationElement
import com.android.tools.smali.dexlib2.iface.value.AnnotationEncodedValue
-class MutableAnnotationEncodedValue(annotationEncodedValue: AnnotationEncodedValue) : BaseAnnotationEncodedValue(),
+class MutableAnnotationEncodedValue(annotationEncodedValue: AnnotationEncodedValue) :
+ BaseAnnotationEncodedValue(),
MutableEncodedValue {
private var type = annotationEncodedValue.type
diff --git a/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableBooleanEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableBooleanEncodedValue.kt
index 174ddcc..282b24c 100644
--- a/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableBooleanEncodedValue.kt
+++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableBooleanEncodedValue.kt
@@ -3,7 +3,8 @@ package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
import com.android.tools.smali.dexlib2.base.value.BaseBooleanEncodedValue
import com.android.tools.smali.dexlib2.iface.value.BooleanEncodedValue
-class MutableBooleanEncodedValue(booleanEncodedValue: BooleanEncodedValue) : BaseBooleanEncodedValue(),
+class MutableBooleanEncodedValue(booleanEncodedValue: BooleanEncodedValue) :
+ BaseBooleanEncodedValue(),
MutableEncodedValue {
private var value = booleanEncodedValue.value
@@ -20,4 +21,4 @@ class MutableBooleanEncodedValue(booleanEncodedValue: BooleanEncodedValue) : Bas
return MutableBooleanEncodedValue(this)
}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableByteEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableByteEncodedValue.kt
index 83ec51f..cbb076a 100644
--- a/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableByteEncodedValue.kt
+++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableByteEncodedValue.kt
@@ -19,4 +19,4 @@ class MutableByteEncodedValue(byteEncodedValue: ByteEncodedValue) : BaseByteEnco
return MutableByteEncodedValue(this)
}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableDoubleEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableDoubleEncodedValue.kt
index 0683d79..7258c40 100644
--- a/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableDoubleEncodedValue.kt
+++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableDoubleEncodedValue.kt
@@ -3,7 +3,8 @@ package app.revanced.patcher.util.proxy.mutableTypes.encodedValue
import com.android.tools.smali.dexlib2.base.value.BaseDoubleEncodedValue
import com.android.tools.smali.dexlib2.iface.value.DoubleEncodedValue
-class MutableDoubleEncodedValue(doubleEncodedValue: DoubleEncodedValue) : BaseDoubleEncodedValue(),
+class MutableDoubleEncodedValue(doubleEncodedValue: DoubleEncodedValue) :
+ BaseDoubleEncodedValue(),
MutableEncodedValue {
private var value = doubleEncodedValue.value
@@ -20,4 +21,4 @@ class MutableDoubleEncodedValue(doubleEncodedValue: DoubleEncodedValue) : BaseDo
return MutableDoubleEncodedValue(this)
}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableEncodedValue.kt
index c4f5c04..aa4cefa 100644
--- a/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableEncodedValue.kt
+++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableEncodedValue.kt
@@ -29,4 +29,4 @@ interface MutableEncodedValue : EncodedValue {
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableFloatEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableFloatEncodedValue.kt
index e66a130..f3a914a 100644
--- a/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableFloatEncodedValue.kt
+++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableFloatEncodedValue.kt
@@ -19,4 +19,4 @@ class MutableFloatEncodedValue(floatEncodedValue: FloatEncodedValue) : BaseFloat
return MutableFloatEncodedValue(this)
}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableIntEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableIntEncodedValue.kt
index ae81472..db06751 100644
--- a/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableIntEncodedValue.kt
+++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableIntEncodedValue.kt
@@ -19,4 +19,4 @@ class MutableIntEncodedValue(intEncodedValue: IntEncodedValue) : BaseIntEncodedV
return MutableIntEncodedValue(this)
}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableMethodEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableMethodEncodedValue.kt
index d66ccee..49f5ccc 100644
--- a/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableMethodEncodedValue.kt
+++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableMethodEncodedValue.kt
@@ -4,7 +4,8 @@ import com.android.tools.smali.dexlib2.base.value.BaseMethodEncodedValue
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
import com.android.tools.smali.dexlib2.iface.value.MethodEncodedValue
-class MutableMethodEncodedValue(methodEncodedValue: MethodEncodedValue) : BaseMethodEncodedValue(),
+class MutableMethodEncodedValue(methodEncodedValue: MethodEncodedValue) :
+ BaseMethodEncodedValue(),
MutableEncodedValue {
private var value = methodEncodedValue.value
diff --git a/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableMethodHandleEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableMethodHandleEncodedValue.kt
index cbcfac5..aa93bda 100644
--- a/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableMethodHandleEncodedValue.kt
+++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableMethodHandleEncodedValue.kt
@@ -22,6 +22,4 @@ class MutableMethodHandleEncodedValue(methodHandleEncodedValue: MethodHandleEnco
return MutableMethodHandleEncodedValue(this)
}
}
-
-
-}
\ No newline at end of file
+}
diff --git a/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableMethodTypeEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableMethodTypeEncodedValue.kt
index d11e517..2d67f5f 100644
--- a/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableMethodTypeEncodedValue.kt
+++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableMethodTypeEncodedValue.kt
@@ -4,7 +4,8 @@ import com.android.tools.smali.dexlib2.base.value.BaseMethodTypeEncodedValue
import com.android.tools.smali.dexlib2.iface.reference.MethodProtoReference
import com.android.tools.smali.dexlib2.iface.value.MethodTypeEncodedValue
-class MutableMethodTypeEncodedValue(methodTypeEncodedValue: MethodTypeEncodedValue) : BaseMethodTypeEncodedValue(),
+class MutableMethodTypeEncodedValue(methodTypeEncodedValue: MethodTypeEncodedValue) :
+ BaseMethodTypeEncodedValue(),
MutableEncodedValue {
private var value = methodTypeEncodedValue.value
@@ -21,6 +22,4 @@ class MutableMethodTypeEncodedValue(methodTypeEncodedValue: MethodTypeEncodedVal
return MutableMethodTypeEncodedValue(this)
}
}
-
-
-}
\ No newline at end of file
+}
diff --git a/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableNullEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableNullEncodedValue.kt
index b4305fa..4513ab6 100644
--- a/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableNullEncodedValue.kt
+++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableNullEncodedValue.kt
@@ -9,4 +9,4 @@ class MutableNullEncodedValue : BaseNullEncodedValue(), MutableEncodedValue {
return MutableByteEncodedValue(this)
}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableStringEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableStringEncodedValue.kt
index 351924a..290276d 100644
--- a/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableStringEncodedValue.kt
+++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableStringEncodedValue.kt
@@ -4,7 +4,8 @@ import com.android.tools.smali.dexlib2.base.value.BaseStringEncodedValue
import com.android.tools.smali.dexlib2.iface.value.ByteEncodedValue
import com.android.tools.smali.dexlib2.iface.value.StringEncodedValue
-class MutableStringEncodedValue(stringEncodedValue: StringEncodedValue) : BaseStringEncodedValue(),
+class MutableStringEncodedValue(stringEncodedValue: StringEncodedValue) :
+ BaseStringEncodedValue(),
MutableEncodedValue {
private var value = stringEncodedValue.value
@@ -21,4 +22,4 @@ class MutableStringEncodedValue(stringEncodedValue: StringEncodedValue) : BaseSt
return MutableByteEncodedValue(this)
}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/kotlin/app/revanced/patcher/util/smali/InlineSmaliCompiler.kt b/src/main/kotlin/app/revanced/patcher/util/smali/InlineSmaliCompiler.kt
index 23cd1ec..f2e1503 100644
--- a/src/main/kotlin/app/revanced/patcher/util/smali/InlineSmaliCompiler.kt
+++ b/src/main/kotlin/app/revanced/patcher/util/smali/InlineSmaliCompiler.kt
@@ -1,9 +1,6 @@
package app.revanced.patcher.util.smali
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
-import org.antlr.runtime.CommonTokenStream
-import org.antlr.runtime.TokenSource
-import org.antlr.runtime.tree.CommonTreeNodeStream
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcodes
import com.android.tools.smali.dexlib2.builder.BuilderInstruction
@@ -12,6 +9,9 @@ import com.android.tools.smali.smali.LexerErrorInterface
import com.android.tools.smali.smali.smaliFlexLexer
import com.android.tools.smali.smali.smaliParser
import com.android.tools.smali.smali.smaliTreeWalker
+import org.antlr.runtime.CommonTokenStream
+import org.antlr.runtime.TokenSource
+import org.antlr.runtime.tree.CommonTreeNodeStream
import java.io.InputStreamReader
import java.util.Locale
@@ -32,15 +32,23 @@ class InlineSmaliCompiler {
* if the parameters and registers of the method are passed.
*/
fun compile(
- instructions: String, parameters: String, registers: Int, forStaticMethod: Boolean
+ instructions: String,
+ parameters: String,
+ registers: Int,
+ forStaticMethod: Boolean,
): List {
- val input = METHOD_TEMPLATE.format(Locale.ENGLISH,
- if (forStaticMethod) {
- "static"
- } else {
- ""
- }, parameters, registers, instructions
- )
+ val input =
+ METHOD_TEMPLATE.format(
+ Locale.ENGLISH,
+ if (forStaticMethod) {
+ "static"
+ } else {
+ ""
+ },
+ parameters,
+ registers,
+ instructions,
+ )
val reader = InputStreamReader(input.byteInputStream())
val lexer: LexerErrorInterface = smaliFlexLexer(reader, 15)
val tokens = CommonTokenStream(lexer as TokenSource)
@@ -48,7 +56,7 @@ class InlineSmaliCompiler {
val result = parser.smali_file()
if (parser.numberOfSyntaxErrors > 0 || lexer.numberOfSyntaxErrors > 0) {
throw IllegalStateException(
- "Encountered ${parser.numberOfSyntaxErrors} parser syntax errors and ${lexer.numberOfSyntaxErrors} lexer syntax errors!"
+ "Encountered ${parser.numberOfSyntaxErrors} parser syntax errors and ${lexer.numberOfSyntaxErrors} lexer syntax errors!",
)
}
val treeStream = CommonTreeNodeStream(result.tree)
@@ -70,10 +78,11 @@ class InlineSmaliCompiler {
* @returns A list of instructions.
*/
fun String.toInstructions(method: MutableMethod? = null): List {
- return InlineSmaliCompiler.compile(this,
+ return InlineSmaliCompiler.compile(
+ this,
method?.parameters?.joinToString("") { it } ?: "",
method?.implementation?.registerCount ?: 1,
- method?.let { AccessFlags.STATIC.isSet(it.accessFlags) } ?: true
+ method?.let { AccessFlags.STATIC.isSet(it.accessFlags) } ?: true,
)
}
@@ -82,4 +91,4 @@ fun String.toInstructions(method: MutableMethod? = null): List this.addInstruction(TestInstruction(i)) }
- },
- ).let { testMethod = it.toMutable() }
+ fun createTestMethod() =
+ ImmutableMethod(
+ "TestClass;",
+ "testMethod",
+ null,
+ "V",
+ AccessFlags.PUBLIC.value,
+ null,
+ null,
+ MutableMethodImplementation(16).also { testMethodImplementation = it }.apply {
+ repeat(10) { i -> this.addInstruction(TestInstruction(i)) }
+ },
+ ).let { testMethod = it.toMutable() }
@Test
- fun addInstructionsToImplementationIndexed() = applyToImplementation {
- addInstructions(5, getTestInstructions(5..6)).also {
- assertRegisterIs(5, 5)
- assertRegisterIs(6, 6)
+ fun addInstructionsToImplementationIndexed() =
+ applyToImplementation {
+ addInstructions(5, getTestInstructions(5..6)).also {
+ assertRegisterIs(5, 5)
+ assertRegisterIs(6, 6)
- assertRegisterIs(5, 7)
+ assertRegisterIs(5, 7)
+ }
}
- }
@Test
- fun addInstructionsToImplementation() = applyToImplementation {
- addInstructions(getTestInstructions(10..11)).also {
- assertRegisterIs(10, 10)
- assertRegisterIs(11, 11)
+ fun addInstructionsToImplementation() =
+ applyToImplementation {
+ addInstructions(getTestInstructions(10..11)).also {
+ assertRegisterIs(10, 10)
+ assertRegisterIs(11, 11)
+ }
}
- }
@Test
- fun removeInstructionsFromImplementationIndexed() = applyToImplementation {
- removeInstructions(5, 5).also { assertRegisterIs(4, 4) }
- }
-
- @Test
- fun removeInstructionsFromImplementation() = applyToImplementation {
- removeInstructions(0).also { assertRegisterIs(9, 9) }
- removeInstructions(1).also { assertRegisterIs(1, 0) }
- removeInstructions(2).also { assertRegisterIs(3, 0) }
- }
-
- @Test
- fun replaceInstructionsInImplementationIndexed() = applyToImplementation {
- replaceInstructions(5, getTestInstructions(0..1)).also {
- assertRegisterIs(0, 5)
- assertRegisterIs(1, 6)
- assertRegisterIs(7, 7)
+ fun removeInstructionsFromImplementationIndexed() =
+ applyToImplementation {
+ removeInstructions(5, 5).also { assertRegisterIs(4, 4) }
}
- }
@Test
- fun addInstructionToMethodIndexed() = applyToMethod {
- addInstruction(5, TestInstruction(0)).also { assertRegisterIs(0, 5) }
- }
-
- @Test
- fun addInstructionToMethod() = applyToMethod {
- addInstruction(TestInstruction(0)).also { assertRegisterIs(0, 10) }
- }
-
- @Test
- fun addSmaliInstructionToMethodIndexed() = applyToMethod {
- addInstruction(5, getTestSmaliInstruction(0)).also { assertRegisterIs(0, 5) }
- }
-
- @Test
- fun addSmaliInstructionToMethod() = applyToMethod {
- addInstruction(getTestSmaliInstruction(0)).also { assertRegisterIs(0, 10) }
- }
-
- @Test
- fun addInstructionsToMethodIndexed() = applyToMethod {
- addInstructions(5, getTestInstructions(0..1)).also {
- assertRegisterIs(0, 5)
- assertRegisterIs(1, 6)
-
- assertRegisterIs(5, 7)
+ fun removeInstructionsFromImplementation() =
+ applyToImplementation {
+ removeInstructions(0).also { assertRegisterIs(9, 9) }
+ removeInstructions(1).also { assertRegisterIs(1, 0) }
+ removeInstructions(2).also { assertRegisterIs(3, 0) }
}
- }
@Test
- fun addInstructionsToMethod() = applyToMethod {
- addInstructions(getTestInstructions(0..1)).also {
- assertRegisterIs(0, 10)
- assertRegisterIs(1, 11)
-
- assertRegisterIs(9, 9)
+ fun replaceInstructionsInImplementationIndexed() =
+ applyToImplementation {
+ replaceInstructions(5, getTestInstructions(0..1)).also {
+ assertRegisterIs(0, 5)
+ assertRegisterIs(1, 6)
+ assertRegisterIs(7, 7)
+ }
}
- }
@Test
- fun addSmaliInstructionsToMethodIndexed() = applyToMethod {
- addInstructionsWithLabels(5, getTestSmaliInstructions(0..1)).also {
- assertRegisterIs(0, 5)
- assertRegisterIs(1, 6)
-
- assertRegisterIs(5, 7)
+ fun addInstructionToMethodIndexed() =
+ applyToMethod {
+ addInstruction(5, TestInstruction(0)).also { assertRegisterIs(0, 5) }
}
- }
@Test
- fun addSmaliInstructionsToMethod() = applyToMethod {
- addInstructions(getTestSmaliInstructions(0..1)).also {
- assertRegisterIs(0, 10)
- assertRegisterIs(1, 11)
-
- assertRegisterIs(9, 9)
+ fun addInstructionToMethod() =
+ applyToMethod {
+ addInstruction(TestInstruction(0)).also { assertRegisterIs(0, 10) }
}
- }
@Test
- fun addSmaliInstructionsWithExternalLabelToMethodIndexed() = applyToMethod {
- val label = ExternalLabel("testLabel", getInstruction(5))
-
- addInstructionsWithLabels(
- 5,
- getTestSmaliInstructions(0..1).plus("\n").plus("goto :${label.name}"),
- label
- ).also {
- assertRegisterIs(0, 5)
- assertRegisterIs(1, 6)
- assertRegisterIs(5, 8)
-
- val gotoTarget = getInstruction(7)
- .target.location.instruction as OneRegisterInstruction
-
- assertEquals(5, gotoTarget.registerA)
+ fun addSmaliInstructionToMethodIndexed() =
+ applyToMethod {
+ addInstruction(5, getTestSmaliInstruction(0)).also { assertRegisterIs(0, 5) }
}
- }
@Test
- fun removeInstructionFromMethodIndexed() = applyToMethod {
- removeInstruction(5).also {
- assertRegisterIs(4, 4)
- assertRegisterIs(6, 5)
+ fun addSmaliInstructionToMethod() =
+ applyToMethod {
+ addInstruction(getTestSmaliInstruction(0)).also { assertRegisterIs(0, 10) }
}
- }
@Test
- fun removeInstructionsFromMethodIndexed() = applyToMethod {
- removeInstructions(5, 5).also { assertRegisterIs(4, 4) }
- }
+ fun addInstructionsToMethodIndexed() =
+ applyToMethod {
+ addInstructions(5, getTestInstructions(0..1)).also {
+ assertRegisterIs(0, 5)
+ assertRegisterIs(1, 6)
- @Test
- fun removeInstructionsFromMethod() = applyToMethod {
- removeInstructions(0).also { assertRegisterIs(9, 9) }
- removeInstructions(1).also { assertRegisterIs(1, 0) }
- removeInstructions(2).also { assertRegisterIs(3, 0) }
- }
-
- @Test
- fun replaceInstructionInMethodIndexed() = applyToMethod {
- replaceInstruction(5, TestInstruction(0)).also { assertRegisterIs(0, 5) }
- }
-
- @Test
- fun replaceInstructionsInMethodIndexed() = applyToMethod {
- replaceInstructions(5, getTestInstructions(0..1)).also {
- assertRegisterIs(0, 5)
- assertRegisterIs(1, 6)
- assertRegisterIs(7, 7)
+ assertRegisterIs(5, 7)
+ }
}
- }
@Test
- fun replaceSmaliInstructionsInMethodIndexed() = applyToMethod {
- replaceInstructions(5, getTestSmaliInstructions(0..1)).also {
- assertRegisterIs(0, 5)
- assertRegisterIs(1, 6)
- assertRegisterIs(7, 7)
+ fun addInstructionsToMethod() =
+ applyToMethod {
+ addInstructions(getTestInstructions(0..1)).also {
+ assertRegisterIs(0, 10)
+ assertRegisterIs(1, 11)
+
+ assertRegisterIs(9, 9)
+ }
+ }
+
+ @Test
+ fun addSmaliInstructionsToMethodIndexed() =
+ applyToMethod {
+ addInstructionsWithLabels(5, getTestSmaliInstructions(0..1)).also {
+ assertRegisterIs(0, 5)
+ assertRegisterIs(1, 6)
+
+ assertRegisterIs(5, 7)
+ }
+ }
+
+ @Test
+ fun addSmaliInstructionsToMethod() =
+ applyToMethod {
+ addInstructions(getTestSmaliInstructions(0..1)).also {
+ assertRegisterIs(0, 10)
+ assertRegisterIs(1, 11)
+
+ assertRegisterIs(9, 9)
+ }
+ }
+
+ @Test
+ fun addSmaliInstructionsWithExternalLabelToMethodIndexed() =
+ applyToMethod {
+ val label = ExternalLabel("testLabel", getInstruction(5))
+
+ addInstructionsWithLabels(
+ 5,
+ getTestSmaliInstructions(0..1).plus("\n").plus("goto :${label.name}"),
+ label,
+ ).also {
+ assertRegisterIs(0, 5)
+ assertRegisterIs(1, 6)
+ assertRegisterIs(5, 8)
+
+ val gotoTarget =
+ getInstruction(7)
+ .target.location.instruction as OneRegisterInstruction
+
+ assertEquals(5, gotoTarget.registerA)
+ }
+ }
+
+ @Test
+ fun removeInstructionFromMethodIndexed() =
+ applyToMethod {
+ removeInstruction(5).also {
+ assertRegisterIs(4, 4)
+ assertRegisterIs(6, 5)
+ }
+ }
+
+ @Test
+ fun removeInstructionsFromMethodIndexed() =
+ applyToMethod {
+ removeInstructions(5, 5).also { assertRegisterIs(4, 4) }
+ }
+
+ @Test
+ fun removeInstructionsFromMethod() =
+ applyToMethod {
+ removeInstructions(0).also { assertRegisterIs(9, 9) }
+ removeInstructions(1).also { assertRegisterIs(1, 0) }
+ removeInstructions(2).also { assertRegisterIs(3, 0) }
+ }
+
+ @Test
+ fun replaceInstructionInMethodIndexed() =
+ applyToMethod {
+ replaceInstruction(5, TestInstruction(0)).also { assertRegisterIs(0, 5) }
+ }
+
+ @Test
+ fun replaceInstructionsInMethodIndexed() =
+ applyToMethod {
+ replaceInstructions(5, getTestInstructions(0..1)).also {
+ assertRegisterIs(0, 5)
+ assertRegisterIs(1, 6)
+ assertRegisterIs(7, 7)
+ }
+ }
+
+ @Test
+ fun replaceSmaliInstructionsInMethodIndexed() =
+ applyToMethod {
+ replaceInstructions(5, getTestSmaliInstructions(0..1)).also {
+ assertRegisterIs(0, 5)
+ assertRegisterIs(1, 6)
+ assertRegisterIs(7, 7)
+ }
}
- }
// region Helper methods
@@ -212,22 +234,29 @@ private object InstructionExtensionsTest {
testMethod.apply(block)
}
- private fun MutableMethodImplementation.assertRegisterIs(register: Int, atIndex: Int) = assertEquals(
- register, getInstruction(atIndex).registerA
+ private fun MutableMethodImplementation.assertRegisterIs(
+ register: Int,
+ atIndex: Int,
+ ) = assertEquals(
+ register,
+ getInstruction(atIndex).registerA,
)
- private fun MutableMethod.assertRegisterIs(register: Int, atIndex: Int) =
- implementation!!.assertRegisterIs(register, atIndex)
+ private fun MutableMethod.assertRegisterIs(
+ register: Int,
+ atIndex: Int,
+ ) = implementation!!.assertRegisterIs(register, atIndex)
private fun getTestInstructions(range: IntRange) = range.map { TestInstruction(it) }
private fun getTestSmaliInstruction(register: Int) = "const/16 v$register, 0"
- private fun getTestSmaliInstructions(range: IntRange) = range.joinToString("\n") {
- getTestSmaliInstruction(it)
- }
+ private fun getTestSmaliInstructions(range: IntRange) =
+ range.joinToString("\n") {
+ getTestSmaliInstruction(it)
+ }
// endregion
private class TestInstruction(register: Int) : BuilderInstruction21s(Opcode.CONST_16, register, 0)
-}
\ No newline at end of file
+}
diff --git a/src/test/kotlin/app/revanced/patcher/patch/PatchInitializationTest.kt b/src/test/kotlin/app/revanced/patcher/patch/PatchInitializationTest.kt
new file mode 100644
index 0000000..f780175
--- /dev/null
+++ b/src/test/kotlin/app/revanced/patcher/patch/PatchInitializationTest.kt
@@ -0,0 +1,29 @@
+package app.revanced.patcher.patch
+
+import app.revanced.patcher.data.ResourceContext
+import org.junit.jupiter.api.assertThrows
+import kotlin.test.Test
+import app.revanced.patcher.patch.annotation.Patch as PatchAnnotation
+
+object PatchInitializationTest {
+ @Test
+ fun `initialize using constructor`() {
+ val patch =
+ object : ResourcePatch(name = "Resource patch test") {
+ override fun execute(context: ResourceContext) {}
+ }
+
+ assert(patch.name == "Resource patch test")
+ }
+
+ @Test
+ fun `initialize using annotation`() {
+ val patch =
+ @PatchAnnotation("Resource patch test")
+ object : ResourcePatch() {
+ override fun execute(context: ResourceContext) {}
+ }
+
+ assert(patch.name == "Resource patch test")
+ }
+}
diff --git a/src/test/kotlin/app/revanced/patcher/patch/options/PatchOptionsTest.kt b/src/test/kotlin/app/revanced/patcher/patch/options/PatchOptionsTest.kt
index 943d91d..6b89602 100644
--- a/src/test/kotlin/app/revanced/patcher/patch/options/PatchOptionsTest.kt
+++ b/src/test/kotlin/app/revanced/patcher/patch/options/PatchOptionsTest.kt
@@ -67,8 +67,7 @@ internal class PatchOptionsTest {
}
@Test
- fun `should allow setting custom value`() =
- assertDoesNotThrow { OptionsTestPatch.stringOptionWithChoices = "unknown" }
+ fun `should allow setting custom value`() = assertDoesNotThrow { OptionsTestPatch.stringOptionWithChoices = "unknown" }
@Test
fun `should allow resetting value`() = assertDoesNotThrow { OptionsTestPatch.stringOptionWithChoices = null }
@@ -86,42 +85,43 @@ internal class PatchOptionsTest {
}
@Test
- fun `option types should be known`() =
- assertTrue(OptionsTestPatch.options["array"].valueType == "StringArray")
+ fun `option types should be known`() = assertTrue(OptionsTestPatch.options["array"].valueType == "StringArray")
@Test
- fun `getting default value should work`() =
- assertDoesNotThrow { assertNull(OptionsTestPatch.resettableOption.default) }
+ fun `getting default value should work`() = assertDoesNotThrow { assertNull(OptionsTestPatch.resettableOption.default) }
+ @Suppress("DEPRECATION")
private object OptionsTestPatch : BytecodePatch() {
var booleanOption by booleanPatchOption(
"bool",
- true
+ true,
)
var requiredStringOption by stringPatchOption(
"required",
"default",
- required = true
- )
- var stringArrayOption = stringArrayPatchOption(
- "array",
- arrayOf("1", "2")
+ required = true,
)
+ var stringArrayOption =
+ stringArrayPatchOption(
+ "array",
+ arrayOf("1", "2"),
+ )
var stringOptionWithChoices by stringPatchOption(
"choices",
"value",
- values = mapOf("Valid option value" to "valid")
+ values = mapOf("Valid option value" to "valid"),
)
var validatedOption by stringPatchOption(
-
"validated",
- "default"
+ "default",
) { it == "valid" }
- var resettableOption = stringPatchOption(
- "resettable", null,
- required = true
- )
+ var resettableOption =
+ stringPatchOption(
+ "resettable",
+ null,
+ required = true,
+ )
override fun execute(context: BytecodeContext) {}
}
-}
\ No newline at end of file
+}
diff --git a/src/test/kotlin/app/revanced/patcher/patch/usage/ExampleBytecodePatch.kt b/src/test/kotlin/app/revanced/patcher/patch/usage/ExampleBytecodePatch.kt
index cca07ed..2f4b5f2 100644
--- a/src/test/kotlin/app/revanced/patcher/patch/usage/ExampleBytecodePatch.kt
+++ b/src/test/kotlin/app/revanced/patcher/patch/usage/ExampleBytecodePatch.kt
@@ -32,7 +32,7 @@ import com.google.common.collect.ImmutableList
name = "Example bytecode patch",
description = "Example demonstration of a bytecode patch.",
dependencies = [ExampleResourcePatch::class],
- compatiblePackages = [CompatiblePackage("com.example.examplePackage", arrayOf("0.0.1", "0.0.2"))]
+ compatiblePackages = [CompatiblePackage("com.example.examplePackage", arrayOf("0.0.1", "0.0.2"))],
)
object ExampleBytecodePatch : BytecodePatch(setOf(ExampleFingerprint)) {
// Entry point of a patch. Supplied fingerprints are resolved at this point.
@@ -60,7 +60,7 @@ object ExampleBytecodePatch : BytecodePatch(setOf(ExampleFingerprint)) {
invoke-static { }, LTestClass;->returnHello()Ljava/lang/String;
move-result-object v1
invoke-virtual { v0, v1 }, Ljava/io/PrintStream;->println(Ljava/lang/String;)V
- """
+ """,
)
}
@@ -82,14 +82,14 @@ object ExampleBytecodePatch : BytecodePatch(setOf(ExampleFingerprint)) {
BuilderInstruction21c(
Opcode.CONST_STRING,
0,
- ImmutableStringReference("Hello, ReVanced! Adding bytecode.")
+ ImmutableStringReference("Hello, ReVanced! Adding bytecode."),
),
- BuilderInstruction11x(Opcode.RETURN_OBJECT, 0)
+ BuilderInstruction11x(Opcode.RETURN_OBJECT, 0),
),
null,
- null
- )
- ).toMutable()
+ null,
+ ),
+ ).toMutable(),
)
// Add a field in the main class.
@@ -105,12 +105,12 @@ object ExampleBytecodePatch : BytecodePatch(setOf(ExampleFingerprint)) {
ImmutableFieldReference(
"Ljava/lang/System;",
"out",
- "Ljava/io/PrintStream;"
- )
+ "Ljava/io/PrintStream;",
+ ),
),
null,
- null
- ).toMutable()
+ null,
+ ).toMutable(),
)
}
} ?: throw PatchException("Fingerprint failed to resolve.")
@@ -121,7 +121,10 @@ object ExampleBytecodePatch : BytecodePatch(setOf(ExampleFingerprint)) {
* @param index The index of the instruction to replace.
* @param string The replacement string.
*/
- private fun MutableMethod.replaceStringAt(index: Int, string: String) {
+ private fun MutableMethod.replaceStringAt(
+ index: Int,
+ string: String,
+ ) {
val instruction = getInstruction(index)
// Utility method of dexlib2.
@@ -139,8 +142,7 @@ object ExampleBytecodePatch : BytecodePatch(setOf(ExampleFingerprint)) {
// At last, use the method replaceInstruction to replace it at the given index startIndex.
replaceInstruction(
index,
- "const-string ${strInstruction.registerA}, ${ImmutableStringReference(string)}"
+ "const-string ${strInstruction.registerA}, ${ImmutableStringReference(string)}",
)
}
}
-
diff --git a/src/test/kotlin/app/revanced/patcher/patch/usage/ExampleFingerprint.kt b/src/test/kotlin/app/revanced/patcher/patch/usage/ExampleFingerprint.kt
index 3a1d7d4..64bd62d 100644
--- a/src/test/kotlin/app/revanced/patcher/patch/usage/ExampleFingerprint.kt
+++ b/src/test/kotlin/app/revanced/patcher/patch/usage/ExampleFingerprint.kt
@@ -1,7 +1,7 @@
package app.revanced.patcher.patch.usage
import app.revanced.patcher.extensions.or
-import app.revanced.patcher.fingerprint.annotation.FuzzyPatternScanMethod
import app.revanced.patcher.fingerprint.MethodFingerprint
+import app.revanced.patcher.fingerprint.annotation.FuzzyPatternScanMethod
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
@@ -12,9 +12,9 @@ object ExampleFingerprint : MethodFingerprint(
listOf("[L"),
listOf(
Opcode.SGET_OBJECT,
- null, // Matching unknown opcodes.
+ null, // Matching unknown opcodes.
Opcode.INVOKE_STATIC, // This is intentionally wrong to test fuzzy matching.
- Opcode.RETURN_VOID
+ Opcode.RETURN_VOID,
),
- null
-)
\ No newline at end of file
+ null,
+)
diff --git a/src/test/kotlin/app/revanced/patcher/patch/usage/ExampleResourcePatch.kt b/src/test/kotlin/app/revanced/patcher/patch/usage/ExampleResourcePatch.kt
index f7a9981..011c0f0 100644
--- a/src/test/kotlin/app/revanced/patcher/patch/usage/ExampleResourcePatch.kt
+++ b/src/test/kotlin/app/revanced/patcher/patch/usage/ExampleResourcePatch.kt
@@ -4,19 +4,19 @@ import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.ResourcePatch
import org.w3c.dom.Element
-
class ExampleResourcePatch : ResourcePatch() {
override fun execute(context: ResourceContext) {
context.xmlEditor["AndroidManifest.xml"].use { editor ->
- val element = editor // regular DomFileEditor
- .file
- .getElementsByTagName("application")
- .item(0) as Element
+ val element =
+ editor // regular DomFileEditor
+ .file
+ .getElementsByTagName("application")
+ .item(0) as Element
element
.setAttribute(
"exampleAttribute",
- "exampleValue"
+ "exampleValue",
)
}
}
-}
\ No newline at end of file
+}
diff --git a/src/test/kotlin/app/revanced/patcher/util/smali/InlineSmaliCompilerTest.kt b/src/test/kotlin/app/revanced/patcher/util/smali/InlineSmaliCompilerTest.kt
index 08b0393..4421932 100644
--- a/src/test/kotlin/app/revanced/patcher/util/smali/InlineSmaliCompilerTest.kt
+++ b/src/test/kotlin/app/revanced/patcher/util/smali/InlineSmaliCompilerTest.kt
@@ -33,16 +33,18 @@ internal class InlineSmaliCompilerTest {
val insnIndex = insnAmount - 2
val targetIndex = insnIndex - 1
- method.addInstructions(arrayOfNulls(insnAmount).also {
- Arrays.fill(it, "const/4 v0, 0x0")
- }.joinToString("\n"))
+ method.addInstructions(
+ arrayOfNulls(insnAmount).also {
+ Arrays.fill(it, "const/4 v0, 0x0")
+ }.joinToString("\n"),
+ )
method.addInstructionsWithLabels(
targetIndex,
"""
:test
const/4 v0, 0x1
if-eqz v0, :test
- """
+ """,
)
val insn = method.getInstruction(insnIndex)
@@ -59,7 +61,7 @@ internal class InlineSmaliCompilerTest {
"""
const/4 v0, 0x1
const/4 v0, 0x0
- """
+ """,
)
assertEquals(labelIndex, method.newLabel(labelIndex).location.index)
@@ -71,7 +73,7 @@ internal class InlineSmaliCompilerTest {
if-eqz v0, :test
return-void
""",
- ExternalLabel("test", method.getInstruction(1))
+ ExternalLabel("test", method.getInstruction(1)),
)
val insn = method.getInstruction(insnIndex)
@@ -93,13 +95,16 @@ internal class InlineSmaliCompilerTest {
accessFlags,
emptySet(),
emptySet(),
- MutableMethodImplementation(registerCount)
+ MutableMethodImplementation(registerCount),
).toMutable()
- private fun instructionEquals(want: BuilderInstruction, have: BuilderInstruction) {
+ private fun instructionEquals(
+ want: BuilderInstruction,
+ have: BuilderInstruction,
+ ) {
assertEquals(want.opcode, have.opcode)
assertEquals(want.format, have.format)
assertEquals(want.codeUnits, have.codeUnits)
}
}
-}
\ No newline at end of file
+}