From 67a974b70c1351df5a44e02c8eb9377a89d5a8d7 Mon Sep 17 00:00:00 2001 From: Dan <46821332+nsadeveloper789@users.noreply.github.com> Date: Mon, 27 Jul 2026 19:27:10 +0000 Subject: [PATCH] GP-7091: Fix sleigh.xml and pcoderef.xml GP-7091: Fix B4-Modeling.md GP-7091: Fix B3-Scripting.md --- .../Decompiler/src/main/doc/pcoderef.xml | 2 +- .../Decompiler/src/main/doc/sleigh.xml | 2 +- .../GhidraClass/Debugger/B3-Scripting.html | 67 ++++++++----------- .../GhidraClass/Debugger/B3-Scripting.md | 24 +++---- .../GhidraClass/Debugger/B4-Modeling.html | 2 +- .../GhidraClass/Debugger/B4-Modeling.md | 2 +- .../ghidra_scripts/ZeroTimerScript.java | 21 ++---- GhidraDocs/languages/html/pseudo-ops.html | 2 +- .../languages/html/sleigh_constructors.html | 2 +- 9 files changed, 50 insertions(+), 74 deletions(-) diff --git a/Ghidra/Features/Decompiler/src/main/doc/pcoderef.xml b/Ghidra/Features/Decompiler/src/main/doc/pcoderef.xml index e609b2d803..64965a5443 100644 --- a/Ghidra/Features/Decompiler/src/main/doc/pcoderef.xml +++ b/Ghidra/Features/Decompiler/src/main/doc/pcoderef.xml @@ -3501,7 +3501,7 @@ still have normal data-flow and can be manipulated symbolically. - output = cpool(input0,intput1); + output = cpool(input0,input1); diff --git a/Ghidra/Features/Decompiler/src/main/doc/sleigh.xml b/Ghidra/Features/Decompiler/src/main/doc/sleigh.xml index 838b544f1c..8da735e1aa 100644 --- a/Ghidra/Features/Decompiler/src/main/doc/sleigh.xml +++ b/Ghidra/Features/Decompiler/src/main/doc/sleigh.xml @@ -3416,7 +3416,7 @@ scope. The macro can refer to these and any global specific symbol. macro resultflags(op) { zeroflag = (op == 0); - signflag = (op1 s< 0); + signflag = (op s< 0); } :add r1,r2 is opcode=0xba & r1 & r2 { r1 = r1 + r2; resultflags(r1); } diff --git a/GhidraDocs/GhidraClass/Debugger/B3-Scripting.html b/GhidraDocs/GhidraClass/Debugger/B3-Scripting.html index 0a29e84350..56e5268923 100644 --- a/GhidraDocs/GhidraClass/Debugger/B3-Scripting.html +++ b/GhidraDocs/GhidraClass/Debugger/B3-Scripting.html @@ -467,42 +467,35 @@ check the program counter:

