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