<s> import os <EOL> import sys <EOL> import signal <EOL> import logging <EOL> import cPickle <EOL> try : <EOL> from PySide import QtCore , QtGui <EOL> except ImportError : <EOL> import sip <EOL> sip . setapi ( '<STR_LIT>' , <NUM_LIT:2> ) <EOL> sip . setapi ( '<STR_LIT>' , <NUM_LIT:2> ) <EOL> from PyQt4 import QtCore , QtGui <EOL> QtGui . QFileDialog . getOpenFileName = QtGui . QFileDialog . getOpenFileNameAndFilter <EOL> QtGui . QFileDialog . getSaveFileName = QtGui . QFileDialog . getSaveFileNameAndFilter <EOL> from pyiiasmh_cli import PyiiAsmhApp <EOL> import mainwindow_ui <EOL> import prefs_ui <EOL> class PyiiAsmhGui ( PyiiAsmhApp ) : <EOL> def __init__ ( self ) : <EOL> super ( PyiiAsmhGui , self ) . __init__ ( ) <EOL> self . app = None <EOL> self . ui = None <EOL> self . uiprefs = None <EOL> self . filename = None <EOL> self . prefs = { "<STR_LIT>" : True , "<STR_LIT>" : False , <EOL> "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } <EOL> self . default_qtstyle = None <EOL> def convert ( self , action ) : <EOL> self . get_uivars ( action ) <EOL> stbar = self . ui . statusBar ( ) <EOL> if action == "<STR_LIT>" : <EOL> self . geckocodes = self . assemble ( self . opcodes , None , None ) <EOL> self . ui . geckocodesPTextEdit . setPlainText ( self . geckocodes ) <EOL> stbar . showMessage ( "<STR_LIT>" , <NUM_LIT> ) <EOL> else : <EOL> dsm_out = self . disassemble ( self . geckocodes , None , None ) <EOL> self . opcodes = dsm_out [ <NUM_LIT:0> ] <EOL> self . bapo = dsm_out [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] <EOL> self . xor = dsm_out [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] <EOL> self . chksum = dsm_out [ <NUM_LIT:1> ] [ <NUM_LIT:2> ] <EOL> self . codetype = dsm_out [ <NUM_LIT:1> ] [ <NUM_LIT:3> ] <EOL> self . ui . opcodesPTextEdit . setPlainText ( self . opcodes ) <EOL> if self . bapo is not None : <EOL> self . ui . bapoLineEdit . setText ( self . bapo ) <EOL> if self . xor is not None : <EOL> self . ui . xorLineEdit . setText ( self . xor ) <EOL> if self . chksum is not None : <EOL> self . ui . checksumLineEdit . setText ( self . chksum ) <EOL> self . radio = { "<STR_LIT>" : self . ui . c0Radio , <EOL> "<STR_LIT>" : self . ui . c2d2Radio , <EOL> "<STR_LIT>" : self . ui . f2f4Radio } <EOL> self . radio . get ( self . codetype , self . ui . rawRadio ) . setChecked ( True ) <EOL> stbar . showMessage ( "<STR_LIT>" , <NUM_LIT> ) <EOL> def get_uivars ( self , action ) : <EOL> if action == "<STR_LIT>" : <EOL> self . geckocodes = str ( self . ui . geckocodesPTextEdit . toPlainText ( ) ) <EOL> else : <EOL> self . bapo = str ( self . ui . bapoLineEdit . text ( ) ) <EOL> self . xor = str ( self . ui . xorLineEdit . text ( ) ) <EOL> self . chksum = str ( self . ui . checksumLineEdit . text ( ) ) <EOL> try : <EOL> self . opcodes = str ( self . ui . opcodesPTextEdit . toPlainText ( ) ) + "<STR_LIT:\n>" <EOL> except UnicodeEncodeError , UnicodeDecodeError : <EOL> self . opcodes = ( self . ui . opcodesPTextEdit . toPlainText ( ) + u"<STR_LIT:\n>" <EOL> ) . encode ( '<STR_LIT:ascii>' , '<STR_LIT:ignore>' ) <EOL> if self . ui . c0Radio . isChecked ( ) : <EOL> self . codetype = "<STR_LIT>" <EOL> elif self . ui . c2d2Radio . isChecked ( ) : <EOL> self . codetype = "<STR_LIT>" <EOL> elif self . ui . f2f4Radio . isChecked ( ) : <EOL> self . codetype = "<STR_LIT>" <EOL> else : <EOL> self . codetype = None <EOL> if self . bapo == "<STR_LIT>" : <EOL> if self . codetype not in ( "<STR_LIT>" , None ) : <EOL> self . bapo = "<STR_LIT>" <EOL> else : <EOL> self . bapo = None <EOL> if self . xor == "<STR_LIT>" : <EOL> if self . codetype == "<STR_LIT>" : <EOL> self . xor = "<STR_LIT>" <EOL> else : <EOL> self . xor = None <EOL> if self . chksum == "<STR_LIT>" : <EOL> if self . codetype == "<STR_LIT>" : <EOL> self . chksum = "<STR_LIT>" <EOL> else : <EOL> self . chksum = None <EOL> def confirm_prompt ( self , title , text , inform_text , detailed_text = None ) : <EOL> cp = QtGui . QMessageBox ( self . app . activeWindow ( ) ) <EOL> cp . setWindowTitle ( title ) <EOL> cp . setText ( text ) <EOL> cp . setInformativeText ( inform_text ) <EOL> if detailed_text is not None : <EOL> cp . setDetailedText ( detailed_text ) <EOL> cp . setIcon ( QtGui . QMessageBox . Warning ) <EOL> cp . setStandardButtons ( QtGui . QMessageBox . Yes | QtGui . QMessageBox . No ) <EOL> cp . setDefaultButton ( QtGui . QMessageBox . No ) <EOL> return cp . exec_ ( ) == QtGui . QMessageBox . No <EOL> def confirm_helper ( self , action , reload_file = False ) : <EOL> if self . prefs . get ( "<STR_LIT>" ) : <EOL> inform_text = "<STR_LIT>" <EOL> if action . __name__ == "<STR_LIT>" : <EOL> if reload_file : <EOL> title = "<STR_LIT>" <EOL> text = "<STR_LIT>" <EOL> else : <EOL> title = "<STR_LIT>" <EOL> text = "<STR_LIT>" <EOL> title += "<STR_LIT>" <EOL> text = "<STR_LIT>" + text <EOL> elif action . __name__ == "<STR_LIT>" : <EOL> title = "<STR_LIT>" <EOL> text = "<STR_LIT>" <EOL> else : <EOL> title = "<STR_LIT>" <EOL> text = "<STR_LIT>" <EOL> if self . confirm_prompt ( title , text , inform_text ) : <EOL> return <EOL> if action . __name__ == "<STR_LIT>" : <EOL> action ( reload_file ) <EOL> else : <EOL> action ( ) <EOL> def show_dialog ( self , dialog_type = None ) : <EOL> if dialog_type == "<STR_LIT>" : <EOL> QtGui . QMessageBox . aboutQt ( self . app . activeWindow ( ) ) <EOL> elif dialog_type == "<STR_LIT>" : <EOL> ext = "<STR_LIT>" <EOL> if sys . platform == "<STR_LIT:win32>" : <EOL> ext += "<STR_LIT>" <EOL> desc = "<STR_LIT>" <EOL> desc += "<STR_LIT>" <EOL> desc += "<STR_LIT>" <EOL> desc += "<STR_LIT>" <EOL> desc += "<STR_LIT>" <EOL> desc += "<STR_LIT>" <EOL> desc += "<STR_LIT>" <EOL> desc += "<STR_LIT>" <EOL> desc += "<STR_LIT>" + ext + "<STR_LIT>" <EOL> desc += "<STR_LIT>" <EOL> desc += "<STR_LIT>" <EOL> desc += "<STR_LIT>" <EOL> desc += "<STR_LIT>" <EOL> QtGui . QMessageBox . about ( self . app . activeWindow ( ) , <EOL> "<STR_LIT>" , desc ) <EOL> else : <EOL> self . uiprefs . show ( ) <EOL> def new_session ( self ) : <EOL> self . ui . bapoLineEdit . setText ( "<STR_LIT>" ) <EOL> self . ui . xorLineEdit . setText ( "<STR_LIT>" ) <EOL> self . ui . checksumLineEdit . setText ( "<STR_LIT>" ) <EOL> self . ui . opcodesPTextEdit . setPlainText ( "<STR_LIT>" ) <EOL> self . ui . geckocodesPTextEdit . setPlainText ( "<STR_LIT>" ) <EOL> self . ui . actionSave . setEnabled ( False ) <EOL> self . ui . actionReload . setEnabled ( False ) <EOL> self . filename = None <EOL> self . save_prefs ( ) <EOL> if self . prefs . get ( "<STR_LIT>" ) == "<STR_LIT>" : <EOL> self . ui . c0Radio . setChecked ( True ) <EOL> elif self . prefs . get ( "<STR_LIT>" ) == "<STR_LIT>" : <EOL> self . ui . c2d2Radio . setChecked ( True ) <EOL> elif self . prefs . get ( "<STR_LIT>" ) == "<STR_LIT>" : <EOL> self . ui . f2f4Radio . setChecked ( True ) <EOL> else : <EOL> self . ui . rawRadio . setChecked ( True ) <EOL> self . ui . setWindowTitle ( "<STR_LIT>" ) <EOL> self . ui . statusBar ( ) . showMessage ( "<STR_LIT>" , <NUM_LIT> ) <EOL> def open_session ( self , reload_file = False ) : <EOL> if not reload_file : <EOL> if self . filename is None : <EOL> fname = str ( QtGui . QFileDialog . getOpenFileName ( self . ui , <EOL> "<STR_LIT>" , os . path . expanduser ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" ) [ <NUM_LIT:0> ] ) <EOL> else : <EOL> fname = str ( QtGui . QFileDialog . getOpenFileName ( self . ui , <EOL> "<STR_LIT>" , os . path . split ( self . filename ) [ <NUM_LIT:0> ] , <EOL> "<STR_LIT>" ) [ <NUM_LIT:0> ] ) <EOL> if fname is "<STR_LIT>" : <EOL> return <EOL> else : <EOL> self . filename = fname <EOL> try : <EOL> f = open ( self . filename , "<STR_LIT:rb>" ) <EOL> except IOError as e : <EOL> self . log . exception ( e ) <EOL> else : <EOL> try : <EOL> data = cPickle . load ( f ) <EOL> except cPickle . UnpicklingError as e : <EOL> self . log . exception ( e ) <EOL> else : <EOL> self . ui . bapoLineEdit . setText ( data . get ( "<STR_LIT>" ) ) <EOL> self . ui . xorLineEdit . setText ( data . get ( "<STR_LIT>" ) ) <EOL> self . ui . checksumLineEdit . setText ( data . get ( "<STR_LIT>" ) ) <EOL> self . ui . opcodesPTextEdit . setPlainText ( data . get ( "<STR_LIT>" ) ) <EOL> self . ui . geckocodesPTextEdit . setPlainText ( data . get ( "<STR_LIT>" ) ) <EOL> self . ui . actionSave . setEnabled ( True ) <EOL> self . ui . actionReload . setEnabled ( True ) <EOL> if data . get ( "<STR_LIT>" ) == "<STR_LIT>" : <EOL> self . ui . c0Radio . setChecked ( True ) <EOL> elif data . get ( "<STR_LIT>" ) == "<STR_LIT>" : <EOL> self . ui . c2d2Radio . setChecked ( True ) <EOL> elif data . get ( "<STR_LIT>" ) == "<STR_LIT>" : <EOL> self . ui . f2f4Radio . setChecked ( True ) <EOL> else : <EOL> self . ui . rawRadio . setChecked ( True ) <EOL> self . save_prefs ( ) <EOL> self . ui . setWindowTitle ( "<STR_LIT>" + <EOL> os . path . split ( self . filename ) [ <NUM_LIT:1> ] ) <EOL> self . ui . statusBar ( ) . showMessage ( "<STR_LIT>" + <EOL> os . path . split ( self . filename ) [ <NUM_LIT:1> ] + "<STR_LIT>" , <NUM_LIT> ) <EOL> finally : <EOL> f . close ( ) <EOL> def save_session ( self , save_as = True ) : <EOL> if save_as : <EOL> if self . filename is None : <EOL> fname = str ( QtGui . QFileDialog . getSaveFileName ( self . ui , <EOL> "<STR_LIT>" , os . path . expanduser ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" ) [ <NUM_LIT:0> ] ) <EOL> else : <EOL> fname = str ( QtGui . QFileDialog . getSaveFileName ( self . ui , <EOL> "<STR_LIT>" , os . path . split ( self . filename ) [ <NUM_LIT:0> ] , <EOL> "<STR_LIT>" ) [ <NUM_LIT:0> ] ) <EOL> if fname is "<STR_LIT>" : <EOL> return <EOL> else : <EOL> self . filename = fname <EOL> try : <EOL> f = open ( self . filename , "<STR_LIT:wb>" ) <EOL> except IOError as e : <EOL> self . log . exception ( e ) <EOL> else : <EOL> data = { } <EOL> data [ "<STR_LIT>" ] = str ( self . ui . bapoLineEdit . text ( ) ) <EOL> data [ "<STR_LIT>" ] = str ( self . ui . xorLineEdit . text ( ) ) <EOL> data [ "<STR_LIT>" ] = str ( self . ui . checksumLineEdit . text ( ) ) <EOL> data [ "<STR_LIT>" ] = str ( self . ui . opcodesPTextEdit . toPlainText ( ) ) + "<STR_LIT:\n>" <EOL> data [ "<STR_LIT>" ] = str ( self . ui . geckocodesPTextEdit . toPlainText ( ) ) <EOL> if self . ui . c0Radio . isChecked ( ) : <EOL> data [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> elif self . ui . c2d2Radio . isChecked ( ) : <EOL> data [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> elif self . ui . f2f4Radio . isChecked ( ) : <EOL> data [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> else : <EOL> data [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> cPickle . dump ( data , f , <NUM_LIT:2> ) <EOL> self . ui . actionSave . setEnabled ( True ) <EOL> self . ui . actionReload . setEnabled ( True ) <EOL> self . save_prefs ( ) <EOL> self . ui . setWindowTitle ( "<STR_LIT>" + <EOL> os . path . split ( self . filename ) [ <NUM_LIT:1> ] ) <EOL> self . ui . statusBar ( ) . showMessage ( "<STR_LIT>" + <EOL> os . path . split ( self . filename ) [ <NUM_LIT:1> ] + "<STR_LIT>" , <NUM_LIT> ) <EOL> f . close ( ) <EOL> def load_prefs ( self ) : <EOL> try : <EOL> f = open ( "<STR_LIT>" , "<STR_LIT:rb>" ) <EOL> except IOError : <EOL> self . log . warning ( "<STR_LIT>" ) <EOL> else : <EOL> try : <EOL> filename = cPickle . load ( f ) <EOL> except cPickle . UnpicklingError as e : <EOL> self . log . exception ( e ) <EOL> else : <EOL> if filename is not None : <EOL> self . filename = filename <EOL> finally : <EOL> f . close ( ) <EOL> try : <EOL> f = open ( "<STR_LIT>" , "<STR_LIT:rb>" ) <EOL> except IOError : <EOL> self . log . warning ( "<STR_LIT>" ) <EOL> else : <EOL> try : <EOL> p = cPickle . load ( f ) <EOL> except cPickle . UnpicklingError as e : <EOL> self . log . exception ( e ) <EOL> else : <EOL> if p . get ( "<STR_LIT>" ) in ( True , False ) : <EOL> self . prefs [ "<STR_LIT>" ] = p . get ( "<STR_LIT>" ) <EOL> if p . get ( "<STR_LIT>" ) in ( True , False ) : <EOL> self . prefs [ "<STR_LIT>" ] = p . get ( "<STR_LIT>" ) <EOL> if p . get ( "<STR_LIT>" ) in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> self . prefs [ "<STR_LIT>" ] = p . get ( "<STR_LIT>" ) <EOL> if p . get ( "<STR_LIT>" ) == "<STR_LIT>" : <EOL> self . ui . c0Radio . setChecked ( True ) <EOL> if p . get ( "<STR_LIT>" ) == "<STR_LIT>" : <EOL> self . ui . c2d2Radio . setChecked ( True ) <EOL> if p . get ( "<STR_LIT>" ) == "<STR_LIT>" : <EOL> self . ui . f2f4Radio . setChecked ( True ) <EOL> if ( p . get ( "<STR_LIT>" ) in list ( QtGui . QStyleFactory . keys ( ) ) or <EOL> p . get ( "<STR_LIT>" ) == "<STR_LIT>" ) : <EOL> self . prefs [ "<STR_LIT>" ] = p . get ( "<STR_LIT>" ) <EOL> setCIndex = self . uiprefs . qtstyleSelect . setCurrentIndex <EOL> if self . prefs . get ( "<STR_LIT>" ) in ( None , "<STR_LIT>" ) : <EOL> setCIndex ( <NUM_LIT:0> ) <EOL> else : <EOL> setCIndex ( self . uiprefs . qtstyleSelect . findText ( <EOL> self . prefs . get ( "<STR_LIT>" ) , <EOL> flags = QtCore . Qt . MatchFixedString ) ) <EOL> setCIndex = self . uiprefs . codetypeSelect . setCurrentIndex <EOL> setCIndex ( self . uiprefs . codetypeSelect . findText ( <EOL> self . prefs . get ( "<STR_LIT>" ) , <EOL> flags = QtCore . Qt . MatchFixedString ) ) <EOL> self . ui . set_close_event ( self . prefs . get ( "<STR_LIT>" ) ) <EOL> self . uiprefs . confirmation . setChecked ( self . prefs . get ( "<STR_LIT>" ) ) <EOL> self . uiprefs . loadLast . setChecked ( self . prefs . get ( "<STR_LIT>" ) ) <EOL> finally : <EOL> f . close ( ) <EOL> def save_prefs ( self ) : <EOL> self . prefs [ "<STR_LIT>" ] = self . uiprefs . confirmation . isChecked ( ) <EOL> self . prefs [ "<STR_LIT>" ] = self . uiprefs . loadLast . isChecked ( ) <EOL> self . prefs [ "<STR_LIT>" ] = str ( self . uiprefs . codetypeSelect . currentText ( ) ) <EOL> self . prefs [ "<STR_LIT>" ] = str ( self . uiprefs . qtstyleSelect . currentText ( ) ) <EOL> self . ui . set_close_event ( self . prefs . get ( "<STR_LIT>" ) ) <EOL> try : <EOL> f = open ( "<STR_LIT>" , "<STR_LIT:wb>" ) <EOL> except IOError as e : <EOL> self . log . exception ( e ) <EOL> else : <EOL> cPickle . dump ( self . prefs , f , <NUM_LIT:2> ) <EOL> f . close ( ) <EOL> try : <EOL> f = open ( "<STR_LIT>" , "<STR_LIT:wb>" ) <EOL> except IOError as e : <EOL> self . log . exception ( e ) <EOL> else : <EOL> cPickle . dump ( self . filename , f , <NUM_LIT:2> ) <EOL> f . close ( ) <EOL> def load_qtstyle ( self , style , first_style_load = False ) : <EOL> if style != "<STR_LIT>" : <EOL> self . app . setStyle ( style ) <EOL> else : <EOL> self . app . setStyle ( self . default_qtstyle ) <EOL> if first_style_load : <EOL> setCIndex = self . uiprefs . qtstyleSelect . setCurrentIndex <EOL> setCIndex ( self . uiprefs . qtstyleSelect . findText ( style , <EOL> flags = QtCore . Qt . MatchFixedString ) ) <EOL> def connect_signals ( self ) : <EOL> connect = QtCore . QObject . connect <EOL> connect ( self . ui . asmButton , QtCore . SIGNAL ( "<STR_LIT>" ) , <EOL> lambda : self . convert ( "<STR_LIT>" ) ) <EOL> connect ( self . ui . dsmButton , QtCore . SIGNAL ( "<STR_LIT>" ) , <EOL> lambda : self . convert ( "<STR_LIT>" ) ) <EOL> connect ( self . ui . actionQuit , QtCore . SIGNAL ( "<STR_LIT>" ) , <EOL> lambda : self . confirm_helper ( self . ui . close ) ) <EOL> connect ( self . ui . actionPreferences , QtCore . SIGNAL ( "<STR_LIT>" ) , <EOL> self . show_dialog ) <EOL> connect ( self . ui . actionAbout_Qt , QtCore . SIGNAL ( "<STR_LIT>" ) , <EOL> lambda : self . show_dialog ( "<STR_LIT>" ) ) <EOL> connect ( self . ui . actionAbout_PyiiASMH , QtCore . SIGNAL ( "<STR_LIT>" ) , <EOL> lambda : self . show_dialog ( "<STR_LIT>" ) ) <EOL> connect ( self . ui . actionNew , QtCore . SIGNAL ( "<STR_LIT>" ) , <EOL> lambda : self . confirm_helper ( self . new_session ) ) <EOL> connect ( self . ui . actionOpen , QtCore . SIGNAL ( "<STR_LIT>" ) , <EOL> lambda : self . confirm_helper ( self . open_session ) ) <EOL> connect ( self . ui . actionSave_As , QtCore . SIGNAL ( "<STR_LIT>" ) , <EOL> self . save_session ) <EOL> connect ( self . ui . actionReload , QtCore . SIGNAL ( "<STR_LIT>" ) , <EOL> lambda : self . confirm_helper ( self . open_session , True ) ) <EOL> connect ( self . ui . actionSave , QtCore . SIGNAL ( "<STR_LIT>" ) , <EOL> lambda : self . save_session ( False ) ) <EOL> connect ( self . uiprefs . buttonBox , QtCore . SIGNAL ( "<STR_LIT>" ) , <EOL> self . save_prefs ) <EOL> connect ( self . uiprefs . qtstyleSelect , <EOL> QtCore . SIGNAL ( "<STR_LIT>" ) , <EOL> lambda : self . load_qtstyle ( <EOL> self . uiprefs . qtstyleSelect . currentText ( ) ) ) <EOL> def run ( self ) : <EOL> self . app = QtGui . QApplication ( sys . argv ) <EOL> self . default_qtstyle = self . app . style ( ) . objectName ( ) <EOL> self . ui = mainwindow_ui . MainWindowUi ( ) <EOL> self . uiprefs = prefs_ui . PrefsUi ( ) <EOL> self . uiprefs . qtstyleSelect . addItem ( "<STR_LIT>" ) <EOL> for i in range ( <NUM_LIT:0> , len ( list ( QtGui . QStyleFactory . keys ( ) ) ) ) : <EOL> self . uiprefs . qtstyleSelect . addItem ( <EOL> list ( QtGui . QStyleFactory . keys ( ) ) [ i ] ) <EOL> self . load_prefs ( ) <EOL> self . load_qtstyle ( self . prefs . get ( "<STR_LIT>" ) , True ) <EOL> self . ui . opcodesPTextEdit . setFocus ( ) <EOL> regex = QtCore . QRegExp ( "<STR_LIT>" ) <EOL> validator = QtGui . QRegExpValidator ( regex , None ) <EOL> self . ui . bapoLineEdit . setValidator ( validator ) <EOL> self . ui . xorLineEdit . setValidator ( validator ) <EOL> self . ui . checksumLineEdit . setValidator ( validator ) <EOL> if self . filename is not None and self . prefs . get ( "<STR_LIT>" ) : <EOL> self . open_session ( self . filename ) <EOL> self . connect_signals ( ) <EOL> self . ui . show ( ) <EOL> sys . exit ( self . app . exec_ ( ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> app = PyiiAsmhGui ( ) <EOL> signal . signal ( signal . SIGINT , signal . SIG_DFL ) <EOL> app . run ( ) </s>
