Skip to content

Commit

Permalink
update versions and fix jshell
Browse files Browse the repository at this point in the history
  • Loading branch information
goatshriek committed Jul 7, 2024
1 parent 6aae4a2 commit b40441e
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 43 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,25 @@ jobs:
runs-on: "ubuntu-latest"
strategy:
matrix:
ghidra: ["11.1"]
ghidra: ["11.1", "11.1.1"]
include:
- ghidra: "11.1"
ghidra-url: "https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_11.1_build/ghidra_11.1_PUBLIC_20240607.zip"
ghidra-sha256: "293f60e04fa480315d2c467f4b2b4b10b3b6b5c8a8416bf7167fe082406e3be8"
ghidra-filename: "ghidra_11.1_PUBLIC_20240607.zip"
ghidra-folder: "ghidra_11.1_PUBLIC"
- ghidra: "11.1.1"
ghidra-url: "https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_11.1.1_build/ghidra_11.1.1_PUBLIC_20240614.zip"
ghidra-sha256: "7fe8d9a6e7e5267f3cf487a0c046b21fb08d7a602facaa2e81ac2f09b5df2866"
ghidra-filename: "ghidra_11.1.1_PUBLIC_20240614.zip"
ghidra-folder: "ghidra_11.1.1_PUBLIC"

