Skip to content
Snippets Groups Projects
Commit c90913ce authored by momo's avatar momo
Browse files

use defined loadLibrary instead of system

parent 6de5b259
No related branches found
No related tags found
No related merge requests found
......@@ -69,7 +69,7 @@ private static void loadDynLibraries() {
logger.log(Level.INFO, "MSVCR100 and MSVCP100 libraries loaded"); //NON-NLS
} catch (UnsatisfiedLinkError e) {
logger.log(Level.SEVERE, "Error loading MSVCR100 and MSVCP100 libraries, ", e); //NON-NLS
logger.log(Level.WARNING, "Error loading MSVCR100 and MSVCP100 libraries"); //NON-NLS
}
try {
......
......@@ -201,14 +201,9 @@ public static String getLogDirectory() {
* @return Lib path string
*/
public static String getLibsPath() {
System.out.println(PlatformUtil.getInstallPath());
System.out.println(PlatformUtil.getInstallModulesPath());
System.out.println(PlatformUtil.getLogDirectory());
System.out.println(PlatformUtil.getUserModulesPath());
System.out.println(PlatformUtil.getUserDirectory());
File coreFolder = InstalledFileLocator.getDefault().locate("core", PlatformUtil.class.getPackage().getName(), false); //NON-NLS
File rootPath = coreFolder.getParentFile().getParentFile();
return new File(".").getAbsolutePath() + ".\\build\\cluster\\modules\\lib\\" + getOSArch() + "\\";
// locate uses "/" regardless of format
File libFolder = InstalledFileLocator.getDefault().locate("modules/lib/" + getOSArch(), PlatformUtil.class.getPackage().getName(), false); //NON-NLS
return libFolder.getAbsolutePath();
}
public static String getDefaultPlatformFileEncoding() {
......@@ -292,8 +287,13 @@ public static String getOSArch() {
return arch.endsWith("64") ? "x86_64" : "x86"; //NON-NLS
}
/**
* load library from library path (hardcoded .dll for now).
*
* @param libName name of library to be loaded
*/
public static void loadLibrary(String libName) {
String path = getLibsPath();
String path = getLibsPath() + File.separator;
String ext = ".dll";
System.load(path + libName + ext);
}
......
......@@ -6,6 +6,14 @@
<code-name-base>org.sleuthkit.autopsy.corelibs</code-name-base>
<suite-component/>
<module-dependencies>
<dependency>
<code-name-base>org.openide.modules</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>7.43.1</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.util</code-name-base>
<build-prerequisite/>
......
......@@ -5,3 +5,4 @@ OpenIDE-Module-Long-Description=\
OpenIDE-Module-Name=Autopsy-CoreLibs
OpenIDE-Module-Short-Description=Autopsy Core module external libraries
SigarLoader.linkErr.msg=Could not load sigar library for your environment (non-critical), OS-level metrics will be unavailable.
ScalpelCarver.archUnknown=unknown
/*
*
* Autopsy Forensic Browser
*
* Copyright 2012-15 Basis Technology Corp.
*
* Copyright 2012 42six Solutions.
* Contact: aebadirad <at> 42six <dot> com
* Project Contact/Architect: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.sleuthkit.autopsy.corelibs;
import java.io.File;
import org.openide.modules.InstalledFileLocator;
import org.openide.util.NbBundle;
class LibsPathUtil {
public static final String OS_ARCH_UNKNOWN = NbBundle.getMessage(LibsPathUtil.class, "LibsPathUtil.archUnknown");
private LibsPathUtil() {}
/**
* load library from library path (hardcoded .dll for now).
*
* @param libName name of library to be loaded
*/
public static void loadLibrary(String libName) {
String path = getLibsPath() + File.separator;
String ext = ".dll";
System.load(path + libName + ext);
}
/**
* Gets the absolute path to the lib folder
*
* @return Lib path string
*/
public static String getLibsPath() {
// locate uses "/" regardless of format
File libFolder = InstalledFileLocator.getDefault().locate("modules/lib/" + getOSArch(), LibsPathUtil.class.getPackage().getName(), false); //NON-NLS
return libFolder.getAbsolutePath();
}
/**
* Get OS arch details, or OS_ARCH_UNKNOWN
*
* @return OS arch string
*/
public static String getOSArch() {
String arch = System.getProperty("os.arch"); //NON-NLS
if(arch == null)
return OS_ARCH_UNKNOWN;
else
return arch.endsWith("64") ? "x86_64" : "x86"; //NON-NLS
}
}
......@@ -44,9 +44,9 @@ public static Sigar getSigar() {
try {
//rely on netbeans / jna to locate the lib variation for architecture/OS
if (PlatformUtil.isWindows()) {
System.loadLibrary("libsigar"); //NON-NLS
LibsPathUtil.loadLibrary("libsigar"); //NON-NLS
} else {
System.loadLibrary("sigar"); //NON-NLS
LibsPathUtil.loadLibrary("sigar"); //NON-NLS
}
sigar = new Sigar();
sigar.enableLogging(false); //forces a test
......
......@@ -6,6 +6,14 @@
<code-name-base>org.sleuthkit.autopsy.scalpel</code-name-base>
<standalone/>
<module-dependencies>
<dependency>
<code-name-base>org.openide.modules</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>7.43.1</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.util</code-name-base>
<build-prerequisite/>
......
......@@ -5,4 +5,5 @@ ScalpelCarver.carve.exception.invalidArgs=Invalid arguments for scalpel carving.
ScalpelCarver.carve.exception.cannotReadConfig=Cannot read libscalpel config file\: {0}
ScalpelCarver.carve.exception.cannotWriteConfig=Cannot write to libscalpel output dir\: {0}
ScalpelOutputParser.outputStart.text=The following files were carved\:
ScalpelOutputParser.toString.text=CarvedFileMeta'{'fileName\={0}, start\: {1}, size\: {2}'}'
\ No newline at end of file
ScalpelOutputParser.toString.text=CarvedFileMeta'{'fileName\={0}, start\: {1}, size\: {2}'}'
LibsPathUtil.archUnknown=unknown
\ No newline at end of file
......@@ -27,6 +27,7 @@
import java.util.logging.Level;
import org.openide.util.NbBundle;
import org.openide.modules.InstalledFileLocator;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.scalpel.jni.ScalpelOutputParser.CarvedFileMeta;
import org.sleuthkit.datamodel.AbstractFile;
......@@ -75,7 +76,7 @@ private static boolean loadLib(String id) {
boolean success = false;
try {
//rely on netbeans / jna to locate the lib variation for architecture/OS
System.loadLibrary(id);
loadLibrary(id);
success = true;
} catch (UnsatisfiedLinkError ex) {
String msg = NbBundle.getMessage(ScalpelCarver.class, "ScalpelCarver.loadLib.errMsg.cannotLoadLib", id);
......@@ -89,6 +90,41 @@ private static boolean loadLib(String id) {
return success;
}
/**
* load library from library path (hardcoded .dll for now).
*
* @param libName name of library to be loaded
*/
private static void loadLibrary(String libName) {
String path = getLibsPath() + File.separator;
String ext = ".dll";
System.load(path + libName + ext);
}
/**
* Gets the absolute path to the lib folder
*
* @return Lib path string
*/
public static String getLibsPath() {
// locate uses "/" regardless of format
File libFolder = InstalledFileLocator.getDefault().locate("modules/lib/" + getOSArch(), ScalpelCarver.class.getPackage().getName(), false); //NON-NLS
return libFolder.getAbsolutePath();
}
/**
* Get OS arch details, or OS_ARCH_UNKNOWN
*
* @return OS arch string
*/
private static String getOSArch() {
String arch = System.getProperty("os.arch"); //NON-NLS
if(arch == null)
return NbBundle.getMessage(ScalpelCarver.class, "ScalpelCarver.archUnknown");
else
return arch.endsWith("64") ? "x86_64" : "x86"; //NON-NLS
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment