You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VerifyDialog.java 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. package org.aspectj.apache.bcel.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 (https://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. * <https://www.apache.org/>.
  54. */
  55. import java.awt.Color;
  56. import org.aspectj.apache.bcel.Repository;
  57. import org.aspectj.apache.bcel.classfile.JavaClass;
  58. /**
  59. * A class for simple graphical class file verification.
  60. * Use the main(String []) method with fully qualified
  61. * class names as arguments to use it as a stand-alone
  62. * application.
  63. * Use the VerifyDialog(String) constructor to use this
  64. * class in your application.
  65. * [This class was created using VisualAge for Java,
  66. * but it does not work under VAJ itself (Version 3.02 JDK 1.2)]
  67. * @version $Id: VerifyDialog.java,v 1.2 2008/05/28 23:53:01 aclement Exp $
  68. * @author <A HREF="https://www.inf.fu-berlin.de/~ehaase"/>Enver Haase</A>
  69. * @see #main(String[])
  70. * @see #VerifyDialog(String)
  71. */
  72. public class VerifyDialog extends javax.swing.JDialog {
  73. /** Machine-generated. */
  74. private javax.swing.JPanel ivjJDialogContentPane = null;
  75. /** Machine-generated. */
  76. private javax.swing.JPanel ivjPass1Panel = null;
  77. /** Machine-generated. */
  78. private javax.swing.JPanel ivjPass2Panel = null;
  79. /** Machine-generated. */
  80. private javax.swing.JPanel ivjPass3Panel = null;
  81. /** Machine-generated. */
  82. private javax.swing.JButton ivjPass1Button = null;
  83. /** Machine-generated. */
  84. private javax.swing.JButton ivjPass2Button = null;
  85. /** Machine-generated. */
  86. private javax.swing.JButton ivjPass3Button = null;
  87. /** Machine-generated. */
  88. IvjEventHandler ivjEventHandler = new IvjEventHandler();
  89. /**
  90. * The class to verify. Default set to 'java.lang.Object'
  91. * in case this class is instantiated via one of the many
  92. * machine-generated constructors.
  93. */
  94. private String class_name = "java.lang.Object";
  95. /**
  96. * This field is here to count the number of open VerifyDialog
  97. * instances so the JVM can be exited afer every Dialog had been
  98. * closed.
  99. */
  100. private static int classes_to_verify;
  101. /** Machine-generated. */
  102. class IvjEventHandler implements java.awt.event.ActionListener {
  103. public void actionPerformed(java.awt.event.ActionEvent e) {
  104. if (e.getSource() == VerifyDialog.this.getPass1Button())
  105. connEtoC1(e);
  106. if (e.getSource() == VerifyDialog.this.getPass2Button())
  107. connEtoC2(e);
  108. if (e.getSource() == VerifyDialog.this.getPass3Button())
  109. connEtoC3(e);
  110. if (e.getSource() == VerifyDialog.this.getFlushButton())
  111. connEtoC4(e);
  112. };
  113. };
  114. /** Machine-generated. */
  115. private javax.swing.JButton ivjFlushButton = null;
  116. /** Machine-generated. */
  117. public VerifyDialog() {
  118. super();
  119. initialize();
  120. }
  121. /** Machine-generated. */
  122. public VerifyDialog(java.awt.Dialog owner) {
  123. super(owner);
  124. }
  125. /** Machine-generated. */
  126. public VerifyDialog(java.awt.Dialog owner, String title) {
  127. super(owner, title);
  128. }
  129. /** Machine-generated. */
  130. public VerifyDialog(java.awt.Dialog owner, String title, boolean modal) {
  131. super(owner, title, modal);
  132. }
  133. /** Machine-generated. */
  134. public VerifyDialog(java.awt.Dialog owner, boolean modal) {
  135. super(owner, modal);
  136. }
  137. /** Machine-generated. */
  138. public VerifyDialog(java.awt.Frame owner) {
  139. super(owner);
  140. }
  141. /** Machine-generated. */
  142. public VerifyDialog(java.awt.Frame owner, String title) {
  143. super(owner, title);
  144. }
  145. /** Machine-generated. */
  146. public VerifyDialog(java.awt.Frame owner, String title, boolean modal) {
  147. super(owner, title, modal);
  148. }
  149. /** Machine-generated. */
  150. public VerifyDialog(java.awt.Frame owner, boolean modal) {
  151. super(owner, modal);
  152. }
  153. /**
  154. * Use this constructor if you want a possibility to verify other
  155. * class files than java.lang.Object.
  156. * @param fully_qualified_class_name java.lang.String
  157. */
  158. public VerifyDialog(String fully_qualified_class_name) {
  159. super();
  160. int dotclasspos = fully_qualified_class_name.lastIndexOf(".class");
  161. if (dotclasspos != -1) fully_qualified_class_name = fully_qualified_class_name.substring(0,dotclasspos);
  162. fully_qualified_class_name = fully_qualified_class_name.replace('/', '.');
  163. class_name = fully_qualified_class_name;
  164. initialize();
  165. }
  166. /** Machine-generated. */
  167. private void connEtoC1(java.awt.event.ActionEvent arg1) {
  168. try {
  169. // user code begin {1}
  170. // user code end
  171. this.pass1Button_ActionPerformed(arg1);
  172. // user code begin {2}
  173. // user code end
  174. } catch (java.lang.Throwable ivjExc) {
  175. // user code begin {3}
  176. // user code end
  177. handleException(ivjExc);
  178. }
  179. }
  180. /** Machine-generated. */
  181. private void connEtoC2(java.awt.event.ActionEvent arg1) {
  182. try {
  183. // user code begin {1}
  184. // user code end
  185. this.pass2Button_ActionPerformed(arg1);
  186. // user code begin {2}
  187. // user code end
  188. } catch (java.lang.Throwable ivjExc) {
  189. // user code begin {3}
  190. // user code end
  191. handleException(ivjExc);
  192. }
  193. }
  194. /** Machine-generated. */
  195. private void connEtoC3(java.awt.event.ActionEvent arg1) {
  196. try {
  197. // user code begin {1}
  198. // user code end
  199. this.pass4Button_ActionPerformed(arg1);
  200. // user code begin {2}
  201. // user code end
  202. } catch (java.lang.Throwable ivjExc) {
  203. // user code begin {3}
  204. // user code end
  205. handleException(ivjExc);
  206. }
  207. }
  208. /** Machine-generated. */
  209. private void connEtoC4(java.awt.event.ActionEvent arg1) {
  210. try {
  211. // user code begin {1}
  212. // user code end
  213. this.flushButton_ActionPerformed(arg1);
  214. // user code begin {2}
  215. // user code end
  216. } catch (java.lang.Throwable ivjExc) {
  217. // user code begin {3}
  218. // user code end
  219. handleException(ivjExc);
  220. }
  221. }
  222. /** Machine-generated. */
  223. public void flushButton_ActionPerformed(java.awt.event.ActionEvent actionEvent) {
  224. VerifierFactory.getVerifier(class_name).flush();
  225. Repository.removeClass(class_name); // Make sure it will be reloaded.
  226. getPass1Panel().setBackground(Color.gray);
  227. getPass1Panel().repaint();
  228. getPass2Panel().setBackground(Color.gray);
  229. getPass2Panel().repaint();
  230. getPass3Panel().setBackground(Color.gray);
  231. getPass3Panel().repaint();
  232. }
  233. /** Machine-generated. */
  234. private javax.swing.JButton getFlushButton() {
  235. if (ivjFlushButton == null) {
  236. try {
  237. ivjFlushButton = new javax.swing.JButton();
  238. ivjFlushButton.setName("FlushButton");
  239. ivjFlushButton.setText("Flush: Forget old verification results");
  240. ivjFlushButton.setBackground(java.awt.SystemColor.controlHighlight);
  241. ivjFlushButton.setBounds(60, 215, 300, 30);
  242. ivjFlushButton.setForeground(java.awt.Color.red);
  243. ivjFlushButton.setActionCommand("FlushButton");
  244. // user code begin {1}
  245. // user code end
  246. } catch (java.lang.Throwable ivjExc) {
  247. // user code begin {2}
  248. // user code end
  249. handleException(ivjExc);
  250. }
  251. }
  252. return ivjFlushButton;
  253. }
  254. /** Machine-generated. */
  255. private javax.swing.JPanel getJDialogContentPane() {
  256. if (ivjJDialogContentPane == null) {
  257. try {
  258. ivjJDialogContentPane = new javax.swing.JPanel();
  259. ivjJDialogContentPane.setName("JDialogContentPane");
  260. ivjJDialogContentPane.setLayout(null);
  261. getJDialogContentPane().add(getPass1Panel(), getPass1Panel().getName());
  262. getJDialogContentPane().add(getPass3Panel(), getPass3Panel().getName());
  263. getJDialogContentPane().add(getPass2Panel(), getPass2Panel().getName());
  264. getJDialogContentPane().add(getPass1Button(), getPass1Button().getName());
  265. getJDialogContentPane().add(getPass2Button(), getPass2Button().getName());
  266. getJDialogContentPane().add(getPass3Button(), getPass3Button().getName());
  267. getJDialogContentPane().add(getFlushButton(), getFlushButton().getName());
  268. // user code begin {1}
  269. // user code end
  270. } catch (java.lang.Throwable ivjExc) {
  271. // user code begin {2}
  272. // user code end
  273. handleException(ivjExc);
  274. }
  275. }
  276. return ivjJDialogContentPane;
  277. }
  278. /** Machine-generated. */
  279. private javax.swing.JButton getPass1Button() {
  280. if (ivjPass1Button == null) {
  281. try {
  282. ivjPass1Button = new javax.swing.JButton();
  283. ivjPass1Button.setName("Pass1Button");
  284. ivjPass1Button.setText("Pass1: Verify binary layout of .class file");
  285. ivjPass1Button.setBackground(java.awt.SystemColor.controlHighlight);
  286. ivjPass1Button.setBounds(100, 40, 300, 30);
  287. ivjPass1Button.setActionCommand("Button1");
  288. // user code begin {1}
  289. // user code end
  290. } catch (java.lang.Throwable ivjExc) {
  291. // user code begin {2}
  292. // user code end
  293. handleException(ivjExc);
  294. }
  295. }
  296. return ivjPass1Button;
  297. }
  298. /** Machine-generated. */
  299. private javax.swing.JPanel getPass1Panel() {
  300. if (ivjPass1Panel == null) {
  301. try {
  302. ivjPass1Panel = new javax.swing.JPanel();
  303. ivjPass1Panel.setName("Pass1Panel");
  304. ivjPass1Panel.setLayout(null);
  305. ivjPass1Panel.setBackground(java.awt.SystemColor.controlShadow);
  306. ivjPass1Panel.setBounds(30, 30, 50, 50);
  307. // user code begin {1}
  308. // user code end
  309. } catch (java.lang.Throwable ivjExc) {
  310. // user code begin {2}
  311. // user code end
  312. handleException(ivjExc);
  313. }
  314. }
  315. return ivjPass1Panel;
  316. }
  317. /** Machine-generated. */
  318. private javax.swing.JButton getPass2Button() {
  319. if (ivjPass2Button == null) {
  320. try {
  321. ivjPass2Button = new javax.swing.JButton();
  322. ivjPass2Button.setName("Pass2Button");
  323. ivjPass2Button.setText("Pass 2: Verify static .class file constraints");
  324. ivjPass2Button.setBackground(java.awt.SystemColor.controlHighlight);
  325. ivjPass2Button.setBounds(100, 100, 300, 30);
  326. ivjPass2Button.setActionCommand("Button2");
  327. // user code begin {1}
  328. // user code end
  329. } catch (java.lang.Throwable ivjExc) {
  330. // user code begin {2}
  331. // user code end
  332. handleException(ivjExc);
  333. }
  334. }
  335. return ivjPass2Button;
  336. }
  337. /** Machine-generated. */
  338. private javax.swing.JPanel getPass2Panel() {
  339. if (ivjPass2Panel == null) {
  340. try {
  341. ivjPass2Panel = new javax.swing.JPanel();
  342. ivjPass2Panel.setName("Pass2Panel");
  343. ivjPass2Panel.setLayout(null);
  344. ivjPass2Panel.setBackground(java.awt.SystemColor.controlShadow);
  345. ivjPass2Panel.setBounds(30, 90, 50, 50);
  346. // user code begin {1}
  347. // user code end
  348. } catch (java.lang.Throwable ivjExc) {
  349. // user code begin {2}
  350. // user code end
  351. handleException(ivjExc);
  352. }
  353. }
  354. return ivjPass2Panel;
  355. }
  356. /** Machine-generated. */
  357. private javax.swing.JButton getPass3Button() {
  358. if (ivjPass3Button == null) {
  359. try {
  360. ivjPass3Button = new javax.swing.JButton();
  361. ivjPass3Button.setName("Pass3Button");
  362. ivjPass3Button.setText("Passes 3a+3b: Verify code arrays");
  363. ivjPass3Button.setBackground(java.awt.SystemColor.controlHighlight);
  364. ivjPass3Button.setBounds(100, 160, 300, 30);
  365. ivjPass3Button.setActionCommand("Button2");
  366. // user code begin {1}
  367. // user code end
  368. } catch (java.lang.Throwable ivjExc) {
  369. // user code begin {2}
  370. // user code end
  371. handleException(ivjExc);
  372. }
  373. }
  374. return ivjPass3Button;
  375. }
  376. /** Machine-generated. */
  377. private javax.swing.JPanel getPass3Panel() {
  378. if (ivjPass3Panel == null) {
  379. try {
  380. ivjPass3Panel = new javax.swing.JPanel();
  381. ivjPass3Panel.setName("Pass3Panel");
  382. ivjPass3Panel.setLayout(null);
  383. ivjPass3Panel.setBackground(java.awt.SystemColor.controlShadow);
  384. ivjPass3Panel.setBounds(30, 150, 50, 50);
  385. // user code begin {1}
  386. // user code end
  387. } catch (java.lang.Throwable ivjExc) {
  388. // user code begin {2}
  389. // user code end
  390. handleException(ivjExc);
  391. }
  392. }
  393. return ivjPass3Panel;
  394. }
  395. /** Machine-generated. */
  396. private void handleException(java.lang.Throwable exception) {
  397. /* Uncomment the following lines to print uncaught exceptions to stdout */
  398. System.out.println("--------- UNCAUGHT EXCEPTION ---------");
  399. exception.printStackTrace(System.out);
  400. }
  401. /** Machine-generated. */
  402. private void initConnections() throws java.lang.Exception {
  403. // user code begin {1}
  404. // user code end
  405. getPass1Button().addActionListener(ivjEventHandler);
  406. getPass2Button().addActionListener(ivjEventHandler);
  407. getPass3Button().addActionListener(ivjEventHandler);
  408. getFlushButton().addActionListener(ivjEventHandler);
  409. }
  410. /** Machine-generated. */
  411. private void initialize() {
  412. try {
  413. // user code begin {1}
  414. // user code end
  415. setName("VerifyDialog");
  416. setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
  417. setSize(430, 280);
  418. setVisible(true);
  419. setModal(true);
  420. setResizable(false);
  421. setContentPane(getJDialogContentPane());
  422. initConnections();
  423. } catch (java.lang.Throwable ivjExc) {
  424. handleException(ivjExc);
  425. }
  426. // user code begin {2}
  427. setTitle("'"+class_name+"' verification - JustIce / BCEL");
  428. // user code end
  429. }
  430. /**
  431. * Verifies one or more class files.
  432. * Verification results are presented graphically: Red means 'rejected',
  433. * green means 'passed' while yellow means 'could not be verified yet'.
  434. * @param args java.lang.String[] fully qualified names of classes to verify.
  435. */
  436. public static void main(java.lang.String[] args) {
  437. classes_to_verify = args.length;
  438. for (int i=0; i<args.length; i++){
  439. try {
  440. VerifyDialog aVerifyDialog;
  441. aVerifyDialog = new VerifyDialog(args[i]);
  442. aVerifyDialog.setModal(true);
  443. aVerifyDialog.addWindowListener(new java.awt.event.WindowAdapter() {
  444. public void windowClosing(java.awt.event.WindowEvent e) {
  445. classes_to_verify--;
  446. if (classes_to_verify == 0) System.exit(0);
  447. };
  448. });
  449. aVerifyDialog.setVisible(true);
  450. } catch (Throwable exception) {
  451. System.err.println("Exception occurred in main() of javax.swing.JDialog");
  452. exception.printStackTrace(System.out);
  453. }
  454. }
  455. }
  456. /** Machine-generated. */
  457. public void pass1Button_ActionPerformed(java.awt.event.ActionEvent actionEvent) {
  458. Verifier v = VerifierFactory.getVerifier(class_name);
  459. VerificationResult vr = v.doPass1();
  460. if (vr.getStatus() == VerificationResult.VERIFIED_OK){
  461. getPass1Panel().setBackground(Color.green);
  462. getPass1Panel().repaint();
  463. }
  464. if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED){
  465. getPass1Panel().setBackground(Color.red);
  466. getPass1Panel().repaint();
  467. }
  468. }
  469. /** Machine-generated. */
  470. public void pass2Button_ActionPerformed(java.awt.event.ActionEvent actionEvent) {
  471. pass1Button_ActionPerformed(actionEvent);
  472. Verifier v = VerifierFactory.getVerifier(class_name);
  473. VerificationResult vr = v.doPass2();
  474. if (vr.getStatus() == VerificationResult.VERIFIED_OK){
  475. getPass2Panel().setBackground(Color.green);
  476. getPass2Panel().repaint();
  477. }
  478. if (vr.getStatus() == VerificationResult.VERIFIED_NOTYET){
  479. getPass2Panel().setBackground(Color.yellow);
  480. getPass2Panel().repaint();
  481. }
  482. if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED){
  483. getPass2Panel().setBackground(Color.red);
  484. getPass2Panel().repaint();
  485. }
  486. }
  487. /** Machine-generated. */
  488. public void pass4Button_ActionPerformed(java.awt.event.ActionEvent actionEvent) {
  489. pass2Button_ActionPerformed(actionEvent);
  490. Color color = Color.green;
  491. Verifier v = VerifierFactory.getVerifier(class_name);
  492. VerificationResult vr = v.doPass2();
  493. if (vr.getStatus() == VerificationResult.VERIFIED_OK){
  494. JavaClass jc = Repository.lookupClass(class_name);
  495. int nr = jc.getMethods().length;
  496. for (int i=0; i<nr; i++) {
  497. vr = v.doPass3b(i);
  498. if (vr.getStatus() != VerificationResult.VERIFIED_OK){
  499. color = Color.red;
  500. break;
  501. }
  502. }
  503. }
  504. else{
  505. color = Color.yellow;
  506. }
  507. getPass3Panel().setBackground(color);
  508. getPass3Panel().repaint();
  509. }
  510. }