Skip to content

Commit

Permalink
move jshell and groovy to terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
goatshriek committed Jul 12, 2024
1 parent a2ef6fd commit bde79a0
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@
package com.goatshriek.rubydragon.groovy;

import java.awt.event.KeyEvent;
import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.nio.charset.StandardCharsets;

import com.goatshriek.rubydragon.DragonPlugin;
import com.goatshriek.rubydragon.GhidraInterpreter;
import com.goatshriek.rubydragon.jshell.JShellGhidraInterpreter;

import docking.ActionContext;
import docking.DockingUtils;
Expand All @@ -32,6 +37,8 @@
import ghidra.app.plugin.core.interpreter.InterpreterConnection;
import ghidra.app.plugin.core.interpreter.InterpreterConsole;
import ghidra.app.plugin.core.interpreter.InterpreterPanelService;
import ghidra.app.services.Terminal;
import ghidra.app.services.TerminalService;
import ghidra.framework.plugintool.PluginInfo;
import ghidra.framework.plugintool.PluginTool;
import ghidra.framework.plugintool.util.PluginStatus;
Expand All @@ -56,6 +63,17 @@ public class GroovyDragonPlugin extends DragonPlugin implements InterpreterConne

private InterpreterConsole console;
private GroovyGhidraInterpreter interpreter;

private Terminal terminal;

private PipedInputStream errIn;
private PipedOutputStream errOut;

private PipedInputStream stdOutIn;
private PipedOutputStream stdOutOut;

private PipedInputStream stdInIn;
private PipedOutputStream stdInOut;

