当前位置: 首页>>代码示例>>Java>>正文


Java MethodGen.getInstructionList方法代码示例

本文整理汇总了Java中org.apache.bcel.generic.MethodGen.getInstructionList方法的典型用法代码示例。如果您正苦于以下问题:Java MethodGen.getInstructionList方法的具体用法?Java MethodGen.getInstructionList怎么用?Java MethodGen.getInstructionList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.bcel.generic.MethodGen的用法示例。


在下文中一共展示了MethodGen.getInstructionList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: analyzeMethod

import org.apache.bcel.generic.MethodGen; //导入方法依赖的package包/类
private void analyzeMethod(Method m, ClassContext classContext) throws CFGBuilderException, DataflowAnalysisException {
    MethodGen methodGen = classContext.getMethodGen(m);
    ConstantPoolGen cpg = classContext.getConstantPoolGen();
    CFG cfg = classContext.getCFG(m);

    if (methodGen == null || methodGen.getInstructionList() == null) {
        return; //No instruction .. nothing to do
    }
    for (Iterator<Location> i = cfg.locationIterator(); i.hasNext(); ) {
        Location location = i.next();
        Instruction inst = location.getHandle().getInstruction();
        if (inst instanceof InvokeInstruction) {
            InvokeInstruction invoke = (InvokeInstruction) inst;
            String methodName = invoke.getMethodName(cpg);
            if ("enableDefaultTyping".equals(methodName)) {
                JavaClass clz = classContext.getJavaClass();
                bugReporter.reportBug(new BugInstance(this, DESERIALIZATION_TYPE, HIGH_PRIORITY)
                        .addClass(clz)
                        .addMethod(clz, m)
                        .addCalledMethod(cpg, invoke)
                        .addSourceLine(classContext, m, location)
                );
            }
        }
    }
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:27,代码来源:UnsafeJacksonDeserializationDetector.java

示例2: calcNrSpawns

import org.apache.bcel.generic.MethodGen; //导入方法依赖的package包/类
private int calcNrSpawns(MethodGen mg) {
InstructionList il = mg.getInstructionList();
if (il == null) {
    return 0;
}

InstructionHandle[] ins = il.getInstructionHandles();
int count = 0;

for (int i = 0; i < ins.length; i++) {
    if (ins[i].getInstruction() instanceof INVOKEVIRTUAL) {
	Method target = self.findMethod((INVOKEVIRTUAL) (ins[i]
		.getInstruction()));
	JavaClass cl = self.findMethodClass((INVOKEVIRTUAL) (ins[i]
		.getInstruction()));
	if (isSpawnable(target, cl)) {
	    count++;
	}
    }
}

return count;
   }
 
开发者ID:pieterhijma,项目名称:cashmere,代码行数:24,代码来源:MethodTable.java

示例3: containsSpawnedCall

import org.apache.bcel.generic.MethodGen; //导入方法依赖的package包/类
boolean containsSpawnedCall(MethodGen m) {
InstructionList code = m.getInstructionList();

if (code == null) {
    return false;
}

InstructionHandle ih[] = code.getInstructionHandles();

for (int i = 0; i < ih.length; i++) {
    Instruction ins = ih[i].getInstruction();
    if (ins instanceof INVOKEVIRTUAL) {
	Method target = self.findMethod((INVOKEVIRTUAL) (ins));
	JavaClass cl = self.findMethodClass((INVOKEVIRTUAL) (ins));
	if (isSpawnable(target, cl)) {
	    return true;
	}
    }
}

return false;
   }
 
开发者ID:pieterhijma,项目名称:cashmere,代码行数:23,代码来源:MethodTable.java

示例4: analyzeMethod

import org.apache.bcel.generic.MethodGen; //导入方法依赖的package包/类
private void analyzeMethod(Method m, ClassContext classContext) throws CFGBuilderException, DataflowAnalysisException
    {

        MethodGen methodGen = classContext.getMethodGen(m);
        ConstantPoolGen cpg = classContext.getConstantPoolGen();
        CFG cfg = classContext.getCFG(m);

        if (methodGen == null || methodGen.getInstructionList() == null) {
            return; //No instruction .. nothing to do
        }

        for (Iterator<Location> i = cfg.locationIterator(); i.hasNext(); ) {
            Location location = i.next();
            Instruction inst = location.getHandle().getInstruction();

            //
            if (inst instanceof InvokeInstruction) {
//                System.out.println(inst.getName());
                InvokeInstruction invoke = (InvokeInstruction) inst;

                String className = invoke.getClassName(cpg);
                if ("java.io.ObjectInputStream".equals(className) || className.contains("InputStream") || InterfaceUtils.isSubtype(className, "java.io.ObjectInputStream")) {

                    String methodName = invoke.getMethodName(cpg);
                    if (OBJECT_INPUTSTREAM_READ_METHODS.contains(methodName)) {

                        JavaClass clz = classContext.getJavaClass();
                        bugReporter.reportBug(new BugInstance(this, OBJECT_DESERIALIZATION_TYPE, HIGH_PRIORITY) //
                                .addClass(clz).addMethod(clz, m).addSourceLine(classContext,m,location));
                    }
                }

            }
        }
    }
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:36,代码来源:ObjectDeserializationDetector.java

示例5: insertAllDeleteLocalRecords

import org.apache.bcel.generic.MethodGen; //导入方法依赖的package包/类
void insertAllDeleteLocalRecords(MethodGen m) {
    int maxLocals = m.getMaxLocals();
    InstructionList il = m.getInstructionList();

    for (InstructionHandle i = il.getStart(); i != null; i = i.getNext()) {
        Instruction ins = i.getInstruction();
        if (ins instanceof ReturnInstruction) {
            i = insertDeleteLocalRecord(m, il, i, maxLocals);
        }
    }
}
 
开发者ID:pieterhijma,项目名称:cashmere,代码行数:12,代码来源:Cashmerec.java

示例6: removeUnusedLocals

import org.apache.bcel.generic.MethodGen; //导入方法依赖的package包/类
void removeUnusedLocals(Method mOrig, MethodGen m) {
    InstructionList il = m.getInstructionList();
    InstructionHandle[] ins = il.getInstructionHandles();
    for (int i = 0; i < ins.length; i++) {
        Instruction in = ins[i].getInstruction();

        if (in instanceof LocalVariableInstruction) {
            LocalVariableInstruction curr = (LocalVariableInstruction) in;
            if (mtab.getLocal(m, curr, ins[i].getPosition()) != null
                && curr.getIndex() < m.getMaxLocals() - 5
                && !mtab.isLocalUsedInInlet(mOrig, curr.getIndex())) {
                if (curr instanceof IINC) {
                    ins[i].setInstruction(new NOP());
                } else if (curr instanceof LSTORE || curr instanceof DSTORE) {
                    ins[i].setInstruction(new POP2());
                } else if (curr instanceof StoreInstruction) {
                    ins[i].setInstruction(new POP());
                } else if (curr instanceof ALOAD) {
                    ins[i].setInstruction(new ACONST_NULL());
                } else if (curr instanceof FLOAD) {
                    ins[i].setInstruction(new FCONST((float) 0.0));
                } else if (curr instanceof ILOAD) {
                    ins[i].setInstruction(new ICONST(0));
                } else if (curr instanceof DLOAD) {
                    ins[i].setInstruction(new DCONST(0.0));
                } else if (curr instanceof LLOAD) {
                    ins[i].setInstruction(new LCONST(0L));
                } else {
                    System.out.println("unhandled ins in "
                        + "removeUnusedLocals: " + curr);
                    System.exit(1);
                }
            }
        }
    }
}
 
开发者ID:pieterhijma,项目名称:cashmere,代码行数:37,代码来源:Cashmerec.java

示例7: showMethod

import org.apache.bcel.generic.MethodGen; //导入方法依赖的package包/类
void showMethod(PrintStream out, MethodGen methodGen, ConstantPool cp) {
InstructionList il = methodGen.getInstructionList();
InstructionHandle[] instructionHandles = il.getInstructionHandles();
ConstantPoolGen cpg = new ConstantPoolGen(cp);
int balanceOnStack = 0;
for (InstructionHandle ih : instructionHandles) {
    int produced = ih.getInstruction().produceStack(cpg);
    int consumed = ih.getInstruction().consumeStack(cpg);
    balanceOnStack = balanceOnStack + produced - consumed;
    out.printf("%d:\t(c: %d, p: %d, t: %d)\t%s\n", 
	ih.getPosition(), consumed, produced, balanceOnStack,
	ih.getInstruction().toString(cp));
}
   }
 
开发者ID:pieterhijma,项目名称:cashmere,代码行数:15,代码来源:ClassViewer.java

示例8: nullAdaptClass

import org.apache.bcel.generic.MethodGen; //导入方法依赖的package包/类
byte[] nullAdaptClass(final InputStream is, final String name)
        throws Exception
{
    JavaClass jc = new ClassParser(is, name + ".class").parse();
    ClassGen cg = new ClassGen(jc);
    ConstantPoolGen cp = cg.getConstantPool();
    Method[] ms = cg.getMethods();
    for (int j = 0; j < ms.length; ++j) {
        MethodGen mg = new MethodGen(ms[j], cg.getClassName(), cp);
        boolean lv = ms[j].getLocalVariableTable() == null;
        boolean ln = ms[j].getLineNumberTable() == null;
        if (lv) {
            mg.removeLocalVariables();
        }
        if (ln) {
            mg.removeLineNumbers();
        }
        mg.stripAttributes(skipDebug);
        InstructionList il = mg.getInstructionList();
        if (il != null) {
            InstructionHandle ih = il.getStart();
            while (ih != null) {
                ih = ih.getNext();
            }
            if (compute) {
                mg.setMaxStack();
                mg.setMaxLocals();
            }
        }
        cg.replaceMethod(ms[j], mg.getMethod());
    }
    return cg.getJavaClass().getBytes();
}
 
开发者ID:typetools,项目名称:annotation-tools,代码行数:34,代码来源:BCELPerfTest.java

示例9: change1

import org.apache.bcel.generic.MethodGen; //导入方法依赖的package包/类
private boolean change1(MethodGen mg)
    {
        InstructionList il = mg.getInstructionList();
        InstructionFinder f   = new InstructionFinder(il);
        String            pat = "[LDC_W|LDC] INVOKEVIRTUAL IFNE ICONST_1 GOTO ICONST_0";

        boolean changed = false;
        for(Iterator j = f.search(pat, new IsLdcClass()); j.hasNext(); )
        {
            InstructionHandle[] match = (InstructionHandle[]) j.next();

            // replace
            //    LDC_W <class>
            //    INVOKEVIRTUAL Class.desiredAssertionStatus
            //    IFNE
            //    ICONST_1
            //    goto
            //    ICONST_0
            // with
            //    ICONST_1

            changed = true;
            match[0].setInstruction(InstructionConstants.ICONST_1);
            try
            {
                il.delete(match[1], match[5]);
//                System.out.println(il);
            }
            catch (TargetLostException e)
            {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }
        }
        return changed;
    }
 
开发者ID:BowlerHatLLC,项目名称:feathers-sdk,代码行数:36,代码来源:Downgrader.java

示例10: check_reflection

import org.apache.bcel.generic.MethodGen; //导入方法依赖的package包/类
private int check_reflection(MethodGen mgen, ConstantPoolGen cpgen) {
	int cnt = 0;

	InstructionList ilist = mgen.getInstructionList();
	if (ilist == null || ilist.size() == 0)
		return cnt;

	for (Instruction instr : ilist.getInstructions()) {
		// go through all instructions and look for invokes
		if (instr instanceof InvokeInstruction) {
			InvokeInstruction invoke = (InvokeInstruction) instr;
			ReferenceType rtype = invoke.getReferenceType(cpgen);

			if (rtype instanceof ObjectType) {
				String cname = ((ObjectType) rtype).getClassName();
				String mname = invoke.getName(cpgen);

				// we look for exact match
				if (cname.equals("java.lang.reflect.Method") && mname.equals("invoke")) {
					// Util.log(rtype.toString());
					cnt++;
				}
			} else {
				// reference type can be ArrayType or UninitializedObjectType
			}
		}
	}

	return cnt;
}
 
开发者ID:USC-NSL,项目名称:SIF,代码行数:31,代码来源:ClassFileScanner.java

示例11: counterAdaptClass

import org.apache.bcel.generic.MethodGen; //导入方法依赖的package包/类
byte[] counterAdaptClass(final InputStream is, final String name)
        throws Exception
{
    JavaClass jc = new ClassParser(is, name + ".class").parse();
    ClassGen cg = new ClassGen(jc);
    ConstantPoolGen cp = cg.getConstantPool();
    if (!cg.isInterface()) {
        FieldGen fg = new FieldGen(ACC_PUBLIC,
                Type.getType("I"),
                "_counter",
                cp);
        cg.addField(fg.getField());
    }
    Method[] ms = cg.getMethods();
    for (int j = 0; j < ms.length; ++j) {
        MethodGen mg = new MethodGen(ms[j], cg.getClassName(), cp);
        if (!mg.getName().equals("<init>") && !mg.isStatic()
                && !mg.isAbstract() && !mg.isNative())
        {
            if (mg.getInstructionList() != null) {
                InstructionList il = new InstructionList();
                il.append(new ALOAD(0));
                il.append(new ALOAD(0));
                il.append(new GETFIELD(cp.addFieldref(name, "_counter", "I")));
                il.append(new ICONST(1));
                il.append(new IADD());
                il.append(new PUTFIELD(cp.addFieldref(name, "_counter", "I")));
                mg.getInstructionList().insert(il);
                mg.setMaxStack(Math.max(mg.getMaxStack(), 2));
                boolean lv = ms[j].getLocalVariableTable() == null;
                boolean ln = ms[j].getLineNumberTable() == null;
                if (lv) {
                    mg.removeLocalVariables();
                }
                if (ln) {
                    mg.removeLineNumbers();
                }
                cg.replaceMethod(ms[j], mg.getMethod());
            }
        }
    }
    return cg.getJavaClass().getBytes();
}
 
开发者ID:typetools,项目名称:annotation-tools,代码行数:44,代码来源:BCELPerfTest.java

示例12: change2

import org.apache.bcel.generic.MethodGen; //导入方法依赖的package包/类
private boolean change2(MethodGen mg)
{
    InstructionList il = mg.getInstructionList();
    InstructionFinder f   = new InstructionFinder(il);
    String            pat = "ALOAD_0 ALOAD_1 PUTFIELD ALOAD_0 INVOKESPECIAL";

    boolean changed = false;
    for(Iterator j = f.search(pat, new IsInnerConstructor()); j.hasNext(); )
    {
        InstructionHandle[] match = (InstructionHandle[]) j.next();

        // replace
        //    ALOAD_0       [0] 
        //    ALOAD_1		[1]
        //    PUTFIELD		[2]
        //    ALOAD_0		[3]
        //    INVOKESPECIAL	[4]
        // with
        //    ALOAD_0		[0]
        //    INVOKESPECIAL	[4]
        //    ALOAD_0		[3]
        //    ALOAD_1		[1]
        //    PUTFIELD		[2]

        changed = true;
        try
        {
            InstructionList il2 = new InstructionList();
            il2.append(match[3].getInstruction());
            il2.append(match[4].getInstruction());
            il.delete(match[3], match[4]);
            il.insert(match[0], il2);
        }
        catch (TargetLostException e)
        {
        	System.err.println("ERROR IN "+mg);
            e.printStackTrace();
        }
    }
    return changed;
}
 
开发者ID:BowlerHatLLC,项目名称:feathers-sdk,代码行数:42,代码来源:Downgrader.java

示例13: instrument_reflection

import org.apache.bcel.generic.MethodGen; //导入方法依赖的package包/类
private static Method instrument_reflection(InstructionFactory inf, MethodGen mgen, ConstantPoolGen cpgen) {
	Method ret = mgen.getMethod();

	InstructionList ilist = mgen.getInstructionList();
	if (ilist == null || ilist.size() == 0)
		return ret;

	InstructionHandle[] ihdls = ilist.getInstructionHandles();

	for (InstructionHandle ihdl : ihdls) {
		Instruction instr = ihdl.getInstruction();

		// go through all instructions and look for invokes
		if (instr instanceof InvokeInstruction) {
			InvokeInstruction invoke = (InvokeInstruction) instr;
			ReferenceType rtype = invoke.getReferenceType(cpgen);

			if (rtype instanceof ObjectType) {
				String cname = ((ObjectType) rtype).getClassName();
				String mname = invoke.getName(cpgen);

				// we look for exact match
				if (cname.equals("java.lang.reflect.Method") && mname.equals("invoke")) {
					// Util.log(rtype.toString());
					Type[] arg_types = { new ObjectType(java.lang.reflect.Method.class.getCanonicalName()), Type.OBJECT, new ArrayType(Type.OBJECT, 1) };
					ihdl.setInstruction(inf.createInvoke(SIFAStub.class.getCanonicalName(), "invoke", Type.OBJECT, arg_types, Constants.INVOKESTATIC));
				}
			} else {
				// reference type can be ArrayType or UninitializedObjectType
			}
		}
	}

	ilist.setPositions();

	mgen.setInstructionList(ilist);
	mgen.removeLineNumbers();
	mgen.setMaxStack();
	mgen.setMaxLocals();

	ret = mgen.getMethod();

	return ret;
}
 
开发者ID:USC-NSL,项目名称:SIF,代码行数:45,代码来源:ReflectionHandler.java

示例14: isGetterMethod

import org.apache.bcel.generic.MethodGen; //导入方法依赖的package包/类
/**
 * Determine whether or not the the given method is a getter method. I.e.,
 * if it just returns the value of an instance field.
 *
 * @param classContext
 *            the ClassContext for the class containing the method
 * @param method
 *            the method
 */
@SuppressWarnings("unchecked")
public static boolean isGetterMethod(ClassContext classContext, Method method) {
    MethodGen methodGen = classContext.getMethodGen(method);
    if (methodGen == null)
        return false;
    InstructionList il = methodGen.getInstructionList();
    // System.out.println("Checking getter method: " + method.getName());
    if (il.getLength() > 60)
        return false;

    int count = 0;
    Iterator<InstructionHandle> it = il.iterator();
    while (it.hasNext()) {
        InstructionHandle ih = it.next();
        switch (ih.getInstruction().getOpcode()) {
        case Constants.GETFIELD:
            count++;
            if (count > 1)
                return false;
            break;
        case Constants.PUTFIELD:
        case Constants.BALOAD:
        case Constants.CALOAD:
        case Constants.DALOAD:
        case Constants.FALOAD:
        case Constants.IALOAD:
        case Constants.LALOAD:
        case Constants.SALOAD:
        case Constants.AALOAD:
        case Constants.BASTORE:
        case Constants.CASTORE:
        case Constants.DASTORE:
        case Constants.FASTORE:
        case Constants.IASTORE:
        case Constants.LASTORE:
        case Constants.SASTORE:
        case Constants.AASTORE:
        case Constants.PUTSTATIC:
            return false;
        case Constants.INVOKESTATIC:
        case Constants.INVOKEVIRTUAL:
        case Constants.INVOKEINTERFACE:
        case Constants.INVOKESPECIAL:
        case Constants.GETSTATIC:
            // no-op

        }
    }
    // System.out.println("Found getter method: " + method.getName());
    return true;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:61,代码来源:FindInconsistentSync2.java

示例15: isGetterMethod

import org.apache.bcel.generic.MethodGen; //导入方法依赖的package包/类
/**
 * Determine whether or not the the given method is a getter method. I.e.,
 * if it just returns the value of an instance field.
 *
 * @param classContext
 *            the ClassContext for the class containing the method
 * @param method
 *            the method
 */
public static boolean isGetterMethod(ClassContext classContext, Method method) {
    MethodGen methodGen = classContext.getMethodGen(method);
    if (methodGen == null)
        return false;
    InstructionList il = methodGen.getInstructionList();
    // System.out.println("Checking getter method: " + method.getName());
    if (il.getLength() > 60)
        return false;

    int count = 0;
    Iterator<InstructionHandle> it = il.iterator();
    while (it.hasNext()) {
        InstructionHandle ih = it.next();
        switch (ih.getInstruction().getOpcode()) {
        case Constants.GETFIELD:
            count++;
            if (count > 1)
                return false;
            break;
        case Constants.PUTFIELD:
        case Constants.BALOAD:
        case Constants.CALOAD:
        case Constants.DALOAD:
        case Constants.FALOAD:
        case Constants.IALOAD:
        case Constants.LALOAD:
        case Constants.SALOAD:
        case Constants.AALOAD:
        case Constants.BASTORE:
        case Constants.CASTORE:
        case Constants.DASTORE:
        case Constants.FASTORE:
        case Constants.IASTORE:
        case Constants.LASTORE:
        case Constants.SASTORE:
        case Constants.AASTORE:
        case Constants.PUTSTATIC:
            return false;
        case Constants.INVOKESTATIC:
        case Constants.INVOKEVIRTUAL:
        case Constants.INVOKEINTERFACE:
        case Constants.INVOKESPECIAL:
        case Constants.GETSTATIC:
            // no-op

        }
    }
    // System.out.println("Found getter method: " + method.getName());
    return true;
}
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:60,代码来源:FindInconsistentSync2.java


注:本文中的org.apache.bcel.generic.MethodGen.getInstructionList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。