Skip to content

Commit

Permalink
#52: display selected properties in html report
Browse files Browse the repository at this point in the history
  • Loading branch information
FelipeFcosta committed Jan 27, 2023
1 parent 1a2314c commit e9b4f81
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public void actionPerformed(ActionEvent e) {
String text = source.getText();
boolean isSelected = source.isSelected();
columnsManager.allCheckBoxesState.put(text, isSelected);
columnsManager.updateCol(text, isSelected);
}
}

Expand Down
11 changes: 11 additions & 0 deletions iped-engine/src/main/java/iped/engine/data/IPEDSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,17 @@ private void askNewImagePath(long imgId, List<String> paths, File sleuthFile) th
sleuthCase.setImagePaths(imgId, newPaths);
}

public String getItemProperty(int id, String propertyName) {
String propertyValue = null;
try {
Document doc = searcher.doc(getLuceneId(id));
propertyValue = doc.get(propertyName);
} catch (IOException e) {
e.printStackTrace();
}
return propertyValue;
}

public int getSourceId() {
return sourceId;
}
Expand Down
48 changes: 35 additions & 13 deletions iped-engine/src/main/java/iped/engine/task/HTMLReportTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@

import javax.imageio.ImageIO;

import org.apache.commons.lang3.BooleanUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -95,6 +96,16 @@ public class HTMLReportTask extends AbstractTask {

private static Logger logger = LoggerFactory.getLogger(HTMLReportTask.class);

private IPEDSource ipedCase;

private static final String propNamePlaceHolder = "%PROPERTY_NAME%";
private static final String propValuePlaceHolder = "%PROPERTY_VALUE%";

private static final List<String> basicReportProps = Arrays.asList(BasicProps.NAME, BasicProps.PATH, BasicProps.TYPE, BasicProps.LENGTH,
BasicProps.CREATED, BasicProps.MODIFIED, BasicProps.ACCESSED, BasicProps.DELETED, BasicProps.CARVED,
BasicProps.HASH, IndexItem.ID_IN_SOURCE);


/**
* Collator utilizado para ordenação correta alfabética, incluindo acentuação.
*/
Expand Down Expand Up @@ -285,6 +296,7 @@ else if (infoFile.getName().endsWith(".report")) { //$NON-NLS-1$
*/
@Override
public void finish() throws Exception {
ipedCase = new IPEDSource(this.output.getParentFile(), worker.writer);

if (isEnabled() && caseData.containsReport() && info != null) {

Expand Down Expand Up @@ -322,12 +334,10 @@ public void finish() throws Exception {

long t = System.currentTimeMillis();

try (IPEDSource ipedCase = new IPEDSource(this.output.getParentFile(), worker.writer)) {
for (int labelId : ipedCase.getBookmarks().getBookmarkMap().keySet()) {
String labelName = ipedCase.getBookmarks().getBookmarkName(labelId);
String comments = ipedCase.getBookmarks().getBookmarkComment(labelId);
labelcomments.put(labelName, comments);
}
for (int labelId : ipedCase.getBookmarks().getBookmarkMap().keySet()) {
String labelName = ipedCase.getBookmarks().getBookmarkName(labelId);
String comments = ipedCase.getBookmarks().getBookmarkComment(labelId);
labelcomments.put(labelName, comments);
}

reportSubFolder.mkdirs();
Expand Down Expand Up @@ -390,6 +400,10 @@ protected void process(IItem evidence) throws Exception {
reg.created = evidence.getCreationDate();
reg.path = evidence.getPath();

reg.evidenceId = evidence.getId();
// reg.evidenceId = ipedCase.getLuceneId(evidence.getId());
// reg.evidenceId = ipedCase.getLuceneId(new ItemId(0, evidence.getId()));

Set<String> categories = evidence.getCategorySet();
categories = categories.stream().map(c -> CategoryLocalization.getInstance().getLocalizedCategory(c.trim()))
.collect(Collectors.toSet());
Expand Down Expand Up @@ -754,7 +768,7 @@ private void createBookmarkPage(DateFormat dateFormat, NumberFormat longFormat,
}
}

// Fill Basic Properties if present
// // Fill Basic Properties if present
if (selectedProperties.contains(BasicProps.NAME))
fillItemProperty(it, "Name", "<b>" + reg.name + "</b>");
if (selectedProperties.contains(BasicProps.PATH))
Expand All @@ -770,17 +784,21 @@ private void createBookmarkPage(DateFormat dateFormat, NumberFormat longFormat,
if (selectedProperties.contains(BasicProps.ACCESSED))
fillItemProperty(it, "Last Accessed Date", formatDate(reg.accessed, dateFormat));
if (selectedProperties.contains(BasicProps.DELETED))
fillItemProperty(it, "Deleted",
reg.deleted ? Messages.getString("HTMLReportTask.Yes") : Messages.getString("HTMLReportTask.No"));
fillItemProperty(it, "Deleted", String.valueOf(reg.deleted));
if (selectedProperties.contains(BasicProps.CARVED))
fillItemProperty(it, "Carved",
reg.carved ? Messages.getString("HTMLReportTask.Yes") : Messages.getString("HTMLReportTask.No"));
fillItemProperty(it, "Carved", String.valueOf(reg.carved));
if (selectedProperties.contains(BasicProps.HASH))
fillItemProperty(it, "Hash", reg.hash);
if (selectedProperties.contains(IndexItem.ID_IN_SOURCE)) {
String export = reg.export == null ? "-" : "<b><a href=\"../" + reg.export + "\">" + reg.export + "</a></b>";
fillItemProperty(it, "Exported as", export);
}
for (String property : selectedProperties) {
if (!basicReportProps.contains(property)) {
String propertyValue = ipedCase.getItemProperty(reg.evidenceId, property);
fillItemProperty(it, property, propertyValue);
}
}

items.append(it);
}
Expand Down Expand Up @@ -819,8 +837,11 @@ private void createBookmarkPage(DateFormat dateFormat, NumberFormat longFormat,
}

private void fillItemProperty(StringBuilder it, String propertyName, String propertyValue) {
String propNamePlaceHolder = "%PROPERTY_NAME%";
String propValuePlaceHolder = "%PROPERTY_VALUE%";
Boolean boolProperty = BooleanUtils.toBooleanObject(propertyValue);
if (boolProperty != null) {
propertyValue = boolProperty ? Messages.getString("HTMLReportTask.Yes")
: Messages.getString("HTMLReportTask.No");
}

replaceFirst(it, propNamePlaceHolder, propertyName);
replaceFirst(it, propValuePlaceHolder, propertyValue);
Expand Down Expand Up @@ -1126,6 +1147,7 @@ class ReportEntry {
Long length;
boolean deleted, carved, isImage, isVideo;
Date accessed, modified, created;
int evidenceId;
}

/**
Expand Down

0 comments on commit e9b4f81

Please sign in to comment.