1 17 package org.apache.bcel.verifier; 18 19 import java.awt.Color ; 20 import org.apache.bcel.Repository; 21 import org.apache.bcel.classfile.JavaClass; 22 23 37 public class VerifyDialog extends javax.swing.JDialog { 38 39 40 private javax.swing.JPanel ivjJDialogContentPane = null; 41 42 private javax.swing.JPanel ivjPass1Panel = null; 43 44 private javax.swing.JPanel ivjPass2Panel = null; 45 46 private javax.swing.JPanel ivjPass3Panel = null; 47 48 private javax.swing.JButton ivjPass1Button = null; 49 50 private javax.swing.JButton ivjPass2Button = null; 51 52 private javax.swing.JButton ivjPass3Button = null; 53 54 IvjEventHandler ivjEventHandler = new IvjEventHandler(); 55 60 private String class_name = "java.lang.Object"; 61 66 private static int classes_to_verify; 67 68 69 class IvjEventHandler implements java.awt.event.ActionListener { 70 71 public void actionPerformed( java.awt.event.ActionEvent e ) { 72 if (e.getSource() == VerifyDialog.this.getPass1Button()) { 73 connEtoC1(e); 74 } 75 if (e.getSource() == VerifyDialog.this.getPass2Button()) { 76 connEtoC2(e); 77 } 78 if (e.getSource() == VerifyDialog.this.getPass3Button()) { 79 connEtoC3(e); 80 } 81 if (e.getSource() == VerifyDialog.this.getFlushButton()) { 82 connEtoC4(e); 83 } 84 }; 85 }; 86 87 88 private javax.swing.JButton ivjFlushButton = null; 89 90 91 92 public VerifyDialog() { 93 super(); 94 initialize(); 95 } 96 97 98 99 public VerifyDialog(java.awt.Dialog owner) { 100 super(owner); 101 } 102 103 104 105 public VerifyDialog(java.awt.Dialog owner, String title) { 106 super(owner, title); 107 } 108 109 110 111 public VerifyDialog(java.awt.Dialog owner, String title, boolean modal) { 112 super(owner, title, modal); 113 } 114 115 116 117 public VerifyDialog(java.awt.Dialog owner, boolean modal) { 118 super(owner, modal); 119 } 120 121 122 123 public VerifyDialog(java.awt.Frame owner) { 124 super(owner); 125 } 126 127 128 129 public VerifyDialog(java.awt.Frame owner, String title) { 130 super(owner, title); 131 } 132 133 134 135 public VerifyDialog(java.awt.Frame owner, String title, boolean modal) { 136 super(owner, title, modal); 137 } 138 139 140 141 public VerifyDialog(java.awt.Frame owner, boolean modal) { 142 super(owner, modal); 143 } 144 145 146 151 public VerifyDialog(String fully_qualified_class_name) { 152 super(); 153 int dotclasspos = fully_qualified_class_name.lastIndexOf(".class"); 154 if (dotclasspos != -1) { 155 fully_qualified_class_name = fully_qualified_class_name.substring(0, dotclasspos); 156 } 157 fully_qualified_class_name = fully_qualified_class_name.replace('/', '.'); 158 class_name = fully_qualified_class_name; 159 initialize(); 160 } 161 162 163 164 private void connEtoC1( java.awt.event.ActionEvent arg1 ) { 165 try { 166 this.pass1Button_ActionPerformed(arg1); 169 } catch (java.lang.Throwable ivjExc) { 172 handleException(ivjExc); 175 } 176 } 177 178 179 180 private void connEtoC2( java.awt.event.ActionEvent arg1 ) { 181 try { 182 this.pass2Button_ActionPerformed(arg1); 185 } catch (java.lang.Throwable ivjExc) { 188 handleException(ivjExc); 191 } 192 } 193 194 195 196 private void connEtoC3( java.awt.event.ActionEvent arg1 ) { 197 try { 198 this.pass4Button_ActionPerformed(arg1); 201 } catch (java.lang.Throwable ivjExc) { 204 handleException(ivjExc); 207 } 208 } 209 210 211 212 private void connEtoC4( java.awt.event.ActionEvent arg1 ) { 213 try { 214 this.flushButton_ActionPerformed(arg1); 217 } catch (java.lang.Throwable ivjExc) { 220 handleException(ivjExc); 223 } 224 } 225 226 227 228 public void flushButton_ActionPerformed( java.awt.event.ActionEvent actionEvent ) { 229 VerifierFactory.getVerifier(class_name).flush(); 230 Repository.removeClass(class_name); getPass1Panel().setBackground(Color.gray); 232 getPass1Panel().repaint(); 233 getPass2Panel().setBackground(Color.gray); 234 getPass2Panel().repaint(); 235 getPass3Panel().setBackground(Color.gray); 236 getPass3Panel().repaint(); 237 } 238 239 240 241 private javax.swing.JButton getFlushButton() { 242 if (ivjFlushButton == null) { 243 try { 244 ivjFlushButton = new javax.swing.JButton (); 245 ivjFlushButton.setName("FlushButton"); 246 ivjFlushButton.setText("Flush: Forget old verification results"); 247 ivjFlushButton.setBackground(java.awt.SystemColor.controlHighlight); 248 ivjFlushButton.setBounds(60, 215, 300, 30); 249 ivjFlushButton.setForeground(java.awt.Color.red); 250 ivjFlushButton.setActionCommand("FlushButton"); 251 } catch (java.lang.Throwable ivjExc) { 254 handleException(ivjExc); 257 } 258 } 259 return ivjFlushButton; 260 } 261 262 263 264 private javax.swing.JPanel getJDialogContentPane() { 265 if (ivjJDialogContentPane == null) { 266 try { 267 ivjJDialogContentPane = new javax.swing.JPanel (); 268 ivjJDialogContentPane.setName("JDialogContentPane"); 269 ivjJDialogContentPane.setLayout(null); 270 getJDialogContentPane().add(getPass1Panel(), getPass1Panel().getName()); 271 getJDialogContentPane().add(getPass3Panel(), getPass3Panel().getName()); 272 getJDialogContentPane().add(getPass2Panel(), getPass2Panel().getName()); 273 getJDialogContentPane().add(getPass1Button(), getPass1Button().getName()); 274 getJDialogContentPane().add(getPass2Button(), getPass2Button().getName()); 275 getJDialogContentPane().add(getPass3Button(), getPass3Button().getName()); 276 getJDialogContentPane().add(getFlushButton(), getFlushButton().getName()); 277 } catch (java.lang.Throwable ivjExc) { 280 handleException(ivjExc); 283 } 284 } 285 return ivjJDialogContentPane; 286 } 287 288 289 290 private javax.swing.JButton getPass1Button() { 291 if (ivjPass1Button == null) { 292 try { 293 ivjPass1Button = new javax.swing.JButton (); 294 ivjPass1Button.setName("Pass1Button"); 295 ivjPass1Button.setText("Pass1: Verify binary layout of .class file"); 296 ivjPass1Button.setBackground(java.awt.SystemColor.controlHighlight); 297 ivjPass1Button.setBounds(100, 40, 300, 30); 298 ivjPass1Button.setActionCommand("Button1"); 299 } catch (java.lang.Throwable ivjExc) { 302 handleException(ivjExc); 305 } 306 } 307 return ivjPass1Button; 308 } 309 310 311 312 private javax.swing.JPanel getPass1Panel() { 313 if (ivjPass1Panel == null) { 314 try { 315 ivjPass1Panel = new javax.swing.JPanel (); 316 ivjPass1Panel.setName("Pass1Panel"); 317 ivjPass1Panel.setLayout(null); 318 ivjPass1Panel.setBackground(java.awt.SystemColor.controlShadow); 319 ivjPass1Panel.setBounds(30, 30, 50, 50); 320 } catch (java.lang.Throwable ivjExc) { 323 handleException(ivjExc); 326 } 327 } 328 return ivjPass1Panel; 329 } 330 331 332 333 private javax.swing.JButton getPass2Button() { 334 if (ivjPass2Button == null) { 335 try { 336 ivjPass2Button = new javax.swing.JButton (); 337 ivjPass2Button.setName("Pass2Button"); 338 ivjPass2Button.setText("Pass 2: Verify static .class file constraints"); 339 ivjPass2Button.setBackground(java.awt.SystemColor.controlHighlight); 340 ivjPass2Button.setBounds(100, 100, 300, 30); 341 ivjPass2Button.setActionCommand("Button2"); 342 } catch (java.lang.Throwable ivjExc) { 345 handleException(ivjExc); 348 } 349 } 350 return ivjPass2Button; 351 } 352 353 354 355 private javax.swing.JPanel getPass2Panel() { 356 if (ivjPass2Panel == null) { 357 try { 358 ivjPass2Panel = new javax.swing.JPanel (); 359 ivjPass2Panel.setName("Pass2Panel"); 360 ivjPass2Panel.setLayout(null); 361 ivjPass2Panel.setBackground(java.awt.SystemColor.controlShadow); 362 ivjPass2Panel.setBounds(30, 90, 50, 50); 363 } catch (java.lang.Throwable ivjExc) { 366 handleException(ivjExc); 369 } 370 } 371 return ivjPass2Panel; 372 } 373 374 375 376 private javax.swing.JButton getPass3Button() { 377 if (ivjPass3Button == null) { 378 try { 379 ivjPass3Button = new javax.swing.JButton (); 380 ivjPass3Button.setName("Pass3Button"); 381 ivjPass3Button.setText("Passes 3a+3b: Verify code arrays"); 382 ivjPass3Button.setBackground(java.awt.SystemColor.controlHighlight); 383 ivjPass3Button.setBounds(100, 160, 300, 30); 384 ivjPass3Button.setActionCommand("Button2"); 385 } catch (java.lang.Throwable ivjExc) { 388 handleException(ivjExc); 391 } 392 } 393 return ivjPass3Button; 394 } 395 396 397 398 private javax.swing.JPanel getPass3Panel() { 399 if (ivjPass3Panel == null) { 400 try { 401 ivjPass3Panel = new javax.swing.JPanel (); 402 ivjPass3Panel.setName("Pass3Panel"); 403 ivjPass3Panel.setLayout(null); 404 ivjPass3Panel.setBackground(java.awt.SystemColor.controlShadow); 405 ivjPass3Panel.setBounds(30, 150, 50, 50); 406 } catch (java.lang.Throwable ivjExc) { 409 handleException(ivjExc); 412 } 413 } 414 return ivjPass3Panel; 415 } 416 417 418 419 private void handleException( java.lang.Throwable exception ) { 420 421 System.out.println("--------- UNCAUGHT EXCEPTION ---------"); 422 exception.printStackTrace(System.out); 423 } 424 425 426 427 private void initConnections() throws java.lang.Exception { 428 getPass1Button().addActionListener(ivjEventHandler); 431 getPass2Button().addActionListener(ivjEventHandler); 432 getPass3Button().addActionListener(ivjEventHandler); 433 getFlushButton().addActionListener(ivjEventHandler); 434 } 435 436 437 438 private void initialize() { 439 try { 440 setName("VerifyDialog"); 443 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 444 setSize(430, 280); 445 setVisible(true); 446 setModal(true); 447 setResizable(false); 448 setContentPane(getJDialogContentPane()); 449 initConnections(); 450 } catch (java.lang.Throwable ivjExc) { 451 handleException(ivjExc); 452 } 453 setTitle("'" + class_name + "' verification - JustIce / BCEL"); 455 } 457 458 459 465 public static void main( java.lang.String [] args ) { 466 classes_to_verify = args.length; 467 for (int i = 0; i < args.length; i++) { 468 try { 469 VerifyDialog aVerifyDialog; 470 aVerifyDialog = new VerifyDialog(args[i]); 471 aVerifyDialog.setModal(true); 472 aVerifyDialog.addWindowListener(new java.awt.event.WindowAdapter () { 473 474 public void windowClosing( java.awt.event.WindowEvent e ) { 475 classes_to_verify--; 476 if (classes_to_verify == 0) { 477 System.exit(0); 478 } 479 }; 480 }); 481 aVerifyDialog.setVisible(true); 482 } catch (Throwable exception) { 483 System.err.println("Exception occurred in main() of javax.swing.JDialog"); 484 exception.printStackTrace(System.out); 485 } 486 } 487 } 488 489 490 491 public void pass1Button_ActionPerformed( java.awt.event.ActionEvent actionEvent ) { 492 Verifier v = VerifierFactory.getVerifier(class_name); 493 VerificationResult vr = v.doPass1(); 494 if (vr.getStatus() == VerificationResult.VERIFIED_OK) { 495 getPass1Panel().setBackground(Color.green); 496 getPass1Panel().repaint(); 497 } 498 if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED) { 499 getPass1Panel().setBackground(Color.red); 500 getPass1Panel().repaint(); 501 } 502 } 503 504 505 506 public void pass2Button_ActionPerformed( java.awt.event.ActionEvent actionEvent ) { 507 pass1Button_ActionPerformed(actionEvent); 508 Verifier v = VerifierFactory.getVerifier(class_name); 509 VerificationResult vr = v.doPass2(); 510 if (vr.getStatus() == VerificationResult.VERIFIED_OK) { 511 getPass2Panel().setBackground(Color.green); 512 getPass2Panel().repaint(); 513 } 514 if (vr.getStatus() == VerificationResult.VERIFIED_NOTYET) { 515 getPass2Panel().setBackground(Color.yellow); 516 getPass2Panel().repaint(); 517 } 518 if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED) { 519 getPass2Panel().setBackground(Color.red); 520 getPass2Panel().repaint(); 521 } 522 } 523 524 525 526 public void pass4Button_ActionPerformed( java.awt.event.ActionEvent actionEvent ) { 527 pass2Button_ActionPerformed(actionEvent); 528 Color color = Color.green; 529 Verifier v = VerifierFactory.getVerifier(class_name); 530 VerificationResult vr = v.doPass2(); 531 if (vr.getStatus() == VerificationResult.VERIFIED_OK) { 532 JavaClass jc = null; 533 try { 534 jc = Repository.lookupClass(class_name); 535 int nr = jc.getMethods().length; 536 for (int i = 0; i < nr; i++) { 537 vr = v.doPass3b(i); 538 if (vr.getStatus() != VerificationResult.VERIFIED_OK) { 539 color = Color.red; 540 break; 541 } 542 } 543 } catch (ClassNotFoundException ex) { 544 ex.printStackTrace(); 546 } 547 } else { 548 color = Color.yellow; 549 } 550 getPass3Panel().setBackground(color); 551 getPass3Panel().repaint(); 552 } 553 } 554 | Popular Tags |