Autopsy  4.16.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
Installer.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2018 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.core;
20 
21 import com.sun.jna.platform.win32.Kernel32;
22 import java.awt.Cursor;
23 import java.io.File;
24 import java.io.IOException;
25 import java.nio.file.Path;
26 import java.nio.file.Paths;
27 import java.util.ArrayList;
28 import java.util.List;
29 import java.util.concurrent.Callable;
30 import java.util.concurrent.ExecutionException;
31 import java.util.concurrent.FutureTask;
32 import java.util.logging.Handler;
33 import java.util.logging.Level;
34 import javafx.application.Platform;
35 import javafx.embed.swing.JFXPanel;
36 import net.sf.sevenzipjbinding.SevenZip;
37 import net.sf.sevenzipjbinding.SevenZipNativeInitializationException;
38 import org.apache.commons.io.FileUtils;
39 import org.apache.commons.lang3.StringUtils;
40 import org.openide.modules.InstalledFileLocator;
41 import org.openide.modules.ModuleInstall;
42 import org.openide.util.NbBundle;
43 import org.openide.windows.WindowManager;
53 
58 public class Installer extends ModuleInstall {
59 
60  private static final long serialVersionUID = 1L;
61 
62  private final List<ModuleInstall> packageInstallers;
63  private static final Logger logger = Logger.getLogger(Installer.class.getName());
64  private static volatile boolean javaFxInit = false;
65 
66  static {
68  }
69 
70  private static void loadDynLibraries() {
71  /*
72  * On Windows, we distribute dlls that libtsk_jni depend on. If
73  * libtsk_jni tries to load them, they will not be found by Windows
74  * because they are in special NetBeans folders. So, we manually load
75  * them from within Autopsy so that they are found via the NetBeans
76  * loading setup. These are copied by the build script when making the
77  * ZIP file. In a development environment they will need to be loaded
78  * from standard places in your system.
79  *
80  * On non-Windows platforms, we assume the dependncies are all installed
81  * and loadable (i.e. a 'make install' was done).
82  */
83  if (PlatformUtil.isWindowsOS()) {
84  try {
86 
87  //Note: if shipping with a different CRT version, this will only print a warning
88  //and try to use linker mechanism to find the correct versions of libs.
89  //We should update this if we officially switch to a new version of CRT/compiler
90  System.loadLibrary("api-ms-win-core-console-l1-1-0"); //NON-NLS
91  System.loadLibrary("api-ms-win-core-datetime-l1-1-0"); //NON-NLS
92  System.loadLibrary("api-ms-win-core-debug-l1-1-0"); //NON-NLS
93  System.loadLibrary("api-ms-win-core-errorhandling-l1-1-0"); //NON-NLS
94  System.loadLibrary("api-ms-win-core-file-l1-1-0"); //NON-NLS
95  System.loadLibrary("api-ms-win-core-file-l1-2-0"); //NON-NLS
96  System.loadLibrary("api-ms-win-core-file-l2-1-0"); //NON-NLS
97  System.loadLibrary("api-ms-win-core-handle-l1-1-0"); //NON-NLS
98  System.loadLibrary("api-ms-win-core-heap-l1-1-0"); //NON-NLS
99  System.loadLibrary("api-ms-win-core-interlocked-l1-1-0"); //NON-NLS
100  System.loadLibrary("api-ms-win-core-libraryloader-l1-1-0"); //NON-NLS
101  System.loadLibrary("api-ms-win-core-localization-l1-2-0"); //NON-NLS
102  System.loadLibrary("api-ms-win-core-memory-l1-1-0"); //NON-NLS
103  System.loadLibrary("api-ms-win-core-namedpipe-l1-1-0"); //NON-NLS
104  System.loadLibrary("api-ms-win-core-processenvironment-l1-1-0"); //NON-NLS
105  System.loadLibrary("api-ms-win-core-processthreads-l1-1-0"); //NON-NLS
106  System.loadLibrary("api-ms-win-core-processthreads-l1-1-1"); //NON-NLS
107  System.loadLibrary("api-ms-win-core-profile-l1-1-0"); //NON-NLS
108  System.loadLibrary("api-ms-win-core-rtlsupport-l1-1-0"); //NON-NLS
109  System.loadLibrary("api-ms-win-core-string-l1-1-0"); //NON-NLS
110  System.loadLibrary("api-ms-win-core-synch-l1-1-0"); //NON-NLS
111  System.loadLibrary("api-ms-win-core-synch-l1-2-0"); //NON-NLS
112  System.loadLibrary("api-ms-win-core-sysinfo-l1-1-0"); //NON-NLS
113  System.loadLibrary("api-ms-win-core-timezone-l1-1-0"); //NON-NLS
114  System.loadLibrary("api-ms-win-core-util-l1-1-0"); //NON-NLS
115  System.loadLibrary("api-ms-win-crt-conio-l1-1-0"); //NON-NLS
116  System.loadLibrary("api-ms-win-crt-convert-l1-1-0"); //NON-NLS
117  System.loadLibrary("api-ms-win-crt-environment-l1-1-0"); //NON-NLS
118  System.loadLibrary("api-ms-win-crt-filesystem-l1-1-0"); //NON-NLS
119  System.loadLibrary("api-ms-win-crt-heap-l1-1-0"); //NON-NLS
120  System.loadLibrary("api-ms-win-crt-locale-l1-1-0"); //NON-NLS
121  System.loadLibrary("api-ms-win-crt-math-l1-1-0"); //NON-NLS
122  System.loadLibrary("api-ms-win-crt-multibyte-l1-1-0"); //NON-NLS
123  System.loadLibrary("api-ms-win-crt-private-l1-1-0"); //NON-NLS
124  System.loadLibrary("api-ms-win-crt-process-l1-1-0"); //NON-NLS
125  System.loadLibrary("api-ms-win-crt-runtime-l1-1-0"); //NON-NLS
126  System.loadLibrary("api-ms-win-crt-stdio-l1-1-0"); //NON-NLS
127  System.loadLibrary("api-ms-win-crt-string-l1-1-0"); //NON-NLS
128  System.loadLibrary("api-ms-win-crt-time-l1-1-0"); //NON-NLS
129  System.loadLibrary("api-ms-win-crt-utility-l1-1-0"); //NON-NLS
130 
131  System.loadLibrary("ucrtbase"); //NON-NLS
132  System.loadLibrary("vcruntime140"); //NON-NLS
133  System.loadLibrary("msvcp140"); //NON-NLS
134 
135  logger.log(Level.INFO, "Visual C Runtime libraries loaded"); //NON-NLS
136  } catch (UnsatisfiedLinkError e) {
137  logger.log(Level.SEVERE, "Error loading Visual C Runtime libraries, ", e); //NON-NLS
138  }
139 
140  try {
141  System.loadLibrary("zlib"); //NON-NLS
142  logger.log(Level.INFO, "ZLIB library loaded loaded"); //NON-NLS
143  } catch (UnsatisfiedLinkError e) {
144  logger.log(Level.SEVERE, "Error loading ZLIB library, ", e); //NON-NLS
145  }
146 
147  try {
148  System.loadLibrary("libewf"); //NON-NLS
149  logger.log(Level.INFO, "EWF library loaded"); //NON-NLS
150  } catch (UnsatisfiedLinkError e) {
151  logger.log(Level.SEVERE, "Error loading EWF library, ", e); //NON-NLS
152  }
153 
154  try {
155  System.loadLibrary("libvmdk"); //NON-NLS
156  logger.log(Level.INFO, "VMDK library loaded"); //NON-NLS
157  } catch (UnsatisfiedLinkError e) {
158  logger.log(Level.SEVERE, "Error loading VMDK library, ", e); //NON-NLS
159  }
160 
161  try {
162  System.loadLibrary("libvhdi"); //NON-NLS
163  logger.log(Level.INFO, "VHDI library loaded"); //NON-NLS
164  } catch (UnsatisfiedLinkError e) {
165  logger.log(Level.SEVERE, "Error loading VHDI library, ", e); //NON-NLS
166  }
167 
168  // Only attempt to load OpenSSL if we're in 64 bit mode
169  if(System.getProperty("sun.arch.data.model").contains("64")) {
170  // libcrypto must be loaded before libssl to make sure it's the correct version
171  try {
172  System.loadLibrary("libcrypto-1_1-x64"); //NON-NLS
173  logger.log(Level.INFO, "Crypto library loaded"); //NON-NLS
174  } catch (UnsatisfiedLinkError e) {
175  logger.log(Level.SEVERE, "Error loading Crypto library, ", e); //NON-NLS
176  }
177 
178  try {
179  System.loadLibrary("libssl-1_1-x64"); //NON-NLS
180  logger.log(Level.INFO, "OpenSSL library loaded"); //NON-NLS
181  } catch (UnsatisfiedLinkError e) {
182  logger.log(Level.SEVERE, "Error loading OpenSSL library, ", e); //NON-NLS
183  }
184  }
185  }
186  }
187 
188  public Installer() {
189  logger.log(Level.INFO, "core installer created"); //NON-NLS
190  javaFxInit = false;
191 
192  // Prevent the Autopsy UI from shrinking on high DPI displays
193  System.setProperty("sun.java2d.dpiaware", "false");
194  System.setProperty("prism.allowhidpi", "false");
195 
196  // Update existing configuration in case of unsupported settings
197  updateConfig();
198 
199  packageInstallers = new ArrayList<>();
200  packageInstallers.add(org.sleuthkit.autopsy.coreutils.Installer.getDefault());
201  packageInstallers.add(org.sleuthkit.autopsy.corecomponents.Installer.getDefault());
202  packageInstallers.add(org.sleuthkit.autopsy.datamodel.Installer.getDefault());
203  packageInstallers.add(org.sleuthkit.autopsy.ingest.Installer.getDefault());
205  packageInstallers.add(org.sleuthkit.autopsy.healthmonitor.Installer.getDefault());
206  packageInstallers.add(org.sleuthkit.autopsy.casemodule.Installer.getDefault());
207 
217  try {
218  FileTypeDetector fileTypeDetector = new FileTypeDetector();
220  logger.log(Level.SEVERE, "Failed to load file type detector.", ex);
221  }
222  }
223 
228  private void updateConfig() {
229  String mode = ModuleSettings.getConfigSetting(SETTINGS_PROPERTIES, "AutopsyMode");
230  if (mode != null) {
231  int ordinal = Integer.parseInt(mode);
232  if (ordinal > 1) {
234  ModuleSettings.setConfigSetting(UserPreferences.SETTINGS_PROPERTIES, "JoinAutoModeCluster", Boolean.toString(false));
235  }
236  }
237  }
238 
245  public static boolean isJavaFxInited() {
246  return javaFxInit;
247  }
248 
249  private static void initJavaFx() {
250  //initialize java fx if exists
251  System.setProperty("javafx.macosx.embedded", "true");
252  try {
253  // Creating a JFXPanel initializes JavaFX
254  JFXPanel panel = new JFXPanel();
255  Platform.setImplicitExit(false);
256  javaFxInit = true;
257  } catch (UnsatisfiedLinkError | NoClassDefFoundError | Exception e) {
258  //in case javafx not present
259  final String msg = NbBundle.getMessage(Installer.class, "Installer.errorInitJavafx.msg");
260  final String details = NbBundle.getMessage(Installer.class, "Installer.errorInitJavafx.details");
261  logger.log(Level.SEVERE, msg
262  + details, e);
263 
264  WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
265  @Override
266  public void run() {
267  MessageNotifyUtil.Notify.error(msg, details);
268  }
269  });
270  }
271  }
272 
278  private static void addGstreamerPathsToEnv() {
279  if (System.getProperty("jna.nosys") == null) {
280  System.setProperty("jna.nosys", "true");
281  }
282 
283  Path gstreamerPath = InstalledFileLocator.getDefault().locate("gstreamer", Installer.class.getPackage().getName(), false).toPath();
284 
285  if (gstreamerPath == null) {
286  logger.log(Level.SEVERE, "Failed to find GStreamer.");
287  } else {
288  String arch = "x86_64";
289  if (!PlatformUtil.is64BitJVM()) {
290  arch = "x86";
291  }
292 
293  Path gstreamerBasePath = Paths.get(gstreamerPath.toString(), "1.0", arch);
294  Path gstreamerBinPath = Paths.get(gstreamerBasePath.toString(), "bin");
295  Path gstreamerLibPath = Paths.get(gstreamerBasePath.toString(), "lib", "gstreamer-1.0");
296 
297  // Update the PATH environment variable to contain the GStreamer
298  // lib and bin paths.
299  Kernel32 k32 = Kernel32.INSTANCE;
300  String path = System.getenv("PATH");
301  if (StringUtils.isBlank(path)) {
302  k32.SetEnvironmentVariable("PATH", gstreamerLibPath.toString());
303  } else {
304  /*
305  * Note that we *prepend* the paths so that the Gstreamer
306  * binaries associated with the current release are found rather
307  * than binaries associated with an earlier version of Autopsy.
308  */
309  k32.SetEnvironmentVariable("PATH", gstreamerBinPath.toString() + File.pathSeparator + gstreamerLibPath.toString() + path);
310  }
311  }
312  }
313 
318  private static void ensureClassifierFolderExists() {
319  File objectDetectionClassifierDir = new File(PlatformUtil.getObjectDetectionClassifierPath());
320  objectDetectionClassifierDir.mkdir();
321  }
322 
327  private static void ensurePythonModulesFolderExists() {
328  File pythonModulesDir = new File(PlatformUtil.getUserPythonModulesPath());
329  pythonModulesDir.mkdir();
330  }
331 
336  private static void ensureOcrLanguagePacksFolderExists() {
337  File ocrLanguagePacksDir = new File(PlatformUtil.getOcrLanguagePacksPath());
338  boolean createDirectory = ocrLanguagePacksDir.mkdir();
339 
340  //If the directory did not exist, copy the tessdata folder over so we
341  //support english.
342  if (createDirectory) {
343  File tessdataDir = InstalledFileLocator.getDefault().locate(
344  "Tesseract-OCR/tessdata", Installer.class.getPackage().getName(), false);
345  try {
346  FileUtils.copyDirectory(tessdataDir, ocrLanguagePacksDir);
347  } catch (IOException ex) {
348  logger.log(Level.SEVERE, "Copying over default language packs for Tesseract failed.", ex);
349  }
350  }
351  }
352 
353  @Override
354  public void restored() {
355  super.restored();
359  initJavaFx();
361  for (ModuleInstall mi : packageInstallers) {
362  try {
363  mi.restored();
364  logger.log(Level.INFO, "{0} restore succeeded", mi.getClass().getName()); //NON-NLS
365  } catch (Exception e) {
366  String msg = mi.getClass().getName() + " restore failed"; //NON-NLS
367  logger.log(Level.WARNING, msg, e);
368  }
369  }
370  logger.log(Level.INFO, "Autopsy Core restore completed"); //NON-NLS
371  preloadJython();
372  }
373 
379  private void initializeSevenZip() {
380  try {
381  SevenZip.initSevenZipFromPlatformJAR();
382  logger.log(Level.INFO, "7zip-java bindings loaded"); //NON-NLS
383  } catch (SevenZipNativeInitializationException e) {
384  logger.log(Level.SEVERE, "Error loading 7zip-java bindings", e); //NON-NLS
385  }
386  }
387 
391  private void preloadJython() {
392  Runnable loader = () -> {
393  try {
396  } catch (Exception ex) {
397  // This is a firewall exception to ensure that any possible exception caused
398  // by this initial load of the Jython modules are caught and logged.
399  logger.log(Level.SEVERE, "There was an error while doing an initial load of python plugins.", ex);
400  }
401 
402  };
403  new Thread(loader).start();
404  }
405 
406  @Override
407  public void validate() throws IllegalStateException {
408  super.validate();
409 
410  logger.log(Level.INFO, "validate()"); //NON-NLS
411  for (ModuleInstall mi : packageInstallers) {
412  logger.log(Level.INFO, "{0} validate()", mi.getClass().getName()); //NON-NLS
413  try {
414  mi.validate();
415  } catch (IllegalStateException e) {
416  logger.log(Level.WARNING, "", e);
417  }
418  }
419  }
420 
421  @Override
422  public void uninstalled() {
423  super.uninstalled();
424 
425  logger.log(Level.INFO, "uninstalled()"); //NON-NLS
426 
427  for (ModuleInstall mi : packageInstallers) {
428  logger.log(Level.INFO, "{0} uninstalled()", mi.getClass().getName()); //NON-NLS
429  try {
430  mi.uninstalled();
431  } catch (Exception e) {
432  logger.log(Level.WARNING, "", e);
433  }
434  }
435  }
436 
437  @NbBundle.Messages({
438  "Installer.closing.confirmationDialog.title=Ingest is Running",
439  "Installer.closing.confirmationDialog.message=Ingest is running, are you sure you want to exit?",
440  "# {0} - exception message", "Installer.closing.messageBox.caseCloseExceptionMessage=Error closing case: {0}"
441  })
442  @Override
443  public boolean closing() {
444  if (IngestRunningCheck.checkAndConfirmProceed(Bundle.Installer_closing_confirmationDialog_title(), Bundle.Installer_closing_confirmationDialog_message())) {
445  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
446  FutureTask<Void> future = new FutureTask<>(new Callable<Void>() {
447  @Override
448  public Void call() throws Exception {
450  return null;
451  }
452  });
453  Thread thread = new Thread(future);
454  thread.start();
455  try {
456  future.get();
457  } catch (InterruptedException ex) {
458  logger.log(Level.SEVERE, "Unexpected interrupt closing the current case", ex);
459  } catch (ExecutionException ex) {
460  logger.log(Level.SEVERE, "Error closing the current case", ex);
461  MessageNotifyUtil.Message.error(Bundle.Installer_closing_messageBox_caseCloseExceptionMessage(ex.getMessage()));
462  } finally {
463  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
464  }
465  return true;
466  } else {
467  return false;
468  }
469  }
470 
471  @Override
472  public void close() {
473  super.close();
474 
475  logger.log(Level.INFO, "close()"); //NON-NLS
476 
477  //exit JavaFx plat
478  if (javaFxInit) {
479  Platform.exit();
480  }
481 
482  for (ModuleInstall mi : packageInstallers) {
483  logger.log(Level.INFO, "{0} close()", mi.getClass().getName()); //NON-NLS
484  try {
485  mi.close();
486  } catch (Exception e) {
487  logger.log(Level.WARNING, "", e);
488  }
489  }
490  for (Handler h : logger.getHandlers()) {
491  h.close(); //must call h.close or a .LCK file will remain.
492  }
493  }
494 }
static synchronized String getConfigSetting(String moduleName, String settingName)
static synchronized List< IngestModuleFactory > getIngestModuleFactories()
static boolean checkAndConfirmProceed(String optionsDlgTitle, String optionsDlgMessage)
static void setMode(SelectedMode mode)
static synchronized Installer getDefault()
Definition: Installer.java:47
static synchronized List< GeneralReportModule > getGeneralReportModules()
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
static volatile boolean javaFxInit
Definition: Installer.java:64
static synchronized Installer getDefault()
Definition: Installer.java:38
static synchronized Installer getDefault()
Definition: Installer.java:33
static void ensureOcrLanguagePacksFolderExists()
Definition: Installer.java:336
static synchronized Installer getDefault()
Definition: Installer.java:31
static void error(String title, String message)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
final List< ModuleInstall > packageInstallers
Definition: Installer.java:62
static synchronized Installer getDefault()
Definition: Installer.java:39
static synchronized Installer getDefault()
Definition: Installer.java:35

Copyright © 2012-2020 Basis Technology. Generated on: Tue Sep 22 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.