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());
88 private static String getPlatform() {
89 String os = System.getProperty(
"os.name").toLowerCase();
92 }
else if (LibraryUtils.isMac()) {
94 }
else if (LibraryUtils.isLinux()) {
98 String arch = System.getProperty(
"os.arch");
99 return arch.toLowerCase() +
"/" + os.toLowerCase();
107 private static boolean isWindows() {
108 return System.getProperty(
"os.name").toLowerCase().contains(
"windows");
116 private static boolean isMac() {
117 return System.getProperty(
"os.name").toLowerCase().contains(
"mac");
125 private static boolean isLinux() {
126 return System.getProperty(
"os.name").equals(
"Linux");
136 private static boolean loadNativeLibFromTskJar(Lib library) {
137 String libName = library.getLibName();
138 String userName = System.getProperty(
"user.name");
140 StringBuilder pathInJarBase =
new StringBuilder();
141 pathInJarBase.append(
"/NATIVELIBS/");
142 pathInJarBase.append(getPlatform());
143 pathInJarBase.append(
"/");
144 pathInJarBase.append(libName);
147 String libExt = null;
148 for (String ext : EXTS) {
149 urlInJar = SleuthkitJNI.class.getResource(pathInJarBase.toString() + ext);
150 if (urlInJar != null) {
156 if (urlInJar == null) {
157 System.out.println(
"Library not found in jar (" + libName +
")");
160 StringBuilder pathToTempFile =
new StringBuilder();
161 pathToTempFile.append(System.getProperty(
"java.io.tmpdir"));
162 pathToTempFile.append(java.io.File.separator);
163 pathToTempFile.append(libName);
164 pathToTempFile.append(
"_");
165 pathToTempFile.append(userName);
166 pathToTempFile.append(libExt);
169 java.io.File tempLibFile =
new java.io.File(pathToTempFile.toString());
177 for (Lib l : Lib.values()) {
178 String ext = getExtByPlatform();
180 java.io.File f =
new java.io.File(l.getLibName() + ext);
186 java.io.File fUnix =
new java.io.File(l.getUnixName() + ext);
188 if (fUnix.exists()) {
195 if (tempLibFile.exists()) {
196 if (tempLibFile.delete() ==
false) {
197 System.out.println(
"Error deleting old native library. Is the app already running? (" + tempLibFile.toString() +
")");
203 InputStream in = urlInJar.openStream();
204 OutputStream out =
new FileOutputStream(tempLibFile);
206 byte[] buffer =
new byte[1024];
208 while ((length = in.read(buffer)) > 0) {
209 out.write(buffer, 0, length);
215 System.load(tempLibFile.getAbsolutePath());
216 }
catch (IOException e) {
218 System.out.println(
"Error loading library: " + e.getMessage());
224 private static String getExtByPlatform() {
227 }
else if (isMac()) {
static boolean loadSleuthkitJNI()
Lib(String name, String unixName)
static final String[] EXTS