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

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