Skip to content
Snippets Groups Projects
Commit a9a6fcca authored by Jeff Wallace's avatar Jeff Wallace
Browse files

CRT now included in tsk jni jar file. Temp files are now deleted correctly.

parent c7970249
No related branches found
No related tags found
No related merge requests found
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
<property name="x86_64" location="build/NATIVELIBS/x86_64" /> <property name="x86_64" location="build/NATIVELIBS/x86_64" />
<property name="i386" location="build/NATIVELIBS/i386" /> <property name="i386" location="build/NATIVELIBS/i386" />
<property name="i586" location="build/NATIVELIBS/i586" /> <property name="i586" location="build/NATIVELIBS/i586" />
<property name="crt" location="${basedir}/crt" />
<path id="libraries"> <path id="libraries">
<fileset dir="${lib}"> <fileset dir="${lib}">
...@@ -131,6 +132,15 @@ pattern="lib/[artifact]-[revision](-[classifier]).[ext]" /> ...@@ -131,6 +132,15 @@ pattern="lib/[artifact]-[revision](-[classifier]).[ext]" />
<copy todir="${x86_64}/win"> <copy todir="${x86_64}/win">
<fileset refid="win64dlls" /> <fileset refid="win64dlls" />
</copy> </copy>
<fileset dir="${crt}/win64" id="crt64dlls">
<include name="*.dll" />
</fileset>
<copy todir="${amd64}/win">
<fileset refid="crt64dlls" />
</copy>
<copy todir="${x86_64}/win">
<fileset refid="crt64dlls" />
</copy>
</target> </target>
<target name="copyWinLibs32" depends="checkLibDirs" if="win32.exists"> <target name="copyWinLibs32" depends="checkLibDirs" if="win32.exists">
...@@ -147,6 +157,18 @@ pattern="lib/[artifact]-[revision](-[classifier]).[ext]" /> ...@@ -147,6 +157,18 @@ pattern="lib/[artifact]-[revision](-[classifier]).[ext]" />
<copy todir="${i586}/win"> <copy todir="${i586}/win">
<fileset refid="win32dlls" /> <fileset refid="win32dlls" />
</copy> </copy>
<fileset dir="${crt}/win32" id="crt32dlls">
<include name="*.dll" />
</fileset>
<copy todir="${i386}/win">
<fileset refid="crt32dlls" />
</copy>
<copy todir="${x86}/win">
<fileset refid="crt32dlls" />
</copy>
<copy todir="${i586}/win">
<fileset refid="crt32dlls" />
</copy>
</target> </target>
<target name="jni" depends="compile" description="make the jni.h file"> <target name="jni" depends="compile" description="make the jni.h file">
......
File added
File added
File added
File added
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.URL; import java.net.URL;
import java.nio.file.Files;
/** /**
* Collection of methods to load libraries embedded in the TSK Datamodel Jar file. * Collection of methods to load libraries embedded in the TSK Datamodel Jar file.
...@@ -18,15 +19,22 @@ ...@@ -18,15 +19,22 @@
public class LibraryUtils { public class LibraryUtils {
public static final String[] EXTS = new String[] { ".so", ".dylib", ".dll", ".jnilib" }; public static final String[] EXTS = new String[] { ".so", ".dylib", ".dll", ".jnilib" };
public static final Lib[] CRT_LIBS = new Lib[] { Lib.MSVCP, Lib.MSVCR };
public static final Lib[] OTHER_LIBS = new Lib[] { Lib.ZLIB, Lib.LIBEWF, Lib.TSK_JNI };
/** /**
* The libraries the TSK Datamodel needs. * The libraries the TSK Datamodel needs.
*/ */
public enum Lib { public enum Lib {
MSVCP ("msvcp100"),
MSVCR ("msvcr100"),
ZLIB ("zlib"), ZLIB ("zlib"),
LIBEWF ("libewf"), LIBEWF ("libewf"),
TSK_JNI ("tsk_jni"); TSK_JNI ("tsk_jni");
private final String name; private final String name;
Lib(String name) { Lib(String name) {
this.name = name; this.name = name;
} }
...@@ -52,7 +60,6 @@ public static String getPlatform() { ...@@ -52,7 +60,6 @@ public static String getPlatform() {
} }
// os.arch represents the architecture of the JVM, not the os // os.arch represents the architecture of the JVM, not the os
String arch = System.getProperty("os.arch"); String arch = System.getProperty("os.arch");
System.out.println(arch.toLowerCase() + "/" + os.toLowerCase());
return arch.toLowerCase() + "/" + os.toLowerCase(); return arch.toLowerCase() + "/" + os.toLowerCase();
} }
...@@ -66,7 +73,7 @@ public static boolean isWindows() { ...@@ -66,7 +73,7 @@ public static boolean isWindows() {
} }
/** /**
* Attempt to load the specified library. * Attempt to extract and load the specified library.
* *
* @param library * @param library
* @return * @return
...@@ -98,7 +105,11 @@ public static void loadLibrary(Lib library) { ...@@ -98,7 +105,11 @@ public static void loadLibrary(Lib library) {
// copy library to temp folder and load it // copy library to temp folder and load it
try { try {
java.io.File libTemp = new java.io.File(System.getProperty("java.io.tmpdir") + libName + libExt); java.io.File libTemp = new java.io.File(System.getProperty("java.io.tmpdir") + libName + libExt);
libTemp.deleteOnExit();
if(libTemp.exists()) {
// Delete old file
Files.delete(libTemp.toPath());
}
InputStream in = libraryURL.openStream(); InputStream in = libraryURL.openStream();
OutputStream out = new FileOutputStream(libTemp); OutputStream out = new FileOutputStream(libTemp);
...@@ -112,11 +123,17 @@ public static void loadLibrary(Lib library) { ...@@ -112,11 +123,17 @@ public static void loadLibrary(Lib library) {
out.close(); out.close();
System.load(libTemp.getAbsolutePath()); System.load(libTemp.getAbsolutePath());
libTemp.delete();
} catch (IOException e) { } catch (IOException e) {
// Loading failed. // Loading failed.
} }
} }
}
public static Lib[] getCRTLibs() {
return CRT_LIBS;
}
public static Lib[] getLibs() {
return OTHER_LIBS;
} }
} }
...@@ -118,19 +118,31 @@ public class SleuthkitJNI { ...@@ -118,19 +118,31 @@ public class SleuthkitJNI {
//Linked library loading //Linked library loading
static { static {
try { if (LibraryUtils.isWindows()) {
try {
//on windows force loading ms crt dependencies first //on windows force loading ms crt dependencies first
//in case linker can't find them on some systems //in case linker can't find them on some systems
//Note: if shipping with a different CRT version, this will only print a warning //Note: if shipping with a different CRT version, this will only print a warning
//and try to use linker mechanism to find the correct versions of libs. //and try to use linker mechanism to find the correct versions of libs.
//We should update this if we officially switch to a new version of CRT/compiler //We should update this if we officially switch to a new version of CRT/compiler
System.loadLibrary("msvcr100"); for(LibraryUtils.Lib crt : LibraryUtils.getCRTLibs()) {
System.loadLibrary("msvcp100"); LibraryUtils.loadLibrary(crt);
}
System.out.println("Loaded CRT libraries"); System.out.println("Loaded CRT libraries");
} catch (UnsatisfiedLinkError e) { } catch (UnsatisfiedLinkError e1) {
System.out.println("Can't find CRT libraries"); System.out.println(e1.toString());
try {
// Try to load from system path
System.out.println("Can't find CRT libraries, attempting to load from System.loadLibrary");
System.loadLibrary("msvcr100");
System.loadLibrary("msvcp100");
} catch (UnsatisfiedLinkError e2) {
System.out.println("SleuthkitJNI: error loading CRT libraries, " + e2.toString());
}
} }
for(LibraryUtils.Lib lib : LibraryUtils.Lib.values()) { }
for(LibraryUtils.Lib lib : LibraryUtils.getLibs()) {
try { try {
LibraryUtils.loadLibrary(lib); LibraryUtils.loadLibrary(lib);
System.out.println("SleuthkitJNI: loaded " + lib); System.out.println("SleuthkitJNI: loaded " + lib);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment