[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

    Icyene

    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

    Giant

    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

    Icyene

    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

    Giant

    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

    Icyene

  6. Offline

    Giant

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

    Icyene

    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

    Giant

    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! :)

    Edit:
    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

    Chiller

    @Icyene Where does VirtualMachine come from?
     
  10. Offline

    Icyene

    tools.jar.

    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

    hawkfalcon

    Do u still need Mac?
     
  12. Offline

    gregthegeek

    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

    Icyene

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

    gregthegeek

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

    Icyene

    Same place :)
     
  16. Offline

    gregthegeek

    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

    Icyene

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

    gregthegeek

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

    Icyene

  20. Offline

    gregthegeek

  21. Offline

    Icyene

    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

    asif

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

    p000ison

    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

    IDragonfire


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

    Code:
    // your custom code
    return;
    // old code, not called now
    
     
  25. Offline

    foodyling

    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

    krazytraynz

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

    Edit: Just used 186 instead.
     
  27. Offline

    qlimax5000

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

    UbuntuFreak

    Hey,

    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:
    Code:java
    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. }
    7.  
    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:
    Code:java
    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

    Cirno

    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