mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-20 03:24:55 +00:00
improve plaso modules getAbstractFile() method to be more robust; use try-with-resources
This commit is contained in:
parent
d3429c2c97
commit
15af1e03d0
@ -20,6 +20,7 @@ package org.sleuthkit.autopsy.modules.plaso;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
@ -43,6 +44,7 @@ import org.sleuthkit.autopsy.ingest.IngestJobContext;
|
||||
import org.sleuthkit.autopsy.ingest.IngestMessage;
|
||||
import org.sleuthkit.autopsy.ingest.IngestServices;
|
||||
import org.sleuthkit.datamodel.AbstractFile;
|
||||
import org.sleuthkit.datamodel.Blackboard.BlackboardException;
|
||||
import org.sleuthkit.datamodel.BlackboardArtifact;
|
||||
import static org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_TL_EVENT;
|
||||
import org.sleuthkit.datamodel.BlackboardAttribute;
|
||||
@ -270,9 +272,9 @@ public class PlasoIngestModule implements DataSourceIngestModule {
|
||||
String connectionString = "jdbc:sqlite:" + plasoDb; //NON-NLS
|
||||
String sqlStatement = "select substr(filename,1) filename, strftime('%s', datetime) 'epoch_date', description, source, type, sourcetype \n"
|
||||
+ " from log2timeline where source not in ('FILE') and sourcetype not in ('UNKNOWN');";
|
||||
try {
|
||||
SQLiteDBConnect tempdbconnect = new SQLiteDBConnect("org.sqlite.JDBC", connectionString); //NON-NLS
|
||||
try (ResultSet resultSet = tempdbconnect.executeQry(sqlStatement)) {
|
||||
|
||||
try (SQLiteDBConnect tempdbconnect = new SQLiteDBConnect("org.sqlite.JDBC", connectionString); //NON-NLS
|
||||
ResultSet resultSet = tempdbconnect.executeQry(sqlStatement)) {
|
||||
while (resultSet.next()) {
|
||||
if (context.dataSourceIngestIsCancelled()) {
|
||||
logger.log(Level.INFO, Bundle.PlasoIngestModule_create_artifacts_cancelled()); //NON-NLS
|
||||
@ -313,12 +315,12 @@ public class PlasoIngestModule implements DataSourceIngestModule {
|
||||
bbart.addAttributes(bbattributes);
|
||||
try {
|
||||
/*
|
||||
* post the artifact which will index the artifact
|
||||
* for keyword search, and fire an event to notify
|
||||
* UI of this new artifact
|
||||
* post the artifact which will index the artifact for
|
||||
* keyword search, and fire an event to notify UI of
|
||||
* this new artifact
|
||||
*/
|
||||
blackboard.postArtifact(bbart, MODULE_NAME);
|
||||
} catch (org.sleuthkit.datamodel.Blackboard.BlackboardException ex) {
|
||||
} catch (BlackboardException ex) {
|
||||
logger.log(Level.INFO, Bundle.PlasoIngestModule_exception_posting_artifact(), ex); //NON-NLS
|
||||
}
|
||||
|
||||
@ -326,8 +328,6 @@ public class PlasoIngestModule implements DataSourceIngestModule {
|
||||
logger.log(Level.INFO, Bundle.PlasoIngestModule_exception_adding_artifact(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
tempdbconnect.closeConnection();
|
||||
} catch (SQLException ex) {
|
||||
logger.log(Level.SEVERE, Bundle.PlasoIngestModule_exception_database_error(), ex); //NON-NLS
|
||||
}
|
||||
@ -336,12 +336,12 @@ public class PlasoIngestModule implements DataSourceIngestModule {
|
||||
@NbBundle.Messages({"PlasoIngestModule_exception_find_file=Exception finding file."})
|
||||
private AbstractFile getAbstractFile(String file) {
|
||||
|
||||
List<AbstractFile> abstractFiles;
|
||||
File eventFile = new File(file.replaceAll("\\\\", "/"));
|
||||
String fileName = eventFile.getName().toLowerCase();
|
||||
String filePath = eventFile.getParent();
|
||||
filePath = filePath.replaceAll("\\\\", "/");
|
||||
filePath = filePath.toLowerCase() + "/";
|
||||
Path path = Paths.get(file);
|
||||
String fileName = path.getFileName().toString();
|
||||
String filePath = path.getParent().toString().replaceAll("\\\\", "/");
|
||||
if (filePath.endsWith("/") == false) {
|
||||
filePath += "/";
|
||||
}
|
||||
|
||||
// check the cached file
|
||||
if (previousFile != null
|
||||
@ -351,7 +351,7 @@ public class PlasoIngestModule implements DataSourceIngestModule {
|
||||
|
||||
}
|
||||
try {
|
||||
abstractFiles = fileManager.findFiles(fileName, filePath);
|
||||
List<AbstractFile> abstractFiles = fileManager.findFiles(fileName, filePath);
|
||||
if (abstractFiles.size() == 1) {
|
||||
return abstractFiles.get(0);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user