I’m using proguard.classfile.editor.InstructionSequencesReplacer
in proguard-core to replace sets of instructions (as shown here). If a stack map frame appears in the middle of an instruction set in a class file, the instruction set is not replaced. Is there a way to have the instructions be replaced?
Hi @Askew6226 !
Have you tried running the CodePreverifier
after making your changes to recreate the stackmap frames? e.g.
programClassPool.classesAccept(
new ClassVersionFilter(VersionConstants.CLASS_VERSION_1_6,
new AllMethodVisitor(
new AllAttributeVisitor(
new CodePreverifier(false)))));
If this doesn’t help, can you share a reproducible sample?
Thanks,
James
Hi @james,
I think the problem I am running into is how I’m trying to handle the stack map frames that appear in the class before I try to replace instructions (though I did try running the CodePreverifier).
I’ve attached a class that contains a stack map frame.
Also attached is what I’m using to make replacements in the class with proguard-core 9.0.8.
I’m using Krakatau to examine the bytecode and I notice that even if I remove the stack map frames, the instruction replacement does not work when I try to replace the “sipush 1122” instruction that comes after the frame.
Am I doing anything wrong?
ClassWithStackMapFrame.java (278 Bytes)
ClassTransformer.java (5.7 KB)
ClassWithStackMapFrame krakatau output:
.version 52 0
.class public super ClassWithStackMapFrame
.super java/lang/Object
.method protected <init> : ()V
.code stack 4 locals 8
L0: aload_0
L1: invokespecial Method java/lang/Object <init> ()V
L4: invokestatic Method java/lang/System currentTimeMillis ()J
L7: ldc2_w 55567L
L10: lsub
L11: lstore_1
L12: lload_1
L13: ldc2_w 12345L
L16: lsub
L17: lstore_3
L18: lload_3
L19: ldc2_w 567L
L22: lcmp
L23: ifne L32
L26: sipush 890
L29: goto L35
.stack full
locals Object ClassWithStackMapFrame Long Long
stack
.end stack
L32: sipush 1122
.stack stack_1 Integer
L35: istore 5
L37: invokestatic Method java/lang/System currentTimeMillis ()J
L40: ldc2_w 44455L
L43: ladd
L44: lstore 6
L46: return
L47:
.linenumbertable
L0 2
L4 3
L12 4
L18 5
L37 6
L46 7
.end linenumbertable
.end code
.end method
.sourcefile 'ClassWithStackMapFrame.java'
.end class