List of usage examples for org.objectweb.asm.tree InsnList size
int size
To view the source code for org.objectweb.asm.tree InsnList size.
Click Source Link
From source file:ht.misc.injectsocks.InjectSockstTransformerImpl.java
License:Apache License
public byte[] inject(byte[] classfileBuffer) { try {// w ww . j a va 2 s.c o m ClassReader cr = new ClassReader(classfileBuffer); ClassNode cn = new ClassNode(); cr.accept(cn, 0); ArrayList<AbstractInsnNode> injectPos = new ArrayList<AbstractInsnNode>(); @SuppressWarnings("unchecked") List<MethodNode> methods = (List<MethodNode>) cn.methods; for (int i = 0; i < methods.size(); ++i) { MethodNode method = methods.get(i); InsnList instructions = method.instructions; if (instructions.size() <= 0) continue; //System.out.println("Method: "+method.name+" "); for (int j = 0; j < instructions.size(); ++j) { AbstractInsnNode insn = (AbstractInsnNode) instructions.get(j); //System.out.println("\tInsn: opc="+OpcodeUtil.getOpcode(insn.getOpcode())+", type="+insn.getType()); if (insn.getType() == AbstractInsnNode.METHOD_INSN) { MethodInsnNode min = (MethodInsnNode) insn; //System.out.printf("\t\towner=%s, name=%s, desc=%s\n", min.owner, min.name, min.desc); if (min.owner.equals("java/net/Socket") && min.name.equals("<init>") && min.desc.equals("()V")) { min.desc = "(Ljava/net/Proxy;)V"; injectPos.add(min); } } } for (int k = 0; k < injectPos.size(); k++) { AbstractInsnNode pos = injectPos.get(k); MethodInsnNode newMin = new MethodInsnNode(Opcodes.INVOKESTATIC, "ht/misc/injectsocks/ProxyManager", "getProxy", "()Ljava/net/Proxy;", false); instructions.insertBefore(pos, newMin); } } ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); cn.accept(cw); byte[] injectedClassfileBuffer = cw.toByteArray(); System.out.printf("INFO: classfileBuffer.legnth=%d, injectedClassfileBuffer.length=%d\n", classfileBuffer.length, injectedClassfileBuffer.length); return injectedClassfileBuffer; } catch (Throwable e) { e.printStackTrace(); return classfileBuffer; } }
From source file:ht.misc.injectsocks.InjectSockstTransformerImpl.java
License:Apache License
public void printClassByteCode(byte code[]) { ClassReader cr = new ClassReader(code); ClassNode cn = new ClassNode(); cr.accept(cn, 0);/*from ww w . jav a 2s.co m*/ @SuppressWarnings("unchecked") List<MethodNode> methods = (List<MethodNode>) cn.methods; for (int i = 0; i < methods.size(); ++i) { MethodNode method = methods.get(i); InsnList instructions = method.instructions; if (instructions.size() <= 0) continue; System.out.println("Method: " + method.name + " "); for (int j = 0; j < instructions.size(); ++j) { AbstractInsnNode insn = (AbstractInsnNode) instructions.get(j); System.out.println( "\tInsn: opc=" + OpcodeUtil.getOpcode(insn.getOpcode()) + ", type=" + insn.getType()); if (insn.getType() == AbstractInsnNode.METHOD_INSN) { MethodInsnNode min = (MethodInsnNode) insn; System.out.printf("\t\towner=%s, name=%s, desc=%s\n", min.owner, min.name, min.desc); } } } }
From source file:ivorius.ivtoolkit.asm.IvNodeFinder.java
License:Apache License
public static AbstractInsnNode findNode(IvSingleNodeMatcher matcher, InsnList insnList) { for (int i = 0; i < insnList.size(); i++) { AbstractInsnNode node = insnList.get(i); if (matcher.matchNode(node)) { return node; }//from w ww. j a va 2 s. c o m } return null; }
From source file:ivorius.ivtoolkit.asm.IvNodeFinder.java
License:Apache License
public static AbstractInsnNode findNodeList(IvMultiNodeMatcher matcher, InsnList insnList) { for (int i = 0; i < insnList.size(); i++) { AbstractInsnNode node = insnList.get(i); if (matcher.matchFromNodeInList(insnList, node)) { return node; }//from ww w.j a va2s.c o m } return null; }
From source file:ivorius.ivtoolkit.asm.IvNodeFinder.java
License:Apache License
public static List<AbstractInsnNode> findNodes(IvSingleNodeMatcher matcher, InsnList insnList) { List<AbstractInsnNode> nodes = new ArrayList<AbstractInsnNode>(); for (int i = 0; i < insnList.size(); i++) { AbstractInsnNode node = insnList.get(i); if (matcher.matchNode(node)) { nodes.add(node);/*from w w w. ja v a 2 s . co m*/ } } return nodes; }
From source file:ivorius.ivtoolkit.asm.IvNodeFinder.java
License:Apache License
public static List<AbstractInsnNode> findNodeLists(IvMultiNodeMatcher matcher, InsnList insnList) { List<AbstractInsnNode> nodes = new ArrayList<AbstractInsnNode>(); for (int i = 0; i < insnList.size(); i++) { AbstractInsnNode node = insnList.get(i); if (matcher.matchFromNodeInList(insnList, node)) { nodes.add(node);/*ww w. j av a2 s.c o m*/ } } return nodes; }
From source file:jaspex.speculation.newspec.FlowFrame.java
License:Open Source License
static void printCode(MethodNode mn, List<? extends Frame<?>> frames, Collection<FlowFrame> highlight, FlowFrame specialHighlight) {// w w w . j a v a 2s . c o m if (!Log.isTraceEnabled()) return; Textifier textifier = new Textifier(); TraceMethodVisitor tmv = new TraceMethodVisitor(textifier); mn.accept(tmv); highlight = highlight != null ? highlight : new ArrayList<FlowFrame>(); List<String> instructions = listGenericCast(textifier.getText()); InsnList il = mn.instructions; int offset = mn.tryCatchBlocks.size(); for (int i = 0; i < instructions.size(); i++) { int pos = i - offset; Frame<?> f = pos >= 0 && pos < frames.size() ? frames.get(pos) : null; String insn = pos < il.size() && pos >= 0 ? il.get(pos).toString().replace("org.objectweb.asm.tree.", "") : null; String highlightColor = specialHighlight != null && specialHighlight.equals(f) ? "45" : highlight.contains(f) ? "41" : "32"; Log.trace(pos + instructions.get(i).replace("\n", "") + " " + (f != null ? color(f.toString(), highlightColor) : "") + " (" + insn + ")"); } }
From source file:kilim.analysis.BasicBlock.java
License:Open Source License
@SuppressWarnings("unchecked") static ArrayList<BasicBlock> dupCopyContents(boolean deepCopy, BasicBlock targetBB, BasicBlock returnToBB, HashMap<BasicBlock, BasicBlock> bbCopyMap, HashMap<Label, LabelNode> labelCopyMap) throws KilimException { ArrayList<BasicBlock> newBBs = new ArrayList<BasicBlock>(targetBB.getSubBlocks().size()); for (BasicBlock orig : targetBB.getSubBlocks()) { BasicBlock dup = bbCopyMap.get(orig); dup.flags = orig.flags;//from w ww. j ava2 s . c o m dup.caughtExceptionType = orig.caughtExceptionType; dup.startPos = orig.startPos; dup.endPos = orig.endPos; dup.flow = orig.flow; dup.numPredecessors = orig.numPredecessors; dup.startFrame = null; dup.usage = orig.usage.copy(); dup.handlers = orig.handlers; if (orig.follower != null) { dup.follower = bbCopyMap.get(orig.follower); if (dup.follower == null) { assert dup.lastInstruction() == RET; } } dup.successors = new ArrayList<BasicBlock>(orig.successors.size()); if (orig.lastInstruction() == RET) { dup.addSuccessor(returnToBB); } else { for (BasicBlock s : orig.successors) { BasicBlock b = bbCopyMap.get(s); dup.addSuccessor(b); } } if (deepCopy) { MethodFlow flow = targetBB.flow; InsnList instructions = flow.instructions; // copy instructions dup.startLabel = labelCopyMap.get(orig.startLabel).getLabel(); dup.startPos = instructions.size(); dup.endPos = dup.startPos + (orig.endPos - orig.startPos); // Note: last instruction (@endPos) isn't copied in the loop. // If it has labels, a new instruction is generated; either // way the last instruction is appended separately. int newPos = instructions.size(); int end = orig.endPos; // create new labels and instructions for (int i = orig.startPos; i <= end; i++, newPos++) { Label l = flow.getLabelAt(i); if (l != null) { l = labelCopyMap.get(l).getLabel(); assert l != null; flow.setLabel(newPos, l); } if (i != end) { // last insn gets special treatment instructions.add(instructions.get(i)); } } AbstractInsnNode lastInsn = (AbstractInsnNode) instructions.get(orig.endPos); LabelNode dupLabel; int opcode = lastInsn.getOpcode(); if (lastInsn instanceof JumpInsnNode) { JumpInsnNode jin = (JumpInsnNode) lastInsn; if (lastInsn.getOpcode() != JSR) { dupLabel = labelCopyMap.get(jin.label); assert dupLabel != null; lastInsn = new JumpInsnNode(lastInsn.getOpcode(), dupLabel); } } else if (opcode == TABLESWITCH) { TableSwitchInsnNode tsin = (TableSwitchInsnNode) lastInsn; LabelNode[] labels = new LabelNode[tsin.labels.size()]; for (int i = 0; i < labels.length; i++) { dupLabel = labelCopyMap.get(tsin.labels.get(i)); assert dupLabel != null; labels[i] = dupLabel; } dupLabel = labelCopyMap.get(tsin.dflt); assert dupLabel != null; lastInsn = new TableSwitchInsnNode(tsin.min, tsin.max, dupLabel, labels); } else if (opcode == LOOKUPSWITCH) { LookupSwitchInsnNode lsin = (LookupSwitchInsnNode) lastInsn; LabelNode[] labels = new LabelNode[lsin.labels.size()]; for (int i = 0; i < labels.length; i++) { dupLabel = labelCopyMap.get(lsin.labels.get(i)); assert dupLabel != null; labels[i] = dupLabel; } dupLabel = labelCopyMap.get(lsin.dflt); assert dupLabel != null; int[] keys = new int[lsin.keys.size()]; for (int i = 0; i < keys.length; i++) { keys[i] = (Integer) lsin.keys.get(i); } lastInsn = new LookupSwitchInsnNode(dupLabel, keys, labels); } instructions.add(lastInsn); // new handlers dup.handlers = new ArrayList<Handler>(orig.handlers.size()); if (orig.handlers.size() > 0) { for (Handler oh : orig.handlers) { Handler h = new Handler(dup.startPos + (oh.from - orig.startPos), dup.endPos + (oh.to - orig.endPos), oh.type, oh.catchBB); dup.handlers.add(h); } } } newBBs.add(dup); } return newBBs; }
From source file:me.themallard.bitmmo.api.analysis.util.pattern.Pattern.java
License:Open Source License
public int getOffset(InsnList list) { for (int i = 0; i < list.size() - elements.size(); i++) { boolean x = true; for (int j = 0; j < elements.size(); j++) { if (!elements.get(j).matches(list.get(i + j))) { x = false;/*from ww w.j av a2 s . com*/ break; } } if (x) return i; } return -1; }
From source file:net.epoxide.surge.asm.InstructionComparator.java
License:Creative Commons License
public static InsnList getImportantList(InsnList list) { if (list.size() == 0) return list; final HashMap<LabelNode, LabelNode> labels = new HashMap<LabelNode, LabelNode>(); for (AbstractInsnNode insn = list.getFirst(); insn != null; insn = insn.getNext()) if (insn instanceof LabelNode) labels.put((LabelNode) insn, (LabelNode) insn); final InsnList importantNodeList = new InsnList(); for (AbstractInsnNode insn = list.getFirst(); insn != null; insn = insn.getNext()) { if (insn instanceof LabelNode || insn instanceof LineNumberNode) continue; importantNodeList.add(insn.clone(labels)); }/*from w ww.j a v a 2 s . c om*/ return importantNodeList; }