class="sourceCode numberSource java numberLines">while (true) { monitor.checkCancelled(); - TargetExecutionState execState = getExecutionState(trace); + TraceExecutionState execState = getExecutionState(trace); switch (execState) { - case STOPPED: - resume(); - break; - case TERMINATED: - case INACTIVE: - throw new AssertionError("Target terminated"); - case ALIVE: - println( - "I don't know whether or not the target is running. Please make it RUNNING."); - break; - case RUNNING: - /** - * Probably timed out waiting for break. That's fine. Give the player time to - * win. - */ - break; - default: - throw new AssertionError("Unrecognized state: " + execState); - } - try { - monitor.setMessage("Waiting for player to win"); - waitForBreak(1, TimeUnit.SECONDS); - } - catch (TimeoutException e) { - // Give the player time to win. - continue; - } - flushAsyncPipelines(trace); - Address pc = getProgramCounter(); - println("STOPPED at pc = " + pc); - if (resetDyn.equals(pc)) { - break; - } -} + case STOPPED -> resume(); + case TERMINATED, INACTIVE -> throw new AssertionError("Target terminated"); + case ALIVE -> println( + "I don't know whether or not the target is running. Please make it RUNNING."); + case RUNNING -> { + /** + * Probably timed out waiting for break. That's fine. Give the player time to + * win. + */ + } + default -> throw new AssertionError("Unrecognized state: " + execState); + } + try { + monitor.setMessage("Waiting for player to win"); + waitForBreak(1, TimeUnit.SECONDS); + } + catch (TimeoutException e) { + // Give the player time to win. + continue; + } + flushAsyncPipelines(trace); + Address pc = getProgramCounter(); + println("STOPPED at pc = " + pc); + if (resetDyn.equals(pc)) { + break; + } +}

The “center” of this loop is a call to waitForBreak() on line 27. This is the simplest primitive for waiting on the target to meet any condition. Because we expect the user to take more than a @@ -511,9 +504,7 @@ keep waiting. Using a timeout of 1 second ensures we can terminate promptly should the user cancel the script.

Before waiting, we need to make sure the target is running. Because we could repeat the loop while the target is already running, we should -only call resume() if the target is stopped. There are -utility methods on TargetExecutionState like -isRunning(), which you might prefer to use. Here, we +only call resume() if the target is stopped. Here, we exhaustively handle every kind of state using a switch statement, which does make the code a bit verbose.

When the target does break, we first allow the UI to finish diff --git a/GhidraDocs/GhidraClass/Debugger/B3-Scripting.md b/GhidraDocs/GhidraClass/Debugger/B3-Scripting.md index 5edd3b3bcd..5bfa41d803 100644 --- a/GhidraDocs/GhidraClass/Debugger/B3-Scripting.md +++ b/GhidraDocs/GhidraClass/Debugger/B3-Scripting.md @@ -293,26 +293,19 @@ We do not need to be precise in this check; it suffices to check the program cou while (true) { monitor.checkCancelled(); - TargetExecutionState execState = getExecutionState(trace); + TraceExecutionState execState = getExecutionState(trace); switch (execState) { - case STOPPED: - resume(); - break; - case TERMINATED: - case INACTIVE: - throw new AssertionError("Target terminated"); - case ALIVE: - println( - "I don't know whether or not the target is running. Please make it RUNNING."); - break; - case RUNNING: + case STOPPED -> resume(); + case TERMINATED, INACTIVE -> throw new AssertionError("Target terminated"); + case ALIVE -> println( + "I don't know whether or not the target is running. Please make it RUNNING."); + case RUNNING -> { /** * Probably timed out waiting for break. That's fine. Give the player time to * win. */ - break; - default: - throw new AssertionError("Unrecognized state: " + execState); + } + default -> throw new AssertionError("Unrecognized state: " + execState); } try { monitor.setMessage("Waiting for player to win"); @@ -338,7 +331,6 @@ Using a timeout of 1 second ensures we can terminate promptly should the user ca Before waiting, we need to make sure the target is running. Because we could repeat the loop while the target is already running, we should only call `resume()` if the target is stopped. -There are utility methods on `TargetExecutionState` like `isRunning()`, which you might prefer to use. Here, we exhaustively handle every kind of state using a switch statement, which does make the code a bit verbose. When the target does break, we first allow the UI to finish interrogating the target. diff --git a/GhidraDocs/GhidraClass/Debugger/B4-Modeling.html b/GhidraDocs/GhidraClass/Debugger/B4-Modeling.html index 240cb37007..d2cd7ae433 100644 --- a/GhidraDocs/GhidraClass/Debugger/B4-Modeling.html +++ b/GhidraDocs/GhidraClass/Debugger/B4-Modeling.html @@ -585,7 +585,7 @@ class="sourceCode numberSource java numberLines">< to complete the model. There is some odd nuance in the naming of p-code operations, so do read the documentation carefully. If you are not entirely certain what an operation does, take a look at OpBehaviorFactory. +href="../../../Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/opbehavior/OpBehaviorFactory.java">OpBehaviorFactory. You can also examine the concrete implementation on byte arrays BytesPcodeArithmetic.

diff --git a/GhidraDocs/GhidraClass/Debugger/B4-Modeling.md b/GhidraDocs/GhidraClass/Debugger/B4-Modeling.md index e842d565fa..5da7b2eddd 100644 --- a/GhidraDocs/GhidraClass/Debugger/B4-Modeling.md +++ b/GhidraDocs/GhidraClass/Debugger/B4-Modeling.md @@ -387,7 +387,7 @@ public class ModelingScript extends GhidraScript { It should be fairly apparent how you could add more expression types to complete the model. There is some odd nuance in the naming of p-code operations, so do read the documentation carefully. -If you are not entirely certain what an operation does, take a look at [OpBehaviorFactory](../../../Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcode/opbehavior/OpBehaviorFactory.java). +If you are not entirely certain what an operation does, take a look at [OpBehaviorFactory](../../../Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/opbehavior/OpBehaviorFactory.java). You can also examine the concrete implementation on byte arrays [BytesPcodeArithmetic](../../../Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/exec/BytesPcodeArithmetic.java). ### Mapping the Model diff --git a/GhidraDocs/GhidraClass/Debugger/ghidra_scripts/ZeroTimerScript.java b/GhidraDocs/GhidraClass/Debugger/ghidra_scripts/ZeroTimerScript.java index f2ce28f99b..13af363ee8 100644 --- a/GhidraDocs/GhidraClass/Debugger/ghidra_scripts/ZeroTimerScript.java +++ b/GhidraDocs/GhidraClass/Debugger/ghidra_scripts/ZeroTimerScript.java @@ -91,24 +91,17 @@ public class ZeroTimerScript extends GhidraScript implements FlatDebuggerAPI { TraceExecutionState execState = getExecutionState(trace); switch (execState) { - case STOPPED: - resume(); - break; - case TERMINATED: - case INACTIVE: - throw new AssertionError("Target terminated"); - case ALIVE: - println( - "I don't know whether or not the target is running. Please make it RUNNING."); - break; - case RUNNING: + case STOPPED -> resume(); + case TERMINATED, INACTIVE -> throw new AssertionError("Target terminated"); + case ALIVE -> println( + "I don't know whether or not the target is running. Please make it RUNNING."); + case RUNNING -> { /** * Probably timed out waiting for break. That's fine. Give the player time to * win. */ - break; - default: - throw new AssertionError("Unrecognized state: " + execState); + } + default -> throw new AssertionError("Unrecognized state: " + execState); } try { monitor.setMessage("Waiting for player to win"); diff --git a/GhidraDocs/languages/html/pseudo-ops.html b/GhidraDocs/languages/html/pseudo-ops.html index f4e25e24c3..e2131ee77e 100644 --- a/GhidraDocs/languages/html/pseudo-ops.html +++ b/GhidraDocs/languages/html/pseudo-ops.html @@ -149,7 +149,7 @@ still have normal data-flow and can be manipulated symbolically. - output = cpool(input0,intput1); + output = cpool(input0,input1); diff --git a/GhidraDocs/languages/html/sleigh_constructors.html b/GhidraDocs/languages/html/sleigh_constructors.html index 9ddb572f74..2591f07445 100644 --- a/GhidraDocs/languages/html/sleigh_constructors.html +++ b/GhidraDocs/languages/html/sleigh_constructors.html @@ -2138,7 +2138,7 @@ scope. The macro can refer to these and any global specific symbol.
 macro resultflags(op) {
   zeroflag = (op == 0);
-  signflag = (op1 s< 0);
+  signflag = (op s< 0);
 }
 
 :add r1,r2 is opcode=0xba & r1 & r2 { r1 = r1 + r2; resultflags(r1); }