19 package org.sleuthkit.datamodel;
21 import java.io.FileOutputStream;
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.io.OutputStream;
35 public static final String[]
EXTS =
new String[]{
".so",
".dylib",
".dll",
".jnilib"};
51 Lib(String name, String unixName) {
53 this.unixName = unixName;
73 System.out.println(
"SleuthkitJNI: failed to load " +
Lib.
TSK_JNI.getLibName());
75 System.out.println(
"SleuthkitJNI: loaded " +
Lib.
TSK_JNI.getLibName());
86 String os = System.getProperty(
"os.name").toLowerCase();
95 String arch = System.getProperty(
"os.arch");
96 return arch.toLowerCase() +
"/" + os.toLowerCase();
105 return System.getProperty(
"os.name").toLowerCase().contains(
"windows");
114 return System.getProperty(
"os.name").toLowerCase().contains(
"mac");
123 return System.getProperty(
"os.name").equals(
"Linux");
136 StringBuilder pathInJarBase =
new StringBuilder();
137 pathInJarBase.append(
"/NATIVELIBS/");
139 pathInJarBase.append(
"/");
140 pathInJarBase.append(libName);
143 String libExt = null;
144 for (String ext : EXTS) {
145 urlInJar =
SleuthkitJNI.class.getResource(pathInJarBase.toString() + ext);
146 if (urlInJar != null) {
152 if (urlInJar == null) {
153 System.out.println(
"Library not found in jar (" + libName +
")");
159 java.io.File tempLibFile =
new java.io.File(System.getProperty(
"java.io.tmpdir") + java.io.File.separator + libName + libExt);
160 System.out.println(
"Temp Folder for Libraries: " + tempLibFile.getParent());
166 for (
Lib l :
Lib.values()) {
169 java.io.File f =
new java.io.File(l.getLibName() + ext);
175 java.io.File fUnix =
new java.io.File(l.getUnixName() + ext);
177 if (fUnix.exists()) {
184 if (tempLibFile.exists()) {
185 if (tempLibFile.delete() ==
false) {
186 System.out.println(
"Error deleting old native library. Is the app already running? (" + tempLibFile.toString() +
")");
192 InputStream in = urlInJar.openStream();
193 OutputStream out =
new FileOutputStream(tempLibFile);
195 byte[] buffer =
new byte[1024];
197 while ((length = in.read(buffer)) > 0) {
198 out.write(buffer, 0, length);
204 System.load(tempLibFile.getAbsolutePath());
205 }
catch (IOException e) {
207 System.out.println(
"Error loading library: " + e.getMessage());
216 }
else if (
isMac()) {
static boolean isWindows()
static String getExtByPlatform()
static boolean loadSleuthkitJNI()
static String getPlatform()
Lib(String name, String unixName)
static boolean loadNativeLibFromTskJar(Lib library)
static final String[] EXTS