Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to PR #4074 (Linux Local Disk) #7686

Draft
wants to merge 15 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -168,6 +168,7 @@ LocalDiskPanel.imageWriterError.isDirectory=Error - VHD path is a directory
LocalDiskPanel.localDiskMessage.unspecified=Unspecified
LocalDiskPanel.moduleErrorMessage.body=A module caused an error listening to LocalDiskPanel updates. See log to determine which module. Some data could be incomplete.
LocalDiskPanel.moduleErrorMessage.title=Module Error
LocalDiskSelectionDialog.columnName.Details=Details
LocalDiskSelectionDialog.columnName.diskName=Disk Name
LocalDiskSelectionDialog.columnName.diskSize=Disk Size
LocalDiskSelectionDialog.errorMessage.disksNotDetected=Disks were not detected. On some systems it requires admin privileges (or "Run as administrator").
Expand Down
Expand Up @@ -7,6 +7,7 @@
<ResourceString bundle="org/sleuthkit/autopsy/casemodule/Bundle.properties" key="LocalDiskSelectionDialog.title" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="alwaysOnTop" type="boolean" value="true"/>
<Property name="modal" type="boolean" value="true"/>
<Property name="resizable" type="boolean" value="false"/>
</Properties>
<SyntheticProperties>
Expand Down
Expand Up @@ -18,19 +18,25 @@
*/
package org.sleuthkit.autopsy.casemodule;

