[TUTORIAL|EXTREME] Beyond Reflection - ASM - Replacing Loaded Classes

Discussion in 'Resources' started by Icyene, Sep 5, 2012.

Thread Status:
Not open for further replies.
  1. Offline


    Maybe, maybe not. The devs of Java haven't had a good reason to update the Attach API since Java 1.6, so I doubt they decided to... Its probably just compilation differences. I analyzed their methods with dependency walker and they are identical. Should work.
  2. Offline


    That's interesting, where the f*ck does the file size difference come from then? The only thing I can think of the 64bit compile vs. a 32bit compile maybe? If you want, I can set up a few vm's to get you your libs! :)
  3. Offline


    Giant Difference in how they are handled, etc? 2Kb is a negligible difference.

    Thanks for the offer! If you could get the darned Solaris ones it would be wonderful. ATM I'm stuck downloading the OpenJDK for Mac x64...
  4. Offline


    Icyene I'll look into it, but considering how the Solaris download is already sort of hidden deeply away somewhere! :D
    *Must find*
  5. Offline


  6. Offline


    Yea, that's the JDK, I meant Solaris itself ;) But have already found it! :D
  7. Offline


    Giant but the library is in the package :O Why do you need to install Solaris? The same thing can be done by extracting the files from the .tar.gz. Also, I have Solaris 32-bit :)
  8. Offline


    Hehe, yea I sort of realized that after I saw your link... But anyhow, you don't need to install solaris to be able to use it you know... As quite a few other linux/unix distros it offers a live disk/usb installer, which gives you some space to play around before installing it! :)

    Anyhow here you go:
    Solaris x64 - https://dl.dropbox.com/u/11165157/Java 7/64/solaris/libattach.so
    Solaris Sparc x64 - https://dl.dropbox.com/u/11165157/Java 7/64/solaris sparc/libattach.so
    Solaris Sparc x86 - https://dl.dropbox.com/u/11165157/Java 7/32/solaris sparc/libattach.so

    Edit 2:
    That's odd, it seems the x86 version of the solaris sparc jdk might not contain the attach lib?!

    Edit 3:
    Never mind found it, seems to be located in jdk/jre/lib/sparc....
  9. Offline


    @Icyene Where does VirtualMachine come from?
  10. Offline



    Giant YIPPEE! Thanks!

    EDIT: Pushed to git, now there is a Libraries.zip. Tomorrow I'll add extracting and java.library.path changing to match the correct library. Or ask xiaomao to do it :p
  11. Offline


    Do u still need Mac?
  12. Offline


    Where does ClassReader and ClassWriter come from? I am currently importing them from com.avaje.ebean.enhance.asm, but I am getting errors on both of them. ClassWriter says that the constructor new ClassWriter(boolean) is undefined, and ClassReader says that the method 'accept' takes the args ClassVisitor and int, not ClassAdapter and boolean.
  13. Offline


    For this tutorial I used the org.objectweb.asm.ClassWriter/Reader. These come with the ASM-objectweb jar file.
    gregthegeek likes this.
  14. Offline


    Ahh, beautiful. Where does ClassAdapter come from?
  15. Offline


    Same place :)
  16. Offline


    For some reason it's not there for me. I can only get it from com.avaje.ebean.enhance.asm, and that one gives me errors.
  17. Offline


    Strange... maybe try downloading all the asm libraries and referencing all?
  18. Offline


    Hmm, doesn't seem to be working. Where is the jar downloaded from? I think I might have the wrong one.
  19. Offline


  20. Offline


  21. Offline


    gregthegeek Sorry for the late response. Here are the binaries I am using. Use the org.objectweb imports where possible. Have fun :)

    Attached Files:

    gregthegeek likes this.
  22. Offline


    How do I remove the transformer ? I mean where do I have to call the method Killagent()?
  23. Offline


    heyho, I've been very interested in byte code manipulation since the last few days. So as far as I can see it is possible to "add method calls inside a method", but is it also possible to remove specific or all calls? So is it possible to override a method completly?
  24. Offline


    You can overwrite the method if you add first you custom code and then disable the old code with a return statement.

    // your custom code
    // old code, not called now
  25. Offline


    I'm interested in this tutorial, would it be possible to replace some of the server files during runtime to call events? Such as when a beacon applies a potion effect to a player, replace the class during runtime to make it call a BeaconEffectEvent or something?
  26. Offline


    I don't see INVOKEDYNAMIC, only INTERFACE, SPECIAL, STATIC, and VIRTUAL. Did something change?

    Edit: Just used 186 instead.
  27. Offline


    I have a Mac at home, do you need any file from that? If so - which?
  28. Offline



    I have a problem running your code. The reason is that ASM5 does not have a ClassAdapter / MethodAdapter anymore, they have moved to ClassVisitor and MethodVisitor. With that, their contructor has changed.

    Your Code:
    1. public class ProfileClassAdapter extends ClassAdapter {
    2. private String className;
    3. public ProfileClassAdapter(ClassVisitor visitor, String theClass) {
    4. super(visitor);
    5. this.className = theClass;
    6. }
    8. @Override
    9. public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    10. // awesome stuff here
    11. }
    12. }

    What needed to be changed:
    1. public class ProfileClassAdapter extends ClassVisitor {
    2. private String className;
    3. public ProfileClassAdapter(ClassVisitor visitor, String theClass) {
    4. super(0); // <- IllegalArgumentException
    5. this.className = theClass;
    6. }
    7. @Override
    8. public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    9. // awesome stuff here
    10. }
    11. }

    However, this gives an error in the Agent.java's custom transform method, as the loader parameter is null. After removing that check the mentioned line, super(0), throws an IllegalArgumentException. What do I have to place instead of the 0?
  29. Offline


    If you want the enum/named int, I think you put Opcodes.ASM5. Otherwise, if you want a number, use 327680
Thread Status:
Not open for further replies.

Share This Page