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"}; 
 
   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()); 
 
   88                 String os = System.getProperty(
"os.name").toLowerCase();
 
   97                 String arch = System.getProperty(
"os.arch");
 
   98                 return arch.toLowerCase() + 
"/" + os.toLowerCase();
 
  107                 return System.getProperty(
"os.name").toLowerCase().contains(
"windows"); 
 
  116                 return System.getProperty(
"os.name").toLowerCase().contains(
"mac"); 
 
  125                 return System.getProperty(
"os.name").equals(
"Linux"); 
 
  139                 StringBuilder pathInJarBase = 
new StringBuilder();
 
  140                 pathInJarBase.append(
"/NATIVELIBS/"); 
 
  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()) {
 
  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()); 
 
  219                 } 
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