Autopsy  4.4.1
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-2017 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.util.ArrayList;
24 import java.util.List;
25 import java.util.concurrent.Callable;
26 import java.util.concurrent.ExecutionException;
27 import java.util.concurrent.FutureTask;
28 import java.util.logging.Handler;
29 import java.util.logging.Level;
30 import javafx.application.Platform;
31 import javafx.embed.swing.JFXPanel;
32 import javax.swing.SwingWorker;
33 import org.openide.LifecycleManager;
34 import org.openide.modules.ModuleInstall;
35 import org.openide.util.NbBundle;
36 import org.openide.windows.WindowManager;
42 
47 public class Installer extends ModuleInstall {
48 
49  private static final long serialVersionUID = 1L;
50 
51  private final List<ModuleInstall> packageInstallers;
52  private static final Logger logger = Logger.getLogger(Installer.class.getName());
53  private static volatile boolean javaFxInit = false;
54 
55  static {
57  }
58 
59  private static void loadDynLibraries() {
60  /*
61  * On Windows, we distribute dlls that libtsk_jni depend on. If
62  * libtsk_jni tries to load them, they will not be found by Windows
63  * because they are in special NetBeans folders. So, we manually load
64  * them from within Autopsy so that they are found via the NetBeans
65  * loading setup. These are copied by the build script when making the
66  * ZIP file. In a development environment they will need to be loaded
67  * from standard places in your system.
68  *
69  * On non-Windows platforms, we assume the dependncies are all installed
70  * and loadable (i.e. a 'make install' was done).
71  */
72  if (PlatformUtil.isWindowsOS()) {
73  try {
74  //Note: if shipping with a different CRT version, this will only print a warning
75  //and try to use linker mechanism to find the correct versions of libs.
76  //We should update this if we officially switch to a new version of CRT/compiler
77  System.loadLibrary("api-ms-win-core-console-l1-1-0"); //NON-NLS
78  System.loadLibrary("api-ms-win-core-datetime-l1-1-0"); //NON-NLS
79  System.loadLibrary("api-ms-win-core-debug-l1-1-0"); //NON-NLS
80  System.loadLibrary("api-ms-win-core-errorhandling-l1-1-0"); //NON-NLS
81  System.loadLibrary("api-ms-win-core-file-l1-1-0"); //NON-NLS
82  System.loadLibrary("api-ms-win-core-file-l1-2-0"); //NON-NLS
83  System.loadLibrary("api-ms-win-core-file-l2-1-0"); //NON-NLS
84  System.loadLibrary("api-ms-win-core-handle-l1-1-0"); //NON-NLS
85  System.loadLibrary("api-ms-win-core-heap-l1-1-0"); //NON-NLS
86  System.loadLibrary("api-ms-win-core-interlocked-l1-1-0"); //NON-NLS
87  System.loadLibrary("api-ms-win-core-libraryloader-l1-1-0"); //NON-NLS
88  System.loadLibrary("api-ms-win-core-localization-l1-2-0"); //NON-NLS
89  System.loadLibrary("api-ms-win-core-memory-l1-1-0"); //NON-NLS
90  System.loadLibrary("api-ms-win-core-namedpipe-l1-1-0"); //NON-NLS
91  System.loadLibrary("api-ms-win-core-processenvironment-l1-1-0"); //NON-NLS
92  System.loadLibrary("api-ms-win-core-processthreads-l1-1-0"); //NON-NLS
93  System.loadLibrary("api-ms-win-core-processthreads-l1-1-1"); //NON-NLS
94  System.loadLibrary("api-ms-win-core-profile-l1-1-0"); //NON-NLS
95  System.loadLibrary("api-ms-win-core-rtlsupport-l1-1-0"); //NON-NLS
96  System.loadLibrary("api-ms-win-core-string-l1-1-0"); //NON-NLS
97  System.loadLibrary("api-ms-win-core-synch-l1-1-0"); //NON-NLS
98  System.loadLibrary("api-ms-win-core-synch-l1-2-0"); //NON-NLS
99  System.loadLibrary("api-ms-win-core-sysinfo-l1-1-0"); //NON-NLS
100  System.loadLibrary("api-ms-win-core-timezone-l1-1-0"); //NON-NLS
101  System.loadLibrary("api-ms-win-core-util-l1-1-0"); //NON-NLS
102  System.loadLibrary("api-ms-win-crt-conio-l1-1-0"); //NON-NLS
103  System.loadLibrary("api-ms-win-crt-convert-l1-1-0"); //NON-NLS
104  System.loadLibrary("api-ms-win-crt-environment-l1-1-0"); //NON-NLS
105  System.loadLibrary("api-ms-win-crt-filesystem-l1-1-0"); //NON-NLS
106  System.loadLibrary("api-ms-win-crt-heap-l1-1-0"); //NON-NLS
107  System.loadLibrary("api-ms-win-crt-locale-l1-1-0"); //NON-NLS
108  System.loadLibrary("api-ms-win-crt-math-l1-1-0"); //NON-NLS
109  System.loadLibrary("api-ms-win-crt-multibyte-l1-1-0"); //NON-NLS
110  System.loadLibrary("api-ms-win-crt-private-l1-1-0"); //NON-NLS
111  System.loadLibrary("api-ms-win-crt-process-l1-1-0"); //NON-NLS
112  System.loadLibrary("api-ms-win-crt-runtime-l1-1-0"); //NON-NLS
113  System.loadLibrary("api-ms-win-crt-stdio-l1-1-0"); //NON-NLS
114  System.loadLibrary("api-ms-win-crt-string-l1-1-0"); //NON-NLS
115  System.loadLibrary("api-ms-win-crt-time-l1-1-0"); //NON-NLS
116  System.loadLibrary("api-ms-win-crt-utility-l1-1-0"); //NON-NLS
117 
118  System.loadLibrary("ucrtbase"); //NON-NLS
119  System.loadLibrary("vcruntime140"); //NON-NLS
120  System.loadLibrary("msvcp140"); //NON-NLS
121 
122  logger.log(Level.INFO, "Visual C Runtime libraries loaded"); //NON-NLS
123  } catch (UnsatisfiedLinkError e) {
124  logger.log(Level.SEVERE, "Error loading Visual C Runtime libraries, ", e); //NON-NLS
125  }
126 
127  try {
128  System.loadLibrary("zlib"); //NON-NLS
129  logger.log(Level.INFO, "ZLIB library loaded loaded"); //NON-NLS
130  } catch (UnsatisfiedLinkError e) {
131  logger.log(Level.SEVERE, "Error loading ZLIB library, ", e); //NON-NLS
132  }
133 
134  try {
135  System.loadLibrary("libewf"); //NON-NLS
136  logger.log(Level.INFO, "EWF library loaded"); //NON-NLS
137  } catch (UnsatisfiedLinkError e) {
138  logger.log(Level.SEVERE, "Error loading EWF library, ", e); //NON-NLS
139  }
140 
141  try {
142  System.loadLibrary("libvmdk"); //NON-NLS
143  logger.log(Level.INFO, "VMDK library loaded"); //NON-NLS
144  } catch (UnsatisfiedLinkError e) {
145  logger.log(Level.SEVERE, "Error loading VMDK library, ", e); //NON-NLS
146  }
147 
148  try {
149  System.loadLibrary("libvhdi"); //NON-NLS
150  logger.log(Level.INFO, "VHDI library loaded"); //NON-NLS
151  } catch (UnsatisfiedLinkError e) {
152  logger.log(Level.SEVERE, "Error loading VHDI library, ", e); //NON-NLS
153  }
154 
155  /*
156  * PostgreSQL
157  */
158  try {
159  System.loadLibrary("msvcr120"); //NON-NLS
160  logger.log(Level.INFO, "MSVCR 120 library loaded"); //NON-NLS
161  } catch (UnsatisfiedLinkError e) {
162  logger.log(Level.SEVERE, "Error loading MSVCR120 library, ", e); //NON-NLS
163  }
164 
165  try {
166  System.loadLibrary("libeay32"); //NON-NLS
167  logger.log(Level.INFO, "LIBEAY32 library loaded"); //NON-NLS
168  } catch (UnsatisfiedLinkError e) {
169  logger.log(Level.SEVERE, "Error loading LIBEAY32 library, ", e); //NON-NLS
170  }
171 
172  try {
173  System.loadLibrary("ssleay32"); //NON-NLS
174  logger.log(Level.INFO, "SSLEAY32 library loaded"); //NON-NLS
175  } catch (UnsatisfiedLinkError e) {
176  logger.log(Level.SEVERE, "Error loading SSLEAY32 library, ", e); //NON-NLS
177  }
178 
179  try {
180  System.loadLibrary("libiconv-2"); //NON-NLS
181  logger.log(Level.INFO, "libiconv-2 library loaded"); //NON-NLS
182  } catch (UnsatisfiedLinkError e) {
183  logger.log(Level.SEVERE, "Error loading libiconv-2 library, ", e); //NON-NLS
184  }
185 
186  try {
187  System.loadLibrary("libintl-8"); //NON-NLS
188  logger.log(Level.INFO, "libintl-8 library loaded"); //NON-NLS
189  } catch (UnsatisfiedLinkError e) {
190  logger.log(Level.SEVERE, "Error loading libintl-8 library, ", e); //NON-NLS
191  }
192 
193  try {
194  System.loadLibrary("libpq"); //NON-NLS
195  logger.log(Level.INFO, "LIBPQ library loaded"); //NON-NLS
196  } catch (UnsatisfiedLinkError e) {
197  logger.log(Level.SEVERE, "Error loading LIBPQ library, ", e); //NON-NLS
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  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  }
217 
224  public static boolean isJavaFxInited() {
225  return javaFxInit;
226  }
227 
228  private static void initJavaFx() {
229  //initialize java fx if exists
230  System.setProperty("javafx.macosx.embedded", "true");
231  try {
232  // Creating a JFXPanel initializes JavaFX
233  JFXPanel panel = new JFXPanel();
234  Platform.setImplicitExit(false);
235  javaFxInit = true;
236  } catch (UnsatisfiedLinkError | NoClassDefFoundError | Exception e) {
237  //in case javafx not present
238  final String msg = NbBundle.getMessage(Installer.class, "Installer.errorInitJavafx.msg");
239  final String details = NbBundle.getMessage(Installer.class, "Installer.errorInitJavafx.details");
240  logger.log(Level.SEVERE, msg
241  + details, e);
242 
243  WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
244  @Override
245  public void run() {
246  MessageNotifyUtil.Notify.error(msg, details);
247  }
248  });
249  }
250  }
251 
252  private static void ensurePythonModulesFolderExists() {
253  File pythonModulesDir = new File(PlatformUtil.getUserPythonModulesPath());
254  pythonModulesDir.mkdir();
255  }
256 
257  @Override
258  public void restored() {
259  super.restored();
261  initJavaFx();
262  for (ModuleInstall mi : packageInstallers) {
263  try {
264  mi.restored();
265  logger.log(Level.INFO, "{0} restore succeeded", mi.getClass().getName()); //NON-NLS
266  } catch (Exception e) {
267  String msg = mi.getClass().getName() + " restore failed"; //NON-NLS
268  logger.log(Level.WARNING, msg, e);
269  }
270  }
271  logger.log(Level.INFO, "Autopsy Core restore completed"); //NON-NLS
272  }
273 
274  @Override
275  public void validate() throws IllegalStateException {
276  super.validate();
277 
278  logger.log(Level.INFO, "validate()"); //NON-NLS
279  for (ModuleInstall mi : packageInstallers) {
280  logger.log(Level.INFO, "{0} validate()", mi.getClass().getName()); //NON-NLS
281  try {
282  mi.validate();
283  } catch (IllegalStateException e) {
284  logger.log(Level.WARNING, "", e);
285  }
286  }
287  }
288 
289  @Override
290  public void uninstalled() {
291  super.uninstalled();
292 
293  logger.log(Level.INFO, "uninstalled()"); //NON-NLS
294 
295  for (ModuleInstall mi : packageInstallers) {
296  logger.log(Level.INFO, "{0} uninstalled()", mi.getClass().getName()); //NON-NLS
297  try {
298  mi.uninstalled();
299  } catch (Exception e) {
300  logger.log(Level.WARNING, "", e);
301  }
302  }
303  }
304 
305  @NbBundle.Messages({
306  "Installer.closing.confirmationDialog.title=Ingest is Running",
307  "Installer.closing.confirmationDialog.message=Ingest is running, are you sure you want to exit?",
308  "# {0} - exception message", "Installer.closing.messageBox.caseCloseExceptionMessage=Error closing case: {0}"
309  })
310  @Override
311  public boolean closing() {
312  if (IngestRunningCheck.checkAndConfirmProceed(Bundle.Installer_closing_confirmationDialog_title(), Bundle.Installer_closing_confirmationDialog_message())) {
313  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
314  FutureTask<Void> future = new FutureTask<>(new Callable<Void>() {
315  @Override
316  public Void call() throws Exception {
318  return null;
319  }
320  });
321  Thread thread = new Thread(future);
322  thread.start();
323  try {
324  future.get();
325  } catch (InterruptedException ex) {
326  logger.log(Level.SEVERE, "Unexpected interrupt closing the current case", ex);
327  } catch (ExecutionException ex) {
328  logger.log(Level.SEVERE, "Error closing the current case", ex);
329  MessageNotifyUtil.Message.error(Bundle.Installer_closing_messageBox_caseCloseExceptionMessage(ex.getMessage()));
330  } finally {
331  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
332  }
333  return true;
334  } else {
335  return false;
336  }
337  }
338 
339  @Override
340  public void close() {
341  super.close();
342 
343  logger.log(Level.INFO, "close()"); //NON-NLS
344 
345  //exit JavaFx plat
346  if (javaFxInit) {
347  Platform.exit();
348  }
349 
350  for (ModuleInstall mi : packageInstallers) {
351  logger.log(Level.INFO, "{0} close()", mi.getClass().getName()); //NON-NLS
352  try {
353  mi.close();
354  } catch (Exception e) {
355  logger.log(Level.WARNING, "", e);
356  }
357  }
358  for (Handler h : logger.getHandlers()) {
359  h.close(); //must call h.close or a .LCK file will remain.
360  }
361  }
362 }
static boolean checkAndConfirmProceed(String optionsDlgTitle, String optionsDlgMessage)
static synchronized Installer getDefault()
Definition: Installer.java:44
static volatile boolean javaFxInit
Definition: Installer.java:53
static synchronized Installer getDefault()
Definition: Installer.java:38
static synchronized Installer getDefault()
Definition: Installer.java:31
static void error(String title, String message)
synchronized static Logger getLogger(String name)
Definition: Logger.java:161
final List< ModuleInstall > packageInstallers
Definition: Installer.java:51
static synchronized Installer getDefault()
Definition: Installer.java:35

Copyright © 2012-2016 Basis Technology. Generated on: Fri Sep 29 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.