Package IDAscope :: Module IDAscope
[hide private]
[frames] | no frames]

Source Code for Module IDAscope.IDAscope

  1  #!/usr/bin/python 
  2  ######################################################################## 
  3  # Copyright (c) 2012 
  4  # Daniel Plohmann <daniel.plohmann<at>gmail<dot>com> 
  5  # Alexander Hanel <alexander.hanel<at>gmail<dot>com> 
  6  # All rights reserved. 
  7  ######################################################################## 
  8  # 
  9  #  This file is part of IDAscope 
 10  # 
 11  #  IDAscope is free software: you can redistribute it and/or modify it 
 12  #  under the terms of the GNU General Public License as published by 
 13  #  the Free Software Foundation, either version 3 of the License, or 
 14  #  (at your option) any later version. 
 15  # 
 16  #  This program is distributed in the hope that it will be useful, but 
 17  #  WITHOUT ANY WARRANTY; without even the implied warranty of 
 18  #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
 19  #  General Public License for more details. 
 20  # 
 21  #  You should have received a copy of the GNU General Public License 
 22  #  along with this program.  If not, see 
 23  #  <http://www.gnu.org/licenses/>. 
 24  # 
 25  ######################################################################## 
 26   
 27  import os 
 28  import time 
 29   
 30  import idaapi 
 31  from idaapi import PluginForm, plugin_t 
 32  from PySide import QtGui 
 33  from PySide.QtGui import QIcon 
 34   
 35  from idascope.core.structures.IDAscopeConfiguration import IDAscopeConfiguration 
 36  from idascope.core.SemanticIdentifier import SemanticIdentifier 
 37  from idascope.core.DocumentationHelper import DocumentationHelper 
 38  from idascope.core.WinApiProvider import WinApiProvider 
 39  from idascope.core.CryptoIdentifier import CryptoIdentifier 
 40  from idascope.core.IdaProxy import IdaProxy 
 41  from idascope.widgets.FunctionInspectionWidget import FunctionInspectionWidget 
 42  from idascope.widgets.WinApiWidget import WinApiWidget 
 43  from idascope.widgets.CryptoIdentificationWidget import CryptoIdentificationWidget 
 44   
 45  ################################################################################ 
 46  # Core of the IDAscope GUI. 
 47  ################################################################################ 
 48   
 49  HOTKEYS = None 
 50  IDASCOPE = None 
 51  NAME = "simpliFiRE.IDAscope v1.0" 
 52   
 53   
