Skip to content

Instantly share code, notes, and snippets.

@TheMatt2
Last active July 21, 2021 15:45
Show Gist options
  • Save TheMatt2/de1c0520e14fcadd4b27cd8073d55b1a to your computer and use it in GitHub Desktop.
Save TheMatt2/de1c0520e14fcadd4b27cd8073d55b1a to your computer and use it in GitHub Desktop.
Demonstration of scripts that will hang Ghidra. Part of Bug Report Submission
import ghidra.app.script.GhidraScript;
public class PrintHangTest extends GhidraScript {
long STALL_TIME = 60 * 1000; // milliseconds
@Override
public void run() throws Exception {
if (currentProgram == null) {
return;
}
long start = System.currentTimeMillis();
long stop = start;
// Set monitor to show canceling does not work
monitor.setIndeterminate(true);
// Wait for monitor to show
Thread.sleep(5000);
long count = 0;
while (stop - start < STALL_TIME) {
println("Hello " + count); // Causes a hang
//print("Hello " + count + "\n"); // Causes a hang
//print("Hello " + count); // Causes a hang
//printf("Hello %d", count); // Causes a hang that is slightly recoverable
// Even adding a millisecond delay prevents the hanging
//Thread.sleep(1);
count++;
stop = System.currentTimeMillis();
monitor.checkCanceled();
}
float seconds = stop - start;
float persec = seconds / count;
seconds = seconds / 1000;
printf("Printed Hello %d times in %.4f seconds\n", count, seconds);
printf("That is a print every %e milliseconds\n", persec);
}
}
"""
Script that demos hanging Ghidra by printing quickly to the screen.
Calling println() causes Ghidra to hang, and not respond until a bit after
the script exists
"""
import time
STALL_TIME = 60 # seconds
def main():
if not currentProgram:
return
start = stop = time.time()
monitor.setIndeterminate(True) # Set monitor to show canceling does not work
time.sleep(5) # Wait for monitor to show
count = 0
while stop - start < STALL_TIME:
println("Hello %d" % count) # Causes hang
#print("Hello %d" % count) # Causes soft crash
#printf("Hello %d\n", count)
# Even adding a millisecond delay prevents the hanging
#time.sleep(0.001)
count += 1
stop = time.time()
monitor.checkCanceled()
seconds = stop - start
persec = seconds * 1.0 / count
printf("Printed Hello %d times in %.4f seconds\n", count, seconds)
printf("That is a print every %e milliseconds\n", persec)
if __name__ == '__main__':
main()
"""
Script that demos hanging Ghidra by printing quickly to the screen.
By calling printf(), it seems it is possible to get Ghidra to cancel the script.
Though Ghidra is still slow to respond.
"""
import time
STALL_TIME = 60 # seconds
import sys
def main():
if not currentProgram:
return
start = stop = time.time()
monitor.setIndeterminate(True) # Set monitor to show canceling does not work
time.sleep(5) # Wait for monitor to show
count = 0
while stop - start < STALL_TIME:
#println("Hello %d" % count) # Causes hang
#print("Hello %d" % count) # Causes soft crash
printf("Hello %d\n", count)
# Even adding a millisecond delay prevents the hanging
#time.sleep(0.001)
count += 1
stop = time.time()
monitor.checkCanceled()
seconds = stop - start
persec = seconds * 1.0 / count
printf("Printed Hello %d times in %.4f seconds\n", count, seconds)
printf("That is a print every %e milliseconds\n", persec)
if __name__ == '__main__':
main()
"""
Script that demos hanging Ghidra by printing quickly to the screen.
Calling print() causes Ghidra to remaing in a hanging state seemingly indefinetly.
"""
import time
STALL_TIME = 60 # seconds
def main():
if not currentProgram:
return
start = stop = time.time()
monitor.setIndeterminate(True) # Set monitor to show canceling does not work
time.sleep(5) # Wait for monitor to show
count = 0
while stop - start < STALL_TIME:
#println("Hello %d" % count) # Causes hang
print("Hello %d" % count) # Causes soft crash
#printf("Hello %d\n", count)
# Even adding a millisecond delay prevents the hanging
#time.sleep(0.001)
count += 1
stop = time.time()
monitor.checkCanceled()
seconds = stop - start
persec = seconds * 1.0 / count
printf("Printed Hello %d times in %.4f seconds\n", count, seconds)
printf("That is a print every %e milliseconds\n", persec)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment