From 2b01ea24fe1fc43391c115da5297d936e17ac89f Mon Sep 17 00:00:00 2001 From: apriestman <apriestman@basistech.com> Date: Tue, 18 Feb 2020 13:26:29 -0500 Subject: [PATCH] Get SleuthkitCase version through JNI. --- bindings/java/jni/dataModel_SleuthkitJNI.cpp | 9 +++++++++ bindings/java/jni/dataModel_SleuthkitJNI.h | 8 ++++++++ .../datamodel/CaseDatabaseFactory.java | 11 +++++------ .../org/sleuthkit/datamodel/SleuthkitJNI.java | 19 +++++++++++++++++++ 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/bindings/java/jni/dataModel_SleuthkitJNI.cpp b/bindings/java/jni/dataModel_SleuthkitJNI.cpp index daf05a52b..9572b510c 100644 --- a/bindings/java/jni/dataModel_SleuthkitJNI.cpp +++ b/bindings/java/jni/dataModel_SleuthkitJNI.cpp @@ -2315,6 +2315,15 @@ JNIEXPORT jboolean JNICALL Java_org_sleuthkit_datamodel_SleuthkitJNI_isImageSupp return (jboolean) result; } +/* +* Returns the current Sleuthkit version as a long +* @return the current version +*/ +JNIEXPORT jlong JNICALL Java_org_sleuthkit_datamodel_SleuthkitJNI_getSleuthkitVersionNat +(JNIEnv * env, jclass obj) { + return (jlong)TSK_VERSION_NUM; +} + /* * Finish the image being created by image writer. diff --git a/bindings/java/jni/dataModel_SleuthkitJNI.h b/bindings/java/jni/dataModel_SleuthkitJNI.h index a724200b0..17bbaa665 100644 --- a/bindings/java/jni/dataModel_SleuthkitJNI.h +++ b/bindings/java/jni/dataModel_SleuthkitJNI.h @@ -439,6 +439,14 @@ JNIEXPORT jstring JNICALL Java_org_sleuthkit_datamodel_SleuthkitJNI_getCurDirNat JNIEXPORT jboolean JNICALL Java_org_sleuthkit_datamodel_SleuthkitJNI_isImageSupportedNat (JNIEnv *, jclass, jstring); +/* + * Class: org_sleuthkit_datamodel_SleuthkitJNI + * Method: getSleuthkitVersionNat + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_org_sleuthkit_datamodel_SleuthkitJNI_getSleuthkitVersionNat + (JNIEnv *, jclass); + /* * Class: org_sleuthkit_datamodel_SleuthkitJNI * Method: finishImageWriterNat diff --git a/bindings/java/src/org/sleuthkit/datamodel/CaseDatabaseFactory.java b/bindings/java/src/org/sleuthkit/datamodel/CaseDatabaseFactory.java index 5adb2b2fd..db96a7f67 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/CaseDatabaseFactory.java +++ b/bindings/java/src/org/sleuthkit/datamodel/CaseDatabaseFactory.java @@ -30,7 +30,7 @@ import org.sleuthkit.datamodel.SQLHelper.SQLiteHelper; /** - * + * Creates a SQLite or PostgreSQL case database. */ class CaseDatabaseFactory { private static final Logger logger = Logger.getLogger(CaseDatabaseFactory.class.getName()); @@ -125,7 +125,7 @@ private void initializeSchema() throws TskCoreException { */ private void addDbInfo(Connection conn) throws TskCoreException { CaseDbSchemaVersionNumber version = SleuthkitCase.CURRENT_DB_SCHEMA_VERSION; - long tskVersionNum = 0; // This is the current version of TSK (not the DB schema version) + long tskVersionNum = SleuthkitJNI.getSleuthkitVersion(); // This is the current version of TSK try (Statement stmt = conn.createStatement()) { stmt.execute("CREATE TABLE tsk_db_info (schema_ver INTEGER, tsk_ver INTEGER, schema_minor_ver INTEGER)"); @@ -552,8 +552,8 @@ private class SQLiteDbCreationHelper extends DbCreationHelper { @Override void createDatabase() throws TskCoreException { - // SQLite doesn't need to explicitly create the case database, so - // just check that the folder exists and the database does not + // SQLite doesn't need to explicitly create the case database but we will set the + // chunk size here after a check that the folder exists and the database does not File dbFile = new File(dbPath); if (dbFile.exists()) { throw new TskCoreException("Case database already exists : " + dbPath); @@ -584,7 +584,6 @@ Connection getConnection() { @Override void performPreInitialization(Connection conn) throws TskCoreException { - try (Statement stmt = conn.createStatement()) { stmt.execute(PRAGMA_SYNC_OFF); stmt.execute(PRAGMA_READ_UNCOMMITTED_TRUE); @@ -594,7 +593,7 @@ void performPreInitialization(Connection conn) throws TskCoreException { } catch (SQLException ex) { throw new TskCoreException("Error setting pragmas", ex); } - + /* TODO? Implement this C code // increase the DB by 1MB at a time -- supposed to help performance when populating int chunkSize = 1024 * 1024; diff --git a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitJNI.java b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitJNI.java index 344c28e2f..615752834 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitJNI.java +++ b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitJNI.java @@ -1734,6 +1734,23 @@ public static long findDeviceSize(String devPath) throws TskCoreException { public static boolean isImageSupported(String imagePath) { return isImageSupportedNat(imagePath); } + + /** Get the version of the Sleuthkit code in number form. + * Upper byte is A, next is B, and next byte is C in version A.B.C. + * Lowest byte is 0xff, except in beta releases, in which case it + * increments from 1. Nightly snapshots will have upper byte as + * 0xff and next bytes with year, month, and date, respectively. + * Note that you will not be able to differentiate between snapshots + * from the trunk or branches with this method... + * For example, 3.1.2 would be stored as 0x030102FF. + * 3.1.2b1 would be 0x03010201. Snapshot from Jan 2, 2003 would be + * 0xFF030102. + * + * @return the current Sleuthkit version + */ + static long getSleuthkitVersion() { + return getSleuthkitVersionNat(); + } /** * Get a read lock for the C++ layer. Do not get this lock after obtaining @@ -1982,6 +1999,8 @@ public static long openFile(long fsHandle, long fileId, TSK_FS_ATTR_TYPE_ENUM at private static native String getCurDirNat(long process); private static native boolean isImageSupportedNat(String imagePath); + + private static native long getSleuthkitVersionNat(); private static native int finishImageWriterNat(long a_img_info); -- GitLab