def _processSourcesList(self):
        corename = tools.determineCoreName( FESettings.getSettings().getValue("ig_default_core"))
        locationDD = tools.determineAbsPath( FESettings.getSettings().getValue("ig_location_dd"))
        #print corename

        self._devicesDict = {}
        self._core  = self._initCore(corename, ddloc = locationDD)
        suggestions, devices = self._core.getPossibleSources()
        self._page1._cbSources.Clear()
        i = 0
        for sug in suggestions:
            self._page1._cbSources.Append(sug, None)
            self._devicesDict[sug] = devices[i]
            i += 1
Exemplo n.º 2
0
 def _assembleCommand(self):
     """
     Assembles the command as it would be used in a Shell environment.
     
     Puts together the command C{dd} with the parameters for source file, destination
     file and blocksize and, if enabled, finishes with the bits for the output redirection. If
     redirection is enabled, both buffers will be redirected (standard output as well as 
     standard error output).
     
     @return: Command String as used on a shell
     @rtype: C{String}
     """
     command = self._settings.getPathDD()
     bs = str(self._settings.getBlocksize())
     source = self._settings.getSource()
     dest = self._settings.getDestination()
     
     st = "\"" + command + "\"" + " " + PARAM_BLOCKSIZE + "=" + bs + " " + PARAM_INPUTFILE + "="  + \
         "\"" + source + "\"" + " " + PARAM_OUTPUTFILE + "=" + "\"" + dest + "\""
         
     if self._settings.getRedirectOutputBuffer() != None:
         st = st + " > " + self._settings.getRedirectOutputBuffer() + " 2> " + self._settings.getRedirectOutputBuffer()
     
     # we need to be root
     sudo = FESettings.getSettings().getValue('command_sudo')
     st = sudo + " " + st
     return st
    def _checkOverwrite(self, path):
##        import os, wx
        if os.access(path, os.F_OK):
            # the file is there already - ask for overwriting
            dlg = wx.MessageDialog(self, "The destination image file exists already." \
                                    "\n(name: " + path + ")" \
                                    "\n\nOverwrite this file?",
                                  "Overwrite image file", wx.YES_NO | wx.ICON_QUESTION)
            if dlg.ShowModal() == wx.ID_YES:
                # ok; let's try to delete this thing then
                dlg.Destroy()
                try:
                    os.unlink(path)
                except OSError:
                    # let's try again with root priv
                    print "Seems to be root; try again with root priv"
                    sudo = FESettings.getSettings().getValue('command_sudo')
                    command = sudo + " rm " + path
                    try:
                        ret = os.system(command)
                    except OSError, msg:
                        # ups
                        dlg1 = wx.MessageDialog(self, "Problem with deleting old file.\n\n" 
                                                "Low level Error Message:\n%s" 
                                                "\n\nProcessing aborted!" %(msg) ,
                                              "Overwrite error", wx.OK | wx.ICON_ERROR)
                        dlg1.ShowModal()
                        dlg1.Destroy()
                        return 0
            else:
                dlg.Destroy()
                return 0
    def _displayResults(self):
        elapsed = tools.processTime(self._timeAllTogether)
        self._page4._timeOverall.SetLabel("Overall time: " + elapsed[0] + ":" + elapsed[1] + ":" + elapsed[2])
        self._page4._lFilesRecovered.SetLabel("Files recovered: " + str(self.status.getOverallFound()))
        if self._page1.if_dir.GetValue() == "Working Directory":
            location_dest = tools.determineAbsPath("./")
        else:
            location_dest = tools.determineAbsPath(self._page1.if_dir.GetValue())
        self._page4._outputLocation.SetLabel("Look for your recovered files in:\n " +
                                             location_dest)

        if FESettings.getSettings().getValue("ig_delete_imagefile") == "yes":
            location_dest = tools.determineAbsPath( FESettings.getSettings().getValue("ig_output_dir"))
            if os.path.exists(location_dest):
                os.remove(location_dest)
                print "Image file removed."
    def _startImageProcessing(self):
        from imagegenerator import Runtime

        corename = tools.determineCoreName( FESettings.getSettings().getValue("ig_default_core"))
        location_dd = tools.determineAbsPath( FESettings.getSettings().getValue("ig_location_dd"))
        location_dest = tools.determineAbsPath( os.path.join(FESettings.getSettings().getValue("ig_output_dir"), FESettings.getSettings().getValue("ig_output_filename")))
        
        self._timeAllTogether = 0
        
        sourceTmp = self._page1._cbSources.GetValue()
