1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.bcel.verifier;
18
19 import org.apache.bcel.Repository;
20 import org.apache.bcel.classfile.JavaClass;
21 import org.apache.bcel.classfile.Utility;
22
23
24
25
26
27 public class TransitiveHull implements VerifierFactoryObserver {
28
29
30
31
32
33 public static void main(final String[] args) {
34 if (args.length != 1) {
35 System.out.println("Need exactly one argument: The root class to verify.");
36 System.exit(1);
37 }
38 final int dotclasspos = args[0].lastIndexOf(JavaClass.EXTENSION);
39 if (dotclasspos != -1) {
40 args[0] = args[0].substring(0, dotclasspos);
41 }
42 args[0] = Utility.pathToPackage(args[0]);
43 final TransitiveHull th = new TransitiveHull();
44 VerifierFactory.attach(th);
45 VerifierFactory.getVerifier(args[0]);
46 VerifierFactory.detach(th);
47 }
48
49
50 private int indent;
51
52
53 private TransitiveHull() {
54 }
55
56
57 @Override
58 public void update(final String className) {
59 System.gc();
60 for (int i = 0; i < indent; i++) {
61 System.out.print(" ");
62 }
63 System.out.println(className);
64 indent += 1;
65 final Verifier v = VerifierFactory.getVerifier(className);
66 VerificationResult vr;
67 vr = v.doPass1();
68 if (vr != VerificationResult.VR_OK) {
69 System.out.println("Pass 1:\n" + vr);
70 }
71 vr = v.doPass2();
72 if (vr != VerificationResult.VR_OK) {
73 System.out.println("Pass 2:\n" + vr);
74 }
75 if (vr == VerificationResult.VR_OK) {
76 try {
77 final JavaClass jc = Repository.lookupClass(v.getClassName());
78 for (int i = 0; i < jc.getMethods().length; i++) {
79 vr = v.doPass3a(i);
80 if (vr != VerificationResult.VR_OK) {
81 System.out.println(v.getClassName() + ", Pass 3a, method " + i + " ['" + jc.getMethods()[i] + "']:\n" + vr);
82 }
83 vr = v.doPass3b(i);
84 if (vr != VerificationResult.VR_OK) {
85 System.out.println(v.getClassName() + ", Pass 3b, method " + i + " ['" + jc.getMethods()[i] + "']:\n" + vr);
86 }
87 }
88 } catch (final ClassNotFoundException e) {
89 System.err.println("Could not find class " + v.getClassName() + " in Repository");
90 }
91 }
92 indent -= 1;
93 }
94 }