Autopsy  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());
215  }
216 
223  public static boolean isJavaFxInited() {
224  return javaFxInit;
225  }
226 
227  private static void initJavaFx() {
228  //initialize java fx if exists
229  System.setProperty("javafx.macosx.embedded", "true");
230  try {
231  // Creating a JFXPanel initializes JavaFX
232  JFXPanel panel = new JFXPanel();
233  Platform.setImplicitExit(false);
234  javaFxInit = true;
235  } catch (UnsatisfiedLinkError | NoClassDefFoundError | Exception e) {
236  //in case javafx not present
237  final String msg = NbBundle.getMessage(Installer.class, "Installer.errorInitJavafx.msg");
238  final String details = NbBundle.getMessage(Installer.class, "Installer.errorInitJavafx.details");
239  logger.log(Level.SEVERE, msg
240  + details, e);
241 
242  WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
243  @Override
244  public void run() {
245  MessageNotifyUtil.Notify.error(msg, details);
246  }
247  });
248  }
249  }
250 
251  private static void ensurePythonModulesFolderExists() {
252  File pythonModulesDir = new File(PlatformUtil.getUserPythonModulesPath());
253  pythonModulesDir.mkdir();
254  }
255 
256  @Override
257  public void restored() {
258  super.restored();
260  initJavaFx();
261  for (ModuleInstall mi : packageInstallers) {
262  try {
263  mi.restored();
264  logger.log(Level.INFO, "{0} restore succeeded", mi.getClass().getName()); //NON-NLS
265  } catch (Exception e) {
266  String msg = mi.getClass().getName() + " restore failed"; //NON-NLS
267  logger.log(Level.WARNING, msg, e);
268  }
269  }
270  logger.log(Level.INFO, "Autopsy Core restore completed"); //NON-NLS
271  }
272 
273  @Override
274  public void validate() throws IllegalStateException {
275  super.validate();
276 
277  logger.log(Level.INFO, "validate()"); //NON-NLS
278  for (ModuleInstall mi : packageInstallers) {
279  logger.log(Level.INFO, "{0} validate()", mi.getClass().getName()); //NON-NLS
280  try {
281  mi.validate();
282  } catch (IllegalStateException e) {
283  logger.log(Level.WARNING, "", e);
284  }
285  }
286  }
287 
288  @Override
289  public void uninstalled() {
290  super.uninstalled();
291 
292  logger.log(Level.INFO, "uninstalled()"); //NON-NLS
293 
294  for (ModuleInstall mi : packageInstallers) {
295  logger.log(Level.INFO, "{0} uninstalled()", mi.getClass().getName()); //NON-NLS
296  try {
297  mi.uninstalled();
298  } catch (Exception e) {
299  logger.log(Level.WARNING, "", e);
300  }
301  }
302  }
303 
304  @NbBundle.Messages({
305  "Installer.closing.confirmationDialog.title=Ingest is Running",
306  "Installer.closing.confirmationDialog.message=Ingest is running, are you sure you want to exit?",
307  "# {0} - exception message", "Installer.closing.messageBox.caseCloseExceptionMessage=Error closing case: {0}"
308  })
309  @Override
310  public boolean closing() {
311  if (IngestRunningCheck.checkAndConfirmProceed(Bundle.Installer_closing_confirmationDialog_title(), Bundle.Installer_closing_confirmationDialog_message())) {
312  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
313  FutureTask<Void> future = new FutureTask<>(new Callable<Void>() {
314  @Override
315  public Void call() throws Exception {
317  return null;
318  }
319  });
320  Thread thread = new Thread(future);
321  thread.start();
322  try {
323  future.get();
324  } catch (InterruptedException ex) {
325  logger.log(Level.SEVERE, "Unexpected interrupt closing the current case", ex);
326  } catch (ExecutionException ex) {
327  logger.log(Level.SEVERE, "Error closing the current case", ex);
328  MessageNotifyUtil.Message.error(Bundle.Installer_closing_messageBox_caseCloseExceptionMessage(ex.getMessage()));
329  } finally {
330  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
331  }
332  return true;
333  } else {
334  return false;
335  }
336  }
337 
338  @Override
339  public void close() {
340  super.close();
341 
342  logger.log(Level.INFO, "close()"); //NON-NLS
343 
344  //exit JavaFx plat
345  if (javaFxInit) {
346  Platform.exit();
347  }
348 
349  for (ModuleInstall mi : packageInstallers) {
350  logger.log(Level.INFO, "{0} close()", mi.getClass().getName()); //NON-NLS
351  try {
352  mi.close();
353  } catch (Exception e) {
354  logger.log(Level.WARNING, "", e);
355  }
356  }
357  for (Handler h : logger.getHandlers()) {
358  h.close(); //must call h.close or a .LCK file will remain.
359  }
360  }
361 }
static boolean checkAndConfirmProceed(String optionsDlgTitle, String optionsDlgMessage)
static synchronized Installer getDefault()
Definition: Installer.java:55
static volatile boolean javaFxInit
Definition: Installer.java:53
static synchronized Installer getDefault()
Definition: Installer.java:38
static synchronized Installer getDefault()
Definition: Installer.java:31
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: Mon Apr 24 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.