• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java VerificationResult类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: verify

import org.apache.bcel.verifier.VerificationResult; //导入依赖的package包/类
/**
 * Verify the integrity of the jar file.
 * 
 * @throws IOException
 * @throws ClassFormatException
 */
private void verify() throws ClassFormatException, IOException {
	for (JavaClass cls : bcelClasses) {
		Verifier verifier = VerifierFactory.getVerifier(cls.getClassName());
		Method[] methods = cls.getMethods();
		for (int i = 0; i < methods.length; i++) {
			VerificationResult vr;
			// Do a pass 3a for the constructor of java.lang.Object because
			// we are using an uninitialized "this".
			if (cls.getClassName().equals(Names.JAVA_LANG_OBJECT)
					&& methods[i].getName().equals(SootMethod.constructorName)) {
				vr = verifier.doPass3a(i);
			} else {
				vr = verifier.doPass3b(i);
			}

			Assertions.verificationResultOKAssertion(vr, cls.getClassName(), methods[i].getName());
		}
	}
}
 
开发者ID:karimhamdanali,项目名称:averroes,代码行数:26,代码来源:JarFile.java


示例2: visitFieldInstruction

import org.apache.bcel.verifier.VerificationResult; //导入依赖的package包/类
/**
* Ensures the general preconditions of a FieldInstruction instance.
*/
public void visitFieldInstruction(FieldInstruction o){
	// visitLoadClass(o) has been called before: Every FieldOrMethod
	// implements LoadClass.
	// visitCPInstruction(o) has been called before.
// A FieldInstruction may be: GETFIELD, GETSTATIC, PUTFIELD, PUTSTATIC 
	Constant c = cpg.getConstant(o.getIndex());
	if (!(c instanceof ConstantFieldref)){
		constraintViolated(o, "Index '"+o.getIndex()+"' should refer to a CONSTANT_Fieldref_info structure, but refers to '"+c+"'.");
	}
	// the o.getClassType(cpg) type has passed pass 2; see visitLoadClass(o).
	Type t = o.getType(cpg);
	if (t instanceof ObjectType){
		String name = ((ObjectType)t).getClassName();
		Verifier v = VerifierFactory.getVerifier( name );
		VerificationResult vr = v.doPass2();
		if (vr.getStatus() != VerificationResult.VERIFIED_OK){
			constraintViolated((Instruction) o, "Class '"+name+"' is referenced, but cannot be loaded and resolved: '"+vr+"'.");
		}
	}
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:24,代码来源:InstConstraintVisitor.java


示例3: visitFieldInstruction

import org.apache.bcel.verifier.VerificationResult; //导入依赖的package包/类
/**
 * Ensures the general preconditions of a FieldInstruction instance.
 */
public void visitFieldInstruction(FieldInstruction o) {
    // visitLoadClass(o) has been called before: Every FieldOrMethod
    // implements LoadClass.
    // visitCPInstruction(o) has been called before.
    // A FieldInstruction may be: GETFIELD, GETSTATIC, PUTFIELD, PUTSTATIC
    Constant c = cpg.getConstant(o.getIndex());
    if (!(c instanceof ConstantFieldref)) {
        constraintViolated(o, "Index '" + o.getIndex() + "' should refer to a CONSTANT_Fieldref_info structure, but refers to '" + c + "'.");
    }
    // the o.getClassType(cpg) type has passed pass 2; see visitLoadClass(o).
    Type t = o.getType(cpg);
    if (t instanceof ObjectType) {
        String name = ((ObjectType) t).getClassName();
        Verifier v = VerifierFactory.getVerifier(name);
        VerificationResult vr = v.doPass2();
        if (vr.getStatus() != VerificationResult.VERIFIED_OK) {
            constraintViolated(o, "Class '" + name + "' is referenced, but cannot be loaded and resolved: '" + vr + "'.");
        }
    }
}
 
开发者ID:miuirussia,项目名称:KJBE,代码行数:24,代码来源:InstConstraintVisitor.java


示例4: verificationResultOKAssertion

import org.apache.bcel.verifier.VerificationResult; //导入依赖的package包/类
/**
 * Create an assertion that a {@link VerificationResult} has the value {@value VerificationResult#VR_OK}. This means
 * that BCEL successfully verified the class file of the given class name.
 * 
 * @param verificationResult
 * @param className
 * @param methodName
 */
public static void verificationResultOKAssertion(VerificationResult verificationResult, String className,
		String methodName) {
	if (!verificationResult.equals(VerificationResult.VR_OK)) {
		throw new AssertionError(System.getProperty("line.separator").concat(className)
				.concat(System.getProperty("line.separator")).concat(methodName)
				.concat(System.getProperty("line.separator")).concat(verificationResult.toString()));
	}
}
 
开发者ID:karimhamdanali,项目名称:averroes,代码行数:17,代码来源:Assertions.java


示例5: visitLoadClass

import org.apache.bcel.verifier.VerificationResult; //导入依赖的package包/类
/**
 * Assures the generic preconditions of a LoadClass instance.
 * The referenced class is loaded and pass2-verified.
 */
public void visitLoadClass(LoadClass o){
	ObjectType t = o.getLoadClassType(cpg);
	if (t != null){// null means "no class is loaded"
		Verifier v = VerifierFactory.getVerifier(t.getClassName());
		VerificationResult vr = v.doPass1();
		if (vr.getStatus() != VerificationResult.VERIFIED_OK){
			constraintViolated((Instruction) o, "Class '"+o.getLoadClassType(cpg).getClassName()+"' is referenced, but cannot be loaded: '"+vr+"'.");
		}
	}
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:15,代码来源:Pass3aVerifier.java


示例6: getLocalVariablesInfo

import org.apache.bcel.verifier.VerificationResult; //导入依赖的package包/类
/**
 * Returns a LocalVariablesInfo object containing information
 * about the usage of the local variables in the Code attribute
 * of the said method or <B>null</B> if the class file this
 * Pass2Verifier operates on could not be pass-2-verified correctly.
 * The method number method_nr is the method you get using
 * <B>Repository.lookupClass(myOwner.getClassname()).getMethods()[method_nr];</B>.
 * You should not add own information. Leave that to JustIce.
 */
public LocalVariablesInfo getLocalVariablesInfo(int method_nr){
	if (this.verify() != VerificationResult.VR_OK) {
           return null; // It's cached, don't worry.
       }
	if (method_nr < 0 || method_nr >= localVariablesInfos.length){
		throw new AssertionViolatedException("Method number out of range.");
	}
	return localVariablesInfos[method_nr];
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:19,代码来源:Pass2Verifier.java


示例7: every_class_has_an_accessible_superclass

import org.apache.bcel.verifier.VerificationResult; //导入依赖的package包/类
/**
 * Ensures that every class has a super class and that
 * <B>final</B> classes are not subclassed.
 * This means, the class this Pass2Verifier operates
 * on has proper super classes (transitively) up to
 * java.lang.Object.
 * The reason for really loading (and Pass1-verifying)
 * all of those classes here is that we need them in
 * Pass2 anyway to verify no final methods are overridden
 * (that could be declared anywhere in the ancestor hierarchy).
 *
 * @throws ClassConstraintException otherwise.
 */
private void every_class_has_an_accessible_superclass(){
    try {
	Set hs = new HashSet(); // save class names to detect circular inheritance
	JavaClass jc = Repository.lookupClass(myOwner.getClassName());
	int supidx = -1;

	while (supidx != 0){
		supidx = jc.getSuperclassNameIndex();
	
		if (supidx == 0){
			if (jc != Repository.lookupClass(Type.OBJECT.getClassName())){
				throw new ClassConstraintException("Superclass of '"+jc.getClassName()+"' missing but not "+Type.OBJECT.getClassName()+" itself!");
			}
		}
		else{
			String supername = jc.getSuperclassName();
			if (! hs.add(supername)){	// If supername already is in the list
				throw new ClassConstraintException("Circular superclass hierarchy detected.");
			}
			Verifier v = VerifierFactory.getVerifier(supername);
			VerificationResult vr = v.doPass1();

			if (vr != VerificationResult.VR_OK){
				throw new ClassConstraintException("Could not load in ancestor class '"+supername+"'.");
			}
			jc = Repository.lookupClass(supername);

			if (jc.isFinal()){
				throw new ClassConstraintException("Ancestor class '"+supername+"' has the FINAL access modifier and must therefore not be subclassed.");
			}
		}
	}

    } catch (ClassNotFoundException e) {
	// FIXME: this might not be the best way to handle missing classes.
	throw new AssertionViolatedException("Missing class: " + e.toString());
    }
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:52,代码来源:Pass2Verifier.java


示例8: visitLoadClass

import org.apache.bcel.verifier.VerificationResult; //导入依赖的package包/类
/**
 * Assures the generic preconditions of a LoadClass instance.
 * The referenced class is loaded and pass2-verified.
 */
public void visitLoadClass(LoadClass o){
	ObjectType t = o.getLoadClassType(cpg);
	if (t != null){// null means "no class is loaded"
		Verifier v = VerifierFactory.getVerifier(t.getClassName());
		VerificationResult vr = v.doPass2();
		if (vr.getStatus() != VerificationResult.VERIFIED_OK){
			constraintViolated((Instruction) o, "Class '"+o.getLoadClassType(cpg).getClassName()+"' is referenced, but cannot be loaded and resolved: '"+vr+"'.");
		}
	}
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:15,代码来源:InstConstraintVisitor.java


示例9: visitLoadClass

import org.apache.bcel.verifier.VerificationResult; //导入依赖的package包/类
/**
 * Assures the generic preconditions of a LoadClass instance.
 * The referenced class is loaded and pass2-verified.
 */
public void visitLoadClass(LoadClass o) {
    ObjectType t = o.getLoadClassType(cpg);
    if (t != null) {// null means "no class is loaded"
        Verifier v = VerifierFactory.getVerifier(t.getClassName());
        VerificationResult vr = v.doPass1();
        if (vr.getStatus() != VerificationResult.VERIFIED_OK) {
            constraintViolated((Instruction) o, "Class '" + o.getLoadClassType(cpg).getClassName() + "' is referenced, but cannot be loaded: '" + vr + "'.");
        }
    }
}
 
开发者ID:miuirussia,项目名称:KJBE,代码行数:15,代码来源:Pass3aVerifier.java


示例10: every_class_has_an_accessible_superclass

import org.apache.bcel.verifier.VerificationResult; //导入依赖的package包/类
/**
 * Ensures that every class has a super class and that
 * <B>final</B> classes are not subclassed.
 * This means, the class this Pass2Verifier operates
 * on has proper super classes (transitively) up to
 * java.lang.Object.
 * The reason for really loading (and Pass1-verifying)
 * all of those classes here is that we need them in
 * Pass2 anyway to verify no final methods are overridden
 * (that could be declared anywhere in the ancestor hierarchy).
 *
 * @throws ClassConstraintException otherwise.
 */
private void every_class_has_an_accessible_superclass() {
    HashSet<String> hs = new HashSet<String>(); // save class names to detect circular inheritance
    JavaClass jc = Repository.lookupClass(myOwner.getClassName());
    int supidx = -1;

    while (supidx != 0) {
        supidx = jc.getSuperclassNameIndex();

        if (supidx == 0) {
            if (jc != Repository.lookupClass(Type.OBJECT.getClassName())) {
                throw new ClassConstraintException("Superclass of '" + jc.getClassName() + "' missing but not " + Type.OBJECT.getClassName() + " itself!");
            }
        } else {
            String supername = jc.getSuperclassName();
            if (!hs.add(supername)) {    // If supername already is in the list
                throw new ClassConstraintException("Circular superclass hierarchy detected.");
            }
            Verifier v = VerifierFactory.getVerifier(supername);
            VerificationResult vr = v.doPass1();

            if (vr != VerificationResult.VR_OK) {
                throw new ClassConstraintException("Could not load in ancestor class '" + supername + "'.");
            }
            jc = Repository.lookupClass(supername);

            if (jc.isFinal()) {
                throw new ClassConstraintException("Ancestor class '" + supername + "' has the FINAL access modifier and must therefore not be subclassed.");
            }
        }
    }
}
 
开发者ID:miuirussia,项目名称:KJBE,代码行数:45,代码来源:Pass2Verifier.java


示例11: visitLoadClass

import org.apache.bcel.verifier.VerificationResult; //导入依赖的package包/类
/**
 * Assures the generic preconditions of a LoadClass instance.
 * The referenced class is loaded and pass2-verified.
 */
public void visitLoadClass(LoadClass o) {
    ObjectType t = o.getLoadClassType(cpg);
    if (t != null) {// null means "no class is loaded"
        Verifier v = VerifierFactory.getVerifier(t.getClassName());
        VerificationResult vr = v.doPass2();
        if (vr.getStatus() != VerificationResult.VERIFIED_OK) {
            constraintViolated((Instruction) o, "Class '" + o.getLoadClassType(cpg).getClassName() + "' is referenced, but cannot be loaded and resolved: '" + vr + "'.");
        }
    }
}
 
开发者ID:miuirussia,项目名称:KJBE,代码行数:15,代码来源:InstConstraintVisitor.java


示例12: visitINVOKESTATIC

import org.apache.bcel.verifier.VerificationResult; //导入依赖的package包/类
/**
 * Ensures the specific preconditions of the said instruction.
 */
public void visitINVOKESTATIC(INVOKESTATIC o){
    try {
	// Method is not native, otherwise pass 3 would not happen.
	
	Type t = o.getType(cpg);
	if (t instanceof ObjectType){
		String name = ((ObjectType)t).getClassName();
		Verifier v = VerifierFactory.getVerifier( name );
		VerificationResult vr = v.doPass2();
		if (vr.getStatus() != VerificationResult.VERIFIED_OK){
			constraintViolated((Instruction) o, "Class '"+name+"' is referenced, but cannot be loaded and resolved: '"+vr+"'.");
		}
	}

	Type[] argtypes = o.getArgumentTypes(cpg);
	int nargs = argtypes.length;
	
	for (int i=nargs-1; i>=0; i--){
		Type fromStack = stack().peek( (nargs-1) - i );	// 0 to nargs-1
		Type fromDesc = argtypes[i];
		if (fromDesc == Type.BOOLEAN ||
				fromDesc == Type.BYTE ||
				fromDesc == Type.CHAR ||
				fromDesc == Type.SHORT){
			fromDesc = Type.INT;
		}
		if (! fromStack.equals(fromDesc)){
			if (fromStack instanceof ReferenceType && fromDesc instanceof ReferenceType){
				ReferenceType rFromStack = (ReferenceType) fromStack;
				ReferenceType rFromDesc = (ReferenceType) fromDesc;
				// TODO: This check can possibly only be done using Staerk-et-al's "set of object types"
				// instead of a "wider cast object type" created during verification.
				if ( ! rFromStack.isAssignmentCompatibleWith(rFromDesc) ){
					constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack (which is not assignment compatible).");
				}
                   referenceTypeIsInitialized(o, rFromStack);
			}
			else{
				constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack.");
			}
		}
	}
    } catch (ClassNotFoundException e) {
	// FIXME: maybe not the best way to handle this
	throw new AssertionViolatedException("Missing class: " + e.toString());
    }
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:51,代码来源:InstConstraintVisitor.java


示例13: visitINVOKEVIRTUAL

import org.apache.bcel.verifier.VerificationResult; //导入依赖的package包/类
/**
 * Ensures the specific preconditions of the said instruction.
 */
public void visitINVOKEVIRTUAL(INVOKEVIRTUAL o){
    try {
	// the o.getClassType(cpg) type has passed pass 2; see visitLoadClass(o).

	Type t = o.getType(cpg);
	if (t instanceof ObjectType){
		String name = ((ObjectType)t).getClassName();
		Verifier v = VerifierFactory.getVerifier( name );
		VerificationResult vr = v.doPass2();
		if (vr.getStatus() != VerificationResult.VERIFIED_OK){
			constraintViolated((Instruction) o, "Class '"+name+"' is referenced, but cannot be loaded and resolved: '"+vr+"'.");
		}
	}


	Type[] argtypes = o.getArgumentTypes(cpg);
	int nargs = argtypes.length;
	
	for (int i=nargs-1; i>=0; i--){
		Type fromStack = stack().peek( (nargs-1) - i );	// 0 to nargs-1
		Type fromDesc = argtypes[i];
		if (fromDesc == Type.BOOLEAN ||
				fromDesc == Type.BYTE ||
				fromDesc == Type.CHAR ||
				fromDesc == Type.SHORT){
			fromDesc = Type.INT;
		}
		if (! fromStack.equals(fromDesc)){
			if (fromStack instanceof ReferenceType && fromDesc instanceof ReferenceType){
				ReferenceType rFromStack = (ReferenceType) fromStack;
				ReferenceType rFromDesc = (ReferenceType) fromDesc;
				// TODO: This can possibly only be checked when using Staerk-et-al's "set of object types" instead
				// of a single "wider cast object type" created during verification.
				if ( ! rFromStack.isAssignmentCompatibleWith(rFromDesc) ){
					constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack (which is not assignment compatible).");
				}
                   referenceTypeIsInitialized(o, rFromStack);
			}
			else{
				constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack.");
			}
		}
	}
	
	Type objref = stack().peek(nargs);
	if (objref == Type.NULL){
		return;
	}
	if (! (objref instanceof ReferenceType) ){
		constraintViolated(o, "Expecting a reference type as 'objectref' on the stack, not a '"+objref+"'.");
	}
	referenceTypeIsInitialized(o, (ReferenceType) objref);
	if (!(objref instanceof ObjectType)){
		if (!(objref instanceof ArrayType)){
			constraintViolated(o, "Expecting an ObjectType as 'objectref' on the stack, not a '"+objref+"'."); // could be a ReturnaddressType
		}
		else{
			objref = GENERIC_ARRAY;
		}
	}
	
	String objref_classname = ((ObjectType) objref).getClassName();

	String theClass = o.getClassName(cpg);

	if ( ! Repository.instanceOf(objref_classname, theClass) ){
		constraintViolated(o, "The 'objref' item '"+objref+"' does not implement '"+theClass+"' as expected.");
	}	
    } catch (ClassNotFoundException e) {
	// FIXME: maybe not the best way to handle this
	throw new AssertionViolatedException("Missing class: " + e.toString());
    }
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:77,代码来源:InstConstraintVisitor.java


示例14: visitExceptionTable

import org.apache.bcel.verifier.VerificationResult; //导入依赖的package包/类
public void visitExceptionTable(ExceptionTable obj) {//vmspec2 4.7.4
    // incorrectly named, it's the Exceptions attribute (vmspec2 4.7.4)
    checkIndex(obj, obj.getNameIndex(), CONST_Utf8);

    String name = ((ConstantUtf8) cp.getConstant(obj.getNameIndex())).getBytes();
    if (!name.equals("Exceptions")) {
        throw new ClassConstraintException("The Exceptions attribute '" + tostring(obj) + "' is not correctly named 'Exceptions' but '" + name + "'.");
    }

    int[] exc_indices = obj.getExceptionIndexTable();

    for (int exc_indice : exc_indices) {
        checkIndex(obj, exc_indice, CONST_Class);

        ConstantClass cc = (ConstantClass) (cp.getConstant(exc_indice));
        checkIndex(cc, cc.getNameIndex(), CONST_Utf8); // cannot be sure this ConstantClass has already been visited (checked)!
        String cname = ((ConstantUtf8) cp.getConstant(cc.getNameIndex())).getBytes().replace('/', '.'); //convert internal notation on-the-fly to external notation

        Verifier v = VerifierFactory.getVerifier(cname);
        VerificationResult vr = v.doPass1();

        if (vr != VerificationResult.VR_OK) {
            throw new ClassConstraintException("Exceptions attribute '" + tostring(obj) + "' references '" + cname + "' as an Exception but it does not pass verification pass 1: " + vr);
        } else {
            // We cannot safely trust any other "instanceof" mechanism. We need to transitively verify
            // the ancestor hierarchy.
            JavaClass e = Repository.lookupClass(cname);
            JavaClass t = Repository.lookupClass(Type.THROWABLE.getClassName());
            JavaClass o = Repository.lookupClass(Type.OBJECT.getClassName());
            while (e != o) {
                if (e == t) break; // It's a subclass of Throwable, OKAY, leave.

                v = VerifierFactory.getVerifier(e.getSuperclassName());
                vr = v.doPass1();
                if (vr != VerificationResult.VR_OK) {
                    throw new ClassConstraintException("Exceptions attribute '" + tostring(obj) + "' references '" + cname + "' as an Exception but '" + e.getSuperclassName() + "' in the ancestor hierachy does not pass verification pass 1: " + vr);
                } else {
                    e = Repository.lookupClass(e.getSuperclassName());
                }
            }
            if (e != t)
                throw new ClassConstraintException("Exceptions attribute '" + tostring(obj) + "' references '" + cname + "' as an Exception but it is not a subclass of '" + t.getClassName() + "'.");
        }
    }
}
 
开发者ID:miuirussia,项目名称:KJBE,代码行数:46,代码来源:Pass2Verifier.java


示例15: visitINVOKESTATIC

import org.apache.bcel.verifier.VerificationResult; //导入依赖的package包/类
/**
 * Ensures the specific preconditions of the said instruction.
 */
public void visitINVOKESTATIC(INVOKESTATIC o) {
    // Method is not native, otherwise pass 3 would not happen.

    Type t = o.getType(cpg);
    if (t instanceof ObjectType) {
        String name = ((ObjectType) t).getClassName();
        Verifier v = VerifierFactory.getVerifier(name);
        VerificationResult vr = v.doPass2();
        if (vr.getStatus() != VerificationResult.VERIFIED_OK) {
            constraintViolated(o, "Class '" + name + "' is referenced, but cannot be loaded and resolved: '" + vr + "'.");
        }
    }

    Type[] argtypes = o.getArgumentTypes(cpg);
    int nargs = argtypes.length;

    for (int i = nargs - 1; i >= 0; i--) {
        Type fromStack = stack().peek((nargs - 1) - i);    // 0 to nargs-1
        Type fromDesc = argtypes[i];
        if (fromDesc == Type.BOOLEAN ||
                fromDesc == Type.BYTE ||
                fromDesc == Type.CHAR ||
                fromDesc == Type.SHORT) {
            fromDesc = Type.INT;
        }
        if (!fromStack.equals(fromDesc)) {
            if (fromStack instanceof ReferenceType && fromDesc instanceof ReferenceType) {
                ReferenceType rFromStack = (ReferenceType) fromStack;
                ReferenceType rFromDesc = (ReferenceType) fromDesc;
                // TODO: This check can possibly only be done using Staerk-et-al's "set of object types"
                // instead of a "wider cast object type" created during verification.
                if (!rFromStack.isAssignmentCompatibleWith(rFromDesc)) {
                    constraintViolated(o, "Expecting a '" + fromDesc + "' but found a '" + fromStack + "' on the stack (which is not assignment compatible).");
                }
            } else {
                constraintViolated(o, "Expecting a '" + fromDesc + "' but found a '" + fromStack + "' on the stack.");
            }
        }
    }
}
 
开发者ID:miuirussia,项目名称:KJBE,代码行数:44,代码来源:InstConstraintVisitor.java


示例16: visitINVOKEVIRTUAL

import org.apache.bcel.verifier.VerificationResult; //导入依赖的package包/类
/**
 * Ensures the specific preconditions of the said instruction.
 */
public void visitINVOKEVIRTUAL(INVOKEVIRTUAL o) {
    // the o.getClassType(cpg) type has passed pass 2; see visitLoadClass(o).

    Type t = o.getType(cpg);
    if (t instanceof ObjectType) {
        String name = ((ObjectType) t).getClassName();
        Verifier v = VerifierFactory.getVerifier(name);
        VerificationResult vr = v.doPass2();
        if (vr.getStatus() != VerificationResult.VERIFIED_OK) {
            constraintViolated(o, "Class '" + name + "' is referenced, but cannot be loaded and resolved: '" + vr + "'.");
        }
    }


    Type[] argtypes = o.getArgumentTypes(cpg);
    int nargs = argtypes.length;

    for (int i = nargs - 1; i >= 0; i--) {
        Type fromStack = stack().peek((nargs - 1) - i);    // 0 to nargs-1
        Type fromDesc = argtypes[i];
        if (fromDesc == Type.BOOLEAN ||
                fromDesc == Type.BYTE ||
                fromDesc == Type.CHAR ||
                fromDesc == Type.SHORT) {
            fromDesc = Type.INT;
        }
        if (!fromStack.equals(fromDesc)) {
            if (fromStack instanceof ReferenceType && fromDesc instanceof ReferenceType) {
                ReferenceType rFromStack = (ReferenceType) fromStack;
                ReferenceType rFromDesc = (ReferenceType) fromDesc;
                // TODO: This can possibly only be checked when using Staerk-et-al's "set of object types" instead
                // of a single "wider cast object type" created during verification.
                if (!rFromStack.isAssignmentCompatibleWith(rFromDesc)) {
                    constraintViolated(o, "Expecting a '" + fromDesc + "' but found a '" + fromStack + "' on the stack (which is not assignment compatible).");
                }
            } else {
                constraintViolated(o, "Expecting a '" + fromDesc + "' but found a '" + fromStack + "' on the stack.");
            }
        }
    }

    Type objref = stack().peek(nargs);
    if (objref == Type.NULL) {
        return;
    }
    if (!(objref instanceof ReferenceType)) {
        constraintViolated(o, "Expecting a reference type as 'objectref' on the stack, not a '" + objref + "'.");
    }
    referenceTypeIsInitialized(o, (ReferenceType) objref);
    if (!(objref instanceof ObjectType)) {
        if (!(objref instanceof ArrayType)) {
            constraintViolated(o, "Expecting an ObjectType as 'objectref' on the stack, not a '" + objref + "'."); // could be a ReturnaddressType
        } else {
            objref = GENERIC_ARRAY;
        }
    }

    String objref_classname = ((ObjectType) objref).getClassName();

    String theClass = o.getClassName(cpg);

    if (!Repository.instanceOf(objref_classname, theClass)) {
        constraintViolated(o, "The 'objref' item '" + objref + "' does not implement '" + theClass + "' as expected.");
    }
}
 
开发者ID:miuirussia,项目名称:KJBE,代码行数:69,代码来源:InstConstraintVisitor.java


示例17: do_verify

import org.apache.bcel.verifier.VerificationResult; //导入依赖的package包/类
/**
 * Pass 3b implements the data flow analysis as described in the Java Virtual
 * Machine Specification, Second Edition.
 * Later versions will use LocalVariablesInfo objects to verify if the
 * verifier-inferred types and the class file's debug information (LocalVariables
 * attributes) match [TODO].
 *
 * @see org.apache.bcel.verifier.statics.LocalVariablesInfo
 * @see org.apache.bcel.verifier.statics.Pass2Verifier#getLocalVariablesInfo(int)
 */
public VerificationResult do_verify() {
    if (!myOwner.doPass3a(method_no).equals(VerificationResult.VR_OK)) {
        return VerificationResult.VR_NOTYET;
    }

    // Pass 3a ran before, so it's safe to assume the JavaClass object is
    // in the BCEL repository.
    JavaClass jc = Repository.lookupClass(myOwner.getClassName());

    ConstantPoolGen constantPoolGen = new ConstantPoolGen(jc.getConstantPool());
    // Init Visitors
    InstConstraintVisitor icv = new InstConstraintVisitor();
    icv.setConstantPoolGen(constantPoolGen);

    ExecutionVisitor ev = new ExecutionVisitor();
    ev.setConstantPoolGen(constantPoolGen);

    Method[] methods = jc.getMethods(); // Method no "method_no" exists, we ran Pass3a before on it!

    try {

        MethodGen mg = new MethodGen(methods[method_no], myOwner.getClassName(), constantPoolGen);

        icv.setMethodGen(mg);

        ////////////// DFA BEGINS HERE ////////////////
        if (!(mg.isAbstract() || mg.isNative())) { // IF mg HAS CODE (See pass 2)

            ControlFlowGraph cfg = new ControlFlowGraph(mg);

            // Build the initial frame situation for this method.
            Frame f = new Frame(mg.getMaxLocals(), mg.getMaxStack());
            if (!mg.isStatic()) {
                if (mg.getName().equals(Constants.CONSTRUCTOR_NAME)) {
                    Frame._this = new UninitializedObjectType(new ObjectType(jc.getClassName()));
                    f.getLocals().set(0, Frame._this);
                } else {
                    Frame._this = null;
                    f.getLocals().set(0, new ObjectType(jc.getClassName()));
                }
            }
            Type[] argtypes = mg.getArgumentTypes();
            int twoslotoffset = 0;
            for (int j = 0; j < argtypes.length; j++) {
                if (argtypes[j] == Type.SHORT || argtypes[j] == Type.BYTE || argtypes[j] == Type.CHAR || argtypes[j] == Type.BOOLEAN) {
                    argtypes[j] = Type.INT;
                }
                f.getLocals().set(twoslotoffset + j + (mg.isStatic() ? 0 : 1), argtypes[j]);
                if (argtypes[j].getSize() == 2) {
                    twoslotoffset++;
                    f.getLocals().set(twoslotoffset + j + (mg.isStatic() ? 0 : 1), Type.UNKNOWN);
                }
            }
            circulationPump(cfg, cfg.contextOf(mg.getInstructionList().getStart()), f, icv, ev);
        }
    } catch (VerifierConstraintViolatedException ce) {
        ce.extendMessage("Constraint violated in method '" + methods[method_no] + "':\n", "");
        return new VerificationResult(VerificationResult.VERIFIED_REJECTED, ce.getMessage());
    } catch (RuntimeException re) {
        // These are internal errors

        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        re.printStackTrace(pw);

        throw new AssertionViolatedException("Some RuntimeException occured while verify()ing class '" + jc.getClassName() + "', method '" + methods[method_no] + "'. Original RuntimeException's stack trace:\n---\n" + sw + "---\n");
    }
    return VerificationResult.VR_OK;
}
 
开发者ID:miuirussia,项目名称:KJBE,代码行数:80,代码来源:Pass3bVerifier.java


示例18: getLocalVariablesInfo

import org.apache.bcel.verifier.VerificationResult; //导入依赖的package包/类
/**
 * Returns a LocalVariablesInfo object containing information
 * about the usage of the local variables in the Code attribute
 * of the said method or <B>null</B> if the class file this
 * Pass2Verifier operates on could not be pass-2-verified correctly.
 * The method number method_nr is the method you get using
 * <B>Repository.lookupClass(myOwner.getClassname()).getMethods()[method_nr];</B>.
 * You should not add own information. Leave that to JustIce.
 * @param method_nr
 */
public LocalVariablesInfo getLocalVariablesInfo(int method_nr) {
    if (this.verify() != VerificationResult.VR_OK) return null; // It's cached, don't worry.
    if (method_nr < 0 || method_nr >= localVariablesInfos.length) {
        throw new AssertionViolatedException("Method number out of range.");
    }
    return localVariablesInfos[method_nr];
}
 
开发者ID:miuirussia,项目名称:KJBE,代码行数:18,代码来源:Pass2Verifier.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ASTNode类代码示例发布时间:2022-05-22
下一篇:
Java KeyPairProvider类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap