diff --git a/bindings/java/src/org/sleuthkit/datamodel/CarvedFileContainer.java b/bindings/java/src/org/sleuthkit/datamodel/CarvedFileContainer.java index e40c518a5736e7c36cfb89136014f350c338a823..0e45967b8d4b542d01f74b56b63298ac4213a8f2 100755 --- a/bindings/java/src/org/sleuthkit/datamodel/CarvedFileContainer.java +++ b/bindings/java/src/org/sleuthkit/datamodel/CarvedFileContainer.java @@ -1,7 +1,7 @@ /* * Sleuth Kit Data Model * - * Copyright 2012-2014 Basis Technology Corp. + * Copyright 2011-2016 Basis Technology Corp. * Contact: carrier <at> sleuthkit <dot> org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,12 +20,16 @@ import java.util.List; +/** + * @deprecated Use CarvingResult instead. + */ +@Deprecated public final class CarvedFileContainer { - private String mCarvedFileName; - private long mCarvedFileSize; - private long mContainerId; - private List<TskFileRange> mRangeData; + private final String mCarvedFileName; + private final long mCarvedFileSize; + private final long mContainerId; + private final List<TskFileRange> mRangeData; public CarvedFileContainer(String carvedFileName, long carvedFileSize, long containerId, List<TskFileRange> rangeData) { mCarvedFileName = carvedFileName; diff --git a/bindings/java/src/org/sleuthkit/datamodel/CarvingResult.java b/bindings/java/src/org/sleuthkit/datamodel/CarvingResult.java index b1fc7e5dd94e21d3e8e789ab9797beab867baae9..89d82cb7d21032d91b9e7413567d3721b031cefc 100755 --- a/bindings/java/src/org/sleuthkit/datamodel/CarvingResult.java +++ b/bindings/java/src/org/sleuthkit/datamodel/CarvingResult.java @@ -21,9 +21,8 @@ import java.util.List; /** - * A carving result consisting of a set of carved files and the parent content - * (e.g., an unallocated space file or an image data source) from which the - * files were carved. + * A carving result consisting of a set of carved files and the parent from + * which the files were carved. */ public final class CarvingResult { @@ -32,11 +31,11 @@ public final class CarvingResult { /** * Constructs a carving result consisting of a set of carved files and the - * parent content (e.g., an unallocated space file or an image data source) - * from which the files were carved. + * parent from which the files were carved. * - * @param parent The parent of a set of carved files. - * @param carvedFiles The carved files. + * @param parent The parent of the set of carved files in the carving + * result. + * @param carvedFiles The set of carved files in the carving result. */ public CarvingResult(Content parent, List<CarvedFile> carvedFiles) { this.parent = parent; @@ -46,7 +45,7 @@ public CarvingResult(Content parent, List<CarvedFile> carvedFiles) { /** * Gets the parent of the carved files in a carving result. * - * @return The carved files parent. + * @return The parent of the set of carved files in the carving result. */ final Content getParent() { return parent; @@ -55,15 +54,14 @@ final Content getParent() { /** * Gets the carved files in a carving result. * - * @return The carved files. + * @return The set of carved files in the carving result. */ final List<CarvedFile> getCarvedFiles() { return carvedFiles; } /** - * A file carved out of parent content (e.g., an unallocated space file or - * an image data source). + * A carved file. */ public static class CarvedFile { @@ -72,12 +70,11 @@ public static class CarvedFile { private final List<TskFileRange> layoutInParent; /** - * Constructs a file carved out of parent content (e.g., an unallocated - * space file or an image data source). + * Constructs a carved file. * * @param name The name of the file. * @param sizeInBytes The size of the file in bytes. - * @param layoutInParent The layout of the file within the parent. + * @param layoutInParent The layout of the file within its parent. */ public CarvedFile(String name, long sizeInBytes, List<TskFileRange> layoutInParent) { this.name = name; @@ -106,7 +103,7 @@ final long getSizeInBytes() { /** * Gets the layout of the carved file within its parent. * - * @return A list of TskRange objects representing the layoput of the + * @return A list of TskRange objects representing the layout of the * carved file within its parent. */ final List<TskFileRange> getLayoutInParent() { diff --git a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java index afe57e1024a41788e19386b2c24e566724159d5d..317f98ebc80bef38389115b78beebce99b5ea236 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java +++ b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java @@ -3436,11 +3436,10 @@ public List<VirtualDirectory> getVirtualDirectoryRoots() throws TskCoreException } /** - * Adds a set of files carved from an image, volume, or file system to the - * case. + * Adds a carving result to the case database. * - * @param carvingResult The carving results (parent and carved files) to be - * added. + * @param carvingResult The carving result (a set of carved files and their + * parent) to be added. * * @return A list of LayoutFile representations of the carved files. * @@ -3451,34 +3450,33 @@ public final List<LayoutFile> addCarvedFiles(CarvingResult carvingResult) throws CaseDbTransaction transaction = null; Statement statement = null; ResultSet resultSet = null; - acquireExclusiveLock(); + acquireExclusiveLock(); // This is a no-op for a PostgreSQL case database. try { transaction = beginTransaction(); CaseDbConnection connection = transaction.getConnection(); /* - * Find the root file system, volume, or image ancestor of the - * carved files parent. This is necessary because the carved files - * will be "re-parented" as children of the $CarvedFiles virtual - * directory of this ancestor. + * Currently carved files are "re-parented" as children of the + * $CarvedFiles virtual directory of the root file system, volume, + * or image ancestor of the carved files parent. */ Content root = carvingResult.getParent(); - while ((root instanceof FileSystem == false) - && (root instanceof Volume == false) - && (root instanceof Image == false)) { + while (null != root + && root instanceof FileSystem == false + && root instanceof Volume == false + && root instanceof Image == false) { root = root.getParent(); } /* - * Get or create the cached $CarvedFiles virtual directory for the - * root ancestor. + * Get or create the $CarvedFiles virtual directory for the root + * ancestor. */ VirtualDirectory carvedFilesDir = rootIdsToCarvedFileDirs.get(root.getId()); if (null == carvedFilesDir) { List<Content> children = Collections.emptyList(); if (root instanceof FileSystem) { - FileSystem fileSystem = (FileSystem) root; - children = fileSystem.getRootDirectory().getChildren(); + children = ((FileSystem) root).getRootDirectory().getChildren(); } else if (root instanceof Volume || root instanceof Image) { children = root.getChildren(); } @@ -3506,8 +3504,8 @@ public final List<LayoutFile> addCarvedFiles(CarvingResult carvingResult) throws */ PreparedStatement prepStmt = connection.getPreparedStatement(PREPARED_STATEMENT.INSERT_OBJECT, Statement.RETURN_GENERATED_KEYS); prepStmt.clearParameters(); - prepStmt.setLong(1, carvedFilesDir.getId()); - prepStmt.setLong(2, TskData.ObjectType.ABSTRACTFILE.getObjectType()); + prepStmt.setLong(1, carvedFilesDir.getId()); // par_obj_id + prepStmt.setLong(2, TskData.ObjectType.ABSTRACTFILE.getObjectType()); // type connection.executeUpdate(prepStmt); resultSet = prepStmt.getGeneratedKeys(); resultSet.next(); @@ -3522,26 +3520,26 @@ public final List<LayoutFile> addCarvedFiles(CarvingResult carvingResult) throws */ prepStmt = connection.getPreparedStatement(PREPARED_STATEMENT.INSERT_FILE); prepStmt.clearParameters(); - prepStmt.setLong(1, carvedFileId); + prepStmt.setLong(1, carvedFileId); // obj_id if (root instanceof FileSystem) { - prepStmt.setLong(2, root.getId()); + prepStmt.setLong(2, root.getId()); // fs_obj_id } else { - prepStmt.setNull(2, java.sql.Types.BIGINT); + prepStmt.setNull(2, java.sql.Types.BIGINT); // fs_obj_id } - prepStmt.setString(3, carvedFile.getName()); - prepStmt.setShort(4, TSK_DB_FILES_TYPE_ENUM.CARVED.getFileType()); - prepStmt.setShort(5, (short) 1); // Has a path - prepStmt.setShort(6, TSK_FS_NAME_TYPE_ENUM.REG.getValue()); - prepStmt.setShort(7, TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_REG.getValue()); - prepStmt.setShort(8, TSK_FS_NAME_FLAG_ENUM.UNALLOC.getValue()); - prepStmt.setShort(9, TSK_FS_META_FLAG_ENUM.UNALLOC.getValue()); - prepStmt.setLong(10, carvedFile.getSizeInBytes()); - prepStmt.setNull(11, java.sql.Types.BIGINT); - prepStmt.setNull(12, java.sql.Types.BIGINT); - prepStmt.setNull(13, java.sql.Types.BIGINT); - prepStmt.setNull(14, java.sql.Types.BIGINT); - prepStmt.setString(15, carvedFilesDir.getUniquePath()); - prepStmt.setLong(16, carvedFilesDir.getDataSourceObjectId()); + prepStmt.setString(3, carvedFile.getName()); // name + prepStmt.setShort(4, TSK_DB_FILES_TYPE_ENUM.CARVED.getFileType()); // type + prepStmt.setShort(5, (short) 1); // has_path + prepStmt.setShort(6, TSK_FS_NAME_TYPE_ENUM.REG.getValue()); // dir_type + prepStmt.setShort(7, TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_REG.getValue()); // meta_type + prepStmt.setShort(8, TSK_FS_NAME_FLAG_ENUM.UNALLOC.getValue()); // dir_flags + prepStmt.setShort(9, TSK_FS_META_FLAG_ENUM.UNALLOC.getValue()); // nmeta_flags + prepStmt.setLong(10, carvedFile.getSizeInBytes()); // size + prepStmt.setNull(11, java.sql.Types.BIGINT); // ctime + prepStmt.setNull(12, java.sql.Types.BIGINT); // crtime + prepStmt.setNull(13, java.sql.Types.BIGINT); // atime + prepStmt.setNull(14, java.sql.Types.BIGINT); // mtime + prepStmt.setString(15, carvedFilesDir.getUniquePath()); // parent path + prepStmt.setLong(16, carvedFilesDir.getDataSourceObjectId()); // data_source_obj_id connection.executeUpdate(prepStmt); // Add a row in the tsk_layout_file table for each TskFileRange. @@ -3550,10 +3548,10 @@ public final List<LayoutFile> addCarvedFiles(CarvingResult carvingResult) throws prepStmt = connection.getPreparedStatement(PREPARED_STATEMENT.INSERT_LAYOUT_FILE); for (TskFileRange tskFileRange : carvedFile.getLayoutInParent()) { prepStmt.clearParameters(); - prepStmt.setLong(1, carvedFileId); - prepStmt.setLong(2, tskFileRange.getByteStart()); - prepStmt.setLong(3, tskFileRange.getByteLen()); - prepStmt.setLong(4, tskFileRange.getSequence()); + prepStmt.setLong(1, carvedFileId); // obj_id + prepStmt.setLong(2, tskFileRange.getByteStart()); // byte_start + prepStmt.setLong(3, tskFileRange.getByteLen()); // byte_len + prepStmt.setLong(4, tskFileRange.getSequence()); // sequence connection.executeUpdate(prepStmt); } @@ -3586,7 +3584,7 @@ public final List<LayoutFile> addCarvedFiles(CarvingResult carvingResult) throws } finally { closeResultSet(resultSet); closeStatement(statement); - releaseExclusiveLock(); + releaseExclusiveLock(); // This is a no-op for a PostgreSQL case database. } } @@ -7062,14 +7060,12 @@ public LayoutFile addCarvedFile(String carvedFileName, long carvedFileSize, long files.add(carvedFile); CarvingResult carvingResult; Content parent = getContentById(containerId); - if (parent instanceof Image) { - carvingResult = new CarvingResult((Image) parent, files); - } else if (parent instanceof Volume) { - carvingResult = new CarvingResult((Volume) parent, files); - } else if (parent instanceof FileSystem) { - carvingResult = new CarvingResult((FileSystem) parent, files); + if (parent instanceof FileSystem + || parent instanceof Volume + || parent instanceof Image) { + carvingResult = new CarvingResult(parent, files); } else { - throw new TskCoreException(String.format("Parent (id =%d) is not an image, volume or file system", containerId)); + throw new TskCoreException(String.format("Parent (id =%d) is not an file system, volume or image", containerId)); } return addCarvedFiles(carvingResult).get(0); } @@ -7097,14 +7093,12 @@ public List<LayoutFile> addCarvedFiles(List<CarvedFileContainer> filesToAdd) thr } CarvingResult carvingResult; Content parent = getContentById(filesToAdd.get(0).getId()); - if (parent instanceof Image) { - carvingResult = new CarvingResult((Image) parent, carvedFiles); - } else if (parent instanceof Volume) { - carvingResult = new CarvingResult((Volume) parent, carvedFiles); - } else if (parent instanceof FileSystem) { - carvingResult = new CarvingResult((FileSystem) parent, carvedFiles); + if (parent instanceof FileSystem + || parent instanceof Volume + || parent instanceof Image) { + carvingResult = new CarvingResult(parent, carvedFiles); } else { - throw new TskCoreException(String.format("Parent (id =%d) is not an image, volume or file system", parent.getId())); + throw new TskCoreException(String.format("Parent (id =%d) is not an file system, volume or image", parent.getId())); } return addCarvedFiles(carvingResult); }