/** Used to load in and return the myOwner-matching JavaClass object when needed. Avoids loading in a class file when it's not really needed! */ private JavaClass getJavaClass(){ if (jc == null){ jc = Repository.lookupClass(myOwner.getClassName()); } return jc; }
/** * Used to load in and return the myOwner-matching JavaClass object when needed. * Avoids loading in a class file when it's not really needed! */ private JavaClass getJavaClass() { if (jc == null) { try { jc = Repository.lookupClass(myOwner.getClassName()); } catch (final ClassNotFoundException e) { // FIXME: currently, Pass1Verifier treats jc == null as a special // case, so we don't need to do anything here. A better solution // would be to simply throw the ClassNotFoundException // out of this method. } } return jc; }
public synchronized void update(String s){ int size = listeners.size(); Verifier[] verifiers = VerifierFactory.getVerifiers(); int num_of_verifiers = verifiers.length; cache.clear(); for (int i=0; i<num_of_verifiers; i++) { cache.add(verifiers[i].getClassName()); } for (int i=0; i<size; i++){ ListDataEvent e = new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, 0, num_of_verifiers-1); ((javax.swing.event.ListDataListener) (listeners.get(i))).contentsChanged(e); } }
@Override public synchronized void update(final String s) { final Verifier[] verifiers = VerifierFactory.getVerifiers(); final int num_of_verifiers = verifiers.length; cache.clear(); for (final Verifier verifier : verifiers) { cache.add(verifier.getClassName()); } for (final ListDataListener listener : listeners) { final ListDataEvent e = new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, 0, num_of_verifiers - 1); listener.contentsChanged(e); } }
/** * Ensures that the constant pool entries satisfy the static constraints * as described in The Java Virtual Machine Specification, 2nd Edition. * * @throws ClassConstraintException otherwise. */ private void constant_pool_entries_satisfy_static_constraints(){ // Most of the consistency is handled internally by BCEL; here // we only have to verify if the indices of the constants point // to constants of the appropriate type and such. JavaClass jc = Repository.lookupClass(myOwner.getClassName()); new CPESSC_Visitor(jc); // constructor implicitely traverses jc }
final JavaClass jc = Repository.lookupClass(v.getClassName()); for (int i = 0; i < jc.getMethods().length; i++) { vr = v.doPass3a(i); if (vr != VerificationResult.VR_OK) { System.out.println(v.getClassName() + ", Pass 3a, method " + i + " ['" + jc.getMethods()[i] + "']:\n" + vr); System.out.println(v.getClassName() + ", Pass 3b, method " + i + " ['" + jc.getMethods()[i] + "']:\n" + vr); System.err.println("Could not find class " + v.getClassName() + " in Repository");
public void update(String classname){ System.gc(); // avoid swapping if possible. for (int i=0; i<indent; i++){ System.out.print(" "); } System.out.println(classname); indent += 1; Verifier v = VerifierFactory.getVerifier(classname); VerificationResult vr; vr = v.doPass1(); if (vr != VerificationResult.VR_OK) //System.exit(1); System.out.println("Pass 1:\n"+vr); vr = v.doPass2(); if (vr != VerificationResult.VR_OK) //System.exit(1); System.out.println("Pass 2:\n"+vr); if (vr == VerificationResult.VR_OK){ JavaClass jc = Repository.lookupClass(v.getClassName()); for (int i=0; i<jc.getMethods().length; i++){ vr = v.doPass3a(i); if (vr != VerificationResult.VR_OK) //System.exit(1); System.out.println(v.getClassName()+", Pass 3a, method "+i+" ['"+jc.getMethods()[i]+"']:\n"+vr); vr = v.doPass3b(i); if (vr != VerificationResult.VR_OK) //System.exit(1); System.out.println(v.getClassName()+", Pass 3b, method "+i+" ['"+jc.getMethods()[i]+"']:\n"+vr); } } indent -= 1; }
synchronized void pass3bJList_valueChanged( final ListSelectionEvent e ) { if (e.getValueIsAdjusting()) { return; } final Verifier v = VerifierFactory.getVerifier(current_class); final StringBuilder all3bmsg = new StringBuilder(); boolean all3bok = true; boolean rejected = false; for (int i = 0; i < pass3bJList.getModel().getSize(); i++) { if (pass3bJList.isSelectedIndex(i)) { final VerificationResult vr = v.doPass3b(i); if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED) { all3bok = false; rejected = true; } JavaClass jc = null; try { jc = Repository.lookupClass(v.getClassName()); all3bmsg.append("Method '").append(jc.getMethods()[i]).append("': ") .append(vr.getMessage().replace('\n', ' ')).append("\n\n"); } catch (final ClassNotFoundException ex) { // FIXME: handle the error ex.printStackTrace(); } } } pass3bTextPane.setText(all3bmsg.toString()); pass3bTextPane.setBackground(all3bok ? Color.green : (rejected ? Color.red : Color.yellow)); }
synchronized void pass3aJList_valueChanged( final ListSelectionEvent e ) { if (e.getValueIsAdjusting()) { return; } final Verifier v = VerifierFactory.getVerifier(current_class); final StringBuilder all3amsg = new StringBuilder(); boolean all3aok = true; boolean rejected = false; for (int i = 0; i < pass3aJList.getModel().getSize(); i++) { if (pass3aJList.isSelectedIndex(i)) { final VerificationResult vr = v.doPass3a(i); if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED) { all3aok = false; rejected = true; } JavaClass jc = null; try { jc = Repository.lookupClass(v.getClassName()); all3amsg.append("Method '").append(jc.getMethods()[i]).append("': ") .append(vr.getMessage().replace('\n', ' ') ).append("\n\n"); } catch (final ClassNotFoundException ex) { // FIXME: handle the error ex.printStackTrace(); } } } pass3aTextPane.setText(all3amsg.toString()); pass3aTextPane.setBackground(all3aok ? Color.green : (rejected ? Color.red : Color.yellow)); }
/** * Ensures that the constant pool entries satisfy the static constraints * as described in The Java Virtual Machine Specification, 2nd Edition. * * @throws ClassConstraintException otherwise. */ private void constant_pool_entries_satisfy_static_constraints() { try { // Most of the consistency is handled internally by BCEL; here // we only have to verify if the indices of the constants point // to constants of the appropriate type and such. final JavaClass jc = Repository.lookupClass(myOwner.getClassName()); new CPESSC_Visitor(jc); // constructor implicitly traverses jc } catch (final ClassNotFoundException e) { // FIXME: this might not be the best way to handle missing classes. throw new AssertionViolatedException("Missing class: " + e, e); } }
synchronized void pass3bJList_valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) return; Verifier v = VerifierFactory.getVerifier(current_class); String all3bmsg = ""; boolean all3bok = true; boolean rejected = false; for (int i=0; i<pass3bJList.getModel().getSize(); i++){ if (pass3bJList.isSelectedIndex(i)){ VerificationResult vr = v.doPass3b(i); if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED){ all3bok = false; rejected = true; } all3bmsg += "Method '"+Repository.lookupClass(v.getClassName()).getMethods()[i]+"': "+vr.getMessage().replace('\n',' ')+"\n\n"; } } pass3bTextPane.setText(all3bmsg); pass3bTextPane.setBackground(all3bok? Color.green : (rejected? Color.red : Color.yellow)); }
/** * Utility method to return the max_locals value of the method verified * by the surrounding Pass3aVerifier instance. */ private int max_locals(){ return Repository.lookupClass(myOwner.getClassName()).getMethods()[method_no].getCode().getMaxLocals(); }
synchronized void pass3aJList_valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) return; Verifier v = VerifierFactory.getVerifier(current_class); String all3amsg = ""; boolean all3aok = true; boolean rejected = false; for (int i=0; i<pass3aJList.getModel().getSize(); i++){ if (pass3aJList.isSelectedIndex(i)){ VerificationResult vr = v.doPass3a(i); if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED){ all3aok = false; rejected = true; } all3amsg += "Method '"+Repository.lookupClass(v.getClassName()).getMethods()[i]+"': "+vr.getMessage().replace('\n',' ')+"\n\n"; } } pass3aTextPane.setText(all3amsg); pass3aTextPane.setBackground(all3aok? Color.green : (rejected? Color.red : Color.yellow)); }
/** * Utility method to return the max_locals value of the method verified * by the surrounding Pass3aVerifier instance. */ private int max_locals() { try { return Repository.lookupClass(myOwner.getClassName()).getMethods()[method_no].getCode().getMaxLocals(); } catch (final ClassNotFoundException e) { // FIXME: maybe not the best way to handle this throw new AssertionViolatedException("Missing class: " + e, e); } }
/** * Ensures that the ConstantCP-subclassed entries of the constant * pool are valid. According to "Yellin: Low Level Security in Java", * this method does not verify the existence of referenced entities * (such as classes) but only the formal correctness (such as well-formed * signatures). * The visitXXX() methods throw ClassConstraintException instances otherwise. * <B>Precondition: index-style cross referencing in the constant * pool must be valid. Simply invoke constant_pool_entries_satisfy_static_constraints() * before.</B> * * @throws ClassConstraintException otherwise. * @see #constant_pool_entries_satisfy_static_constraints() */ private void field_and_method_refs_are_valid(){ JavaClass jc = Repository.lookupClass(myOwner.getClassName()); DescendingVisitor v = new DescendingVisitor(jc, new FAMRAV_Visitor(jc)); v.visit(); }
/** Checks if the constraints of operands of the said instruction(s) are satisfied. */ public void visitPUTSTATIC(PUTSTATIC o){ String field_name = o.getFieldName(cpg); JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName()); Field[] fields = jc.getFields(); Field f = null; for (int i=0; i<fields.length; i++){ if (fields[i].getName().equals(field_name)){ f = fields[i]; break; } } if (f == null){ throw new AssertionViolatedException("Field not found?!?"); } if (f.isFinal()){ if (!(myOwner.getClassName().equals(o.getClassType(cpg).getClassName()))){ constraintViolated(o, "Referenced field '"+f+"' is final and must therefore be declared in the current class '"+myOwner.getClassName()+"' which is not the case: it is declared in '"+o.getClassType(cpg).getClassName()+"'."); } } if (! (f.isStatic())){ constraintViolated(o, "Referenced field '"+f+"' is not static which it should be."); } String meth_name = Repository.lookupClass(myOwner.getClassName()).getMethods()[method_no].getName(); // If it's an interface, it can be set only in <clinit>. if ((!(jc.isClass())) && (!(meth_name.equals(Constants.STATIC_INITIALIZER_NAME)))){ constraintViolated(o, "Interface field '"+f+"' must be set in a '"+Constants.STATIC_INITIALIZER_NAME+"' method."); } }
JavaClass jc = Repository.lookupClass(myOwner.getClassName());
/** * Ensures that the ConstantCP-subclassed entries of the constant * pool are valid. According to "Yellin: Low Level Security in Java", * this method does not verify the existence of referenced entities * (such as classes) but only the formal correctness (such as well-formed * signatures). * The visitXXX() methods throw ClassConstraintException instances otherwise. * <B>Precondition: index-style cross referencing in the constant * pool must be valid. Simply invoke constant_pool_entries_satisfy_static_constraints() * before.</B> * * @throws ClassConstraintException otherwise. * @see #constant_pool_entries_satisfy_static_constraints() */ private void field_and_method_refs_are_valid() { try { final JavaClass jc = Repository.lookupClass(myOwner.getClassName()); final DescendingVisitor v = new DescendingVisitor(jc, new FAMRAV_Visitor(jc)); v.visit(); } catch (final ClassNotFoundException e) { // FIXME: this might not be the best way to handle missing classes. throw new AssertionViolatedException("Missing class: " + e, e); } }
if (!(myOwner.getClassName().equals(getObjectType(o).getClassName()))) { constraintViolated(o, "Referenced field '"+f+"' is final and must therefore be declared in the current class '"+ myOwner.getClassName()+"' which is not the case: it is declared in '"+o.getReferenceType(cpg)+"'."); final String meth_name = Repository.lookupClass(myOwner.getClassName()).getMethods()[method_no].getName();
ConstantPoolGen cpg = new ConstantPoolGen(Repository.lookupClass(myOwner.getClassName()).getConstantPool()); InstOperandConstraintVisitor v = new InstOperandConstraintVisitor(cpg);