Merge pull request #926 from rcordovano/release-3.1.1

Remove use of deprecated method in Python sample and make easier to test
This commit is contained in:
Richard Cordovano 2014-10-29 17:38:48 -04:00
commit e5ec1e8233

View File

@ -27,7 +27,6 @@
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE. # OTHER DEALINGS IN THE SOFTWARE.
import jarray import jarray
from java.lang import System from java.lang import System
from org.sleuthkit.datamodel import SleuthkitCase from org.sleuthkit.datamodel import SleuthkitCase
@ -86,43 +85,44 @@ class SampleJythonDataSourceIngestModule(DataSourceIngestModule):
self.context = context self.context = context
def process(self, dataSource, progressBar): def process(self, dataSource, progressBar):
if self.context.isJobCancelled(): if self.context.isJobCancelled():
return IngestModule.ProcessResult.OK return IngestModule.ProcessResult.OK
# Configure progress bar for 2 tasks # Configure progress bar for 2 tasks
progressBar.switchToDeterminate(2) progressBar.switchToDeterminate(2)
autopsyCase = Case.getCurrentCase() autopsyCase = Case.getCurrentCase()
sleuthkitCase = autopsyCase.getSleuthkitCase() sleuthkitCase = autopsyCase.getSleuthkitCase()
services = Services(sleuthkitCase) services = Services(sleuthkitCase)
fileManager = services.getFileManager() fileManager = services.getFileManager()
# Get count of files with .doc extension. # Get count of files with "test" in name.
fileCount = 0; fileCount = 0;
docFiles = fileManager.findFiles(dataSource, "%.doc") files = fileManager.findFiles(dataSource, "%test%")
for docFile in docFiles: for file in files:
fileCount += 1 fileCount += 1
progressBar.progress(1) progressBar.progress(1)
if self.context.isJobCancelled(): if self.context.isJobCancelled():
return IngestModule.ProcessResult.OK return IngestModule.ProcessResult.OK
# Get files by creation time. # Get files by creation time.
currentTime = System.currentTimeMillis() / 1000 currentTime = System.currentTimeMillis() / 1000
minTime = currentTime - (14 * 24 * 60 * 60) # Go back two weeks. minTime = currentTime - (14 * 24 * 60 * 60) # Go back two weeks.
otherFiles = sleuthkitCase.findFilesWhere("crtime > %d" % minTime) otherFiles = sleuthkitCase.findAllFilesWhere("crtime > %d" % minTime)
for otherFile in otherFiles: for otherFile in otherFiles:
fileCount += 1 fileCount += 1
progressBar.progress(1); progressBar.progress(1);
if self.context.isJobCancelled(): if self.context.isJobCancelled():
return IngestModule.ProcessResult.OK; return IngestModule.ProcessResult.OK;
#Post a message to the ingest messages in box. #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) message = IngestMessage.createMessage(IngestMessage.MessageType.DATA,
IngestServices.getInstance().postMessage(message) "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. # File-level ingest module. One gets created per thread.
@ -134,27 +134,27 @@ class SampleJythonFileIngestModule(FileIngestModule):
pass pass
def process(self, file): def process(self, file):
# If the file has a txt extension, post an artifact to the blackboard. # If the file has a txt extension, post an artifact to the blackboard.
if file.getName().endswith("txt"): if file.getName().find("test") != -1:
art = file.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT) 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") att = BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME.getTypeID(), "Sample Jython File Ingest Module", "Text Files")
art.addAttribute(att) art.addAttribute(att)
# Read the contents of the file. # Read the contents of the file.
inputStream = ReadContentInputStream(file) inputStream = ReadContentInputStream(file)
buffer = jarray.zeros(1024, "b") buffer = jarray.zeros(1024, "b")
totLen = 0 totLen = 0
len = inputStream.read(buffer) len = inputStream.read(buffer)
while (len != -1): while (len != -1):
totLen = totLen + len totLen = totLen + len
len = inputStream.read(buffer) len = inputStream.read(buffer)
# Send the size of the file to the ingest messages in box. # Send the size of the file to the ingest messages in box.
msgText = "Size of %s is %d bytes" % ((file.getName(), totLen)) msgText = "Size of %s is %d bytes" % ((file.getName(), totLen))
message = IngestMessage.createMessage(IngestMessage.MessageType.DATA, "Sample Jython File IngestModule", msgText) message = IngestMessage.createMessage(IngestMessage.MessageType.DATA, "Sample Jython File IngestModule", msgText)
ingestServices = IngestServices.getInstance().postMessage(message) ingestServices = IngestServices.getInstance().postMessage(message)
return IngestModule.ProcessResult.OK return IngestModule.ProcessResult.OK
def shutDown(self): def shutDown(self):
pass pass