File size: 7,654 Bytes
ce4b573
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# DFF -- An Open Source Digital Forensics Framework
# Copyright (C) 2009-2011 ArxSys
# This program is free software, distributed under the terms of
# the GNU General Public License Version 2. See the LICENSE file
# at the top of the source tree.
#  
# See http://www.digital-forensic.org for more information about this
# project. Please do not directly contact any of the maintainers of
# DFF for assistance; the project provides a web site, mailing lists
# and IRC channels for your use.
# 
# Author(s):
#  Solal Jacob <sja@digital-forensic.org>
#  Jeremy Mounier <jmo@digital-forensic.org>
#

import os

from PyQt4.QtGui import QFileDialog, QMessageBox, QInputDialog, QDialog, QDialogButtonBox, QComboBox, QPushButton, QFormLayout, QHBoxLayout, QPixmap, QLabel, QApplication
from PyQt4.QtCore import QObject, QString, SIGNAL, SLOT, Qt, QEvent, QDir

from api.taskmanager import *
from api.taskmanager.taskmanager import * 
from api.loader import *
from api.vfs import vfs
from api.devices.devices import Devices
from api.gui.widget.devicesdialog import DevicesDialog
from api.gui.widget.layoutmanager import *
from api.types.libtypes import typeId

from ui.gui.dialog.preferences import Preferences
from ui.gui.resources.ui_about import Ui_About
from ui.gui.resources.ui_evidencedialog import Ui_evidenceDialog

from ui.gui.widget.modulesmanager import *

class Dialog(QObject):
  def __init__(self, parent):
     QObject.__init__(self)
     self.parent = parent 
     self.vfs = vfs.vfs()
     self.taskmanager = TaskManager()
     self.loader = loader.loader()

  def preferences(self):
    """Open a preferences dialog"""
    
    pref = Preferences(self.parent)
    ret = pref.exec_()
    if ret:
      pass
#      pref.conf.root_index = pref.root_index_line.text()
#      pref.conf.index_name = pref.index_name_line.text()
#      pref.conf.index_path = pref.conf.root_index + "/" + pref.conf.index_name

#      root_index_dir = QDir(pref.conf.root_index)
#      if not root_index_dir.exists():
#        root_index_dir.mkpath(pref.conf.root_index)
#@      default_index_dir = QDir(pref.conf.index_path)
 #     if not default_index_dir.exists():
 #       default_index_dir.mkpath(pref.conf.index_path)

  def addDevices(self):
       """Open a device list dialog"""
       dev = DevicesDialog(self.parent)
       if dev.exec_():
	 if dev.selectedDevice:
           args = {}
	   args["path"] = str(dev.selectedDevice.blockDevice())
	   args["parent"] = self.vfs.getnode("/Local devices")
	   args["size"] = long(dev.selectedDevice.size())
	   exec_type = ["thread", "gui"]
	   try:
             if os.name == "nt":
	       args["name"] = str(dev.selectedDevice.model())
             conf = self.loader.get_conf(str("devices"))
             genargs = conf.generate(args)
             self.taskmanager.add("devices", genargs, exec_type)	
           except RuntimeError:
             err_type, err_value, err_traceback = sys.exc_info()
             err_trace =  traceback.format_tb(err_traceback)
             err_typeval = traceback.format_exception_only(err_type, err_value)
             terr = QString()
             detailerr = QString()
             for err in err_trace:
               detailerr.append(err)
               for errw in err_typeval:
                 terr.append(errw)
                 detailerr.append(err)
             self.messageBox(terr, detailerr)
       del dev

  def addFiles(self):
        """ Open a Dialog for select a file and add in VFS """
        edialog = evidenceDialog(self.parent)
        ir = edialog.exec_()
        if ir > 0:
          args = {}
          paths = edialog.manager.get("local")
          if edialog.rawcheck.isChecked():
            module = "local"
            args["path"] = paths
	    args["parent"] = self.vfs.getnode('/Logical files')
          elif edialog.ewfcheck.isChecked():
            module = "ewf"
            args["files"] = paths
	    args["parent"] = self.vfs.getnode('/Logical files')
          else:
            module = "aff"
            args["path"] = paths
	    args["parent"] = self.vfs.getnode('/Logical files')
          self.conf = self.loader.get_conf(str(module))
          try:
            genargs = self.conf.generate(args)
            self.taskmanager.add(str(module), genargs, ["thread", "gui"])
          except RuntimeError:
            err_type, err_value, err_traceback = sys.exc_info()
            err_trace =  traceback.format_tb(err_traceback)
            err_typeval = traceback.format_exception_only(err_type, err_value)
            terr = QString()
            detailerr = QString()
            for err in err_trace:
              detailerr.append(err)
              for errw in err_typeval:
                terr.append(errw)
                detailerr.append(err)
            self.messageBox(terr, detailerr)

  def messageBox(self, coretxt, detail):
    msg = QMessageBox()
    msg.setWindowTitle("Error in configuration")
    msg.setText("An error was detected in the configuration")
    msg.setInformativeText(coretxt)
    msg.setIcon(QMessageBox.Critical)
    msg.setDetailedText(detail)
    msg.setStandardButtons(QMessageBox.Ok)
    ret = msg.exec_()
 
  def loadDriver(self):
        sFileName = QFileDialog.getOpenFileName(self.parent, self.parent.actionLoadModule.toolTip(), os.path.expanduser('~'),  "Modules(*.py)")
        if (sFileName) :
            self.loader.do_load(str(sFileName.toUtf8()))

  def about(self):
        """ Open a About Dialog """
        about = About()
        about.exec_()

  def manager(self):
        """ Open module browser dialog """
        module = browserDialog(self.parent)
        ir = module.exec_()
        if ir > 0:
          module.browser.execute()

#class managerDialog(QDialog):
#    def __init__(self,  mainWindow):
#        QDialog.__init__(self, mainWindow)
#        l = QVBoxLayout()
#        l.addWidget(modulesManager(self))
#        self.setLayout(l)

class About(QDialog, Ui_About):
  def __init__(self):
    super(QDialog, self).__init__()
    self.setupUi(self)
    self.label.setText(self.label.text().arg(QApplication.instance().applicationVersion()))

  def changeEvent(self, event):
    """ Search for a language change event
    
    This event have to call retranslateUi to change interface language on
    the fly.
    """
    if event.type() == QEvent.LanguageChange:
      self.retranslateUi(self)
      self.label.setText(self.label.text().arg(QApplication.instance().applicationVersion()))
    else:
      QDialog.changeEvent(self, event)


class evidenceDialog(QDialog, Ui_evidenceDialog):
  def __init__(self, parent):
    super(QDialog, self).__init__()
    self.setupUi(self)
    self.loader = loader.loader()
    self.createShape()

  def createShape(self):
    """ Removes EWF if not in modules

    Set itemData for easy access without taking care of text (can be
    translated).
    TODO Futur : Get all DFF connectors
    """    
    if "ewf" not in self.loader.modules:
      self.ewfcheck.setEnabled(False)
    if "aff" not in self.loader.modules:
      self.affcheck.setEnabled(False)
    self.rawcheck.setChecked(True)

    self.manager = layoutManager()

    self.manager.addPathList("local", typeId.Path, [], [])    

    self.pathlayout.addWidget(self.manager)

  def changeEvent(self, event):
    """ Search for a language change event
    
    This event have to call retranslateUi to change interface language on
    the fly.
    """
    if event.type() == QEvent.LanguageChange:
      self.retranslateUi(self)
      self.label.setText(self.label.text().arg(QApplication.instance().applicationVersion()))
    else:
      QDialog.changeEvent(self, event)