Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "Ghidrathon"]
path = Ghidrathon
url = https://github.com/mandiant/Ghidrathon.git
[submodule "data/lumina_structs"]
path = data/lumina_structs
url = https://github.com/ubcctf/lumina_structs
1 change: 1 addition & 0 deletions data/lumina_structs
Submodule lumina_structs added at dc84a0
11 changes: 5 additions & 6 deletions src/main/java/org/maplebacon/lumina/LuminaPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,14 @@ public LuminaPlugin(PluginTool tool) throws IOException {
protected void init() {
//start the lumina client; DONE move to a separate thread in case other plugins want to make a jep interpreter on the GUI thread too? (also for running background tasks)
try {
python = new PythonExecutor();
ResourceFile entry = Arrays.asList(pyScripts.listFiles()).stream().filter(f -> f.getName().equals("entry.py")).map(f -> new ResourceFile(f)).findFirst().get();

//set any errors to print to the console; it is expected that all communciations should be done through Msg logger but for debugging purposes this would be much more visible
ConsoleService console = tool.getService(ConsoleService.class);
python.setStreams(console.getStdOut(), console.getStdErr());

python = new PythonExecutor(console.getStdOut(), console.getStdErr());

ResourceFile entry = Arrays.asList(pyScripts.listFiles()).stream().filter(f -> f.getName().equals("entry.py")).map(f -> new ResourceFile(f)).findFirst().get();

python.set("plugin", this); //pass everything we need to do the plugin in python; getTool will give us the rest we need

//hotfix for relative imports
python.eval("import sys; sys.path.append(r'" + pyScripts.getParentFile().getParent() + "'); __package__ = 'data'");

Expand Down
19 changes: 8 additions & 11 deletions src/main/java/org/maplebacon/lumina/PythonExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import generic.jar.ResourceFile;
import ghidrathon.interpreter.GhidrathonInterpreter;
import ghidrathon.GhidrathonConfig;
import ghidrathon.GhidrathonUtils;

/**
* The class responsible for executing python code,
Expand All @@ -27,16 +29,20 @@ public class PythonExecutor {
/**
* Instantiates the environment for the python interpreter.
*/
public PythonExecutor() {
public PythonExecutor(PrintWriter out, PrintWriter err) {
BasicThreadFactory factory = new BasicThreadFactory.Builder()
.namingPattern("Lumina-JEP-thread-%d")
.priority(7) //higher than norm, lower than critical
.build();

pyThread = Executors.newSingleThreadExecutor(factory);

final GhidrathonConfig config = GhidrathonUtils.getDefaultGhidrathonConfig();
config.addStdOut(out);
config.addStdErr(err);

try { //wait until it finishes
pyThread.submit(() -> python = GhidrathonInterpreter.get()).get();
pyThread.submit(() -> python = GhidrathonInterpreter.get(config)).get();
} catch (InterruptedException | ExecutionException e) {
python = null; //disable on error
}
Expand Down Expand Up @@ -95,15 +101,6 @@ public void runScript(ResourceFile line) {
public void set(String name, Object obj) { //we dont really need a sync method for this since we dont really care about when it finishes and the ordering is already guaranteed
pyThread.execute(() -> python.set(name, obj));
}

/**
* Redirects the python interpreter output to the streams provided
* @param out stream to redirect stdout to
* @param err stream to redirect stderr to
*/
public void setStreams(PrintWriter out, PrintWriter err) { //we dont really need a sync method for this since we dont really care about when it finishes and the ordering is already guaranteed
pyThread.execute(() -> python.setStreams(out, err));
}


/**
Expand Down
File renamed without changes.
File renamed without changes.