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

Copyright © 2012-2018 Basis Technology. Generated on: Wed Sep 18 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.