Example usage for org.objectweb.asm Opcodes ILOAD

List of usage examples for org.objectweb.asm Opcodes ILOAD

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes ILOAD.

Prototype

int ILOAD

To view the source code for org.objectweb.asm Opcodes ILOAD.

Click Source Link

Usage

From source file:com.dank.analysis.impl.character.player.config.PlayerConfig.java

License:GNU General Public License

@Override
public void evaluate(ClassNode cn) {
    for (final MethodNode mn : cn.methods) {
        //            if (mn.desc.endsWith("()V")) {
        //                for (final BasicBlock block : mn.graph()) {
        //                    if (block.count(new MemberQuery(Opcodes.PUTSTATIC, "[S")) == 2 && block.count(new MemberQuery(Opcodes.PUTSTATIC, "[[S")) == 2 &&
        //                            block.count(new MemberQuery(Opcodes.GETSTATIC, "[S")) == 2 && block.count(new MemberQuery(Opcodes.GETSTATIC, "[[S")) == 2) {
        //                            System.out.println(cn.name + "." + mn.name);
        //                            FieldInsnNode fin = (FieldInsnNode) block.get(new MemberQuery(Opcodes.PUTSTATIC, "[S"));
        //                            Hook.CLIENT.put(new RSField(fin, "colorsToFind"));
        ////from  w w  w .  ja va2  s  .co  m
        //                            fin = (FieldInsnNode) block.get(Opcodes.PUTSTATIC, 1);
        //                            Hook.CLIENT.put(new RSField(fin, "colorsToReplace"));
        //
        //                            fin = (FieldInsnNode) block.get(Opcodes.PUTSTATIC, 2);
        //                            Hook.CLIENT.put(new RSField(fin, "colorsToFind1"));
        //
        //                            fin = (FieldInsnNode) block.get(Opcodes.PUTSTATIC, 3);
        //                            Hook.CLIENT.put(new RSField(fin, "colorsToReplace1"));
        //
        //                    }
        //                }
        //            }
        if (!mn.isStatic() && !mn.desc.endsWith("V")) {
            for (final BasicBlock block : mn.graph()) {
                if (block.count(Opcodes.ILOAD) == 3 && block.count(FieldInsnNode.class) == 3) {
                    final FieldInsnNode fin = (FieldInsnNode) block
                            .get(new MemberQuery(Opcodes.GETFIELD, "[I"));
                    if (fin == null)
                        continue;
                    Hook.PLAYER_CONFIG.put(new RSField(fin, "appearanceColors"));
                }
            }
        }
    }
    for (final FieldNode fn : cn.fields) {
        if (!fn.isStatic()) {
            FieldData fd = DynaFlowAnalyzer.getField(cn.name, fn.name);
            if (fn.desc.equals("Z")) {
                Hook.PLAYER_CONFIG.put(new RSField(fn, "female"));
            } else if (fn.desc.equals("I")) {
                Hook.PLAYER_CONFIG.put(new RSField(fn, "npcId"));
            } else if (fn.desc.equals("[I")
                    && !fn.name.equals(Hook.PLAYER_CONFIG.get("appearanceColors").name)) {
                Hook.PLAYER_CONFIG.put(new RSField(fn, "appearance"));
            } else if (fn.desc.equals("J")) {
                boolean isAnimated = false;
                for (MethodData md : fd.referencedFrom) {
                    if (new Wildcard("(?)V").matches(md.METHOD_DESC)) {
                        isAnimated = true;
                        break;
                    }
                }
                if (isAnimated)
                    Hook.PLAYER_CONFIG.put(new RSField(fn, "animatedModelId"));
                else
                    Hook.PLAYER_CONFIG.put(new RSField(fn, "baseModelId"));
            }
        }
    }
}

From source file:com.dank.analysis.impl.landscape.DynamicObject.java

License:GNU General Public License

