Search in sources :

Example 36 with LocalVariableNode

use of org.objectweb.asm.tree.LocalVariableNode in project soot by Sable.

the class AsmMethodSource method getLocal.

private Local getLocal(int idx) {
    if (idx >= maxLocals)
        throw new IllegalArgumentException("Invalid local index: " + idx);
    Integer i = idx;
    Local l = locals.get(i);
    if (l == null) {
        String name;
        if (localVars != null) {
            name = null;
            for (LocalVariableNode lvn : localVars) {
                if (lvn.index == idx) {
                    name = lvn.name;
                    break;
                }
            }
            /* normally for try-catch blocks */
            if (name == null)
                name = "l" + idx;
        } else {
            name = "l" + idx;
        }
        l = Jimple.v().newLocal(name, UnknownType.v());
        locals.put(i, l);
    }
    return l;
}
Also used : Local(soot.Local) LocalVariableNode(org.objectweb.asm.tree.LocalVariableNode)

Example 37 with LocalVariableNode

use of org.objectweb.asm.tree.LocalVariableNode in project bytecode-viewer by Konloch.

the class ASMResourceUtil method renameClassNode.

public static void renameClassNode(final String oldName, final String newName) {
    for (ClassNode c : BytecodeViewer.getLoadedClasses()) {
        for (InnerClassNode oo : c.innerClasses) {
            if (oo.innerName != null && oo.innerName.equals(oldName))
                oo.innerName = newName;
            if (oo.name.equals(oldName))
                oo.name = newName;
            if (oo.outerName != null && oo.outerName.equals(oldName))
                oo.outerName = newName;
        }
        if (c.signature != null)
            c.signature = c.signature.replace(oldName, newName);
        if (c.superName.equals(oldName))
            c.superName = newName;
        for (Object o : c.fields.toArray()) {
            FieldNode f = (FieldNode) o;
            f.desc = f.desc.replace(oldName, newName);
        }
        for (Object o : c.methods.toArray()) {
            MethodNode m = (MethodNode) o;
            if (m.localVariables != null)
                for (LocalVariableNode node : m.localVariables) node.desc = node.desc.replace(oldName, newName);
            if (m.signature != null)
                m.signature = m.signature.replace(oldName, newName);
            for (int i = 0; i < m.exceptions.size(); i++) if (m.exceptions.get(i).equals(oldName))
                m.exceptions.set(i, newName);
            for (AbstractInsnNode i : m.instructions.toArray()) {
                if (i instanceof TypeInsnNode) {
                    TypeInsnNode t = (TypeInsnNode) i;
                    if (t.desc.equals(oldName))
                        t.desc = newName;
                }
                if (i instanceof MethodInsnNode) {
                    MethodInsnNode mi = (MethodInsnNode) i;
                    if (mi.owner.equals(oldName))
                        mi.owner = newName;
                    mi.desc = mi.desc.replace(oldName, newName);
                }
                if (i instanceof FieldInsnNode) {
                    FieldInsnNode fi = (FieldInsnNode) i;
                    if (fi.owner.equals(oldName))
                        fi.owner = newName;
                    fi.desc = fi.desc.replace(oldName, newName);
                }
            }
        }
    }
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) InnerClassNode(org.objectweb.asm.tree.InnerClassNode) FieldNode(org.objectweb.asm.tree.FieldNode) MethodNode(org.objectweb.asm.tree.MethodNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) InnerClassNode(org.objectweb.asm.tree.InnerClassNode) LocalVariableNode(org.objectweb.asm.tree.LocalVariableNode)

Example 38 with LocalVariableNode

use of org.objectweb.asm.tree.LocalVariableNode in project Random-Things by lumien231.

the class ClassTransformer method patchEntityRenderer.

