Search in sources :

Example 81 with LabelNode

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

the class ClassTransformer method patchInventoryPlayer.

private byte[] patchInventoryPlayer(byte[] basicClass) {
    ClassNode classNode = new ClassNode();
    ClassReader classReader = new ClassReader(basicClass);
    classReader.accept(classNode, 0);
    logger.log(Level.DEBUG, "Found InventoryPlayer Class: " + classNode.name);
    MethodNode dropAllItems = null;
    for (MethodNode mn : classNode.methods) {
        if (mn.name.equals(MCPNames.method("func_70436_m"))) {
            dropAllItems = mn;
            break;
        }
    }
    if (dropAllItems != null) {
        logger.log(Level.DEBUG, " - Found dropAllItems (1/2)");
        for (int i = 0; i < dropAllItems.instructions.size(); i++) {
            AbstractInsnNode ain = dropAllItems.instructions.get(i);
            if (ain instanceof JumpInsnNode) {
                JumpInsnNode jin = (JumpInsnNode) ain;
                if (jin.getOpcode() == Opcodes.IFNE) {
                    AbstractInsnNode before = dropAllItems.instructions.get(i - 1);
                    if (before instanceof MethodInsnNode && ((MethodInsnNode) before).name.equals(MCPNames.method("func_190926_b"))) {
                        LabelNode l0 = jin.label;
                        InsnList toInsert = new InsnList();
                        toInsert.add(new VarInsnNode(ALOAD, 0));
                        toInsert.add(new VarInsnNode(ILOAD, 3));
                        toInsert.add(new VarInsnNode(ALOAD, 4));
                        toInsert.add(new MethodInsnNode(Opcodes.INVOKESTATIC, asmHandler, "shouldPlayerDrop", "(Lnet/minecraft/entity/player/InventoryPlayer;ILnet/minecraft/item/ItemStack;)Z", false));
                        toInsert.add(new JumpInsnNode(IFEQ, l0));
                        dropAllItems.instructions.insert(jin, toInsert);
                        i += 5;
                        logger.log(Level.DEBUG, " - Patched dropAllItems (2/2)");
                    }
                }
            }
        }
    }
    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) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) InsnList(org.objectweb.asm.tree.InsnList) VarInsnNode(org.objectweb.asm.tree.VarInsnNode)

Example 82 with LabelNode

use of org.objectweb.asm.tree.LabelNode in project CodeChickenLib by Chicken-Bones.

the class ASMBlock method mergeLabels.

/**
 * Pulls all common labels from other into this
 * @return this
 */
public ASMBlock mergeLabels(ASMBlock other) {
    if (labels.isEmpty() || other.labels.isEmpty())
        return this;
    // common labels, give them our nodes
    HashMap<LabelNode, LabelNode> labelMap = list.identityLabelMap();
    for (Entry<String, LabelNode> entry : other.labels.entrySet()) {
        LabelNode old = labels.get(entry.getKey());
        if (old != null)
            labelMap.put(old, entry.getValue());
    }
    HashSet<LabelNode> usedLabels = new HashSet<LabelNode>();
    for (AbstractInsnNode insn = other.list.list.getFirst(); insn != null; insn = insn.getNext()) if (insn.getType() == LABEL)
        usedLabels.add((LabelNode) insn);
    replaceLabels(labelMap, usedLabels);
    return this;
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode)

Example 83 with LabelNode

use of org.objectweb.asm.tree.LabelNode in project spring-loaded by spring-projects.

the class TypeDiffComputer method sameLookupSwitchInsn.

