findpattern.java
来自「代码是一个分类器的实现,其中使用了部分weka的源代码。可以将项目导入eclip」· Java 代码 · 共 495 行 · 第 1/2 页
JAVA
495 行
/** * @return number of matched instructions, or -1 if the match did not succeed */ public final int getMatchLength() { return match_length; } /** * @return the matched piece of code as an array of instruction (handles) */ public final InstructionHandle[] getMatch() { if(match_length == -1) throw new ClassGenException("Nothing matched."); InstructionHandle[] match = new InstructionHandle[match_length]; System.arraycopy(handles, matched_from, match, 0, match_length); return match; } /** * Defines a new instruction list. Automatically calls * <a href="#reread()">reread()</a> to update the object. * * @param il the new instuction list */ public final void setInstructionList(InstructionList il) { this.il = il; reread(); } /** * Internal debugging routines. */ private static final String pattern2string(String pattern) { return pattern2string(pattern, true); } private static final String pattern2string(String pattern, boolean make_string) { StringBuffer buf = new StringBuffer(); for(int i=0; i < pattern.length(); i++) { char ch = pattern.charAt(i); if(ch >= OFFSET) { if(make_string) buf.append(Constants.OPCODE_NAMES[ch - OFFSET]); else buf.append((int)(ch - OFFSET)); } else buf.append(ch); } return buf.toString(); } /* Static initializer. */ static { String instruction_pattern, binstruction_pattern, if_icmp_pattern, if_pattern, push_pattern, iload_pattern, aload_pattern, fload_pattern, dload_pattern, lload_pattern, istore_pattern, astore_pattern, fstore_pattern, dstore_pattern, lstore_pattern, invoke_pattern, return_pattern, if_pattern2; StringBuffer buf; /* Make instruction string */ buf = new StringBuffer("("); for(short i=0; i < NO_OPCODES; i++) { if(Constants.NO_OF_OPERANDS[i] != Constants.UNDEFINED) { // Not an invalid opcode buf.append(makeChar(i)); if(i < NO_OPCODES - 1) buf.append('|'); } } buf.append(')'); instruction_pattern = buf.toString(); /* Make BranchInstruction string */ appendPatterns(buf = new StringBuffer("("), Constants.IFEQ, Constants.LOOKUPSWITCH); buf.append('|'); appendPatterns(buf, Constants.IFNULL, Constants.JSR_W); buf.append(')'); binstruction_pattern = buf.toString(); /* Make IF_ICMP__ pattern string */ appendPatterns(buf = new StringBuffer("("), Constants.IF_ICMPEQ, Constants.IF_ICMPLE); buf.append(')'); if_icmp_pattern = buf.toString(); /* Make IF__ pattern string */ appendPatterns(buf = new StringBuffer("("), Constants.IFEQ, Constants.IFLE); buf.append(')'); if_pattern = buf.toString(); /* Make PUSH pattern string */ appendPatterns(buf = new StringBuffer("("), Constants.ACONST_NULL,Constants. LDC2_W); buf.append(')'); push_pattern = buf.toString(); /* Make ILOAD__ pattern string */ appendPatterns(buf = new StringBuffer("("), Constants.ILOAD_0, Constants.ILOAD_3); buf.append('|'); buf.append(makeChar(Constants.ILOAD)); buf.append(')'); iload_pattern = buf.toString(); /* Make ALOAD__ pattern string */ appendPatterns(buf = new StringBuffer("("), Constants.ALOAD_0, Constants.ALOAD_3); buf.append('|'); buf.append(makeChar(Constants.ALOAD)); buf.append(')'); aload_pattern = buf.toString(); /* Make FLOAD__ pattern string */ appendPatterns(buf = new StringBuffer("("), Constants.FLOAD_0, Constants.FLOAD_3); buf.append('|'); buf.append(makeChar(Constants.FLOAD)); buf.append(')'); fload_pattern = buf.toString(); /* Make DLOAD__ pattern string */ appendPatterns(buf = new StringBuffer("("), Constants.DLOAD_0, Constants.DLOAD_3); buf.append('|'); buf.append(makeChar(Constants.DLOAD)); buf.append(')'); dload_pattern = buf.toString(); /* Make LLOAD__ pattern string */ appendPatterns(buf = new StringBuffer("("), Constants.LLOAD_0, Constants.LLOAD_3); buf.append('|'); buf.append(makeChar(Constants.LLOAD)); buf.append(')'); lload_pattern = buf.toString(); /* Make ISTORE__ pattern string */ appendPatterns(buf = new StringBuffer("("), Constants.ISTORE_0, Constants.ISTORE_3); buf.append('|'); buf.append(makeChar(Constants.ISTORE)); buf.append(')'); istore_pattern = buf.toString(); /* Make ASTORE__ pattern string */ appendPatterns(buf = new StringBuffer("("), Constants.ASTORE_0, Constants.ASTORE_3); buf.append('|'); buf.append(makeChar(Constants.ASTORE)); buf.append(')'); astore_pattern = buf.toString(); /* Make FSTORE__ pattern string */ appendPatterns(buf = new StringBuffer("("), Constants.FSTORE_0, Constants.FSTORE_3); buf.append('|'); buf.append(makeChar(Constants.FSTORE)); buf.append(')'); fstore_pattern = buf.toString(); /* Make DSTORE__ pattern string */ appendPatterns(buf = new StringBuffer("("), Constants.DSTORE_0, Constants.DSTORE_3); buf.append('|'); buf.append(makeChar(Constants.DSTORE)); buf.append(')'); dstore_pattern = buf.toString(); /* Make LSTORE__ pattern string */ appendPatterns(buf = new StringBuffer("("), Constants.LSTORE_0, Constants.LSTORE_3); buf.append('|'); buf.append(makeChar(Constants.LSTORE)); buf.append(')'); lstore_pattern = buf.toString(); /* Make INVOKE pattern string */ appendPatterns(buf = new StringBuffer("("), Constants.INVOKEVIRTUAL, Constants.INVOKEINTERFACE); buf.append(')'); invoke_pattern = buf.toString(); /* Make RETURN pattern string */ appendPatterns(buf = new StringBuffer("("), Constants.IRETURN, Constants.RETURN); buf.append(')'); return_pattern = buf.toString(); /* Make IfInstruction pattern string */ appendPatterns(buf = new StringBuffer("("), Constants.IFEQ, Constants.IF_ACMPNE); buf.append('|'); buf.append(makeChar(Constants.IFNULL)); buf.append('|'); buf.append(makeChar(Constants.IFNONNULL)); buf.append(')'); if_pattern2 = buf.toString(); pattern_map = new String[] { instruction_pattern, binstruction_pattern, if_icmp_pattern, if_pattern, push_pattern, iload_pattern, aload_pattern, fload_pattern, dload_pattern, lload_pattern, istore_pattern, astore_pattern, fstore_pattern, dstore_pattern, lstore_pattern, invoke_pattern, return_pattern, if_pattern2 }; } /** * Convert opcode number to char. */ private static final char makeChar(short opcode) { return (char)(opcode + OFFSET); } /** * Append instructions characters starting from `start' to `to'. */ private final static void appendPatterns(StringBuffer buf, short from, short to) { for(short i=from; i <= to; i++) { buf.append(makeChar(i)); if(i < to) buf.append('|'); } } /** * @return the inquired instruction list */ public final InstructionList getInstructionList() { return il; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?