diff --git a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java index 7fbf4f9d7dddb5d7653a76a372aa1d271e552a31..4999526674b4837b43488c3b79464bd1be867b75 100755 --- a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java +++ b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java @@ -239,12 +239,12 @@ void fireTSKEvent(Object event) { private final Map<Long, Content> frequentlyUsedContentMap = new HashMap<>(); private Examiner cachedCurrentExaminer = null; - + static { Properties p = new Properties(System.getProperties()); - p.put("com.mchange.v2.log.MLog", "com.mchange.v2.log.FallbackMLog"); - p.put("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL", "SEVERE"); - System.setProperties(p); + p.put("com.mchange.v2.log.MLog", "com.mchange.v2.log.FallbackMLog"); + p.put("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL", "SEVERE"); + System.setProperties(p); } /** @@ -373,7 +373,8 @@ private void init() throws Exception { typeNameToAttributeTypeMap = new ConcurrentHashMap<>(); /* - * The database schema must be updated before loading blackboard artifact/attribute types + * The database schema must be updated before loading blackboard + * artifact/attribute types */ updateDatabaseSchema(null); initBlackboardArtifactTypes(); @@ -523,7 +524,7 @@ public synchronized TaggingManager getTaggingManager() { public ScoringManager getScoringManager() throws TskCoreException { return scoringManager; } - + /** * Gets the OS account realm manager for this case. * @@ -534,7 +535,7 @@ public ScoringManager getScoringManager() throws TskCoreException { public OsAccountRealmManager getOsAccountRealmManager() throws TskCoreException { return osAccountRealmManager; } - + /** * Gets the OS account manager for this case. * @@ -545,7 +546,7 @@ public OsAccountRealmManager getOsAccountRealmManager() throws TskCoreException public OsAccountManager getOsAccountManager() throws TskCoreException { return osAccountManager; } - + /** * Gets the Hosts manager for this case. * @@ -556,7 +557,7 @@ public OsAccountManager getOsAccountManager() throws TskCoreException { public HostManager getHostManager() throws TskCoreException { return hostManager; } - + /** * Gets the Person manager for this case. * @@ -567,7 +568,7 @@ public HostManager getHostManager() throws TskCoreException { public PersonManager getPersonManager() throws TskCoreException { return personManager; } - + /** * Gets the HostAddress manager for this case. * @@ -577,8 +578,8 @@ public PersonManager getPersonManager() throws TskCoreException { */ public HostAddressManager getHostAddressManager() throws TskCoreException { return hostAddressManager; - } - + } + /** * Make sure the predefined artifact types are in the artifact types table. * @@ -1179,26 +1180,26 @@ private CaseDbSchemaVersionNumber updateFromSchema2toSchema3(CaseDbSchemaVersion // Convert existing tag artifact and attribute rows to rows in the new tags tables. Map<String, Long> tagNames = new HashMap<>(); long tagNameCounter = 1; - + // Convert file tags. // We need data from the TSK_TAG_NAME and TSK_COMMENT attributes, and need the file size from the tsk_files table. - resultSet = statement.executeQuery("SELECT * FROM \n" + - "(SELECT blackboard_artifacts.obj_id AS objId, blackboard_attributes.artifact_id AS artifactId, blackboard_attributes.value_text AS name\n" + - "FROM blackboard_artifacts INNER JOIN blackboard_attributes \n" + - "ON blackboard_artifacts.artifact_id = blackboard_attributes.artifact_id \n" + - "WHERE blackboard_artifacts.artifact_type_id = " + - BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE.getTypeID() + - " AND blackboard_attributes.attribute_type_id = " + BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TAG_NAME.getTypeID() - + ") AS tagNames \n" + - "INNER JOIN \n" + - "(SELECT tsk_files.obj_id as objId2, tsk_files.size AS fileSize \n" + - "FROM blackboard_artifacts INNER JOIN tsk_files \n" + - "ON blackboard_artifacts.obj_id = tsk_files.obj_id) AS fileData \n" + - "ON tagNames.objId = fileData.objId2 \n" + - "LEFT JOIN \n" + - "(SELECT value_text AS comment, artifact_id AS tagArtifactId FROM blackboard_attributes WHERE attribute_type_id = " + - BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COMMENT.getTypeID() + ") AS tagComments \n" + - "ON tagNames.artifactId = tagComments.tagArtifactId"); + resultSet = statement.executeQuery("SELECT * FROM \n" + + "(SELECT blackboard_artifacts.obj_id AS objId, blackboard_attributes.artifact_id AS artifactId, blackboard_attributes.value_text AS name\n" + + "FROM blackboard_artifacts INNER JOIN blackboard_attributes \n" + + "ON blackboard_artifacts.artifact_id = blackboard_attributes.artifact_id \n" + + "WHERE blackboard_artifacts.artifact_type_id = " + + BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE.getTypeID() + + " AND blackboard_attributes.attribute_type_id = " + BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TAG_NAME.getTypeID() + + ") AS tagNames \n" + + "INNER JOIN \n" + + "(SELECT tsk_files.obj_id as objId2, tsk_files.size AS fileSize \n" + + "FROM blackboard_artifacts INNER JOIN tsk_files \n" + + "ON blackboard_artifacts.obj_id = tsk_files.obj_id) AS fileData \n" + + "ON tagNames.objId = fileData.objId2 \n" + + "LEFT JOIN \n" + + "(SELECT value_text AS comment, artifact_id AS tagArtifactId FROM blackboard_attributes WHERE attribute_type_id = " + + BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COMMENT.getTypeID() + ") AS tagComments \n" + + "ON tagNames.artifactId = tagComments.tagArtifactId"); while (resultSet.next()) { long objId = resultSet.getLong("objId"); @@ -1208,46 +1209,46 @@ private CaseDbSchemaVersionNumber updateFromSchema2toSchema3(CaseDbSchemaVersion if (tagComment == null) { tagComment = ""; } - - if (tagName != null && ! tagName.isEmpty()) { + + if (tagName != null && !tagName.isEmpty()) { // Get the index for the tag name, adding it to the database if needed. long tagNameIndex; if (tagNames.containsKey(tagName)) { tagNameIndex = tagNames.get(tagName); } else { - statement2.execute("INSERT INTO tag_names (display_name, description, color) " + - "VALUES(\"" + tagName + "\", \"\", \"None\")"); + statement2.execute("INSERT INTO tag_names (display_name, description, color) " + + "VALUES(\"" + tagName + "\", \"\", \"None\")"); tagNames.put(tagName, tagNameCounter); tagNameIndex = tagNameCounter; tagNameCounter++; } - - statement2.execute("INSERT INTO content_tags (obj_id, tag_name_id, comment, begin_byte_offset, end_byte_offset) " + - "VALUES(" + objId + ", " + tagNameIndex + ", \"" + tagComment + "\", 0, " + fileSize + ")"); + + statement2.execute("INSERT INTO content_tags (obj_id, tag_name_id, comment, begin_byte_offset, end_byte_offset) " + + "VALUES(" + objId + ", " + tagNameIndex + ", \"" + tagComment + "\", 0, " + fileSize + ")"); } } resultSet.close(); - + // Convert artifact tags. // We need data from the TSK_TAG_NAME, TSK_TAGGED_ARTIFACT, and TSK_COMMENT attributes. - resultSet = statement.executeQuery("SELECT * FROM \n" + - "(SELECT blackboard_artifacts.obj_id AS objId, blackboard_attributes.artifact_id AS artifactId, " + - "blackboard_attributes.value_text AS name\n" + - "FROM blackboard_artifacts INNER JOIN blackboard_attributes \n" + - "ON blackboard_artifacts.artifact_id = blackboard_attributes.artifact_id \n" + - "WHERE blackboard_artifacts.artifact_type_id = " + - BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_ARTIFACT.getTypeID() + - " AND blackboard_attributes.attribute_type_id = " + BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TAG_NAME.getTypeID() - + ") AS tagNames \n" + - "INNER JOIN \n" + - "(SELECT value_int64 AS taggedArtifactId, artifact_id AS associatedArtifactId FROM blackboard_attributes WHERE attribute_type_id = " + - BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TAGGED_ARTIFACT.getTypeID() + ") AS tagArtifacts \n" + - "ON tagNames.artifactId = tagArtifacts.associatedArtifactId \n" + - "LEFT JOIN \n" + - "(SELECT value_text AS comment, artifact_id AS commentArtifactId FROM blackboard_attributes WHERE attribute_type_id = " + - BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COMMENT.getTypeID() + ") AS tagComments \n" + - "ON tagNames.artifactId = tagComments.commentArtifactId"); - + resultSet = statement.executeQuery("SELECT * FROM \n" + + "(SELECT blackboard_artifacts.obj_id AS objId, blackboard_attributes.artifact_id AS artifactId, " + + "blackboard_attributes.value_text AS name\n" + + "FROM blackboard_artifacts INNER JOIN blackboard_attributes \n" + + "ON blackboard_artifacts.artifact_id = blackboard_attributes.artifact_id \n" + + "WHERE blackboard_artifacts.artifact_type_id = " + + BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_ARTIFACT.getTypeID() + + " AND blackboard_attributes.attribute_type_id = " + BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TAG_NAME.getTypeID() + + ") AS tagNames \n" + + "INNER JOIN \n" + + "(SELECT value_int64 AS taggedArtifactId, artifact_id AS associatedArtifactId FROM blackboard_attributes WHERE attribute_type_id = " + + BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TAGGED_ARTIFACT.getTypeID() + ") AS tagArtifacts \n" + + "ON tagNames.artifactId = tagArtifacts.associatedArtifactId \n" + + "LEFT JOIN \n" + + "(SELECT value_text AS comment, artifact_id AS commentArtifactId FROM blackboard_attributes WHERE attribute_type_id = " + + BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COMMENT.getTypeID() + ") AS tagComments \n" + + "ON tagNames.artifactId = tagComments.commentArtifactId"); + while (resultSet.next()) { long artifactId = resultSet.getLong("taggedArtifactId"); String tagName = resultSet.getString("name"); @@ -1255,25 +1256,25 @@ private CaseDbSchemaVersionNumber updateFromSchema2toSchema3(CaseDbSchemaVersion if (tagComment == null) { tagComment = ""; } - if (tagName != null && ! tagName.isEmpty()) { + if (tagName != null && !tagName.isEmpty()) { // Get the index for the tag name, adding it to the database if needed. long tagNameIndex; if (tagNames.containsKey(tagName)) { tagNameIndex = tagNames.get(tagName); } else { - statement2.execute("INSERT INTO tag_names (display_name, description, color) " + - "VALUES(\"" + tagName + "\", \"\", \"None\")"); + statement2.execute("INSERT INTO tag_names (display_name, description, color) " + + "VALUES(\"" + tagName + "\", \"\", \"None\")"); tagNames.put(tagName, tagNameCounter); tagNameIndex = tagNameCounter; tagNameCounter++; } - - statement2.execute("INSERT INTO blackboard_artifact_tags (artifact_id, tag_name_id, comment) " + - "VALUES(" + artifactId + ", " + tagNameIndex + ", \"" + tagComment + "\")"); + + statement2.execute("INSERT INTO blackboard_artifact_tags (artifact_id, tag_name_id, comment) " + + "VALUES(" + artifactId + ", " + tagNameIndex + ", \"" + tagComment + "\")"); } - } + } resultSet.close(); - + statement.execute( "DELETE FROM blackboard_attributes WHERE artifact_id IN " //NON-NLS + "(SELECT artifact_id FROM blackboard_artifacts WHERE artifact_type_id = " //NON-NLS @@ -2258,10 +2259,12 @@ private CaseDbSchemaVersionNumber updateFromSchema8dot4toSchema8dot5(CaseDbSchem statement.execute("ALTER TABLE tag_names ADD COLUMN rank INTEGER"); - /* Update existing Project Vic tag names (from Image Gallery in Autopsy) - * to be part of a Tag Set. - * NOTE: These names are out of date and will not work with the Project VIC - * Report module. New cases will get the new names from Image Gallery. */ + /* + * Update existing Project Vic tag names (from Image Gallery in + * Autopsy) to be part of a Tag Set. NOTE: These names are out of + * date and will not work with the Project VIC Report module. New + * cases will get the new names from Image Gallery. + */ String insertStmt = "INSERT INTO tsk_tag_sets (name) VALUES ('Project VIC')"; if (getDatabaseType() == DbType.POSTGRESQL) { statement.execute(insertStmt, Statement.RETURN_GENERATED_KEYS); @@ -2321,7 +2324,7 @@ private CaseDbSchemaVersionNumber updateFromSchema8dot4toSchema8dot5(CaseDbSchem releaseSingleUserCaseWriteLock(); } } - + private CaseDbSchemaVersionNumber updateFromSchema8dot5toSchema8dot6(CaseDbSchemaVersionNumber schemaVersion, CaseDbConnection connection) throws SQLException, TskCoreException { if (schemaVersion.getMajor() != 8) { return schemaVersion; @@ -2342,7 +2345,7 @@ private CaseDbSchemaVersionNumber updateFromSchema8dot5toSchema8dot6(CaseDbSchem closeStatement(statement); releaseSingleUserCaseWriteLock(); } - } + } @SuppressWarnings("deprecation") private CaseDbSchemaVersionNumber updateFromSchema8dot6toSchema9dot0(CaseDbSchemaVersionNumber schemaVersion, CaseDbConnection connection) throws SQLException, TskCoreException { @@ -2357,48 +2360,48 @@ private CaseDbSchemaVersionNumber updateFromSchema8dot6toSchema9dot0(CaseDbSchem Statement statement = connection.createStatement(); acquireSingleUserCaseWriteLock(); try { - String dateDataType = "BIGINT"; + String dateDataType = "BIGINT"; String bigIntDataType = "BIGINT"; - String blobDataType = "BYTEA"; + String blobDataType = "BYTEA"; String primaryKeyType = "BIGSERIAL"; if (this.dbType.equals(DbType.SQLITE)) { - dateDataType = "INTEGER"; + dateDataType = "INTEGER"; bigIntDataType = "INTEGER"; - blobDataType = "BLOB"; + blobDataType = "BLOB"; primaryKeyType = "INTEGER"; } - statement.execute("ALTER TABLE data_source_info ADD COLUMN added_date_time "+ dateDataType ); + statement.execute("ALTER TABLE data_source_info ADD COLUMN added_date_time " + dateDataType); statement.execute("ALTER TABLE data_source_info ADD COLUMN acquisition_tool_settings TEXT"); statement.execute("ALTER TABLE data_source_info ADD COLUMN acquisition_tool_name TEXT"); statement.execute("ALTER TABLE data_source_info ADD COLUMN acquisition_tool_version TEXT"); - + // Add category type and initialize the types. We use the list of artifact types that // were categorized as analysis results as of the 8.7 update to ensure consistency in // case the built-in types change in a later release. statement.execute("ALTER TABLE blackboard_artifact_types ADD COLUMN category_type INTEGER DEFAULT 0"); - String analysisTypeObjIdList = - BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID() + ", " - + BlackboardArtifact.ARTIFACT_TYPE.TSK_HASHSET_HIT.getTypeID() + ", " - + BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT.getTypeID() + ", " - + BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE.getTypeID() + ", " - + BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_ARTIFACT.getTypeID() + ", " - + BlackboardArtifact.ARTIFACT_TYPE.TSK_ENCRYPTION_DETECTED.getTypeID() + ", " - + BlackboardArtifact.ARTIFACT_TYPE.TSK_EXT_MISMATCH_DETECTED.getTypeID() + ", " - + BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT.getTypeID() + ", " - + BlackboardArtifact.ARTIFACT_TYPE.TSK_FACE_DETECTED.getTypeID() + ", " - + BlackboardArtifact.ARTIFACT_TYPE.TSK_ENCRYPTION_SUSPECTED.getTypeID() + ", " - + BlackboardArtifact.ARTIFACT_TYPE.TSK_OBJECT_DETECTED.getTypeID() + ", " - + BlackboardArtifact.ARTIFACT_TYPE.TSK_VERIFICATION_FAILED.getTypeID() + ", " - + BlackboardArtifact.ARTIFACT_TYPE.TSK_DATA_SOURCE_USAGE.getTypeID() + ", " - + BlackboardArtifact.ARTIFACT_TYPE.TSK_USER_CONTENT_SUSPECTED.getTypeID() + ", " - + BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_ACCOUNT_TYPE.getTypeID() + ", " - + BlackboardArtifact.ARTIFACT_TYPE.TSK_YARA_HIT.getTypeID() + ", " - + BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_CATEGORIZATION.getTypeID(); + String analysisTypeObjIdList + = BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID() + ", " + + BlackboardArtifact.ARTIFACT_TYPE.TSK_HASHSET_HIT.getTypeID() + ", " + + BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT.getTypeID() + ", " + + BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE.getTypeID() + ", " + + BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_ARTIFACT.getTypeID() + ", " + + BlackboardArtifact.ARTIFACT_TYPE.TSK_ENCRYPTION_DETECTED.getTypeID() + ", " + + BlackboardArtifact.ARTIFACT_TYPE.TSK_EXT_MISMATCH_DETECTED.getTypeID() + ", " + + BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT.getTypeID() + ", " + + BlackboardArtifact.ARTIFACT_TYPE.TSK_FACE_DETECTED.getTypeID() + ", " + + BlackboardArtifact.ARTIFACT_TYPE.TSK_ENCRYPTION_SUSPECTED.getTypeID() + ", " + + BlackboardArtifact.ARTIFACT_TYPE.TSK_OBJECT_DETECTED.getTypeID() + ", " + + BlackboardArtifact.ARTIFACT_TYPE.TSK_VERIFICATION_FAILED.getTypeID() + ", " + + BlackboardArtifact.ARTIFACT_TYPE.TSK_DATA_SOURCE_USAGE.getTypeID() + ", " + + BlackboardArtifact.ARTIFACT_TYPE.TSK_USER_CONTENT_SUSPECTED.getTypeID() + ", " + + BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_ACCOUNT_TYPE.getTypeID() + ", " + + BlackboardArtifact.ARTIFACT_TYPE.TSK_YARA_HIT.getTypeID() + ", " + + BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_CATEGORIZATION.getTypeID(); statement.execute("UPDATE blackboard_artifact_types SET category_type = " + BlackboardArtifact.Category.ANALYSIS_RESULT.getID() + " WHERE artifact_type_id IN (" + analysisTypeObjIdList + ")"); - // Create tsk file attributes table + // Create tsk file attributes table statement.execute("CREATE TABLE tsk_file_attributes (id " + primaryKeyType + " PRIMARY KEY, " + "obj_id " + bigIntDataType + " NOT NULL, " + "attribute_type_id " + bigIntDataType + " NOT NULL, " @@ -2429,7 +2432,7 @@ private CaseDbSchemaVersionNumber updateFromSchema8dot6toSchema9dot0(CaseDbSchem statement.execute("CREATE TABLE tsk_persons (id " + primaryKeyType + " PRIMARY KEY, " + "name TEXT NOT NULL, " // person name + "UNIQUE(name)) "); - + // Create host table. statement.execute("CREATE TABLE tsk_hosts (id " + primaryKeyType + " PRIMARY KEY, " + "name TEXT NOT NULL, " // host name @@ -2442,16 +2445,16 @@ private CaseDbSchemaVersionNumber updateFromSchema8dot6toSchema9dot0(CaseDbSchem // Create OS Account and related tables statement.execute("CREATE TABLE tsk_os_account_realms (id " + primaryKeyType + " PRIMARY KEY, " - + "realm_name TEXT DEFAULT NULL, " // realm name - for a domain realm, may be null - + "realm_addr TEXT DEFAULT NULL, " // a sid/uid or some some other identifier, may be null - + "realm_signature TEXT NOT NULL, " // Signature exists only to prevent duplicates. It is made up of realm address/name and scope host - + "scope_host_id " + bigIntDataType + " DEFAULT NULL, " // if the realm scope is a single host - + "scope_confidence INTEGER, " // indicates whether we know for sure the realm scope or if we are inferring it - + "db_status INTEGER DEFAULT 0, " // active/merged/deleted - + "merged_into " + bigIntDataType + " DEFAULT NULL, " - + "UNIQUE(realm_signature), " - + "FOREIGN KEY(scope_host_id) REFERENCES tsk_hosts(id)," - + "FOREIGN KEY(merged_into) REFERENCES tsk_os_account_realms(id) )"); + + "realm_name TEXT DEFAULT NULL, " // realm name - for a domain realm, may be null + + "realm_addr TEXT DEFAULT NULL, " // a sid/uid or some some other identifier, may be null + + "realm_signature TEXT NOT NULL, " // Signature exists only to prevent duplicates. It is made up of realm address/name and scope host + + "scope_host_id " + bigIntDataType + " DEFAULT NULL, " // if the realm scope is a single host + + "scope_confidence INTEGER, " // indicates whether we know for sure the realm scope or if we are inferring it + + "db_status INTEGER DEFAULT 0, " // active/merged/deleted + + "merged_into " + bigIntDataType + " DEFAULT NULL, " + + "UNIQUE(realm_signature), " + + "FOREIGN KEY(scope_host_id) REFERENCES tsk_hosts(id)," + + "FOREIGN KEY(merged_into) REFERENCES tsk_os_account_realms(id) )"); // Add host column and create a host for each existing data source. // We will create a host for each device id so that related data sources will @@ -2464,8 +2467,8 @@ private CaseDbSchemaVersionNumber updateFromSchema8dot6toSchema9dot0(CaseDbSchem while (resultSet.next()) { long objId = resultSet.getLong("obj_id"); String deviceId = resultSet.getString("device_id"); - - if (! hostMap.containsKey(deviceId)) { + + if (!hostMap.containsKey(deviceId)) { String hostName = "Host " + hostIndex; updateStatement.execute("INSERT INTO tsk_hosts (name, db_status) VALUES ('" + hostName + "', 0)"); hostMap.put(deviceId, hostIndex); @@ -2476,7 +2479,7 @@ private CaseDbSchemaVersionNumber updateFromSchema8dot6toSchema9dot0(CaseDbSchem } finally { closeStatement(updateStatement); } - + statement.execute("CREATE TABLE tsk_os_accounts (os_account_obj_id " + bigIntDataType + " PRIMARY KEY, " + "login_name TEXT DEFAULT NULL, " // login name, if available, may be null + "full_name TEXT DEFAULT NULL, " // full name, if available, may be null @@ -2487,11 +2490,11 @@ private CaseDbSchemaVersionNumber updateFromSchema8dot6toSchema9dot0(CaseDbSchem + "type INTEGER, " // service/interactive + "created_date " + bigIntDataType + " DEFAULT NULL, " + "db_status INTEGER DEFAULT 0, " // active/merged/deleted - + "merged_into " + bigIntDataType + " DEFAULT NULL, " + + "merged_into " + bigIntDataType + " DEFAULT NULL, " + "UNIQUE(signature, realm_id), " + "FOREIGN KEY(os_account_obj_id) REFERENCES tsk_objects(obj_id) ON DELETE CASCADE, " + "FOREIGN KEY(realm_id) REFERENCES tsk_os_account_realms(id)," - + "FOREIGN KEY(merged_into) REFERENCES tsk_os_accounts(os_account_obj_id) )"); + + "FOREIGN KEY(merged_into) REFERENCES tsk_os_accounts(os_account_obj_id) )"); statement.execute("CREATE TABLE tsk_os_account_attributes (id " + primaryKeyType + " PRIMARY KEY, " + "os_account_obj_id " + bigIntDataType + " NOT NULL, " @@ -2525,7 +2528,6 @@ private CaseDbSchemaVersionNumber updateFromSchema8dot6toSchema9dot0(CaseDbSchem statement.execute("ALTER TABLE tsk_files ADD COLUMN owner_uid TEXT DEFAULT NULL"); statement.execute("ALTER TABLE tsk_files ADD COLUMN os_account_obj_id " + bigIntDataType + " DEFAULT NULL REFERENCES tsk_os_accounts(os_account_obj_id) "); - // create host address tables statement.execute("CREATE TABLE tsk_host_addresses (id " + primaryKeyType + " PRIMARY KEY, " + "address_type INTEGER NOT NULL, " @@ -2560,10 +2562,8 @@ private CaseDbSchemaVersionNumber updateFromSchema8dot6toSchema9dot0(CaseDbSchem + "data_source_obj_id " + bigIntDataType + " NOT NULL, " // data source where the usage was found + "UNIQUE(addr_obj_id, obj_id), " + "FOREIGN KEY(addr_obj_id) REFERENCES tsk_host_addresses(id) ON DELETE CASCADE, " - + "FOREIGN KEY(obj_id) REFERENCES tsk_objects(obj_id) ON DELETE CASCADE )"); - - + return new CaseDbSchemaVersionNumber(9, 0); } finally { @@ -2683,10 +2683,10 @@ public String getBackupDatabasePath() { * that is returned can be passed to methods that take a CaseDbTransaction. * The caller is responsible for calling either commit() or rollback() on * the transaction object. - * + * * Note that this beginning the transaction also acquires the single user - * case write lock, which will be automatically released when the transaction - * is closed. + * case write lock, which will be automatically released when the + * transaction is closed. * * @return A CaseDbTransaction object. * @@ -3508,7 +3508,7 @@ public List<BlackboardArtifact> getBlackboardArtifacts(BlackboardAttribute.ATTRI + " AND arts.review_status_id !=" + BlackboardArtifact.ReviewStatus.REJECTED.getID()); //NON-NLS ArrayList<BlackboardArtifact> artifacts = new ArrayList<BlackboardArtifact>(); while (rs.next()) { - artifacts.add(new BlackboardArtifact(this, rs.getLong("artifact_id"), rs.getLong("obj_id"), rs.getLong("artifact_obj_id"), + artifacts.add(new BlackboardArtifact(this, rs.getLong("artifact_id"), rs.getLong("obj_id"), rs.getLong("artifact_obj_id"), rs.getObject("data_source_obj_id") != null ? rs.getLong("data_source_obj_id") : null, rs.getInt("artifact_type_id"), rs.getString("type_name"), rs.getString("display_name"), BlackboardArtifact.ReviewStatus.withID(rs.getInt("review_status_id")))); @@ -3524,7 +3524,6 @@ public List<BlackboardArtifact> getBlackboardArtifacts(BlackboardAttribute.ATTRI } } - /** * Get all blackboard artifacts that have an attribute of the given type and * String value. Does not included rejected artifacts. @@ -3565,7 +3564,7 @@ public List<BlackboardArtifact> getBlackboardArtifacts(BlackboardAttribute.ATTRI + " AND arts.review_status_id !=" + BlackboardArtifact.ReviewStatus.REJECTED.getID()); ArrayList<BlackboardArtifact> artifacts = new ArrayList<BlackboardArtifact>(); while (rs.next()) { - artifacts.add(new BlackboardArtifact(this, rs.getLong("artifact_id"), rs.getLong("obj_id"), rs.getLong("artifact_obj_id"), + artifacts.add(new BlackboardArtifact(this, rs.getLong("artifact_id"), rs.getLong("obj_id"), rs.getLong("artifact_obj_id"), rs.getObject("data_source_obj_id") != null ? rs.getLong("data_source_obj_id") : null, rs.getInt("artifact_type_id"), rs.getString("type_name"), rs.getString("display_name"), BlackboardArtifact.ReviewStatus.withID(rs.getInt("review_status_id")))); @@ -4217,7 +4216,8 @@ public List<BlackboardArtifact> getBlackboardArtifacts(ARTIFACT_TYPE artifactTyp } /** - * Get the blackboard artifact with the given artifact id (artifact_id in blackboard_artifacts) + * Get the blackboard artifact with the given artifact id (artifact_id in + * blackboard_artifacts) * * @param artifactID artifact ID (artifact_id column) * @@ -4355,10 +4355,10 @@ void addBlackBoardAttribute(BlackboardAttribute attr, int artifactTypeId, CaseDb statement.setLong(6, attr.getAttributeType().getValueType().getType()); connection.executeUpdate(statement); } - + void addFileAttribute(Attribute attr, CaseDbConnection connection) throws SQLException, TskCoreException { - PreparedStatement statement; - statement = connection.getPreparedStatement(PREPARED_STATEMENT.INSERT_FILE_ATTRIBUTE, Statement.RETURN_GENERATED_KEYS); + PreparedStatement statement; + statement = connection.getPreparedStatement(PREPARED_STATEMENT.INSERT_FILE_ATTRIBUTE, Statement.RETURN_GENERATED_KEYS); statement.clearParameters(); statement.setLong(1, attr.getAttributeParentId()); @@ -4382,29 +4382,29 @@ void addFileAttribute(Attribute attr, CaseDbConnection connection) throws SQLExc } else { statement.setNull(6, java.sql.Types.INTEGER); } - + if (attr.getAttributeType().getValueType() == TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.DATETIME || attr.getAttributeType().getValueType() == TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.LONG) { statement.setLong(7, attr.getValueLong()); } else { statement.setNull(7, java.sql.Types.BIGINT); } - + if (attr.getAttributeType().getValueType() == TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.DOUBLE) { statement.setDouble(8, attr.getValueDouble()); } else { statement.setNull(8, java.sql.Types.DOUBLE); } - - connection.executeUpdate(statement); + + connection.executeUpdate(statement); try (ResultSet resultSet = statement.getGeneratedKeys()) { - if(!resultSet.next()) { + if (!resultSet.next()) { throw new TskCoreException(String.format("Failed to insert file attribute " + "with id=%d. The expected key was not generated", attr.getId())); } - + attr.setId(resultSet.getLong(1)); - } + } } /** @@ -4740,8 +4740,9 @@ BlackboardArtifact.Type getArtifactType(int artTypeId) throws TskCoreException { /** * Add an artifact type with the given name. Will return an artifact Type. - * - * This assumes that the artifact type being added has the category DATA_ARTIFACT. + * + * This assumes that the artifact type being added has the category + * DATA_ARTIFACT. * * @param artifactTypeName System (unique) name of artifact * @param displayName Display (non-unique) name of artifact @@ -4753,17 +4754,18 @@ BlackboardArtifact.Type getArtifactType(int artTypeId) throws TskCoreException { * within tsk core */ public BlackboardArtifact.Type addBlackboardArtifactType(String artifactTypeName, String displayName) throws TskCoreException, TskDataException { - + return addBlackboardArtifactType(artifactTypeName, displayName, BlackboardArtifact.Category.DATA_ARTIFACT); } /** - * Add an artifact type with the given name and category. Will return an artifact Type. + * Add an artifact type with the given name and category. Will return an + * artifact Type. * * @param artifactTypeName System (unique) name of artifact * @param displayName Display (non-unique) name of artifact - * @param category Artifact type category. - * + * @param category Artifact type category. + * * * @return Type of the artifact added. * @@ -4792,7 +4794,7 @@ BlackboardArtifact.Type addBlackboardArtifactType(String artifactTypeName, Strin maxID++; } } - connection.executeUpdate(s, "INSERT INTO blackboard_artifact_types (artifact_type_id, type_name, display_name, category_type) VALUES ('" + maxID + "', '" + artifactTypeName + "', '" + displayName + "', " + category.getID() + " )"); //NON-NLS + connection.executeUpdate(s, "INSERT INTO blackboard_artifact_types (artifact_type_id, type_name, display_name, category_type) VALUES ('" + maxID + "', '" + artifactTypeName + "', '" + displayName + "', " + category.getID() + " )"); //NON-NLS BlackboardArtifact.Type type = new BlackboardArtifact.Type(maxID, artifactTypeName, displayName, category); this.typeIdToArtifactTypeMap.put(type.getTypeID(), type); this.typeNameToArtifactTypeMap.put(type.getTypeName(), type); @@ -4867,9 +4869,12 @@ public ArrayList<BlackboardAttribute> getBlackboardAttributes(final BlackboardAr /** * Get the attributes associated with the given file. + * * @param file + * * @return - * @throws TskCoreException + * + * @throws TskCoreException */ ArrayList<Attribute> getFileAttributes(final AbstractFile file) throws TskCoreException { CaseDbConnection connection = connections.getConnection(); @@ -5057,9 +5062,11 @@ public BlackboardArtifact newBlackboardArtifact(ARTIFACT_TYPE artifactType, long /** * Add a new blackboard artifact with the given type. * - * @param artifactType the type the given artifact should have - * @param obj_id the content object id associated with this artifact - * @param data_source_obj_id The data source obj id associated with this artifact + * @param artifactType the type the given artifact should have + * @param obj_id the content object id associated with this + * artifact + * @param data_source_obj_id The data source obj id associated with this + * artifact * * @return a new blackboard artifact * @@ -5072,7 +5079,7 @@ BlackboardArtifact newBlackboardArtifact(int artifactTypeID, long obj_id, long d return newBlackboardArtifact(artifactTypeID, obj_id, type.getTypeName(), type.getDisplayName(), data_source_obj_id, connection); } } - + private BlackboardArtifact newBlackboardArtifact(int artifact_type_id, long obj_id, String artifactTypeName, String artifactDisplayName) throws TskCoreException { try (CaseDbConnection connection = connections.getConnection()) { long data_source_obj_id = getDataSourceObjectId(connection, obj_id); @@ -5080,36 +5087,36 @@ private BlackboardArtifact newBlackboardArtifact(int artifact_type_id, long obj_ } } - PreparedStatement createInsertArtifactStatement(int artifact_type_id, long obj_id, long artifact_obj_id, long data_source_obj_id, CaseDbConnection connection) throws TskCoreException, SQLException { - - PreparedStatement statement; - if (dbType == DbType.POSTGRESQL) { - statement = connection.getPreparedStatement(PREPARED_STATEMENT.POSTGRESQL_INSERT_ARTIFACT, Statement.RETURN_GENERATED_KEYS); - statement.clearParameters(); - statement.setLong(1, obj_id); - statement.setLong(2, artifact_obj_id); - statement.setLong(3, data_source_obj_id); - statement.setInt(4, artifact_type_id); - } else { - statement = connection.getPreparedStatement(PREPARED_STATEMENT.INSERT_ARTIFACT, Statement.RETURN_GENERATED_KEYS); - statement.clearParameters(); - this.nextArtifactId++; - statement.setLong(1, this.nextArtifactId); - statement.setLong(2, obj_id); - statement.setLong(3, artifact_obj_id); - statement.setLong(4, data_source_obj_id); - statement.setInt(5, artifact_type_id); - } - + PreparedStatement createInsertArtifactStatement(int artifact_type_id, long obj_id, long artifact_obj_id, long data_source_obj_id, CaseDbConnection connection) throws TskCoreException, SQLException { + + PreparedStatement statement; + if (dbType == DbType.POSTGRESQL) { + statement = connection.getPreparedStatement(PREPARED_STATEMENT.POSTGRESQL_INSERT_ARTIFACT, Statement.RETURN_GENERATED_KEYS); + statement.clearParameters(); + statement.setLong(1, obj_id); + statement.setLong(2, artifact_obj_id); + statement.setLong(3, data_source_obj_id); + statement.setInt(4, artifact_type_id); + } else { + statement = connection.getPreparedStatement(PREPARED_STATEMENT.INSERT_ARTIFACT, Statement.RETURN_GENERATED_KEYS); + statement.clearParameters(); + this.nextArtifactId++; + statement.setLong(1, this.nextArtifactId); + statement.setLong(2, obj_id); + statement.setLong(3, artifact_obj_id); + statement.setLong(4, data_source_obj_id); + statement.setInt(5, artifact_type_id); + } + return statement; } - + BlackboardArtifact newBlackboardArtifact(int artifact_type_id, long obj_id, String artifactTypeName, String artifactDisplayName, long data_source_obj_id, CaseDbConnection connection) throws TskCoreException { acquireSingleUserCaseWriteLock(); - try { + try { long artifact_obj_id = addObject(obj_id, TskData.ObjectType.ARTIFACT.getObjectType(), connection); PreparedStatement statement = createInsertArtifactStatement(artifact_type_id, obj_id, artifact_obj_id, data_source_obj_id, connection); - + connection.executeUpdate(statement); try (ResultSet resultSet = statement.getGeneratedKeys()) { resultSet.next(); @@ -5142,11 +5149,11 @@ BlackboardArtifact newBlackboardArtifact(int artifact_type_id, long obj_id, Stri * @throws TskCoreException */ AnalysisResult newAnalysisResult(BlackboardArtifact.Type artifactType, long objId, Long dataSourceObjId, Score score, String conclusion, String configuration, String justification, CaseDbConnection connection) throws TskCoreException { - + if (artifactType.getCategory() != BlackboardArtifact.Category.ANALYSIS_RESULT) { - throw new TskCoreException(String.format("Artifact type (name = %s) is not of the AnalysisResult category. ", artifactType.getTypeName()) ); + throw new TskCoreException(String.format("Artifact type (name = %s) is not of the AnalysisResult category. ", artifactType.getTypeName())); } - + long artifactID; acquireSingleUserCaseWriteLock(); try { @@ -5168,7 +5175,7 @@ AnalysisResult newAnalysisResult(BlackboardArtifact.Type artifactType, long objI || !StringUtils.isBlank(conclusion) || !StringUtils.isBlank(configuration) || !StringUtils.isBlank(justification)) { - + PreparedStatement analysisResultsStatement; analysisResultsStatement = connection.getPreparedStatement(PREPARED_STATEMENT.INSERT_ANALYSIS_RESULT); @@ -5193,14 +5200,14 @@ AnalysisResult newAnalysisResult(BlackboardArtifact.Type artifactType, long objI } finally { closeResultSet(resultSet); } - + } catch (SQLException ex) { throw new TskCoreException("Error creating a analysis result", ex); } finally { releaseSingleUserCaseWriteLock(); } } - + /** * Checks if the content object has children. Note: this is generally more * efficient then preloading all children and checking if the set is empty, @@ -5900,7 +5907,8 @@ AbstractFile getAbstractFileById(long objectId, CaseDbConnection connection) thr /** * Get artifact from blackboard_artifacts table by its artifact_obj_id * - * @param id id of the artifact in blackboard_artifacts table (artifact_obj_id column) + * @param id id of the artifact in blackboard_artifacts table + * (artifact_obj_id column) * * @return Artifact object populated, or null if not found. * @@ -5908,7 +5916,7 @@ AbstractFile getAbstractFileById(long objectId, CaseDbConnection connection) thr * core and file could not be queried */ public BlackboardArtifact getArtifactById(long id) throws TskCoreException { - + CaseDbConnection connection = connections.getConnection(); acquireSingleUserCaseReadLock(); ResultSet rs = null; @@ -5917,12 +5925,12 @@ public BlackboardArtifact getArtifactById(long id) throws TskCoreException { PreparedStatement statement = connection.getPreparedStatement(PREPARED_STATEMENT.SELECT_ARTIFACT_TYPE_BY_ARTIFACT_OBJ_ID); statement.clearParameters(); statement.setLong(1, id); - + rs = connection.executeQuery(statement); if (!rs.next()) { throw new TskCoreException("Error getting artifacttype for artifact with artifact_obj_id = " + id); } - + // based on the artifact type category, get the analysis result or the data artifact BlackboardArtifact.Type artifactType = getArtifactType(rs.getInt("artifact_type_id")); switch (artifactType.getCategory()) { @@ -5933,7 +5941,7 @@ public BlackboardArtifact getArtifactById(long id) throws TskCoreException { default: throw new TskCoreException(String.format("Unknown artifact category for artifact with artifact_obj_id = %d, and artifact type = %s", id, artifactType.getTypeName())); } - + } catch (SQLException ex) { throw new TskCoreException("Error getting artifacts by artifact_obj_id, artifact_obj_id = " + id, ex); } finally { @@ -6296,13 +6304,12 @@ public VirtualDirectory addVirtualDirectory(long parentId, String directoryName, //extension, since this is not really file we just set it to null statement.setString(21, null); - + statement.setString(22, OsAccount.NO_OWNER_ID); // ownerUid statement.setNull(23, java.sql.Types.BIGINT); // osAccountObjId - + connection.executeUpdate(statement); - return new VirtualDirectory(this, newObjId, dataSourceObjectId, directoryName, dirType, metaType, dirFlag, metaFlags, null, null, FileKnown.UNKNOWN, parentPath); @@ -6435,7 +6442,7 @@ public LocalDirectory addLocalDirectory(long parentId, String directoryName, Cas statement.setString(22, OsAccount.NO_OWNER_ID); // ownerUid statement.setNull(23, java.sql.Types.BIGINT); // osAccountObjId - + connection.executeUpdate(statement); return new LocalDirectory(this, newObjId, dataSourceObjectId, directoryName, dirType, @@ -6470,7 +6477,7 @@ public LocalDirectory addLocalDirectory(long parentId, String directoryName, Cas public LocalFilesDataSource addLocalFilesDataSource(String deviceId, String rootDirectoryName, String timeZone, CaseDbTransaction transaction) throws TskCoreException { return addLocalFilesDataSource(deviceId, rootDirectoryName, timeZone, null, transaction); } - + /** * Adds a local/logical files and/or directories data source. * @@ -6497,7 +6504,7 @@ public LocalFilesDataSource addLocalFilesDataSource(String deviceId, String root Statement statement = null; try { CaseDbConnection connection = transaction.getConnection(); - + // Insert a row for the root virtual directory of the data source // into the tsk_objects table. long newObjId = addObject(0, TskData.ObjectType.ABSTRACTFILE.getObjectType(), connection); @@ -6505,8 +6512,8 @@ public LocalFilesDataSource addLocalFilesDataSource(String deviceId, String root // If no host was supplied, make one if (host == null) { host = getHostManager().newHost("LogicalFileSet_" + newObjId + " Host", transaction); - } - + } + // Insert a row for the virtual directory of the data source into // the data_source_info table. statement = connection.createStatement(); @@ -6587,8 +6594,8 @@ public Image addImage(TskData.TSK_IMG_TYPE_ENUM type, long sectorSize, long size String deviceId, CaseDbTransaction transaction) throws TskCoreException { return addImage(type, sectorSize, size, displayName, imagePaths, timezone, md5, sha1, sha256, deviceId, null, transaction); - } - + } + /** * Add an image to the database. * @@ -6646,7 +6653,7 @@ public Image addImage(TskData.TSK_IMG_TYPE_ENUM type, long sectorSize, long size preparedStatement.setLong(3, i); connection.executeUpdate(preparedStatement); } - + // Create the display name String name = displayName; if (name == null || name.isEmpty()) { @@ -6657,7 +6664,7 @@ public Image addImage(TskData.TSK_IMG_TYPE_ENUM type, long sectorSize, long size name = ""; } } - + // Create a host if needed if (host == null) { if (name.isEmpty()) { @@ -6912,7 +6919,7 @@ public FsContent addFileSystemFile(long dataSourceObjId, long fsObjId, TSK_FS_NAME_FLAG_ENUM dirFlag, short metaFlags, long size, long ctime, long crtime, long atime, long mtime, boolean isFile, Content parent) throws TskCoreException { - + CaseDbTransaction transaction = beginTransaction(); try { @@ -6921,7 +6928,7 @@ public FsContent addFileSystemFile(long dataSourceObjId, long fsObjId, ctime, crtime, atime, mtime, null, null, null, isFile, parent, OsAccount.NO_OWNER_ID, null, Collections.emptyList(), transaction); - + transaction.commit(); transaction = null; return fileSystemFile; @@ -6981,7 +6988,7 @@ public FsContent addFileSystemFile(long dataSourceObjId, long fsObjId, long ctime, long crtime, long atime, long mtime, String md5Hash, String sha256Hash, String mimeType, boolean isFile, Content parent, String ownerUid, - OsAccount osAccount, List<Attribute> fileAttributes, + OsAccount osAccount, List<Attribute> fileAttributes, CaseDbTransaction transaction) throws TskCoreException { TimelineManager timelineManager = getTimelineManager(); @@ -7005,7 +7012,7 @@ public FsContent addFileSystemFile(long dataSourceObjId, long fsObjId, } else { parentPath = "/"; } - + PreparedStatement statement = connection.getPreparedStatement(PREPARED_STATEMENT.INSERT_FILE_SYSTEM_FILE); statement.clearParameters(); statement.setLong(1, objectId); // obj_is @@ -7049,17 +7056,17 @@ public FsContent addFileSystemFile(long dataSourceObjId, long fsObjId, size, ctime, crtime, atime, mtime, md5Hash, sha256Hash, null, parentPath, null, parent.getId(), mimeType, null, extension, ownerUid, osAccountId); timelineManager.addEventsForNewFile(derivedFile, connection); - + for (Attribute fileAttribute : fileAttributes) { fileAttribute.setAttributeParentId(objectId); fileAttribute.setCaseDatabase(this); addFileAttribute(fileAttribute, connection); } - if(osAccount != null) { + if (osAccount != null) { osAccountManager.newOsAccountInstance(osAccount, dataSourceObjId, OsAccountInstance.OsAccountInstanceType.LAUNCHED, connection); } - + return new org.sleuthkit.datamodel.File(this, objectId, dataSourceObjId, fsObjId, attrType, attrId, fileName, metaAddr, metaSeq, dirType, metaType, dirFlag, metaFlags, @@ -7071,7 +7078,7 @@ public FsContent addFileSystemFile(long dataSourceObjId, long fsObjId, throw new TskCoreException(String.format("Failed to INSERT file system file %s (%s) with parent id %d in tsk_files table", fileName, parentPath, parent.getId()), ex); } finally { closeStatement(queryStatement); - } + } } /** @@ -7153,8 +7160,9 @@ public final List<LayoutFile> addLayoutFiles(Content parent, List<TskFileRange> * INSERT INTO tsk_files (obj_id, fs_obj_id, name, type, * has_path, dir_type, meta_type, dir_flags, meta_flags, size, * ctime, crtime, atime, mtime, md5, known, mime_type, - * parent_path, data_source_obj_id,extension, owner_uid, os_account_obj_id) VALUES (?, ?, ?, - * ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?, ?, ?) + * parent_path, data_source_obj_id,extension, owner_uid, + * os_account_obj_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, + * ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?, ?, ?) */ PreparedStatement prepStmt = connection.getPreparedStatement(PREPARED_STATEMENT.INSERT_FILE); prepStmt.clearParameters(); @@ -7181,10 +7189,10 @@ public final List<LayoutFile> addLayoutFiles(Content parent, List<TskFileRange> //extension, since this is not a FS file we just set it to null prepStmt.setString(21, null); - + prepStmt.setString(22, OsAccount.NO_OWNER_ID); // ownerUid prepStmt.setNull(23, java.sql.Types.BIGINT); // osAccountObjId - + connection.executeUpdate(prepStmt); /* @@ -7340,8 +7348,9 @@ public final List<LayoutFile> addCarvedFiles(CarvingResult carvingResult) throws * INSERT INTO tsk_files (obj_id, fs_obj_id, name, type, * has_path, dir_type, meta_type, dir_flags, meta_flags, size, * ctime, crtime, atime, mtime, md5, known, mime_type, - * parent_path, data_source_obj_id,extenion, owner_uid, os_account_obj_id) - * VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + * parent_path, data_source_obj_id,extenion, owner_uid, + * os_account_obj_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, + * ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) */ PreparedStatement prepStmt = connection.getPreparedStatement(PREPARED_STATEMENT.INSERT_FILE); prepStmt.clearParameters(); @@ -7370,10 +7379,10 @@ public final List<LayoutFile> addCarvedFiles(CarvingResult carvingResult) throws prepStmt.setString(19, parentPath); // parent path prepStmt.setLong(20, carvedFilesDir.getDataSourceObjectId()); // data_source_obj_id prepStmt.setString(21, extractExtension(carvedFile.getName())); //extension - + prepStmt.setString(22, OsAccount.NO_OWNER_ID); // ownerUid prepStmt.setNull(23, java.sql.Types.BIGINT); // osAccountObjId - + connection.executeUpdate(prepStmt); /* @@ -7552,7 +7561,7 @@ public DerivedFile addDerivedFile(String fileName, String localPath, final String extension = extractExtension(fileName); //extension statement.setString(21, extension); - + statement.setString(22, OsAccount.NO_OWNER_ID); // ownerUid statement.setNull(23, java.sql.Types.BIGINT); // osAccountObjId @@ -7875,7 +7884,7 @@ public LocalFile addLocalFile(String fileName, String localPath, parent.getId(), parentPath, dataSourceObjId, localPath, - encodingType, extension, + encodingType, extension, OsAccount.NO_OWNER_ID, OsAccount.NO_ACCOUNT); getTimelineManager().addEventsForNewFile(localFile, connection); return localFile; @@ -7988,8 +7997,8 @@ public LayoutFile addLayoutFile(String fileName, * tsk_files (obj_id, fs_obj_id, name, type, has_path, dir_type, * meta_type, dir_flags, meta_flags, size, ctime, crtime, atime, * mtime, md5, known, mime_type, parent_path, - * data_source_obj_id,extenion, owner_uid, os_account_obj_id) - * VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + * data_source_obj_id,extenion, owner_uid, os_account_obj_id) VALUES + * (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) */ PreparedStatement prepStmt = connection.getPreparedStatement(PREPARED_STATEMENT.INSERT_FILE); prepStmt.clearParameters(); @@ -8028,10 +8037,10 @@ public LayoutFile addLayoutFile(String fileName, prepStmt.setLong(20, parent.getDataSource().getId()); // data_source_obj_id prepStmt.setString(21, extractExtension(fileName)); //extension - + prepStmt.setString(22, OsAccount.NO_OWNER_ID); // ownerUid prepStmt.setNull(23, java.sql.Types.BIGINT); // osAccountObjId - + connection.executeUpdate(prepStmt); /* @@ -8257,16 +8266,16 @@ public List<AbstractFile> findAllFilesWhere(String sqlWhereClause) throws TskCor releaseSingleUserCaseReadLock(); } } - + /** * Find and return list of all (abstract) files matching the specific Where - * clause with the give parentId. You need to know the database schema to + * clause with the give parentId. You need to know the database schema to * use this, which is outlined on the * <a href="http://wiki.sleuthkit.org/index.php?title=SQLite_Database_v3_Schema">wiki</a>. * You should use enums from org.sleuthkit.datamodel.TskData to make the * queries easier to maintain and understand. - * - * @param parentId The parentId + * + * @param parentId The parentId * @param sqlWhereClause a SQL where clause appropriate for the desired * files (do not begin the WHERE clause with the word * WHERE!) @@ -8276,19 +8285,19 @@ public List<AbstractFile> findAllFilesWhere(String sqlWhereClause) throws TskCor * * @throws TskCoreException \ref query_database_page */ - public List<AbstractFile> findAllFilesInFolderWhere(long parentId, String sqlWhereClause) throws TskCoreException{ - String queryTemplate = "SELECT tsk_files.* FROM tsk_files JOIN tsk_objects ON tsk_objects.obj_id = tsk_files.obj_id WHERE par_obj_id = %d AND %s"; - - try(CaseDbConnection connection = connections.getConnection()) { + public List<AbstractFile> findAllFilesInFolderWhere(long parentId, String sqlWhereClause) throws TskCoreException { + String queryTemplate = "SELECT tsk_files.* FROM tsk_files JOIN tsk_objects ON tsk_objects.obj_id = tsk_files.obj_id WHERE par_obj_id = %d AND %s"; + + try (CaseDbConnection connection = connections.getConnection()) { acquireSingleUserCaseReadLock(); - + String query = String.format(queryTemplate, parentId, sqlWhereClause); - try(Statement s = connection.createStatement(); ResultSet rs = connection.executeQuery(s, query)) { + try (Statement s = connection.createStatement(); ResultSet rs = connection.executeQuery(s, query)) { return resultSetToAbstractFiles(rs, connection); - } catch(SQLException ex) { + } catch (SQLException ex) { throw new TskCoreException("SQLException thrown when calling 'SleuthkitCase.findAllFilesInFolderWhere(): " + query, ex); } - }finally { + } finally { releaseSingleUserCaseReadLock(); } } @@ -9112,8 +9121,8 @@ List<Long> getVolumeChildrenIds(Volume vol) throws TskCoreException { */ public Image addImageInfo(long deviceObjId, List<String> imageFilePaths, String timeZone) throws TskCoreException { return addImageInfo(deviceObjId, imageFilePaths, timeZone, null); - } - + } + /** * Adds an image to the case database. * @@ -9149,8 +9158,8 @@ public Map<Long, List<String>> getImagePaths() throws TskCoreException { ResultSet rs1 = null; try { s1 = connection.createStatement(); - rs1 = connection.executeQuery(s1, "SELECT tsk_image_info.obj_id, tsk_image_names.name FROM tsk_image_info " + - "LEFT JOIN tsk_image_names ON tsk_image_info.obj_id = tsk_image_names.obj_id"); //NON-NLS + rs1 = connection.executeQuery(s1, "SELECT tsk_image_info.obj_id, tsk_image_names.name FROM tsk_image_info " + + "LEFT JOIN tsk_image_names ON tsk_image_info.obj_id = tsk_image_names.obj_id"); //NON-NLS Map<Long, List<String>> imgPaths = new LinkedHashMap<Long, List<String>>(); while (rs1.next()) { long obj_id = rs1.getLong("obj_id"); //NON-NLS @@ -9166,7 +9175,7 @@ public Map<Long, List<String>> getImagePaths() throws TskCoreException { if (name != null) { imagePaths.add(name); } - } + } } return imgPaths; } catch (SQLException ex) { @@ -9376,12 +9385,12 @@ private List<AbstractFile> resultSetToAbstractFiles(ResultSet rs, CaseDbConnecti if (parentPath == null) { parentPath = "/"; //NON-NLS } - + Long osAccountObjId = rs.getLong("os_account_obj_id"); if (rs.wasNull()) { osAccountObjId = null; } - + LayoutFile lf = new LayoutFile(this, rs.getLong("obj_id"), //NON-NLS rs.getLong("data_source_obj_id"), @@ -9391,9 +9400,9 @@ private List<AbstractFile> resultSetToAbstractFiles(ResultSet rs, CaseDbConnecti TSK_FS_NAME_FLAG_ENUM.valueOf(rs.getShort("dir_flags")), rs.getShort("meta_flags"), //NON-NLS rs.getLong("size"), //NON-NLS rs.getLong("ctime"), rs.getLong("crtime"), rs.getLong("atime"), rs.getLong("mtime"), //NON-NLS - rs.getString("md5"), rs.getString("sha256"), FileKnown.valueOf(rs.getByte("known")), parentPath, - rs.getString("mime_type"), - rs.getString("owner_uid"), osAccountObjId ); //NON-NLS + rs.getString("md5"), rs.getString("sha256"), FileKnown.valueOf(rs.getByte("known")), parentPath, + rs.getString("mime_type"), + rs.getString("owner_uid"), osAccountObjId); //NON-NLS results.add(lf); } else if (type == TSK_DB_FILES_TYPE_ENUM.DERIVED.getFileType()) { final DerivedFile df; @@ -9432,7 +9441,7 @@ org.sleuthkit.datamodel.File file(ResultSet rs, FileSystem fs) throws SQLExcepti if (rs.wasNull()) { osAccountObjId = null; } - + org.sleuthkit.datamodel.File f = new org.sleuthkit.datamodel.File(this, rs.getLong("obj_id"), //NON-NLS rs.getLong("data_source_obj_id"), rs.getLong("fs_obj_id"), //NON-NLS TskData.TSK_FS_ATTR_TYPE_ENUM.valueOf(rs.getShort("attr_type")), //NON-NLS @@ -9465,7 +9474,7 @@ Directory directory(ResultSet rs, FileSystem fs) throws SQLException { if (rs.wasNull()) { osAccountObjId = null; } - + Directory dir = new Directory(this, rs.getLong("obj_id"), rs.getLong("data_source_obj_id"), rs.getLong("fs_obj_id"), //NON-NLS TskData.TSK_FS_ATTR_TYPE_ENUM.valueOf(rs.getShort("attr_type")), //NON-NLS rs.getInt("attr_id"), rs.getString("name"), rs.getLong("meta_addr"), rs.getInt("meta_seq"), //NON-NLS @@ -9613,12 +9622,12 @@ private DerivedFile derivedFile(ResultSet rs, CaseDbConnection connection, long if (parentPath == null) { parentPath = ""; } - + Long osAccountObjId = rs.getLong("os_account_obj_id"); if (rs.wasNull()) { osAccountObjId = null; } - + final DerivedFile df = new DerivedFile(this, objId, rs.getLong("data_source_obj_id"), rs.getString("name"), //NON-NLS TSK_FS_NAME_TYPE_ENUM.valueOf(rs.getShort("dir_type")), //NON-NLS @@ -9628,7 +9637,7 @@ private DerivedFile derivedFile(ResultSet rs, CaseDbConnection connection, long rs.getLong("ctime"), rs.getLong("crtime"), rs.getLong("atime"), rs.getLong("mtime"), //NON-NLS rs.getString("md5"), rs.getString("sha256"), FileKnown.valueOf(rs.getByte("known")), //NON-NLS parentPath, localPath, parentId, rs.getString("mime_type"), - encodingType, rs.getString("extension"), + encodingType, rs.getString("extension"), rs.getString("owner_uid"), osAccountObjId); return df; } @@ -9677,7 +9686,7 @@ private LocalFile localFile(ResultSet rs, CaseDbConnection connection, long pare if (rs.wasNull()) { osAccountObjId = null; } - + LocalFile file = new LocalFile(this, objId, rs.getString("name"), //NON-NLS TSK_DB_FILES_TYPE_ENUM.valueOf(rs.getShort("type")), //NON-NLS TSK_FS_NAME_TYPE_ENUM.valueOf(rs.getShort("dir_type")), //NON-NLS @@ -9719,7 +9728,7 @@ org.sleuthkit.datamodel.SlackFile slackFile(ResultSet rs, FileSystem fs) throws rs.getLong("ctime"), rs.getLong("crtime"), rs.getLong("atime"), rs.getLong("mtime"), //NON-NLS (short) rs.getInt("mode"), rs.getInt("uid"), rs.getInt("gid"), //NON-NLS rs.getString("md5"), rs.getString("sha256"), FileKnown.valueOf(rs.getByte("known")), //NON-NLS - rs.getString("parent_path"), rs.getString("mime_type"), rs.getString("extension"), + rs.getString("parent_path"), rs.getString("mime_type"), rs.getString("extension"), rs.getString("owner_uid"), osAccountObjId); //NON-NLS f.setFileSystem(fs); return f; @@ -9786,7 +9795,7 @@ List<Content> fileChildren(ResultSet rs, CaseDbConnection connection, long paren rs.getLong("size"), rs.getLong("ctime"), rs.getLong("crtime"), rs.getLong("atime"), rs.getLong("mtime"), rs.getString("md5"), rs.getString("sha256"), - FileKnown.valueOf(rs.getByte("known")), parentPath, rs.getString("mime_type"), + FileKnown.valueOf(rs.getByte("known")), parentPath, rs.getString("mime_type"), rs.getString("owner_uid"), osAccountObjId); children.add(lf); break; @@ -9911,9 +9920,10 @@ CaseDbConnection getConnection() throws TskCoreException { /** * Gets the string used to identify this case in the JNI cache. - * + * * @return The string for this case - * @throws TskCoreException + * + * @throws TskCoreException */ String getCaseHandleIdentifier() { return caseHandleIdentifier; @@ -10044,8 +10054,6 @@ void setImageName(String name, long objId) throws TskCoreException { } } - - /** * Updates the image's total size and sector size.This function may be used * to update the sizes after the image was created. @@ -10071,7 +10079,7 @@ void setImageSizes(Image image, long totalSize, long sectorSize) throws TskCoreE preparedStatement.setLong(3, image.getId()); connection.executeUpdate(preparedStatement); } catch (SQLException ex) { - throw new TskCoreException(String.format("Error updating image sizes to %d and sector size to %d for object ID %d ",totalSize, sectorSize, image.getId()), ex); + throw new TskCoreException(String.format("Error updating image sizes to %d and sector size to %d for object ID %d ", totalSize, sectorSize, image.getId()), ex); } finally { releaseSingleUserCaseWriteLock(); } @@ -10106,8 +10114,8 @@ public void setFileMIMEType(AbstractFile file, String mimeType) throws TskCoreEx } /** - * Sets the unalloc meta flags for the file in the case database, and updates - * the meta flags in given file object. Also updates the dir flag to + * Sets the unalloc meta flags for the file in the case database, and + * updates the meta flags in given file object. Also updates the dir flag to * unalloc. * * @param file A file. @@ -10116,16 +10124,16 @@ public void setFileMIMEType(AbstractFile file, String mimeType) throws TskCoreEx * @throws TskCoreException If there is an error updating the case database. */ public void setFileUnalloc(AbstractFile file) throws TskCoreException { - + // get the flags, reset the ALLOC flag, and set the UNALLOC flag short metaFlag = file.getMetaFlagsAsInt(); Set<TSK_FS_META_FLAG_ENUM> metaFlagAsSet = TSK_FS_META_FLAG_ENUM.valuesOf(metaFlag); metaFlagAsSet.remove(TSK_FS_META_FLAG_ENUM.ALLOC); metaFlagAsSet.add(TSK_FS_META_FLAG_ENUM.UNALLOC); - + short newMetaFlgs = TSK_FS_META_FLAG_ENUM.toInt(metaFlagAsSet); short newDirFlags = TSK_FS_NAME_FLAG_ENUM.UNALLOC.getValue(); - + CaseDbConnection connection = connections.getConnection(); Statement statement = null; ResultSet rs = null; @@ -10133,12 +10141,12 @@ public void setFileUnalloc(AbstractFile file) throws TskCoreException { try { statement = connection.createStatement(); connection.executeUpdate(statement, String.format("UPDATE tsk_files SET meta_flags = '%d', dir_flags = '%d' WHERE obj_id = %d", newMetaFlgs, newDirFlags, file.getId())); - + file.removeMetaFlag(TSK_FS_META_FLAG_ENUM.ALLOC); file.setMetaFlag(TSK_FS_META_FLAG_ENUM.UNALLOC); - + file.setDirFlag(TSK_FS_NAME_FLAG_ENUM.UNALLOC); - + } catch (SQLException ex) { throw new TskCoreException(String.format("Error setting unalloc meta flag for file (obj_id = %s)", file.getId()), ex); } finally { @@ -10148,7 +10156,7 @@ public void setFileUnalloc(AbstractFile file) throws TskCoreException { releaseSingleUserCaseWriteLock(); } } - + /** * Store the md5Hash for the file in the database * @@ -10399,7 +10407,6 @@ void setAcquisitionDetails(DataSource datasource, String details) throws TskCore } } - /** * Sets the acquisition tool details such as its name, version number and * any settings used during the acquisition to acquire data. @@ -10434,12 +10441,12 @@ void setAcquisitionToolDetails(DataSource datasource, String name, String versio /** * Set the acquisition details in the data_source_info table. - * + * * @param dataSourceId The data source ID. * @param details The acquisition details. * @param trans The current transaction. - * - * @throws TskCoreException + * + * @throws TskCoreException */ void setAcquisitionDetails(long dataSourceId, String details, CaseDbTransaction trans) throws TskCoreException { acquireSingleUserCaseWriteLock(); @@ -10456,7 +10463,7 @@ void setAcquisitionDetails(long dataSourceId, String details, CaseDbTransaction releaseSingleUserCaseWriteLock(); } } - + /** * Get the acquisition details from the data_source_info table * @@ -10491,12 +10498,14 @@ String getAcquisitionDetails(DataSource datasource) throws TskCoreException { } /** - * Get String value from the provided column from data_source_info table. - * + * Get String value from the provided column from data_source_info table. + * * @param datasource The datasource - * @param columnName The column from which the data should be returned - * @return String value from the column - * @throws TskCoreException + * @param columnName The column from which the data should be returned + * + * @return String value from the column + * + * @throws TskCoreException */ String getDataSourceInfoString(DataSource datasource, String columnName) throws TskCoreException { long id = datasource.getId(); @@ -10522,13 +10531,14 @@ String getDataSourceInfoString(DataSource datasource, String columnName) throws } } - /** * Get Long value from the provided column from data_source_info table. * * @param datasource The datasource * @param columnName The column from which the data should be returned + * * @return Long value from the column + * * @throws TskCoreException */ Long getDataSourceInfoLong(DataSource datasource, String columnName) throws TskCoreException { @@ -10916,7 +10926,7 @@ public TagName addOrUpdateTagName(String displayName, String description, TagNam resultSet.next(); return new TagName(resultSet.getLong("tag_name_id"), displayName, description, color, knownStatus, resultSet.getLong("tag_set_id"), resultSet.getInt("rank")); - + } catch (SQLException ex) { throw new TskCoreException("Error adding row for " + displayName + " tag name to tag_names table", ex); } finally { @@ -12220,7 +12230,6 @@ private enum PREPARED_STATEMENT { SELECT_FILE_BY_ID("SELECT * FROM tsk_files WHERE obj_id = ? LIMIT 1"), //NON-NLS SELECT_ARTIFACT_BY_ARTIFACT_OBJ_ID("SELECT * FROM blackboard_artifacts WHERE artifact_obj_id = ? LIMIT 1"), SELECT_ARTIFACT_TYPE_BY_ARTIFACT_OBJ_ID("SELECT artifact_type_id FROM blackboard_artifacts WHERE artifact_obj_id = ? LIMIT 1"), - SELECT_ARTIFACT_BY_ARTIFACT_ID("SELECT * FROM blackboard_artifacts WHERE artifact_id = ? LIMIT 1"), INSERT_ARTIFACT("INSERT INTO blackboard_artifacts (artifact_id, obj_id, artifact_obj_id, data_source_obj_id, artifact_type_id, review_status_id) " //NON-NLS + "VALUES (?, ?, ?, ?, ?," + BlackboardArtifact.ReviewStatus.UNDECIDED.getID() + ")"), //NON-NLS @@ -12389,7 +12398,7 @@ private enum PREPARED_STATEMENT { + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"), SELECT_TAG_NAME_BY_ID("SELECT * FROM tag_names where tag_name_id = ?"), SELECT_TAG_NAME_BY_NAME("SELECT * FROM tag_names where display_name = ?"); - + private final String sql; private PREPARED_STATEMENT(String sql) { @@ -12580,14 +12589,15 @@ public void execute() throws SQLException { } /** - * Obtains a write lock on tsk_aggregate_score table. - * Only PostgreSQL is supported. - * - * NOTE: We run into deadlock risks when we start to lock - * multiple tables. If that need arrises, consider changing - * to opportunistic locking and single-step transactions. - */ + * Obtains a write lock on tsk_aggregate_score table. Only PostgreSQL is + * supported. + * + * NOTE: We run into deadlock risks when we start to lock multiple + * tables. If that need arrises, consider changing to opportunistic + * locking and single-step transactions. + */ private class AggregateScoreTablePostgreSQLWriteLock implements DbCommand { + private final Connection connection; AggregateScoreTablePostgreSQLWriteLock(Connection connection) { @@ -12598,7 +12608,7 @@ private class AggregateScoreTablePostgreSQLWriteLock implements DbCommand { public void execute() throws SQLException { PreparedStatement preparedStatement = connection.prepareStatement("LOCK TABLE ONLY tsk_aggregate_score in SHARE ROW EXCLUSIVE MODE"); preparedStatement.execute(); - + } } @@ -12765,17 +12775,17 @@ PreparedStatement getPreparedStatement(PREPARED_STATEMENT statementKey, int gene } return statement; } - + /** - * Get a prepared statement for the given input. - * Will cache the prepared statement for this connection. - * - * @param sqlStatement The SQL for the prepared statement. - * @param generateKeys The generate keys enum from Statement. - * + * Get a prepared statement for the given input. Will cache the prepared + * statement for this connection. + * + * @param sqlStatement The SQL for the prepared statement. + * @param generateKeys The generate keys enum from Statement. + * * @return The prepared statement - * - * @throws SQLException + * + * @throws SQLException */ PreparedStatement getPreparedStatement(String sqlStatement, int generateKeys) throws SQLException { PreparedStatement statement; @@ -12846,14 +12856,14 @@ void rollbackTransactionWithThrow() throws SQLException { connection.setAutoCommit(true); } } - + /** * Blocks until a write lock can be obtained on the tsk_aggregate_score - * table. Used to ensure only one thread/client is updating the score - * at a time. Can be called multiple times on the same transaction. - * + * table. Used to ensure only one thread/client is updating the score at + * a time. Can be called multiple times on the same transaction. + * * @throws SQLException - * @throws TskCoreException + * @throws TskCoreException */ void getAggregateScoreTableWriteLock() throws SQLException, TskCoreException { switch (getDatabaseType()) { @@ -12911,10 +12921,10 @@ void executeUpdate(PreparedStatement statement) throws SQLException { @Override public void close() { try { - for (PreparedStatement stmt:preparedStatements.values()) { + for (PreparedStatement stmt : preparedStatements.values()) { closeStatement(stmt); } - for (PreparedStatement stmt:adHocPreparedStatements.values()) { + for (PreparedStatement stmt : adHocPreparedStatements.values()) { closeStatement(stmt); } connection.close(); @@ -13031,12 +13041,12 @@ void executeCommand(DbCommand command) throws SQLException { * Transaction interface because that sort of flexibility and its associated * complexity is not needed. Also, TskCoreExceptions are thrown to be * consistent with the outer SleuthkitCase class. - * - * This class will automatically acquire the single user case write lock - * and release it when the transaction is closed. Otherwise we risk deadlock + * + * This class will automatically acquire the single user case write lock and + * release it when the transaction is closed. Otherwise we risk deadlock * because this transaction can lock up SQLite and make it "busy" and - * another thread may get a write lock to the DB, but not - * be able to do anything because the DB is busy. + * another thread may get a write lock to the DB, but not be able to do + * anything because the DB is busy. */ public static final class CaseDbTransaction { @@ -13046,16 +13056,16 @@ public static final class CaseDbTransaction { // A collection of object score changes that ocuured as part of this transaction. // When the transaction is committed, events are fired to notify any listeners. // Score changes are stored as a map keyed by objId to prevent duplicates. - private Map<Long, ScoreChange> scoreChangeMap = new HashMap<>(); + private Map<Long, ScoreChange> scoreChangeMap = new HashMap<>(); private List<Host> hostsAdded = new ArrayList<>(); private List<OsAccount> accountsChanged = new ArrayList<>(); private List<OsAccount> accountsAdded = new ArrayList<>(); private List<Long> deletedOsAccountObjectIds = new ArrayList<>(); private List<Long> deletedResultObjectIds = new ArrayList<>(); - + private static Set<Long> threadsWithOpenTransaction = new HashSet<>(); private static final Object threadsWithOpenTransactionLock = new Object(); - + private CaseDbTransaction(SleuthkitCase sleuthkitCase, CaseDbConnection connection) throws TskCoreException { this.connection = connection; this.sleuthkitCase = sleuthkitCase; @@ -13081,10 +13091,9 @@ CaseDbConnection getConnection() { return this.connection; } - /** * Saves a score change done as part of the transaction. - * + * * @param scoreChange Score change. */ void registerScoreChange(ScoreChange scoreChange) { @@ -13093,62 +13102,70 @@ void registerScoreChange(ScoreChange scoreChange) { /** * Saves a host that has been added as a part of this transaction. + * * @param host The host. */ void registerAddedHost(Host host) { if (host != null) { - this.hostsAdded.add(host); + this.hostsAdded.add(host); } } - + /** * Saves an account that has been updated as a part of this transaction. + * * @param account The account. - */ + */ void registerChangedOsAccount(OsAccount account) { if (account != null) { accountsChanged.add(account); } } - + /** * Saves an account that has been deleted as a part of this transaction. + * * @param osAccountObjId The account. - */ + */ void registerDeletedOsAccount(long osAccountObjId) { deletedOsAccountObjectIds.add(osAccountObjId); - } - + } + /** * Saves an account that has been added as a part of this transaction. + * * @param account The account. - */ + */ void registerAddedOsAccount(OsAccount account) { if (account != null) { accountsAdded.add(account); } } - + /** - * Saves an analysis result that has been deleted as a part of this transaction. - * + * Saves an analysis result that has been deleted as a part of this + * transaction. + * * @param result Deleted result. */ void registerDeletedAnalysisResult(long analysisResultObjId) { this.deletedResultObjectIds.add(analysisResultObjId); } + /** * Check if the given thread has an open transaction. - * + * * @param threadId Thread id to check for. - * - * @return True if the given thread has an open transaction, false otherwise. + * + * @return True if the given thread has an open transaction, false + * otherwise. */ private static boolean hasOpenTransaction(long threadId) { synchronized (threadsWithOpenTransactionLock) { return threadsWithOpenTransaction.contains(threadId); } } + /** * Commits the transaction on the case database that was begun when this * object was constructed. @@ -13162,7 +13179,7 @@ public void commit() throws TskCoreException { throw new TskCoreException("Failed to commit transaction on case database", ex); } finally { close(); - + if (!scoreChangeMap.isEmpty()) { // Group the score changes by data source id Map<Long, List<ScoreChange>> changesByDataSource = scoreChangeMap.values().stream() @@ -13173,7 +13190,7 @@ public void commit() throws TskCoreException { sleuthkitCase.fireTSKEvent(new AggregateScoresChangedEvent(entry.getKey(), ImmutableSet.copyOf(entry.getValue()))); } } - + // Fire events for any new or changed objects if (!hostsAdded.isEmpty()) { sleuthkitCase.fireTSKEvent(new TskEvent.HostsAddedTskEvent(hostsAdded)); @@ -13843,7 +13860,7 @@ public DerivedFile addDerivedFile(String fileName, String localPath, isFile, parentFile, rederiveDetails, toolName, toolVersion, otherDetails, TskData.EncodingType.NONE); } - + /** * Adds a local/logical file to the case database. The database operations * are done within a caller-managed transaction; the caller is responsible @@ -13870,7 +13887,7 @@ public DerivedFile addDerivedFile(String fileName, String localPath, * * @throws TskCoreException if there is an error completing a case database * operation. - * + * * @deprecated Use the newer version with explicit sha256 parameter */ @Deprecated @@ -13878,8 +13895,8 @@ public LocalFile addLocalFile(String fileName, String localPath, long size, long ctime, long crtime, long atime, long mtime, String md5, FileKnown known, String mimeType, boolean isFile, TskData.EncodingType encodingType, - Content parent, CaseDbTransaction transaction) throws TskCoreException { - + Content parent, CaseDbTransaction transaction) throws TskCoreException { + return addLocalFile(fileName, localPath, size, ctime, crtime, atime, mtime, md5, null, known, mimeType, isFile, encodingType, parent, transaction);