test: use findClass with className & cleanup

This commit is contained in:
Lucaskyy 2022-03-31 23:22:57 +02:00 committed by oSumAtrIX
parent 4087f49863
commit a1b6b06bd3
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4

View File

@ -36,57 +36,55 @@ fun main() {
signatures signatures
) )
val mainMethodPatchViaClassProxy = object : Patch("main-method-patch-via-proxy") { patcher.addPatches(
override fun execute(cache: Cache): PatchResult { object : Patch("main-method-patch-via-proxy") {
val proxy = cache.findClass { classDef -> override fun execute(cache: Cache): PatchResult {
classDef.type.contains("XAdRemover") val proxy = cache.findClass("XAdRemover")
} ?: return PatchResultError("Class 'XAdRemover' could not be found") ?: return PatchResultError("Class 'XAdRemover' could not be found")
val xAdRemoverClass = proxy.resolve() val xAdRemoverClass = proxy.resolve()
val hideReelMethod = xAdRemoverClass.methods.single { method -> method.name.contains("HideReel") } val hideReelMethod = xAdRemoverClass.methods.single { method -> method.name.contains("HideReel") }
val readSettingsMethodRef = ImmutableMethodReference( val readSettingsMethodRef = ImmutableMethodReference(
"Lfi/razerman/youtube/XGlobals;", "Lfi/razerman/youtube/XGlobals;",
"ReadSettings", "ReadSettings",
emptyList(), emptyList(),
"V" "V"
) )
val instructions = hideReelMethod.implementation!!.instructions val instructions = hideReelMethod.implementation!!.instructions
val readSettingsInstruction = BuilderInstruction35c( val readSettingsInstruction = BuilderInstruction35c(
Opcode.INVOKE_STATIC, Opcode.INVOKE_STATIC,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
readSettingsMethodRef readSettingsMethodRef
) )
// TODO: figure out control flow // TODO: figure out control flow
// otherwise the we would still jump over to the original instruction at index 21 instead to our new one // otherwise the we would still jump over to the original instruction at index 21 instead to our new one
instructions.add( instructions.add(
21, 21,
readSettingsInstruction readSettingsInstruction
) )
return PatchResultSuccess() return PatchResultSuccess()
} }
} },
object : Patch("main-method-patch-via-signature") {
val mainMethodPatchViaSignature = object : Patch("main-method-patch-via-signature") { override fun execute(cache: Cache): PatchResult {
override fun execute(cache: Cache): PatchResult { val mainMethodMap = cache.resolvedMethods["main-method"]
val mainMethodMap = cache.resolvedMethods["main-method"] mainMethodMap.definingClassProxy.immutableClass.methods.single { method ->
mainMethodMap.definingClassProxy.immutableClass.methods.single { method -> method.name == mainMethodMap.resolvedMethodName
method.name == mainMethodMap.resolvedMethodName }
return PatchResultSuccess()
} }
return PatchResultSuccess()
} }
} )
patcher.addPatches(mainMethodPatchViaClassProxy, mainMethodPatchViaSignature)
patcher.applyPatches() patcher.applyPatches()
patcher.save() patcher.save()
} }