示例#1
0
 def startOffset(self):
     self.offsetLayout = QHBoxLayout()
     self.offsetSpinBox = QFFSpinBox(self)
     self.offsetSpinBox.setMinimum(0)
     self.offsetSpinBox.setMaximum(self.filesize)
     self.offsetLabel = QLabel("start offset:")
     self.offsetLayout.addWidget(self.offsetLabel)
     self.offsetLayout.addWidget(self.offsetSpinBox)
示例#2
0
class PyCarver(QWidget, fso):
    def __init__(self):
        fso.__init__(self)
        QWidget.__init__(self)
        self.name = "carver"
        self.res = results(self.name)
        self.carver = Carver()
        setattr(self, "vread", self.carver.vread)
        setattr(self, "vseek", self.carver.vseek)
        setattr(self, "vopen", self.carver.vopen)
        setattr(self, "vclose", self.carver.vclose)
        self.mapperFunc = getattr(self.carver, "process")
        self.addNodesFunc = getattr(self.carver, "AddNodes")
        self.tellFunc = getattr(self.carver, "tell")

    def start(self, args):
        self.carver.start(args)
        self.name += " <" + args.get_node("ifile").name + ">"
        self.filesize = args.get_node("ifile").attr.size


    def status(self):
        return 0


    def g_display(self):
        self.draw()
        

    def updateWidget(self):
        pass


    def startOffset(self):
        self.offsetLayout = QHBoxLayout()
        self.offsetSpinBox = QFFSpinBox(self)
        self.offsetSpinBox.setMinimum(0)
        self.offsetSpinBox.setMaximum(self.filesize)
        self.offsetLabel = QLabel("start offset:")
        self.offsetLayout.addWidget(self.offsetLabel)
        self.offsetLayout.addWidget(self.offsetSpinBox)

    def setStateInfo(self, sinfo):
        self.stateinfo = str(sinfo)

    def draw(self):
        #define layout
        self.vbox = QVBoxLayout()
        self.setLayout(self.vbox)

        #define all area
        #self.user = userPattern()
        self.pp = predefPattern()
        self.startButton = QPushButton("Start")
        self.stopButton = QPushButton("Stop")
        self.alignedCheck = QCheckBox("match only at the beginning of sector")
        self.startOffset()
        self.carvingProcess = carvingProcess()
        self.carver.connection(self.carvingProcess)
        self.carvingProcess.connection(self.carver)
        self.connect(self.carvingProcess, SIGNAL("stateInfo(QString)"), self.setStateInfo)
        
        #add widget and hide progress bars
        self.vbox.addWidget(self.pp)
        #self.vbox.addWidget(self.user)
        self.vbox.addLayout(self.offsetLayout)
        self.vbox.addWidget(self.alignedCheck)
        self.vbox.addWidget(self.startButton)
        self.vbox.addWidget(self.stopButton)
        self.vbox.addWidget(self.carvingProcess)
        self.carvingProcess.hide()
        self.stopButton.setEnabled(False)

        #define connectors
        self.connect(self.stopButton, SIGNAL("clicked()"), self.stopCarving)
        self.connect(self.startButton, SIGNAL("clicked()"), self.startCarving)
        self.connect(self.carvingProcess, SIGNAL("end(QString)"), self.carvingEnded)


    def carvingEnded(self, res):
        results = str(res).split("\n")
        print results
        for item in results:
            begidx = item.find(":")
            self.res.add_const(str(item[:begidx]), str(item[begidx+1:] + "\n"))
        self.startButton.setEnabled(True)
        self.stopButton.setEnabled(False)


    def stopCarving(self):
        self.carvingProcess.killJob()
        self.stopButton.setDown(True)


    def createContext(self, selected):
        toCarve = listDescr()
        toCarve.thisown = False
        for key, items in selected.iteritems():
            for item in items:
                descr = filetypes[key][item]
                for p in descr:
                    header = pattern()
                    footer = pattern()
                    header.thisown = False
                    footer.thisown = False
                    header.needle = p[0]
                    header.size = len(p[0])
                    footer.needle = p[1]
                    footer.size = len(p[1])
                    if p[0].find(wildcard) != -1 or p[1].find(wildcard) != -1:
                        header.wildcard = wildcard
                        footer.wildcard = wildcard
                    else:
                        header.wildcard = ""
                        footer.wildcard = ""
                    d = description()
                    d.thisown = False
                    d.header = header
                    d.footer = footer
                    d.type = item
                    d.window = p[2]
                    d.aligned = False
                    toCarve.append(d)
        return toCarve
        

    def startCarving(self):
        self.startButton.setEnabled(False)
        self.stopButton.setEnabled(True)
        self.stopButton.setDown(False)
        selected = self.pp.getChecked()
        toCarve = self.createContext(selected)
        factor = round(float(self.filesize) / 2147483647)
        if factor == 0:
            factor = 1
        carvingArgs = {"min": 0, "max": self.filesize, "toCarve": toCarve, 
                       "callback": self.addNodesFunc, "mapper": self.mapperFunc,
                       "factor": factor, "start": self.offsetSpinBox.value(),
                       "aligned": self.alignedCheck.isChecked()}
        self.carvingProcess.show()
        self.carvingProcess.doJob(**carvingArgs)