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