Skip to content

Commit

Permalink
'#43 some plugins declares a lambda function directly on artifact parse
Browse files Browse the repository at this point in the history
method declaration. If so, method name is not declared, so a direct
access to this PyCallable should be done.
  • Loading branch information
patrickdalla committed Oct 18, 2023
1 parent 5ead16f commit 17eaec9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,10 @@ private void loadArtifacts(File scriptFile) {
Collection c = e.getValue();

PyCallable p = (PyCallable) c.toArray()[2];
String methodName = (String) p.getAttr("__name__");

LeapArtifactsPlugin plugin = new LeapArtifactsPlugin();
plugin.setModuleName(moduleName);
plugin.setMethodName(methodName);
plugin.setMethod(p);
plugin.setName((String) c.toArray()[0]);

Object o = c.toArray()[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
import java.nio.file.PathMatcher;
import java.util.HashSet;

import jep.python.PyCallable;

public class LeapArtifactsPlugin {
String moduleName;
String methodName;
PyCallable method;

String name;
HashSet<String> patterns = new HashSet<String>();
HashSet<PathMatcher> compiledPatterns = new HashSet<PathMatcher>();
Expand All @@ -23,10 +27,6 @@ public String getMethodName() {
return methodName;
}

public void setMethodName(String methodName) {
this.methodName = methodName;
}

public String getName() {
return name;
}
Expand All @@ -48,4 +48,13 @@ public void addPattern(String pattern) {
compiledPatterns.add(FileSystems.getDefault().getPathMatcher("glob:" + pattern));
}

public PyCallable getMethod() {
return method;
}

public void setMethod(PyCallable method) {
this.method = method;
this.methodName = (String) method.getAttr("__name__");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,12 @@ public void executePlugin(IItem evidence, LeapArtifactsPlugin p, List<String> fi
jep.eval("import sys");
jep.eval("from java.lang import System");
jep.eval("from iped.engine.task.leappbridge import ArtifactJavaReport");
jep.eval("from " + p.getModuleName() + " import " + p.getMethodName() + " as parse");
if (p.getMethodName().contains("lambda")) {
jep.eval("from " + p.getModuleName() + " import *");
jep.set("parse", p.getMethod());
} else {
jep.eval("from " + p.getModuleName() + " import " + p.getMethodName() + " as parse");
}


// creates a dumb file seeker. some plugins refers to directory although not
Expand Down

0 comments on commit 17eaec9

Please sign in to comment.