env:
GHIDRA_INSTALL_DIR: /home/runner/ghidra/${{ matrix.ghidra-folder }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Cache Ghidra
uses: actions/cache@v2
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
id: cache-ghidra
with:
path: ~/ghidra
Expand All @@ -36,7 +41,7 @@ jobs:
wget -q ${{ matrix.ghidra-url }}
echo "${{ matrix.ghidra-sha256 }} ${{ matrix.ghidra-filename }}" | sha256sum -c
unzip ${{ matrix.ghidra-filename }} -d ~/ghidra
- uses: actions/setup-java@v2
- uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: 'adopt'
java-version: '17'
Expand Down
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Current function, data, and instruction interpreter variables.

### Changed
- Upgrade to JRuby 9.4.7.0 (Ruby 3.1.4)
- Upgrade to Groovy 4.0.21
- Upgrade to JRuby 9.4.8.0 (Ruby 3.1.4)
- Upgrade to Clojure 1.11.3
- Upgrade to Groovy 4.0.22
- Upgrade to Kotlin 2.0.0

### Removed
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ plugins {
}

dependencies {
implementation('org.jruby:jruby-complete:9.4.7.0')
implementation('org.clojure:clojure:1.11.2')
implementation('org.apache.groovy:groovy:4.0.21')
implementation('org.apache.groovy:groovy-groovysh:4.0.21')
implementation('org.jruby:jruby-complete:9.4.8.0')
implementation('org.clojure:clojure:1.11.3')
implementation('org.apache.groovy:groovy:4.0.22')
implementation('org.apache.groovy:groovy-groovysh:4.0.22')
testImplementation('junit:junit:4.13.2')
runtimeOnly('org.jetbrains.kotlin:kotlin-scripting-jsr223:2.0.0')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
*/
public abstract class GhidraInterpreter implements Disposable {

private FlatProgramAPI api = null;
protected FlatProgramAPI api = null;

/**
* Imports all of the classes listed in the auto import list by calling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
import ghidra.app.plugin.core.interpreter.InterpreterConsole;
import ghidra.program.flatapi.FlatProgramAPI;
import ghidra.program.model.address.Address;
import ghidra.program.model.listing.Data;
import ghidra.program.model.listing.Function;
import ghidra.program.model.listing.Instruction;
import ghidra.program.model.listing.Program;
import ghidra.program.util.ProgramLocation;
import ghidra.program.util.ProgramSelection;
Expand Down Expand Up @@ -134,36 +137,6 @@ public JShellGhidraInterpreter(InterpreterConsole console, DragonPlugin parentPl
this(console.getStdin(), console.getStdOut(), console.getStdErr(), parentPlugin);
}

/**
* Creates a new JShell interpreter, and declares the internal variables.
*
* @since 3.1.0
*/
@Override
public void initInteractiveInterpreter() {
PrintStream outPrintStream = new PrintStream(outStream);
PrintStream errPrintStream = new PrintStream(errStream);

JShell.Builder builder = JShell.builder();
builder.out(outPrintStream);
builder.err(errPrintStream);
builder.executionEngine(new LocalExecutionControlProvider(), new HashMap<String, String>());
jshell = builder.build();

// declare the built-in variables
jshell.eval(String.format("%s currentAddress = null;", Address.class.getName()));
jshell.eval(String.format("%s currentAPI = null;", FlatProgramAPI.class.getName()));
jshell.eval(String.format("%s currentHighlight = null;", ProgramSelection.class.getName()));
jshell.eval(String.format("%s currentLocation = null;", ProgramLocation.class.getName()));
jshell.eval(String.format("%s currentProgram = null;", Program.class.getName()));
jshell.eval(String.format("%s currentSelection = null;", ProgramSelection.class.getName()));

// set any variables that were provided before creation
setVariables.forEach((name, var) -> {
setVariableInJShell(name, var.type, var.value);
});
}

/**
* Should end the interpreter and release all resources.
*/
Expand Down Expand Up @@ -267,6 +240,39 @@ public void importClass(String packageName, String className) {
}
}

/**
* Creates a new JShell interpreter, and declares the internal variables.
*
* @since 3.1.0
*/
@Override
public void initInteractiveInterpreter() {
PrintStream outPrintStream = new PrintStream(outStream);
PrintStream errPrintStream = new PrintStream(errStream);

JShell.Builder builder = JShell.builder();
builder.out(outPrintStream);
builder.err(errPrintStream);
builder.executionEngine(new LocalExecutionControlProvider(), new HashMap<String, String>());
jshell = builder.build();

// declare the built-in variables
jshell.eval(String.format("%s currentAddress = null;", Address.class.getName()));
jshell.eval(String.format("%s currentAPI = null;", FlatProgramAPI.class.getName()));
jshell.eval(String.format("%s currentData = null;", Data.class.getName()));
jshell.eval(String.format("%s currentFunction = null;", Function.class.getName()));
jshell.eval(String.format("%s currentHighlight = null;", ProgramSelection.class.getName()));
jshell.eval(String.format("%s currentInstruction = null;", Instruction.class.getName()));
jshell.eval(String.format("%s currentLocation = null;", ProgramLocation.class.getName()));
jshell.eval(String.format("%s currentProgram = null;", Program.class.getName()));
jshell.eval(String.format("%s currentSelection = null;", ProgramSelection.class.getName()));

// set any variables that were provided before creation
setVariables.forEach((name, var) -> {
setVariableInJShell(name, var.type, var.value);
});
}

/**
* Interrupts this interpreter.
*/
Expand Down Expand Up @@ -324,9 +330,14 @@ public void setVariable(String name, Object value) {
*
* @param name The name of the variable.
* @param type The type of the variable.
* @param value The new value of the variable.
* @param value The new value of the variable. If this is null, then this call
* does nothing.
*/
private void setVariable(String name, Class<?> type, Object value) {
if (value == null) {
return;
}

setVariables.put(name, new Variable(type, value));

if (jshell != null) {
Expand Down Expand Up @@ -369,6 +380,12 @@ public void startInteractiveSession() {
public void updateAddress(Address address) {
if (address != null) {
setVariable(getCurrentAddressName(), Address.class, address);

if (api != null) {
setVariable(getCurrentDataName(), Data.class, api.getDataContaining(address));
setVariable(getCurrentFunctionName(), Function.class, api.getFunctionContaining(address));
setVariable(getCurrentInstructionName(), Instruction.class, api.getInstructionContaining(address));
}
}
}

Expand Down Expand Up @@ -408,7 +425,8 @@ public void updateLocation(ProgramLocation loc) {
public void updateProgram(Program program) {
if (program != null) {
setVariable(getCurrentProgramName(), Program.class, program);
setVariable(getCurrentAPIName(), FlatProgramAPI.class, new FlatProgramAPI(program));
api = new FlatProgramAPI(program);
setVariable(getCurrentAPIName(), FlatProgramAPI.class, api);
}
}

Expand Down

0 comments on commit b40441e

Please sign in to comment.