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


Java INVOKEVIRTUAL类代码示例

本文整理汇总了Java中org.apache.bcel.generic.INVOKEVIRTUAL的典型用法代码示例。如果您正苦于以下问题:Java INVOKEVIRTUAL类的具体用法?Java INVOKEVIRTUAL怎么用?Java INVOKEVIRTUAL使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: fillSpawnTable

import org.apache.bcel.generic.INVOKEVIRTUAL; //导入依赖的package包/类
private void fillSpawnTable(MethodTableEntry me) {
InstructionList il = me.mg.getInstructionList();
InstructionHandle[] ins = il.getInstructionHandles();

il.setPositions();

int spawnId = 0;

for (int k = 0; k < ins.length; k++) {
    if (ins[k].getInstruction() instanceof INVOKEVIRTUAL) {
	Method target = self.findMethod((INVOKEVIRTUAL) (ins[k]
		.getInstruction()));
	JavaClass cl = self.findMethodClass((INVOKEVIRTUAL) (ins[k]
		.getInstruction()));
	if (isSpawnable(target, cl)) {
	    // we have a spawn!
	    analyzeSpawn(me, ins[k], spawnId);
	    spawnId++;
	}
    }
}
   }
 
开发者ID:pieterhijma,项目名称:cashmere,代码行数:23,代码来源:MethodTable.java

示例2: calcNrSpawns

import org.apache.bcel.generic.INVOKEVIRTUAL; //导入依赖的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.INVOKEVIRTUAL; //导入依赖的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: insertSync

import org.apache.bcel.generic.INVOKEVIRTUAL; //导入依赖的package包/类
private void insertSync(Analyzer analyzer) throws MethodRewriteFailure {
d.log(1, "trying to insert sync statement(s)\n");
InstructionHandle[] ihs = 
    analyzer.proposeSyncInsertion(this, new Debug(d.turnedOn(), d.getStartLevel() + 2));

InstructionList instructionList = getInstructionList();

for (InstructionHandle ih : ihs) {
    InstructionHandle syncInvoke = 
	instructionList.insert(ih, 
		new INVOKEVIRTUAL(indexSync));
    InstructionHandle newTarget = instructionList.insert(syncInvoke, 
	    spawnableCalls.get(0).getObjectReference().getInstruction());
    // the same objectReference for every sync insertion
    instructionList.redirectBranches(ih, newTarget);
    d.log(2, "inserted sync()\n");
}
d.log(1, "inserted sync statement(s)\n");
   }
 
开发者ID:pieterhijma,项目名称:cashmere,代码行数:20,代码来源:SpawningMethod.java

示例5: callsSync

import org.apache.bcel.generic.INVOKEVIRTUAL; //导入依赖的package包/类
private boolean callsSync() {
ConstantPoolGen cpg = getConstantPool();
InstructionList instructionList = getInstructionList();
InstructionHandle handle = instructionList.getStart();
while (handle != null) {
    Instruction ins = handle.getInstruction();
    if (ins instanceof INVOKEVIRTUAL) {
	INVOKEVIRTUAL inv = (INVOKEVIRTUAL) ins;
	if (inv.getMethodName(cpg).equals("sync") &&
		inv.getSignature(cpg).equals("()V")) {
	    JavaClass cl = findMethodClass(inv, cpg);
	    if (cl != null && cl.getClassName().equals("ibis.cashmere.CashmereObject")) {
		return true;
	    }
	}
    }
    handle = handle.getNext();
}
return false;
   }
 
开发者ID:pieterhijma,项目名称:cashmere,代码行数:21,代码来源:SpawningMethod.java

示例6: preScreen