@SuppressWarnings("unchecked")
private static boolean sameLookupSwitchInsn(AbstractInsnNode o, AbstractInsnNode n) {
    if (!(n instanceof LookupSwitchInsnNode)) {
        return false;
    }
    LookupSwitchInsnNode lsio = (LookupSwitchInsnNode) o;
    LookupSwitchInsnNode lsin = (LookupSwitchInsnNode) n;
    if (sameLabels(lsio.dflt, lsin.dflt)) {
        return false;
    }
    List<Integer> keyso = lsio.keys;
    List<Integer> keysn = lsin.keys;
    if (keyso.size() != keysn.size()) {
        return false;
    }
    for (int i = 0, max = keyso.size(); i < max; i++) {
        if (keyso.get(i) != keysn.get(i)) {
            return false;
        }
    }
    List<LabelNode> labelso = lsio.labels;
    List<LabelNode> labelsn = lsin.labels;
    if (labelso.size() != labelsn.size()) {
        return false;
    }
    for (int i = 0, max = labelso.size(); i < max; i++) {
        if (!sameLabelNode(labelso.get(i), labelsn.get(i))) {
            return false;
        }
    }
    return true;
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) LookupSwitchInsnNode(org.objectweb.asm.tree.LookupSwitchInsnNode)

Example 84 with LabelNode

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

the class ASMMethodVariables method initLocalVariables.

// new method only.
public void initLocalVariables(final InsnList instructions) {
    // find enter & exit instruction.
    final LabelNode variableStartLabelNode = new LabelNode();
    final LabelNode variableEndLabelNode = new LabelNode();
    if (instructions.getFirst() != null) {
        instructions.insertBefore(instructions.getFirst(), variableStartLabelNode);
    } else {
        instructions.insert(variableStartLabelNode);
    }
    instructions.insert(instructions.getLast(), variableEndLabelNode);
    if (!isStatic()) {
        addLocalVariable("this", Type.getObjectType(this.declaringClassInternalName).getDescriptor(), variableStartLabelNode, variableEndLabelNode);
    }
    for (Type type : this.argumentTypes) {
        addLocalVariable(JavaAssistUtils.javaClassNameToVariableName(type.getClassName()), type.getDescriptor(), variableStartLabelNode, variableEndLabelNode);
    }
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) InterceptorType(com.navercorp.pinpoint.profiler.instrument.interceptor.InterceptorType) Type(org.objectweb.asm.Type)

Example 85 with LabelNode

use of org.objectweb.asm.tree.LabelNode in project maple-ir by LLVM-but-worse.

the class LookupSwitchInsnNodeSerializer method deserialize.

@Override
public LookupSwitchInsnNode deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject jsonObject = (JsonObject) json;
    LabelNode dflt = context.deserialize(jsonObject.get("dflt"), LabelNode.class);
    List<Integer> keysList = context.deserialize(jsonObject.get("keys"), List.class);
    List<LabelNode> labelsList = context.deserialize(jsonObject.get("labels"), List.class);
    int[] keys = new int[keysList.size()];
    for (int i = 0; i < keys.length; i++) {
        keys[i] = keysList.get(i);
    }
    LabelNode[] labels = new LabelNode[labelsList.size()];
    for (int i = 0; i < labels.length; i++) {
        labels[i] = labelsList.get(i);
    }
    return new LookupSwitchInsnNode(dflt, keys, labels);
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) JsonObject(com.google.gson.JsonObject) LookupSwitchInsnNode(org.objectweb.asm.tree.LookupSwitchInsnNode)

Aggregations

LabelNode (org.objectweb.asm.tree.LabelNode)89 JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)37 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)32 Label (org.objectweb.asm.Label)28 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)23 InsnList (org.objectweb.asm.tree.InsnList)22 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)21 InsnNode (org.objectweb.asm.tree.InsnNode)20 MethodNode (org.objectweb.asm.tree.MethodNode)19 LdcInsnNode (org.objectweb.asm.tree.LdcInsnNode)17 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)16 TypeInsnNode (org.objectweb.asm.tree.TypeInsnNode)15 ClassNode (org.objectweb.asm.tree.ClassNode)14 ClassReader (org.objectweb.asm.ClassReader)12 LineNumberNode (org.objectweb.asm.tree.LineNumberNode)10 Type (org.objectweb.asm.Type)8 LocalVariableNode (org.objectweb.asm.tree.LocalVariableNode)8 LinkedList (java.util.LinkedList)6 ArrayList (java.util.ArrayList)5 LookupSwitchInsnNode (org.objectweb.asm.tree.LookupSwitchInsnNode)5