mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 10:19:23 +02:00
GP-4157: Injected "this" object into python script state so users of
askProgram() can release the consumer
This commit is contained in:
parent
8db312e27e
commit
8d27aa3f70
2 changed files with 12 additions and 2 deletions
|
@ -31,6 +31,7 @@ from ghidra.program.model.listing import Program
|
|||
from ghidra.util import Msg
|
||||
|
||||
from java.lang import IllegalArgumentException
|
||||
from ghidra.util.exception import CancelledException
|
||||
|
||||
# The presence of the AskScript.properties file in the same location (as AskScript.java)
|
||||
# allows for the following behavior:
|
||||
|
@ -67,8 +68,12 @@ try:
|
|||
#for b in bytes:
|
||||
# print "b = " + str(b & 0xff)
|
||||
|
||||
try:
|
||||
prog = askProgram("Please choose a program to open.")
|
||||
print "Program picked: " + prog.getName()
|
||||
finally:
|
||||
if prog is not None:
|
||||
prog.release(this)
|
||||
|
||||
domFile = askDomainFile("Which domain file would you like?")
|
||||
print "Domain file: " + domFile.getName()
|
||||
|
@ -102,4 +107,6 @@ try:
|
|||
|
||||
except IllegalArgumentException as error:
|
||||
Msg.warn(self, "Error during headless processing: " + error.toString())
|
||||
except CancelledException:
|
||||
print "Cancelled"
|
||||
|
||||
|
|
|
@ -338,6 +338,9 @@ public class GhidraPythonInterpreter extends InteractiveInterpreter {
|
|||
return;
|
||||
}
|
||||
|
||||
// Inject 'this'
|
||||
setVariable("this", script);
|
||||
|
||||
// Loop though the script class hierarchy
|
||||
for (Class<?> scriptClass = script.getClass(); scriptClass != Object.class; scriptClass =
|
||||
scriptClass.getSuperclass()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue