mirror of
https://github.com/revanced/revanced-patcher.git
synced 2025-05-01 05:44:24 +02:00
feat: add p
naming scheme to smali compiler
This commit is contained in:
parent
8f12873200
commit
79909cf260
@ -15,8 +15,8 @@ import java.io.InputStreamReader
|
|||||||
private const val METHOD_TEMPLATE = """
|
private const val METHOD_TEMPLATE = """
|
||||||
.class public Linlinecompiler;
|
.class public Linlinecompiler;
|
||||||
.super Ljava/lang/Object;
|
.super Ljava/lang/Object;
|
||||||
.method public static compiler()V
|
.method public static compiler(%s)V
|
||||||
.registers 1
|
.registers %d
|
||||||
%s
|
%s
|
||||||
.end method
|
.end method
|
||||||
"""
|
"""
|
||||||
@ -25,14 +25,15 @@ class InlineSmaliCompiler {
|
|||||||
companion object {
|
companion object {
|
||||||
/**
|
/**
|
||||||
* Compiles a string of Smali code to a list of instructions.
|
* Compiles a string of Smali code to a list of instructions.
|
||||||
|
* p0, p1 etc. will only work correctly if the parameters and registers are passed.
|
||||||
* Do not cross the boundaries of the control flow (if-nez insn, etc),
|
* Do not cross the boundaries of the control flow (if-nez insn, etc),
|
||||||
* as that will result in exceptions since the labels cannot be calculated.
|
* as that will result in exceptions since the labels cannot be calculated.
|
||||||
* Do not create dummy labels to fix the issue, since the code addresses will
|
* Do not create dummy labels to fix the issue, since the code addresses will
|
||||||
* be messed up and results in broken Dalvik bytecode.
|
* be messed up and results in broken Dalvik bytecode.
|
||||||
* FIXME: Fix the above issue. When this is fixed, add the proper conversions in [InstructionConverter].
|
* FIXME: Fix the above issue. When this is fixed, add the proper conversions in [InstructionConverter].
|
||||||
*/
|
*/
|
||||||
fun compileMethodInstructions(instructions: String): List<BuilderInstruction> {
|
fun compileMethodInstructions(instructions: String, parameters: String, registers: Int): List<BuilderInstruction> {
|
||||||
val input = METHOD_TEMPLATE.format(instructions)
|
val input = METHOD_TEMPLATE.format(parameters, registers, instructions)
|
||||||
val reader = InputStreamReader(input.byteInputStream())
|
val reader = InputStreamReader(input.byteInputStream())
|
||||||
val lexer: LexerErrorInterface = smaliFlexLexer(reader, 15)
|
val lexer: LexerErrorInterface = smaliFlexLexer(reader, 15)
|
||||||
val tokens = CommonTokenStream(lexer as TokenSource)
|
val tokens = CommonTokenStream(lexer as TokenSource)
|
||||||
@ -53,5 +54,5 @@ class InlineSmaliCompiler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun String.toInstructions() = InlineSmaliCompiler.compileMethodInstructions(this)
|
fun String.toInstructions(parameters: String = "", registers: Int = 1) = InlineSmaliCompiler.compileMethodInstructions(this, parameters, registers)
|
||||||
fun String.toInstruction() = this.toInstructions().first()
|
fun String.toInstruction(parameters: String = "", registers: Int = 1) = this.toInstructions(parameters, registers).first()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user