@Override
public void evaluate(ClassNode cn) {
    RSMethod rotatedModel = (RSMethod) Hook.ENTITY.get("getRotatedModel");//Inherited method from Entity
    if (rotatedModel != null) {
        MethodData sub = DynaFlowAnalyzer.getMethod(cn.name, rotatedModel.name, rotatedModel.desc);
        if (sub != null)
            Hook.DYNAMIC_OBJECT.put(new RSMethod(sub.bytecodeMethod, "getRotatedModel"));
    }//from  w  w  w.  ja v a  2 s . c om
    for (FieldNode fn : cn.fields) {
        if (fn.isStatic())
            continue;
        if (fn.desc.equals("L" + Hook.ANIMATION_SEQUENCE.getInternalName() + ";")) {
            Hook.DYNAMIC_OBJECT.put(new RSField(fn, "animationSequence"));
        }
    }
    final MethodNode mn = cn.getMethodByName("<init>");
    if (mn != null) {
        final int[] indexes = { 1, 2, 3, 4, 5, 6 };
        final String[] hooks = { "id", "type", "orientation", "floorLevel", "regionX", "regionY" };
        for (int i = 0; i < indexes.length; i++) {
            final FieldInsnNode fin = load(mn, Opcodes.ILOAD, indexes[i], Hook.DYNAMIC_OBJECT);
            if (fin != null) {
                Hook.DYNAMIC_OBJECT.put(new RSField(fin, hooks[i]));
            }
        }
    }
}

From source file:com.dank.analysis.impl.landscape.GraphicsStub.java

License:GNU General Public License

@Override
public void evaluate(ClassNode cn) {
    for (final FieldNode fn : cn.fields) {
        if (fn.desc.equals("Z") && !fn.isStatic()) {
            Hook.GRAPHICS_STUB.put(new RSField(fn, "finished"));
        }/*from w  w w .  j av a2  s  .co m*/
    }
    final MethodNode mn = cn.getMethodByName("<init>");
    if (mn != null) {
        final int[] indexes = { 1, 2, 3, 4, 5, 6 };
        final String[] hooks = { "id", "floorLevel", "regionX", "regionY", "height", "startCycle" };
        for (int i = 0; i < indexes.length; i++) {
            final FieldInsnNode fin = load(mn, Opcodes.ILOAD, indexes[i], Hook.GRAPHICS_STUB);
            if (fin != null) {
                Hook.GRAPHICS_STUB.put(new RSField(fin, hooks[i]));
            }
        }
    }
    for (FieldNode fn : cn.fields) {
        if (fn.isStatic())
            continue;
        if (fn.desc.equals("L" + Hook.ANIMATION_SEQUENCE.getInternalName() + ";")) {
            Hook.GRAPHICS_STUB.put(new RSField(fn, "animationSequence"));
        }
    }
}

From source file:com.geeksaga.light.profiler.util.ASMUtil.java

License:Apache License

public static VarInsnNode createILOAD(int index) {
    return new VarInsnNode(Opcodes.ILOAD, index);
}

From source file:com.github.anba.es6draft.compiler.assembler.InstructionAssembler.java

License:Open Source License

private void load(int var, Type type) {
    assert var >= 0 && variables.isActive(var) : "variable is not initialized";
    switch (type.getOpcode(Opcodes.ILOAD)) {
    case Opcodes.ILOAD:
        iload(var);
        return;//from  w  w  w.j  a v  a2  s . co m
    case Opcodes.LLOAD:
        lload(var);
        return;
    case Opcodes.FLOAD:
        fload(var);
        return;
    case Opcodes.DLOAD:
        dload(var);
        return;
    case Opcodes.ALOAD:
        aload(var);
        return;
    default:
        throw new IllegalArgumentException();
    }
}

From source file:com.github.anba.es6draft.compiler.assembler.InstructionAssembler.java

License:Open Source License

private void iload(int var) {
    methodVisitor.visitVarInsn(Opcodes.ILOAD, var);
    stack.iload(var);
}

From source file:com.github.jasmo.obfuscate.InlineAccessors.java

License:Open Source License

