Autopsy  4.9.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
ImageFilePanel.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.casemodule;
20 
21 import java.io.File;
22 import java.util.Calendar;
23 import java.util.List;
24 import javax.swing.JFileChooser;
25 import javax.swing.JOptionPane;
26 import javax.swing.JPanel;
27 import javax.swing.JTextField;
28 import javax.swing.event.DocumentEvent;
29 import javax.swing.event.DocumentListener;
30 import javax.swing.filechooser.FileFilter;
31 import org.apache.commons.lang3.StringUtils;
32 import org.openide.util.NbBundle;
38 import org.sleuthkit.datamodel.HashUtility;
39 
45 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
46 public class ImageFilePanel extends JPanel implements DocumentListener {
47 
48  private static final long serialVersionUID = 1L;
49  private static final String PROP_LASTIMAGE_PATH = "LBL_LastImage_PATH"; //NON-NLS
50  private static final String[] SECTOR_SIZE_CHOICES = {"Auto Detect", "512", "1024", "2048", "4096"};
51  private final JFileChooser fileChooser = new JFileChooser();
52  private final String contextName;
53 
62  private ImageFilePanel(String context, List<FileFilter> fileChooserFilters) {
63  this.contextName = context;
64  initComponents();
65 
66  // Populate the drop down list of time zones
67  createTimeZoneList();
68 
69  // Populate the drop down list of sector size options
70  for (String choice : SECTOR_SIZE_CHOICES) {
71  sectorSizeComboBox.addItem(choice);
72  }
73  sectorSizeComboBox.setSelectedIndex(0);
74 
75  errorLabel.setVisible(false);
76 
77  fileChooser.setDragEnabled(false);
78  fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
79  fileChooser.setMultiSelectionEnabled(false);
80  fileChooserFilters.forEach(fileChooser::addChoosableFileFilter);
81  if (fileChooserFilters.isEmpty() == false) {
82  fileChooser.setFileFilter(fileChooserFilters.get(0));
83  }
84  }
85 
90  private void createTimeZoneList() {
91  List<String> timeZoneList = TimeZoneUtils.createTimeZoneList();
92  for (String timeZone : timeZoneList) {
93  timeZoneComboBox.addItem(timeZone);
94  }
95 
96  // set the selected timezone
97  timeZoneComboBox.setSelectedItem(TimeZoneUtils.createTimeZoneString(Calendar.getInstance().getTimeZone()));
98  }
99 
110  public static synchronized ImageFilePanel createInstance(String context, List<FileFilter> fileChooserFilters) {
111  ImageFilePanel instance = new ImageFilePanel(context, fileChooserFilters);
112  // post-constructor initialization of listener support without leaking references of uninitialized objects
113  instance.getPathTextField().getDocument().addDocumentListener(instance);
114  instance.getMd5TextFieldField().getDocument().addDocumentListener(instance);
115  instance.getSha1TextField().getDocument().addDocumentListener(instance);
116  instance.getSha256TextField().getDocument().addDocumentListener(instance);
117  return instance;
118  }
119 
120  private JTextField getPathTextField() {
121  return pathTextField;
122  }
123 
124  private JTextField getMd5TextFieldField() {
125  return md5HashTextField;
126  }
127 
128  private JTextField getSha1TextField() {
129  return sha1HashTextField;
130  }
131 
132  private JTextField getSha256TextField() {
133  return sha256HashTextField;
134  }
135 
141  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
142  private void initComponents() {
143 
144  pathLabel = new javax.swing.JLabel();
145  browseButton = new javax.swing.JButton();
146  pathTextField = new javax.swing.JTextField();
147  timeZoneLabel = new javax.swing.JLabel();
148  timeZoneComboBox = new javax.swing.JComboBox<>();
149  noFatOrphansCheckbox = new javax.swing.JCheckBox();
150  errorLabel = new javax.swing.JLabel();
151  sectorSizeLabel = new javax.swing.JLabel();
152  sectorSizeComboBox = new javax.swing.JComboBox<>();
153  sha256HashLabel = new javax.swing.JLabel();
154  sha256HashTextField = new javax.swing.JTextField();
155  sha1HashTextField = new javax.swing.JTextField();
156  md5HashTextField = new javax.swing.JTextField();
157  sha1HashLabel = new javax.swing.JLabel();
158  md5HashLabel = new javax.swing.JLabel();
159 
160  setMinimumSize(new java.awt.Dimension(0, 65));
161  setPreferredSize(new java.awt.Dimension(403, 65));
162 
163  org.openide.awt.Mnemonics.setLocalizedText(pathLabel, org.openide.util.NbBundle.getMessage(ImageFilePanel.class, "ImageFilePanel.pathLabel.text")); // NOI18N
164 
165  org.openide.awt.Mnemonics.setLocalizedText(browseButton, org.openide.util.NbBundle.getMessage(ImageFilePanel.class, "ImageFilePanel.browseButton.text")); // NOI18N
166  browseButton.addActionListener(new java.awt.event.ActionListener() {
167  public void actionPerformed(java.awt.event.ActionEvent evt) {
168  browseButtonActionPerformed(evt);
169  }
170  });
171 
172  pathTextField.setText(org.openide.util.NbBundle.getMessage(ImageFilePanel.class, "ImageFilePanel.pathTextField.text")); // NOI18N
173 
174  org.openide.awt.Mnemonics.setLocalizedText(timeZoneLabel, org.openide.util.NbBundle.getMessage(ImageFilePanel.class, "ImageFilePanel.timeZoneLabel.text")); // NOI18N
175 
176  timeZoneComboBox.setMaximumRowCount(30);
177 
178  org.openide.awt.Mnemonics.setLocalizedText(noFatOrphansCheckbox, org.openide.util.NbBundle.getMessage(ImageFilePanel.class, "ImageFilePanel.noFatOrphansCheckbox.text")); // NOI18N
179  noFatOrphansCheckbox.setToolTipText(org.openide.util.NbBundle.getMessage(ImageFilePanel.class, "ImageFilePanel.noFatOrphansCheckbox.toolTipText")); // NOI18N
180 
181  errorLabel.setForeground(new java.awt.Color(255, 0, 0));
182  org.openide.awt.Mnemonics.setLocalizedText(errorLabel, org.openide.util.NbBundle.getMessage(ImageFilePanel.class, "ImageFilePanel.errorLabel.text")); // NOI18N
183 
184  org.openide.awt.Mnemonics.setLocalizedText(sectorSizeLabel, org.openide.util.NbBundle.getMessage(ImageFilePanel.class, "ImageFilePanel.sectorSizeLabel.text")); // NOI18N
185 
186  org.openide.awt.Mnemonics.setLocalizedText(sha256HashLabel, org.openide.util.NbBundle.getMessage(ImageFilePanel.class, "ImageFilePanel.sha256HashLabel.text")); // NOI18N
187 
188  sha256HashTextField.setText(org.openide.util.NbBundle.getMessage(ImageFilePanel.class, "ImageFilePanel.sha256HashTextField.text")); // NOI18N
189 
190  sha1HashTextField.setText(org.openide.util.NbBundle.getMessage(ImageFilePanel.class, "ImageFilePanel.sha1HashTextField.text")); // NOI18N
191 
192  md5HashTextField.setText(org.openide.util.NbBundle.getMessage(ImageFilePanel.class, "ImageFilePanel.md5HashTextField.text")); // NOI18N
193 
194  org.openide.awt.Mnemonics.setLocalizedText(sha1HashLabel, org.openide.util.NbBundle.getMessage(ImageFilePanel.class, "ImageFilePanel.sha1HashLabel.text")); // NOI18N
195 
196  org.openide.awt.Mnemonics.setLocalizedText(md5HashLabel, org.openide.util.NbBundle.getMessage(ImageFilePanel.class, "ImageFilePanel.md5HashLabel.text")); // NOI18N
197 
198  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
199  this.setLayout(layout);
200  layout.setHorizontalGroup(
201  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
202  .addGroup(layout.createSequentialGroup()
203  .addComponent(pathTextField)
204  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
205  .addComponent(browseButton)
206  .addGap(2, 2, 2))
207  .addGroup(layout.createSequentialGroup()
208  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
209  .addComponent(sha256HashLabel)
210  .addComponent(sha1HashLabel)
211  .addComponent(md5HashLabel)
212  .addComponent(sectorSizeLabel)
213  .addComponent(timeZoneLabel))
214  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
215  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
216  .addComponent(sha256HashTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 455, Short.MAX_VALUE)
217  .addComponent(sha1HashTextField)
218  .addComponent(md5HashTextField)
219  .addComponent(sectorSizeComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
220  .addComponent(timeZoneComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
221  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
222  .addGroup(layout.createSequentialGroup()
223  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
224  .addComponent(pathLabel)
225  .addComponent(errorLabel)
226  .addComponent(noFatOrphansCheckbox, javax.swing.GroupLayout.PREFERRED_SIZE, 262, javax.swing.GroupLayout.PREFERRED_SIZE))
227  .addGap(0, 325, Short.MAX_VALUE))
228  );
229  layout.setVerticalGroup(
230  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
231  .addGroup(layout.createSequentialGroup()
232  .addComponent(pathLabel)
233  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
234  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
235  .addComponent(browseButton)
236  .addComponent(pathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
237  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
238  .addComponent(noFatOrphansCheckbox)
239  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
240  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
241  .addComponent(timeZoneComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
242  .addComponent(timeZoneLabel))
243  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
244  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
245  .addComponent(sectorSizeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
246  .addComponent(sectorSizeLabel))
247  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
248  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
249  .addComponent(md5HashTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
250  .addComponent(md5HashLabel))
251  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
252  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
253  .addComponent(sha1HashTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
254  .addComponent(sha1HashLabel))
255  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
256  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
257  .addComponent(sha256HashTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
258  .addComponent(sha256HashLabel))
259  .addGap(18, 18, 18)
260  .addComponent(errorLabel)
261  .addContainerGap(23, Short.MAX_VALUE))
262  );
263  }// </editor-fold>//GEN-END:initComponents
264 
265  @NbBundle.Messages({"ImageFilePanel.000.confirmationMessage=The selected file"
266  + " has extenson .001 but there is a .000 file in the sequence of raw images."
267  + "\nShould the .000 file be used as the start, instead of the selected .001 file?\n"})
268  private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
269  String oldText = getContentPaths();
270  // set the current directory of the FileChooser if the ImagePath Field is valid
271  File currentDir = new File(oldText);
272  if (currentDir.exists()) {
273  fileChooser.setCurrentDirectory(currentDir);
274  }
275 
276  if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
277  String path = fileChooser.getSelectedFile().getPath();
278  if (path.endsWith(".001")) {
279  String zeroX3_path = StringUtils.removeEnd(path, ".001") + ".000";
280  if (new File(zeroX3_path).exists()) {
281  int showConfirmDialog = JOptionPane.showConfirmDialog(this,
282  Bundle.ImageFilePanel_000_confirmationMessage(),
283  "Choose .001 file?", JOptionPane.YES_NO_OPTION);
284  if (showConfirmDialog == JOptionPane.YES_OPTION) {
285  path = zeroX3_path;
286  }
287  }
288  }
289  setContentPath(path);
290  }
291 
292  updateHelper();
293  }//GEN-LAST:event_browseButtonActionPerformed
294 
295  // Variables declaration - do not modify//GEN-BEGIN:variables
296  private javax.swing.JButton browseButton;
297  private javax.swing.JLabel errorLabel;
298  private javax.swing.JLabel md5HashLabel;
299  private javax.swing.JTextField md5HashTextField;
300  private javax.swing.JCheckBox noFatOrphansCheckbox;
301  private javax.swing.JLabel pathLabel;
302  private javax.swing.JTextField pathTextField;
303  private javax.swing.JComboBox<String> sectorSizeComboBox;
304  private javax.swing.JLabel sectorSizeLabel;
305  private javax.swing.JLabel sha1HashLabel;
306  private javax.swing.JTextField sha1HashTextField;
307  private javax.swing.JLabel sha256HashLabel;
308  private javax.swing.JTextField sha256HashTextField;
309  private javax.swing.JComboBox<String> timeZoneComboBox;
310  private javax.swing.JLabel timeZoneLabel;
311  // End of variables declaration//GEN-END:variables
312 
318  public String getContentPaths() {
319  return pathTextField.getText();
320  }
321 
327  public void setContentPath(String s) {
328  pathTextField.setText(s);
329  }
330 
336  public int getSectorSize() {
337  int sectorSizeSelectionIndex = sectorSizeComboBox.getSelectedIndex();
338 
339  if (sectorSizeSelectionIndex == 0) {
340  return 0;
341  }
342 
343  return Integer.valueOf((String) sectorSizeComboBox.getSelectedItem());
344  }
345 
346  public String getTimeZone() {
347  String tz = timeZoneComboBox.getSelectedItem().toString();
348  return tz.substring(tz.indexOf(')') + 2).trim();
349  }
350 
351  public boolean getNoFatOrphans() {
352  return noFatOrphansCheckbox.isSelected();
353  }
354 
355  String getMd5() {
356  return this.md5HashTextField.getText();
357  }
358 
359  String getSha1() {
360  return this.sha1HashTextField.getText();
361  }
362 
363  String getSha256() {
364  return this.sha256HashTextField.getText();
365  }
366 
367  public void reset() {
368  //reset the UI elements to default
369  pathTextField.setText(null);
370  }
371 
377  @NbBundle.Messages({
378  "ImageFilePanel.validatePanel.dataSourceOnCDriveError=Warning: Path to multi-user data source is on \"C:\" drive",
379  "ImageFilePanel.validatePanel.invalidMD5=Invalid MD5 hash",
380  "ImageFilePanel.validatePanel.invalidSHA1=Invalid SHA1 hash",
381  "ImageFilePanel.validatePanel.invalidSHA256=Invalid SHA256 hash",})
382  public boolean validatePanel() {
383  errorLabel.setVisible(false);
384 
385  String path = getContentPaths();
386  if (StringUtils.isBlank(path) || (!(new File(path).isFile() || DriveUtils.isPhysicalDrive(path) || DriveUtils.isPartition(path)))) {
387  return false;
388  }
389 
390  if (!StringUtils.isBlank(getMd5()) && !HashUtility.isValidMd5Hash(getMd5())) {
391  errorLabel.setVisible(true);
392  errorLabel.setText(Bundle.ImageFilePanel_validatePanel_invalidMD5());
393  return false;
394  }
395 
396  if (!StringUtils.isBlank(getSha1()) && !HashUtility.isValidSha1Hash(getSha1())) {
397  errorLabel.setVisible(true);
398  errorLabel.setText(Bundle.ImageFilePanel_validatePanel_invalidSHA1());
399  return false;
400  }
401 
402  if (!StringUtils.isBlank(getSha256()) && !HashUtility.isValidSha256Hash(getSha256())) {
403  errorLabel.setVisible(true);
404  errorLabel.setText(Bundle.ImageFilePanel_validatePanel_invalidSHA256());
405  return false;
406  }
407 
409  errorLabel.setVisible(true);
410  errorLabel.setText(Bundle.ImageFilePanel_validatePanel_dataSourceOnCDriveError());
411  }
412 
413  return true;
414  }
415 
416  public void storeSettings() {
417  String imagePathName = getContentPaths();
418  if (null != imagePathName) {
419  String imagePath = imagePathName.substring(0, imagePathName.lastIndexOf(File.separator) + 1);
420  ModuleSettings.setConfigSetting(contextName, PROP_LASTIMAGE_PATH, imagePath);
421  }
422  }
423 
424  public void readSettings() {
425  String lastImagePath = ModuleSettings.getConfigSetting(contextName, PROP_LASTIMAGE_PATH);
426  if (StringUtils.isNotBlank(lastImagePath)) {
427  setContentPath(lastImagePath);
428  }
429  }
430 
431  @Override
432  public void insertUpdate(DocumentEvent e) {
433  updateHelper();
434  }
435 
436  @Override
437  public void removeUpdate(DocumentEvent e) {
438  updateHelper();
439  }
440 
441  @Override
442  public void changedUpdate(DocumentEvent e) {
443  updateHelper();
444  }
445 
452  @NbBundle.Messages({"ImageFilePanel.moduleErr=Module Error",
453  "ImageFilePanel.moduleErr.msg=A module caused an error listening to ImageFilePanel updates."
454  + " See log to determine which module. Some data could be incomplete.\n"})
455  private void updateHelper() {
456  firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(), false, true);
457  }
458 
462  public void select() {
463  pathTextField.requestFocusInWindow();
464  }
465 }
static boolean isPhysicalDrive(String path)
Definition: DriveUtils.java:43
static boolean isValidForMultiUserCase(String path, Case.CaseType caseType)
javax.swing.JComboBox< String > sectorSizeComboBox
static synchronized ImageFilePanel createInstance(String context, List< FileFilter > fileChooserFilters)
static String createTimeZoneString(TimeZone timeZone)
void browseButtonActionPerformed(java.awt.event.ActionEvent evt)
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
ImageFilePanel(String context, List< FileFilter > fileChooserFilters)
javax.swing.JComboBox< String > timeZoneComboBox
static String getConfigSetting(String moduleName, String settingName)
static boolean isPartition(String path)
Definition: DriveUtils.java:54

Copyright © 2012-2018 Basis Technology. Generated on: Tue Dec 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.