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();
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 +
")");
162 java.io.File tempLibFile =
new java.io.File(System.getProperty(
"java.io.tmpdir") + java.io.File.separator + libName + libExt);
163 System.out.println(
"Temp Folder for Libraries: " + tempLibFile.getParent());
169 for (Lib l : Lib.values()) {
170 String ext = getExtByPlatform();
172 java.io.File f =
new java.io.File(l.getLibName() + ext);
178 java.io.File fUnix =
new java.io.File(l.getUnixName() + ext);
180 if (fUnix.exists()) {
187 if (tempLibFile.exists()) {
188 if (tempLibFile.delete() ==
false) {
189 System.out.println(
"Error deleting old native library. Is the app already running? (" + tempLibFile.toString() +
")");
195 InputStream in = urlInJar.openStream();
196 OutputStream out =
new FileOutputStream(tempLibFile);
198 byte[] buffer =
new byte[1024];
200 while ((length = in.read(buffer)) > 0) {
201 out.write(buffer, 0, length);
207 System.load(tempLibFile.getAbsolutePath());
208 }
catch (IOException e) {
210 System.out.println(
"Error loading library: " + e.getMessage());
216 private static String getExtByPlatform() {
219 }
else if (isMac()) {
static boolean loadSleuthkitJNI()
Lib(String name, String unixName)
static final String[] EXTS