mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-17 18:17:43 +00:00
hex/string viewer handle case when file offset could not be read, which can happen e.g. for deleted content
This commit is contained in:
parent
2cadfadfa9
commit
5b21911756
@ -50,7 +50,9 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont
|
|||||||
// for error handling
|
// for error handling
|
||||||
private String className = this.getClass().toString();
|
private String className = this.getClass().toString();
|
||||||
|
|
||||||
/** Creates new form DataContentViewerHex */
|
/**
|
||||||
|
* Creates new form DataContentViewerHex
|
||||||
|
*/
|
||||||
public DataContentViewerHex() {
|
public DataContentViewerHex() {
|
||||||
initComponents();
|
initComponents();
|
||||||
customizeComponents();
|
customizeComponents();
|
||||||
@ -63,20 +65,21 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
JMenuItem jmi = (JMenuItem) e.getSource();
|
JMenuItem jmi = (JMenuItem) e.getSource();
|
||||||
if(jmi.equals(copyMenuItem))
|
if (jmi.equals(copyMenuItem)) {
|
||||||
outputViewPane.copy();
|
outputViewPane.copy();
|
||||||
else if(jmi.equals(selectAllMenuItem))
|
} else if (jmi.equals(selectAllMenuItem)) {
|
||||||
outputViewPane.selectAll();
|
outputViewPane.selectAll();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
copyMenuItem.addActionListener(actList);
|
copyMenuItem.addActionListener(actList);
|
||||||
selectAllMenuItem.addActionListener(actList);
|
selectAllMenuItem.addActionListener(actList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method is called from within the constructor to
|
/**
|
||||||
* initialize the form.
|
* This method is called from within the constructor to initialize the form.
|
||||||
* WARNING: Do NOT modify this code. The content of this method is
|
* WARNING: Do NOT modify this code. The content of this method is always
|
||||||
* always regenerated by the Form Editor.
|
* regenerated by the Form Editor.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||||
@ -273,7 +276,6 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont
|
|||||||
currentPageLabel.setText(Integer.toString(currentPage));
|
currentPageLabel.setText(Integer.toString(currentPage));
|
||||||
setDataView(dataSource, currentOffset, false);
|
setDataView(dataSource, currentOffset, false);
|
||||||
}//GEN-LAST:event_goToPageTextFieldActionPerformed
|
}//GEN-LAST:event_goToPageTextFieldActionPerformed
|
||||||
|
|
||||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||||
private javax.swing.JMenuItem copyMenuItem;
|
private javax.swing.JMenuItem copyMenuItem;
|
||||||
private javax.swing.JLabel currentPageLabel;
|
private javax.swing.JLabel currentPageLabel;
|
||||||
@ -300,23 +302,39 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont
|
|||||||
* @param reset whether to reset the dataView or not
|
* @param reset whether to reset the dataView or not
|
||||||
*/
|
*/
|
||||||
public void setDataView(Content dataSource, long offset, boolean reset) {
|
public void setDataView(Content dataSource, long offset, boolean reset) {
|
||||||
|
if (dataSource == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// change the cursor to "waiting cursor" for this operation
|
// change the cursor to "waiting cursor" for this operation
|
||||||
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||||
try {
|
|
||||||
try {
|
|
||||||
this.dataSource = dataSource;
|
this.dataSource = dataSource;
|
||||||
|
String errorText = null;
|
||||||
|
Boolean setVisible = false;
|
||||||
|
|
||||||
int bytesRead = 0;
|
int bytesRead = 0;
|
||||||
if (!reset && dataSource.getSize() > 0) {
|
if (!reset && dataSource.getSize() > 0) {
|
||||||
|
try {
|
||||||
bytesRead = dataSource.read(data, offset, pageLength); // read the data
|
bytesRead = dataSource.read(data, offset, pageLength); // read the data
|
||||||
|
} catch (TskException ex) {
|
||||||
|
setVisible = true;
|
||||||
|
errorText = "(offset " + currentOffset + "-" + (currentOffset + pageLength)
|
||||||
|
+ " could not be read)";
|
||||||
|
Logger.getLogger(this.className).log(Level.WARNING, "Error while trying to show the hex content.", ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the data on the bottom and show it
|
// set the data on the bottom and show it
|
||||||
Boolean setVisible = false;
|
|
||||||
|
|
||||||
if (bytesRead > 0) {
|
if (bytesRead > 0) {
|
||||||
setVisible = true;
|
setVisible = true;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
errorText = "(offset " + currentOffset + "-" + (currentOffset + pageLength)
|
||||||
|
+ " could not be read)";
|
||||||
|
setVisible = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// disable or enable the next button
|
// disable or enable the next button
|
||||||
if (!reset && offset + pageLength < dataSource.getSize()) {
|
if (!reset && offset + pageLength < dataSource.getSize()) {
|
||||||
@ -340,7 +358,13 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont
|
|||||||
|
|
||||||
// set the output view
|
// set the output view
|
||||||
int showLength = bytesRead < pageLength ? bytesRead : (int) pageLength;
|
int showLength = bytesRead < pageLength ? bytesRead : (int) pageLength;
|
||||||
|
if (errorText == null) {
|
||||||
outputViewPane.setText(DataConversion.byteArrayToHex(data, showLength, offset, outputViewPane.getFont()));
|
outputViewPane.setText(DataConversion.byteArrayToHex(data, showLength, offset, outputViewPane.getFont()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
outputViewPane.setText(errorText);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// reset or hide the labels
|
// reset or hide the labels
|
||||||
totalPageLabel.setText("");
|
totalPageLabel.setText("");
|
||||||
@ -350,13 +374,9 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont
|
|||||||
}
|
}
|
||||||
|
|
||||||
outputViewPane.moveCaretPosition(0);
|
outputViewPane.moveCaretPosition(0);
|
||||||
} catch (TskException ex) {
|
|
||||||
// TODO: maybe make this error bubble up further
|
|
||||||
Logger.getLogger(this.className).log(Level.WARNING, "Error while trying to show the hex content.", ex);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
this.setCursor(null);
|
this.setCursor(null);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -426,12 +446,12 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont
|
|||||||
if (node == null) {
|
if (node == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
FsContent fsContent = node.getLookup().lookup(FsContent.class);
|
Content content = node.getLookup().lookup(Content.class);
|
||||||
LayoutFile lc = node.getLookup().lookup(LayoutFile.class);
|
|
||||||
if(fsContent != null && fsContent.getSize() != 0)
|
if (content != null && content.getSize() != 0) {
|
||||||
return true;
|
|
||||||
if(lc != null && lc.getSize() != 0)
|
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -455,7 +475,8 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont
|
|||||||
rightClickMenu.setLocation(evt.getLocationOnScreen());
|
rightClickMenu.setLocation(evt.getLocationOnScreen());
|
||||||
rightClickMenu.setVisible(true);
|
rightClickMenu.setVisible(true);
|
||||||
copyMenuItem.setEnabled(outputViewPane.getSelectedText() != null);
|
copyMenuItem.setEnabled(outputViewPane.getSelectedText() != null);
|
||||||
}else
|
} else {
|
||||||
rightClickMenu.setVisible(false);
|
rightClickMenu.setVisible(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -54,11 +54,12 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
|
|||||||
private Content dataSource;
|
private Content dataSource;
|
||||||
// for error handling
|
// for error handling
|
||||||
private String className = this.getClass().toString();
|
private String className = this.getClass().toString();
|
||||||
|
|
||||||
//string extract utility
|
//string extract utility
|
||||||
private final StringExtract stringExtract = new StringExtract();
|
private final StringExtract stringExtract = new StringExtract();
|
||||||
|
|
||||||
/** Creates new form DataContentViewerString */
|
/**
|
||||||
|
* Creates new form DataContentViewerString
|
||||||
|
*/
|
||||||
public DataContentViewerString() {
|
public DataContentViewerString() {
|
||||||
initComponents();
|
initComponents();
|
||||||
customizeComponents();
|
customizeComponents();
|
||||||
@ -71,11 +72,12 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
JMenuItem jmi = (JMenuItem) e.getSource();
|
JMenuItem jmi = (JMenuItem) e.getSource();
|
||||||
if(jmi.equals(copyMenuItem))
|
if (jmi.equals(copyMenuItem)) {
|
||||||
outputViewPane.copy();
|
outputViewPane.copy();
|
||||||
else if(jmi.equals(selectAllMenuItem))
|
} else if (jmi.equals(selectAllMenuItem)) {
|
||||||
outputViewPane.selectAll();
|
outputViewPane.selectAll();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
copyMenuItem.addActionListener(actList);
|
copyMenuItem.addActionListener(actList);
|
||||||
selectAllMenuItem.addActionListener(actList);
|
selectAllMenuItem.addActionListener(actList);
|
||||||
@ -87,10 +89,10 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method is called from within the constructor to
|
/**
|
||||||
* initialize the form.
|
* This method is called from within the constructor to initialize the form.
|
||||||
* WARNING: Do NOT modify this code. The content of this method is
|
* WARNING: Do NOT modify this code. The content of this method is always
|
||||||
* always regenerated by the Form Editor.
|
* regenerated by the Form Editor.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||||
@ -296,7 +298,6 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
|
|||||||
setDataView(dataSource, currentOffset, false);
|
setDataView(dataSource, currentOffset, false);
|
||||||
}
|
}
|
||||||
}//GEN-LAST:event_languageComboActionPerformed
|
}//GEN-LAST:event_languageComboActionPerformed
|
||||||
|
|
||||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||||
private javax.swing.JMenuItem copyMenuItem;
|
private javax.swing.JMenuItem copyMenuItem;
|
||||||
private javax.swing.JLabel currentPageLabel;
|
private javax.swing.JLabel currentPageLabel;
|
||||||
@ -325,21 +326,30 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
|
|||||||
* @param reset whether to reset the dataView or not
|
* @param reset whether to reset the dataView or not
|
||||||
*/
|
*/
|
||||||
public void setDataView(Content dataSource, long offset, boolean reset) {
|
public void setDataView(Content dataSource, long offset, boolean reset) {
|
||||||
|
if (dataSource == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// change the cursor to "waiting cursor" for this operation
|
// change the cursor to "waiting cursor" for this operation
|
||||||
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||||
try {
|
|
||||||
try {
|
|
||||||
this.dataSource = dataSource;
|
this.dataSource = dataSource;
|
||||||
|
|
||||||
int bytesRead = 0;
|
int bytesRead = 0;
|
||||||
if (!reset && dataSource.getSize() > 0) {
|
|
||||||
bytesRead = dataSource.read(data, offset, pageLength); // read the data
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// set the data on the bottom and show it
|
// set the data on the bottom and show it
|
||||||
String text = "";
|
String text = "";
|
||||||
Boolean setVisible = false;
|
Boolean setVisible = false;
|
||||||
|
if (!reset && dataSource.getSize() > 0) {
|
||||||
|
try {
|
||||||
|
bytesRead = dataSource.read(data, offset, pageLength); // read the data
|
||||||
|
} catch (TskException ex) {
|
||||||
|
text = "(offset " + currentOffset + "-" + (currentOffset + pageLength)
|
||||||
|
+ " could not be read)";
|
||||||
|
setVisible = true;
|
||||||
|
Logger logger = Logger.getLogger(this.className);
|
||||||
|
logger.log(Level.WARNING, "Error while trying to show the String content.", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (bytesRead > 0) {
|
if (bytesRead > 0) {
|
||||||
//text = DataConversion.getString(data, bytesRead, 4);
|
//text = DataConversion.getString(data, bytesRead, 4);
|
||||||
@ -353,6 +363,10 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
|
|||||||
}
|
}
|
||||||
|
|
||||||
setVisible = true;
|
setVisible = true;
|
||||||
|
} else {
|
||||||
|
text = "(offset " + currentOffset + "-" + (currentOffset + pageLength)
|
||||||
|
+ " could not be read)";
|
||||||
|
setVisible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// disable or enable the next button
|
// disable or enable the next button
|
||||||
@ -383,13 +397,9 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
|
|||||||
setComponentsVisibility(false); // hides the components that not needed
|
setComponentsVisibility(false); // hides the components that not needed
|
||||||
}
|
}
|
||||||
outputViewPane.moveCaretPosition(0);
|
outputViewPane.moveCaretPosition(0);
|
||||||
} catch (TskException ex) {
|
|
||||||
Logger logger = Logger.getLogger(this.className);
|
|
||||||
logger.log(Level.WARNING, "Error while trying to show the String content.", ex);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
this.setCursor(null);
|
this.setCursor(null);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -421,11 +431,11 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
|
|||||||
if (selectedNode != null) {
|
if (selectedNode != null) {
|
||||||
Lookup lookup = selectedNode.getLookup();
|
Lookup lookup = selectedNode.getLookup();
|
||||||
Content content = lookup.lookup(Content.class);
|
Content content = lookup.lookup(Content.class);
|
||||||
if (content != null) {
|
if (content
|
||||||
|
!= null) {
|
||||||
this.setDataView(content, 0, false);
|
this.setDataView(content, 0, false);
|
||||||
return;
|
return;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
StringContent scontent = selectedNode.getLookup().lookup(StringContent.class);
|
StringContent scontent = selectedNode.getLookup().lookup(StringContent.class);
|
||||||
if (scontent != null) {
|
if (scontent != null) {
|
||||||
this.setDataView(scontent);
|
this.setDataView(scontent);
|
||||||
@ -433,7 +443,6 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setDataView(null, 0, true);
|
this.setDataView(null, 0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -469,13 +478,17 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
|
|||||||
public boolean isSupported(Node node) {
|
public boolean isSupported(Node node) {
|
||||||
if (node == null) {
|
if (node == null) {
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
FsContent fsContent = node.getLookup().lookup(FsContent.class);
|
Content content = node.getLookup().lookup(Content.class);
|
||||||
LayoutFile lc = node.getLookup().lookup(LayoutFile.class);
|
|
||||||
if(fsContent != null && fsContent.getSize() != 0)
|
if (content
|
||||||
return true;
|
!= null && content.getSize()
|
||||||
if(lc != null && lc.getSize() != 0)
|
!= 0) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -523,7 +536,8 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
|
|||||||
rightClickMenu.setLocation(evt.getLocationOnScreen());
|
rightClickMenu.setLocation(evt.getLocationOnScreen());
|
||||||
rightClickMenu.setVisible(true);
|
rightClickMenu.setVisible(true);
|
||||||
copyMenuItem.setEnabled(outputViewPane.getSelectedText() != null);
|
copyMenuItem.setEnabled(outputViewPane.getSelectedText() != null);
|
||||||
}else
|
} else {
|
||||||
rightClickMenu.setVisible(false);
|
rightClickMenu.setVisible(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user