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