本文整理汇总了Java中org.apache.bcel.verifier.VerificationResult类的典型用法代码示例。如果您正苦于以下问题:Java VerificationResult类的具体用法?Java VerificationResult怎么用?Java VerificationResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
VerificationResult类属于org.apache.bcel.verifier包,在下文中一共展示了VerificationResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
}
}
}
示例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+"'.");
}
}
}
示例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 + "'.");
}
}
}
示例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()));
}
}
示例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+"'.");
}
}
}
示例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];
}
示例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());
}
}
示例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+"'.");
}
}
}
示例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 + "'.");
}
}
}
示例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.");
}
}
}
}
示例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 + "'.");
}
}
}
示例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());
}
}
示例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());
}
}
示例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() + "'.");
}
}
}
示例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.");
}
}
}
}