From 41e88605c33d1f0d9e7f5466cac03a3b339afb82 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sat, 4 Jun 2022 02:25:13 +0200 Subject: [PATCH] feat: optional `forStaticMethod` parameter for `InlineSmaliCompiler.compileMethodInstructions` --- .../patcher/util/smali/InlineSmaliCompiler.kt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) 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 80b96c7f..68cd1894 100644 --- a/src/main/kotlin/app/revanced/patcher/util/smali/InlineSmaliCompiler.kt +++ b/src/main/kotlin/app/revanced/patcher/util/smali/InlineSmaliCompiler.kt @@ -13,9 +13,9 @@ import org.jf.smali.smaliTreeWalker import java.io.InputStreamReader private const val METHOD_TEMPLATE = """ -.class public Linlinecompiler; +.class LInlineCompiler; .super Ljava/lang/Object; -.method public static compiler(%s)V +.method %s dummyMethod(%s)V .registers %d %s .end method @@ -35,9 +35,10 @@ class InlineSmaliCompiler { fun compileMethodInstructions( instructions: String, parameters: String, - registers: Int + registers: Int, + forStaticMethod: Boolean ): List { - val input = METHOD_TEMPLATE.format(parameters, registers, instructions) + val input = METHOD_TEMPLATE.format(if (forStaticMethod) "static" else "", parameters, registers, instructions) val reader = InputStreamReader(input.byteInputStream()) val lexer: LexerErrorInterface = smaliFlexLexer(reader, 15) val tokens = CommonTokenStream(lexer as TokenSource) @@ -58,8 +59,8 @@ class InlineSmaliCompiler { } } -fun String.toInstructions(parameters: String = "", registers: Int = 1) = - InlineSmaliCompiler.compileMethodInstructions(this, parameters, registers) +fun String.toInstructions(parameters: String = "", registers: Int = 1, forStaticMethod: Boolean = true) = + InlineSmaliCompiler.compileMethodInstructions(this, parameters, registers, forStaticMethod) -fun String.toInstruction(parameters: String = "", registers: Int = 1) = - this.toInstructions(parameters, registers).first() +fun String.toInstruction(parameters: String = "", registers: Int = 1, forStaticMethod: Boolean = true) = + this.toInstructions(parameters, registers, forStaticMethod).first()