Skip to content

Commit

Permalink
add currentFunction variable
Browse files Browse the repository at this point in the history
  • Loading branch information
goatshriek committed Jul 7, 2024
1 parent ae57f02 commit 6a3c7f3
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 8 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [4.0.0] - 2024-06-08
## [4.0.0] - 2024-07-06
### Added
- Current function interpreter variables with the function containing the
current address.

### Changed
- Upgrade to JRuby 9.4.7.0 (Ruby 3.1.4)
- Upgrade to Groovy 4.0.21
Expand Down
6 changes: 4 additions & 2 deletions src/main/help/help/topics/Clojure/interpreter.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ <H2>Environment</H2>

The same variables that are available in Ghidra's native Java and Python
environments are also available in the Clojure interpreter as global
variables, both for interactive sessions and scripts. These are all added
to the ghidra namespace:
variables, both for interactive sessions and scripts. There are also some
extra variables for commonly needed values such as the current function.
These are all added to the ghidra namespace:
</P>

<PRE>
ghidra/current-address
ghidra/current-function
ghidra/current-highlight
ghidra/current-location
ghidra/current-program
Expand Down
4 changes: 3 additions & 1 deletion src/main/help/help/topics/Groovy/interpreter.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ <H2>Environment</H2>

The same variables that are available in Ghidra's native Java and Python
environments are also available in the Groovy interpreter as global
variables, both for interactive sessions and scripts:
variables, both for interactive sessions and scripts. There are also some
extra variables for commonly needed values such as the current function.
</P>

<PRE>
currentAddress
currentFunction
currentHighlight
currentLocation
currentProgram
Expand Down
4 changes: 3 additions & 1 deletion src/main/help/help/topics/JShell/interpreter.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ <H2>Environment</H2>

The same variables that are available in Ghidra's Java and Python
environments are also available in the JShell interpreter as global
variables:
variables. There are also some extra variables for commonly needed
values such as the current function.
</P>

<PRE>
currentAddress
currentFunction
currentHighlight
currentLocation
currentProgram
Expand Down
4 changes: 3 additions & 1 deletion src/main/help/help/topics/Kotlin/interpreter.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ <H2>Environment</H2>

The same variables that are available in Ghidra's native Java and Python
environments are also available in the Kotlin interpreter as global
variables, both for interactive sessions and scripts:
variables, both for interactive sessions and scripts. There are also some
extra variables for commonly needed values such as the current function.
</P>

<PRE>
currentAddress
currentFunction
currentHighlight
currentLocation
currentProgram
Expand Down
4 changes: 3 additions & 1 deletion src/main/help/help/topics/Ruby/interpreter.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ <H2>Environment</H2>

The same variables that are available in Ghidra's Java and Python
environments are also available in the Ruby interpreter as global variables,
both for interactive sessions and scripts:
both for interactive sessions and scripts. There are also some extra
variables, for commonly needed values such as the current function.
</P>

<PRE>
$current_address
$current_function
$current_highlight
$current_location
$current_program
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/com/goatshriek/rubydragon/GhidraInterpreter.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
*/
public abstract class GhidraInterpreter implements Disposable {

private FlatProgramAPI api = null;

/**
* Imports all of the classes listed in the auto import list by calling
* importClass for each one.
Expand Down Expand Up @@ -122,6 +124,17 @@ public String getCurrentAPIName() {
return "currentAPI";
}

/**
* The default name for the current function variable.
*
* @return The default name for the current function variable.
*
* @since 4.0.0
*/
public String getCurrentFunctionName() {
return "currentFunction";
}

/**
* The default name for the current highlight variable.
*
Expand Down Expand Up @@ -293,6 +306,7 @@ public void setStreams(InterpreterConsole console) {
*/
public void updateAddress(Address address) {
setVariable(getCurrentAddressName(), address);
setVariable(getCurrentFunctionName(), api.getFunctionContaining(address));
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ public String getCurrentAPIName() {
return "current-api";
}

/**
* The name for the current function variable.
*
* @return The name for the current function variable.
*
* @since 4.0.0
*/
@Override
public String getCurrentFunctionName() {
return "current-function";
}

/**
* The name for the current highlight variable.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@ public String getCurrentAPIName() {
return "$current_api";
}

/**
* The name for the current function variable.
*
* @return The name for the current function variable.
*
* @since 4.0.0
*/
@Override
public String getCurrentFunctionName() {
return "$current_function";
}

/**
* The name for the current highlight variable.
*
Expand Down

0 comments on commit 6a3c7f3

Please sign in to comment.