mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-03 08:04:36 +02:00
chore: lint code
This commit is contained in:
parent
4fd2577a8f
commit
adc9072bba
@ -10,7 +10,6 @@ import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
|||||||
import app.revanced.util.getTargetIndex
|
import app.revanced.util.getTargetIndex
|
||||||
import app.revanced.util.resultOrThrow
|
import app.revanced.util.resultOrThrow
|
||||||
import com.android.tools.smali.dexlib2.Opcode
|
import com.android.tools.smali.dexlib2.Opcode
|
||||||
import com.android.tools.smali.dexlib2.util.MethodUtil
|
|
||||||
import kotlin.properties.Delegates
|
import kotlin.properties.Delegates
|
||||||
|
|
||||||
abstract class BaseMainActivityResolvePatch(
|
abstract class BaseMainActivityResolvePatch(
|
||||||
@ -19,9 +18,11 @@ abstract class BaseMainActivityResolvePatch(
|
|||||||
setOf(mainActivityOnCreateFingerprint)
|
setOf(mainActivityOnCreateFingerprint)
|
||||||
) {
|
) {
|
||||||
lateinit var mainActivityMutableClass: MutableClass
|
lateinit var mainActivityMutableClass: MutableClass
|
||||||
lateinit var onBackPressedMethod: MutableMethod
|
|
||||||
private lateinit var constructorMethod: MutableMethod
|
private lateinit var constructorMethod: MutableMethod
|
||||||
|
private lateinit var onBackPressedMethod: MutableMethod
|
||||||
private lateinit var onCreateMethod: MutableMethod
|
private lateinit var onCreateMethod: MutableMethod
|
||||||
|
|
||||||
private var constructorMethodIndex by Delegates.notNull<Int>()
|
private var constructorMethodIndex by Delegates.notNull<Int>()
|
||||||
private var onBackPressedMethodIndex by Delegates.notNull<Int>()
|
private var onBackPressedMethodIndex by Delegates.notNull<Int>()
|
||||||
|
|
||||||
@ -30,20 +31,12 @@ abstract class BaseMainActivityResolvePatch(
|
|||||||
onCreateMethod = mainActivityResult.mutableMethod
|
onCreateMethod = mainActivityResult.mutableMethod
|
||||||
mainActivityMutableClass = mainActivityResult.mutableClass
|
mainActivityMutableClass = mainActivityResult.mutableClass
|
||||||
|
|
||||||
/**
|
// set constructor method
|
||||||
* Set Constructor Method
|
constructorMethod = getMethod("<init>")
|
||||||
*/
|
|
||||||
constructorMethod =
|
|
||||||
mainActivityMutableClass.methods.find { method -> MethodUtil.isConstructor(method) }
|
|
||||||
?: throw PatchException("Could not find constructorMethod")
|
|
||||||
constructorMethodIndex = constructorMethod.implementation!!.instructions.size - 1
|
constructorMethodIndex = constructorMethod.implementation!!.instructions.size - 1
|
||||||
|
|
||||||
/**
|
// set onBackPressed method
|
||||||
* Set OnBackPressed Method
|
onBackPressedMethod = getMethod("onBackPressed")
|
||||||
*/
|
|
||||||
onBackPressedMethod =
|
|
||||||
mainActivityMutableClass.methods.find { method -> method.name == "onBackPressed" }
|
|
||||||
?: throw PatchException("Could not find onBackPressedMethod")
|
|
||||||
onBackPressedMethodIndex = onBackPressedMethod.getTargetIndex(Opcode.RETURN_VOID)
|
onBackPressedMethodIndex = onBackPressedMethod.getTargetIndex(Opcode.RETURN_VOID)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,16 +47,23 @@ abstract class BaseMainActivityResolvePatch(
|
|||||||
onBackPressedMethod.injectMethodCall(classDescriptor, methodDescriptor, onBackPressedMethodIndex)
|
onBackPressedMethod.injectMethodCall(classDescriptor, methodDescriptor, onBackPressedMethodIndex)
|
||||||
|
|
||||||
fun injectOnCreateMethodCall(classDescriptor: String, methodDescriptor: String) =
|
fun injectOnCreateMethodCall(classDescriptor: String, methodDescriptor: String) =
|
||||||
onCreateMethod.injectMethodCall(classDescriptor, methodDescriptor, 0)
|
onCreateMethod.injectMethodCall(classDescriptor, methodDescriptor)
|
||||||
|
|
||||||
|
private fun getMethod(methodDescriptor: String) =
|
||||||
|
mainActivityMutableClass.methods.find { method -> method.name == methodDescriptor }
|
||||||
|
?: throw PatchException("Could not find $methodDescriptor")
|
||||||
|
|
||||||
|
private fun MutableMethod.injectMethodCall(
|
||||||
|
classDescriptor: String,
|
||||||
|
methodDescriptor: String
|
||||||
|
) = injectMethodCall(classDescriptor, methodDescriptor, 0)
|
||||||
|
|
||||||
private fun MutableMethod.injectMethodCall(
|
private fun MutableMethod.injectMethodCall(
|
||||||
classDescriptor: String,
|
classDescriptor: String,
|
||||||
methodDescriptor: String,
|
methodDescriptor: String,
|
||||||
insertIndex: Int
|
insertIndex: Int
|
||||||
) {
|
) = addInstruction(
|
||||||
addInstruction(
|
insertIndex,
|
||||||
insertIndex,
|
"invoke-static/range {p0 .. p0}, $classDescriptor->$methodDescriptor(Landroid/app/Activity;)V"
|
||||||
"invoke-static/range {p0 .. p0}, $classDescriptor->$methodDescriptor(Landroid/app/Activity;)V"
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user