From 5aa4538f5ec8a6521ca8d7f23d58a4113dd73125 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matou=C5=A1=20Ku=C4=8Dera?= Date: Tue, 20 Aug 2024 13:13:45 +0200 Subject: [PATCH] fix: TeaVM analyzer bug --- .../editor/InstructionSequenceReplacer.java | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/base/src/main/java/proguard/classfile/editor/InstructionSequenceReplacer.java b/base/src/main/java/proguard/classfile/editor/InstructionSequenceReplacer.java index 103b6b21e..24773f503 100644 --- a/base/src/main/java/proguard/classfile/editor/InstructionSequenceReplacer.java +++ b/base/src/main/java/proguard/classfile/editor/InstructionSequenceReplacer.java @@ -396,13 +396,45 @@ public Instruction create(Clazz clazz, CodeAttribute codeAttribute, int index) { instructionSequenceMatcher.matchedInstructionOffset(matchedInstructionIndex); // Create the instruction. - replacementInstructions[index].accept( - clazz, null, codeAttribute, matchedInstructionOffset, this); + Instruction insn = replacementInstructions[index]/*.accept(clazz, null, codeAttribute, matchedInstructionOffset, this)*/; + + // fix TeaVM analyzer bug, we can't have nice things + if (insn instanceof SimpleInstruction) { + this.visitSimpleInstruction(clazz, null, codeAttribute, matchedInstructionOffset, (SimpleInstruction) insn); + } else if (insn instanceof VariableInstruction) { + this.visitVariableInstruction(clazz, null, codeAttribute, matchedInstructionOffset, (VariableInstruction) insn); + } else if (insn instanceof ConstantInstruction) { + this.visitConstantInstruction(clazz, null, codeAttribute, matchedInstructionOffset, (ConstantInstruction) insn); + } else if (insn instanceof BranchInstruction) { + this.visitBranchInstruction(clazz, null, codeAttribute, matchedInstructionOffset, (BranchInstruction) insn); + } else if (insn instanceof TableSwitchInstruction) { + this.visitTableSwitchInstruction(clazz, null, codeAttribute, matchedInstructionOffset, (TableSwitchInstruction) insn); + } else if (insn instanceof LookUpSwitchInstruction) { + this.visitLookUpSwitchInstruction(clazz, null, codeAttribute, matchedInstructionOffset, (LookUpSwitchInstruction) insn); + } else if (insn instanceof Catch) { + this.visitCatchInstruction(clazz, null, codeAttribute, matchedInstructionOffset, (Catch) insn); + } else if (insn instanceof Label) { + this.visitLabelInstruction(clazz, null, codeAttribute, matchedInstructionOffset, (Label) insn); + } else { + this.visitAnyInstruction(clazz, null, codeAttribute, matchedInstructionOffset, insn); + } // Return it. return replacementInstruction; } + @SuppressWarnings("DataFlowIssue") + private void teaVMFix0() { + this.visitSimpleInstruction(null, null, null, 0, null); + this.visitVariableInstruction(null, null, null, 0, null); + this.visitConstantInstruction(null, null, null, 0, null); + this.visitBranchInstruction(null, null, null, 0, null); + this.visitTableSwitchInstruction(null, null, null, 0, null); + this.visitLookUpSwitchInstruction(null, null, null, 0, null); + this.visitLabelInstruction(null, null, null, 0, null); + this.visitCatchInstruction(null, null, null, 0, null); + } + // Implementations for InstructionVisitor. @Override