Jump to content

Recommended Posts

Posted

Hi! I try add a invocation's method with ASM in AbstractPlayer. This work perfect in 1.6.4 but it's illegal in 1.7.2. I have a error: according to forge I modify the vanilla class! But i can do this differently!

Sorry for my english i don't speak very well english

Posted

Yes I trying to patch getSkinUrl and getCapeUrl

 

package fr.lefgolas.pickandcraft;

 

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

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.ClassNode;

import org.objectweb.asm.tree.InsnList;

import org.objectweb.asm.tree.InsnNode;

import org.objectweb.asm.tree.MethodInsnNode;

import org.objectweb.asm.tree.MethodNode;

import org.objectweb.asm.tree.VarInsnNode;

 

 

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

 

@Override

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

//on cherche la classe qui nous interressent. On gère les deux cas: si elle est "obscurcie" ou pas

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 targetMethod1Name = "", targetMethod2Name = "";

boolean ok1 = false, ok2 = false;

       

        if(obfuscated == true) {

        targetMethod1Name ="d";

targetMethod2Name = "e";

        }

        else {

        targetMethod1Name ="getSkinUrl";

targetMethod2Name = "getCapeUrl";

        }

       

 

      //on prépare la manipulation

    ClassNode classNode = new ClassNode();

        ClassReader classReader = new ClassReader(bytes);

        classReader.accept(classNode, 0);

       

 

      //Maintenant, on boucle sur toutes les méthodes déclarées dans la classe jusqu'à trouver la/les methode(s) cible(s)

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

        while(methods.hasNext())

        {

            MethodNode m = methods.next();

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

 

       

          //On vérifie si il s'agit de la méthode cible et si elle a la même signature (plus de détail ici: http://journals.ecs.soton.ac.uk/java/tutorial/native1.1/implementing/method.html)

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

            {

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

               

                //on créer une liste d'instruction pour invoquer une méthode statique

                InsnList toInject = new InsnList();

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

                //new MethodInsnNode(on déclare le type de la méthode, "le chemin de la classe", "le nom de la méthode", "sa signature")

                toInject.add(new MethodInsnNode(INVOKESTATIC, "fr.lefgolas.pickandcraft/PlayerCustom", "getURLSkinCustom", "(Ljava/lang/String;)Ljava/lang/String;"));

                toInject.add(new InsnNode(ARETURN));

               

                  // on remplace les instructions déjà présente dans la méthode par notre liste d'instruction

                  m.instructions = toInject;

                  ok1 = true;

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

            }

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

            {

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

                  InsnList toInject = new InsnList();

                   

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

                  toInject.add(new MethodInsnNode(INVOKESTATIC, "fr.lefgolas.pickandcraft/PlayerCustom", "getURLCapeCustom", "(Ljava/lang/String;)Ljava/lang/String;"));

                  toInject.add(new InsnNode(ARETURN));

               

                  // on remplace les instructions déjà présente dans la méthode par notre liste d'instruction

                  m.instructions = toInject;

                  ok2 = true;

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

            }

           

            if(ok1 && ok2)

            break;

        }

       

      //on finit la manipulation

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

        classNode.accept(writer);

        return writer.toByteArray();

      }

}

 

Posted

No, I want also patch getSkinUrl! More over the library is complicated for that i want do! And i want patch other functions. This is why I want understand why ASM don't work

 

I would like use ASM because is most simple.

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I tried do download the essential mod to my mod pack but i didnt work. I paly on 1.21 and it should work. I use neoforge for my modding. The weird things is my friend somehow added the mod to his modpack and many others that I somehow can´t. Is there anything i can do? 
    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
  • Topics

×
×
  • Create New...

Important Information

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