#ASM Help

1 messages · Page 1 of 1 (latest)

woven valve
#

Hey friends! I'm wondering why some of my code isn't working quite well. I'm using ASM and playing around with bytecode injection. Currently I have it injecting into the bytecode correctly, however I'm having some trouble getting it copy the original code as well. Beforehand I was wrapping the instructions in a try-catch statement, but it was copying the original code into the catch statement, which is obviously not what I want. I'm at the end of my rope here trying to figure this out, not even ChatGPT can provide any insight. If anyone could point me in the right direction that'd be amazing. Forgot to note, the MethodNode is the methodnode of InjectMethod#injectableMethod(String className)

Original Code:

    public ConstructorTest(QuickTest test) {
        this.test = test;
        System.out.println("ConstructorTest");
    }

    @InjectLocation
    public ConstructorTest(QuickTest test1,String test) {
        this.test = test1;
        System.out.println("ConstructorTest " + test);
    }```

Injected Code (Removing the annotation is intentional):

```public ConstructorTest(QuickTest var1) {
        String var2 = "Lme/quicktest/QuickTest;";
        System.out.println("Injecting into " + var2);
    }

    public ConstructorTest(QuickTest var1, String var2) {
        String var3 = "Lme/quicktest/QuickTest;";
        System.out.println("Injecting into " + var3);
    }```

Method in which I am stealing instructions from:

```public class InjectMethod {
    public void injectableMethod(String className) {
        System.out.println("Injecting into " + className);
    }
}```

Code Visitor:

```              @Override
              public void visitCode() {
                super.visitCode();
                if (isAnnotated) {
                  isAnnotated = false;
                  System.out.println("Injecting into " + name);

                  int varIndex = methodNode.maxLocals;

                  methodNode.visitLocalVariable(
                      "className",
                      "Ljava/lang/String;",
                      null,
                      new Label(),
                      new Label(),
                      varIndex);
                  methodNode.maxLocals++;


                  super.visitLdcInsn(className);
                  super.visitVarInsn(Opcodes.ASTORE, 1);
                  super.visitVarInsn(Opcodes.ALOAD, 1);

                  // Insert the instructions of the methodNodeToInsert at the beginning
                  // of the visited method's instruction list
                  methodNode.instructions.accept(this);

                  super.visitLabel(new Label());

                  System.out.println("Finished injecting into " + name);
                }
              }```
toxic finchBOT
#

<@&987246399047479336> please have a look, thanks.

toxic finchBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

woven valve
#

Bmp

weak remnant
karmic magnet
#

Here's what I did for another project

toxic finchBOT
# karmic magnet

I uploaded your attachments as gist. That way, they are easier to read for everyone, especially mobile users 👍

karmic magnet
#

Can't remember if this sets the result of a CompletableFuture or copies the method into a CompletableFuture

woven valve