##            sourceTmp = self._cbSources.GetStringSelection()
        if self._devicesDict.has_key(sourceTmp):
            source = self._devicesDict[sourceTmp]
        else:
            source = sourceTmp
        #location_dest = "d:\\temp\\dd.img"
        if os.path.exists(location_dest):
            print "Image file existing - I am overwriting."
            try:
                os.remove(location_dest)
            except OSError:
                # let's try again with root priv
                print "Seems to be root; try again with root priv"
                sudo = FESettings.getSettings().getValue('command_sudo')
                command = sudo + " rm " + location_dest
                ret = os.system(command)
                # FIX ME: if not working ...
        redirectBuffer = DEBUG_FILENAME
        settings = Runtime.Settings(path_dd = location_dd, source = source, 
                destination = location_dest, redirectOutput = redirectBuffer)
        #corename = tools.determineCoreName( getSettings("ig_default_core"))
        #print corename
        core = self._initCore(corename, settings)

        status = Runtime.Status()
        status.setStarted()
        sizeEstimation = core.getSizeEstimationForPartition(settings.getSource())
        if sizeEstimation:
            status.setEndFilesize(sizeEstimation)
        thread.start_new_thread(core.createImage,(status,))
        
        self._mytimer = wx.Timer(self, _TIMER_ID)
        self._mytimer.Start(1000, 0)
        wx.EVT_TIMER(self, _TIMER_ID, self._updateValuesImaging)
        self._status = status
        self._settings = settings
    def _startFileRecovery(self):
        location_img = tools.determineAbsPath( os.path.join(FESettings.getSettings().getValue("ig_output_dir"), FESettings.getSettings().getValue("ig_output_filename")))
        if self._page1.if_dir.GetValue() == "Working Directory":
            location_dest = tools.determineAbsPath("./")
        else:
            location_dest = tools.determineAbsPath(self._page1.if_dir.GetValue())
        
        self.settings = ExecutionSettings(sourceFiles = [location_img], 
                                          signatures = signatures.getCopyOfAllSignauteres(),
                                          output_frequency = 2300, output_level = 0,
                                          dest_folder = location_dest)
        self.status = ExecutionStatus(self.settings)
        self.startTime = time.time()

        if FileExtractorCore.init(self.status) < 0:
            print "Error on initialisation"
            
        thread.start_new_thread(self._startRecoveryInThred,(self.status,))

        self._mytimer = wx.Timer(self, _TIMER_ID1)
        self._mytimer.Start(1000, 0)
        wx.EVT_TIMER(self, _TIMER_ID1, self._updateValuesRecovery)
        self._page3.label_current_percentage.SetLabel(self.label_current_percentage_value)
        self._page3.label_current_found.SetLabel(self.label_current_found_value)

    def _displayResults(self):
        elapsed = tools.processTime(self._timeAllTogether)
        self._page4._timeOverall.SetLabel("Overall time: " + elapsed[0] + ":" + elapsed[1] + ":" + elapsed[2])
        self._page4._lFilesRecovered.SetLabel("Files recovered: " + str(self.status.getOverallFound()))
        if self._page1.if_dir.GetValue() == "Working Directory":
            location_dest = tools.determineAbsPath("./")
        else:
            location_dest = tools.determineAbsPath(self._page1.if_dir.GetValue())
        self._page4._outputLocation.SetLabel("Look for your recovered files in:\n " +
                                             location_dest)

        if FESettings.getSettings().getValue("ig_delete_imagefile") == "yes":
            location_dest = tools.determineAbsPath( FESettings.getSettings().getValue("ig_output_dir"))
            if os.path.exists(location_dest):
                os.remove(location_dest)
                print "Image file removed."


if __name__ == "__main__":    
    app = wx.PySimpleApp()
    # load settings
    FESettings.getSettings().load()

    app._wizard = FileExtractorWizard()
    app._wizard.Destroy()
    app.MainLoop()