[VFramework]Hooking Fields

Discussion in 'Programming General' started by iJava, Dec 6, 2012.

[VFramework]Hooking Fields
  1. Unread #1 - Dec 6, 2012 at 6:20 AM
  2. iJava
    Joined:
    Nov 21, 2011
    Posts:
    1,197
    Referrals:
    11
    Sythe Gold:
    485
    Discord Unique ID:
    220055593568829441

    iJava .Previously known as RSGoldRush
    $200 USD Donor New

    [VFramework]Hooking Fields

    Ok so I'm going to make a series of tutorials based around VFramework. Today I'm going to use "getInterfaceBounds" as an example.

    NOTE : THIS PATTERN MAY NOT WORK FOR YOU

    Since this field is in the client class we already have a container for it. So first we create our analyzer in the Client container :

    Code:
    private class InterfaceBounds extends Analyzer {
    
        public InterfaceBounds(final Container container) {
                super(container);
            }
    
             @Override
            public boolean execute(final Container container) {
    
              return false
    
           }
    
    }
    Now lets begin checking each field :

    Code:
    private class InterfaceBounds extends Analyzer {
    
            public InterfaceBounds(final Container container) {
                super(container);
            }
    
            @Override
            public boolean execute(final Container container) {
                for (final FieldNode fn : container.fields) {
                    if (!fn.desc.equals("[Ljava/awt/Rectangle;") || !Modifier.isStatic(fn.access)) {
                        continue;
                    }
    
    }
    
    }
    Since interfacebounds is an array of rectangles and is static we skip through anything that ins't.

    Now we need to iterate through each method :

    Code:
    for (final MethodNode mn : container.nodes.keySet()) {
                        if (!mn.desc.endsWith(")V") || mn.name.contains("<clinit>") || !Modifier.isStatic(mn.access) || !Modifier.isFinal(mn.access)) {
                            continue;
                        }
    Here we skipped the method if it wasn't void, skipped the <clinit> method, wasn't static and wasn't final.

    Now we define our pattern using EIS :

    Code:
    final EIS eis = new EIS(container.nodes.get(mn), "imul if_icmpge getstatic iload aaload");
    That is pretty self-explanitory, Now we need to check that the pattern was found in the methodnode :

    Code:
    if (eis.found() < 1) {
                            continue;
                        }
    EIS create a list of AbstractInsnNode[], so now we need to find which array matches our fieldnode type which we filtered through earlier, so we do :

    Code:
    AbstractInsnNode[] match;
                        while ((match = eis.next()) != null) {
                            if (!((FieldInsnNode) match[2]).name.equals(fn.name)) {
                                continue;
                            }
    
    }
    This iterates through the list of AbstractInsnNode[] until the field at instruction '2' matches A fieldnode where it's static and an array of rectangles if you remember the code we had at the start. The '2' refers to the index in the pattern where the field exists, so the getstatic(index of 2) referenced the field and therefore has our FieldNode.

    Now we finish everything off with this :

    Code:
        track();
                            container.output.add("@ getInterfaceBounds() --> " + fn.desc + " " + container.clazz.name + "." + fn.name);
                            Processor.addFieldGetter(container.clazz, fn, "getInterfaceBounds");
                            return true;
    The track(), stops the timer(used for stats), the second line just adds the output to your updater log, the third line injects a getter into the client node, called getInterfaceBounds() and returns the fieldnode we found, next line is well you know.

    Our final code should look like this :

    Code:
    private class InterfaceBounds extends Analyzer {
    
            public InterfaceBounds(final Container container) {
                super(container);
            }
    
            @Override
            public boolean execute(final Container container) {
                for (final FieldNode fn : container.fields) {
                    if (!fn.desc.equals("[Ljava/awt/Rectangle;") || !Modifier.isStatic(fn.access)) {
                        continue;
                    }
                    for (final MethodNode mn : container.nodes.keySet()) {
                        if (!mn.desc.endsWith(")V") || mn.name.contains("<clinit>") || !Modifier.isStatic(mn.access) || !Modifier.isFinal(mn.access)) {
                            continue;
                        }
                        final EIS eis = new EIS(container.nodes.get(mn), "imul if_icmpge getstatic iload aaload");
                        if (eis.found() < 1) {
                            continue;
                        }
                        AbstractInsnNode[] match;
                        while ((match = eis.next()) != null) {
                            if (!((FieldInsnNode) match[2]).name.equals(fn.name)) {
                                continue;
                            }
                            track();
                            container.output.add("@ getInterfaceBounds() --> " + fn.desc + " " + container.clazz.name + "." + fn.name);
                            Processor.addFieldGetter(container.clazz, fn, "getInterfaceBounds");
                            return true;
                        }
                    }
                }
                container.output.add("@ getInterfaceBounds() --> broken");
                return false;
            }
        }
    Notice the part I added at the bottom? If it had not found the pattern(eis.found() == 0 in every methodnode) then it would add the broken output to the updater log and return false.

    Output :
    Code:
    @ getInterfaceBounds() --> [Ljava/awt/Rectangle; client.rv
    Hope this helped, please ask any questions.
     
< What Language's To Learn? | Java Runtime Error >

Users viewing this thread
1 guest


 
 
Adblock breaks this site