<s> from PySide import QtCore , QtGui <EOL> from androguard . core import androconf <EOL> from androguard . gui . helpers import display2classmethod , class2func , classmethod2display , method2func <EOL> class XrefDialogClass ( QtGui . QDialog ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , <EOL> parent = None , <EOL> win = None , <EOL> current_class = None , <EOL> class_analysis = None ) : <EOL> super ( XrefDialogClass , self ) . __init__ ( parent ) <EOL> self . current_class = current_class <EOL> self . class_analysis = class_analysis <EOL> title = "<STR_LIT>" % current_class <EOL> self . setWindowTitle ( title ) <EOL> xrefs_list = [ ] <EOL> ref_kind_map = { <NUM_LIT:0> : "<STR_LIT>" , <NUM_LIT:1> : "<STR_LIT>" } <EOL> xrefs_from = class_analysis . get_xref_from ( ) <EOL> for ref_class in xrefs_from : <EOL> for ref_kind , ref_method , _ in xrefs_from [ ref_class ] : <EOL> xrefs_list . append ( ( '<STR_LIT>' , ref_kind_map [ ref_kind ] , ref_method , <EOL> ref_class . get_vm_class ( ) ) ) <EOL> xrefs_to = class_analysis . get_xref_to ( ) <EOL> for ref_class in xrefs_to : <EOL> for ref_kind , ref_method , _ in xrefs_to [ ref_class ] : <EOL> xrefs_list . append ( ( '<STR_LIT>' , ref_kind_map [ ref_kind ] , ref_method , <EOL> ref_class . get_vm_class ( ) ) ) <EOL> closeButton = QtGui . QPushButton ( "<STR_LIT>" ) <EOL> closeButton . clicked . connect ( self . close ) <EOL> xreflayout = QtGui . QGridLayout ( ) <EOL> xrefwin = XrefListView ( self , <EOL> win = win , <EOL> xrefs = xrefs_list , <EOL> headers = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> xreflayout . addWidget ( xrefwin , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> buttonsLayout = QtGui . QHBoxLayout ( ) <EOL> buttonsLayout . addStretch ( <NUM_LIT:1> ) <EOL> buttonsLayout . addWidget ( closeButton ) <EOL> mainLayout = QtGui . QVBoxLayout ( ) <EOL> mainLayout . addLayout ( xreflayout ) <EOL> mainLayout . addLayout ( buttonsLayout ) <EOL> self . setLayout ( mainLayout ) <EOL> class XrefDialogMethod ( QtGui . QDialog ) : <EOL> def __init__ ( self , <EOL> parent = None , <EOL> win = None , <EOL> current_class = None , <EOL> class_analysis = None , <EOL> method_analysis = None ) : <EOL> super ( XrefDialogMethod , self ) . __init__ ( parent ) <EOL> self . current_class = current_class <EOL> self . class_analysis = class_analysis <EOL> self . method_analysis = method_analysis <EOL> title = "<STR_LIT>" % self . method_analysis . method <EOL> self . setWindowTitle ( title ) <EOL> xrefs_list = [ ] <EOL> xrefs_from = self . method_analysis . get_xref_from ( ) <EOL> for ref_class , ref_method , _ in xrefs_from : <EOL> xrefs_list . append ( ( '<STR_LIT>' , ref_method , ref_class . get_vm_class ( ) ) ) <EOL> xrefs_to = self . method_analysis . get_xref_to ( ) <EOL> for ref_class , ref_method , _ in xrefs_to : <EOL> xrefs_list . append ( ( '<STR_LIT>' , ref_method , ref_class . get_vm_class ( ) ) ) <EOL> closeButton = QtGui . QPushButton ( "<STR_LIT>" ) <EOL> closeButton . clicked . connect ( self . close ) <EOL> xreflayout = QtGui . QGridLayout ( ) <EOL> xrefwin = XrefListView ( self , win = win , xrefs = xrefs_list ) <EOL> xreflayout . addWidget ( xrefwin , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> buttonsLayout = QtGui . QHBoxLayout ( ) <EOL> buttonsLayout . addStretch ( <NUM_LIT:1> ) <EOL> buttonsLayout . addWidget ( closeButton ) <EOL> mainLayout = QtGui . QVBoxLayout ( ) <EOL> mainLayout . addLayout ( xreflayout ) <EOL> mainLayout . addLayout ( buttonsLayout ) <EOL> self . setLayout ( mainLayout ) <EOL> class XrefDialogField ( QtGui . QDialog ) : <EOL> def __init__ ( self , <EOL> parent = None , <EOL> win = None , <EOL> current_class = None , <EOL> class_analysis = None , <EOL> field_analysis = None ) : <EOL> super ( XrefDialogField , self ) . __init__ ( parent ) <EOL> self . current_class = current_class <EOL> self . class_analysis = class_analysis <EOL> self . field_analysis = field_analysis <EOL> title = "<STR_LIT>" % self . field_analysis . field <EOL> self . setWindowTitle ( title ) <EOL> xrefs_list = [ ] <EOL> xrefs_read = self . field_analysis . get_xref_read ( ) <EOL> for ref_class , ref_method in xrefs_read : <EOL> xrefs_list . append ( ( '<STR_LIT>' , ref_method , ref_class . get_vm_class ( ) ) ) <EOL> xrefs_write = self . field_analysis . get_xref_write ( ) <EOL> for ref_class , ref_method in xrefs_write : <EOL> xrefs_list . append ( ( '<STR_LIT>' , ref_method , ref_class . get_vm_class ( ) ) ) <EOL> closeButton = QtGui . QPushButton ( "<STR_LIT>" ) <EOL> closeButton . clicked . connect ( self . close ) <EOL> xreflayout = QtGui . QGridLayout ( ) <EOL> xrefwin = XrefListView ( self , win = win , xrefs = xrefs_list ) <EOL> xreflayout . addWidget ( xrefwin , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> buttonsLayout = QtGui . QHBoxLayout ( ) <EOL> buttonsLayout . addStretch ( <NUM_LIT:1> ) <EOL> buttonsLayout . addWidget ( closeButton ) <EOL> mainLayout = QtGui . QVBoxLayout ( ) <EOL> mainLayout . addLayout ( xreflayout ) <EOL> mainLayout . addLayout ( buttonsLayout ) <EOL> self . setLayout ( mainLayout ) <EOL> class XrefDialogString ( QtGui . QDialog ) : <EOL> def __init__ ( self , parent = None , win = None , string_analysis = None ) : <EOL> super ( XrefDialogString , self ) . __init__ ( parent ) <EOL> self . string_analysis = string_analysis <EOL> title = "<STR_LIT>" % self . string_analysis . value <EOL> self . setWindowTitle ( title ) <EOL> xrefs_list = [ ] <EOL> xrefs_from = self . string_analysis . get_xref_from ( ) <EOL> for ref_class , ref_method in xrefs_from : <EOL> xrefs_list . append ( ( '<STR_LIT>' , ref_method , ref_class . get_vm_class ( ) ) ) <EOL> closeButton = QtGui . QPushButton ( "<STR_LIT>" ) <EOL> closeButton . clicked . connect ( self . close ) <EOL> xreflayout = QtGui . QGridLayout ( ) <EOL> xrefwin = XrefListView ( self , win = win , xrefs = xrefs_list ) <EOL> xreflayout . addWidget ( xrefwin , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> buttonsLayout = QtGui . QHBoxLayout ( ) <EOL> buttonsLayout . addStretch ( <NUM_LIT:1> ) <EOL> buttonsLayout . addWidget ( closeButton ) <EOL> mainLayout = QtGui . QVBoxLayout ( ) <EOL> mainLayout . addLayout ( xreflayout ) <EOL> mainLayout . addLayout ( buttonsLayout ) <EOL> self . setLayout ( mainLayout ) <EOL> class XrefDialog ( QtGui . QDialog ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , parent = None , win = None , xrefs_list = None , method = "<STR_LIT>" ) : <EOL> super ( XrefDialog , self ) . __init__ ( parent ) <EOL> if not isinstance ( xrefs_list , list ) or len ( xrefs_list ) == <NUM_LIT:0> : <EOL> androconf . warning ( "<STR_LIT>" ) <EOL> return <EOL> if not method : <EOL> title = "<STR_LIT>" % path . split ( "<STR_LIT:/>" ) [ - <NUM_LIT:1> ] <EOL> else : <EOL> title = "<STR_LIT>" % ( path . split ( "<STR_LIT:/>" ) [ - <NUM_LIT:1> ] , method ) <EOL> self . setWindowTitle ( title ) <EOL> layout = QtGui . QGridLayout ( ) <EOL> xrefwin = XrefListView ( self , win = win , xrefs = xrefs_list ) <EOL> layout . addWidget ( xrefwin , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> self . setLayout ( layout ) <EOL> @ classmethod <EOL> def get_xrefs_list ( cls , class_item , method = None ) : <EOL> '''<STR_LIT>''' <EOL> androconf . debug ( "<STR_LIT>" % class_item ) <EOL> item = class_item <EOL> if method : <EOL> item = method <EOL> return XrefDialog . get_xrefs_list_from_element ( item ) <EOL> @ classmethod <EOL> def get_xrefs_list_from_element ( cls , element ) : <EOL> '''<STR_LIT>''' <EOL> xref_items = element . XREFfrom . items <EOL> androconf . debug ( "<STR_LIT>" % len ( xref_items ) ) <EOL> xrefs = [ ] <EOL> for xref_item in xref_items : <EOL> class_ = xref_item [ <NUM_LIT:0> ] . get_class_name ( ) <EOL> method_ = xref_item [ <NUM_LIT:0> ] . get_name ( ) <EOL> descriptor_ = xref_item [ <NUM_LIT:0> ] . get_descriptor ( ) <EOL> xrefs . append ( classmethod2display ( class_ , method_ , descriptor_ ) ) <EOL> return xrefs <EOL> class XrefListView ( QtGui . QWidget ) : <EOL> def __init__ ( self , <EOL> parent = None , <EOL> win = None , <EOL> xrefs = None , <EOL> headers = [ "<STR_LIT>" , "<STR_LIT>" ] ) : <EOL> super ( XrefListView , self ) . __init__ ( parent ) <EOL> self . parent = parent <EOL> self . mainwin = win <EOL> self . xrefs = xrefs <EOL> self . headers = headers <EOL> self . setMinimumSize ( <NUM_LIT> , <NUM_LIT> ) <EOL> self . filterPatternLineEdit = QtGui . QLineEdit ( ) <EOL> self . filterPatternLabel = QtGui . QLabel ( "<STR_LIT>" ) <EOL> self . filterPatternLabel . setBuddy ( self . filterPatternLineEdit ) <EOL> self . filterPatternLineEdit . textChanged . connect ( self . filterRegExpChanged ) <EOL> self . xrefwindow = XrefValueWindow ( self , win , self . xrefs , self . headers ) <EOL> sourceLayout = QtGui . QVBoxLayout ( ) <EOL> sourceLayout . addWidget ( self . xrefwindow ) <EOL> sourceLayout . addWidget ( self . filterPatternLabel ) <EOL> sourceLayout . addWidget ( self . filterPatternLineEdit ) <EOL> self . setLayout ( sourceLayout ) <EOL> def filterRegExpChanged ( self , value ) : <EOL> regExp = QtCore . QRegExp ( value ) <EOL> self . xrefwindow . proxyModel . setFilterRegExp ( regExp ) <EOL> def close ( self ) : <EOL> self . parent . close ( ) <EOL> class XrefValueWindow ( QtGui . QTreeView ) : <EOL> def __init__ ( self , parent = None , win = None , xrefs = None , headers = None ) : <EOL> super ( XrefValueWindow , self ) . __init__ ( parent ) <EOL> self . parent = parent <EOL> self . mainwin = win <EOL> self . xrefs = xrefs <EOL> self . headers = headers <EOL> self . reverse_strings = { } <EOL> self . proxyModel = QtGui . QSortFilterProxyModel ( ) <EOL> self . proxyModel . setDynamicSortFilter ( True ) <EOL> self . model = QtGui . QStandardItemModel ( len ( self . xrefs ) , <EOL> len ( self . headers ) , self ) <EOL> column = <NUM_LIT:0> <EOL> for header in headers : <EOL> self . model . setHeaderData ( column , QtCore . Qt . Horizontal , header ) <EOL> column += <NUM_LIT:1> <EOL> row = <NUM_LIT:0> <EOL> for ref in xrefs : <EOL> for column in range ( len ( self . headers ) ) : <EOL> self . model . setData ( self . model . index ( <EOL> row , column , QtCore . QModelIndex ( ) ) , "<STR_LIT:%s>" % ref [ column ] ) <EOL> row += <NUM_LIT:1> <EOL> self . proxyModel . setSourceModel ( self . model ) <EOL> self . setRootIsDecorated ( False ) <EOL> self . setAlternatingRowColors ( True ) <EOL> self . setModel ( self . proxyModel ) <EOL> self . setSortingEnabled ( True ) <EOL> self . setEditTriggers ( QtGui . QAbstractItemView . NoEditTriggers ) <EOL> self . doubleClicked . connect ( self . slotDoubleClicked ) <EOL> def slotDoubleClicked ( self , mi ) : <EOL> mi = self . proxyModel . mapToSource ( mi ) <EOL> row = mi . row ( ) <EOL> column = mi . column ( ) <EOL> if column == len ( self . headers ) - <NUM_LIT:1> : <EOL> data = mi . data ( ) <EOL> xref_method = None <EOL> xref_class = None <EOL> for xref in self . xrefs : <EOL> if str ( xref [ - <NUM_LIT:2> ] ) == data : <EOL> xref_method = xref [ - <NUM_LIT:2> ] <EOL> xref_class = xref [ - <NUM_LIT:1> ] <EOL> break <EOL> if xref_class and xref_method : <EOL> self . mainwin . openSourceWindow ( current_class = xref_class , <EOL> method = xref_method ) <EOL> self . parent . close ( ) <EOL> return <EOL> else : <EOL> self . mainwin . showStatus ( "<STR_LIT>" ) <EOL> return </s>
