24 package org.sleuthkit.autopsy.casemodule.services;
26 import java.io.Closeable;
27 import java.io.IOException;
28 import java.util.ArrayList;
29 import java.util.Collection;
30 import java.util.List;
31 import java.util.logging.Level;
32 import org.openide.util.NbBundle;
43 import org.
sleuthkit.datamodel.SleuthkitCase.CaseDbTransaction;
50 import org.apache.commons.lang3.StringUtils;
102 public List<AbstractFile>
findFilesByParentPath(
long dataSourceObjectID, String parentPath)
throws TskCoreException {
118 public List<AbstractFile>
findFilesByMimeType(Content dataSource, Collection<String> mimeTypes)
throws TskCoreException {
119 return caseDb.findAllFilesWhere(
"data_source_obj_id = " + dataSource.getId() +
" AND " +
createFileTypeInCondition(mimeTypes));
133 return caseDb.getFileManager().findFilesExactName(parentId, name);
144 String types = StringUtils.join(mimeTypes,
"', '");
145 return "mime_type IN ('" + types +
"')";
158 return "data_source_obj_id = " + dataSourceObjectID +
" AND parent_path LIKE '" + parentPath +
"%'";
173 public List<AbstractFile>
findFiles(String fileName)
throws TskCoreException {
174 List<AbstractFile> result =
new ArrayList<>();
175 List<Content> dataSources = caseDb.getRootObjects();
176 for (Content dataSource : dataSources) {
177 result.addAll(
findFiles(dataSource, fileName));
198 public List<AbstractFile>
findFiles(String fileName, String parentSubString)
throws TskCoreException {
199 List<AbstractFile> result =
new ArrayList<>();
200 List<Content> dataSources = caseDb.getRootObjects();
201 for (Content dataSource : dataSources) {
202 result.addAll(
findFiles(dataSource, fileName, parentSubString));
221 public List<AbstractFile>
findFiles(String fileName, AbstractFile parent)
throws TskCoreException {
222 return caseDb.findFilesInFolder(fileName, parent);
239 public List<AbstractFile>
findFiles(Content dataSource, String fileName)
throws TskCoreException {
240 return caseDb.findFiles(dataSource, fileName);
261 public List<AbstractFile>
findFiles(Content dataSource, String fileName, String parentSubString)
throws TskCoreException {
262 return caseDb.findFiles(dataSource, fileName, parentSubString);
282 public List<AbstractFile>
openFiles(Content dataSource, String filePath)
throws TskCoreException {
283 return caseDb.openFiles(dataSource, filePath);
318 long ctime,
long crtime,
long atime,
long mtime,
321 String rederiveDetails, String toolName, String toolVersion, String otherDetails,
322 TskData.EncodingType encodingType) throws TskCoreException {
323 return caseDb.addDerivedFile(fileName, localPath, size,
324 ctime, crtime, atime, mtime,
325 isFile, parentObj, rederiveDetails, toolName, toolVersion, otherDetails, encodingType);
360 long ctime,
long crtime,
long atime,
long mtime,
361 boolean isFile, String mimeType,
362 String rederiveDetails, String toolName, String toolVersion, String otherDetails,
363 TskData.EncodingType encodingType) throws TskCoreException {
364 return caseDb.updateDerivedFile(derivedFile, localPath, size,
365 ctime, crtime, atime, mtime,
366 isFile, mimeType, rederiveDetails, toolName, toolVersion, otherDetails, encodingType);
380 public List<LayoutFile>
addCarvedFiles(CarvingResult carvingResult)
throws TskCoreException {
381 return caseDb.addCarvedFiles(carvingResult);
427 return addLocalFilesDataSource(deviceId, rootVirtualDirectoryName, timeZone, null, localFilePaths, progressUpdater);
459 public LocalFilesDataSource
addLocalFilesDataSource(String deviceId, String rootVirtualDirectoryName, String timeZone, Host host,
460 List<String> localFilePaths,
FileAddProgressUpdater progressUpdater)
throws TskCoreException, TskDataException {
462 CaseDbTransaction trans = null;
464 String rootDirectoryName = rootVirtualDirectoryName;
465 if (rootDirectoryName.isEmpty()) {
473 trans = caseDb.beginTransaction();
474 LocalFilesDataSource dataSource = caseDb.addLocalFilesDataSource(deviceId, rootDirectoryName, timeZone, host, trans);
475 List<AbstractFile> filesAdded =
new ArrayList<>();
476 for (java.io.File localFile : localFiles) {
477 AbstractFile fileAdded =
addLocalFile(trans, dataSource, localFile, TskData.EncodingType.NONE, progressUpdater);
478 if (null != fileAdded) {
479 filesAdded.add(fileAdded);
481 throw new TskCoreException(NbBundle.getMessage(
this.getClass(),
"FileManager.addLocalFilesDirs.exception.cantAdd.msg", localFile.getAbsolutePath()));
490 for (AbstractFile fileAdded : filesAdded) {
500 }
catch (TskCoreException ex) {
501 LOGGER.log(Level.SEVERE,
"Failed to rollback transaction after exception", ex);
521 int localFileDataSourcesCounter = 0;
523 List<VirtualDirectory> localFileDataSources = caseDb.getVirtualDirectoryRoots();
524 for (VirtualDirectory vd : localFileDataSources) {
526 ++localFileDataSourcesCounter;
530 }
catch (TskCoreException ex) {
531 throw new TskCoreException(
"Error querying for existing local file data sources with defualt names", ex);
548 List<java.io.File> localFiles =
new ArrayList<>();
549 for (String path : localFilePaths) {
550 java.io.File localFile =
new java.io.File(path);
551 if (!localFile.exists() || !localFile.canRead()) {
552 throw new TskDataException(String.format(
"File at %s does not exist or cannot be read", localFile.getAbsolutePath()));
554 localFiles.add(localFile);
576 private AbstractFile
addLocalFile(CaseDbTransaction trans, SpecialDirectory parentDirectory, java.io.File localFile,
578 if (localFile.isDirectory()) {
582 LocalDirectory localDirectory = caseDb.addLocalDirectory(parentDirectory.getId(), localFile.getName(), trans);
583 progressUpdater.fileAdded(localDirectory);
588 final java.io.File[] childFiles = localFile.listFiles();
589 if (childFiles != null && childFiles.length > 0) {
590 for (java.io.File childFile : childFiles) {
591 addLocalFile(trans, localDirectory, childFile, progressUpdater);
595 return localDirectory;
597 return caseDb.addLocalFile(localFile.getName(), localFile.getAbsolutePath(), localFile.length(),
599 localFile.isFile(), encodingType, parentDirectory, trans);
611 public void close() throws IOException {
640 }
catch (TskDataException ex) {
641 throw new TskCoreException(ex.getLocalizedMessage(), ex);
664 public LayoutFile
addCarvedFile(String fileName,
long fileSize,
long parentObjId, List<TskFileRange> layout)
throws TskCoreException {
665 Content parent = caseDb.getContentById(parentObjId);
666 List<CarvingResult.CarvedFile> carvedFiles =
new ArrayList<>();
667 carvedFiles.add(
new CarvingResult.CarvedFile(fileName, fileSize, layout));
668 List<LayoutFile> layoutFiles = caseDb.addCarvedFiles(
new CarvingResult(parent, carvedFiles));
669 return layoutFiles.get(0);
688 public List<LayoutFile>
addCarvedFiles(List<org.sleuthkit.datamodel.CarvedFileContainer> filesToAdd)
throws TskCoreException {
689 return caseDb.addCarvedFiles(filesToAdd);
726 long ctime,
long crtime,
long atime,
long mtime,
728 AbstractFile parentFile,
729 String rederiveDetails, String toolName, String toolVersion, String otherDetails)
throws TskCoreException {
730 return addDerivedFile(fileName, localPath, size, ctime, crtime, atime, mtime, isFile, parentFile,
731 rederiveDetails, toolName, toolVersion, otherDetails, TskData.EncodingType.NONE);
754 private AbstractFile
addLocalFile(CaseDbTransaction trans, SpecialDirectory parentDirectory, java.io.File localFile,
FileAddProgressUpdater progressUpdater)
throws TskCoreException {
755 return addLocalFile(trans, parentDirectory, localFile, TskData.EncodingType.NONE, progressUpdater);
777 public List<AbstractFile>
findFiles(Content dataSource, String fileName, AbstractFile parent)
throws TskCoreException {
static String createFileTypeInCondition(Collection< String > mimeTypes)
List< LayoutFile > addCarvedFiles(CarvingResult carvingResult)
List< AbstractFile > openFiles(Content dataSource, String filePath)
List< AbstractFile > findFilesByMimeType(Collection< String > mimeTypes)
List< AbstractFile > findFiles(String fileName)
LocalFilesDataSource addLocalFilesDataSource(String deviceId, String rootVirtualDirectoryName, String timeZone, List< String > localFilePaths, FileAddProgressUpdater progressUpdater)
List< LayoutFile > addCarvedFiles(List< org.sleuthkit.datamodel.CarvedFileContainer > filesToAdd)
static final Logger LOGGER
LayoutFile addCarvedFile(String fileName, long fileSize, long parentObjId, List< TskFileRange > layout)
void fileAdded(AbstractFile newFile)
List< AbstractFile > findFiles(Content dataSource, String fileName, String parentSubString)
VirtualDirectory addLocalFilesDirs(List< String > localFilePaths, FileAddProgressUpdater progressUpdater)
List< AbstractFile > findFilesByMimeType(Content dataSource, Collection< String > mimeTypes)
AbstractFile addLocalFile(CaseDbTransaction trans, SpecialDirectory parentDirectory, java.io.File localFile, FileAddProgressUpdater progressUpdater)
List< AbstractFile > findFiles(Content dataSource, String fileName, AbstractFile parent)
LocalFilesDataSource addLocalFilesDataSource(String deviceId, String rootVirtualDirectoryName, String timeZone, Host host, List< String > localFilePaths, FileAddProgressUpdater progressUpdater)
static String createParentPathCondition(long dataSourceObjectID, String parentPath)
DerivedFile updateDerivedFile(DerivedFile derivedFile, String localPath, long size, long ctime, long crtime, long atime, long mtime, boolean isFile, String mimeType, String rederiveDetails, String toolName, String toolVersion, String otherDetails, TskData.EncodingType encodingType)
final SleuthkitCase caseDb
List< AbstractFile > findFiles(String fileName, String parentSubString)
DerivedFile addDerivedFile(String fileName, String localPath, long size, long ctime, long crtime, long atime, long mtime, boolean isFile, AbstractFile parentFile, String rederiveDetails, String toolName, String toolVersion, String otherDetails)
static String generateFilesDataSourceName(SleuthkitCase caseDb)
void fireModuleContentEvent(ModuleContentEvent moduleContentEvent)
List< AbstractFile > findFiles(Content dataSource, String fileName)
List< AbstractFile > findFilesExactName(long parentId, String name)
List< AbstractFile > findFiles(String fileName, AbstractFile parent)
AbstractFile addLocalFile(CaseDbTransaction trans, SpecialDirectory parentDirectory, java.io.File localFile, TskData.EncodingType encodingType, FileAddProgressUpdater progressUpdater)
synchronized static Logger getLogger(String name)
FileManager(SleuthkitCase caseDb)
List< AbstractFile > findFilesByParentPath(long dataSourceObjectID, String parentPath)
static final String LOGICAL_FILE_SET_PREFIX
List< java.io.File > getFilesAndDirectories(List< String > localFilePaths)
DerivedFile addDerivedFile(String fileName, String localPath, long size, long ctime, long crtime, long atime, long mtime, boolean isFile, Content parentObj, String rederiveDetails, String toolName, String toolVersion, String otherDetails, TskData.EncodingType encodingType)
static synchronized IngestServices getInstance()