54 -class IDAscopeForm(PluginForm):
55 """ 56 This class contains the main window of IDAscope 57 Setup of core modules and widgets is performed in here. 58 """ 59
60 - def __init__(self):
61 super(IDAscopeForm, self).__init__() 62 global HOTKEYS 63 HOTKEYS = [] 64 self.idascope_widgets = [] 65 self.root_file_path = \ 66 os.path.realpath(__file__)[:os.path.realpath(__file__).rfind(os.sep) + 1] 67 self.config = IDAscopeConfiguration(self.root_file_path + os.sep + "config.json") 68 self.icon = QIcon(self.config.icon_file_path + "idascope.png")
69
70 - def setup_shared_modules(self):
71 """ 72 Setup shared IDAscope modules. 73 """ 74 time_before = time.time() 75 print ("setting up shared modules...") 76 self.semantic_identifier = SemanticIdentifier(self.config.semantics_file) 77 self.semantic_identifier.scan() 78 self.documentation_helper = DocumentationHelper(self.config.semantics_file) 79 self.winapi_provider = WinApiProvider(self.config) 80 self.ida_proxy = IdaProxy() 81 self.crypto_identifier = CryptoIdentifier() 82 print ("this took %3.2f seconds." % (time.time() - time_before))
83
84 - def setup_widgets(self):
85 """ 86 Setup IDAscope widgets. 87 """ 88 time_before = time.time() 89 print ("setting up widgets...") 90 self.idascope_widgets.append(FunctionInspectionWidget(self)) 91 self.idascope_widgets.append(WinApiWidget(self)) 92 self.idascope_widgets.append(CryptoIdentificationWidget(self)) 93 self.setup_IDAscope_form() 94 print ("this took %3.2f seconds." % (time.time() - time_before))
95
96 - def setup_IDAscope_form(self):
97 """ 98 Orchestrate the already initialized widgets in tabs on the main window. 99 """ 100 self.tabs = QtGui.QTabWidget() 101 self.tabs.setTabsClosable(False) 102 for widget in self.idascope_widgets: 103 self.tabs.addTab(widget, widget.icon, widget.name) 104 layout = QtGui.QVBoxLayout() 105 layout.addWidget(self.tabs) 106 self.parent.setLayout(layout)
107
108 - def OnCreate(self, form):
109 """ 110 When creating the form, setup the shared modules and widgets 111 """ 112 self.parent = self.FormToPySideWidget(form) 113 self.parent.setWindowIcon(self.icon) 114 self.setup_shared_modules() 115 self.setup_widgets()
116
117 - def OnClose(self, form):
118 """ 119 Perform cleanup. 120 """ 121 global IDASCOPE 122 del IDASCOPE
123
124 - def Show(self):
125 return PluginForm.Show(self, 126 NAME, 127 options=(PluginForm.FORM_CLOSE_LATER | PluginForm.FORM_RESTORE | PluginForm.FORM_SAVE))
128 129 ################################################################################ 130 # functionality offered to IDAscope's widgets 131 ################################################################################ 132
133 - def setTabFocus(self, widget_name):
134 """ 135 Can be used by IDAscope widgets to set focus to a widget, identified by name. 136 @param widget_name: A widget name 137 @type widget_name: str 138 """ 139 for widget in self.idascope_widgets: 140 if widget.name == widget_name: 141 tab_index = self.tabs.indexOf(widget) 142 self.tabs.setCurrentIndex(tab_index) 143 return
144
145 - def register_hotkey(self, shortcut, py_function_pointer):
146 """ 147 Can be used by IDAscope widgets to register hotkeys. 148 Uses a global list HOTKEYS of function pointers that link to the desired functionality. 149 Right now, linked functions cannot take parameters and should scrape all information they need by themselves. 150 @param shortcut: A string describing a shortcut, e.g. "ctrl+F3" 151 @type shortcut: str 152 @param py_function_pointer: a python function that shall be called when the shortcut is triggered. 153 @type py_function_pointer: a pointer to a python function 154 """ 155 global HOTKEYS 156 hotkey_index = len(HOTKEYS) 157 hotkey_name = "idascope_HOTKEY_%d" % hotkey_index 158 HOTKEYS.append(py_function_pointer) 159 self.ida_proxy.CompileLine('static %s() { RunPythonStatement("HOTKEYS[%d]()"); }' % (hotkey_name, hotkey_index)) 160 self.ida_proxy.AddHotkey(shortcut, hotkey_name)
161 162 ################################################################################ 163 # Usage as plugin 164 ################################################################################ 165 166
167 -class IDAscopePlugin(plugin_t):
168 """ 169 Plugin version of IDAscope. Use this to deploy IDAscope via IDA plugins folder. 170 """ 171 flags = idaapi.PLUGIN_UNL 172 comment = NAME 173 help = "A plugin to help to identify the relevant parts" 174 wanted_name = "IDAscope" 175 wanted_hotkey = "Ctrl-F4" 176
177 - def init(self):
178 # Some initialization 179 self.icon_id = 0 180 return idaapi.PLUGIN_OK
181
182 - def run(self, arg=0):
183 # Create form 184 f = IDAscopeForm() 185 186 # Show the form 187 exit_code = f.Show() 188 if exit_code == 0: 189 f.Free() 190 return 191 192 f.Free() 193 return
194
195 - def term(self):
196 pass
197 198
199 -def PLUGIN_ENTRY():
200 return IDAscopePlugin()
201 202 ################################################################################ 203 # Usage as script 204 ################################################################################ 205 206
207 -def main():
208 global IDASCOPE 209 210 try: 211 IDASCOPE 212 IDASCOPE.OnClose(IDASCOPE) 213 print ("reloading IDAscope") 214 IDASCOPE = IDAscopeForm() 215 return 216 except Exception as exc: 217 print exc 218 IDASCOPE = IDAscopeForm() 219 220 IDASCOPE.Show()
221 222 223 if __name__ == "__main__": 224 main() 225