1 package com.sun.org.apache.bcel.internal.verifier; 2 3 56 57 import com.sun.org.apache.bcel.internal.*; 58 import com.sun.org.apache.bcel.internal.classfile.*; 59 import com.sun.org.apache.bcel.internal.generic.*; 60 import com.sun.org.apache.bcel.internal.util.*; 61 import com.sun.org.apache.bcel.internal.verifier.statics.*; 62 import com.sun.org.apache.bcel.internal.verifier.structurals.*; 63 import com.sun.org.apache.bcel.internal.verifier.exc.*; 64 import com.sun.org.apache.bcel.internal.verifier.exc.Utility; import java.util.ArrayList ; 66 import java.util.HashMap ; 67 import java.util.Iterator ; 68 69 83 public class Verifier{ 84 87 private final String classname; 88 89 90 private Pass1Verifier p1v; 91 92 private Pass2Verifier p2v; 93 94 private HashMap p3avs = new HashMap (); 95 96 private HashMap p3bvs = new HashMap (); 97 98 99 public VerificationResult doPass1(){ 100 if (p1v == null){ 101 p1v = new Pass1Verifier(this); 102 } 103 return p1v.verify(); 104 } 105 106 107 public VerificationResult doPass2(){ 108 if (p2v == null){ 109 p2v = new Pass2Verifier(this); 110 } 111 return p2v.verify(); 112 } 113 114 115 public VerificationResult doPass3a(int method_no){ 116 String key = Integer.toString(method_no); 117 Pass3aVerifier p3av; 118 p3av = (Pass3aVerifier) (p3avs.get(key)); 119 if (p3avs.get(key) == null){ 120 p3av = new Pass3aVerifier(this, method_no); 121 p3avs.put(key, p3av); 122 } 123 return p3av.verify(); 124 } 125 126 127 public VerificationResult doPass3b(int method_no){ 128 String key = Integer.toString(method_no); 129 Pass3bVerifier p3bv; 130 p3bv = (Pass3bVerifier) (p3bvs.get(key)); 131 if (p3bvs.get(key) == null){ 132 p3bv = new Pass3bVerifier(this, method_no); 133 p3bvs.put(key, p3bv); 134 } 135 return p3bv.verify(); 136 } 137 138 141 private Verifier(){ 142 classname = ""; } 145 150 Verifier(String fully_qualified_classname){ 151 classname = fully_qualified_classname; 152 flush(); 153 } 154 155 162 public final String getClassName(){ 163 return classname; 164 } 165 166 172 public void flush(){ 173 p1v = null; 174 p2v = null; 175 p3avs.clear(); 176 p3bvs.clear(); 177 } 178 179 183 public String [] getMessages(){ 184 ArrayList messages = new ArrayList (); 185 186 if (p1v != null){ 187 String [] p1m = p1v.getMessages(); 188 for (int i=0; i<p1m.length; i++){ 189 messages.add("Pass 1: "+p1m[i]); 190 } 191 } 192 if (p2v != null){ 193 String [] p2m = p2v.getMessages(); 194 for (int i=0; i<p2m.length; i++){ 195 messages.add("Pass 2: "+p2m[i]); 196 } 197 } 198 Iterator p3as = p3avs.values().iterator(); 199 while (p3as.hasNext()){ 200 Pass3aVerifier pv = (Pass3aVerifier) p3as.next(); 201 String [] p3am = pv.getMessages(); 202 int meth = pv.getMethodNo(); 203 for (int i=0; i<p3am.length; i++){ 204 messages.add("Pass 3a, method "+meth+" ('"+Repository.lookupClass(classname).getMethods()[meth]+"'): "+p3am[i]); 205 } 206 } 207 Iterator p3bs = p3bvs.values().iterator(); 208 while (p3bs.hasNext()){ 209 Pass3bVerifier pv = (Pass3bVerifier) p3bs.next(); 210 String [] p3bm = pv.getMessages(); 211 int meth = pv.getMethodNo(); 212 for (int i=0; i<p3bm.length; i++){ 213 messages.add("Pass 3b, method "+meth+" ('"+Repository.lookupClass(classname).getMethods()[meth]+"'): "+p3bm[i]); 214 } 215 } 216 217 String [] ret = new String [messages.size()]; 218 for (int i=0; i< messages.size(); i++){ 219 ret[i] = (String ) messages.get(i); 220 } 221 222 return ret; 223 } 224 225 235 public static void _main(String [] args){ 236 System.out.println("JustIce by Enver Haase, (C) 2001. http://bcel.sourceforge.net\n"); 237 for(int k=0; k < args.length; k++) { 238 239 if (args[k].endsWith(".class")){ 240 int dotclasspos = args[k].lastIndexOf(".class"); 241 if (dotclasspos != -1) args[k] = args[k].substring(0,dotclasspos); 242 } 243 244 args[k] = args[k].replace('/', '.'); 245 246 System.out.println("Now verifiying: "+args[k]+"\n"); 247 248 Verifier v = VerifierFactory.getVerifier(args[k]); 249 VerificationResult vr; 250 251 vr = v.doPass1(); 252 System.out.println("Pass 1:\n"+vr); 253 254 vr = v.doPass2(); 255 System.out.println("Pass 2:\n"+vr); 256 257 if (vr == VerificationResult.VR_OK){ 258 JavaClass jc = Repository.lookupClass(args[k]); 259 for (int i=0; i<jc.getMethods().length; i++){ 260 vr = v.doPass3a(i); 261 System.out.println("Pass 3a, method "+i+" ['"+jc.getMethods()[i]+"']:\n"+vr); 262 263 vr = v.doPass3b(i); 264 System.out.println("Pass 3b, method number "+i+" ['"+jc.getMethods()[i]+"']:\n"+vr); 265 } 266 } 267 268 System.out.println("Warnings:"); 269 String [] warnings = v.getMessages(); 270 if (warnings.length == 0) System.out.println("<none>"); 271 for (int j=0; j<warnings.length; j++){ 272 System.out.println(warnings[j]); 273 } 274 275 System.out.println("\n"); 276 277 v.flush(); 279 Repository.clearCache(); 280 System.gc(); 281 } 282 } 283 } 284 | Popular Tags |