Autopsy  4.10.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 java.awt.Cursor;
22 import java.io.File;
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.concurrent.Callable;
27 import java.util.concurrent.ExecutionException;
28 import java.util.concurrent.FutureTask;
29 import java.util.logging.Handler;
30 import java.util.logging.Level;
31 import javafx.application.Platform;
32 import javafx.embed.swing.JFXPanel;
33 import org.apache.commons.io.FileUtils;
34 import org.openide.modules.InstalledFileLocator;
35 import org.openide.modules.ModuleInstall;
36 import org.openide.util.NbBundle;
37 import org.openide.windows.WindowManager;
45 
50 public class Installer extends ModuleInstall {
51 
52  private static final long serialVersionUID = 1L;
53 
54  private final List<ModuleInstall> packageInstallers;
55  private static final Logger logger = Logger.getLogger(Installer.class.getName());
56  private static volatile boolean javaFxInit = false;
57 
58  static {
60  }
61 
62  private static void loadDynLibraries() {
63  /*
64  * On Windows, we distribute dlls that libtsk_jni depend on. If
65  * libtsk_jni tries to load them, they will not be found by Windows
66  * because they are in special NetBeans folders. So, we manually load
67  * them from within Autopsy so that they are found via the NetBeans
68  * loading setup. These are copied by the build script when making the
69  * ZIP file. In a development environment they will need to be loaded
70  * from standard places in your system.
71  *
72  * On non-Windows platforms, we assume the dependncies are all installed
73  * and loadable (i.e. a 'make install' was done).
74  */
75  if (PlatformUtil.isWindowsOS()) {
76  try {
77  //Note: if shipping with a different CRT version, this will only print a warning
78  //and try to use linker mechanism to find the correct versions of libs.
79  //We should update this if we officially switch to a new version of CRT/compiler
80  System.loadLibrary("api-ms-win-core-console-l1-1-0"); //NON-NLS
81  System.loadLibrary("api-ms-win-core-datetime-l1-1-0"); //NON-NLS
82  System.loadLibrary("api-ms-win-core-debug-l1-1-0"); //NON-NLS
83  System.loadLibrary("api-ms-win-core-errorhandling-l1-1-0"); //NON-NLS
84  System.loadLibrary("api-ms-win-core-file-l1-1-0"); //NON-NLS
85  System.loadLibrary("api-ms-win-core-file-l1-2-0"); //NON-NLS
86  System.loadLibrary("api-ms-win-core-file-l2-1-0"); //NON-NLS
87  System.loadLibrary("api-ms-win-core-handle-l1-1-0"); //NON-NLS
88  System.loadLibrary("api-ms-win-core-heap-l1-1-0"); //NON-NLS
89  System.loadLibrary("api-ms-win-core-interlocked-l1-1-0"); //NON-NLS
90  System.loadLibrary("api-ms-win-core-libraryloader-l1-1-0"); //NON-NLS
91  System.loadLibrary("api-ms-win-core-localization-l1-2-0"); //NON-NLS
92  System.loadLibrary("api-ms-win-core-memory-l1-1-0"); //NON-NLS
93  System.loadLibrary("api-ms-win-core-namedpipe-l1-1-0"); //NON-NLS
94  System.loadLibrary("api-ms-win-core-processenvironment-l1-1-0"); //NON-NLS
95  System.loadLibrary("api-ms-win-core-processthreads-l1-1-0"); //NON-NLS
96  System.loadLibrary("api-ms-win-core-processthreads-l1-1-1"); //NON-NLS
97  System.loadLibrary("api-ms-win-core-profile-l1-1-0"); //NON-NLS
98  System.loadLibrary("api-ms-win-core-rtlsupport-l1-1-0"); //NON-NLS
99  System.loadLibrary("api-ms-win-core-string-l1-1-0"); //NON-NLS
100  System.loadLibrary("api-ms-win-core-synch-l1-1-0"); //NON-NLS
101  System.loadLibrary("api-ms-win-core-synch-l1-2-0"); //NON-NLS
102  System.loadLibrary("api-ms-win-core-sysinfo-l1-1-0"); //NON-NLS
103  System.loadLibrary("api-ms-win-core-timezone-l1-1-0"); //NON-NLS
104  System.loadLibrary("api-ms-win-core-util-l1-1-0"); //NON-NLS
105  System.loadLibrary("api-ms-win-crt-conio-l1-1-0"); //NON-NLS
106  System.loadLibrary("api-ms-win-crt-convert-l1-1-0"); //NON-NLS
107  System.loadLibrary("api-ms-win-crt-environment-l1-1-0"); //NON-NLS
108  System.loadLibrary("api-ms-win-crt-filesystem-l1-1-0"); //NON-NLS
109  System.loadLibrary("api-ms-win-crt-heap-l1-1-0"); //NON-NLS
110  System.loadLibrary("api-ms-win-crt-locale-l1-1-0"); //NON-NLS
111  System.loadLibrary("api-ms-win-crt-math-l1-1-0"); //NON-NLS
112  System.loadLibrary("api-ms-win-crt-multibyte-l1-1-0"); //NON-NLS
113  System.loadLibrary("api-ms-win-crt-private-l1-1-0"); //NON-NLS
114  System.loadLibrary("api-ms-win-crt-process-l1-1-0"); //NON-NLS
115  System.loadLibrary("api-ms-win-crt-runtime-l1-1-0"); //NON-NLS
116  System.loadLibrary("api-ms-win-crt-stdio-l1-1-0"); //NON-NLS
117  System.loadLibrary("api-ms-win-crt-string-l1-1-0"); //NON-NLS
118  System.loadLibrary("api-ms-win-crt-time-l1-1-0"); //NON-NLS
119  System.loadLibrary("api-ms-win-crt-utility-l1-1-0"); //NON-NLS
120 
121  System.loadLibrary("ucrtbase"); //NON-NLS
122  System.loadLibrary("vcruntime140"); //NON-NLS
123  System.loadLibrary("msvcp140"); //NON-NLS
124 
125  logger.log(Level.INFO, "Visual C Runtime libraries loaded"); //NON-NLS
126  } catch (UnsatisfiedLinkError e) {
127  logger.log(Level.SEVERE, "Error loading Visual C Runtime libraries, ", e); //NON-NLS
128  }
129 
130  try {
131  System.loadLibrary("zlib"); //NON-NLS
132  logger.log(Level.INFO, "ZLIB library loaded loaded"); //NON-NLS
133  } catch (UnsatisfiedLinkError e) {
134  logger.log(Level.SEVERE, "Error loading ZLIB library, ", e); //NON-NLS
135  }
136 
137  try {
138  System.loadLibrary("libewf"); //NON-NLS
139  logger.log(Level.INFO, "EWF library loaded"); //NON-NLS
140  } catch (UnsatisfiedLinkError e) {
141  logger.log(Level.SEVERE, "Error loading EWF library, ", e); //NON-NLS
142  }
143 
144  try {
145  System.loadLibrary("libvmdk"); //NON-NLS
146  logger.log(Level.INFO, "VMDK library loaded"); //NON-NLS
147  } catch (UnsatisfiedLinkError e) {
148  logger.log(Level.SEVERE, "Error loading VMDK library, ", e); //NON-NLS
149  }
150 
151  try {
152  System.loadLibrary("libvhdi"); //NON-NLS
153  logger.log(Level.INFO, "VHDI library loaded"); //NON-NLS
154  } catch (UnsatisfiedLinkError e) {
155  logger.log(Level.SEVERE, "Error loading VHDI library, ", e); //NON-NLS
156  }
157 
158  /*
159  * PostgreSQL
160  */
161  try {
162  System.loadLibrary("msvcr120"); //NON-NLS
163  logger.log(Level.INFO, "MSVCR 120 library loaded"); //NON-NLS
164  } catch (UnsatisfiedLinkError e) {
165  logger.log(Level.SEVERE, "Error loading MSVCR120 library, ", e); //NON-NLS
166  }
167 
168  try {
169  System.loadLibrary("libeay32"); //NON-NLS
170  logger.log(Level.INFO, "LIBEAY32 library loaded"); //NON-NLS
171  } catch (UnsatisfiedLinkError e) {
172  logger.log(Level.SEVERE, "Error loading LIBEAY32 library, ", e); //NON-NLS
173  }
174 
175  try {
176  System.loadLibrary("ssleay32"); //NON-NLS
177  logger.log(Level.INFO, "SSLEAY32 library loaded"); //NON-NLS
178  } catch (UnsatisfiedLinkError e) {
179  logger.log(Level.SEVERE, "Error loading SSLEAY32 library, ", e); //NON-NLS
180  }
181 
182  try {
183  System.loadLibrary("libiconv-2"); //NON-NLS
184  logger.log(Level.INFO, "libiconv-2 library loaded"); //NON-NLS
185  } catch (UnsatisfiedLinkError e) {
186  logger.log(Level.SEVERE, "Error loading libiconv-2 library, ", e); //NON-NLS
187  }
188 
189  try {
190  System.loadLibrary("libintl-8"); //NON-NLS
191  logger.log(Level.INFO, "libintl-8 library loaded"); //NON-NLS
192  } catch (UnsatisfiedLinkError e) {
193  logger.log(Level.SEVERE, "Error loading libintl-8 library, ", e); //NON-NLS
194  }
195 
196  try {
197  System.loadLibrary("libpq"); //NON-NLS
198  logger.log(Level.INFO, "LIBPQ library loaded"); //NON-NLS
199  } catch (UnsatisfiedLinkError e) {
200  logger.log(Level.SEVERE, "Error loading LIBPQ library, ", e); //NON-NLS
201  }
202  }
203  }
204 
205  public Installer() {
206  logger.log(Level.INFO, "core installer created"); //NON-NLS
207  javaFxInit = false;
208 
209  // Prevent the Autopsy UI from shrinking on high DPI displays
210  System.setProperty("sun.java2d.dpiaware", "false");
211  System.setProperty("prism.allowhidpi", "false");
212 
213  // Update existing configuration in case of unsupported settings
214  updateConfig();
215 
216  packageInstallers = new ArrayList<>();
217  packageInstallers.add(org.sleuthkit.autopsy.coreutils.Installer.getDefault());
218  packageInstallers.add(org.sleuthkit.autopsy.corecomponents.Installer.getDefault());
219  packageInstallers.add(org.sleuthkit.autopsy.datamodel.Installer.getDefault());
220  packageInstallers.add(org.sleuthkit.autopsy.ingest.Installer.getDefault());
222  packageInstallers.add(org.sleuthkit.autopsy.healthmonitor.Installer.getDefault());
223  }
224 
229  private void updateConfig() {
230  String mode = ModuleSettings.getConfigSetting(SETTINGS_PROPERTIES, "AutopsyMode");
231  if (mode != null) {
232  int ordinal = Integer.parseInt(mode);
233  if (ordinal > 1) {
235  ModuleSettings.setConfigSetting(UserPreferences.SETTINGS_PROPERTIES, "JoinAutoModeCluster", Boolean.toString(false));
236  }
237  }
238  }
239 
246  public static boolean isJavaFxInited() {
247  return javaFxInit;
248  }
249 
250  private static void initJavaFx() {
251  //initialize java fx if exists
252  System.setProperty("javafx.macosx.embedded", "true");
253  try {
254  // Creating a JFXPanel initializes JavaFX
255  JFXPanel panel = new JFXPanel();
256  Platform.setImplicitExit(false);
257  javaFxInit = true;
258  } catch (UnsatisfiedLinkError | NoClassDefFoundError | Exception e) {
259  //in case javafx not present
260  final String msg = NbBundle.getMessage(Installer.class, "Installer.errorInitJavafx.msg");
261  final String details = NbBundle.getMessage(Installer.class, "Installer.errorInitJavafx.details");
262  logger.log(Level.SEVERE, msg
263  + details, e);
264 
265  WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
266  @Override
267  public void run() {
268  MessageNotifyUtil.Notify.error(msg, details);
269  }
270  });
271  }
272  }
273 
278  private static void ensureClassifierFolderExists() {
279  File objectDetectionClassifierDir = new File(PlatformUtil.getObjectDetectionClassifierPath());
280  objectDetectionClassifierDir.mkdir();
281  }
282 
287  private static void ensurePythonModulesFolderExists() {
288  File pythonModulesDir = new File(PlatformUtil.getUserPythonModulesPath());
289  pythonModulesDir.mkdir();
290  }
291 
296  private static void ensureOcrLanguagePacksFolderExists() {
297  File ocrLanguagePacksDir = new File(PlatformUtil.getOcrLanguagePacksPath());
298  boolean createDirectory = ocrLanguagePacksDir.mkdir();
299 
300  //If the directory did not exist, copy the tessdata folder over so we
301  //support english.
302  if(createDirectory) {
303  File tessdataDir = InstalledFileLocator.getDefault().locate(
304  "Tesseract-OCR/tessdata", Installer.class.getPackage().getName(), false);
305  try {
306  FileUtils.copyDirectory(tessdataDir, ocrLanguagePacksDir);
307  } catch (IOException ex) {
308  logger.log(Level.SEVERE, "Copying over default language packs for Tesseract failed.", ex);
309  }
310  }
311  }
312 
313  @Override
314  public void restored() {
315  super.restored();
319  initJavaFx();
320  for (ModuleInstall mi : packageInstallers) {
321  try {
322  mi.restored();
323  logger.log(Level.INFO, "{0} restore succeeded", mi.getClass().getName()); //NON-NLS
324  } catch (Exception e) {
325  String msg = mi.getClass().getName() + " restore failed"; //NON-NLS
326  logger.log(Level.WARNING, msg, e);
327  }
328  }
329  logger.log(Level.INFO, "Autopsy Core restore completed"); //NON-NLS
330  }
331 
332  @Override
333  public void validate() throws IllegalStateException {
334  super.validate();
335 
336  logger.log(Level.INFO, "validate()"); //NON-NLS
337  for (ModuleInstall mi : packageInstallers) {
338  logger.log(Level.INFO, "{0} validate()", mi.getClass().getName()); //NON-NLS
339  try {
340  mi.validate();
341  } catch (IllegalStateException e) {
342  logger.log(Level.WARNING, "", e);
343  }
344  }
345  }
346 
347  @Override
348  public void uninstalled() {
349  super.uninstalled();
350 
351  logger.log(Level.INFO, "uninstalled()"); //NON-NLS
352 
353  for (ModuleInstall mi : packageInstallers) {
354  logger.log(Level.INFO, "{0} uninstalled()", mi.getClass().getName()); //NON-NLS
355  try {
356  mi.uninstalled();
357  } catch (Exception e) {
358  logger.log(Level.WARNING, "", e);
359  }
360  }
361  }
362 
363  @NbBundle.Messages({
364  "Installer.closing.confirmationDialog.title=Ingest is Running",
365  "Installer.closing.confirmationDialog.message=Ingest is running, are you sure you want to exit?",
366  "# {0} - exception message", "Installer.closing.messageBox.caseCloseExceptionMessage=Error closing case: {0}"
367  })
368  @Override
369  public boolean closing() {
370  if (IngestRunningCheck.checkAndConfirmProceed(Bundle.Installer_closing_confirmationDialog_title(), Bundle.Installer_closing_confirmationDialog_message())) {
371  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
372  FutureTask<Void> future = new FutureTask<>(new Callable<Void>() {
373  @Override
374  public Void call() throws Exception {
376  return null;
377  }
378  });
379  Thread thread = new Thread(future);
380  thread.start();
381  try {
382  future.get();
383  } catch (InterruptedException ex) {
384  logger.log(Level.SEVERE, "Unexpected interrupt closing the current case", ex);
385  } catch (ExecutionException ex) {
386  logger.log(Level.SEVERE, "Error closing the current case", ex);
387  MessageNotifyUtil.Message.error(Bundle.Installer_closing_messageBox_caseCloseExceptionMessage(ex.getMessage()));
388  } finally {
389  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
390  }
391  return true;
392  } else {
393  return false;
394  }
395  }
396 
397  @Override
398  public void close() {
399  super.close();
400 
401  logger.log(Level.INFO, "close()"); //NON-NLS
402 
403  //exit JavaFx plat
404  if (javaFxInit) {
405  Platform.exit();
406  }
407 
408  for (ModuleInstall mi : packageInstallers) {
409  logger.log(Level.INFO, "{0} close()", mi.getClass().getName()); //NON-NLS
410  try {
411  mi.close();
412  } catch (Exception e) {
413  logger.log(Level.WARNING, "", e);
414  }
415  }
416  for (Handler h : logger.getHandlers()) {
417  h.close(); //must call h.close or a .LCK file will remain.
418  }
419  }
420 }
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:56
static synchronized Installer getDefault()
Definition: Installer.java:38
static synchronized Installer getDefault()
Definition: Installer.java:33
static void ensureOcrLanguagePacksFolderExists()
Definition: Installer.java:296
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:54
static synchronized Installer getDefault()
Definition: Installer.java:35

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