diff --git a/.gitignore b/.gitignore index 71c02577a1097813e41de7d0b937c72ef264bbf2..d5205772823da74734ee01b901dcf31baab67b41 100755 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,10 @@ /bindings/java/dist /bindings/java/test/output /bindings/java/test/input +/bindings/java/nbproject/genfiles.properties +/bindings/java/nbproject/nbjdk.properties +/bindings/java/nbproject/jdk.xml +/bindings/java/nbproject/nbjdk.xml # Windows build folders /win32/Debug_NoLibs/ diff --git a/bindings/java/nbproject/project.xml b/bindings/java/nbproject/project.xml index 70b41e6b52196f8f91fd64e2db4d8c899ae95153..7be1d26b299adbb2688a9aaf79be66d1e3f14061 100755 --- a/bindings/java/nbproject/project.xml +++ b/bindings/java/nbproject/project.xml @@ -30,17 +30,20 @@ </folders> <ide-actions> <action name="build"> + <script>nbproject/nbjdk.xml</script> <target>dist</target> </action> <action name="clean"> + <script>nbproject/nbjdk.xml</script> <target>clean</target> </action> <action name="rebuild"> + <script>nbproject/nbjdk.xml</script> <target>clean</target> <target>dist</target> </action> <action name="run.single"> - <script>nbproject/ide-file-targets.xml</script> + <script>nbproject/nbjdk.xml</script> <target>run-selected-file-in-test</target> <context> <property>run.class</property> @@ -53,7 +56,7 @@ </context> </action> <action name="compile.single"> - <script>nbproject/ide-file-targets.xml</script> + <script>nbproject/nbjdk.xml</script> <target>compile-selected-files-in-test</target> <context> <property>files</property> @@ -66,25 +69,30 @@ </context> </action> <action name="test"> + <script>nbproject/nbjdk.xml</script> <target>test</target> </action> <action name="javadoc"> + <script>nbproject/nbjdk.xml</script> <target>javadoc</target> </action> </ide-actions> <export> <type>folder</type> <location>build</location> + <script>nbproject/nbjdk.xml</script> <build-target>dist</build-target> </export> <export> <type>folder</type> <location>build</location> + <script>nbproject/nbjdk.xml</script> <build-target>dist</build-target> </export> <export> <type>folder</type> <location>test</location> + <script>nbproject/nbjdk.xml</script> <build-target>dist</build-target> </export> <view> @@ -116,7 +124,7 @@ <package-root>src</package-root> <classpath mode="compile">lib;lib/diffutils-1.2.1.jar;lib/sqlite-jdbc-3.7.8-SNAPSHOT.jar;lib/junit-4.8.2.jar</classpath> <built-to>build</built-to> - <source-level>1.7</source-level> + <source-level>1.6</source-level> </compilation-unit> <compilation-unit> <package-root>test</package-root> @@ -124,7 +132,7 @@ <classpath mode="compile">build;lib/diffutils-1.2.1.jar;lib/diffutils-1.2.1-javadoc.jar;lib/diffutils-1.2.1-sources.jar;lib/junit-4.8.2.jar</classpath> <built-to>build</built-to> <built-to>test</built-to> - <source-level>1.7</source-level> + <source-level>1.6</source-level> </compilation-unit> </java-data> <preferences xmlns="http://www.netbeans.org/ns/auxiliary-configuration-preferences/1"> diff --git a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java index dbd4554a645886bf600e154cce8db3ff7a1b2d9c..bff959e7d30326ab245103b38fbc77f3fe8e1c0f 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java +++ b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java @@ -92,6 +92,7 @@ public class SleuthkitCase { private PreparedStatement getFileSt; private PreparedStatement getFileWithParentSt; private PreparedStatement updateMd5St; + private PreparedStatement getLastContentIdSt; private static final Logger logger = Logger.getLogger(SleuthkitCase.class.getName()); /** @@ -194,6 +195,8 @@ private void initStatements() throws SQLException { getFileWithParentSt = con.prepareStatement("SELECT * FROM tsk_files WHERE LOWER(name) LIKE ? AND LOWER(name) NOT LIKE '%journal%' AND LOWER(parent_path) LIKE ? AND fs_obj_id = ?"); updateMd5St = con.prepareStatement("UPDATE tsk_files SET md5 = ? WHERE obj_id = ?"); + + getLastContentIdSt = con.prepareStatement("SELECT MAX(obj_id) from tsk_objects"); } private void closeStatements() { @@ -295,6 +298,11 @@ private void closeStatements() { updateMd5St.close(); updateMd5St = null; } + + if (getLastContentIdSt != null) { + getLastContentIdSt.close(); + getLastContentIdSt = null; + } } catch (SQLException e) { logger.log(Level.WARNING, @@ -3366,6 +3374,44 @@ public int countFsContentType(TskData.TSK_FS_META_TYPE_ENUM contentType) throws } return count; } + + /** + * Get last (max) object id of content object in tsk_objects. + * + * Note, if you are using this id to create a new object, make sure you are + * getting and using it in the same write lock/transaction to avoid + * potential concurrency issues with other writes + * + * @return currently max id + * @throws TskCoreException exception thrown when database error occurs and + * last object id could not be queried + */ + public long getLastObjectId() throws TskCoreException { + long id = -1; + ResultSet rs = null; + dbReadLock(); + try { + rs = getLastContentIdSt.executeQuery(); + if (rs.next()) { + id = rs.getLong(1); + } + } catch (SQLException e) { + final String msg = "Error getting last object id."; + logger.log(Level.SEVERE, msg, e); + throw new TskCoreException(msg, e); + } finally { + if (rs != null) { + try { + rs.close(); + } catch (SQLException ex) { + logger.log(Level.SEVERE, "Error closing result set after getting last object id.", ex); + } + } + dbReadUnlock(); + } + + return id; + } /** * Escape the single quotes in the given string so they can be added to the diff --git a/bindings/java/test/org/sleuthkit/datamodel/BottomUpTest.java b/bindings/java/test/org/sleuthkit/datamodel/BottomUpTest.java index 2bf44d83c605d62710fb6e5edb38066c7eb85923..2bcdeef88dc6eb51a544fa7662f2e06a70e69b97 100644 --- a/bindings/java/test/org/sleuthkit/datamodel/BottomUpTest.java +++ b/bindings/java/test/org/sleuthkit/datamodel/BottomUpTest.java @@ -23,6 +23,8 @@ import java.util.Collection; import java.util.List; import java.util.Scanner; +import java.util.logging.Level; +import java.util.logging.Logger; import static org.junit.Assert.*; import org.junit.Test; import org.junit.runner.RunWith; @@ -52,7 +54,7 @@ public BottomUpTest(List<String> imagePaths) { */ @Parameterized.Parameters public static Collection<Object[]> testImageData() { - Collection<Object[]> data = new ArrayList<>(); + Collection<Object[]> data = new ArrayList<Object[]>(); for (Object imagePaths : DataModelTestSuite.getImagePaths()) { data.add(new Object[]{imagePaths}); @@ -84,7 +86,8 @@ public void testBottomUpDiff() { } process.commit(); java.io.File lvs = new java.io.File(dbFile.getAbsolutePath() + java.io.File.separator + title); - Scanner climber = new Scanner(lvs); + Scanner climber; + climber = new Scanner(lvs); while (climber.hasNextLine()) { String cliNL = climber.nextLine(); cliNL = cliNL.substring(1); @@ -95,11 +98,13 @@ public void testBottomUpDiff() { c = c.getParent(); } } - } catch (FileNotFoundException | NumberFormatException ex) { + } catch (NumberFormatException ex) { System.out.println(ex.toString()); fail("Failed to run BottomUp test"); } catch (TskCoreException ex) { DataModelTestSuite.writeExceptions(exFile, ex); + } catch (FileNotFoundException ex) { + DataModelTestSuite.writeExceptions(exFile, ex); } } } diff --git a/bindings/java/test/org/sleuthkit/datamodel/CPPtoJavaCompare.java b/bindings/java/test/org/sleuthkit/datamodel/CPPtoJavaCompare.java index f7bf79afe3c180727967c956dd0f0666c0a28ebc..ddf469deaf9f5db4ff9bc81628dcb4d2e1669cdc 100644 --- a/bindings/java/test/org/sleuthkit/datamodel/CPPtoJavaCompare.java +++ b/bindings/java/test/org/sleuthkit/datamodel/CPPtoJavaCompare.java @@ -52,7 +52,7 @@ public CPPtoJavaCompare(List<String> imagePaths) { */ @Parameterized.Parameters public static Collection<Object[]> testImageData() { - Collection<Object[]> data = new ArrayList<>(); + Collection<Object[]> data = new ArrayList<Object[]>(); for (Object imagePaths : DataModelTestSuite.getImagePaths()) { data.add(new Object[]{imagePaths}); @@ -81,7 +81,7 @@ public List<Boolean> basicTest() { super.basicTest(); oldStandardPath = DataModelTestSuite.sortedFlPth(oldStandardPath); testStandardPath = DataModelTestSuite.sortedFlPth(testStandardPath); - List<Boolean> ret = new ArrayList<>(1); + List<Boolean> ret = new ArrayList<Boolean>(1); ret.add(DataModelTestSuite.comparecontent(oldStandardPath, testStandardPath)); return ret; } diff --git a/bindings/java/test/org/sleuthkit/datamodel/CrossCompare.java b/bindings/java/test/org/sleuthkit/datamodel/CrossCompare.java index 3d2c255a28b6dd0c9aea1ec62e3752a1eb86d4e1..ae76095cb8d3631da4b32b4fd0016aad9d444ff0 100644 --- a/bindings/java/test/org/sleuthkit/datamodel/CrossCompare.java +++ b/bindings/java/test/org/sleuthkit/datamodel/CrossCompare.java @@ -53,7 +53,7 @@ public CrossCompare(List<String> imagePaths, String Seq, String TD) { */ @Parameterized.Parameters public static Collection<Object[]> testImageData() { - Collection<Object[]> data = new ArrayList<>(); + Collection<Object[]> data = new ArrayList<Object[]>(); for (Object imagePaths : DataModelTestSuite.getImagePaths()) { data.add(new Object[]{imagePaths, SequentialTraversal.class.getSimpleName(), TopDownTraversal.class.getSimpleName()}); diff --git a/bindings/java/test/org/sleuthkit/datamodel/DataModelTestSuite.java b/bindings/java/test/org/sleuthkit/datamodel/DataModelTestSuite.java index 58b18b6014eaa32ceffb903b39717f7ed14755c6..aa8e03195da158110191f945ff63620e2e9090e1 100644 --- a/bindings/java/test/org/sleuthkit/datamodel/DataModelTestSuite.java +++ b/bindings/java/test/org/sleuthkit/datamodel/DataModelTestSuite.java @@ -73,7 +73,7 @@ public static void setUpClass() throws Exception { * @return */ public static List<ImgTraverser> getTests() { - List<ImgTraverser> ret = new ArrayList<>(); + List<ImgTraverser> ret = new ArrayList<ImgTraverser>(); ret.add(new SequentialTraversal(null)); ret.add(new TopDownTraversal(null)); return ret; @@ -111,9 +111,8 @@ public static void createStandard(String standardPath, String tempDirPath, List< writeExceptions(standardFile.getAbsolutePath(), ex); } process.commit(); - try (FileWriter standardWriter = type.traverse(sk, standardFile.getAbsolutePath())) { - standardWriter.flush(); - } + FileWriter standardWriter = type.traverse(sk, standardFile.getAbsolutePath()); + standardWriter.flush(); runSort(standardFile.getAbsolutePath()); } catch (IOException ex) { logg.log(Level.SEVERE, "Couldn't create Standard", ex); @@ -140,9 +139,9 @@ public boolean accept(java.io.File f) { return isImgFile(f.getName()); } }; - List<List<String>> images = new ArrayList<>(); + List<List<String>> images = new ArrayList<List<String>>(); for (java.io.File imageSet : dir.listFiles(imageFilter)) { - ArrayList<String> imgs = new ArrayList<>(); + ArrayList<String> imgs = new ArrayList<String>(); imgs.add(imageSet.getAbsolutePath()); images.add(imgs); } @@ -344,7 +343,9 @@ public static void readContent(Content c, Appendable result, String StrgFile) { result.append("md5=" + hash); - } catch (IOException | NoSuchAlgorithmException ex) { + } catch (NoSuchAlgorithmException ex) { + logg.log(Level.SEVERE, "Failed to generate Hash", ex); + } catch (IOException ex){ logg.log(Level.SEVERE, "Failed to generate Hash", ex); } catch (TskCoreException ex) { writeExceptions(StrgFile, ex); @@ -471,7 +472,10 @@ private static void runSort(String inp) { String[] cmd = {cygpath, inp, "-o", outp}; try { Runtime.getRuntime().exec(cmd).waitFor(); - } catch (IOException | InterruptedException ex) { + } catch (InterruptedException ex) { + logg.log(Level.SEVERE, "Couldn't create Standard", ex); + throw new RuntimeException(ex); + } catch(IOException ex){ logg.log(Level.SEVERE, "Couldn't create Standard", ex); throw new RuntimeException(ex); } diff --git a/bindings/java/test/org/sleuthkit/datamodel/DiffUtil.java b/bindings/java/test/org/sleuthkit/datamodel/DiffUtil.java index aeb1b0b5e38cabe29ccb2eb5f9040c79ae28d64b..a6b648bdf63726cd42f55ea0967aeaac77a0785a 100644 --- a/bindings/java/test/org/sleuthkit/datamodel/DiffUtil.java +++ b/bindings/java/test/org/sleuthkit/datamodel/DiffUtil.java @@ -42,7 +42,7 @@ public class DiffUtil { * @return */ private static List<String> fileToLines(String filename) { - List<String> lines = new LinkedList<>(); + List<String> lines = new LinkedList<String>(); String line; try { BufferedReader in = new BufferedReader(new FileReader(new java.io.File(filename).getAbsolutePath())); @@ -77,10 +77,9 @@ public static void getDiff(String pathOriginal, String pathRevised, String title diff.append("\n"); } try { - try (FileWriter out = new FileWriter(outp)) { - out.append(diff); - out.flush(); - } + FileWriter out = new FileWriter(outp); + out.append(diff); + out.flush(); } catch (IOException ex) { Logger.getLogger(DiffUtil.class.getName()).log(Level.SEVERE, "Couldn't write Diff to file", ex); } diff --git a/bindings/java/test/org/sleuthkit/datamodel/ImgTraverser.java b/bindings/java/test/org/sleuthkit/datamodel/ImgTraverser.java index 5006f961ebfa29a6ec9b3baa34e3c51821b2d5ab..e390e9b1aef6a08f419db164b6206e7375adde6b 100644 --- a/bindings/java/test/org/sleuthkit/datamodel/ImgTraverser.java +++ b/bindings/java/test/org/sleuthkit/datamodel/ImgTraverser.java @@ -49,7 +49,7 @@ public List<Boolean> basicTest() { oldStandardPath = DataModelTestSuite.standardPath(imagePaths, this.getClass().getSimpleName()); DataModelTestSuite.createStandard(testStandardPath, testFolder.getAbsolutePath(), imagePaths, this); oldExceptionsPath = oldStandardPath.replace(".txt", DataModelTestSuite.EX + ".txt"); - List<Boolean> ret = new ArrayList<>(2); + List<Boolean> ret = new ArrayList<Boolean>(2); ret.add(DataModelTestSuite.comparecontent(oldExceptionsPath, exFile)); ret.add(DataModelTestSuite.comparecontent(oldStandardPath, testStandardPath)); return ret; diff --git a/bindings/java/test/org/sleuthkit/datamodel/SequentialTraversal.java b/bindings/java/test/org/sleuthkit/datamodel/SequentialTraversal.java index 465cc7c4d4bf1cc0fcbb7b96654fdf1c3316ec17..dd2b60756580f11a337ffc40607c6852be1124cc 100644 --- a/bindings/java/test/org/sleuthkit/datamodel/SequentialTraversal.java +++ b/bindings/java/test/org/sleuthkit/datamodel/SequentialTraversal.java @@ -53,7 +53,7 @@ public SequentialTraversal(List<String> imagePaths) { */ @Parameterized.Parameters public static Collection<Object[]> testImageData() { - Collection<Object[]> data = new ArrayList<>(); + Collection<Object[]> data = new ArrayList<Object[]>(); for (Object imagePaths : DataModelTestSuite.getImagePaths()) { data.add(new Object[]{imagePaths}); diff --git a/bindings/java/test/org/sleuthkit/datamodel/TopDownTraversal.java b/bindings/java/test/org/sleuthkit/datamodel/TopDownTraversal.java index b0aa66d41ff5b028e53683ead0a915b84d91b594..cbdcc35c8c061e6343d19864eada0b26529bdfc0 100644 --- a/bindings/java/test/org/sleuthkit/datamodel/TopDownTraversal.java +++ b/bindings/java/test/org/sleuthkit/datamodel/TopDownTraversal.java @@ -55,7 +55,7 @@ public TopDownTraversal(List<String> imagePaths) { */ @Parameters public static Collection<Object[]> testImageData() { - Collection<Object[]> data = new ArrayList<>(); + Collection<Object[]> data = new ArrayList<Object[]>(); for (Object imagePaths : DataModelTestSuite.getImagePaths()) { data.add(new Object[]{imagePaths}); @@ -94,7 +94,7 @@ public FileWriter traverse(SleuthkitCase sk, String path) { } catch (TskCoreException ex) { DataModelTestSuite.writeExceptions(testStandardPath, ex); } - List<Long> lp = new ArrayList<>(); + List<Long> lp = new ArrayList<Long>(); try { FileWriter reslt = new FileWriter(path); FileWriter levs = new FileWriter(path.replace("_" + this.getClass().getSimpleName() + ".txt", DataModelTestSuite.LVS + ".txt")); @@ -136,7 +136,7 @@ private void topDownDF(List<Content> lc, List<Long> lp, Appendable reslt, Append if (c.getChildren().isEmpty()) { levs.append(lp.toString() + "\n"); } else { - topDownDF(c.getChildren(), new ArrayList<>(lp), reslt, levs); + topDownDF(c.getChildren(), new ArrayList<Long>(lp), reslt, levs); } } catch (IOException ex) { logg.log(Level.SEVERE, "Failed to Traverse", ex);