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 java.awt.*;
  56. import java.awt.event.*;
  57. import javax.swing.*;
  58. import javax.swing.event.*;
  59. import com.sun.org.apache.bcel.internal.*;
  60. import com.sun.org.apache.bcel.internal.classfile.*;
  61. import com.sun.org.apache.bcel.internal.verifier.*;
  62. /**
  63. * This class implements a machine-generated frame for use with
  64. * the GraphicalVerfifier.
  65. *
  66. * @version $Id: VerifierAppFrame.java,v 1.1.1.1 2001/10/29 20:00:32 jvanzyl Exp $
  67. * @author Enver Haase
  68. * @see GraphicalVerifier
  69. */
  70. public class VerifierAppFrame extends JFrame {
  71. JPanel contentPane;
  72. JSplitPane jSplitPane1 = new JSplitPane();
  73. JPanel jPanel1 = new JPanel();
  74. JPanel jPanel2 = new JPanel();
  75. JSplitPane jSplitPane2 = new JSplitPane();
  76. JPanel jPanel3 = new JPanel();
  77. JList classNamesJList = new JList();
  78. GridLayout gridLayout1 = new GridLayout();
  79. JPanel messagesPanel = new JPanel();
  80. GridLayout gridLayout2 = new GridLayout();
  81. JMenuBar jMenuBar1 = new JMenuBar();
  82. JMenu jMenu1 = new JMenu();
  83. JScrollPane jScrollPane1 = new JScrollPane();
  84. JScrollPane messagesScrollPane = new JScrollPane();
  85. JScrollPane jScrollPane3 = new JScrollPane();
  86. GridLayout gridLayout4 = new GridLayout();
  87. JScrollPane jScrollPane4 = new JScrollPane();
  88. CardLayout cardLayout1 = new CardLayout();
  89. private String JUSTICE_VERSION = "JustIce by Enver Haase";
  90. private String current_class;
  91. GridLayout gridLayout3 = new GridLayout();
  92. JTextPane pass1TextPane = new JTextPane();
  93. JTextPane pass2TextPane = new JTextPane();
  94. JTextPane messagesTextPane = new JTextPane();
  95. JMenuItem newFileMenuItem = new JMenuItem();
  96. JSplitPane jSplitPane3 = new JSplitPane();
  97. JSplitPane jSplitPane4 = new JSplitPane();
  98. JScrollPane jScrollPane2 = new JScrollPane();
  99. JScrollPane jScrollPane5 = new JScrollPane();
  100. JScrollPane jScrollPane6 = new JScrollPane();
  101. JScrollPane jScrollPane7 = new JScrollPane();
  102. JList pass3aJList = new JList();
  103. JList pass3bJList = new JList();
  104. JTextPane pass3aTextPane = new JTextPane();
  105. JTextPane pass3bTextPane = new JTextPane();
  106. JMenu jMenu2 = new JMenu();
  107. JMenuItem whatisMenuItem = new JMenuItem();
  108. JMenuItem aboutMenuItem = new JMenuItem();
  109. /** Constructor. */
  110. public VerifierAppFrame() {
  111. enableEvents(AWTEvent.WINDOW_EVENT_MASK);
  112. try {
  113. jbInit();
  114. }
  115. catch(Exception e) {
  116. e.printStackTrace();
  117. }
  118. }
  119. /** Initizalization of the components. */
  120. private void jbInit() throws Exception {
  121. //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Ihr Symbol]")));
  122. contentPane = (JPanel) this.getContentPane();
  123. contentPane.setLayout(cardLayout1);
  124. this.setJMenuBar(jMenuBar1);
  125. this.setSize(new Dimension(708, 451));
  126. this.setTitle("JustIce");
  127. jPanel1.setMinimumSize(new Dimension(100, 100));
  128. jPanel1.setPreferredSize(new Dimension(100, 100));
  129. jPanel1.setLayout(gridLayout1);
  130. jSplitPane2.setOrientation(JSplitPane.VERTICAL_SPLIT);
  131. jPanel2.setLayout(gridLayout2);
  132. jPanel3.setMinimumSize(new Dimension(200, 100));
  133. jPanel3.setPreferredSize(new Dimension(400, 400));
  134. jPanel3.setLayout(gridLayout4);
  135. messagesPanel.setMinimumSize(new Dimension(100, 100));
  136. messagesPanel.setLayout(gridLayout3);
  137. jPanel2.setMinimumSize(new Dimension(200, 100));
  138. jMenu1.setText("File");
  139. jScrollPane1.getViewport().setBackground(Color.red);
  140. messagesScrollPane.getViewport().setBackground(Color.red);
  141. messagesScrollPane.setPreferredSize(new Dimension(10, 10));
  142. classNamesJList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
  143. public void valueChanged(ListSelectionEvent e) {
  144. classNamesJList_valueChanged(e);
  145. }
  146. });
  147. classNamesJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  148. jScrollPane3.setBorder(BorderFactory.createLineBorder(Color.black));
  149. jScrollPane3.setPreferredSize(new Dimension(100, 100));
  150. gridLayout4.setRows(4);
  151. gridLayout4.setColumns(1);
  152. gridLayout4.setHgap(1);
  153. jScrollPane4.setBorder(BorderFactory.createLineBorder(Color.black));
  154. jScrollPane4.setPreferredSize(new Dimension(100, 100));
  155. pass1TextPane.setBorder(BorderFactory.createRaisedBevelBorder());
  156. pass1TextPane.setToolTipText("");
  157. pass1TextPane.setEditable(false);
  158. pass2TextPane.setBorder(BorderFactory.createRaisedBevelBorder());
  159. pass2TextPane.setEditable(false);
  160. messagesTextPane.setBorder(BorderFactory.createRaisedBevelBorder());
  161. messagesTextPane.setEditable(false);
  162. newFileMenuItem.setText("New...");
  163. newFileMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(78, java.awt.event.KeyEvent.CTRL_MASK, true));
  164. newFileMenuItem.addActionListener(new java.awt.event.ActionListener() {
  165. public void actionPerformed(ActionEvent e) {
  166. newFileMenuItem_actionPerformed(e);
  167. }
  168. });
  169. pass3aTextPane.setEditable(false);
  170. pass3bTextPane.setEditable(false);
  171. pass3aJList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
  172. public void valueChanged(ListSelectionEvent e) {
  173. pass3aJList_valueChanged(e);
  174. }
  175. });
  176. pass3bJList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
  177. public void valueChanged(ListSelectionEvent e) {
  178. pass3bJList_valueChanged(e);
  179. }
  180. });
  181. jMenu2.setText("Help");
  182. whatisMenuItem.setText("What is...");
  183. whatisMenuItem.addActionListener(new java.awt.event.ActionListener() {
  184. public void actionPerformed(ActionEvent e) {
  185. whatisMenuItem_actionPerformed(e);
  186. }
  187. });
  188. aboutMenuItem.setText("About");
  189. aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
  190. public void actionPerformed(ActionEvent e) {
  191. aboutMenuItem_actionPerformed(e);
  192. }
  193. });
  194. jSplitPane2.add(messagesPanel, JSplitPane.BOTTOM);
  195. messagesPanel.add(messagesScrollPane, null);
  196. messagesScrollPane.getViewport().add(messagesTextPane, null);
  197. jSplitPane2.add(jPanel3, JSplitPane.TOP);
  198. jPanel3.add(jScrollPane3, null);
  199. jScrollPane3.getViewport().add(pass1TextPane, null);
  200. jPanel3.add(jScrollPane4, null);
  201. jPanel3.add(jSplitPane3, null);
  202. jSplitPane3.add(jScrollPane2, JSplitPane.LEFT);
  203. jScrollPane2.getViewport().add(pass3aJList, null);
  204. jSplitPane3.add(jScrollPane5, JSplitPane.RIGHT);
  205. jScrollPane5.getViewport().add(pass3aTextPane, null);
  206. jPanel3.add(jSplitPane4, null);
  207. jSplitPane4.add(jScrollPane6, JSplitPane.LEFT);
  208. jScrollPane6.getViewport().add(pass3bJList, null);
  209. jSplitPane4.add(jScrollPane7, JSplitPane.RIGHT);
  210. jScrollPane7.getViewport().add(pass3bTextPane, null);
  211. jScrollPane4.getViewport().add(pass2TextPane, null);
  212. jSplitPane1.add(jPanel2, JSplitPane.TOP);
  213. jPanel2.add(jScrollPane1, null);
  214. jSplitPane1.add(jPanel1, JSplitPane.BOTTOM);
  215. jPanel1.add(jSplitPane2, null);
  216. jScrollPane1.getViewport().add(classNamesJList, null);
  217. jMenuBar1.add(jMenu1);
  218. jMenuBar1.add(jMenu2);
  219. contentPane.add(jSplitPane1, "jSplitPane1");
  220. jMenu1.add(newFileMenuItem);
  221. jMenu2.add(whatisMenuItem);
  222. jMenu2.add(aboutMenuItem);
  223. jSplitPane2.setDividerLocation(300);
  224. jSplitPane3.setDividerLocation(150);
  225. jSplitPane4.setDividerLocation(150);
  226. }
  227. /** Overridden to stop the application on a closing window. */
  228. protected void processWindowEvent(WindowEvent e) {
  229. super.processWindowEvent(e);
  230. if (e.getID() == WindowEvent.WINDOW_CLOSING) {
  231. System.exit(0);
  232. }
  233. }
  234. synchronized void classNamesJList_valueChanged(ListSelectionEvent e) {
  235. if (e.getValueIsAdjusting()) return;
  236. current_class = classNamesJList.getSelectedValue().toString();
  237. verify();
  238. classNamesJList.setSelectedValue(current_class, true);
  239. }
  240. private void verify(){
  241. setTitle("PLEASE WAIT");
  242. Verifier v = VerifierFactory.getVerifier(current_class);
  243. v.flush(); // Don't cache the verification result for this class.
  244. VerificationResult vr;
  245. vr = v.doPass1();
  246. if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED){
  247. pass1TextPane.setText(vr.getMessage());
  248. pass1TextPane.setBackground(Color.red);
  249. pass2TextPane.setText("");
  250. pass2TextPane.setBackground(Color.yellow);
  251. pass3aTextPane.setText("");
  252. pass3aJList.setListData(new Object[0]);
  253. pass3aTextPane.setBackground(Color.yellow);
  254. pass3bTextPane.setText("");
  255. pass3bJList.setListData(new Object[0]);
  256. pass3bTextPane.setBackground(Color.yellow);
  257. }
  258. else{ // Must be VERIFIED_OK, Pass 1 does not know VERIFIED_NOTYET
  259. pass1TextPane.setBackground(Color.green);
  260. pass1TextPane.setText(vr.getMessage());
  261. vr = v.doPass2();
  262. if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED){
  263. pass2TextPane.setText(vr.getMessage());
  264. pass2TextPane.setBackground(Color.red);
  265. pass3aTextPane.setText("");
  266. pass3aTextPane.setBackground(Color.yellow);
  267. pass3aJList.setListData(new Object[0]);
  268. pass3bTextPane.setText("");
  269. pass3bTextPane.setBackground(Color.yellow);
  270. pass3bJList.setListData(new Object[0]);
  271. }
  272. else{ // must be Verified_OK, because Pass1 was OK (cannot be Verified_NOTYET).
  273. pass2TextPane.setText(vr.getMessage());
  274. pass2TextPane.setBackground(Color.green);
  275. JavaClass jc = Repository.lookupClass(current_class);
  276. boolean all3aok = true;
  277. boolean all3bok = true;
  278. String all3amsg = "";
  279. String all3bmsg = "";
  280. String[] methodnames = new String[jc.getMethods().length];
  281. for (int i=0; i<jc.getMethods().length; i++){
  282. methodnames[i] = jc.getMethods()[i].toString().replace('\n',' ').replace('\t',' ');
  283. }
  284. pass3aJList.setListData(methodnames);
  285. pass3aJList.setSelectionInterval(0,jc.getMethods().length-1);
  286. pass3bJList.setListData(methodnames);
  287. pass3bJList.setSelectionInterval(0,jc.getMethods().length-1);
  288. }
  289. }
  290. String[] msgs = v.getMessages();
  291. messagesTextPane.setBackground(msgs.length == 0? Color.green : Color.yellow);
  292. String allmsgs = "";
  293. for (int i=0; i<msgs.length; i++){
  294. msgs[i] = msgs[i].replace('\n',' ');
  295. allmsgs += msgs[i] + "\n\n";
  296. }
  297. messagesTextPane.setText(allmsgs);
  298. setTitle(current_class + " - " + JUSTICE_VERSION);
  299. }
  300. void newFileMenuItem_actionPerformed(ActionEvent e) {
  301. String classname = JOptionPane.showInputDialog("Please enter the fully qualified name of a class or interface to verify:");
  302. if ((classname == null) || (classname.equals(""))) return;
  303. VerifierFactory.getVerifier(classname); // let observers do the rest.
  304. classNamesJList.setSelectedValue(classname, true);
  305. }
  306. synchronized void pass3aJList_valueChanged(ListSelectionEvent e) {
  307. if (e.getValueIsAdjusting()) return;
  308. Verifier v = VerifierFactory.getVerifier(current_class);
  309. String all3amsg = "";
  310. boolean all3aok = true;
  311. boolean rejected = false;
  312. for (int i=0; i<pass3aJList.getModel().getSize(); i++){
  313. if (pass3aJList.isSelectedIndex(i)){
  314. VerificationResult vr = v.doPass3a(i);
  315. if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED){
  316. all3aok = false;
  317. rejected = true;
  318. }
  319. all3amsg += "Method '"+Repository.lookupClass(v.getClassName()).getMethods()[i]+"': "+vr.getMessage().replace('\n',' ')+"\n\n";
  320. }
  321. }
  322. pass3aTextPane.setText(all3amsg);
  323. pass3aTextPane.setBackground(all3aok? Color.green : (rejected? Color.red : Color.yellow));
  324. }
  325. synchronized void pass3bJList_valueChanged(ListSelectionEvent e) {
  326. if (e.getValueIsAdjusting()) return;
  327. Verifier v = VerifierFactory.getVerifier(current_class);
  328. String all3bmsg = "";
  329. boolean all3bok = true;
  330. boolean rejected = false;
  331. for (int i=0; i<pass3bJList.getModel().getSize(); i++){
  332. if (pass3bJList.isSelectedIndex(i)){
  333. VerificationResult vr = v.doPass3b(i);
  334. if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED){
  335. all3bok = false;
  336. rejected = true;
  337. }
  338. all3bmsg += "Method '"+Repository.lookupClass(v.getClassName()).getMethods()[i]+"': "+vr.getMessage().replace('\n',' ')+"\n\n";
  339. }
  340. }
  341. pass3bTextPane.setText(all3bmsg);
  342. pass3bTextPane.setBackground(all3bok? Color.green : (rejected? Color.red : Color.yellow));
  343. }
  344. void aboutMenuItem_actionPerformed(ActionEvent e) {
  345. JOptionPane.showMessageDialog(this,
  346. "JustIce is a Java class file verifier.\nIt was implemented by Enver Haase in 2001.\nhttp://bcel.sourceforge.net",
  347. JUSTICE_VERSION, JOptionPane.INFORMATION_MESSAGE);
  348. }
  349. void whatisMenuItem_actionPerformed(ActionEvent e) {
  350. JOptionPane.showMessageDialog(this,
  351. "The upper four boxes to the right reflect verification passes according to The Java Virtual Machine Specification.\nThese are (in that order): Pass one, Pass two, Pass three (before data flow analysis), Pass three (data flow analysis).\nThe bottom box to the right shows (warning) messages; warnings do not cause a class to be rejected.",
  352. JUSTICE_VERSION, JOptionPane.INFORMATION_MESSAGE);
  353. }
  354. }