1 package com.sun.org.apache.bcel.internal.verifier; 2 3 56 57 import com.sun.org.apache.bcel.internal.*; 58 import com.sun.org.apache.bcel.internal.classfile.*; 59 import com.sun.org.apache.bcel.internal.verifier.*; 60 import java.awt.Color ; 61 62 76 public class VerifyDialog extends javax.swing.JDialog { 77 78 private javax.swing.JPanel ivjJDialogContentPane = null; 79 80 private javax.swing.JPanel ivjPass1Panel = null; 81 82 private javax.swing.JPanel ivjPass2Panel = null; 83 84 private javax.swing.JPanel ivjPass3Panel = null; 85 86 private javax.swing.JButton ivjPass1Button = null; 87 88 private javax.swing.JButton ivjPass2Button = null; 89 90 private javax.swing.JButton ivjPass3Button = null; 91 92 IvjEventHandler ivjEventHandler = new IvjEventHandler(); 93 94 99 private String class_name = "java.lang.Object"; 100 101 106 private static int classes_to_verify; 107 108 109 class IvjEventHandler implements java.awt.event.ActionListener { 110 public void actionPerformed(java.awt.event.ActionEvent e) { 111 if (e.getSource() == VerifyDialog.this.getPass1Button()) 112 connEtoC1(e); 113 if (e.getSource() == VerifyDialog.this.getPass2Button()) 114 connEtoC2(e); 115 if (e.getSource() == VerifyDialog.this.getPass3Button()) 116 connEtoC3(e); 117 if (e.getSource() == VerifyDialog.this.getFlushButton()) 118 connEtoC4(e); 119 }; 120 }; 121 122 private javax.swing.JButton ivjFlushButton = null; 123 124 public VerifyDialog() { 125 super(); 126 initialize(); 127 } 128 129 130 public VerifyDialog(java.awt.Dialog owner) { 131 super(owner); 132 } 133 134 135 public VerifyDialog(java.awt.Dialog owner, String title) { 136 super(owner, title); 137 } 138 139 140 public VerifyDialog(java.awt.Dialog owner, String title, boolean modal) { 141 super(owner, title, modal); 142 } 143 144 145 public VerifyDialog(java.awt.Dialog owner, boolean modal) { 146 super(owner, modal); 147 } 148 149 150 public VerifyDialog(java.awt.Frame owner) { 151 super(owner); 152 } 153 154 155 public VerifyDialog(java.awt.Frame owner, String title) { 156 super(owner, title); 157 } 158 159 160 public VerifyDialog(java.awt.Frame owner, String title, boolean modal) { 161 super(owner, title, modal); 162 } 163 164 165 public VerifyDialog(java.awt.Frame owner, boolean modal) { 166 super(owner, modal); 167 } 168 169 174 public VerifyDialog(String fully_qualified_class_name) { 175 super(); 176 177 int dotclasspos = fully_qualified_class_name.lastIndexOf(".class"); 178 if (dotclasspos != -1) fully_qualified_class_name = fully_qualified_class_name.substring(0,dotclasspos); 179 fully_qualified_class_name = fully_qualified_class_name.replace('/', '.'); 180 181 class_name = fully_qualified_class_name; 182 initialize(); 183 } 184 185 186 187 private void connEtoC1(java.awt.event.ActionEvent arg1) { 188 try { 189 this.pass1Button_ActionPerformed(arg1); 192 } catch (java.lang.Throwable ivjExc) { 195 handleException(ivjExc); 198 } 199 } 200 201 202 private void connEtoC2(java.awt.event.ActionEvent arg1) { 203 try { 204 this.pass2Button_ActionPerformed(arg1); 207 } catch (java.lang.Throwable ivjExc) { 210 handleException(ivjExc); 213 } 214 } 215 216 217 private void connEtoC3(java.awt.event.ActionEvent arg1) { 218 try { 219 this.pass4Button_ActionPerformed(arg1); 222 } catch (java.lang.Throwable ivjExc) { 225 handleException(ivjExc); 228 } 229 } 230 231 232 private void connEtoC4(java.awt.event.ActionEvent arg1) { 233 try { 234 this.flushButton_ActionPerformed(arg1); 237 } catch (java.lang.Throwable ivjExc) { 240 handleException(ivjExc); 243 } 244 } 245 246 247 public void flushButton_ActionPerformed(java.awt.event.ActionEvent actionEvent) { 248 VerifierFactory.getVerifier(class_name).flush(); 249 Repository.removeClass(class_name); getPass1Panel().setBackground(Color.gray); 251 getPass1Panel().repaint(); 252 getPass2Panel().setBackground(Color.gray); 253 getPass2Panel().repaint(); 254 getPass3Panel().setBackground(Color.gray); 255 getPass3Panel().repaint(); 256 } 257 258 259 private javax.swing.JButton getFlushButton() { 260 if (ivjFlushButton == null) { 261 try { 262 ivjFlushButton = new javax.swing.JButton (); 263 ivjFlushButton.setName("FlushButton"); 264 ivjFlushButton.setText("Flush: Forget old verification results"); 265 ivjFlushButton.setBackground(java.awt.SystemColor.controlHighlight); 266 ivjFlushButton.setBounds(60, 215, 300, 30); 267 ivjFlushButton.setForeground(java.awt.Color.red); 268 ivjFlushButton.setActionCommand("FlushButton"); 269 } catch (java.lang.Throwable ivjExc) { 272 handleException(ivjExc); 275 } 276 } 277 return ivjFlushButton; 278 } 279 280 281 private javax.swing.JPanel getJDialogContentPane() { 282 if (ivjJDialogContentPane == null) { 283 try { 284 ivjJDialogContentPane = new javax.swing.JPanel (); 285 ivjJDialogContentPane.setName("JDialogContentPane"); 286 ivjJDialogContentPane.setLayout(null); 287 getJDialogContentPane().add(getPass1Panel(), getPass1Panel().getName()); 288 getJDialogContentPane().add(getPass3Panel(), getPass3Panel().getName()); 289 getJDialogContentPane().add(getPass2Panel(), getPass2Panel().getName()); 290 getJDialogContentPane().add(getPass1Button(), getPass1Button().getName()); 291 getJDialogContentPane().add(getPass2Button(), getPass2Button().getName()); 292 getJDialogContentPane().add(getPass3Button(), getPass3Button().getName()); 293 getJDialogContentPane().add(getFlushButton(), getFlushButton().getName()); 294 } catch (java.lang.Throwable ivjExc) { 297 handleException(ivjExc); 300 } 301 } 302 return ivjJDialogContentPane; 303 } 304 305 306 private javax.swing.JButton getPass1Button() { 307 if (ivjPass1Button == null) { 308 try { 309 ivjPass1Button = new javax.swing.JButton (); 310 ivjPass1Button.setName("Pass1Button"); 311 ivjPass1Button.setText("Pass1: Verify binary layout of .class file"); 312 ivjPass1Button.setBackground(java.awt.SystemColor.controlHighlight); 313 ivjPass1Button.setBounds(100, 40, 300, 30); 314 ivjPass1Button.setActionCommand("Button1"); 315 } catch (java.lang.Throwable ivjExc) { 318 handleException(ivjExc); 321 } 322 } 323 return ivjPass1Button; 324 } 325 326 327 private javax.swing.JPanel getPass1Panel() { 328 if (ivjPass1Panel == null) { 329 try { 330 ivjPass1Panel = new javax.swing.JPanel (); 331 ivjPass1Panel.setName("Pass1Panel"); 332 ivjPass1Panel.setLayout(null); 333 ivjPass1Panel.setBackground(java.awt.SystemColor.controlShadow); 334 ivjPass1Panel.setBounds(30, 30, 50, 50); 335 } catch (java.lang.Throwable ivjExc) { 338 handleException(ivjExc); 341 } 342 } 343 return ivjPass1Panel; 344 } 345 346 347 private javax.swing.JButton getPass2Button() { 348 if (ivjPass2Button == null) { 349 try { 350 ivjPass2Button = new javax.swing.JButton (); 351 ivjPass2Button.setName("Pass2Button"); 352 ivjPass2Button.setText("Pass 2: Verify static .class file constraints"); 353 ivjPass2Button.setBackground(java.awt.SystemColor.controlHighlight); 354 ivjPass2Button.setBounds(100, 100, 300, 30); 355 ivjPass2Button.setActionCommand("Button2"); 356 } catch (java.lang.Throwable ivjExc) { 359 handleException(ivjExc); 362 } 363 } 364 return ivjPass2Button; 365 } 366 367 368 private javax.swing.JPanel getPass2Panel() { 369 if (ivjPass2Panel == null) { 370 try { 371 ivjPass2Panel = new javax.swing.JPanel (); 372 ivjPass2Panel.setName("Pass2Panel"); 373 ivjPass2Panel.setLayout(null); 374 ivjPass2Panel.setBackground(java.awt.SystemColor.controlShadow); 375 ivjPass2Panel.setBounds(30, 90, 50, 50); 376 } catch (java.lang.Throwable ivjExc) { 379 handleException(ivjExc); 382 } 383 } 384 return ivjPass2Panel; 385 } 386 387 388 private javax.swing.JButton getPass3Button() { 389 if (ivjPass3Button == null) { 390 try { 391 ivjPass3Button = new javax.swing.JButton (); 392 ivjPass3Button.setName("Pass3Button"); 393 ivjPass3Button.setText("Passes 3a+3b: Verify code arrays"); 394 ivjPass3Button.setBackground(java.awt.SystemColor.controlHighlight); 395 ivjPass3Button.setBounds(100, 160, 300, 30); 396 ivjPass3Button.setActionCommand("Button2"); 397 } catch (java.lang.Throwable ivjExc) { 400 handleException(ivjExc); 403 } 404 } 405 return ivjPass3Button; 406 } 407 408 409 private javax.swing.JPanel getPass3Panel() { 410 if (ivjPass3Panel == null) { 411 try { 412 ivjPass3Panel = new javax.swing.JPanel (); 413 ivjPass3Panel.setName("Pass3Panel"); 414 ivjPass3Panel.setLayout(null); 415 ivjPass3Panel.setBackground(java.awt.SystemColor.controlShadow); 416 ivjPass3Panel.setBounds(30, 150, 50, 50); 417 } catch (java.lang.Throwable ivjExc) { 420 handleException(ivjExc); 423 } 424 } 425 return ivjPass3Panel; 426 } 427 428 429 private void handleException(java.lang.Throwable exception) { 430 431 432 System.out.println("--------- UNCAUGHT EXCEPTION ---------"); 433 exception.printStackTrace(System.out); 434 } 435 436 437 438 private void initConnections() throws java.lang.Exception { 439 getPass1Button().addActionListener(ivjEventHandler); 442 getPass2Button().addActionListener(ivjEventHandler); 443 getPass3Button().addActionListener(ivjEventHandler); 444 getFlushButton().addActionListener(ivjEventHandler); 445 } 446 447 448 private void initialize() { 449 try { 450 setName("VerifyDialog"); 453 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 454 setSize(430, 280); 455 setVisible(true); 456 setModal(true); 457 setResizable(false); 458 setContentPane(getJDialogContentPane()); 459 initConnections(); 460 } catch (java.lang.Throwable ivjExc) { 461 handleException(ivjExc); 462 } 463 setTitle("'"+class_name+"' verification - JustIce / BCEL"); 465 } 467 473 public static void _main(java.lang.String [] args) { 474 classes_to_verify = args.length; 475 476 for (int i=0; i<args.length; i++){ 477 478 try { 479 VerifyDialog aVerifyDialog; 480 aVerifyDialog = new VerifyDialog(args[i]); 481 aVerifyDialog.setModal(true); 482 aVerifyDialog.addWindowListener(new java.awt.event.WindowAdapter () { 483 public void windowClosing(java.awt.event.WindowEvent e) { 484 classes_to_verify--; 485 if (classes_to_verify == 0) System.exit(0); 486 }; 487 }); 488 aVerifyDialog.setVisible(true); 489 } catch (Throwable exception) { 490 System.err.println("Exception occurred in main() of javax.swing.JDialog"); 491 exception.printStackTrace(System.out); 492 } 493 494 } 495 } 496 497 498 public void pass1Button_ActionPerformed(java.awt.event.ActionEvent actionEvent) { 499 Verifier v = VerifierFactory.getVerifier(class_name); 500 VerificationResult vr = v.doPass1(); 501 if (vr.getStatus() == VerificationResult.VERIFIED_OK){ 502 getPass1Panel().setBackground(Color.green); 503 getPass1Panel().repaint(); 504 } 505 if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED){ 506 getPass1Panel().setBackground(Color.red); 507 getPass1Panel().repaint(); 508 } 509 } 510 511 512 public void pass2Button_ActionPerformed(java.awt.event.ActionEvent actionEvent) { 513 pass1Button_ActionPerformed(actionEvent); 514 515 Verifier v = VerifierFactory.getVerifier(class_name); 516 VerificationResult vr = v.doPass2(); 517 if (vr.getStatus() == VerificationResult.VERIFIED_OK){ 518 getPass2Panel().setBackground(Color.green); 519 getPass2Panel().repaint(); 520 } 521 if (vr.getStatus() == VerificationResult.VERIFIED_NOTYET){ 522 getPass2Panel().setBackground(Color.yellow); 523 getPass2Panel().repaint(); 524 } 525 if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED){ 526 getPass2Panel().setBackground(Color.red); 527 getPass2Panel().repaint(); 528 } 529 } 530 531 532 public void pass4Button_ActionPerformed(java.awt.event.ActionEvent actionEvent) { 533 534 pass2Button_ActionPerformed(actionEvent); 535 536 537 Color color = Color.green; 538 539 Verifier v = VerifierFactory.getVerifier(class_name); 540 VerificationResult vr = v.doPass2(); 541 if (vr.getStatus() == VerificationResult.VERIFIED_OK){ 542 JavaClass jc = Repository.lookupClass(class_name); 543 int nr = jc.getMethods().length; 544 for (int i=0; i<nr; i++) { 545 vr = v.doPass3b(i); 546 if (vr.getStatus() != VerificationResult.VERIFIED_OK){ 547 color = Color.red; 548 break; 549 } 550 } 551 } 552 else{ 553 color = Color.yellow; 554 } 555 556 getPass3Panel().setBackground(color); 557 getPass3Panel().repaint(); 558 } 559 } 560 | Popular Tags |