Autopsy  4.15.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 org.apache.commons.io.FileUtils;
37 import org.apache.commons.lang3.StringUtils;
38 import org.openide.modules.InstalledFileLocator;
39 import org.openide.modules.ModuleInstall;
40 import org.openide.util.NbBundle;
41 import org.openide.windows.WindowManager;
51 
56 public class Installer extends ModuleInstall {
57 
58  private static final long serialVersionUID = 1L;
59 
60  private final List<ModuleInstall> packageInstallers;
61  private static final Logger logger = Logger.getLogger(Installer.class.getName());
62  private static volatile boolean javaFxInit = false;
63 
64  static {
66  }
67 
68  private static void loadDynLibraries() {
69  /*
70  * On Windows, we distribute dlls that libtsk_jni depend on. If
71  * libtsk_jni tries to load them, they will not be found by Windows
72  * because they are in special NetBeans folders. So, we manually load
73  * them from within Autopsy so that they are found via the NetBeans
74  * loading setup. These are copied by the build script when making the
75  * ZIP file. In a development environment they will need to be loaded
76  * from standard places in your system.
77  *
78  * On non-Windows platforms, we assume the dependncies are all installed
79  * and loadable (i.e. a 'make install' was done).
80  */
81  if (PlatformUtil.isWindowsOS()) {
82  try {
84 
85  //Note: if shipping with a different CRT version, this will only print a warning
86  //and try to use linker mechanism to find the correct versions of libs.
87  //We should update this if we officially switch to a new version of CRT/compiler
88  System.loadLibrary("api-ms-win-core-console-l1-1-0"); //NON-NLS
89  System.loadLibrary("api-ms-win-core-datetime-l1-1-0"); //NON-NLS
90  System.loadLibrary("api-ms-win-core-debug-l1-1-0"); //NON-NLS
91  System.loadLibrary("api-ms-win-core-errorhandling-l1-1-0"); //NON-NLS
92  System.loadLibrary("api-ms-win-core-file-l1-1-0"); //NON-NLS
93  System.loadLibrary("api-ms-win-core-file-l1-2-0"); //NON-NLS
94  System.loadLibrary("api-ms-win-core-file-l2-1-0"); //NON-NLS
95  System.loadLibrary("api-ms-win-core-handle-l1-1-0"); //NON-NLS
96  System.loadLibrary("api-ms-win-core-heap-l1-1-0"); //NON-NLS
97  System.loadLibrary("api-ms-win-core-interlocked-l1-1-0"); //NON-NLS
98  System.loadLibrary("api-ms-win-core-libraryloader-l1-1-0"); //NON-NLS
99  System.loadLibrary("api-ms-win-core-localization-l1-2-0"); //NON-NLS
100  System.loadLibrary("api-ms-win-core-memory-l1-1-0"); //NON-NLS
101  System.loadLibrary("api-ms-win-core-namedpipe-l1-1-0"); //NON-NLS
102  System.loadLibrary("api-ms-win-core-processenvironment-l1-1-0"); //NON-NLS
103  System.loadLibrary("api-ms-win-core-processthreads-l1-1-0"); //NON-NLS
104  System.loadLibrary("api-ms-win-core-processthreads-l1-1-1"); //NON-NLS
105  System.loadLibrary("api-ms-win-core-profile-l1-1-0"); //NON-NLS
106  System.loadLibrary("api-ms-win-core-rtlsupport-l1-1-0"); //NON-NLS
107  System.loadLibrary("api-ms-win-core-string-l1-1-0"); //NON-NLS
108  System.loadLibrary("api-ms-win-core-synch-l1-1-0"); //NON-NLS
109  System.loadLibrary("api-ms-win-core-synch-l1-2-0"); //NON-NLS
110  System.loadLibrary("api-ms-win-core-sysinfo-l1-1-0"); //NON-NLS
111  System.loadLibrary("api-ms-win-core-timezone-l1-1-0"); //NON-NLS
112  System.loadLibrary("api-ms-win-core-util-l1-1-0"); //NON-NLS
113  System.loadLibrary("api-ms-win-crt-conio-l1-1-0"); //NON-NLS
114  System.loadLibrary("api-ms-win-crt-convert-l1-1-0"); //NON-NLS
115  System.loadLibrary("api-ms-win-crt-environment-l1-1-0"); //NON-NLS
116  System.loadLibrary("api-ms-win-crt-filesystem-l1-1-0"); //NON-NLS
117  System.loadLibrary("api-ms-win-crt-heap-l1-1-0"); //NON-NLS
118  System.loadLibrary("api-ms-win-crt-locale-l1-1-0"); //NON-NLS
119  System.loadLibrary("api-ms-win-crt-math-l1-1-0"); //NON-NLS
120  System.loadLibrary("api-ms-win-crt-multibyte-l1-1-0"); //NON-NLS
121  System.loadLibrary("api-ms-win-crt-private-l1-1-0"); //NON-NLS
122  System.loadLibrary("api-ms-win-crt-process-l1-1-0"); //NON-NLS
123  System.loadLibrary("api-ms-win-crt-runtime-l1-1-0"); //NON-NLS
124  System.loadLibrary("api-ms-win-crt-stdio-l1-1-0"); //NON-NLS
125  System.loadLibrary("api-ms-win-crt-string-l1-1-0"); //NON-NLS
126  System.loadLibrary("api-ms-win-crt-time-l1-1-0"); //NON-NLS
127  System.loadLibrary("api-ms-win-crt-utility-l1-1-0"); //NON-NLS
128 
129  System.loadLibrary("ucrtbase"); //NON-NLS
130  System.loadLibrary("vcruntime140"); //NON-NLS
131  System.loadLibrary("msvcp140"); //NON-NLS
132 
133  logger.log(Level.INFO, "Visual C Runtime libraries loaded"); //NON-NLS
134  } catch (UnsatisfiedLinkError e) {
135  logger.log(Level.SEVERE, "Error loading Visual C Runtime libraries, ", e); //NON-NLS
136  }
137 
138  try {
139  System.loadLibrary("zlib"); //NON-NLS
140  logger.log(Level.INFO, "ZLIB library loaded loaded"); //NON-NLS
141  } catch (UnsatisfiedLinkError e) {
142  logger.log(Level.SEVERE, "Error loading ZLIB library, ", e); //NON-NLS
143  }
144 
145  try {
146  System.loadLibrary("libewf"); //NON-NLS
147  logger.log(Level.INFO, "EWF library loaded"); //NON-NLS
148  } catch (UnsatisfiedLinkError e) {
149  logger.log(Level.SEVERE, "Error loading EWF library, ", e); //NON-NLS
150  }
151 
152  try {
153  System.loadLibrary("libvmdk"); //NON-NLS
154  logger.log(Level.INFO, "VMDK library loaded"); //NON-NLS
155  } catch (UnsatisfiedLinkError e) {
156  logger.log(Level.SEVERE, "Error loading VMDK library, ", e); //NON-NLS
157  }
158 
159  try {
160  System.loadLibrary("libvhdi"); //NON-NLS
161  logger.log(Level.INFO, "VHDI library loaded"); //NON-NLS
162  } catch (UnsatisfiedLinkError e) {
163  logger.log(Level.SEVERE, "Error loading VHDI library, ", e); //NON-NLS
164  }
165 
166  /*
167  * PostgreSQL
168  */
169  try {
170  System.loadLibrary("msvcr120"); //NON-NLS
171  logger.log(Level.INFO, "MSVCR 120 library loaded"); //NON-NLS
172  } catch (UnsatisfiedLinkError e) {
173  logger.log(Level.SEVERE, "Error loading MSVCR120 library, ", e); //NON-NLS
174  }
175 
176  try {
177  System.loadLibrary("libeay32"); //NON-NLS
178  logger.log(Level.INFO, "LIBEAY32 library loaded"); //NON-NLS
179  } catch (UnsatisfiedLinkError e) {
180  logger.log(Level.SEVERE, "Error loading LIBEAY32 library, ", e); //NON-NLS
181  }
182 
183  try {
184  System.loadLibrary("ssleay32"); //NON-NLS
185  logger.log(Level.INFO, "SSLEAY32 library loaded"); //NON-NLS
186  } catch (UnsatisfiedLinkError e) {
187  logger.log(Level.SEVERE, "Error loading SSLEAY32 library, ", e); //NON-NLS
188  }
189 
190  try {
191  System.loadLibrary("libiconv-2"); //NON-NLS
192  logger.log(Level.INFO, "libiconv-2 library loaded"); //NON-NLS
193  } catch (UnsatisfiedLinkError e) {
194  logger.log(Level.SEVERE, "Error loading libiconv-2 library, ", e); //NON-NLS
195  }
196 
197  try {
198  System.loadLibrary("libintl-8"); //NON-NLS
199  logger.log(Level.INFO, "libintl-8 library loaded"); //NON-NLS
200  } catch (UnsatisfiedLinkError e) {
201  logger.log(Level.SEVERE, "Error loading libintl-8 library, ", e); //NON-NLS
202  }
203 
204  try {
205  System.loadLibrary("libpq"); //NON-NLS
206  logger.log(Level.INFO, "LIBPQ library loaded"); //NON-NLS
207  } catch (UnsatisfiedLinkError e) {
208  logger.log(Level.SEVERE, "Error loading LIBPQ library, ", e); //NON-NLS
209  }
210  }
211  }
212 
213  public Installer() {
214  logger.log(Level.INFO, "core installer created"); //NON-NLS
215  javaFxInit = false;
216 
217  // Prevent the Autopsy UI from shrinking on high DPI displays
218  System.setProperty("sun.java2d.dpiaware", "false");
219  System.setProperty("prism.allowhidpi", "false");
220 
221  // Update existing configuration in case of unsupported settings
222  updateConfig();
223 
224  packageInstallers = new ArrayList<>();
225  packageInstallers.add(org.sleuthkit.autopsy.coreutils.Installer.getDefault());
226  packageInstallers.add(org.sleuthkit.autopsy.corecomponents.Installer.getDefault());
227  packageInstallers.add(org.sleuthkit.autopsy.datamodel.Installer.getDefault());
228  packageInstallers.add(org.sleuthkit.autopsy.ingest.Installer.getDefault());
230  packageInstallers.add(org.sleuthkit.autopsy.healthmonitor.Installer.getDefault());
231 
241  try {
242  FileTypeDetector fileTypeDetector = new FileTypeDetector();
244  logger.log(Level.SEVERE, "Failed to load file type detector.", ex);
245  }
246  }
247 
252  private void updateConfig() {
253  String mode = ModuleSettings.getConfigSetting(SETTINGS_PROPERTIES, "AutopsyMode");
254  if (mode != null) {
255  int ordinal = Integer.parseInt(mode);
256  if (ordinal > 1) {
258  ModuleSettings.setConfigSetting(UserPreferences.SETTINGS_PROPERTIES, "JoinAutoModeCluster", Boolean.toString(false));
259  }
260  }
261  }
262 
269  public static boolean isJavaFxInited() {
270  return javaFxInit;
271  }
272 
273  private static void initJavaFx() {
274  //initialize java fx if exists
275  System.setProperty("javafx.macosx.embedded", "true");
276  try {
277  // Creating a JFXPanel initializes JavaFX
278  JFXPanel panel = new JFXPanel();
279  Platform.setImplicitExit(false);
280  javaFxInit = true;
281  } catch (UnsatisfiedLinkError | NoClassDefFoundError | Exception e) {
282  //in case javafx not present
283  final String msg = NbBundle.getMessage(Installer.class, "Installer.errorInitJavafx.msg");
284  final String details = NbBundle.getMessage(Installer.class, "Installer.errorInitJavafx.details");
285  logger.log(Level.SEVERE, msg
286  + details, e);
287 
288  WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
289  @Override
290  public void run() {
291  MessageNotifyUtil.Notify.error(msg, details);
292  }
293  });
294  }
295  }
296 
302  private static void addGstreamerPathsToEnv() {
303  if (System.getProperty("jna.nosys") == null) {
304  System.setProperty("jna.nosys", "true");
305  }
306 
307  Path gstreamerPath = InstalledFileLocator.getDefault().locate("gstreamer", Installer.class.getPackage().getName(), false).toPath();
308 
309  if (gstreamerPath == null) {
310  logger.log(Level.SEVERE, "Failed to find GStreamer.");
311  } else {
312  String arch = "x86_64";
313  if (!PlatformUtil.is64BitJVM()) {
314  arch = "x86";
315  }
316 
317  Path gstreamerBasePath = Paths.get(gstreamerPath.toString(), "1.0", arch);
318  Path gstreamerBinPath = Paths.get(gstreamerBasePath.toString(), "bin");
319  Path gstreamerLibPath = Paths.get(gstreamerBasePath.toString(), "lib", "gstreamer-1.0");
320 
321  // Update the PATH environment variable to contain the GStreamer
322  // lib and bin paths.
323  Kernel32 k32 = Kernel32.INSTANCE;
324  String path = System.getenv("PATH");
325  if (StringUtils.isBlank(path)) {
326  k32.SetEnvironmentVariable("PATH", gstreamerLibPath.toString());
327  } else {
328  /*
329  * Note that we *prepend* the paths so that the Gstreamer
330  * binaries associated with the current release are found rather
331  * than binaries associated with an earlier version of Autopsy.
332  */
333  k32.SetEnvironmentVariable("PATH", gstreamerBinPath.toString() + File.pathSeparator + gstreamerLibPath.toString() + path);
334  }
335  }
336  }
337 
342  private static void ensureClassifierFolderExists() {
343  File objectDetectionClassifierDir = new File(PlatformUtil.getObjectDetectionClassifierPath());
344  objectDetectionClassifierDir.mkdir();
345  }
346 
351  private static void ensurePythonModulesFolderExists() {
352  File pythonModulesDir = new File(PlatformUtil.getUserPythonModulesPath());
353  pythonModulesDir.mkdir();
354  }
355 
360  private static void ensureOcrLanguagePacksFolderExists() {
361  File ocrLanguagePacksDir = new File(PlatformUtil.getOcrLanguagePacksPath());
362  boolean createDirectory = ocrLanguagePacksDir.mkdir();
363 
364  //If the directory did not exist, copy the tessdata folder over so we
365  //support english.
366  if (createDirectory) {
367  File tessdataDir = InstalledFileLocator.getDefault().locate(
368  "Tesseract-OCR/tessdata", Installer.class.getPackage().getName(), false);
369  try {
370  FileUtils.copyDirectory(tessdataDir, ocrLanguagePacksDir);
371  } catch (IOException ex) {
372  logger.log(Level.SEVERE, "Copying over default language packs for Tesseract failed.", ex);
373  }
374  }
375  }
376 
377  @Override
378  public void restored() {
379  super.restored();
383  initJavaFx();
384  for (ModuleInstall mi : packageInstallers) {
385  try {
386  mi.restored();
387  logger.log(Level.INFO, "{0} restore succeeded", mi.getClass().getName()); //NON-NLS
388  } catch (Exception e) {
389  String msg = mi.getClass().getName() + " restore failed"; //NON-NLS
390  logger.log(Level.WARNING, msg, e);
391  }
392  }
393  logger.log(Level.INFO, "Autopsy Core restore completed"); //NON-NLS
394  preloadJython();
395  }
396 
397 
401  private void preloadJython() {
402  Runnable loader = () -> {
403  try {
406  }
407  catch (Exception ex) {
408  // This is a firewall exception to ensure that any possible exception caused
409  // by this initial load of the Jython modules are caught and logged.
410  logger.log(Level.SEVERE, "There was an error while doing an initial load of python plugins.", ex);
411  }
412 
413  };
414  new Thread(loader).start();
415  }
416 
417  @Override
418  public void validate() throws IllegalStateException {
419  super.validate();
420 
421  logger.log(Level.INFO, "validate()"); //NON-NLS
422  for (ModuleInstall mi : packageInstallers) {
423  logger.log(Level.INFO, "{0} validate()", mi.getClass().getName()); //NON-NLS
424  try {
425  mi.validate();
426  } catch (IllegalStateException e) {
427  logger.log(Level.WARNING, "", e);
428  }
429  }
430  }
431 
432  @Override
433  public void uninstalled() {
434  super.uninstalled();
435 
436  logger.log(Level.INFO, "uninstalled()"); //NON-NLS
437 
438  for (ModuleInstall mi : packageInstallers) {
439  logger.log(Level.INFO, "{0} uninstalled()", mi.getClass().getName()); //NON-NLS
440  try {
441  mi.uninstalled();
442  } catch (Exception e) {
443  logger.log(Level.WARNING, "", e);
444  }
445  }
446  }
447 
448  @NbBundle.Messages({
449  "Installer.closing.confirmationDialog.title=Ingest is Running",
450  "Installer.closing.confirmationDialog.message=Ingest is running, are you sure you want to exit?",
451  "# {0} - exception message", "Installer.closing.messageBox.caseCloseExceptionMessage=Error closing case: {0}"
452  })
453  @Override
454  public boolean closing() {
455  if (IngestRunningCheck.checkAndConfirmProceed(Bundle.Installer_closing_confirmationDialog_title(), Bundle.Installer_closing_confirmationDialog_message())) {
456  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
457  FutureTask<Void> future = new FutureTask<>(new Callable<Void>() {
458  @Override
459  public Void call() throws Exception {
461  return null;
462  }
463  });
464  Thread thread = new Thread(future);
465  thread.start();
466  try {
467  future.get();
468  } catch (InterruptedException ex) {
469  logger.log(Level.SEVERE, "Unexpected interrupt closing the current case", ex);
470  } catch (ExecutionException ex) {
471  logger.log(Level.SEVERE, "Error closing the current case", ex);
472  MessageNotifyUtil.Message.error(Bundle.Installer_closing_messageBox_caseCloseExceptionMessage(ex.getMessage()));
473  } finally {
474  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
475  }
476  return true;
477  } else {
478  return false;
479  }
480  }
481 
482  @Override
483  public void close() {
484  super.close();
485 
486  logger.log(Level.INFO, "close()"); //NON-NLS
487 
488  //exit JavaFx plat
489  if (javaFxInit) {
490  Platform.exit();
491  }
492 
493  for (ModuleInstall mi : packageInstallers) {
494  logger.log(Level.INFO, "{0} close()", mi.getClass().getName()); //NON-NLS
495  try {
496  mi.close();
497  } catch (Exception e) {
498  logger.log(Level.WARNING, "", e);
499  }
500  }
501  for (Handler h : logger.getHandlers()) {
502  h.close(); //must call h.close or a .LCK file will remain.
503  }
504  }
505 }
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:62
static synchronized Installer getDefault()
Definition: Installer.java:38
static synchronized Installer getDefault()
Definition: Installer.java:33
static void ensureOcrLanguagePacksFolderExists()
Definition: Installer.java:360
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:60
static synchronized Installer getDefault()
Definition: Installer.java:35

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