Autopsy  4.19.3
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  UserPreferences.updateConfig();
208  updateConfig();
209 
210  packageInstallers = new ArrayList<>();
211  packageInstallers.add(org.sleuthkit.autopsy.coreutils.Installer.getDefault());
212  packageInstallers.add(org.sleuthkit.autopsy.corecomponents.Installer.getDefault());
213  packageInstallers.add(org.sleuthkit.autopsy.datamodel.Installer.getDefault());
214  packageInstallers.add(org.sleuthkit.autopsy.ingest.Installer.getDefault());
216  packageInstallers.add(org.sleuthkit.autopsy.healthmonitor.Installer.getDefault());
217  packageInstallers.add(org.sleuthkit.autopsy.casemodule.Installer.getDefault());
219  packageInstallers.add(org.sleuthkit.autopsy.report.infrastructure.Installer.getDefault());
220 
230  try {
231  FileTypeDetector fileTypeDetector = new FileTypeDetector();
233  logger.log(Level.SEVERE, "Failed to load file type detector.", ex);
234  }
235  }
236 
241  private void updateConfig() {
242  String mode = ModuleSettings.getConfigSetting(SETTINGS_PROPERTIES, "AutopsyMode");
243  if (mode != null) {
244  int ordinal = Integer.parseInt(mode);
245  if (ordinal > 1) {
247  ModuleSettings.setConfigSetting(UserPreferences.SETTINGS_PROPERTIES, "JoinAutoModeCluster", Boolean.toString(false));
248  }
249  }
250  }
251 
258  public static boolean isJavaFxInited() {
259  return javaFxInit;
260  }
261 
262  private static void initJavaFx() {
263  //initialize java fx if exists
264  System.setProperty("javafx.macosx.embedded", "true");
265  try {
266  // Creating a JFXPanel initializes JavaFX
267  JFXPanel panel = new JFXPanel();
268  Platform.setImplicitExit(false);
269  javaFxInit = true;
270  } catch (UnsatisfiedLinkError | NoClassDefFoundError | Exception e) {
271  //in case javafx not present
272  final String msg = NbBundle.getMessage(Installer.class, "Installer.errorInitJavafx.msg");
273  final String details = NbBundle.getMessage(Installer.class, "Installer.errorInitJavafx.details");
274  logger.log(Level.SEVERE, msg
275  + details, e);
276 
277  WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
278  @Override
279  public void run() {
280  MessageNotifyUtil.Notify.error(msg, details);
281  }
282  });
283  }
284  }
285 
291  private static void addGstreamerPathsToEnv() {
292  if (System.getProperty("jna.nosys") == null) {
293  System.setProperty("jna.nosys", "true");
294  }
295 
296  Path gstreamerPath = InstalledFileLocator.getDefault().locate("gstreamer", Installer.class.getPackage().getName(), false).toPath();
297 
298  if (gstreamerPath == null) {
299  logger.log(Level.SEVERE, "Failed to find GStreamer.");
300  } else {
301  String arch = "x86_64";
302  if (!PlatformUtil.is64BitJVM()) {
303  arch = "x86";
304  }
305 
306  Path gstreamerBasePath = Paths.get(gstreamerPath.toString(), "1.0", arch);
307  Path gstreamerBinPath = Paths.get(gstreamerBasePath.toString(), "bin");
308  Path gstreamerLibPath = Paths.get(gstreamerBasePath.toString(), "lib", "gstreamer-1.0");
309 
310  // Update the PATH environment variable to contain the GStreamer
311  // lib and bin paths.
312  Kernel32 k32 = Kernel32.INSTANCE;
313  String path = System.getenv("PATH");
314  if (StringUtils.isBlank(path)) {
315  k32.SetEnvironmentVariable("PATH", gstreamerLibPath.toString());
316  } else {
317  /*
318  * Note that we *prepend* the paths so that the Gstreamer
319  * binaries associated with the current release are found rather
320  * than binaries associated with an earlier version of Autopsy.
321  */
322  k32.SetEnvironmentVariable("PATH", gstreamerBinPath.toString() + File.pathSeparator + gstreamerLibPath.toString() + path);
323  }
324  }
325  }
326 
331  private static void ensureClassifierFolderExists() {
332  File objectDetectionClassifierDir = new File(PlatformUtil.getObjectDetectionClassifierPath());
333  objectDetectionClassifierDir.mkdir();
334  }
335 
340  private static void ensurePythonModulesFolderExists() {
341  File pythonModulesDir = new File(PlatformUtil.getUserPythonModulesPath());
342  pythonModulesDir.mkdir();
343  }
344 
349  private static void ensureOcrLanguagePacksFolderExists() {
350  File ocrLanguagePacksDir = new File(PlatformUtil.getOcrLanguagePacksPath());
351  boolean createDirectory = ocrLanguagePacksDir.mkdir();
352 
353  //If the directory did not exist, copy the tessdata folder over so we
354  //support english.
355  if (createDirectory) {
356  File tessdataDir = InstalledFileLocator.getDefault().locate(
357  "Tesseract-OCR/tessdata", Installer.class.getPackage().getName(), false);
358  try {
359  FileUtils.copyDirectory(tessdataDir, ocrLanguagePacksDir);
360  } catch (IOException ex) {
361  logger.log(Level.SEVERE, "Copying over default language packs for Tesseract failed.", ex);
362  }
363  }
364  }
365 
366  @Override
367  public void restored() {
368  super.restored();
372  initJavaFx();
374  for (ModuleInstall mi : packageInstallers) {
375  try {
376  mi.restored();
377  logger.log(Level.INFO, "{0} restore succeeded", mi.getClass().getName()); //NON-NLS
378  } catch (Exception e) {
379  String msg = mi.getClass().getName() + " restore failed"; //NON-NLS
380  logger.log(Level.WARNING, msg, e);
381  }
382  }
383  logger.log(Level.INFO, "Autopsy Core restore completed"); //NON-NLS
384  preloadJython();
386  }
387 
393  private static void initializeSevenZip() {
394  try {
395  SevenZip.initSevenZipFromPlatformJAR();
396  logger.log(Level.INFO, "7zip-java bindings loaded"); //NON-NLS
397  } catch (SevenZipNativeInitializationException e) {
398  logger.log(Level.SEVERE, "Error loading 7zip-java bindings", e); //NON-NLS
399  }
400  }
401 
405  private static void preloadJython() {
406  Runnable loader = () -> {
407  try {
411  } catch (Exception ex) {
412  // This is a firewall exception to ensure that any possible exception caused
413  // by this initial load of the Jython modules are caught and logged.
414  logger.log(Level.SEVERE, "There was an error while doing an initial load of python plugins.", ex);
415  }
416 
417  };
418  new Thread(loader).start();
419  }
420 
424  private static void preloadTranslationServices() {
425  Runnable loader = () -> {
426  try {
428  } catch (Exception ex) {
429  // This is a firewall exception to ensure that any possible exception caused
430  // by this initial load of the translation modules are caught and logged.
431  logger.log(Level.SEVERE, "There was an error while doing an initial load of translation services.", ex);
432  }
433  };
434  new Thread(loader).start();
435  }
436 
437  @Override
438  public void validate() throws IllegalStateException {
439  super.validate();
440 
441  logger.log(Level.INFO, "validate()"); //NON-NLS
442  for (ModuleInstall mi : packageInstallers) {
443  logger.log(Level.INFO, "{0} validate()", mi.getClass().getName()); //NON-NLS
444  try {
445  mi.validate();
446  } catch (IllegalStateException e) {
447  logger.log(Level.WARNING, "", e);
448  }
449  }
450  }
451 
452  @Override
453  public void uninstalled() {
454  super.uninstalled();
455 
456  logger.log(Level.INFO, "uninstalled()"); //NON-NLS
457 
458  for (ModuleInstall mi : packageInstallers) {
459  logger.log(Level.INFO, "{0} uninstalled()", mi.getClass().getName()); //NON-NLS
460  try {
461  mi.uninstalled();
462  } catch (Exception e) {
463  logger.log(Level.WARNING, "", e);
464  }
465  }
466  }
467 
468  @NbBundle.Messages({
469  "Installer.closing.confirmationDialog.title=Ingest is Running",
470  "Installer.closing.confirmationDialog.message=Ingest is running, are you sure you want to exit?",
471  "# {0} - exception message", "Installer.closing.messageBox.caseCloseExceptionMessage=Error closing case: {0}"
472  })
473  @Override
474  public boolean closing() {
475  if (IngestRunningCheck.checkAndConfirmProceed(Bundle.Installer_closing_confirmationDialog_title(), Bundle.Installer_closing_confirmationDialog_message())) {
476  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
477  FutureTask<Void> future = new FutureTask<>(new Callable<Void>() {
478  @Override
479  public Void call() throws Exception {
481  return null;
482  }
483  });
484  Thread thread = new Thread(future);
485  thread.start();
486  try {
487  future.get();
488  } catch (InterruptedException ex) {
489  logger.log(Level.SEVERE, "Unexpected interrupt closing the current case", ex);
490  } catch (ExecutionException ex) {
491  logger.log(Level.SEVERE, "Error closing the current case", ex);
492  MessageNotifyUtil.Message.error(Bundle.Installer_closing_messageBox_caseCloseExceptionMessage(ex.getMessage()));
493  } finally {
494  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
495  }
496  return true;
497  } else {
498  return false;
499  }
500  }
501 
502  @Override
503  public void close() {
504  super.close();
505 
506  logger.log(Level.INFO, "close()"); //NON-NLS
507 
508  //exit JavaFx plat
509  if (javaFxInit) {
510  Platform.exit();
511  }
512 
513  for (ModuleInstall mi : packageInstallers) {
514  logger.log(Level.INFO, "{0} close()", mi.getClass().getName()); //NON-NLS
515  try {
516  mi.close();
517  } catch (Exception e) {
518  logger.log(Level.WARNING, "", e);
519  }
520  }
521  for (Handler h : logger.getHandlers()) {
522  h.close(); //must call h.close or a .LCK file will remain.
523  }
524  }
525 }
static synchronized String getConfigSetting(String moduleName, String settingName)
static synchronized List< IngestModuleFactory > getIngestModuleFactories()
static synchronized Installer getDefault()
Definition: Installer.java:41
static boolean checkAndConfirmProceed(String optionsDlgTitle, String optionsDlgMessage)
static void setMode(SelectedMode mode)
static synchronized Installer getDefault()
Definition: Installer.java:56
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:349
static synchronized Installer getDefault()
Definition: Installer.java:50
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 List< DataSourceProcessor > getDataSourceProcessorModules()
static synchronized Installer getDefault()
Definition: Installer.java:35

Copyright © 2012-2022 Basis Technology. Generated on: Tue Mar 21 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.