From da345d41bda36afb82e592a84130be5f276352fc Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Wed, 29 Oct 2014 17:38:14 -0400 Subject: [PATCH] Remove use of deprecated method in Python sample and make easier to test --- .../autopsy/examples/ingestmodule.py | 96 +++++++++---------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/examples/ingestmodule.py b/Core/src/org/sleuthkit/autopsy/examples/ingestmodule.py index 363109742e..e86d453cb6 100755 --- a/Core/src/org/sleuthkit/autopsy/examples/ingestmodule.py +++ b/Core/src/org/sleuthkit/autopsy/examples/ingestmodule.py @@ -27,7 +27,6 @@ # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. - import jarray from java.lang import System from org.sleuthkit.datamodel import SleuthkitCase @@ -86,43 +85,44 @@ class SampleJythonDataSourceIngestModule(DataSourceIngestModule): self.context = context def process(self, dataSource, progressBar): - if self.context.isJobCancelled(): - return IngestModule.ProcessResult.OK + if self.context.isJobCancelled(): + return IngestModule.ProcessResult.OK - # Configure progress bar for 2 tasks - progressBar.switchToDeterminate(2) + # Configure progress bar for 2 tasks + progressBar.switchToDeterminate(2) - autopsyCase = Case.getCurrentCase() - sleuthkitCase = autopsyCase.getSleuthkitCase() - services = Services(sleuthkitCase) - fileManager = services.getFileManager() + autopsyCase = Case.getCurrentCase() + sleuthkitCase = autopsyCase.getSleuthkitCase() + services = Services(sleuthkitCase) + fileManager = services.getFileManager() - # Get count of files with .doc extension. - fileCount = 0; - docFiles = fileManager.findFiles(dataSource, "%.doc") - for docFile in docFiles: - fileCount += 1 - progressBar.progress(1) + # Get count of files with "test" in name. + fileCount = 0; + files = fileManager.findFiles(dataSource, "%test%") + for file in files: + fileCount += 1 + progressBar.progress(1) - if self.context.isJobCancelled(): - return IngestModule.ProcessResult.OK + if self.context.isJobCancelled(): + return IngestModule.ProcessResult.OK - # Get files by creation time. - currentTime = System.currentTimeMillis() / 1000 - minTime = currentTime - (14 * 24 * 60 * 60) # Go back two weeks. - otherFiles = sleuthkitCase.findFilesWhere("crtime > %d" % minTime) - for otherFile in otherFiles: - fileCount += 1 - progressBar.progress(1); + # Get files by creation time. + currentTime = System.currentTimeMillis() / 1000 + minTime = currentTime - (14 * 24 * 60 * 60) # Go back two weeks. + otherFiles = sleuthkitCase.findAllFilesWhere("crtime > %d" % minTime) + for otherFile in otherFiles: + fileCount += 1 + progressBar.progress(1); - if self.context.isJobCancelled(): - return IngestModule.ProcessResult.OK; + if self.context.isJobCancelled(): + return IngestModule.ProcessResult.OK; - #Post a message to the ingest messages in box. - message = IngestMessage.createMessage(IngestMessage.MessageType.DATA, "Sample Jython Data Source Ingest Module", "Found %d files" % fileCount) - IngestServices.getInstance().postMessage(message) + #Post a message to the ingest messages in box. + message = IngestMessage.createMessage(IngestMessage.MessageType.DATA, + "Sample Jython Data Source Ingest Module", "Found %d files" % fileCount) + IngestServices.getInstance().postMessage(message) - return IngestModule.ProcessResult.OK; + return IngestModule.ProcessResult.OK; # File-level ingest module. One gets created per thread. @@ -134,27 +134,27 @@ class SampleJythonFileIngestModule(FileIngestModule): pass def process(self, file): - # If the file has a txt extension, post an artifact to the blackboard. - if file.getName().endswith("txt"): - art = file.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT) - att = BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME.getTypeID(), "Sample Jython File Ingest Module", "Text file") - art.addAttribute(att) + # If the file has a txt extension, post an artifact to the blackboard. + if file.getName().find("test") != -1: + art = file.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT) + att = BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME.getTypeID(), "Sample Jython File Ingest Module", "Text Files") + art.addAttribute(att) - # Read the contents of the file. - inputStream = ReadContentInputStream(file) - buffer = jarray.zeros(1024, "b") - totLen = 0 - len = inputStream.read(buffer) - while (len != -1): - totLen = totLen + len - len = inputStream.read(buffer) + # Read the contents of the file. + inputStream = ReadContentInputStream(file) + buffer = jarray.zeros(1024, "b") + totLen = 0 + len = inputStream.read(buffer) + while (len != -1): + totLen = totLen + len + len = inputStream.read(buffer) - # Send the size of the file to the ingest messages in box. - msgText = "Size of %s is %d bytes" % ((file.getName(), totLen)) - message = IngestMessage.createMessage(IngestMessage.MessageType.DATA, "Sample Jython File IngestModule", msgText) - ingestServices = IngestServices.getInstance().postMessage(message) + # Send the size of the file to the ingest messages in box. + msgText = "Size of %s is %d bytes" % ((file.getName(), totLen)) + message = IngestMessage.createMessage(IngestMessage.MessageType.DATA, "Sample Jython File IngestModule", msgText) + ingestServices = IngestServices.getInstance().postMessage(message) - return IngestModule.ProcessResult.OK + return IngestModule.ProcessResult.OK def shutDown(self): pass