1 package com.sun.org.apache.bcel.internal.verifier; 2 3 56 57 import java.awt.*; 58 import java.awt.event.*; 59 import javax.swing.*; 60 import javax.swing.event.*; 61 import com.sun.org.apache.bcel.internal.*; 62 import com.sun.org.apache.bcel.internal.classfile.*; 63 import com.sun.org.apache.bcel.internal.verifier.*; 64 65 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 115 public VerifierAppFrame() { 116 enableEvents(AWTEvent.WINDOW_EVENT_MASK); 117 try { 118 jbInit(); 119 } 120 catch(Exception e) { 121 e.printStackTrace(); 122 } 123 } 124 125 private void jbInit() throws Exception { 126 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 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(); 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{ 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{ pass2TextPane.setText(vr.getMessage()); 291 pass2TextPane.setBackground(Color.green); 292 293 JavaClass jc = Repository.lookupClass(current_class); 294 boolean all3aok = true; 295 boolean all3bok = true; 296 String all3amsg = ""; 297 String all3bmsg = ""; 298 299 String [] methodnames = new String [jc.getMethods().length]; 300 for (int i=0; i<jc.getMethods().length; i++){ 301 methodnames[i] = jc.getMethods()[i].toString().replace('\n',' ').replace('\t',' '); 302 } 303 pass3aJList.setListData(methodnames); 304 pass3aJList.setSelectionInterval(0,jc.getMethods().length-1); 305 pass3bJList.setListData(methodnames); 306 pass3bJList.setSelectionInterval(0,jc.getMethods().length-1); 307 } 308 309 } 310 String [] msgs = v.getMessages(); 311 messagesTextPane.setBackground(msgs.length == 0? Color.green : Color.yellow); 312 String allmsgs = ""; 313 for (int i=0; i<msgs.length; i++){ 314 msgs[i] = msgs[i].replace('\n',' '); 315 allmsgs += msgs[i] + "\n\n"; 316 } 317 messagesTextPane.setText(allmsgs); 318 319 setTitle(current_class + " - " + JUSTICE_VERSION); 320 } 321 322 void newFileMenuItem_actionPerformed(ActionEvent e) { 323 String classname = JOptionPane.showInputDialog("Please enter the fully qualified name of a class or interface to verify:"); 324 if ((classname == null) || (classname.equals(""))) return; 325 VerifierFactory.getVerifier(classname); classNamesJList.setSelectedValue(classname, true); 327 } 328 329 synchronized void pass3aJList_valueChanged(ListSelectionEvent e) { 330 331 if (e.getValueIsAdjusting()) return; 332 Verifier v = VerifierFactory.getVerifier(current_class); 333 334 String all3amsg = ""; 335 boolean all3aok = true; 336 boolean rejected = false; 337 for (int i=0; i<pass3aJList.getModel().getSize(); i++){ 338 339 if (pass3aJList.isSelectedIndex(i)){ 340 VerificationResult vr = v.doPass3a(i); 341 342 if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED){ 343 all3aok = false; 344 rejected = true; 345 } 346 all3amsg += "Method '"+Repository.lookupClass(v.getClassName()).getMethods()[i]+"': "+vr.getMessage().replace('\n',' ')+"\n\n"; 347 } 348 } 349 pass3aTextPane.setText(all3amsg); 350 pass3aTextPane.setBackground(all3aok? Color.green : (rejected? Color.red : Color.yellow)); 351 352 } 353 354 synchronized void pass3bJList_valueChanged(ListSelectionEvent e) { 355 if (e.getValueIsAdjusting()) return; 356 357 Verifier v = VerifierFactory.getVerifier(current_class); 358 359 String all3bmsg = ""; 360 boolean all3bok = true; 361 boolean rejected = false; 362 for (int i=0; i<pass3bJList.getModel().getSize(); i++){ 363 364 if (pass3bJList.isSelectedIndex(i)){ 365 VerificationResult vr = v.doPass3b(i); 366 367 if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED){ 368 all3bok = false; 369 rejected = true; 370 } 371 all3bmsg += "Method '"+Repository.lookupClass(v.getClassName()).getMethods()[i]+"': "+vr.getMessage().replace('\n',' ')+"\n\n"; 372 } 373 } 374 pass3bTextPane.setText(all3bmsg); 375 pass3bTextPane.setBackground(all3bok? Color.green : (rejected? Color.red : Color.yellow)); 376 377 } 378 379 void aboutMenuItem_actionPerformed(ActionEvent e) { 380 JOptionPane.showMessageDialog(this, 381 "JustIce is a Java class file verifier.\nIt was implemented by Enver Haase in 2001.\nhttp://bcel.sourceforge.net", 382 JUSTICE_VERSION, JOptionPane.INFORMATION_MESSAGE); 383 } 384 385 void whatisMenuItem_actionPerformed(ActionEvent e) { 386 JOptionPane.showMessageDialog(this, 387 "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.", 388 JUSTICE_VERSION, JOptionPane.INFORMATION_MESSAGE); 389 } 390 } 391 | Popular Tags |