Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-7399: mostly ignoring this

d-millar14053c0b6491
diff --git a/Ghidra/Debug/Debugger-isf/src/main/java/ghidra/dbg/isf/IsfServer.java b/Ghidra/Debug/Debugger-isf/src/main/java/ghidra/dbg/isf/IsfServer.java
index 86b4b0f6bb..6102d84aa4 100644
--- a/Ghidra/Debug/Debugger-isf/src/main/java/ghidra/dbg/isf/IsfServer.java
+++ b/Ghidra/Debug/Debugger-isf/src/main/java/ghidra/dbg/isf/IsfServer.java
@@ -39,10 +39,14 @@ import ghidra.program.model.listing.Program;
import ghidra.util.Msg;
import ghidra.util.task.TaskMonitor;
-public class IsfServer extends Thread {
+// NB: This code is included for demonstration purposes only and is not used by the distribution.
+// Real use cases should implement authentication if the server is to be used in an unrestricted environment.
+
+public class IsfServer implements Runnable {
private ServerSocket server;
+ private Thread serverThread;
- private boolean running = false;
+ private volatile boolean running = false;
private GhidraProject project;
private int port = 54321;
private IsfClientHandler handler;
@@ -56,18 +60,39 @@ public class IsfServer extends Thread {
}
public void startServer() {
+ if (running) {
+ return;
+ }
try {
server = new ServerSocket(port, 50, InetAddress.getLoopbackAddress());
- this.start();
+ running = true;
+ serverThread = new Thread(this, "IsfServer-Listener");
+ serverThread.start();
}
catch (IOException e) {
- throw new RuntimeException("Could not start server");
+ throw new RuntimeException("Could not start server", e);
}
}
public void stopServer() {
+ if (!running) {
+ return;
+ }
running = false;
- this.interrupt();
+
+ if (server != null && !server.isClosed()) {
+ try {
+ server.close();
+ }
+ catch (IOException e) {
+ Msg.error(this, "Error closing server socket during shutdown", e);
+ }
+ }
+
+ if (serverThread != null) {
+ serverThread.interrupt();
+ }
+
for (DataTypeManager m : managers.values()) {
m.close();
}
@@ -88,7 +113,13 @@ public class IsfServer extends Thread {
connectionHandler.start();
}
catch (IOException e) {
- Msg.error(this, e);
+ if (!running) {
+ Msg.info(this, "Server socket shutdown.");
+ }
+ else {
+ Msg.error(this, "Unexpected exception - terminating server.", e);
+ stopServer();
+ }
}
}
}
diff --git a/Ghidra/Debug/Debugger-isf/src/main/java/ghidra/dbg/isf/IsfServerLauncher.java b/Ghidra/Debug/Debugger-isf/src/main/java/ghidra/dbg/isf/IsfServerLauncher.java
index 039692c259..6cfea3c382 100644
--- a/Ghidra/Debug/Debugger-isf/src/main/java/ghidra/dbg/isf/IsfServerLauncher.java
+++ b/Ghidra/Debug/Debugger-isf/src/main/java/ghidra/dbg/isf/IsfServerLauncher.java
@@ -26,6 +26,9 @@ import ghidra.util.Msg;
// To be run using runISFServer
+// NB: This code is included for demonstration purposes only and is not used by the distribution.
+// Real use cases should implement authentication if the server is to be used in an unrestricted environment.
+
public class IsfServerLauncher implements GhidraLaunchable {
private GhidraProject project = null;
diff --git a/Ghidra/Debug/Debugger-isf/support/runISFServer b/Ghidra/Debug/Debugger-isf/support/runISFServer
index 090d45d90b..7ba6b70127 100755
--- a/Ghidra/Debug/Debugger-isf/support/runISFServer
+++ b/Ghidra/Debug/Debugger-isf/support/runISFServer
@@ -4,6 +4,9 @@
# Ghidra headless ISF Server launch
#------------------------------------
+# NB: This code is included for demonstration purposes only, as is the implementation of IsfServer.
+# Real use cases should implement authentication if the server is to be used in an unrestricted environment.
+
# Maximum heap memory may be changed if default is inadequate. This will generally be up to 1/4 of
# the physical memory available to the OS. Uncomment MAXMEM setting if non-default value is needed.
MAXMEM=2G