Skip to content

Commit

Permalink
'#2095 Correctly treats getTempFile if it is a reference to an exported
Browse files Browse the repository at this point in the history
file in case output path.
  • Loading branch information
patrickdalla committed May 15, 2024
1 parent 5537ddb commit 00d7586
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public static void install(Jep jep) {
Ilapfuncs.class.getMethod("media_to_html", String.class, Collection.class, String.class));
pt.overrideModuleFunction("scripts.ilapfuncs", "logdevinfo",
Ilapfuncs.class.getMethod("logdevinfo", String.class));
pt.overrideModuleFunction("scripts.ilapfuncs", "tsv", Ilapfuncs.class.getMethod("tsv", String.class,
Collection.class, Collection.class, String.class));
} catch (Exception e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -66,6 +68,11 @@ public static void timeline(String reportFolder, String tlactivity, Collection d

}

public static void tsv(String reportFolder, Collection data_headers, Collection data_list, String tsvname,
String srcfile) {

}

public static String media_to_html(String mediaPath, Collection filesFound, String report_folder) {
for (Object file : filesFound) {
if (file.toString().contains(mediaPath)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import iped.properties.ExtraProperties;
import iped.search.SearchResult;
import iped.utils.DateUtil;
import iped.utils.IOUtil;
import iped.utils.pythonhook.FileHook;
import iped.utils.pythonhook.PythonHook;
import jep.Jep;
Expand Down Expand Up @@ -103,6 +104,7 @@ public LeappBridgeTask() {
private HashMap<String, Document> filesFoundDocuments;

private ALeappConfig config;
private PythonHook pt;

static private File aleappDir;

Expand All @@ -112,7 +114,17 @@ public LeappBridgeTask() {

public static Object open(Collection args, Map kargs) {
Iterator iargs = args.iterator();
return new FileHook(iargs.next().toString());
Object[] o = args.toArray();
if (o.length == 1) {
return new FileHook((String) o[0]);
}
if (o.length == 2) {
return new FileHook((String) o[0], (String) o[1]);
}
if (o.length == 3) {
return new FileHook((String) o[0], (String) o[1], (String) o[3]);
}
return null;
}

@Override
Expand Down Expand Up @@ -140,13 +152,17 @@ public void init(ConfigurationManager configurationManager) throws Exception {
Ilapfuncs.install(jep);
PythonHook pt = PythonHook.installHook(jep);
pt.wrapsClass("scripts.artifact_report", "ArtifactHtmlReport", ArtifactJavaReport.class);

pluginsManager.init(jep, getAleappScriptsDir());
} else {
throw new Exception("ALeapp plugin scripts path not found:" + artifactsPath.getCanonicalPath());
}
}

public FileHook open(String filePath, String mode) {
return new FileHook(filePath, mode);
}

@Override
public void finish() throws Exception {
int decremented = taskCount.decrementAndGet();
Expand Down Expand Up @@ -229,6 +245,12 @@ public void executePlugin(IItem evidence, LeapArtifactsPlugin p, List<String> fi
jep.set("mappedEvidences", mappedEvidences);

jep.eval("logfunc('" + PLUGIN_EXECUTION_MESSAGE + ":" + p.getModuleName() + "')");

//
// PythonHook pt = PythonHook.installHook(jep);
// pt.overrideFileOpen(LeappBridgeTask.class.getMethod("open", String.class,
// String.class));

jep.eval("parse(" + lists + ",'"
+ reportPath.getCanonicalPath().replace("\\", "\\\\") + "',dumb,True,'UTC')");
} finally {
Expand Down Expand Up @@ -531,7 +553,7 @@ private void processPlugin(LeapArtifactsPlugin p, IItem evidence, IItem dumpEvid
for (String pattern : p.patterns) {
IPEDSearcher filesSearcher = new IPEDSearcher(ipedCase);


String query = patternToLuceneQuery(dumpEvidence, pattern);
filesSearcher.setQuery(query);
SearchResult filesResult = filesSearcher.search();
Expand All @@ -554,17 +576,39 @@ private void processPlugin(LeapArtifactsPlugin p, IItem evidence, IItem dumpEvid
IItem item = ipedCase.getItemByLuceneID(artLuceneId);
File tmp = item.getTempFile();

String sourcePath = new File(
ipedCase.getCaseDir() + "/" + artdoc.get(IndexItem.SOURCE_PATH))
.getCanonicalPath();
if (!IOUtil.isTemporaryFile(tmp)) {
if (tmp.getCanonicalPath().startsWith(ipedCase.getCaseDir().getCanonicalPath())) {
// getTempFile returned the file exported in the output case path
String artParentPath = artpath.substring(0, artpath.lastIndexOf("/"));
String artname = artpath.substring(artParentPath.length());
File artfolder = new File(reportDumpPath, artParentPath);
artfolder.mkdirs();

File file_found = new File(artfolder, artname);

if (tmp.getCanonicalPath().startsWith(sourcePath)) {
reportDumpPath = new File(sourcePath);
// the file returned by getTempFile() is the file itself
String fileStr = preparePythonLiteralPath(tmp.getCanonicalPath());
filesFound.add(fileStr);
filesFoundDocuments.put(fileStr, artdoc);
if (!file_found.exists()) {
// if the file wasn't already placed by prior iterations, copy its content
if (!tmp.isDirectory()) {
Files.copy(tmp.toPath(), file_found.toPath());
} else {
// should not occur
System.out.println();
}
}
String fileStr = preparePythonLiteralPath(file_found.getCanonicalPath());
filesFound.add(fileStr);
filesFoundDocuments.put(fileStr, artdoc);
} else {
// the file returned by getTempFile() is the file itself. It must occur
// only if the source evidence is a "path" (not a container)
String sourcePath = new File(
ipedCase.getCaseDir() + "/" + artdoc.get(IndexItem.SOURCE_PATH))
.getCanonicalPath();
reportDumpPath = new File(sourcePath);
String fileStr = preparePythonLiteralPath(tmp.getCanonicalPath());
filesFound.add(fileStr);
filesFoundDocuments.put(fileStr, artdoc);
}
} else {
// the file returned by getTempFile() is a copy to the file in a temp folder
// so recreate the path structure inside the temp folder
Expand Down

0 comments on commit 00d7586

Please sign in to comment.