import org.apache.bcel.generic.INVOKEVIRTUAL; //导入依赖的package包/类
public boolean preScreen(MethodGen mg) {
    ConstantPoolGen cpg = mg.getConstantPool();

    int lockCount = mg.isSynchronized() ? 1 : 0;
    boolean sawWaitOrNotify = false;

    InstructionHandle handle = mg.getInstructionList().getStart();
    while (handle != null && !(lockCount >= 2 && sawWaitOrNotify)) {
        Instruction ins = handle.getInstruction();
        if (ins instanceof MONITORENTER)
            ++lockCount;
        else if (ins instanceof INVOKEVIRTUAL) {
            INVOKEVIRTUAL inv = (INVOKEVIRTUAL) ins;
            String methodName = inv.getMethodName(cpg);
            if (methodName.equals("wait") || methodName.startsWith("notify"))
                sawWaitOrNotify = true;
        }

        handle = handle.getNext();
    }

    return lockCount >= 2 && sawWaitOrNotify;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:24,代码来源:FindTwoLockWait.java

示例7: visitINVOKEVIRTUAL

import org.apache.bcel.generic.INVOKEVIRTUAL; //导入依赖的package包/类
@Override
public void visitINVOKEVIRTUAL(INVOKEVIRTUAL obj) {

    if (obj.getMethodName(cpg).equals("cast") && obj.getClassName(cpg).equals("java.lang.Class")) {
        // treat as no-op
        try {
            ValueNumberFrame frame = getFrame();
            ValueNumber resultType = frame.popValue();
            frame.popValue();
            frame.pushValue(resultType);
        } catch (DataflowAnalysisException e) {
            AnalysisContext.logError("oops", e);
        }
        return;
    }
    // Don't know what this method invocation is doing.
    // Kill all loads.
    if (obj.getMethodName(cpg).toLowerCase().indexOf("lock") >= 0)
        getFrame().killAllLoads();
    else
        killLoadsOfObjectsPassed(obj);
    handleNormalInstruction(obj);
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:24,代码来源:ValueNumberFrameModelingVisitor.java

示例8: analyzeMethod

import org.apache.bcel.generic.INVOKEVIRTUAL; //导入依赖的package包/类
private void analyzeMethod(Method m, ClassContext classContext) throws CFGBuilderException{
    JavaClass clazz = classContext.getJavaClass();
    ConstantPoolGen cpg = classContext.getConstantPoolGen();
    CFG cfg = classContext.getCFG(m);

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

        if (inst instanceof INVOKEVIRTUAL) {
            INVOKEVIRTUAL invoke = (INVOKEVIRTUAL)inst;
            if( "java.lang.StringBuilder".equals(invoke.getClassName(cpg)) && "append".equals(invoke.getMethodName(cpg))) {
                Instruction prev = loc.getHandle().getPrev().getInstruction();

                if (prev instanceof LDC) {
                    LDC ldc = (LDC)prev;
                    Object value = ldc.getValue(cpg);

                    if (value instanceof String) {
                        String v = (String)value;

                        if ("redirect:".equals(v)) {
                            BugInstance bug = new BugInstance(this, SPRING_UNVALIDATED_REDIRECT_TYPE, Priorities.NORMAL_PRIORITY);
                            bug.addClass(clazz).addMethod(clazz,m).addSourceLine(classContext,m,loc);
                            reporter.reportBug(bug);
                        }
                    }
                }
            }
        }
    }
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:33,代码来源:SpringUnvalidatedRedirectDetector.java

示例9: getCookieInstructionLocation

import org.apache.bcel.generic.INVOKEVIRTUAL; //导入依赖的package包/类
/**
 * This method is used to track calls made on a specific object. For instance, this could be used to track if "setHttpOnly(true)"
 * was executed on a specific cookie object.
 *
 * This allows the detector to find interchanged calls like this
 *
 * Cookie cookie1 = new Cookie("f", "foo");     <- This cookie is unsafe
 * Cookie cookie2 = new Cookie("b", "bar");     <- This cookie is safe
 * cookie1.setHttpOnly(false);
 * cookie2.setHttpOnly(true);
 *
 * @param cpg ConstantPoolGen
 * @param startLocation The Location of the cookie initialization call.
 * @param objectStackLocation The index of the cookie on the stack.
 * @param invokeInstruction The instruction we want to detect.s
 * @return The location of the invoke instruction provided for the cookie at a specific index on the stack.
 */
private Location getCookieInstructionLocation(ConstantPoolGen cpg, Location startLocation, int objectStackLocation, String invokeInstruction) {
    Location location = startLocation;
    InstructionHandle handle = location.getHandle();

    int loadedStackValue = 0;

    // Loop until we find the setSecure call for this cookie
    while (handle.getNext() != null) {
        handle = handle.getNext();
        Instruction nextInst = handle.getInstruction();

        // We check if the index of the cookie used for this invoke is the same as the one provided
        if (nextInst instanceof ALOAD) {
            ALOAD loadInst = (ALOAD)nextInst;
            loadedStackValue = loadInst.getIndex();
        }

        if (nextInst instanceof INVOKEVIRTUAL
                && loadedStackValue == objectStackLocation) {
            INVOKEVIRTUAL invoke = (INVOKEVIRTUAL) nextInst;

            String methodNameWithSignature = invoke.getClassName(cpg) + "." + invoke.getMethodName(cpg);

            if (methodNameWithSignature.equals(invokeInstruction)) {

                Integer val = ByteCode.getConstantInt(handle.getPrev());

                if (val != null && val == TRUE_INT_VALUE) {
                    return new Location(handle, location.getBasicBlock());
                }
            }
        }
    }

    return null;
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:54,代码来源:CookieFlagsDetector.java

示例10: get_line_location

import org.apache.bcel.generic.INVOKEVIRTUAL; //导入依赖的package包/类
private Map<String, List<Location>> get_line_location(Method m, ClassContext classContext){
        HashMap<String, List<Location>> all_line_location = new HashMap<>();
        ConstantPoolGen cpg = classContext.getConstantPoolGen();
        CFG cfg = null;
        try {
            cfg = classContext.getCFG(m);
        } catch (CFGBuilderException e) {
            e.printStackTrace();
            return all_line_location;
        }
        for (Iterator<Location> i = cfg.locationIterator(); i.hasNext(); ) {
            Location loc = i.next();
            Instruction inst = loc.getHandle().getInstruction();
            if(inst instanceof INVOKEVIRTUAL) {
                INVOKEVIRTUAL invoke = (INVOKEVIRTUAL) inst;
//                if (classname.equals(invoke.getClassName(cpg)) &&
//                        methodName.equals(invoke.getMethodName(cpg))) {
                    if(all_line_location.containsKey(invoke.getMethodName(cpg))){
                        all_line_location.get(invoke.getMethodName(cpg)).add(loc);
                    }else {
                        LinkedList<Location> loc_list = new LinkedList<>();
                        loc_list.add(loc);
                        all_line_location.put(invoke.getMethodName(cpg), loc_list);
                    }
//                }
            }
        }
        return all_line_location;
    }
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:30,代码来源:LocalDenialOfServiceDetector.java

示例11: getSpawnableCalls

import org.apache.bcel.generic.INVOKEVIRTUAL; //导入依赖的package包/类
private ArrayList<SpawnableCall> getSpawnableCalls(ConstantPoolGen constantPoolGen, MethodGen spawnSignatureGen) throws 
AssumptionFailure {

    ArrayList<SpawnableCall> spawnableCalls = 
	new ArrayList<SpawnableCall>();

    InstructionList il = getInstructionList(); 
    int indexSpawnableCall = 
	constantPoolGen.lookupMethodref(spawnSignatureGen);
    if (indexSpawnableCall < 0) return spawnableCalls;

    INVOKEVIRTUAL spawnableInvoke = 
	new INVOKEVIRTUAL(indexSpawnableCall);


    InstructionHandle ih = il.getStart();

    do {
        Instruction instruction = ih.getInstruction();
   		if (instruction.equals(spawnableInvoke)) {
   		    if (instruction.produceStack(constantPoolGen) > 0) {
   		        spawnableCalls.add(getSpawnableCallReturningValue(ih));
   		    } else if (instruction.produceStack(constantPoolGen) == 0) {
   		        if (spawnSignatureGen.getExceptions().length > 0) {
   		            spawnableCalls.add(getSpawnableCallWithException(ih, spawnSignatureGen));
   		        } else {
   		            throw new AssumptionFailure("Not satisfying assumption that spawnable method returns something or throws something");
   		        }
   		    } else {
   		        throw new AssumptionFailure("Not satisfying assumption that spawnable method returns something or throws something");
   		    }
   		} else {
   		    // OK
   		}
    } while((ih = ih.getNext()) != null);

    return spawnableCalls;
}
 
开发者ID:pieterhijma,项目名称:cashmere,代码行数:39,代码来源:SpawningMethod.java

示例12: isStreamClose

import org.apache.bcel.generic.INVOKEVIRTUAL; //导入依赖的package包/类
public boolean isStreamClose(BasicBlock basicBlock, InstructionHandle handle, ConstantPoolGen cpg, ResourceValueFrame frame,
        RepositoryLookupFailureCallback lookupFailureCallback) {
    if (!mightCloseStream(basicBlock, handle, cpg))
        return false;

    Instruction ins = handle.getInstruction();

    if ((ins instanceof INVOKEVIRTUAL) || (ins instanceof INVOKEINTERFACE)) {
        // Does this instruction close the stream?
        InvokeInstruction inv = (InvokeInstruction) ins;

        if (!frame.isValid() || !getInstanceValue(frame, inv, cpg).isInstance())
            return false;

        // It's a close if the invoked class is any subtype of the stream
        // base class.
        // (Basically, we may not see the exact original stream class,
        // even though it's the same instance.)
        try {
            String classClosed = inv.getClassName(cpg);
            return Hierarchy.isSubtype(classClosed, streamBase) || Hierarchy.isSubtype(streamBase, classClosed) ;
        } catch (ClassNotFoundException e) {
            lookupFailureCallback.reportMissingClass(e);
            return false;
        }
    }

    return false;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:30,代码来源:Stream.java

示例13: visitINVOKEVIRTUAL

import org.apache.bcel.generic.INVOKEVIRTUAL; //导入依赖的package包/类
@Override
public void visitINVOKEVIRTUAL(INVOKEVIRTUAL obj) {
    if (returnsString(obj))
        handleInstanceMethod(obj);
    else
        super.visitINVOKEVIRTUAL(obj);
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:8,代码来源:FindRefComparison.java

示例14: isStringAppend

import org.apache.bcel.generic.INVOKEVIRTUAL; //导入依赖的package包/类
private boolean isStringAppend(Instruction ins, ConstantPoolGen cpg) {
    if (ins instanceof INVOKEVIRTUAL) {
        INVOKEVIRTUAL invoke = (INVOKEVIRTUAL) ins;

        if (invoke.getMethodName(cpg).equals("append") && invoke.getClassName(cpg).startsWith("java.lang.StringB")) {
            String sig = invoke.getSignature(cpg);
            char firstChar = sig.charAt(1);
            return firstChar == '[' || firstChar == 'L';
        }
    }

    return false;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:14,代码来源:FindSqlInjection.java

示例15: visitINVOKEVIRTUAL

import org.apache.bcel.generic.INVOKEVIRTUAL; //导入依赖的package包/类
/** Checks if the constraints of operands of the said instruction(s) are satisfied. */
public void visitINVOKEVIRTUAL(INVOKEVIRTUAL o){
    try {
	// INVOKEVIRTUAL is a LoadClass; the Class where the referenced method is declared in,
	// is therefore resolved/verified.
	// INVOKEVIRTUAL is an InvokeInstruction, the argument and return types are resolved/verified,
	// too. So are the allowed method names.
	String classname = o.getClassName(cpg);
	JavaClass jc = Repository.lookupClass(classname);
	Method[] ms = jc.getMethods();
	Method m = null;
	for (int i=0; i<ms.length; i++){
		if ( (ms[i].getName().equals(o.getMethodName(cpg))) &&
		     (Type.getReturnType(ms[i].getSignature()).equals(o.getReturnType(cpg))) &&
		     (objarrayequals(Type.getArgumentTypes(ms[i].getSignature()), o.getArgumentTypes(cpg))) ){
			m = ms[i];
			break;
		}
	}
	if (m == null){
		constraintViolated(o, "Referenced method '"+o.getMethodName(cpg)+"' with expected signature '"+o.getSignature(cpg)+"' not found in class '"+jc.getClassName()+"'. The native verifier does allow the method to be declared in some superclass or implemented interface, which the Java Virtual Machine Specification, Second Edition does not.");
	}
	if (! (jc.isClass())){
		constraintViolated(o, "Referenced class '"+jc.getClassName()+"' is an interface, but not a class as expected.");
	}
			
    } catch (ClassNotFoundException e) {
	// FIXME: maybe not the best way to handle this
	throw new AssertionViolatedException("Missing class: " + e.toString());
    }
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:32,代码来源:Pass3aVerifier.java


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