/**
* Plugin constructor.
Expand All @@ -64,6 +82,21 @@ public class GroovyDragonPlugin extends DragonPlugin implements InterpreterConne
*/
public GroovyDragonPlugin(PluginTool tool) {
super(tool, "Groovy");

terminal = null;

errIn = new PipedInputStream();
stdOutIn = new PipedInputStream();
stdInIn = new PipedInputStream();

try {
errOut = new PipedOutputStream(errIn);
stdOutOut = new PipedOutputStream(stdOutIn);
stdInOut = new PipedOutputStream(stdInIn);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

/**
Expand All @@ -72,7 +105,7 @@ public GroovyDragonPlugin(PluginTool tool) {
@Override
protected void dispose() {
interpreter.dispose();
console.dispose();
// console.dispose();
super.dispose();
}

Expand All @@ -94,12 +127,16 @@ public GhidraInterpreter getInterpreter() {
public void init() {
super.init();

console = getTool().getService(InterpreterPanelService.class).createInterpreterPanel(this, false);
interpreter = new GroovyGhidraInterpreter(console, this);
console.setPrompt("> ");
console.addFirstActivationCallback(() -> {
interpreter.startInteractiveSession();
});
// console = getTool().getService(InterpreterPanelService.class).createInterpreterPanel(this, false);
// interpreter = new GroovyGhidraInterpreter(console, this);
// console.setPrompt("> ");
// console.addFirstActivationCallback(() -> {
// interpreter.startInteractiveSession();
// });
TerminalService terminalService = getTool().getService(TerminalService.class);
terminal = terminalService.createWithStreams(StandardCharsets.UTF_8, stdOutIn,stdInOut);
interpreter = new GroovyGhidraInterpreter(stdInIn, stdOutOut, stdOutOut, this);
interpreter.startInteractiveSession();

DockingAction resetAction = new DockingAction("Reset Interpreter", getName()) {
@Override
Expand All @@ -109,22 +146,23 @@ public void actionPerformed(ActionContext context) {
interpreter.updateLocation(getProgramLocation());
interpreter.updateProgram(getCurrentProgram());
interpreter.updateSelection(getProgramSelection());
console.clear();
// console.clear();
}
};
resetAction.setDescription("Reset Interpreter");
resetAction.setToolBarData(new ToolBarData(ResourceManager.loadImage("images/reload3.png"), null));
resetAction.setEnabled(true);
resetAction.setKeyBindingData(new KeyBindingData(KeyEvent.VK_D, DockingUtils.CONTROL_KEY_MODIFIER_MASK));
resetAction.setHelpLocation(new HelpLocation(getTitle(), "Reset_Interpreter"));
console.addAction(resetAction);
// console.addAction(resetAction);
}

/**
* Shows the interpreter console.
*/
@Override
public void showConsole() {
console.show();
// console.show();
terminal.toFront();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public void doCall(Groovysh shell) {
outWriter.append(String.format("auto-imported finished (%.3f seconds)\n", importTime));
outWriter.flush();
} else {
outWriter.append("auto-import disabled.\n");
outWriter.append("auto-import disabled.\r\n");
outWriter.flush();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
package com.goatshriek.rubydragon.jshell;

import java.awt.event.KeyEvent;
import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.nio.charset.StandardCharsets;

import com.goatshriek.rubydragon.DragonPlugin;
import com.goatshriek.rubydragon.GhidraInterpreter;
Expand All @@ -32,6 +36,8 @@
import ghidra.app.plugin.core.interpreter.InterpreterConnection;
import ghidra.app.plugin.core.interpreter.InterpreterConsole;
import ghidra.app.plugin.core.interpreter.InterpreterPanelService;
import ghidra.app.services.Terminal;
import ghidra.app.services.TerminalService;
import ghidra.framework.plugintool.PluginInfo;
import ghidra.framework.plugintool.PluginTool;
import ghidra.framework.plugintool.util.PluginStatus;
Expand All @@ -57,6 +63,17 @@ public class JShellDragonPlugin extends DragonPlugin implements InterpreterConne

private InterpreterConsole console;
private JShellGhidraInterpreter interpreter;

private Terminal terminal;

private PipedInputStream errIn;
private PipedOutputStream errOut;

private PipedInputStream stdOutIn;
private PipedOutputStream stdOutOut;

private PipedInputStream stdInIn;
private PipedOutputStream stdInOut;

/**
* Plugin constructor.
Expand All @@ -65,6 +82,21 @@ public class JShellDragonPlugin extends DragonPlugin implements InterpreterConne
*/
public JShellDragonPlugin(PluginTool tool) {
super(tool, "JShell");

terminal = null;

errIn = new PipedInputStream();
stdOutIn = new PipedInputStream();
stdInIn = new PipedInputStream();

try {
errOut = new PipedOutputStream(errIn);
stdOutOut = new PipedOutputStream(stdOutIn);
stdInOut = new PipedOutputStream(stdInIn);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

/**
Expand All @@ -73,7 +105,7 @@ public JShellDragonPlugin(PluginTool tool) {
@Override
protected void dispose() {
interpreter.dispose();
console.dispose();
// console.dispose();
super.dispose();
}

Expand All @@ -95,12 +127,15 @@ public GhidraInterpreter getInterpreter() {
public void init() {
super.init();

console = getTool().getService(InterpreterPanelService.class).createInterpreterPanel(this, false);
interpreter = new JShellGhidraInterpreter(console, this);
console.setPrompt("> ");
console.addFirstActivationCallback(() -> {
interpreter.startInteractiveSession();
});
// console = getTool().getService(InterpreterPanelService.class).createInterpreterPanel(this, false);
TerminalService terminalService = getTool().getService(TerminalService.class);
terminal = terminalService.createWithStreams(StandardCharsets.UTF_8, stdOutIn,stdInOut);
interpreter = new JShellGhidraInterpreter(stdInIn, stdOutOut, stdOutOut, this);
interpreter.startInteractiveSession();
// console.setPrompt("> ");
// console.addFirstActivationCallback(() -> {
// interpreter.startInteractiveSession();
// });

DockingAction interruptAction = new DockingAction("Interrupt Interpreter", getName()) {
@Override
Expand All @@ -113,7 +148,7 @@ public void actionPerformed(ActionContext context) {
interruptAction.setEnabled(true);
interruptAction.setKeyBindingData(new KeyBindingData(KeyEvent.VK_I, DockingUtils.CONTROL_KEY_MODIFIER_MASK));
interruptAction.setHelpLocation(new HelpLocation(getTitle(), "Interrupt_Interpreter"));
console.addAction(interruptAction);
// console.addAction(interruptAction);

DockingAction resetAction = new DockingAction("Reset Interpreter", getName()) {
@Override
Expand All @@ -131,14 +166,15 @@ public void actionPerformed(ActionContext context) {
resetAction.setEnabled(true);
resetAction.setKeyBindingData(new KeyBindingData(KeyEvent.VK_D, DockingUtils.CONTROL_KEY_MODIFIER_MASK));
resetAction.setHelpLocation(new HelpLocation(getTitle(), "Reset_Interpreter"));
console.addAction(resetAction);
// console.addAction(resetAction);
}

/**
* Shows the interpreter console.
*/
@Override
public void showConsole() {
console.show();
// console.show();
terminal.toFront();
}
}

0 comments on commit bde79a0

Please sign in to comment.