From 7d355fcaa3d87210987eb168830c9d6b19fe9c8c Mon Sep 17 00:00:00 2001 From: Ann Priestman <apriestman@basistech.com> Date: Tue, 8 Jan 2019 14:05:53 -0500 Subject: [PATCH] acquisition_details field in data_source_info can be set and retrieved --- .../org/sleuthkit/datamodel/DataSource.java | 17 +++++ .../src/org/sleuthkit/datamodel/Image.java | 24 +++++++ .../datamodel/LocalFilesDataSource.java | 24 +++++++ .../sleuthkit/datamodel/SleuthkitCase.java | 62 +++++++++++++++++++ 4 files changed, 127 insertions(+) diff --git a/bindings/java/src/org/sleuthkit/datamodel/DataSource.java b/bindings/java/src/org/sleuthkit/datamodel/DataSource.java index 25f09d0e1..f2633a117 100755 --- a/bindings/java/src/org/sleuthkit/datamodel/DataSource.java +++ b/bindings/java/src/org/sleuthkit/datamodel/DataSource.java @@ -66,4 +66,21 @@ public interface DataSource extends Content { */ long getContentSize(SleuthkitCase sleuthkitCase) throws TskCoreException; + /** + * Sets the acquisition details field in the case database. + * + * @param details The acquisition details + * + * @throws TskCoreException Thrown if the data can not be written + */ + void setAcquisitionDetails(String details) throws TskCoreException; + + /** + * Gets the acquisition details field from the case database. + * + * @return The acquisition details + * + * @throws TskCoreException Thrown if the data can not be read + */ + String getAcquisitionDetails() throws TskCoreException; } diff --git a/bindings/java/src/org/sleuthkit/datamodel/Image.java b/bindings/java/src/org/sleuthkit/datamodel/Image.java index d5a54b720..203864589 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/Image.java +++ b/bindings/java/src/org/sleuthkit/datamodel/Image.java @@ -501,6 +501,30 @@ public long getContentSize(SleuthkitCase sleuthkitCase) throws TskCoreException return contentSize; } + + /** + * Sets the acquisition details field in the case database. + * + * @param details The acquisition details + * + * @throws TskCoreException Thrown if the data can not be written + */ + @Override + public void setAcquisitionDetails(String details) throws TskCoreException { + getSleuthkitCase().setAcquisitionDetails(this, details); + } + + /** + * Gets the acquisition details field from the case database. + * + * @return The acquisition details + * + * @throws TskCoreException Thrown if the data can not be read + */ + @Override + public String getAcquisitionDetails() throws TskCoreException { + return getSleuthkitCase().getAcquisitionDetails(this); + } /** * Close a ResultSet. diff --git a/bindings/java/src/org/sleuthkit/datamodel/LocalFilesDataSource.java b/bindings/java/src/org/sleuthkit/datamodel/LocalFilesDataSource.java index ed0a78b5e..1d2e25eed 100755 --- a/bindings/java/src/org/sleuthkit/datamodel/LocalFilesDataSource.java +++ b/bindings/java/src/org/sleuthkit/datamodel/LocalFilesDataSource.java @@ -179,6 +179,30 @@ static long getContentSize(SleuthkitCase sleuthkitCase, long dataSourceObjId) th return contentSize; } + + /** + * Sets the acquisition details field in the case database. + * + * @param details The acquisition details + * + * @throws TskCoreException Thrown if the data can not be written + */ + @Override + public void setAcquisitionDetails(String details) throws TskCoreException { + getSleuthkitCase().setAcquisitionDetails(this, details); + } + + /** + * Gets the acquisition details field from the case database. + * + * @return The acquisition details + * + * @throws TskCoreException Thrown if the data can not be read + */ + @Override + public String getAcquisitionDetails() throws TskCoreException { + return getSleuthkitCase().getAcquisitionDetails(this); + } /** * Close a ResultSet. diff --git a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java index 6e6bcd2cf..847eaf467 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java +++ b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java @@ -7908,6 +7908,66 @@ String getSha256ImageHash(Image img) throws TskCoreException { releaseSingleUserCaseReadLock(); } } + + /** + * Set the acquisition details in the data_source_info table + * + * @param datasource The data source + * @param details The acquisition details + * + * @throws TskCoreException Thrown if the database write fails + */ + void setAcquisitionDetails(DataSource datasource, String details) throws TskCoreException { + + long id = datasource.getId(); + CaseDbConnection connection = connections.getConnection(); + acquireSingleUserCaseWriteLock(); + try { + PreparedStatement statement = connection.getPreparedStatement(PREPARED_STATEMENT.UPDATE_ACQUISITION_DETAILS); + statement.clearParameters(); + statement.setString(1, details); + statement.setLong(2, id); + connection.executeUpdate(statement); + } catch (SQLException ex) { + throw new TskCoreException("Error setting acquisition details", ex); + } finally { + connection.close(); + releaseSingleUserCaseWriteLock(); + } + } + + /** + * Get the acquisition details from the data_source_info table + * + * @param datasource The data source + * + * @return The acquisition details + * + * @throws TskCoreException Thrown if the database read fails + */ + String getAcquisitionDetails(DataSource datasource) throws TskCoreException { + long id = datasource.getId(); + CaseDbConnection connection = connections.getConnection(); + acquireSingleUserCaseReadLock(); + ResultSet rs = null; + String hash = ""; + try { + PreparedStatement statement = connection.getPreparedStatement(PREPARED_STATEMENT.SELECT_ACQUISITION_DETAILS); + statement.clearParameters(); + statement.setLong(1, id); + rs = connection.executeQuery(statement); + if (rs.next()) { + hash = rs.getString("acquisition_details"); + } + return hash; + } catch (SQLException ex) { + throw new TskCoreException("Error setting acquisition details", ex); + } finally { + closeResultSet(rs); + connection.close(); + releaseSingleUserCaseReadLock(); + } + } /** * Set the review status of the given artifact to newStatus @@ -9585,6 +9645,8 @@ private enum PREPARED_STATEMENT { SELECT_IMAGE_MD5("SELECT md5 FROM tsk_image_info WHERE obj_id = ?"), //NON-NLS SELECT_IMAGE_SHA1("SELECT sha1 FROM tsk_image_info WHERE obj_id = ?"), //NON-NLS SELECT_IMAGE_SHA256("SELECT sha256 FROM tsk_image_info WHERE obj_id = ?"), //NON-NLS + UPDATE_ACQUISITION_DETAILS("UPDATE data_source_info SET acquisition_details = ? WHERE obj_id = ?"), //NON-NLS + SELECT_ACQUISITION_DETAILS("SELECT acquisition_details FROM data_source_info WHERE obj_id = ?"), //NON-NLS SELECT_LOCAL_PATH_FOR_FILE("SELECT path FROM tsk_files_path WHERE obj_id = ?"), //NON-NLS SELECT_ENCODING_FOR_FILE("SELECT encoding_type FROM tsk_files_path WHERE obj_id = ?"), // NON-NLS SELECT_LOCAL_PATH_AND_ENCODING_FOR_FILE("SELECT path, encoding_type FROM tsk_files_path WHERE obj_id = ?"), // NON_NLS -- GitLab