Autopsy  4.21.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.awt.GraphicsEnvironment;
24 import java.io.File;
25 import java.io.IOException;
26 import java.lang.management.ManagementFactory;
27 import java.nio.file.Path;
28 import java.nio.file.Paths;
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.concurrent.Callable;
32 import java.util.concurrent.ExecutionException;
33 import java.util.concurrent.FutureTask;
34 import java.util.logging.Handler;
35 import java.util.logging.Level;
36 import javafx.application.Platform;
37 import javafx.embed.swing.JFXPanel;
38 import javax.imageio.ImageIO;
39 import javax.swing.JOptionPane;
40 import net.sf.sevenzipjbinding.SevenZip;
41 import net.sf.sevenzipjbinding.SevenZipNativeInitializationException;
42 import org.apache.commons.io.FileUtils;
43 import org.apache.commons.lang3.StringUtils;
44 import org.openide.modules.InstalledFileLocator;
45 import org.openide.modules.ModuleInstall;
46 import org.openide.util.NbBundle;
47 import org.openide.util.NbBundle.Messages;
48 import org.openide.windows.WindowManager;
60 
65 public class Installer extends ModuleInstall {
66 
67  private static final long serialVersionUID = 1L;
68 
69  private final List<ModuleInstall> packageInstallers;
70  private static final Logger logger = Logger.getLogger(Installer.class.getName());
71  private static volatile boolean javaFxInit = false;
72 
73  static {
75 
76  // This call was moved from MediaViewImagePanel so that it is
77  // not called during top level component construction.
78  ImageIO.scanForPlugins();
79 
80  // This will cause OpenCvLoader to load its library instead of
82  }
83 
84  private static void loadDynLibraries() {
85  /*
86  * On Windows, we distribute dlls that libtsk_jni depend on. If
87  * libtsk_jni tries to load them, they will not be found by Windows
88  * because they are in special NetBeans folders. So, we manually load
89  * them from within Autopsy so that they are found via the NetBeans
90  * loading setup. These are copied by the build script when making the
91  * ZIP file. In a development environment they will need to be loaded
92  * from standard places in your system.
93  *
94  * On non-Windows platforms, we assume the dependncies are all installed
95  * and loadable (i.e. a 'make install' was done).
96  */
97  if (PlatformUtil.isWindowsOS()) {
98  try {
100 
101  //Note: if shipping with a different CRT version, this will only print a warning
102  //and try to use linker mechanism to find the correct versions of libs.
103  //We should update this if we officially switch to a new version of CRT/compiler
104  System.loadLibrary("api-ms-win-core-console-l1-1-0"); //NON-NLS
105  System.loadLibrary("api-ms-win-core-datetime-l1-1-0"); //NON-NLS
106  System.loadLibrary("api-ms-win-core-debug-l1-1-0"); //NON-NLS
107  System.loadLibrary("api-ms-win-core-errorhandling-l1-1-0"); //NON-NLS
108  System.loadLibrary("api-ms-win-core-file-l1-1-0"); //NON-NLS
109  System.loadLibrary("api-ms-win-core-file-l1-2-0"); //NON-NLS
110  System.loadLibrary("api-ms-win-core-file-l2-1-0"); //NON-NLS
111  System.loadLibrary("api-ms-win-core-handle-l1-1-0"); //NON-NLS
112  System.loadLibrary("api-ms-win-core-heap-l1-1-0"); //NON-NLS
113  System.loadLibrary("api-ms-win-core-interlocked-l1-1-0"); //NON-NLS
114  System.loadLibrary("api-ms-win-core-libraryloader-l1-1-0"); //NON-NLS
115  System.loadLibrary("api-ms-win-core-localization-l1-2-0"); //NON-NLS
116  System.loadLibrary("api-ms-win-core-memory-l1-1-0"); //NON-NLS
117  System.loadLibrary("api-ms-win-core-namedpipe-l1-1-0"); //NON-NLS
118  System.loadLibrary("api-ms-win-core-processenvironment-l1-1-0"); //NON-NLS
119  System.loadLibrary("api-ms-win-core-processthreads-l1-1-0"); //NON-NLS
120  System.loadLibrary("api-ms-win-core-processthreads-l1-1-1"); //NON-NLS
121  System.loadLibrary("api-ms-win-core-profile-l1-1-0"); //NON-NLS
122  System.loadLibrary("api-ms-win-core-rtlsupport-l1-1-0"); //NON-NLS
123  System.loadLibrary("api-ms-win-core-string-l1-1-0"); //NON-NLS
124  System.loadLibrary("api-ms-win-core-synch-l1-1-0"); //NON-NLS
125  System.loadLibrary("api-ms-win-core-synch-l1-2-0"); //NON-NLS
126  System.loadLibrary("api-ms-win-core-sysinfo-l1-1-0"); //NON-NLS
127  System.loadLibrary("api-ms-win-core-timezone-l1-1-0"); //NON-NLS
128  System.loadLibrary("api-ms-win-core-util-l1-1-0"); //NON-NLS
129  System.loadLibrary("api-ms-win-crt-conio-l1-1-0"); //NON-NLS
130  System.loadLibrary("api-ms-win-crt-convert-l1-1-0"); //NON-NLS
131  System.loadLibrary("api-ms-win-crt-environment-l1-1-0"); //NON-NLS
132  System.loadLibrary("api-ms-win-crt-filesystem-l1-1-0"); //NON-NLS
133  System.loadLibrary("api-ms-win-crt-heap-l1-1-0"); //NON-NLS
134  System.loadLibrary("api-ms-win-crt-locale-l1-1-0"); //NON-NLS
135  System.loadLibrary("api-ms-win-crt-math-l1-1-0"); //NON-NLS
136  System.loadLibrary("api-ms-win-crt-multibyte-l1-1-0"); //NON-NLS
137  System.loadLibrary("api-ms-win-crt-private-l1-1-0"); //NON-NLS
138  System.loadLibrary("api-ms-win-crt-process-l1-1-0"); //NON-NLS
139  System.loadLibrary("api-ms-win-crt-runtime-l1-1-0"); //NON-NLS
140  System.loadLibrary("api-ms-win-crt-stdio-l1-1-0"); //NON-NLS
141  System.loadLibrary("api-ms-win-crt-string-l1-1-0"); //NON-NLS
142  System.loadLibrary("api-ms-win-crt-time-l1-1-0"); //NON-NLS
143  System.loadLibrary("api-ms-win-crt-utility-l1-1-0"); //NON-NLS
144 
145  System.loadLibrary("ucrtbase"); //NON-NLS
146  System.loadLibrary("vcruntime140"); //NON-NLS
147  System.loadLibrary("msvcp140"); //NON-NLS
148 
149  logger.log(Level.INFO, "Visual C Runtime libraries loaded"); //NON-NLS
150  } catch (UnsatisfiedLinkError e) {
151  logger.log(Level.SEVERE, "Error loading Visual C Runtime libraries, ", e); //NON-NLS
152  }
153 
154  try {
155  System.loadLibrary("zlib"); //NON-NLS
156  logger.log(Level.INFO, "ZLIB library loaded loaded"); //NON-NLS
157  } catch (UnsatisfiedLinkError e) {
158  logger.log(Level.SEVERE, "Error loading ZLIB library, ", e); //NON-NLS
159  }
160 
161  try {
162  System.loadLibrary("libewf"); //NON-NLS
163  logger.log(Level.INFO, "EWF library loaded"); //NON-NLS
164  } catch (UnsatisfiedLinkError e) {
165  logger.log(Level.SEVERE, "Error loading EWF library, ", e); //NON-NLS
166  }
167 
168  try {
169  System.loadLibrary("libvmdk"); //NON-NLS
170  logger.log(Level.INFO, "VMDK library loaded"); //NON-NLS
171  } catch (UnsatisfiedLinkError e) {
172  logger.log(Level.SEVERE, "Error loading VMDK library, ", e); //NON-NLS
173  }
174 
175  try {
176  System.loadLibrary("libvhdi"); //NON-NLS
177  logger.log(Level.INFO, "VHDI library loaded"); //NON-NLS
178  } catch (UnsatisfiedLinkError e) {
179  logger.log(Level.SEVERE, "Error loading VHDI library, ", e); //NON-NLS
180  }
181 
182  // Only attempt to load OpenSSL if we're in 64 bit mode
183  if(System.getProperty("sun.arch.data.model").contains("64")) {
184  // libcrypto must be loaded before libssl to make sure it's the correct version
185  try {
186  System.loadLibrary("libcrypto-1_1-x64"); //NON-NLS
187  logger.log(Level.INFO, "Crypto library loaded"); //NON-NLS
188  } catch (UnsatisfiedLinkError e) {
189  logger.log(Level.SEVERE, "Error loading Crypto library, ", e); //NON-NLS
190  }
191 
192  try {
193  System.loadLibrary("libssl-1_1-x64"); //NON-NLS
194  logger.log(Level.INFO, "OpenSSL library loaded"); //NON-NLS
195  } catch (UnsatisfiedLinkError e) {
196  logger.log(Level.SEVERE, "Error loading OpenSSL library, ", e); //NON-NLS
197  }
198  }
199  }
200  }
201 
202  public Installer() {
203  logger.log(Level.INFO, "core installer created"); //NON-NLS
204  javaFxInit = false;
205 
206  // Prevent the Autopsy UI from shrinking on high DPI displays
207  System.setProperty("sun.java2d.dpiaware", "false");
208  System.setProperty("prism.allowhidpi", "false");
209 
210  // Update existing configuration in case of unsupported settings
211  UserPreferences.updateConfig();
212  updateConfig();
213 
214  packageInstallers = new ArrayList<>();
215  packageInstallers.add(org.sleuthkit.autopsy.coreutils.Installer.getDefault());
216  packageInstallers.add(org.sleuthkit.autopsy.corecomponents.Installer.getDefault());
217  packageInstallers.add(org.sleuthkit.autopsy.datamodel.Installer.getDefault());
218  packageInstallers.add(org.sleuthkit.autopsy.ingest.Installer.getDefault());
220  packageInstallers.add(org.sleuthkit.autopsy.healthmonitor.Installer.getDefault());
221  packageInstallers.add(org.sleuthkit.autopsy.casemodule.Installer.getDefault());
223  packageInstallers.add(org.sleuthkit.autopsy.report.infrastructure.Installer.getDefault());
224 
234  try {
235  FileTypeDetector fileTypeDetector = new FileTypeDetector();
237  logger.log(Level.SEVERE, "Failed to load file type detector.", ex);
238  }
239  }
240 
245  private void updateConfig() {
246  String mode = ModuleSettings.getConfigSetting(SETTINGS_PROPERTIES, "AutopsyMode");
247  if (mode != null) {
248  int ordinal = Integer.parseInt(mode);
249  if (ordinal > 1) {
251  ModuleSettings.setConfigSetting(UserPreferences.SETTINGS_PROPERTIES, "JoinAutoModeCluster", Boolean.toString(false));
252  }
253  }
254  }
255 
262  public static boolean isJavaFxInited() {
263  return javaFxInit;
264  }
265 
266  private static void initJavaFx() {
267  //initialize java fx if exists
268  System.setProperty("javafx.macosx.embedded", "true");
269  try {
270 
271  // Due to a lingering issue https://bugs.openjdk.org/browse/JDK-8223377 where glass.dll from java 8 gets loaded instead of the java 17 one.
272  String javaLibraryPath = "java.library.path";
273  String jvmBinPathStr = Paths.get(System.getProperty("java.home"), "bin").toAbsolutePath().toString();
274  String path = System.getProperty(javaLibraryPath);
275  System.setProperty(javaLibraryPath, StringUtils.isBlank(path) ? jvmBinPathStr : jvmBinPathStr + File.pathSeparator + path);
276 
277  // Creating a JFXPanel initializes JavaFX
278  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();
384  initJavaFx();
386  for (ModuleInstall mi : packageInstallers) {
387  try {
388  mi.restored();
389  logger.log(Level.INFO, "{0} restore succeeded", mi.getClass().getName()); //NON-NLS
390  } catch (Exception e) {
391  String msg = mi.getClass().getName() + " restore failed"; //NON-NLS
392  logger.log(Level.WARNING, msg, e);
393  }
394  }
395  logger.log(Level.INFO, "Autopsy Core restore completed"); //NON-NLS
396  preloadJython();
398  }
399 
403  @Messages({
404  "# {0} - physicalMemory",
405  "Installer_checkMemoryAvailable_physicalRamExpected_desc=Physical memory: {0}, is less than the 8 GB required. Some aspects of the application may not work as expected.",
406  "# {0} - maxMemory",
407  "Installer_checkMemoryAvailable_maxMemExpected_desc=Maximum JVM memory: {0}, is less than the 2 GB required. Some aspects of the application may not work as expected."
408  })
409  private void checkMemoryAvailable() {
410  try {
411  long memorySize = ((com.sun.management.OperatingSystemMXBean) ManagementFactory
412  .getOperatingSystemMXBean()).getTotalMemorySize();
413  if (memorySize < 8_000_000_000L) {
414  String desc = Bundle.Installer_checkMemoryAvailable_physicalRamExpected_desc(
415  FileUtils.byteCountToDisplaySize(memorySize));
416  logger.log(Level.SEVERE, desc);
417  }
418  } catch (Throwable t) {
419  logger.log(Level.SEVERE, "There was an error fetching physical memory size", t);
420  }
421 
422  try {
423  long maxMemory = Runtime.getRuntime().maxMemory();
424  if (maxMemory < 2_000_000_000L) {
425  String desc = Bundle.Installer_checkMemoryAvailable_maxMemExpected_desc(
426  FileUtils.byteCountToDisplaySize(maxMemory));
427  logger.log(Level.SEVERE, desc);
428  }
429  } catch (Throwable t) {
430  logger.log(Level.SEVERE, "There was an error fetching jvm max memory", t);
431  }
432  }
433 
439  private static void initializeSevenZip() {
440  try {
441  SevenZip.initSevenZipFromPlatformJAR();
442  logger.log(Level.INFO, "7zip-java bindings loaded"); //NON-NLS
443  } catch (SevenZipNativeInitializationException e) {
444  logger.log(Level.SEVERE, "Error loading 7zip-java bindings", e); //NON-NLS
445  }
446  }
447 
451  private static void preloadJython() {
452  Runnable loader = () -> {
453  try {
457  } catch (Exception ex) {
458  // This is a firewall exception to ensure that any possible exception caused
459  // by this initial load of the Jython modules are caught and logged.
460  logger.log(Level.SEVERE, "There was an error while doing an initial load of python plugins.", ex);
461  }
462 
463  };
464  new Thread(loader).start();
465  }
466 
470  private static void preloadTranslationServices() {
471  Runnable loader = () -> {
472  try {
474  } catch (Exception ex) {
475  // This is a firewall exception to ensure that any possible exception caused
476  // by this initial load of the translation modules are caught and logged.
477  logger.log(Level.SEVERE, "There was an error while doing an initial load of translation services.", ex);
478  }
479  };
480  new Thread(loader).start();
481  }
482 
483  @Override
484  public void validate() throws IllegalStateException {
485  super.validate();
486 
487  logger.log(Level.INFO, "validate()"); //NON-NLS
488  for (ModuleInstall mi : packageInstallers) {
489  logger.log(Level.INFO, "{0} validate()", mi.getClass().getName()); //NON-NLS
490  try {
491  mi.validate();
492  } catch (IllegalStateException e) {
493  logger.log(Level.WARNING, "", e);
494  }
495  }
496  }
497 
498  @Override
499  public void uninstalled() {
500  super.uninstalled();
501 
502  logger.log(Level.INFO, "uninstalled()"); //NON-NLS
503 
504  for (ModuleInstall mi : packageInstallers) {
505  logger.log(Level.INFO, "{0} uninstalled()", mi.getClass().getName()); //NON-NLS
506  try {
507  mi.uninstalled();
508  } catch (Exception e) {
509  logger.log(Level.WARNING, "", e);
510  }
511  }
512  }
513 
514  @NbBundle.Messages({
515  "Installer.closing.confirmationDialog.title=Ingest is Running",
516  "Installer.closing.confirmationDialog.message=Ingest is running, are you sure you want to exit?",
517  "# {0} - exception message", "Installer.closing.messageBox.caseCloseExceptionMessage=Error closing case: {0}"
518  })
519  @Override
520  public boolean closing() {
521  if (IngestRunningCheck.checkAndConfirmProceed(Bundle.Installer_closing_confirmationDialog_title(), Bundle.Installer_closing_confirmationDialog_message())) {
522  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
523  FutureTask<Void> future = new FutureTask<>(new Callable<Void>() {
524  @Override
525  public Void call() throws Exception {
527  return null;
528  }
529  });
530  Thread thread = new Thread(future);
531  thread.start();
532  try {
533  future.get();
534  } catch (InterruptedException ex) {
535  logger.log(Level.SEVERE, "Unexpected interrupt closing the current case", ex);
536  } catch (ExecutionException ex) {
537  logger.log(Level.SEVERE, "Error closing the current case", ex);
538  MessageNotifyUtil.Message.error(Bundle.Installer_closing_messageBox_caseCloseExceptionMessage(ex.getMessage()));
539  } finally {
540  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
541  }
542  return true;
543  } else {
544  return false;
545  }
546  }
547 
548  @Override
549  public void close() {
550  super.close();
551 
552  logger.log(Level.INFO, "close()"); //NON-NLS
553 
554  //exit JavaFx plat
555  if (javaFxInit) {
556  Platform.exit();
557  }
558 
559  for (ModuleInstall mi : packageInstallers) {
560  logger.log(Level.INFO, "{0} close()", mi.getClass().getName()); //NON-NLS
561  try {
562  mi.close();
563  } catch (Exception e) {
564  logger.log(Level.WARNING, "", e);
565  }
566  }
567  for (Handler h : logger.getHandlers()) {
568  h.close(); //must call h.close or a .LCK file will remain.
569  }
570  }
571 }
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:59
static synchronized List< GeneralReportModule > getGeneralReportModules()
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
static volatile boolean javaFxInit
Definition: Installer.java:71
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: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:69
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 Feb 6 2024
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.