Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hello!

I try to modify 2 functions: getSkinUrl and getCapeUrl with ASM in order to create my own skin system. In this way i can do event in my server. Tank's to this code I have managed to delete the content of function and i have add a invocation to a static method. But I want return the result and I don't know how do this!

 

package pickandcraftSkin;

 

import static org.objectweb.asm.Opcodes.ALOAD;

import static org.objectweb.asm.Opcodes.INVOKESTATIC;

 

import java.util.Iterator;

 

import org.objectweb.asm.ClassReader;

import org.objectweb.asm.ClassWriter;

import org.objectweb.asm.tree.AbstractInsnNode;

import org.objectweb.asm.tree.ClassNode;

import org.objectweb.asm.tree.InsnList;

import org.objectweb.asm.tree.MethodInsnNode;

import org.objectweb.asm.tree.MethodNode;

import org.objectweb.asm.tree.VarInsnNode;

 

 

 

 

public class EDClassTransformer implements net.minecraft.launchwrapper.IClassTransformer {

 

@Override

public byte[] transform(String arg0, String arg1, byte[] arg2) {

 

if (arg0.equals("beu")) {

System.out.println("********* INSIDE OBFUSCATED AbstractClientPlayer TRANSFORMER ABOUT TO PATCH: " + arg0);

return patchClassASM(arg0, arg2, true);

        }

 

if (arg0.equals("net.minecraft.client.entity.AbstractClientPlayer")) {

System.out.println("********* INSIDE AbstractClientPlayer TRANSFORMER ABOUT TO PATCH: " + arg0);

return patchClassASM(arg0, arg2, false);

        }

        return arg2;

}

 

public byte[] patchClassASM(String name, byte[] bytes, boolean obfuscated) {

 

String targetMethodName = "";

       

        if(obfuscated == true)

        targetMethodName ="d";

        else

        targetMethodName ="getSkinUrl";

       

 

      //set up ASM class manipulation stuff. Consult the ASM docs for details

    ClassNode classNode = new ClassNode();

        ClassReader classReader = new ClassReader(bytes);

        classReader.accept(classNode, 0);

       

       

     

      //Now we loop over all of the methods declared inside the Explosion class until we get to the targetMethodName "doExplosionB"

 

        // find method to inject into

        @SuppressWarnings("unchecked")

        Iterator<MethodNode> methods = classNode.methods.iterator();

        while(methods.hasNext())

        {

            MethodNode m = methods.next();

            System.out.println("********* Method Name: "+m.name + " Desc:" + m.desc);

 

       

          //Check if this is doExplosionB and it's method signature is (Z)V which means that it accepts a boolean (Z) and returns a void (V)

            if ((m.name.equals(targetMethodName) && m.desc.equals("(Ljava/lang/String;)Ljava/lang/String;")))

            {

                System.out.println("********* Inside target method!");

                //on supprime tous les noeuds

                AbstractInsnNode targetNode = null;

               

                @SuppressWarnings("unchecked")

                Iterator<AbstractInsnNode> iter = m.instructions.iterator();

                int index = -1;

               

                while (iter.hasNext()) {

                    index++;

                    targetNode = iter.next();

                    m.instructions.remove(targetNode);

                }

           

                InsnList toInject = new InsnList();

             

toInject.add(new VarInsnNode(ALOAD, 0));

                    toInject.add(new MethodInsnNode(INVOKESTATIC, "pickandcraftSkin/PlayerCustom", "getURLSkincustom", "(Ljava/lang/String;)Ljava/lang/String;"));

               

                // inject new instruction list into method instruction list

                m.instructions.insert(toInject);

               

                System.out.println("Patching Complete!");

                break;

            }

        }

       

      //ASM specific for cleaning up and returning the final bytes for JVM processing.

        ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);

        classNode.accept(writer);

        return writer.toByteArray();

      }

}

  • Author

But where add the return instruction? Before or after  toInject.add(new MethodInsnNode(INVOKESTATIC, "pickandcraftSkin/PlayerCustom", "getURLSkincustom", "(Ljava/lang/String;)Ljava/lang/String;")) ?

And how add the return instruction? I can't do this: toInject.add("ARETURN")!

 

 

Sorry for my english: I'm french and I don't speak very well english :)

It should be safe to completely replace the instruction list of the method. It would be more efficient, and cleaner.

 

As for what to put in the new instruction list, here's what you need to do:

               if ((m.name.equals(targetMethodName) && m.desc.equals("(Ljava/lang/String;)Ljava/lang/String;")))
               {
                   System.out.println("********* Inside target method!");
                   InsnList toInject = new InsnList();
                     
                   toInject.add(new VarInsnNode(ALOAD, 0));
                   toInject.add(new MethodInsnNode(INVOKESTATIC, "pickandcraftSkin/PlayerCustom", "getURLSkincustom", "(Ljava/lang/String;)Ljava/lang/String;"));
                   toInject.add(new InsnNode(ARETURN));
                
                   // inject new instruction list into method instruction list
                   m.instructions = toInject;
                   
                   System.out.println("Patching Complete!");
                   break;
               }

  • Author

AMAZING!! It work!

Moreover, thanks to you I have understand a little how work the JVM. My problem is resolve!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.