1   package org.apache.bcel.verifier;
2   
3   /* ====================================================================
4    * The Apache Software License, Version 1.1
5    *
6    * Copyright (c) 2001 The Apache Software Foundation.  All rights
7    * reserved.
8    *
9    * Redistribution and use in source and binary forms, with or without
10   * modification, are permitted provided that the following conditions
11   * are met:
12   *
13   * 1. Redistributions of source code must retain the above copyright
14   *    notice, this list of conditions and the following disclaimer.
15   *
16   * 2. Redistributions in binary form must reproduce the above copyright
17   *    notice, this list of conditions and the following disclaimer in
18   *    the documentation and/or other materials provided with the
19   *    distribution.
20   *
21   * 3. The end-user documentation included with the redistribution,
22   *    if any, must include the following acknowledgment:
23   *       "This product includes software developed by the
24   *        Apache Software Foundation (http://www.apache.org/)."
25   *    Alternately, this acknowledgment may appear in the software itself,
26   *    if and wherever such third-party acknowledgments normally appear.
27   *
28   * 4. The names "Apache" and "Apache Software Foundation" and
29   *    "Apache BCEL" must not be used to endorse or promote products
30   *    derived from this software without prior written permission. For
31   *    written permission, please contact apache@apache.org.
32   *
33   * 5. Products derived from this software may not be called "Apache",
34   *    "Apache BCEL", nor may "Apache" appear in their name, without
35   *    prior written permission of the Apache Software Foundation.
36   *
37   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
41   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48   * SUCH DAMAGE.
49   * ====================================================================
50   *
51   * This software consists of voluntary contributions made by many
52   * individuals on behalf of the Apache Software Foundation.  For more
53   * information on the Apache Software Foundation, please see
54   * <http://www.apache.org/>.
55   */
56  
57  import org.apache.bcel.*;
58  import org.apache.bcel.classfile.*;
59  import org.apache.bcel.verifier.*;
60  import java.awt.Color;
61  
62  /***
63   * A class for simple graphical class file verification.
64   * Use the main(String []) method with fully qualified
65   * class names as arguments to use it as a stand-alone
66   * application.
67   * Use the VerifyDialog(String) constructor to use this
68   * class in your application.
69   * [This class was created using VisualAge for Java,
70   * but it does not work under VAJ itself (Version 3.02 JDK 1.2)]
71   * @version $Id: VerifyDialog.java,v 1.1.1.1 2001/10/29 20:00:33 jvanzyl Exp $
72   * @author <A HREF="http://www.inf.fu-berlin.de/~ehaase"/>Enver Haase</A>
73   * @see #main(String[])
74   * @see #VerifyDialog(String)
75   */
76  public class VerifyDialog extends javax.swing.JDialog {
77  	/*** Machine-generated. */
78  	private javax.swing.JPanel ivjJDialogContentPane = null;
79  	/*** Machine-generated. */
80  	private javax.swing.JPanel ivjPass1Panel = null;
81  	/*** Machine-generated. */
82  	private javax.swing.JPanel ivjPass2Panel = null;
83  	/*** Machine-generated. */
84  	private javax.swing.JPanel ivjPass3Panel = null;
85  	/*** Machine-generated. */
86  	private javax.swing.JButton ivjPass1Button = null;
87  	/*** Machine-generated. */
88  	private javax.swing.JButton ivjPass2Button = null;
89  	/*** Machine-generated. */
90  	private javax.swing.JButton ivjPass3Button = null;
91  	/*** Machine-generated. */
92  	IvjEventHandler ivjEventHandler = new IvjEventHandler();
93  
94  	/***
95  	 * The class to verify. Default set to 'java.lang.Object'
96  	 * in case this class is instantiated via one of the many
97  	 * machine-generated constructors.
98  	 */
99  	private String class_name = "java.lang.Object";
100 
101 	/***
102 	 * This field is here to count the number of open VerifyDialog
103 	 * instances so the JVM can be exited afer every Dialog had been
104 	 * closed.
105 	 */
106 	private static int classes_to_verify;
107 
108 /*** Machine-generated. */
109 class IvjEventHandler implements java.awt.event.ActionListener {
110 		public void actionPerformed(java.awt.event.ActionEvent e) {
111 			if (e.getSource() == VerifyDialog.this.getPass1Button()) 
112 				connEtoC1(e);
113 			if (e.getSource() == VerifyDialog.this.getPass2Button()) 
114 				connEtoC2(e);
115 			if (e.getSource() == VerifyDialog.this.getPass3Button()) 
116 				connEtoC3(e);
117 			if (e.getSource() == VerifyDialog.this.getFlushButton()) 
118 				connEtoC4(e);
119 		};
120 	};
121 	/*** Machine-generated. */
122 	private javax.swing.JButton ivjFlushButton = null;
123 /*** Machine-generated. */
124 public VerifyDialog() {
125 	super();
126 	initialize();
127 }
128 
129 /*** Machine-generated. */
130 public VerifyDialog(java.awt.Dialog owner) {
131 	super(owner);
132 }
133 
134 /*** Machine-generated. */
135 public VerifyDialog(java.awt.Dialog owner, String title) {
136 	super(owner, title);
137 }
138 
139 /*** Machine-generated. */
140 public VerifyDialog(java.awt.Dialog owner, String title, boolean modal) {
141 	super(owner, title, modal);
142 }
143 
144 /*** Machine-generated. */
145 public VerifyDialog(java.awt.Dialog owner, boolean modal) {
146 	super(owner, modal);
147 }
148 
149 /*** Machine-generated. */
150 public VerifyDialog(java.awt.Frame owner) {
151 	super(owner);
152 }
153 
154 /*** Machine-generated. */
155 public VerifyDialog(java.awt.Frame owner, String title) {
156 	super(owner, title);
157 }
158 
159 /*** Machine-generated. */
160 public VerifyDialog(java.awt.Frame owner, String title, boolean modal) {
161 	super(owner, title, modal);
162 }
163 
164 /*** Machine-generated. */
165 public VerifyDialog(java.awt.Frame owner, boolean modal) {
166 	super(owner, modal);
167 }
168 
169 /***
170  * Use this constructor if you want a possibility to verify other
171  * class files than java.lang.Object.
172  * @param fully_qualified_class_name java.lang.String
173  */
174 public VerifyDialog(String fully_qualified_class_name) {
175 	super();
176 	
177 	int dotclasspos = fully_qualified_class_name.lastIndexOf(".class");
178 	if (dotclasspos != -1) fully_qualified_class_name = fully_qualified_class_name.substring(0,dotclasspos);
179 	fully_qualified_class_name = fully_qualified_class_name.replace('/', '.');
180 
181 	class_name = fully_qualified_class_name;
182 	initialize();
183 }
184 
185 
186 /*** Machine-generated. */
187 private void connEtoC1(java.awt.event.ActionEvent arg1) {
188 	try {
189 		// user code begin {1}
190 		// user code end
191 		this.pass1Button_ActionPerformed(arg1);
192 		// user code begin {2}
193 		// user code end
194 	} catch (java.lang.Throwable ivjExc) {
195 		// user code begin {3}
196 		// user code end
197 		handleException(ivjExc);
198 	}
199 }
200 
201 /*** Machine-generated. */
202 private void connEtoC2(java.awt.event.ActionEvent arg1) {
203 	try {
204 		// user code begin {1}
205 		// user code end
206 		this.pass2Button_ActionPerformed(arg1);
207 		// user code begin {2}
208 		// user code end
209 	} catch (java.lang.Throwable ivjExc) {
210 		// user code begin {3}
211 		// user code end
212 		handleException(ivjExc);
213 	}
214 }
215 
216 /*** Machine-generated. */
217 private void connEtoC3(java.awt.event.ActionEvent arg1) {
218 	try {
219 		// user code begin {1}
220 		// user code end
221 		this.pass4Button_ActionPerformed(arg1);
222 		// user code begin {2}
223 		// user code end
224 	} catch (java.lang.Throwable ivjExc) {
225 		// user code begin {3}
226 		// user code end
227 		handleException(ivjExc);
228 	}
229 }
230 
231 /*** Machine-generated. */
232 private void connEtoC4(java.awt.event.ActionEvent arg1) {
233 	try {
234 		// user code begin {1}
235 		// user code end
236 		this.flushButton_ActionPerformed(arg1);
237 		// user code begin {2}
238 		// user code end
239 	} catch (java.lang.Throwable ivjExc) {
240 		// user code begin {3}
241 		// user code end
242 		handleException(ivjExc);
243 	}
244 }
245 
246 /*** Machine-generated. */
247 public void flushButton_ActionPerformed(java.awt.event.ActionEvent actionEvent) {
248 	VerifierFactory.getVerifier(class_name).flush();
249 	Repository.removeClass(class_name); // Make sure it will be reloaded.
250 	getPass1Panel().setBackground(Color.gray);
251 	getPass1Panel().repaint();
252 	getPass2Panel().setBackground(Color.gray);
253 	getPass2Panel().repaint();
254 	getPass3Panel().setBackground(Color.gray);
255 	getPass3Panel().repaint();
256 }
257 
258 /*** Machine-generated. */
259 private javax.swing.JButton getFlushButton() {
260 	if (ivjFlushButton == null) {
261 		try {
262 			ivjFlushButton = new javax.swing.JButton();
263 			ivjFlushButton.setName("FlushButton");
264 			ivjFlushButton.setText("Flush: Forget old verification results");
265 			ivjFlushButton.setBackground(java.awt.SystemColor.controlHighlight);
266 			ivjFlushButton.setBounds(60, 215, 300, 30);
267 			ivjFlushButton.setForeground(java.awt.Color.red);
268 			ivjFlushButton.setActionCommand("FlushButton");
269 			// user code begin {1}
270 			// user code end
271 		} catch (java.lang.Throwable ivjExc) {
272 			// user code begin {2}
273 			// user code end
274 			handleException(ivjExc);
275 		}
276 	}
277 	return ivjFlushButton;
278 }
279 
280 /*** Machine-generated. */
281 private javax.swing.JPanel getJDialogContentPane() {
282 	if (ivjJDialogContentPane == null) {
283 		try {
284 			ivjJDialogContentPane = new javax.swing.JPanel();
285 			ivjJDialogContentPane.setName("JDialogContentPane");
286 			ivjJDialogContentPane.setLayout(null);
287 			getJDialogContentPane().add(getPass1Panel(), getPass1Panel().getName());
288 			getJDialogContentPane().add(getPass3Panel(), getPass3Panel().getName());
289 			getJDialogContentPane().add(getPass2Panel(), getPass2Panel().getName());
290 			getJDialogContentPane().add(getPass1Button(), getPass1Button().getName());
291 			getJDialogContentPane().add(getPass2Button(), getPass2Button().getName());
292 			getJDialogContentPane().add(getPass3Button(), getPass3Button().getName());
293 			getJDialogContentPane().add(getFlushButton(), getFlushButton().getName());
294 			// user code begin {1}
295 			// user code end
296 		} catch (java.lang.Throwable ivjExc) {
297 			// user code begin {2}
298 			// user code end
299 			handleException(ivjExc);
300 		}
301 	}
302 	return ivjJDialogContentPane;
303 }
304 
305 /*** Machine-generated. */
306 private javax.swing.JButton getPass1Button() {
307 	if (ivjPass1Button == null) {
308 		try {
309 			ivjPass1Button = new javax.swing.JButton();
310 			ivjPass1Button.setName("Pass1Button");
311 			ivjPass1Button.setText("Pass1: Verify binary layout of .class file");
312 			ivjPass1Button.setBackground(java.awt.SystemColor.controlHighlight);
313 			ivjPass1Button.setBounds(100, 40, 300, 30);
314 			ivjPass1Button.setActionCommand("Button1");
315 			// user code begin {1}
316 			// user code end
317 		} catch (java.lang.Throwable ivjExc) {
318 			// user code begin {2}
319 			// user code end
320 			handleException(ivjExc);
321 		}
322 	}
323 	return ivjPass1Button;
324 }
325 
326 /*** Machine-generated. */
327 private javax.swing.JPanel getPass1Panel() {
328 	if (ivjPass1Panel == null) {
329 		try {
330 			ivjPass1Panel = new javax.swing.JPanel();
331 			ivjPass1Panel.setName("Pass1Panel");
332 			ivjPass1Panel.setLayout(null);
333 			ivjPass1Panel.setBackground(java.awt.SystemColor.controlShadow);
334 			ivjPass1Panel.setBounds(30, 30, 50, 50);
335 			// user code begin {1}
336 			// user code end
337 		} catch (java.lang.Throwable ivjExc) {
338 			// user code begin {2}
339 			// user code end
340 			handleException(ivjExc);
341 		}
342 	}
343 	return ivjPass1Panel;
344 }
345 
346 /*** Machine-generated. */
347 private javax.swing.JButton getPass2Button() {
348 	if (ivjPass2Button == null) {
349 		try {
350 			ivjPass2Button = new javax.swing.JButton();
351 			ivjPass2Button.setName("Pass2Button");
352 			ivjPass2Button.setText("Pass 2: Verify static .class file constraints");
353 			ivjPass2Button.setBackground(java.awt.SystemColor.controlHighlight);
354 			ivjPass2Button.setBounds(100, 100, 300, 30);
355 			ivjPass2Button.setActionCommand("Button2");
356 			// user code begin {1}
357 			// user code end
358 		} catch (java.lang.Throwable ivjExc) {
359 			// user code begin {2}
360 			// user code end
361 			handleException(ivjExc);
362 		}
363 	}
364 	return ivjPass2Button;
365 }
366 
367 /*** Machine-generated. */
368 private javax.swing.JPanel getPass2Panel() {
369 	if (ivjPass2Panel == null) {
370 		try {
371 			ivjPass2Panel = new javax.swing.JPanel();
372 			ivjPass2Panel.setName("Pass2Panel");
373 			ivjPass2Panel.setLayout(null);
374 			ivjPass2Panel.setBackground(java.awt.SystemColor.controlShadow);
375 			ivjPass2Panel.setBounds(30, 90, 50, 50);
376 			// user code begin {1}
377 			// user code end
378 		} catch (java.lang.Throwable ivjExc) {
379 			// user code begin {2}
380 			// user code end
381 			handleException(ivjExc);
382 		}
383 	}
384 	return ivjPass2Panel;
385 }
386 
387 /*** Machine-generated. */
388 private javax.swing.JButton getPass3Button() {
389 	if (ivjPass3Button == null) {
390 		try {
391 			ivjPass3Button = new javax.swing.JButton();
392 			ivjPass3Button.setName("Pass3Button");
393 			ivjPass3Button.setText("Passes 3a+3b: Verify code arrays");
394 			ivjPass3Button.setBackground(java.awt.SystemColor.controlHighlight);
395 			ivjPass3Button.setBounds(100, 160, 300, 30);
396 			ivjPass3Button.setActionCommand("Button2");
397 			// user code begin {1}
398 			// user code end
399 		} catch (java.lang.Throwable ivjExc) {
400 			// user code begin {2}
401 			// user code end
402 			handleException(ivjExc);
403 		}
404 	}
405 	return ivjPass3Button;
406 }
407 
408 /*** Machine-generated. */
409 private javax.swing.JPanel getPass3Panel() {
410 	if (ivjPass3Panel == null) {
411 		try {
412 			ivjPass3Panel = new javax.swing.JPanel();
413 			ivjPass3Panel.setName("Pass3Panel");
414 			ivjPass3Panel.setLayout(null);
415 			ivjPass3Panel.setBackground(java.awt.SystemColor.controlShadow);
416 			ivjPass3Panel.setBounds(30, 150, 50, 50);
417 			// user code begin {1}
418 			// user code end
419 		} catch (java.lang.Throwable ivjExc) {
420 			// user code begin {2}
421 			// user code end
422 			handleException(ivjExc);
423 		}
424 	}
425 	return ivjPass3Panel;
426 }
427 
428 /*** Machine-generated. */
429 private void handleException(java.lang.Throwable exception) {
430 
431 	/* Uncomment the following lines to print uncaught exceptions to stdout */
432 	 System.out.println("--------- UNCAUGHT EXCEPTION ---------");
433 	 exception.printStackTrace(System.out);
434 }
435 
436 
437 /*** Machine-generated. */
438 private void initConnections() throws java.lang.Exception {
439 	// user code begin {1}
440 	// user code end
441 	getPass1Button().addActionListener(ivjEventHandler);
442 	getPass2Button().addActionListener(ivjEventHandler);
443 	getPass3Button().addActionListener(ivjEventHandler);
444 	getFlushButton().addActionListener(ivjEventHandler);
445 }
446 
447 /*** Machine-generated. */
448 private void initialize() {
449 	try {
450 		// user code begin {1}
451 		// user code end
452 		setName("VerifyDialog");
453 		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
454 		setSize(430, 280);
455 		setVisible(true);
456 		setModal(true);
457 		setResizable(false);
458 		setContentPane(getJDialogContentPane());
459 		initConnections();
460 	} catch (java.lang.Throwable ivjExc) {
461 		handleException(ivjExc);
462 	}
463 	// user code begin {2}
464 	setTitle("'"+class_name+"' verification - JustIce / BCEL");
465 	// user code end
466 }
467 /***
468  * Verifies one or more class files.
469  * Verification results are presented graphically: Red means 'rejected',
470  * green means 'passed' while yellow means 'could not be verified yet'.
471  * @param args java.lang.String[] fully qualified names of classes to verify.
472  */
473 public static void main(java.lang.String[] args) {
474 	classes_to_verify = args.length;
475 	
476 	for (int i=0; i<args.length; i++){
477 
478 		try {
479 			VerifyDialog aVerifyDialog;
480 			aVerifyDialog = new VerifyDialog(args[i]);
481 			aVerifyDialog.setModal(true);
482 			aVerifyDialog.addWindowListener(new java.awt.event.WindowAdapter() {
483 				public void windowClosing(java.awt.event.WindowEvent e) {
484 					classes_to_verify--;
485 					if (classes_to_verify == 0) System.exit(0);
486 				};
487 			});
488 			aVerifyDialog.setVisible(true);
489 		} catch (Throwable exception) {
490 			System.err.println("Exception occurred in main() of javax.swing.JDialog");
491 			exception.printStackTrace(System.out);
492 		}
493 	
494 	}
495 }
496 
497 /*** Machine-generated. */
498 public void pass1Button_ActionPerformed(java.awt.event.ActionEvent actionEvent) {
499 	Verifier v = VerifierFactory.getVerifier(class_name);
500 	VerificationResult vr = v.doPass1();
501 	if (vr.getStatus() == VerificationResult.VERIFIED_OK){
502 		getPass1Panel().setBackground(Color.green);
503 		getPass1Panel().repaint();
504 	}
505 	if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED){
506 		getPass1Panel().setBackground(Color.red);
507 		getPass1Panel().repaint();
508 	}
509 }
510 
511 /*** Machine-generated. */
512 public void pass2Button_ActionPerformed(java.awt.event.ActionEvent actionEvent) {
513 	pass1Button_ActionPerformed(actionEvent);
514 	
515 	Verifier v = VerifierFactory.getVerifier(class_name);
516 	VerificationResult vr = v.doPass2();
517 	if (vr.getStatus() == VerificationResult.VERIFIED_OK){
518 		getPass2Panel().setBackground(Color.green);
519 		getPass2Panel().repaint();
520 	}
521 	if (vr.getStatus() == VerificationResult.VERIFIED_NOTYET){
522 		getPass2Panel().setBackground(Color.yellow);
523 		getPass2Panel().repaint();
524 	}
525 	if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED){
526 		getPass2Panel().setBackground(Color.red);
527 		getPass2Panel().repaint();
528 	}
529 }
530 
531 /*** Machine-generated. */
532 public void pass4Button_ActionPerformed(java.awt.event.ActionEvent actionEvent) {
533 	
534 	pass2Button_ActionPerformed(actionEvent);
535 	
536 	
537 	Color color = Color.green;
538 
539 	Verifier v = VerifierFactory.getVerifier(class_name);
540 	VerificationResult vr = v.doPass2();
541 	if (vr.getStatus() == VerificationResult.VERIFIED_OK){
542 		JavaClass jc = Repository.lookupClass(class_name);
543 		int nr = jc.getMethods().length;
544 		for (int i=0; i<nr; i++) {
545 			vr = v.doPass3b(i);
546 			if (vr.getStatus() != VerificationResult.VERIFIED_OK){
547 				color = Color.red;
548 				break;
549 			}
550 		}
551 	}
552 	else{
553 		color = Color.yellow;
554 	}
555 
556 	getPass3Panel().setBackground(color);
557 	getPass3Panel().repaint();
558 }
559 }
This page was automatically generated by Maven