mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-15 01:07:42 +00:00
Merge pull request #6976 from kellykelly3/7599-move-queries-off-edt-string-content-viewer
7599 move queries off edt string content viewer
This commit is contained in:
commit
28a30060b0
@ -1,3 +1,4 @@
|
|||||||
|
StringContentPanel_Loading_String=Loading text...
|
||||||
StringsTextViewer.goToPageTextField.msgDlg=Please enter a valid page number between 1 and {0}
|
StringsTextViewer.goToPageTextField.msgDlg=Please enter a valid page number between 1 and {0}
|
||||||
StringsTextViewer.goToPageTextField.err=Invalid page number
|
StringsTextViewer.goToPageTextField.err=Invalid page number
|
||||||
StringsTextViewer.setDataView.errorText=(offset {0}-{1} could not be read)
|
StringsTextViewer.setDataView.errorText=(offset {0}-{1} could not be read)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Autopsy Forensic Browser
|
* Autopsy Forensic Browser
|
||||||
*
|
*
|
||||||
* Copyright 2011-2019 Basis Technology Corp.
|
* Copyright 2011-2021 Basis Technology Corp.
|
||||||
* Contact: carrier <at> sleuthkit <dot> org
|
* Contact: carrier <at> sleuthkit <dot> org
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@ -23,12 +23,15 @@ import java.awt.event.ActionEvent;
|
|||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import org.openide.util.NbBundle;
|
import org.openide.util.NbBundle;
|
||||||
import org.sleuthkit.autopsy.coreutils.Logger;
|
import org.sleuthkit.autopsy.coreutils.Logger;
|
||||||
import javax.swing.JMenuItem;
|
import javax.swing.JMenuItem;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.SwingWorker;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.openide.util.NbBundle.Messages;
|
||||||
import org.sleuthkit.autopsy.coreutils.StringExtract;
|
import org.sleuthkit.autopsy.coreutils.StringExtract;
|
||||||
import org.sleuthkit.autopsy.coreutils.StringExtract.StringExtractResult;
|
import org.sleuthkit.autopsy.coreutils.StringExtract.StringExtractResult;
|
||||||
import org.sleuthkit.autopsy.coreutils.StringExtract.StringExtractUnicodeTable.SCRIPT;
|
import org.sleuthkit.autopsy.coreutils.StringExtract.StringExtractUnicodeTable.SCRIPT;
|
||||||
@ -49,10 +52,10 @@ public class StringsContentPanel extends javax.swing.JPanel {
|
|||||||
private final byte[] data = new byte[(int) PAGE_LENGTH];
|
private final byte[] data = new byte[(int) PAGE_LENGTH];
|
||||||
private static int currentPage = 1;
|
private static int currentPage = 1;
|
||||||
private Content dataSource;
|
private Content dataSource;
|
||||||
//string extract utility
|
|
||||||
private final StringExtract stringExtract = new StringExtract();
|
|
||||||
private static final Logger logger = Logger.getLogger(StringsContentPanel.class.getName());
|
private static final Logger logger = Logger.getLogger(StringsContentPanel.class.getName());
|
||||||
|
|
||||||
|
private SwingWorker<String, Void> worker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new form StringsTextViewer
|
* Creates new form StringsTextViewer
|
||||||
*/
|
*/
|
||||||
@ -81,10 +84,10 @@ public class StringsContentPanel extends javax.swing.JPanel {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// use wrap layout for better component wrapping
|
// use wrap layout for better component wrapping
|
||||||
WrapLayout layout = new WrapLayout(0,5);
|
WrapLayout layout = new WrapLayout(0, 5);
|
||||||
layout.setOppositeAligned(Arrays.asList(panelScriptSelect));
|
layout.setOppositeAligned(Arrays.asList(panelScriptSelect));
|
||||||
controlPanel.setLayout(layout);
|
controlPanel.setLayout(layout);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final void resetDisplay() {
|
final void resetDisplay() {
|
||||||
@ -363,6 +366,10 @@ public class StringsContentPanel extends javax.swing.JPanel {
|
|||||||
private javax.swing.JLabel totalPageLabel;
|
private javax.swing.JLabel totalPageLabel;
|
||||||
// End of variables declaration//GEN-END:variables
|
// End of variables declaration//GEN-END:variables
|
||||||
|
|
||||||
|
@Messages({
|
||||||
|
"StringContentPanel_Loading_String=Loading text..."
|
||||||
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the DataView (The tabbed panel)
|
* Sets the DataView (The tabbed panel)
|
||||||
*
|
*
|
||||||
@ -370,83 +377,36 @@ public class StringsContentPanel extends javax.swing.JPanel {
|
|||||||
* @param offset the starting offset
|
* @param offset the starting offset
|
||||||
*/
|
*/
|
||||||
void setDataView(Content dataSource, long offset) {
|
void setDataView(Content dataSource, long offset) {
|
||||||
|
|
||||||
|
if (worker != null) {
|
||||||
|
worker.cancel(true);
|
||||||
|
worker = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (dataSource == null) {
|
if (dataSource == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// change the cursor to "waiting cursor" for this operation
|
|
||||||
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
|
||||||
this.dataSource = dataSource;
|
|
||||||
int bytesRead = 0;
|
|
||||||
// set the data on the bottom and show it
|
|
||||||
|
|
||||||
if (dataSource.getSize() > 0) {
|
worker = new ContentWorker(dataSource, offset);
|
||||||
try {
|
outputViewPane.setText(Bundle.StringContentPanel_Loading_String());
|
||||||
bytesRead = dataSource.read(data, offset, PAGE_LENGTH); // read the data
|
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||||
} catch (TskCoreException ex) {
|
worker.execute();
|
||||||
logger.log(Level.WARNING, "Error while trying to show the String content.", ex); //NON-NLS
|
|
||||||
}
|
|
||||||
}
|
|
||||||
String text;
|
|
||||||
if (bytesRead > 0) {
|
|
||||||
//text = DataConversion.getString(data, bytesRead, 4);
|
|
||||||
final SCRIPT selScript = (SCRIPT) languageCombo.getSelectedItem();
|
|
||||||
stringExtract.setEnabledScript(selScript);
|
|
||||||
StringExtractResult res = stringExtract.extract(data, bytesRead, 0);
|
|
||||||
text = res.getText();
|
|
||||||
if (StringUtils.isBlank(text)) {
|
|
||||||
text = NbBundle.getMessage(this.getClass(),
|
|
||||||
"StringsTextViewer.setDataView.errorNoText", currentOffset,
|
|
||||||
currentOffset + PAGE_LENGTH);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
text = NbBundle.getMessage(this.getClass(), "StringsTextViewer.setDataView.errorText", currentOffset,
|
|
||||||
currentOffset + PAGE_LENGTH);
|
|
||||||
}
|
|
||||||
|
|
||||||
// disable or enable the next button
|
|
||||||
if (offset + PAGE_LENGTH < dataSource.getSize()) {
|
|
||||||
nextPageButton.setEnabled(true);
|
|
||||||
} else {
|
|
||||||
nextPageButton.setEnabled(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (offset == 0) {
|
|
||||||
prevPageButton.setEnabled(false);
|
|
||||||
currentPage = 1; // reset the page number
|
|
||||||
} else {
|
|
||||||
prevPageButton.setEnabled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
int totalPage = Math.round((dataSource.getSize() - 1) / PAGE_LENGTH) + 1;
|
|
||||||
totalPageLabel.setText(Integer.toString(totalPage));
|
|
||||||
currentPageLabel.setText(Integer.toString(currentPage));
|
|
||||||
outputViewPane.setText(text); // set the output view
|
|
||||||
setComponentsVisibility(true); // shows the components that not needed
|
|
||||||
outputViewPane.moveCaretPosition(0);
|
|
||||||
|
|
||||||
this.setCursor(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDataView(StringContent dataSource) {
|
void setDataView(StringContent dataSource) {
|
||||||
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
if (worker != null) {
|
||||||
try {
|
worker.cancel(true);
|
||||||
this.dataSource = null;
|
worker = null;
|
||||||
|
|
||||||
// set the data on the bottom and show it
|
|
||||||
String text = dataSource.getString();
|
|
||||||
nextPageButton.setEnabled(false);
|
|
||||||
prevPageButton.setEnabled(false);
|
|
||||||
currentPage = 1;
|
|
||||||
|
|
||||||
int totalPage = 1;
|
|
||||||
totalPageLabel.setText(Integer.toString(totalPage));
|
|
||||||
currentPageLabel.setText(Integer.toString(currentPage));
|
|
||||||
outputViewPane.setText(text); // set the output view
|
|
||||||
setComponentsVisibility(true); // shows the components that not needed
|
|
||||||
outputViewPane.moveCaretPosition(0);
|
|
||||||
} finally {
|
|
||||||
this.setCursor(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dataSource == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
worker = new StringContentWorker(dataSource);
|
||||||
|
outputViewPane.setText(Bundle.StringContentPanel_Loading_String());
|
||||||
|
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||||
|
worker.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -468,4 +428,145 @@ public class StringsContentPanel extends javax.swing.JPanel {
|
|||||||
languageLabel.setVisible(isVisible);
|
languageLabel.setVisible(isVisible);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Swingworker for getting the text from a content object.
|
||||||
|
*/
|
||||||
|
private final class ContentWorker extends SwingWorker<String, Void> {
|
||||||
|
|
||||||
|
private final Content content;
|
||||||
|
private final long offset;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ContentWorker constructor
|
||||||
|
*
|
||||||
|
* @param content Content to get text from.
|
||||||
|
* @param offset The starting offset.
|
||||||
|
*/
|
||||||
|
ContentWorker(Content content, long offset) {
|
||||||
|
this.content = content;
|
||||||
|
this.offset = offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String doInBackground() throws Exception {
|
||||||
|
int bytesRead = 0;
|
||||||
|
// set the data on the bottom and show it
|
||||||
|
|
||||||
|
if (content.getSize() > 0) {
|
||||||
|
try {
|
||||||
|
bytesRead = content.read(data, offset, PAGE_LENGTH); // read the data
|
||||||
|
} catch (TskCoreException ex) {
|
||||||
|
logger.log(Level.WARNING, "Error while trying to show the String content.", ex); //NON-NLS
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String text;
|
||||||
|
if (bytesRead > 0) {
|
||||||
|
//text = DataConversion.getString(data, bytesRead, 4);
|
||||||
|
final SCRIPT selScript = (SCRIPT) languageCombo.getSelectedItem();
|
||||||
|
StringExtract stringExtract = new StringExtract();
|
||||||
|
stringExtract.setEnabledScript(selScript);
|
||||||
|
StringExtractResult res = stringExtract.extract(data, bytesRead, 0);
|
||||||
|
text = res.getText();
|
||||||
|
if (StringUtils.isBlank(text)) {
|
||||||
|
text = NbBundle.getMessage(this.getClass(),
|
||||||
|
"StringsTextViewer.setDataView.errorNoText", currentOffset,
|
||||||
|
currentOffset + PAGE_LENGTH);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
text = NbBundle.getMessage(this.getClass(), "StringsTextViewer.setDataView.errorText", currentOffset,
|
||||||
|
currentOffset + PAGE_LENGTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void done() {
|
||||||
|
if (isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String text = get();
|
||||||
|
dataSource = content;
|
||||||
|
|
||||||
|
// disable or enable the next button
|
||||||
|
if (offset + PAGE_LENGTH < dataSource.getSize()) {
|
||||||
|
nextPageButton.setEnabled(true);
|
||||||
|
} else {
|
||||||
|
nextPageButton.setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (offset == 0) {
|
||||||
|
prevPageButton.setEnabled(false);
|
||||||
|
currentPage = 1; // reset the page number
|
||||||
|
} else {
|
||||||
|
prevPageButton.setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
int totalPage = Math.round((dataSource.getSize() - 1) / PAGE_LENGTH) + 1;
|
||||||
|
totalPageLabel.setText(Integer.toString(totalPage));
|
||||||
|
currentPageLabel.setText("1");
|
||||||
|
outputViewPane.setText(text); // set the output view
|
||||||
|
setComponentsVisibility(true); // shows the components that not needed
|
||||||
|
outputViewPane.moveCaretPosition(0);
|
||||||
|
|
||||||
|
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
||||||
|
|
||||||
|
} catch (InterruptedException | ExecutionException ex) {
|
||||||
|
logger.log(Level.SEVERE, String.format("Failed to get text from content (id=%d)", content.getId()), ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SwingWorker for getting the text from a StringContent object.
|
||||||
|
*/
|
||||||
|
private final class StringContentWorker extends SwingWorker<String, Void> {
|
||||||
|
|
||||||
|
private final StringContent content;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to pulling the text out of a string content object.
|
||||||
|
*
|
||||||
|
* @param content
|
||||||
|
*/
|
||||||
|
StringContentWorker(StringContent content) {
|
||||||
|
this.content = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String doInBackground() throws Exception {
|
||||||
|
return content.getString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void done() {
|
||||||
|
if (isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
String text = get();
|
||||||
|
|
||||||
|
dataSource = null;
|
||||||
|
nextPageButton.setEnabled(false);
|
||||||
|
prevPageButton.setEnabled(false);
|
||||||
|
currentPage = 1;
|
||||||
|
|
||||||
|
totalPageLabel.setText("1");
|
||||||
|
currentPageLabel.setText("1");
|
||||||
|
outputViewPane.setText(text); // set the output view
|
||||||
|
setComponentsVisibility(true); // shows the components that not needed
|
||||||
|
outputViewPane.moveCaretPosition(0);
|
||||||
|
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
||||||
|
|
||||||
|
} catch (InterruptedException | ExecutionException ex) {
|
||||||
|
logger.log(Level.SEVERE, String.format("Failed to get text from StringContent"), ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user