List of usage examples for org.objectweb.asm.tree AbstractInsnNode opcode
int opcode
To view the source code for org.objectweb.asm.tree AbstractInsnNode opcode.
Click Source Link
From source file:me.themallard.bitmmo.api.analysis.util.pattern.element.InstructionElement.java
License:Open Source License
@Override public boolean matches(AbstractInsnNode ain) { return this.opcode == ain.opcode(); }
From source file:me.themallard.bitmmo.api.analysis.util.pattern.element.LdcElement.java
License:Open Source License
@Override public boolean matches(AbstractInsnNode ain) { if (!(ain instanceof LdcInsnNode)) return false; if (insn.opcode() == ain.opcode() && insn.cst == null) return true; if (insn.opcode() != ain.opcode()) return false; LdcInsnNode min = (LdcInsnNode) ain; if (!contains) { if (insn.cst != null && !min.cst.equals(insn.cst)) return false; } else {//from w w w.j a v a2 s .co m if (insn.cst != null && !min.cst.toString().contains(insn.cst.toString())) return false; } return true; }
From source file:me.themallard.bitmmo.api.analysis.util.pattern.element.MethodElement.java
License:Open Source License
@Override public boolean matches(AbstractInsnNode ain) { if (!(ain instanceof MethodInsnNode)) return false; if (insn.opcode() == ain.opcode() && insn.name == null && insn.owner == null) return true; if (insn.opcode() != ain.opcode()) return false; MethodInsnNode min = (MethodInsnNode) ain; if (insn.name != null && !min.name.equals(insn.name)) return false; if (insn.owner != null && !min.name.equals(insn.owner)) return false; if (insn.desc != null && !min.name.equals(insn.desc)) return false; return true;//from w w w . j a v a 2 s.c om }
From source file:the.bytecode.club.bytecodeviewer.decompilers.bytecode.InstructionPattern.java
License:Open Source License
/** * Translate a single {@link AbstractInsnNode} to an * {@link InstructionFilter}./*from www.j a v a2 s . co m*/ * * @param ain * Instruction to convert. * @return A filter an an equivilent to the inputted instruction. */ public static InstructionFilter translate(AbstractInsnNode ain) { if (ain instanceof LdcInsnNode) { return new LdcInstructionFilter(((LdcInsnNode) ain).cst); } else if (ain instanceof TypeInsnNode) { return new TypeInstructionFilter(ain.opcode(), ((TypeInsnNode) ain).desc); } else if (ain instanceof FieldInsnNode) { return new FieldInstructionFilter(ain.opcode(), ((FieldInsnNode) ain).owner, ((FieldInsnNode) ain).name, ((FieldInsnNode) ain).desc); } else if (ain instanceof MethodInsnNode) { return new MethodInstructionFilter(ain.opcode(), ((MethodInsnNode) ain).owner, ((MethodInsnNode) ain).name, ((MethodInsnNode) ain).desc); } else if (ain instanceof VarInsnNode) { return new VarInstructionFilter(ain.opcode(), ((VarInsnNode) ain).var); } else if (ain instanceof InsnNode) { return new InsnInstructionFilter(ain.opcode()); } else if (ain instanceof IincInsnNode) { return new IincInstructionFilter(((IincInsnNode) ain).incr, ((IincInsnNode) ain).var); } else if (ain instanceof JumpInsnNode) { return new JumpInstructionFilter(ain.opcode()); } else if (ain instanceof LabelNode) { return InstructionFilter.ACCEPT_ALL; // TODO: Cache labels and // check. // TODO: That's a // fucking stupid idea. } else if (ain instanceof MultiANewArrayInsnNode) { return new MultiANewArrayInstructionFilter(((MultiANewArrayInsnNode) ain).desc, ((MultiANewArrayInsnNode) ain).dims); } else { return InstructionFilter.ACCEPT_ALL; } }
From source file:the.bytecode.club.bytecodeviewer.decompilers.bytecode.InstructionPrinter.java
License:Open Source License
/** * Creates the print//w w w. ja va 2 s . co m * * @return The print as an ArrayList */ public ArrayList<String> createPrint() { ArrayList<String> info = new ArrayList<String>(); ListIterator<?> it = mNode.instructions.iterator(); boolean firstLabel = false; while (it.hasNext()) { AbstractInsnNode ain = (AbstractInsnNode) it.next(); String line = ""; if (ain instanceof VarInsnNode) { line = printVarInsnNode((VarInsnNode) ain, it); } else if (ain instanceof IntInsnNode) { line = printIntInsnNode((IntInsnNode) ain, it); } else if (ain instanceof FieldInsnNode) { line = printFieldInsnNode((FieldInsnNode) ain, it); } else if (ain instanceof MethodInsnNode) { line = printMethodInsnNode((MethodInsnNode) ain, it); } else if (ain instanceof LdcInsnNode) { line = printLdcInsnNode((LdcInsnNode) ain, it); } else if (ain instanceof InsnNode) { line = printInsnNode((InsnNode) ain, it); } else if (ain instanceof JumpInsnNode) { line = printJumpInsnNode((JumpInsnNode) ain, it); } else if (ain instanceof LineNumberNode) { line = printLineNumberNode((LineNumberNode) ain, it); } else if (ain instanceof LabelNode) { if (firstLabel && Decompiler.BYTECODE.getSettings() .isSelected(ClassNodeDecompiler.Settings.APPEND_BRACKETS_TO_LABELS)) info.add("}"); line = printLabelnode((LabelNode) ain); if (Decompiler.BYTECODE.getSettings() .isSelected(ClassNodeDecompiler.Settings.APPEND_BRACKETS_TO_LABELS)) { if (!firstLabel) firstLabel = true; line += " {"; } } else if (ain instanceof TypeInsnNode) { line = printTypeInsnNode((TypeInsnNode) ain); } else if (ain instanceof FrameNode) { line = ""; } else if (ain instanceof IincInsnNode) { line = printIincInsnNode((IincInsnNode) ain); } else if (ain instanceof TableSwitchInsnNode) { line = printTableSwitchInsnNode((TableSwitchInsnNode) ain); } else if (ain instanceof LookupSwitchInsnNode) { line = printLookupSwitchInsnNode((LookupSwitchInsnNode) ain); } else if (ain instanceof InvokeDynamicInsnNode) { line = printInvokeDynamicInsNode((InvokeDynamicInsnNode) ain); } else { line += "UNADDED OPCODE: " + nameOpcode(ain.opcode()) + " " + ain.toString(); } if (!line.equals("")) { if (match) if (matchedInsns.contains(ain)) line = " -> " + line; info.add(line); } } if (firstLabel && Decompiler.BYTECODE.getSettings() .isSelected(ClassNodeDecompiler.Settings.APPEND_BRACKETS_TO_LABELS)) info.add("}"); return info; }
From source file:the.bytecode.club.bytecodeviewer.plugin.preinstalled.MaliciousCodeScanner.java
License:Open Source License
@Override public void execute(ArrayList<ClassNode> classNodeList) { PluginConsole frame = new PluginConsole("Malicious Code Scanner"); StringBuilder sb = new StringBuilder(); for (ClassNode classNode : classNodeList) { for (Object o : classNode.fields.toArray()) { FieldNode f = (FieldNode) o; Object v = f.value;/* www .j a va 2 s . c o m*/ if (v instanceof String) { String s = (String) v; if ((LWW && s.contains("www.")) || (LHT && s.contains("http://")) || (LHS && s.contains("https://")) || (ORE && s.contains("java/lang/Runtime")) || (ORE && s.contains("java.lang.Runtime")) || (ROB && s.contains("java.awt.Robot")) || (ROB && s.contains("java/awt/Robot")) || (LIP && s.matches("\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b"))) sb.append("Found LDC \"" + s + "\" at field " + classNode.name + "." + f.name + "(" + f.desc + ")" + BytecodeViewer.nl); } if (v instanceof String[]) { for (int i = 0; i < ((String[]) v).length; i++) { String s = ((String[]) v)[i]; if ((LWW && s.contains("www.")) || (LHT && s.contains("http://")) || (LHS && s.contains("https://")) || (ORE && s.contains("java/lang/Runtime")) || (ORE && s.contains("java.lang.Runtime")) || (ROB && s.contains("java.awt.Robot")) || (ROB && s.contains("java/awt/Robot")) || (LIP && s.matches("\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b"))) sb.append("Found LDC \"" + s + "\" at field " + classNode.name + "." + f.name + "(" + f.desc + ")" + BytecodeViewer.nl); } } } boolean prevInsn_aconst_null = false; for (Object o : classNode.methods.toArray()) { MethodNode m = (MethodNode) o; InsnList iList = m.instructions; for (AbstractInsnNode a : iList.toArray()) { if (a instanceof MethodInsnNode) { final MethodInsnNode min = (MethodInsnNode) a; if ((ORE && min.owner.startsWith("java/lang/reflect")) || (ONE && min.owner.startsWith("java/net")) || (ORU && min.owner.equals("java/lang/Runtime")) || (ROB && min.owner.equals("java/awt/Robot")) || (OIO && min.owner.startsWith("java/io"))) { sb.append("Found Method call to " + min.owner + "." + min.name + "(" + min.desc + ") at " + classNode.name + "." + m.name + "(" + m.desc + ")" + BytecodeViewer.nl); } } if (a instanceof LdcInsnNode) { if (((LdcInsnNode) a).cst instanceof String) { final String s = (String) ((LdcInsnNode) a).cst; if ((LWW && s.contains("www.")) || (LHT && s.contains("http://")) || (LHS && s.contains("https://")) || (ORE && s.contains("java/lang/Runtime")) || (ORE && s.contains("java.lang.Runtime")) || (ROB && s.contains("java.awt.Robot")) || (ROB && s.contains("java/awt/Robot")) || (LIP && s.matches("\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b"))) { sb.append("Found LDC \"" + s + "\" at method " + classNode.name + "." + m.name + "(" + m.desc + ")" + BytecodeViewer.nl); } } } // Check if the security manager is getting set to null if ((a instanceof InsnNode) && (a.opcode() == Opcodes.ACONST_NULL)) { prevInsn_aconst_null = true; } else if ((a instanceof MethodInsnNode) && (a.opcode() == Opcodes.INVOKESTATIC)) { final String owner = ((MethodInsnNode) a).owner; final String name = ((MethodInsnNode) a).name; if ((NSM && prevInsn_aconst_null && owner.equals("java/lang/System") && name.equals("setSecurityManager"))) { sb.append("Found Security Manager set to null at method " + classNode.name + "." + m.name + "(" + m.desc + ")" + BytecodeViewer.nl); prevInsn_aconst_null = false; } } else { prevInsn_aconst_null = false; } } } } frame.appendText(sb.toString()); frame.setVisible(true); }
From source file:the.bytecode.club.bytecodeviewer.searching.FieldCallSearch.java
License:Open Source License
@Override public void search(final ClassNode node, final SearchResultNotifier srn, boolean exact) { final Iterator<MethodNode> methods = node.methods.iterator(); String owner = mOwner.getText(); if (owner.isEmpty()) { owner = null;//w w w . j a va2 s. com } String name = mName.getText(); if (name.isEmpty()) { name = null; } String desc = mDesc.getText(); if (desc.isEmpty()) { desc = null; } while (methods.hasNext()) { final MethodNode method = methods.next(); final InsnList insnlist = method.instructions; final ListIterator<AbstractInsnNode> instructions = insnlist.iterator(); while (instructions.hasNext()) { final AbstractInsnNode insnNode = instructions.next(); if (insnNode instanceof FieldInsnNode) { final FieldInsnNode min = (FieldInsnNode) insnNode; if (name == null && owner == null && desc == null) continue; if (exact) { if (name != null && !name.equals(min.name)) { continue; } if (owner != null && !owner.equals(min.owner)) { continue; } if (desc != null && !desc.equals(min.desc)) { continue; } String desc2 = method.desc; try { desc2 = Type.getType(method.desc).toString(); if (desc2 == null || desc2.equals("null")) desc2 = method.desc; } catch (java.lang.ArrayIndexOutOfBoundsException e) { } srn.notifyOfResult(node.name + "." + method.name + desc2 + " > " + OpcodeInfo.OPCODES.get(insnNode.opcode()).toLowerCase()); } else { if (name != null && !min.name.contains(name)) { continue; } if (owner != null && !min.owner.contains(owner)) { continue; } if (desc != null && !min.desc.contains(desc)) { continue; } String desc2 = method.desc; try { desc2 = Type.getType(method.desc).toString(); if (desc2 == null || desc2.equals("null")) desc2 = method.desc; } catch (java.lang.ArrayIndexOutOfBoundsException e) { } srn.notifyOfResult(node.name + "." + method.name + desc2 + " > " + OpcodeInfo.OPCODES.get(insnNode.opcode()).toLowerCase()); } } } } }
From source file:the.bytecode.club.bytecodeviewer.searching.MethodCallSearch.java
License:Open Source License
@Override public void search(final ClassNode node, final SearchResultNotifier srn, boolean exact) { final Iterator<MethodNode> methods = node.methods.iterator(); String owner = mOwner.getText(); if (owner.isEmpty()) { owner = null;/*w ww . ja va 2 s . c o m*/ } String name = mName.getText(); if (name.isEmpty()) { name = null; } String desc = mDesc.getText(); if (desc.isEmpty()) { desc = null; } while (methods.hasNext()) { final MethodNode method = methods.next(); final InsnList insnlist = method.instructions; final ListIterator<AbstractInsnNode> instructions = insnlist.iterator(); while (instructions.hasNext()) { final AbstractInsnNode insnNode = instructions.next(); if (insnNode instanceof MethodInsnNode) { final MethodInsnNode min = (MethodInsnNode) insnNode; if (name == null && owner == null && desc == null) continue; if (exact) { if (name != null && !name.equals(min.name)) { continue; } if (owner != null && !owner.equals(min.owner)) { continue; } if (desc != null && !desc.equals(min.desc)) { continue; } String desc2 = method.desc; try { desc2 = Type.getType(method.desc).toString(); if (desc2 == null || desc2.equals("null")) desc2 = method.desc; } catch (java.lang.ArrayIndexOutOfBoundsException e) { } srn.notifyOfResult(node.name + "." + method.name + desc2 + " > " + OpcodeInfo.OPCODES.get(insnNode.opcode()).toLowerCase()); } else { if (name != null && !min.name.contains(name)) { continue; } if (owner != null && !min.owner.contains(owner)) { continue; } if (desc != null && !min.desc.contains(desc)) { continue; } String desc2 = method.desc; try { desc2 = Type.getType(method.desc).toString(); if (desc2 == null || desc2.equals("null")) desc2 = method.desc; } catch (java.lang.ArrayIndexOutOfBoundsException e) { } srn.notifyOfResult(node.name + "." + method.name + desc2 + " > " + OpcodeInfo.OPCODES.get(insnNode.opcode()).toLowerCase()); } } } } }
From source file:the.bytecode.club.bytecodeviewer.searching.RegexInsnFinder.java
License:Open Source License
private AbstractInsnNode[] cleanInsn(final InsnList insnList) { final List<AbstractInsnNode> il = new ArrayList<AbstractInsnNode>(); final Iterator<AbstractInsnNode> iIt = insnList.iterator(); while (iIt.hasNext()) { final AbstractInsnNode node = iIt.next(); if (node.opcode() >= 0) { il.add(node);/*from w ww . j a v a2s . c om*/ } } return il.toArray(new AbstractInsnNode[il.size()]); }
From source file:the.bytecode.club.bytecodeviewer.searching.RegexInsnFinder.java
License:Open Source License
/** * Refreshes the internal instruction list when you have made changes to the * method./*from w ww . j a v a 2 s . c om*/ */ public void refresh() { origInstructions = cleanInsn(mn.instructions); final List<AbstractInsnNode> il = new ArrayList<AbstractInsnNode>(); for (final AbstractInsnNode ain : mn.instructions.toArray()) if (ain.opcode() >= 0) { il.add(ain); } instructions = il.toArray(new AbstractInsnNode[il.size()]); offsets = new int[instructions.length]; insnString = ""; for (int i = 0; i < instructions.length; i++) { offsets[i] = -1; final AbstractInsnNode ain = instructions[i]; if (ain.opcode() >= 0) { if (ain.opcode() >= opcodes.length) { try { throw new UnexpectedException("Unknown opcode encountered: " + ain.opcode()); } catch (final UnexpectedException e) { new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e); } } offsets[i] = insnString.length(); insnString += opcodes[ain.opcode()]; switch (ain.type()) { case AbstractInsnNode.INT_INSN: final IntInsnNode iin = (IntInsnNode) ain; insnString += "{" + iin.operand + "}"; break; case AbstractInsnNode.LDC_INSN: final LdcInsnNode lin = (LdcInsnNode) ain; insnString += "{" + lin.cst.toString().replace("}", "\\}") + "}"; break; case AbstractInsnNode.VAR_INSN: final VarInsnNode vin = (VarInsnNode) ain; insnString += "_" + vin.var; break; case AbstractInsnNode.IINC_INSN: final IincInsnNode iiin = (IincInsnNode) ain; insnString += "{" + iiin.var + "," + iiin.incr + "}"; break; case AbstractInsnNode.FIELD_INSN: final FieldInsnNode fin = (FieldInsnNode) ain; insnString += "{" + fin.desc + "," + fin.owner + "," + fin.name + "}"; break; case AbstractInsnNode.METHOD_INSN: final MethodInsnNode min = (MethodInsnNode) ain; insnString += "{" + min.desc + "," + min.owner + "," + min.name + "}"; break; case AbstractInsnNode.TYPE_INSN: final TypeInsnNode tin = (TypeInsnNode) ain; insnString += "{" + tin.desc + "}"; break; case AbstractInsnNode.MULTIANEWARRAY_INSN: final MultiANewArrayInsnNode manain = (MultiANewArrayInsnNode) ain; insnString += "{" + manain.dims + "," + manain.desc + "}"; break; default: throw new IllegalArgumentException(String.valueOf(ain.type())); } insnString += " "; } } }