private Query[] getPattern(boolean get, ClassNode owner, FieldNode field) {
    Type type = Type.getType(field.desc);
    List<Query> queries = new LinkedList<>();
    boolean local = local(field.access);
    if (local)//from w  ww. j  a v a  2s . c  o  m
        queries.add(new Query("opcode", Opcodes.ALOAD, "var", 0));
    if (get) {
        int opcode = local ? Opcodes.GETFIELD : Opcodes.GETSTATIC;
        queries.add(new Query("opcode", opcode, "owner", owner.name, "name", field.name, "desc", field.desc));
        queries.add(new Query("opcode", type.getOpcode(Opcodes.IRETURN)));
    } else {
        int opcode = local ? Opcodes.PUTFIELD : Opcodes.PUTSTATIC;
        queries.add(new Query("opcode", type.getOpcode(Opcodes.ILOAD), "var", 0));
        queries.add(new Query("opcode", opcode, "owner", owner.name, "name", field.name, "desc", field.desc));
        queries.add(new Query("opcode", Opcodes.RETURN));
    }
    return queries.toArray(new Query[queries.size()]);
}

From source file:com.github.malamut2.low.AllocationMethodAdapter.java

License:Apache License

private void pushProductOfIntArrayOnStack() {
    Label beginScopeLabel = new Label();
    Label endScopeLabel = new Label();

    int dimsArrayIndex = newLocal("[I", beginScopeLabel, endScopeLabel);
    int counterIndex = newLocal("I", beginScopeLabel, endScopeLabel);
    int productIndex = newLocal("I", beginScopeLabel, endScopeLabel);
    Label loopLabel = new Label();
    Label endLabel = new Label();

    super.visitLabel(beginScopeLabel);

    // stack: ... intArray
    super.visitVarInsn(Opcodes.ASTORE, dimsArrayIndex);
    // -> stack: ...

    // counter = 0
    super.visitInsn(Opcodes.ICONST_0);
    super.visitVarInsn(Opcodes.ISTORE, counterIndex);
    // product = 1
    super.visitInsn(Opcodes.ICONST_1);
    super.visitVarInsn(Opcodes.ISTORE, productIndex);
    // loop:// w  w  w  . j  av  a2s.c om
    super.visitLabel(loopLabel);
    // if index >= arraylength goto end:
    super.visitVarInsn(Opcodes.ILOAD, counterIndex);
    super.visitVarInsn(Opcodes.ALOAD, dimsArrayIndex);
    super.visitInsn(Opcodes.ARRAYLENGTH);
    super.visitJumpInsn(Opcodes.IF_ICMPGE, endLabel);
    // product = product * max(array[counter],1)
    super.visitVarInsn(Opcodes.ALOAD, dimsArrayIndex);
    super.visitVarInsn(Opcodes.ILOAD, counterIndex);
    super.visitInsn(Opcodes.IALOAD);
    super.visitInsn(Opcodes.DUP);
    Label nonZeroDimension = new Label();
    super.visitJumpInsn(Opcodes.IFNE, nonZeroDimension);
    super.visitInsn(Opcodes.POP);
    super.visitInsn(Opcodes.ICONST_1);
    super.visitLabel(nonZeroDimension);
    super.visitVarInsn(Opcodes.ILOAD, productIndex);
    super.visitInsn(Opcodes.IMUL); // if overflow happens it happens.
    super.visitVarInsn(Opcodes.ISTORE, productIndex);
    // iinc counter 1
    super.visitIincInsn(counterIndex, 1);
    // goto loop
    super.visitJumpInsn(Opcodes.GOTO, loopLabel);
    // end:
    super.visitLabel(endLabel);
    // re-push dimensions array
    super.visitVarInsn(Opcodes.ALOAD, dimsArrayIndex);
    // push product
    super.visitVarInsn(Opcodes.ILOAD, productIndex);

    super.visitLabel(endScopeLabel);
}

From source file:com.github.malamut2.low.AllocationMethodAdapter.java

License:Apache License

