Example usage for org.objectweb.asm Opcodes LDC

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

Introduction

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

Prototype

int LDC

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

Click Source Link

Usage

From source file:org.jboss.byteman.agent.adapter.RuleTriggerMethodAdapter.java

License:Open Source License

@Override
public void visitLdcInsn(Object cst) {
    super.visitLdcInsn(cst);
    cfg.add(Opcodes.LDC, cst.toString());
}

From source file:pxb.android.dex2jar.optimize.B.java

License:Apache License

/**
 * <pre>/*from  w  w w .  jav a  2  s  . c om*/
 * BEFORE:
 *     LDC Ljavax/servlet/GenericServlet;.class
 *     ASTORE 1
 *     LDC "/javax/servlet/LocalStrings.properties"
 *     ASTORE 2
 *     ALOAD 1
 *     ALOAD 2
 *     INVOKEVIRTUAL Ljava/lang/Class;.getResourceAsStream (Ljava/lang/String;)Ljava/io/InputStream;
 *     ASTORE 1
 *     NEW Ljava/util/PropertyResourceBundle;
 *     DUP
 *     ALOAD 1
 *     INVOKESPECIAL Ljava/util/PropertyResourceBundle;.&lt;init> (Ljava/io/InputStream;)V
 *     ASTORE 0
 *     ALOAD 0
 *     PUTSTATIC Ljavax/servlet/GenericServlet;.lStrings : Ljava/util/ResourceBundle;
 * </pre>
 * 
 * <pre>
 * AFTER:
 *     LDC Ljavax/servlet/GenericServlet;.class
 *     LDC "/javax/servlet/LocalStrings.properties"
 *     INVOKEVIRTUAL Ljava/lang/Class;.getResourceAsStream (Ljava/lang/String;)Ljava/io/InputStream;
 *     ASTORE 1
 *     NEW Ljava/util/PropertyResourceBundle;
 *     DUP
 *     ALOAD 1
 *     INVOKESPECIAL Ljava/util/PropertyResourceBundle;.&lt;init> (Ljava/io/InputStream;)V
 *     ASTORE 0
 *     ALOAD 0
 *     PUTSTATIC Ljavax/servlet/GenericServlet;.lStrings : Ljava/util/ResourceBundle;
 * </pre>
 * 
 * @param block
 */
private void doLdc(Block block) {
    Map<Integer, LdcInsnNode> map = new HashMap<Integer, LdcInsnNode>();
    AbstractInsnNode p = block.first.getNext();
    while (p != null && p != block.last) {
        if (p.getOpcode() == Opcodes.LDC) {
            AbstractInsnNode q = p.getNext();
            if (isWrite(q)) {
                Integer var = var(q);
                if (block.out.get(var) == null || block.out.get(var) != q) {
                    map.put(var, (LdcInsnNode) p);
                    insnList.remove(q); // remove store
                    q = p.getPrevious();
                    insnList.remove(p); // remove ldc
                    p = q;
                }
            }
        } else if (isRead(p)) {
            Integer var = var(p);
            if (block.out.get(var) == null || block.out.get(var) != p) {
                LdcInsnNode ldc = map.get(var);
                if (ldc != null) {
                    AbstractInsnNode _ldc_copy = ldc.clone(null);
                    insnList.insert(p, _ldc_copy);
                    insnList.remove(p);
                    p = _ldc_copy;
                }
            }
        } else if (isWrite(p)) {
            Integer var = var(p);
            map.remove(var);
        }
        p = p.getNext();
    }
}

From source file:pxb.android.dex2jar.optimize.B.java

License:Apache License

/**
 * @param block//  w w  w.ja v  a 2  s . co m
 */
private void OptmizeFirstBlockLdc() {
    Block block = this.blocks.get(0);
    Map<Integer, LdcInsnNode> map = new HashMap<Integer, LdcInsnNode>();
    AbstractInsnNode p = block.first.getNext();
    while (p != null && p != block.last) {
        if (p.getOpcode() == Opcodes.LDC) {
            AbstractInsnNode q = p.getNext();
            if (isWrite(q)) {
                int var = var(q);
                if (block.out.get(var) == q) {
                    Map<Block, Boolean> couldReplace = new HashMap<Block, Boolean>();
                    Set<Block> replacedBlock = new HashSet<Block>();
                    replacedBlock.add(block);
                    couldReplace.put(block, true);
                    LdcInsnNode ldc = (LdcInsnNode) p;
                    boolean remove = true;
                    for (Block subBlock : block.tos) {
                        boolean x = doOptmizeFirstBlockLdc(ldc, var, subBlock, couldReplace, replacedBlock);
                        if (!x) {
                            remove = false;
                        }
                    }
                    if (remove) {
                        insnList.remove(p);
                        p = q.getNext();
                        insnList.remove(q);
                        map.put(var, ldc);
                        continue;
                    }

                }
            }
        } else if (isRead(p)) {
            int var = var(p);
            LdcInsnNode ldc = map.get(var);
            if (ldc != null) {
                AbstractInsnNode q = p.getNext();
                insnList.remove(p);
                insnList.insertBefore(q, ldc.clone(null));
                p = q;
                continue;
            }
        }
        p = p.getNext();
    }
}

From source file:vazkii.quark.base.asm.ClassTransformer.java

License:Creative Commons License

private static byte[] transformRenderItem(byte[] basicClass) {
    log("Transforming RenderItem");
    MethodSignature sig1 = new MethodSignature("renderItem", "func_180454_a", "a",
            "(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/renderer/block/model/IBakedModel;)V");
    MethodSignature sig2 = new MethodSignature("renderEffect", "func_191966_a", "a",
            "(Lnet/minecraft/client/renderer/block/model/IBakedModel;)V");

    byte[] transClass = basicClass;

    transClass = transform(transClass, Pair.of(sig1, combine((AbstractInsnNode node) -> { // Filter
        return true;
    }, (MethodNode method, AbstractInsnNode node) -> { // Action
        InsnList newInstructions = new InsnList();

        newInstructions.add(new VarInsnNode(Opcodes.ALOAD, 1));
        newInstructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, ASM_HOOKS, "setColorRuneTargetStack",
                "(Lnet/minecraft/item/ItemStack;)V"));

        method.instructions.insertBefore(node, newInstructions);
        return true;
    })));/*ww  w  .j  a  v a2s  .  com*/

    transClass = transform(transClass, Pair.of(sig2, combine((AbstractInsnNode node) -> { // Filter
        return node.getOpcode() == Opcodes.LDC && ((LdcInsnNode) node).cst.equals(-8372020);
    }, (MethodNode method, AbstractInsnNode node) -> { // Action
        InsnList newInstructions = new InsnList();

        newInstructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, ASM_HOOKS, "getRuneColor", "(I)I"));

        method.instructions.insert(node, newInstructions);
        return false;
    })));

    return transClass;
}