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"};
50 private final String name;
51 private final String unixName;
53 Lib(String name, String unixName) {
55 this.unixName = unixName;
75 System.out.println(
"SleuthkitJNI: failed to load " +
Lib.
TSK_JNI.getLibName());
77 System.out.println(
"SleuthkitJNI: loaded " +
Lib.
TSK_JNI.getLibName());
87 private static String getPlatform() {
88 String os = System.getProperty(
"os.name").toLowerCase();
91 }
else if (LibraryUtils.isMac()) {
93 }
else if (LibraryUtils.isLinux()) {
97 String arch = System.getProperty(
"os.arch");
98 return arch.toLowerCase() +
"/" + os.toLowerCase();
106 private static boolean isWindows() {
107 return System.getProperty(
"os.name").toLowerCase().contains(
"windows");
115 private static boolean isMac() {
116 return System.getProperty(
"os.name").toLowerCase().contains(
"mac");
124 private static boolean isLinux() {
125 return System.getProperty(
"os.name").equals(
"Linux");
135 private static boolean loadNativeLibFromTskJar(Lib library) {
136 String libName = library.getLibName();
137 String userName = System.getProperty(
"user.name");
139 StringBuilder pathInJarBase =
new StringBuilder();
140 pathInJarBase.append(
"/NATIVELIBS/");
141 pathInJarBase.append(getPlatform());
142 pathInJarBase.append(
"/");
143 pathInJarBase.append(libName);
146 String libExt = null;
147 for (String ext : EXTS) {
148 urlInJar = SleuthkitJNI.class.getResource(pathInJarBase.toString() + ext);
149 if (urlInJar != null) {
155 if (urlInJar == null) {
156 System.out.println(
"Library not found in jar (" + libName +
")");
159 StringBuilder pathToTempFile =
new StringBuilder();
160 pathToTempFile.append(System.getProperty(
"java.io.tmpdir"));
161 pathToTempFile.append(java.io.File.separator);
162 pathToTempFile.append(libName);
163 pathToTempFile.append(
"_");
164 pathToTempFile.append(userName);
165 pathToTempFile.append(libExt);
168 java.io.File tempLibFile =
new java.io.File(pathToTempFile.toString());
169 System.out.println(
"Temp Folder for Libraries: " + tempLibFile.getParent());
175 for (Lib l : Lib.values()) {
176 String ext = getExtByPlatform();
178 java.io.File f =
new java.io.File(l.getLibName() + ext);
184 java.io.File fUnix =
new java.io.File(l.getUnixName() + ext);
186 if (fUnix.exists()) {
193 if (tempLibFile.exists()) {
194 if (tempLibFile.delete() ==
false) {
195 System.out.println(
"Error deleting old native library. Is the app already running? (" + tempLibFile.toString() +
")");
201 InputStream in = urlInJar.openStream();
202 OutputStream out =
new FileOutputStream(tempLibFile);
204 byte[] buffer =
new byte[1024];
206 while ((length = in.read(buffer)) > 0) {
207 out.write(buffer, 0, length);
213 System.load(tempLibFile.getAbsolutePath());
214 }
catch (IOException e) {
216 System.out.println(
"Error loading library: " + e.getMessage());
222 private static String getExtByPlatform() {
225 }
else if (isMac()) {
static boolean loadSleuthkitJNI()
Lib(String name, String unixName)
static final String[] EXTS