import java.awt.Component;
import java.awt.Window;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.SwingWorker;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;
import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessor;
Expand All @@ -56,7 +62,8 @@ final class LocalDiskSelectionDialog extends JDialog {
private static final long serialVersionUID = 1L;
private List<LocalDisk> disks;
private final LocalDiskModel model;

private final TooltipCellRenderer tooltipCellRenderer = new TooltipCellRenderer();

/**
* Creates a new LocalDiskSelectionDialog instance.
*/
Expand All @@ -69,6 +76,10 @@ final class LocalDiskSelectionDialog extends JDialog {
initComponents();
refreshTable();

for (Enumeration<TableColumn> e = localDiskTable.getColumnModel().getColumns(); e.hasMoreElements();) {
e.nextElement().setCellRenderer(tooltipCellRenderer);
}

localDiskTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
Expand All @@ -82,10 +93,7 @@ public void valueChanged(ListSelectionEvent e) {
* Display the dialog.
*/
void display() {
setModal(true);
setSize(getPreferredSize());
setLocationRelativeTo(this.getParent());
setAlwaysOnTop(false);
setVisible(true);
}

Expand All @@ -109,6 +117,7 @@ private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle(org.openide.util.NbBundle.getMessage(LocalDiskSelectionDialog.class, "LocalDiskSelectionDialog.title")); // NOI18N
setAlwaysOnTop(true);
setModal(true);
setResizable(false);

org.openide.awt.Mnemonics.setLocalizedText(selectLocalDiskLabel, org.openide.util.NbBundle.getMessage(LocalDiskSelectionDialog.class, "LocalDiskSelectionDialog.selectLocalDiskLabel.text")); // NOI18N
Expand Down Expand Up @@ -255,6 +264,21 @@ LocalDisk getLocalDiskSelection() {
}
return null;
}

/**
* Shows tooltip for cell.
*/
private class TooltipCellRenderer extends DefaultTableCellRenderer {
public Component getTableCellRendererComponent(
JTable table, Object value,
boolean isSelected, boolean hasFocus,
int row, int column) {
JLabel c = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
String tooltip = value == null ? "" : value.toString();
c.setToolTipText(tooltip);
return c;
}
}

@NbBundle.Messages({
"LocalDiskSelectionDialog.tableMessage.loading=Loading local disks...",
Expand Down Expand Up @@ -295,13 +319,17 @@ public int getRowCount() {

@Override
public int getColumnCount() {
return 2;

if (PlatformUtil.isLinuxOS()) {
return 3;
} else {
return 2;
}
}

@NbBundle.Messages({
"LocalDiskSelectionDialog.columnName.diskName=Disk Name",
"LocalDiskSelectionDialog.columnName.diskSize=Disk Size"
"LocalDiskSelectionDialog.columnName.diskSize=Disk Size",
"LocalDiskSelectionDialog.columnName.Details=Details"
})

@Override
Expand All @@ -311,6 +339,8 @@ public String getColumnName(int columnIndex) {
return Bundle.LocalDiskSelectionDialog_columnName_diskName();
case 1:
return Bundle.LocalDiskSelectionDialog_columnName_diskSize();
case 2:
return Bundle.LocalDiskSelectionDialog_columnName_Details();
default:
return "Unnamed"; //NON-NLS
}
Expand All @@ -337,6 +367,8 @@ public Object getValueAt(int rowIndex, int columnIndex) {
return disks.get(rowIndex).getName();
case 1:
return disks.get(rowIndex).getReadableSize();
case 2:
return disks.get(rowIndex).getDetail();
default:
return disks.get(rowIndex).getPath();
}
Expand Down
Expand Up @@ -11,6 +11,8 @@ GetOrGenerateThumbnailTask.generatingPreviewFor=Generating preview for {0}
GetOrGenerateThumbnailTask.loadingThumbnailFor=Loading thumbnail for {0}
ImageUtils.ffmpegLoadedError.msg=OpenCV FFMpeg library failed to load, see log for more details
ImageUtils.ffmpegLoadedError.title=OpenCV FFMpeg
LocalDisk_getDetail_autopsyConfig=Autopsy Config
LocalDisk_getDetail_cdRom=CD-ROM
OpenIDE-Module-Name=CoreUtils
JLNK.noPrefPath.text=No preferred path found
PlatformUtil.nameUnknown=unknown
Expand Down
81 changes: 81 additions & 0 deletions Core/src/org/sleuthkit/autopsy/coreutils/LocalDisk.java
Expand Up @@ -18,6 +18,17 @@
*/
package org.sleuthkit.autopsy.coreutils;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import org.openide.util.NbBundle.Messages;

/**
* Representation of a PhysicalDisk or partition.
*/
Expand All @@ -26,11 +37,17 @@ public class LocalDisk {
private String name;
private String path;
private long size;
private String mountPoint;
private static final Logger logger = Logger.getLogger(LocalDisk.class.getName());

public LocalDisk(String name, String path, long size) {
this.name = name;
this.path = path;
this.size = size;
mountPoint = "";
if (PlatformUtil.isLinuxOS() ) {
findLinuxMointPoint(this.path);
}
}

public String getName() {
Expand All @@ -44,6 +61,30 @@ public String getPath() {
public long getSize() {
return size;
}

/**
* Returns details about the mount point
* of the drive as well as if it is an Autopsy
* config or iso.
*
* NOTE: Currently only works for linux.
*/
@Messages({
"LocalDisk_getDetail_autopsyConfig=Autopsy Config",
"LocalDisk_getDetail_cdRom=CD-ROM",
})
public String getDetail() {
String toRet = mountPoint == null ? "" : mountPoint;
if(isConfigDrive()) {
toRet += ", " + Bundle.LocalDisk_getDetail_autopsyConfig();
}

if (isCDDrive()) {
toRet += ", " + Bundle.LocalDisk_getDetail_cdRom();
}

return toRet;
}

public String getReadableSize() {
int unit = 1024;
Expand All @@ -60,4 +101,44 @@ public String toString() {
return name + ": " + getReadableSize();
}

private void findLinuxMointPoint(String path) {
try {
List<String> commandLine = new ArrayList<>();
commandLine.add("/bin/bash");
commandLine.add("-c");
commandLine.add("df -h | grep " + path + " | awk '{print $6}'");

ProcessBuilder pb = new ProcessBuilder(commandLine);
Process process = pb.start();

BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
StringBuilder builder = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
this.mountPoint = builder.toString();
process.destroy();
} catch (IOException ex) {
logger.log(Level.WARNING, "Unable to find the mount point for the device", ex);
}
}

/**
* If AutopsyConfig folder is present, linux autopsy will display drive
* details including 'Autopsy Config'.
*/
private boolean isConfigDrive() {
Path path = Paths.get(this.mountPoint, "AutopsyConfig");
File configFile = new File(path.toString());
return configFile.exists();
}

/**
* For linux autopsy, determines if drive is CD-ROM if the device starts
* with /dev/sr.
*/
private boolean isCDDrive() {
return this.path.toString().trim().toLowerCase().startsWith("/dev/sr");
}
}
15 changes: 13 additions & 2 deletions Core/src/org/sleuthkit/autopsy/coreutils/PlatformUtil.java
Expand Up @@ -335,6 +335,15 @@ public static boolean isWindowsOS() {
return PlatformUtil.getOSName().toLowerCase().contains("windows"); //NON-NLS
}

/**
* Check if running on Linux OS
*
* @return true if running on Linux OS
*/
public static boolean isLinuxOS() {
return PlatformUtil.getOSName().toLowerCase().contains("linux");
}

/**
* Convert file path (quote) for OS specific
*
Expand Down Expand Up @@ -406,11 +415,12 @@ public static List<LocalDisk> getPhysicalDrives() {
}
// Linux drives
} else {
int drivelength = isLinuxOS() ? 3 : 5;
File dev = new File("/dev/");
File[] files = dev.listFiles();
for (File f : files) {
String name = f.getName();
if ((name.contains("hd") || name.contains("sd") || name.contains("disk")) && f.canRead() && name.length() <= 5) { //NON-NLS
if ((name.contains("hd") || name.contains("sd") || name.contains("sr") || name.contains("disk")) && f.canRead() && name.length() <= drivelength) { //NON-NLS
String path = "/dev/" + name; //NON-NLS
if (canReadDrive(path)) {
try {
Expand Down Expand Up @@ -449,11 +459,12 @@ public static List<LocalDisk> getPartitions() {
}
}
} else {
int partitionLength = isLinuxOS() ? 4 : 7;
File dev = new File("/dev/");
File[] files = dev.listFiles();
for (File f : files) {
String name = f.getName();
if ((name.contains("hd") || name.contains("sd") || name.contains("disk")) && f.canRead() && name.length() <= 7) { //NON-NLS
if ((name.contains("hd") || name.contains("sd") || name.contains("disk")) && f.canRead() && name.length() <= partitionLength) { //NON-NLS
String path = "/dev/" + name; //NON-NLS
if (canReadDrive(path)) {
drives.add(new LocalDisk(path, path, f.getTotalSpace()));
Expand Down