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 
267  // 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.
268  String javaLibraryPath = "java.library.path";
269  String jvmBinPathStr = Paths.get(System.getProperty("java.home"), "bin").toAbsolutePath().toString();
270  String path = System.getProperty(javaLibraryPath);
271  System.setProperty(javaLibraryPath, StringUtils.isBlank(path) ? jvmBinPathStr : jvmBinPathStr + File.pathSeparator + path);
272 
273  // Creating a JFXPanel initializes JavaFX
274  new JFXPanel();
275  Platform.setImplicitExit(false);
276  javaFxInit = true;
277  } catch (UnsatisfiedLinkError | NoClassDefFoundError | Exception e) {
278  //in case javafx not present
279  final String msg = NbBundle.getMessage(Installer.class, "Installer.errorInitJavafx.msg");
280  final String details = NbBundle.getMessage(Installer.class, "Installer.errorInitJavafx.details");
281  logger.log(Level.SEVERE, msg
282  + details, e);
283 
284  WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
285  @Override
286  public void run() {
287  MessageNotifyUtil.Notify.error(msg, details);
288  }
289  });
290  }
291  }
292 
298  private static void addGstreamerPathsToEnv() {
299  if (System.getProperty("jna.nosys") == null) {
300  System.setProperty("jna.nosys", "true");
301  }
302 
303  Path gstreamerPath = InstalledFileLocator.getDefault().locate("gstreamer", Installer.class.getPackage().getName(), false).toPath();
304 
305  if (gstreamerPath == null) {
306  logger.log(Level.SEVERE, "Failed to find GStreamer.");
307  } else {
308  String arch = "x86_64";
309  if (!PlatformUtil.is64BitJVM()) {
310  arch = "x86";
311  }
312 
313  Path gstreamerBasePath = Paths.get(gstreamerPath.toString(), "1.0", arch);
314  Path gstreamerBinPath = Paths.get(gstreamerBasePath.toString(), "bin");
315  Path gstreamerLibPath = Paths.get(gstreamerBasePath.toString(), "lib", "gstreamer-1.0");
316 
317  // Update the PATH environment variable to contain the GStreamer
318  // lib and bin paths.
319  Kernel32 k32 = Kernel32.INSTANCE;
320  String path = System.getenv("PATH");
321  if (StringUtils.isBlank(path)) {
322  k32.SetEnvironmentVariable("PATH", gstreamerLibPath.toString());
323  } else {
324  /*
325  * Note that we *prepend* the paths so that the Gstreamer
326  * binaries associated with the current release are found rather
327  * than binaries associated with an earlier version of Autopsy.
328  */
329  k32.SetEnvironmentVariable("PATH", gstreamerBinPath.toString() + File.pathSeparator + gstreamerLibPath.toString() + path);
330  }
331  }
332  }
333 
338  private static void ensureClassifierFolderExists() {
339  File objectDetectionClassifierDir = new File(PlatformUtil.getObjectDetectionClassifierPath());
340  objectDetectionClassifierDir.mkdir();
341  }
342 
347  private static void ensurePythonModulesFolderExists() {
348  File pythonModulesDir = new File(PlatformUtil.getUserPythonModulesPath());
349  pythonModulesDir.mkdir();
350  }
351 
356  private static void ensureOcrLanguagePacksFolderExists() {
357  File ocrLanguagePacksDir = new File(PlatformUtil.getOcrLanguagePacksPath());
358  boolean createDirectory = ocrLanguagePacksDir.mkdir();
359 
360  //If the directory did not exist, copy the tessdata folder over so we
361  //support english.
362  if (createDirectory) {
363  File tessdataDir = InstalledFileLocator.getDefault().locate(
364  "Tesseract-OCR/tessdata", Installer.class.getPackage().getName(), false);
365  try {
366  FileUtils.copyDirectory(tessdataDir, ocrLanguagePacksDir);
367  } catch (IOException ex) {
368  logger.log(Level.SEVERE, "Copying over default language packs for Tesseract failed.", ex);
369  }
370  }
371  }
372 
373  @Override
374  public void restored() {
375  super.restored();
379  initJavaFx();
381  for (ModuleInstall mi : packageInstallers) {
382  try {
383  mi.restored();
384  logger.log(Level.INFO, "{0} restore succeeded", mi.getClass().getName()); //NON-NLS
385  } catch (Exception e) {
386  String msg = mi.getClass().getName() + " restore failed"; //NON-NLS
387  logger.log(Level.WARNING, msg, e);
388  }
389  }
390  logger.log(Level.INFO, "Autopsy Core restore completed"); //NON-NLS
391  preloadJython();
393  }
394 
400  private static void initializeSevenZip() {
401  try {
402  SevenZip.initSevenZipFromPlatformJAR();
403  logger.log(Level.INFO, "7zip-java bindings loaded"); //NON-NLS
404  } catch (SevenZipNativeInitializationException e) {
405  logger.log(Level.SEVERE, "Error loading 7zip-java bindings", e); //NON-NLS
406  }
407  }
408 
412  private static void preloadJython() {
413  Runnable loader = () -> {
414  try {
418  } catch (Exception ex) {
419  // This is a firewall exception to ensure that any possible exception caused
420  // by this initial load of the Jython modules are caught and logged.
421  logger.log(Level.SEVERE, "There was an error while doing an initial load of python plugins.", ex);
422  }
423 
424  };
425  new Thread(loader).start();
426  }
427 
431  private static void preloadTranslationServices() {
432  Runnable loader = () -> {
433  try {
435  } catch (Exception ex) {
436  // This is a firewall exception to ensure that any possible exception caused
437  // by this initial load of the translation modules are caught and logged.
438  logger.log(Level.SEVERE, "There was an error while doing an initial load of translation services.", ex);
439  }
440  };
441  new Thread(loader).start();
442  }
443 
444  @Override
445  public void validate() throws IllegalStateException {
446  super.validate();
447 
448  logger.log(Level.INFO, "validate()"); //NON-NLS
449  for (ModuleInstall mi : packageInstallers) {
450  logger.log(Level.INFO, "{0} validate()", mi.getClass().getName()); //NON-NLS
451  try {
452  mi.validate();
453  } catch (IllegalStateException e) {
454  logger.log(Level.WARNING, "", e);
455  }
456  }
457  }
458 
459  @Override
460  public void uninstalled() {
461  super.uninstalled();
462 
463  logger.log(Level.INFO, "uninstalled()"); //NON-NLS
464 
465  for (ModuleInstall mi : packageInstallers) {
466  logger.log(Level.INFO, "{0} uninstalled()", mi.getClass().getName()); //NON-NLS
467  try {
468  mi.uninstalled();
469  } catch (Exception e) {
470  logger.log(Level.WARNING, "", e);
471  }
472  }
473  }
474 
475  @NbBundle.Messages({
476  "Installer.closing.confirmationDialog.title=Ingest is Running",
477  "Installer.closing.confirmationDialog.message=Ingest is running, are you sure you want to exit?",
478  "# {0} - exception message", "Installer.closing.messageBox.caseCloseExceptionMessage=Error closing case: {0}"
479  })
480  @Override
481  public boolean closing() {
482  if (IngestRunningCheck.checkAndConfirmProceed(Bundle.Installer_closing_confirmationDialog_title(), Bundle.Installer_closing_confirmationDialog_message())) {
483  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
484  FutureTask<Void> future = new FutureTask<>(new Callable<Void>() {
485  @Override
486  public Void call() throws Exception {
488  return null;
489  }
490  });
491  Thread thread = new Thread(future);
492  thread.start();
493  try {
494  future.get();
495  } catch (InterruptedException ex) {
496  logger.log(Level.SEVERE, "Unexpected interrupt closing the current case", ex);
497  } catch (ExecutionException ex) {
498  logger.log(Level.SEVERE, "Error closing the current case", ex);
499  MessageNotifyUtil.Message.error(Bundle.Installer_closing_messageBox_caseCloseExceptionMessage(ex.getMessage()));
500  } finally {
501  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
502  }
503  return true;
504  } else {
505  return false;
506  }
507  }
508 
509  @Override
510  public void close() {
511  super.close();
512 
513  logger.log(Level.INFO, "close()"); //NON-NLS
514 
515  //exit JavaFx plat
516  if (javaFxInit) {
517  Platform.exit();
518  }
519 
520  for (ModuleInstall mi : packageInstallers) {
521  logger.log(Level.INFO, "{0} close()", mi.getClass().getName()); //NON-NLS
522  try {
523  mi.close();
524  } catch (Exception e) {
525  logger.log(Level.WARNING, "", e);
526  }
527  }
528  for (Handler h : logger.getHandlers()) {
529  h.close(); //must call h.close or a .LCK file will remain.
530  }
531  }
532 }
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:67
static synchronized Installer getDefault()
Definition: Installer.java:38
static synchronized Installer getDefault()
Definition: Installer.java:33
static void ensureOcrLanguagePacksFolderExists()
Definition: Installer.java:356
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 Jun 27 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.