private byte[] patchEntityRenderer(byte[] basicClass) {
    ClassNode classNode = new ClassNode();
    ClassReader classReader = new ClassReader(basicClass);
    classReader.accept(classNode, 0);
    logger.log(Level.DEBUG, "Found EntityRenderer Class: " + classNode.name);
    MethodNode renderRainSnow = null;
    MethodNode addRainParticles = null;
    for (MethodNode mn : classNode.methods) {
        if (mn.name.equals(MCPNames.method("func_78474_d"))) {
            renderRainSnow = mn;
        } else if (mn.name.equals(MCPNames.method("func_78484_h"))) {
            addRainParticles = mn;
        }
    }
    if (renderRainSnow != null) {
        logger.log(Level.DEBUG, "- Found renderRainSnow");
        VarInsnNode insnPoint = null;
        for (int i = 0; i < renderRainSnow.instructions.size(); i++) {
            AbstractInsnNode ain = renderRainSnow.instructions.get(i);
            if (ain instanceof MethodInsnNode) {
                MethodInsnNode min = (MethodInsnNode) ain;
                if (min.name.equals(MCPNames.method("func_76738_d"))) {
                    logger.log(Level.DEBUG, "- Found canRain");
                    insnPoint = (VarInsnNode) renderRainSnow.instructions.get(i - 1);
                }
                if (min.name.equals(MCPNames.method("func_76746_c"))) {
                    logger.log(Level.DEBUG, "- Found getEnableSnow");
                    int jumpCounter = i + 1;
                    int worldIndex = 5;
                    int blockPosIndex = 21;
                    // Optifine Why :'(
                    for (LocalVariableNode lv : renderRainSnow.localVariables) {
                        if (lv.desc.equals("Lnet/minecraft/client/multiplayer/WorldClient;") || lv.desc.equals("Lnet/minecraft/world/World;")) {
                            worldIndex = lv.index;
                        } else if (lv.desc.equals("Lnet/minecraft/util/math/BlockPos$MutableBlockPos;")) {
                            blockPosIndex = lv.index;
                        }
                    }
                    AbstractInsnNode jumpNode;
                    while (!((jumpNode = renderRainSnow.instructions.get(jumpCounter)) instanceof JumpInsnNode)) {
                        jumpCounter++;
                    }
                    JumpInsnNode jin = (JumpInsnNode) jumpNode;
                    LabelNode labelNode = jin.label;
                    InsnList toInsert = new InsnList();
                    toInsert.add(new VarInsnNode(ALOAD, worldIndex));
                    toInsert.add(new VarInsnNode(ALOAD, blockPosIndex));
                    toInsert.add(new MethodInsnNode(INVOKESTATIC, asmHandler, "shouldRain", "(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)Z", false));
                    toInsert.add(new JumpInsnNode(IFEQ, labelNode));
                    renderRainSnow.instructions.insertBefore(insnPoint, toInsert);
                    i += 4;
                }
            }
        }
    }
    if (addRainParticles != null) {
        logger.log(Level.DEBUG, "- Found addRainParticles");
        for (int i = 0; i < addRainParticles.instructions.size(); i++) {
            AbstractInsnNode ain = addRainParticles.instructions.get(i);
            if (ain instanceof JumpInsnNode) {
                JumpInsnNode jin = (JumpInsnNode) ain;
                if (jin.getOpcode() == Opcodes.IF_ICMPGT) {
                    LabelNode jumpTarget = jin.label;
                    InsnList toInsert = new InsnList();
                    toInsert.add(new VarInsnNode(ALOAD, 3));
                    toInsert.add(new VarInsnNode(ALOAD, 15));
                    toInsert.add(new MethodInsnNode(INVOKESTATIC, asmHandler, "shouldRain", "(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)Z", false));
                    toInsert.add(new JumpInsnNode(IFEQ, jumpTarget));
                    addRainParticles.instructions.insert(jin, toInsert);
                    break;
                }
            }
        }
    }
    CustomClassWriter writer = new CustomClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
    classNode.accept(writer);
    return writer.toByteArray();
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) ClassNode(org.objectweb.asm.tree.ClassNode) MethodNode(org.objectweb.asm.tree.MethodNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) ClassReader(org.objectweb.asm.ClassReader) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) InsnList(org.objectweb.asm.tree.InsnList) LocalVariableNode(org.objectweb.asm.tree.LocalVariableNode)

Example 39 with LocalVariableNode