/**
 * Reflection-based allocation (@see java.lang.reflect.Array#newInstance) is
 * triggered with a static method call (INVOKESTATIC), so we hook it here.
 * Class initialization is triggered with a constructor call (INVOKESPECIAL)
 * so we hook that here too as a proxy for the new bytecode which leaves an
 * uninitialized object on the stack that we're not allowed to touch.
 * {@link java.lang.Object#clone} is also a call to INVOKESPECIAL,
 * and is hooked here.  {@link java.lang.Class#newInstance} and
 * {@link java.lang.reflect.Constructor#newInstance} are both
 * INVOKEVIRTUAL calls, so they are hooked here, as well.
 *//* www . j av a 2 s  .  co m*/
@Override
public void visitMethodInsn(int opcode, String owner, String name, String signature, boolean itf) {
    if (opcode == Opcodes.INVOKESTATIC &&
    // Array does its own native allocation.  Grr.
            owner.equals("java/lang/reflect/Array") && name.equals("newInstance")) {
        if (signature.equals("(Ljava/lang/Class;I)Ljava/lang/Object;")) {

            Label beginScopeLabel = new Label();
            Label endScopeLabel = new Label();
            super.visitLabel(beginScopeLabel);

            // stack: ... class count
            int countIndex = newLocal("I", beginScopeLabel, endScopeLabel);
            super.visitVarInsn(Opcodes.ISTORE, countIndex);
            // -> stack: ... class
            pushClassNameOnStack();
            // -> stack: ... class className
            int typeNameIndex = newLocal("Ljava/lang/String;", beginScopeLabel, endScopeLabel);
            super.visitVarInsn(Opcodes.ASTORE, typeNameIndex);
            // -> stack: ... class
            super.visitVarInsn(Opcodes.ILOAD, countIndex);
            // -> stack: ... class count
            super.visitMethodInsn(opcode, owner, name, signature, itf);
            // -> stack: ... newobj
            super.visitInsn(Opcodes.DUP);
            // -> stack: ... newobj newobj
            super.visitVarInsn(Opcodes.ILOAD, countIndex);
            // -> stack: ... newobj newobj count
            super.visitInsn(Opcodes.SWAP);
            // -> stack: ... newobj count newobj
            super.visitVarInsn(Opcodes.ALOAD, typeNameIndex);
            super.visitLabel(endScopeLabel);
            // -> stack: ... newobj count newobj className
            super.visitInsn(Opcodes.SWAP);
            // -> stack: ... newobj count className newobj
            super.visitMethodInsn(Opcodes.INVOKESTATIC, recorderClass, recorderMethod, RECORDER_SIGNATURE,
                    false);
            // -> stack: ... newobj
            return;
        } else if (signature.equals("(Ljava/lang/Class;[I)Ljava/lang/Object;")) {
            Label beginScopeLabel = new Label();
            Label endScopeLabel = new Label();
            super.visitLabel(beginScopeLabel);

            int dimsArrayIndex = newLocal("[I", beginScopeLabel, endScopeLabel);
            // stack: ... class dimsArray
            pushProductOfIntArrayOnStack();
            // -> stack: ... class dimsArray product
            int productIndex = newLocal("I", beginScopeLabel, endScopeLabel);
            super.visitVarInsn(Opcodes.ISTORE, productIndex);
            // -> stack: ... class dimsArray

            super.visitVarInsn(Opcodes.ASTORE, dimsArrayIndex);
            // -> stack: ... class
            pushClassNameOnStack();
            // -> stack: ... class className
            int typeNameIndex = newLocal("Ljava/lang/String;", beginScopeLabel, endScopeLabel);
            super.visitVarInsn(Opcodes.ASTORE, typeNameIndex);
            // -> stack: ... class
            super.visitVarInsn(Opcodes.ALOAD, dimsArrayIndex);
            // -> stack: ... class dimsArray
            super.visitMethodInsn(opcode, owner, name, signature, itf);
            // -> stack: ... newobj

            super.visitInsn(Opcodes.DUP);
            // -> stack: ... newobj newobj
            super.visitVarInsn(Opcodes.ILOAD, productIndex);
            // -> stack: ... newobj newobj product
            super.visitInsn(Opcodes.SWAP);
            // -> stack: ... newobj product newobj
            super.visitVarInsn(Opcodes.ALOAD, typeNameIndex);
            super.visitLabel(endScopeLabel);
            // -> stack: ... newobj product newobj className
            super.visitInsn(Opcodes.SWAP);
            // -> stack: ... newobj product className newobj
            super.visitMethodInsn(Opcodes.INVOKESTATIC, recorderClass, recorderMethod, RECORDER_SIGNATURE,
                    false);
            // -> stack: ... newobj
            return;
        }
    }

    if (opcode == Opcodes.INVOKEVIRTUAL) {
        if ("clone".equals(name) && owner.startsWith("[")) {
            super.visitMethodInsn(opcode, owner, name, signature, itf);

            int i = 0;
            while (i < owner.length()) {
                if (owner.charAt(i) != '[') {
                    break;
                }
                i++;
            }
            if (i > 1) {
                // -> stack: ... newobj
                super.visitTypeInsn(Opcodes.CHECKCAST, owner);
                // -> stack: ... arrayref
                calculateArrayLengthAndDispatch(owner.substring(i), i);
            } else {
                // -> stack: ... newobj
                super.visitInsn(Opcodes.DUP);
                // -> stack: ... newobj newobj
                super.visitTypeInsn(Opcodes.CHECKCAST, owner);
                // -> stack: ... newobj arrayref
                super.visitInsn(Opcodes.ARRAYLENGTH);
                // -> stack: ... newobj length
                super.visitInsn(Opcodes.SWAP);
                // -> stack: ... length newobj
                invokeRecordAllocation(owner.substring(i));
            }
            return;
        }
    }

    if (opcode == Opcodes.INVOKESPECIAL) {
        if (!"clone".equals(name) || !"java/lang/Object".equals(owner)) {
            if ("<init>".equals(name) && outstandingAllocs > 0) {
                // Tricky because superclass initializers mean there can be more calls
                // to <init> than calls to NEW; hence outstandingAllocs.
                --outstandingAllocs;

                // Most of the time (i.e. in bytecode generated by javac) it is the case
                // that following an <init> call the top of the stack has a reference ot
                // the newly-initialized object.  But nothing in the JVM Spec requires
                // this, so we need to play games with the stack to make an explicit
                // extra copy (and then discard it).

                dupStackElementBeforeSignatureArgs(signature);
                super.visitMethodInsn(opcode, owner, name, signature, itf);
                super.visitLdcInsn(-1);
                super.visitInsn(Opcodes.SWAP);
                invokeRecordAllocation(owner);
                super.visitInsn(Opcodes.POP);
                return;
            }
        }
    }

    super.visitMethodInsn(opcode, owner, name, signature, itf);

}

From source file:com.github.malamut2.low.AllocationMethodAdapter.java

License:Apache License

private void dupStackElementBeforeSignatureArgs(final String sig) {
    final Label beginScopeLabel = new Label();
    final Label endScopeLabel = new Label();
    super.visitLabel(beginScopeLabel);

    Type[] argTypes = Type.getArgumentTypes(sig);
    int[] args = new int[argTypes.length];

    for (int i = argTypes.length - 1; i >= 0; --i) {
        args[i] = newLocal(argTypes[i], beginScopeLabel, endScopeLabel);
        super.visitVarInsn(argTypes[i].getOpcode(Opcodes.ISTORE), args[i]);
    }/*from  w w  w.  jav  a 2  s  .  c o m*/
    super.visitInsn(Opcodes.DUP);
    for (int i = 0; i < argTypes.length; ++i) {
        int op = argTypes[i].getOpcode(Opcodes.ILOAD);
        super.visitVarInsn(op, args[i]);
        if (op == Opcodes.ALOAD) {
            super.visitInsn(Opcodes.ACONST_NULL);
            super.visitVarInsn(Opcodes.ASTORE, args[i]);
        }
    }
    super.visitLabel(endScopeLabel);
}