Skip to content

Commit

Permalink
test: use findClass with className & cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Sculas authored and oSumAtrIX committed Jun 5, 2022
1 parent 4087f49 commit a1b6b06
Showing 1 changed file with 41 additions and 43 deletions.
84 changes: 41 additions & 43 deletions src/test/kotlin/patcher/PatcherTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,57 +36,55 @@ fun main() {
signatures
)

val mainMethodPatchViaClassProxy = object : Patch("main-method-patch-via-proxy") {
override fun execute(cache: Cache): PatchResult {
val proxy = cache.findClass { classDef ->
classDef.type.contains("XAdRemover")
} ?: return PatchResultError("Class 'XAdRemover' could not be found")
patcher.addPatches(
object : Patch("main-method-patch-via-proxy") {
override fun execute(cache: Cache): PatchResult {
val proxy = cache.findClass("XAdRemover")
?: return PatchResultError("Class 'XAdRemover' could not be found")

val xAdRemoverClass = proxy.resolve()
val hideReelMethod = xAdRemoverClass.methods.single { method -> method.name.contains("HideReel") }
val xAdRemoverClass = proxy.resolve()
val hideReelMethod = xAdRemoverClass.methods.single { method -> method.name.contains("HideReel") }

val readSettingsMethodRef = ImmutableMethodReference(
"Lfi/razerman/youtube/XGlobals;",
"ReadSettings",
emptyList(),
"V"
)

val instructions = hideReelMethod.implementation!!.instructions
val readSettingsMethodRef = ImmutableMethodReference(
"Lfi/razerman/youtube/XGlobals;",
"ReadSettings",
emptyList(),
"V"
)

val readSettingsInstruction = BuilderInstruction35c(
Opcode.INVOKE_STATIC,
0,
0,
0,
0,
0,
0,
readSettingsMethodRef
)
val instructions = hideReelMethod.implementation!!.instructions

// TODO: figure out control flow
// otherwise the we would still jump over to the original instruction at index 21 instead to our new one
instructions.add(
21,
readSettingsInstruction
)
return PatchResultSuccess()
}
}
val readSettingsInstruction = BuilderInstruction35c(
Opcode.INVOKE_STATIC,
0,
0,
0,
0,
0,
0,
readSettingsMethodRef
)

val mainMethodPatchViaSignature = object : Patch("main-method-patch-via-signature") {
override fun execute(cache: Cache): PatchResult {
val mainMethodMap = cache.resolvedMethods["main-method"]
mainMethodMap.definingClassProxy.immutableClass.methods.single { method ->
method.name == mainMethodMap.resolvedMethodName
// TODO: figure out control flow
// otherwise the we would still jump over to the original instruction at index 21 instead to our new one
instructions.add(
21,
readSettingsInstruction
)
return PatchResultSuccess()
}
},
object : Patch("main-method-patch-via-signature") {
override fun execute(cache: Cache): PatchResult {
val mainMethodMap = cache.resolvedMethods["main-method"]
mainMethodMap.definingClassProxy.immutableClass.methods.single { method ->
method.name == mainMethodMap.resolvedMethodName
}
return PatchResultSuccess()
}

return PatchResultSuccess()
}
}
)

patcher.addPatches(mainMethodPatchViaClassProxy, mainMethodPatchViaSignature)
patcher.applyPatches()
patcher.save()
}

0 comments on commit a1b6b06

Please sign in to comment.