use of org.objectweb.asm.tree.LocalVariableNode in project cassandra by apache.

the class MonitorMethodTransformer method reset.

void reset(Label start, Label end) {
    instructions.clear();
    tryCatchBlocks.clear();
    if (visibleLocalVariableAnnotations != null)
        visibleLocalVariableAnnotations.clear();
    if (invisibleLocalVariableAnnotations != null)
        invisibleLocalVariableAnnotations.clear();
    Type[] args = Type.getArgumentTypes(desc);
    // remove all local variables that aren't parameters and the `this` parameter
    maxLocals = args.length == 1 && Type.VOID_TYPE.equals(args[0]) ? 0 : args.length;
    if (isInstanceMethod)
        ++maxLocals;
    // sort our local variables and remove those that aren't parameters
    localVariables.sort(Comparator.comparingInt(c -> c.index));
    ListIterator<LocalVariableNode> it = localVariables.listIterator();
    while (it.hasNext()) {
        LocalVariableNode cur = it.next();
        if (cur.index >= maxLocals) {
            it.remove();
        } else {
            it.set(new LocalVariableNode(cur.name, cur.desc, cur.signature, getLabelNode(start), getLabelNode(end), cur.index));
            switch(cur.desc.charAt(0)) {
                case 'J':
                case 'D':
                    // doubles and longs take two local variable positions
                    ++maxLocals;
            }
        }
    }
    // save the number of pure-parameters for use elsewhere
    maxLocalParams = maxLocals;
}
Also used : MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) Opcodes(org.objectweb.asm.Opcodes) ListIterator(java.util.ListIterator) IntInsnNode(org.objectweb.asm.tree.IntInsnNode) Label(org.objectweb.asm.Label) Type(org.objectweb.asm.Type) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) MethodNode(org.objectweb.asm.tree.MethodNode) LocalVariableNode(org.objectweb.asm.tree.LocalVariableNode) TryCatchBlockNode(org.objectweb.asm.tree.TryCatchBlockNode) FrameNode(org.objectweb.asm.tree.FrameNode) Comparator(java.util.Comparator) InsnNode(org.objectweb.asm.tree.InsnNode) MONITOR(org.apache.cassandra.simulator.asm.TransformationKind.MONITOR) Type(org.objectweb.asm.Type) LocalVariableNode(org.objectweb.asm.tree.LocalVariableNode)

Example 40 with LocalVariableNode

use of org.objectweb.asm.tree.LocalVariableNode in project pinpoint by naver.

the class ASMMethodVariables method addLocalVariable.

int addLocalVariable(final String name, final String desc, final LabelNode start, final LabelNode end) {
    int index = this.nextLocals;
    this.nextLocals += 1;
    final LocalVariableNode node = new LocalVariableNode(name, desc, null, start, end, index);
    this.methodNode.localVariables.add(node);
    return index;
}
Also used : LocalVariableNode(org.objectweb.asm.tree.LocalVariableNode)

Aggregations

LocalVariableNode (org.objectweb.asm.tree.LocalVariableNode)41 Label (org.objectweb.asm.Label)11 MethodNode (org.objectweb.asm.tree.MethodNode)9 Type (org.objectweb.asm.Type)8 LabelNode (org.objectweb.asm.tree.LabelNode)8 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)8 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)6 IincInsnNode (org.objectweb.asm.tree.IincInsnNode)6 GeneratorAdapter (org.objectweb.asm.commons.GeneratorAdapter)5 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)5 InsnList (org.objectweb.asm.tree.InsnList)5 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)5 ClassNode (org.objectweb.asm.tree.ClassNode)4 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3 FieldNode (org.objectweb.asm.tree.FieldNode)3 FrameNode (org.objectweb.asm.tree.FrameNode)3 TryCatchBlockNode (org.objectweb.asm.tree.TryCatchBlockNode)3 NeverNullArgAnalyzerAdapter (edu.columbia.cs.psl.phosphor.instrumenter.analyzer.NeverNullArgAnalyzerAdapter)2 ControlTaintTagStack (edu.columbia.cs.psl.phosphor.struct.ControlTaintTagStack)2