format files and remove commented code

format files and remove commented code
This commit is contained in:
Mark McKinnon 2020-09-03 22:56:40 -04:00
parent b04622d308
commit 641bdab2c4
2 changed files with 135 additions and 128 deletions

View File

@ -150,7 +150,7 @@ public class ILeappAnalyserIngestModule implements DataSourceIngestModule {
if (!iLeappFilesToProcess.isEmpty()) {
// Run iLeapp
for (AbstractFile iLeappFile: iLeappFilesToProcess) {
for (AbstractFile iLeappFile : iLeappFilesToProcess) {
String currentTime = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss z", Locale.US).format(System.currentTimeMillis());//NON-NLS
Path moduleOutputPath = Paths.get(currentCase.getModuleDirectory(), ILEAPP, currentTime);
@ -170,8 +170,8 @@ public class ILeappAnalyserIngestModule implements DataSourceIngestModule {
return ProcessResult.ERROR;
}
} catch (IOException ex) {
logger.log(Level.SEVERE, String.format("Error when trying to execute iLeapp program against file %s", iLeappFile.getLocalAbsPath()), ex);
return ProcessResult.ERROR;
logger.log(Level.SEVERE, String.format("Error when trying to execute iLeapp program against file %s", iLeappFile.getLocalAbsPath()), ex);
return ProcessResult.ERROR;
}
if (context.dataSourceIngestIsCancelled()) {
@ -185,8 +185,8 @@ public class ILeappAnalyserIngestModule implements DataSourceIngestModule {
processiLeappFiles(iLeappTsvOutputFiles, iLeappFile, statusHelper);
}
} catch (IOException | IngestModuleException ex) {
logger.log(Level.SEVERE, String.format("Error trying to process iLeapp output files in directory %s. ", moduleOutputPath.toString()), ex); //NON-NLS
return ProcessResult.ERROR;
logger.log(Level.SEVERE, String.format("Error trying to process iLeapp output files in directory %s. ", moduleOutputPath.toString()), ex); //NON-NLS
return ProcessResult.ERROR;
}
filesProcessedCount++;
@ -205,6 +205,7 @@ public class ILeappAnalyserIngestModule implements DataSourceIngestModule {
* Find the files to process that will be processed by the iLeapp program
*
* @param dataSource
*
* @return List of abstract files to process.
*/
private List<AbstractFile> findiLeappFilesToProcess(Content dataSource) {
@ -218,14 +219,14 @@ public class ILeappAnalyserIngestModule implements DataSourceIngestModule {
iLeappFiles = fileManager.findFiles(dataSource, "%", "/"); //NON-NLS
} catch (TskCoreException ex) {
//Change this
logger.log(Level.WARNING, "No files found to process"); //NON-NLS
return iLeappFiles;
logger.log(Level.WARNING, "No files found to process"); //NON-NLS
return iLeappFiles;
}
List<AbstractFile> iLeappFilesToProcess = new ArrayList<>();
for (AbstractFile iLeappFile: iLeappFiles) {
for (AbstractFile iLeappFile : iLeappFiles) {
if ((iLeappFile.getName().toLowerCase().contains(".zip") || (iLeappFile.getName().toLowerCase().contains(".tar"))
|| iLeappFile.getName().toLowerCase().contains(".tgz"))) {
|| iLeappFile.getName().toLowerCase().contains(".tgz"))) {
iLeappFilesToProcess.add(iLeappFile);
}
}
@ -266,12 +267,12 @@ public class ILeappAnalyserIngestModule implements DataSourceIngestModule {
return exeFile;
}
@NbBundle.Messages({
@NbBundle.Messages({
"ILeappAnalyserIngestModule.error.reading.iLeapp.directory=Error reading iLeapp Output directory."})
/**
* Find the tsv files in the iLeapp output directory and match them to files we know we want to process
* and return the list to process those files.
* Find the tsv files in the iLeapp output directory and match them to files
* we know we want to process and return the list to process those files.
*/
private List<String> findTsvFiles(Path iLeapOutputDir) throws IngestModuleException {
List<String> allTsvFiles = new ArrayList<>();
@ -279,8 +280,8 @@ public class ILeappAnalyserIngestModule implements DataSourceIngestModule {
try (Stream<Path> walk = Files.walk(iLeapOutputDir)) {
allTsvFiles = walk.map(x -> x.toString())
.filter(f -> f.endsWith(".tsv")).collect(Collectors.toList());
allTsvFiles = walk.map(x -> x.toString())
.filter(f -> f.endsWith(".tsv")).collect(Collectors.toList());
for (String tsvFile : allTsvFiles) {
if (tsvFiles.containsKey(FilenameUtils.getName(tsvFile))) {
@ -298,9 +299,11 @@ public class ILeappAnalyserIngestModule implements DataSourceIngestModule {
/**
* Process the iLeapp files that were found that match the xml mapping file
*
* @param iLeappFilesToProcess List of files to process
* @param iLeappImageFile Abstract file to create artifact for
* @param statusHelper progress bar update
* @param iLeappImageFile Abstract file to create artifact for
* @param statusHelper progress bar update
*
* @throws FileNotFoundException
* @throws IOException
*/
@ -311,7 +314,6 @@ public class ILeappAnalyserIngestModule implements DataSourceIngestModule {
String fileName = FilenameUtils.getName(iLeappFileName);
statusHelper.progress(NbBundle.getMessage(this.getClass(), "ILeappAnalyserIngestModule.parsing.file", fileName));
File iLeappFile = new File(iLeappFileName);
// List<List<String>> attrList = new ArrayList<>();
if (tsvFileAttributes.containsKey(fileName)) {
List<List<String>> attrList = tsvFileAttributes.get(fileName);
try {
@ -324,7 +326,6 @@ public class ILeappAnalyserIngestModule implements DataSourceIngestModule {
HashMap<Integer, String> columnNumberToProcess = findColumnsToProcess(line, attrList);
line = reader.readLine();
while (line != null) {
// Collection<BlackboardAttribute> bbattributes = new ArrayList<BlackboardAttribute>();
Collection<BlackboardAttribute> bbattributes = processReadLine(line, columnNumberToProcess, fileName);
if (!bbattributes.isEmpty()) {
BlackboardArtifact bbartifact = createArtifactWithAttributes(artifactType.getTypeID(), iLeappImageFile, bbattributes);
@ -337,8 +338,8 @@ public class ILeappAnalyserIngestModule implements DataSourceIngestModule {
}
}
} catch (TskCoreException ex) {
// check this
throw new IngestModuleException(String.format("Error getting Blackboard Artifact Type for %s", tsvFileArtifacts.get(fileName)), ex);
// check this
throw new IngestModuleException(String.format("Error getting Blackboard Artifact Type for %s", tsvFileArtifacts.get(fileName)), ex);
}
}
@ -352,8 +353,10 @@ public class ILeappAnalyserIngestModule implements DataSourceIngestModule {
/**
* Process the line read and create the necessary attributes for it
* @param line a tsv line to process that was read
*
* @param line a tsv line to process that was read
* @param columnNumberToProcess Which columns to process in the tsv line
*
* @return
*/
private Collection<BlackboardAttribute> processReadLine(String line, HashMap<Integer, String> columnNumberToProcess, String fileName) throws IngestModuleException {
@ -361,7 +364,7 @@ public class ILeappAnalyserIngestModule implements DataSourceIngestModule {
Collection<BlackboardAttribute> bbattributes = new ArrayList<BlackboardAttribute>();
for (Map.Entry<Integer, String> columnToProcess: columnNumberToProcess.entrySet()) {
for (Map.Entry<Integer, String> columnToProcess : columnNumberToProcess.entrySet()) {
Integer columnNumber = columnToProcess.getKey();
String attributeName = columnToProcess.getValue();
@ -387,7 +390,7 @@ public class ILeappAnalyserIngestModule implements DataSourceIngestModule {
Long dateLong = Long.valueOf(0);
try {
Date newDate = dateFormat.parse(columnValues[columnNumber]);
dateLong = newDate.getTime()/1000;
dateLong = newDate.getTime() / 1000;
bbattributes.add(new BlackboardAttribute(attributeType, MODULE_NAME, dateLong));
} catch (ParseException ex) {
// catching error and displaying date that could not be parsed
@ -416,11 +419,15 @@ public class ILeappAnalyserIngestModule implements DataSourceIngestModule {
}
/**
* Process the first line of the tsv file which has the headings. Match the headings to the columns in the XML
* mapping file so we know which columns to process.
* @param line a tsv heading line of the columns in the file
* Process the first line of the tsv file which has the headings. Match the
* headings to the columns in the XML mapping file so we know which columns
* to process.
*
* @param line a tsv heading line of the columns in the file
* @param attrList the list of headings we want to process
* @return the numbered column(s) and attribute(s) we want to use for the column(s)
*
* @return the numbered column(s) and attribute(s) we want to use for the
* column(s)
*/
private HashMap<Integer, String> findColumnsToProcess(String line, List<List<String>> attrList) {
String[] columnNames = line.split("\\t");
@ -442,13 +449,13 @@ public class ILeappAnalyserIngestModule implements DataSourceIngestModule {
return columnsToProcess;
}
@NbBundle.Messages({
@NbBundle.Messages({
"ILeappAnalyserIngestModule.cannot.load.artifact.xml=Cannor load xml artifact file.",
"ILeappAnalyserIngestModule.cannotBuildXmlParser=Cannot buld an XML parser.",
"ILeappAnalyserIngestModule_cannotParseXml=Cannot Parse XML file.",
"ILeappAnalyserIngestModule.postartifacts_error=Error posting Blackboard Artifact",
"ILeappAnalyserIngestModule.error.creating.new.artifacts=Error creating new artifacts."
})
})
/**
* Read the XML config file and load the mappings into maps
@ -458,7 +465,6 @@ public class ILeappAnalyserIngestModule implements DataSourceIngestModule {
try {
String path = PlatformUtil.getUserConfigDirectory() + File.separator + XMLFILE;
File f = new File(path);
logger.log(Level.INFO, "Load successful"); //NON-NLS
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
xmlinput = db.parse(f);
@ -481,42 +487,42 @@ public class ILeappAnalyserIngestModule implements DataSourceIngestModule {
NodeList artifactNlist = xmlinput.getElementsByTagName("ArtifactName"); //NON-NLS
for (int k = 0; k < artifactNlist.getLength(); k++) {
NamedNodeMap nnm = artifactNlist.item(k).getAttributes();
String artifactName = nnm.getNamedItem("artifactname").getNodeValue();
String comment = nnm.getNamedItem("comment").getNodeValue();
String parentName = artifactNlist.item(k).getParentNode().getAttributes().getNamedItem("filename").getNodeValue();
NamedNodeMap nnm = artifactNlist.item(k).getAttributes();
String artifactName = nnm.getNamedItem("artifactname").getNodeValue();
String comment = nnm.getNamedItem("comment").getNodeValue();
String parentName = artifactNlist.item(k).getParentNode().getAttributes().getNamedItem("filename").getNodeValue();
tsvFileArtifacts.put(parentName, artifactName);
tsvFileArtifacts.put(parentName, artifactName);
if (!comment.toLowerCase().matches("null")) {
tsvFileArtifactComments.put(parentName, comment);
}
if (!comment.toLowerCase().matches("null")) {
tsvFileArtifactComments.put(parentName, comment);
}
}
NodeList attributeNlist = xmlinput.getElementsByTagName("AttributeName"); //NON-NLS
for (int k = 0; k < attributeNlist.getLength(); k++) {
List<String> attributeList = new ArrayList<>();
NamedNodeMap nnm = attributeNlist.item(k).getAttributes();
String attributeName = nnm.getNamedItem("attributename").getNodeValue();
if (!attributeName.toLowerCase().matches("null")) {
String columnName = nnm.getNamedItem("columnName").getNodeValue();
String required = nnm.getNamedItem("required").getNodeValue();
String parentName = attributeNlist.item(k).getParentNode().getParentNode().getAttributes().getNamedItem("filename").getNodeValue();
List<String> attributeList = new ArrayList<>();
NamedNodeMap nnm = attributeNlist.item(k).getAttributes();
String attributeName = nnm.getNamedItem("attributename").getNodeValue();
if (!attributeName.toLowerCase().matches("null")) {
String columnName = nnm.getNamedItem("columnName").getNodeValue();
String required = nnm.getNamedItem("required").getNodeValue();
String parentName = attributeNlist.item(k).getParentNode().getParentNode().getAttributes().getNamedItem("filename").getNodeValue();
attributeList.add(attributeName.toLowerCase());
attributeList.add(columnName.toLowerCase());
attributeList.add(required.toLowerCase());
attributeList.add(attributeName.toLowerCase());
attributeList.add(columnName.toLowerCase());
attributeList.add(required.toLowerCase());
if (tsvFileAttributes.containsKey(parentName)) {
if (tsvFileAttributes.containsKey(parentName)) {
List<List<String>> attrList = tsvFileAttributes.get(parentName);
attrList.add(attributeList);
tsvFileAttributes.replace(parentName, attrList);
} else {
} else {
List<List<String>> attrList = new ArrayList<>();
attrList.add(attributeList);
tsvFileAttributes.put(parentName, attrList);
}
}
}
}
}
}
@ -526,11 +532,12 @@ public class ILeappAnalyserIngestModule implements DataSourceIngestModule {
*
* @param type is a blackboard.artifact_type enum to determine which
* type the artifact should be
* @param content is the Content object that needs to have the
* artifact added for it
* @param content is the Content object that needs to have the artifact
* added for it
* @param bbattributes is the collection of blackboard attributes that need
* to be added to the artifact after the artifact has
* been created
*
* @return The newly-created artifact, or null on error
*/
protected BlackboardArtifact createArtifactWithAttributes(int type, AbstractFile abstractFile, Collection<BlackboardAttribute> bbattributes) {
@ -547,14 +554,15 @@ public class ILeappAnalyserIngestModule implements DataSourceIngestModule {
/**
* Method to post a list of BlackboardArtifacts to the blackboard.
*
* @param artifacts A list of artifacts. IF list is empty or null, the function will return.
* @param artifacts A list of artifacts. IF list is empty or null, the
* function will return.
*/
void postArtifacts(Collection<BlackboardArtifact> artifacts) {
if(artifacts == null || artifacts.isEmpty()) {
if (artifacts == null || artifacts.isEmpty()) {
return;
}
try{
try {
Case.getCurrentCase().getSleuthkitCase().getBlackboard().postArtifacts(artifacts, MODULE_NAME);
} catch (Blackboard.BlackboardException ex) {
logger.log(Level.SEVERE, Bundle.ILeappAnalyserIngestModule_postartifacts_error(), ex); //NON-NLS
@ -577,5 +585,4 @@ public class ILeappAnalyserIngestModule implements DataSourceIngestModule {
}
}

View File

@ -27,8 +27,8 @@ import org.sleuthkit.autopsy.ingest.IngestModuleFactoryAdapter;
import org.sleuthkit.autopsy.ingest.IngestModuleIngestJobSettings;
/**
* A factory that creates data source ingest modules that will run iLeapp against
* logical files and saves the output to module output.
* A factory that creates data source ingest modules that will run iLeapp
* against logical files and saves the output to module output.
*/
@ServiceProvider(service = IngestModuleFactory.class)
public class ILeappAnalyserModuleFactory extends IngestModuleFactoryAdapter {