From 01c617d94e58b30bbffb3426fcfa55b8979962bd Mon Sep 17 00:00:00 2001 From: j4k0xb <55899582+j4k0xb@users.noreply.github.com> Date: Thu, 24 Aug 2023 04:21:18 +0200 Subject: [PATCH] feat(Solid Explorer): Add `Remove file size limit` patch Co-authored-by: oSumAtrIX --- .../fingerprints/OnReadyFingerprint.kt | 15 +++++++++++ .../patch/RemoveFileSizeLimitPatch.kt | 27 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/solidexplorer2/functionality/filesize/fingerprints/OnReadyFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/solidexplorer2/functionality/filesize/patch/RemoveFileSizeLimitPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/solidexplorer2/functionality/filesize/fingerprints/OnReadyFingerprint.kt b/src/main/kotlin/app/revanced/patches/solidexplorer2/functionality/filesize/fingerprints/OnReadyFingerprint.kt new file mode 100644 index 0000000000..22e625b681 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/solidexplorer2/functionality/filesize/fingerprints/OnReadyFingerprint.kt @@ -0,0 +1,15 @@ +package app.revanced.patches.solidexplorer2.functionality.filesize.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import com.android.tools.smali.dexlib2.Opcode + +object OnReadyFingerprint : MethodFingerprint( + opcodes = listOf( + Opcode.CONST_WIDE_32, // Constant storing the 2MB limit + Opcode.CMP_LONG, + Opcode.IF_LEZ, + ), + customFingerprint = { methodDef, _ -> + methodDef.definingClass == "Lpl/solidexplorer/plugins/texteditor/TextEditor;" && methodDef.name == "onReady" + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/solidexplorer2/functionality/filesize/patch/RemoveFileSizeLimitPatch.kt b/src/main/kotlin/app/revanced/patches/solidexplorer2/functionality/filesize/patch/RemoveFileSizeLimitPatch.kt new file mode 100644 index 0000000000..28a2dc1bde --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/solidexplorer2/functionality/filesize/patch/RemoveFileSizeLimitPatch.kt @@ -0,0 +1,27 @@ +package app.revanced.patches.solidexplorer2.functionality.filesize.patch + +import app.revanced.extensions.toErrorResult +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Package +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patches.solidexplorer2.functionality.filesize.fingerprints.OnReadyFingerprint +import com.android.tools.smali.dexlib2.iface.instruction.ThreeRegisterInstruction + +@Patch +@Name("Remove file size limit") +@Description("Allows opening files larger than 2 MB in the text editor.") +@Compatibility([Package("pl.solidexplorer2")]) +class RemoveFileSizeLimitPatch : BytecodePatch(listOf(OnReadyFingerprint)) { + override fun execute(context: BytecodeContext) = OnReadyFingerprint.result?.let { result -> + val cmpIndex = result.scanResult.patternScanResult!!.startIndex + 1 + val cmpResultRegister = result.mutableMethod.getInstruction(cmpIndex).registerA + + result.mutableMethod.replaceInstruction(cmpIndex, "const/4 v${cmpResultRegister}, 0x0") + } ?: throw OnReadyFingerprint.toErrorResult() +}