-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for Groovy scripts and an interactive Groovy terminal, both with version 4.0.6. Also corrects an issue with help pages not being found when pressing F1 while hovering over an interpreter window.
- Loading branch information
1 parent
5714ec3
commit 6f43810
Showing
37 changed files
with
1,173 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name=RubyDragon | ||
description=Ruby, Kotlin, JShell, and Clojure interpreters. | ||
description=Ruby, Kotlin, Groovy, Clojure, and JShell interpreters. | ||
author=goatshriek | ||
createdOn= | ||
version=@extversion@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
//Examples of basic Ghidra scripting in Groovy. | ||
//@category: Examples.Groovy | ||
|
||
import ghidra.program.model.listing.CodeUnit | ||
import ghidra.app.util.datatype.DataTypeSelectionDialog | ||
import ghidra.util.data.DataTypeParser | ||
|
||
// of course, standard variable assignments work as expected | ||
// in normal Groovy fashion, you can use getters without the 'get' prefix | ||
programName = currentProgram.name | ||
creationDate = currentProgram.creationDate | ||
languageId = currentProgram.languageID | ||
compilerSpecId = currentProgram.compilerSpec.compilerSpecID | ||
|
||
// printing out some basic program information | ||
// you'll need to use the script.print family of functions to see the output | ||
script.println('Program Info:') | ||
script.println("$programName $languageId ($compilerSpecId)") | ||
script.println() | ||
|
||
// get info about the current program's memory layout | ||
script.println('Memory Layout:') | ||
script.println(String.format('Imagebase: 0x%x', currentProgram.imageBase.offset)) | ||
currentProgram.memory.blocks.each { | ||
script.println("${it.name} [start: 0x${it.start}, end: 0x${it.end}]") | ||
} | ||
script.println() | ||
|
||
// get the current program's function names | ||
script.println('Function List:') | ||
function = script.firstFunction | ||
while (function) { | ||
script.println(function.name) | ||
function = script.getFunctionAfter(function) | ||
} | ||
script.println() | ||
|
||
// get the current location in the program | ||
script.println(String.format('Current Location: 0x%x', currentAddress.offset)) | ||
script.println() | ||
|
||
// get some user input | ||
userInput = script.askString('Hello', 'Please enter a value') | ||
script.println("You entered '$userInput'") | ||
|
||
// output a popup window with the entered value | ||
script.popup(userInput) | ||
|
||
// add a comment to the current program | ||
minAddress = currentProgram.minAddress | ||
codeUnit = currentProgram.listing.getCodeUnitAt(minAddress) | ||
codeUnit.setComment(CodeUnit.PLATE_COMMENT, 'This is an added comment from Groovy!') | ||
|
||
// only valid in interactive scripts | ||
if (!script.isRunningHeadless()) { | ||
// prompting the user for a data type | ||
script.println() | ||
script.println('prompting for a data type...') | ||
tool = script.state.tool | ||
dtm = currentProgram.dataTypeManager | ||
types = DataTypeParser.AllowedDataTypes.FIXED_LENGTH | ||
selectionDialog = new DataTypeSelectionDialog(tool, dtm, -1, types) | ||
tool.showDialog(selectionDialog) | ||
dataType = selectionDialog.getUserChosenDataType() | ||
if (dataType) { | ||
script.println("Chosen data type: $dataType") | ||
} | ||
script.println() | ||
|
||
// report progress to the user interface | ||
// do this anywhere things take a while | ||
script.monitor.initialize(10) | ||
10.times { | ||
script.monitor.checkCanceled() | ||
Thread.sleep(1000) | ||
script.monitor.incrementProgress(1) | ||
script.monitor.message = "working on step $it" | ||
} | ||
} | ||
|
||
// script output against example executable located in this repository at | ||
// src/test/resources/bin/HelloGhidra.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Save all strings of five characters or more in the current program to a file | ||
// with the given name, or `saved_strings.txt` if no filename was given as a | ||
// command line argument. This script is based on the CountAndSaveStrings script | ||
// included with Ghidra. | ||
|
||
// @category: Examples.Groovy | ||
|
||
import java.io.File | ||
|
||
// read in the filename, or default to `saved_strings.txt` if none was passed | ||
filename = args.length > 0 ? args[0] : 'saved_strings.txt' | ||
|
||
// initialize the string counter | ||
stringCount = 0 | ||
|
||
// go through the data in the program | ||
new File(filename).withPrintWriter { outFile -> | ||
currentProgram.listing.getDefinedData(true).each { | ||
typeName = it.dataType.name | ||
valueRep = it.defaultValueRepresentation | ||
if ((typeName.equals('unicode') || typeName.equals('string')) && valueRep.length() > 4) { | ||
outFile.println(valueRep) | ||
stringCount += 1 | ||
} | ||
} | ||
} | ||
|
||
|
||
// print out the final string count | ||
script.println("total number of strings: $stringCount") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.