Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-5163: Read stack at $sp-1 for 2, for negative stack growth.

Dan83a9feedbe67
diff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/hooks.py b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/hooks.py
index 53cc655a25..f0103ea692 100644
--- a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/hooks.py
+++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/hooks.py
@@ -77,8 +77,8 @@ class ProcessState(object):
commands.putreg()
commands.putmem('0x{:x}'.format(util.get_pc()),
"1", display_result=False)
- commands.putmem('0x{:x}'.format(util.get_sp()),
- "1", display_result=False)
+ commands.putmem('0x{:x}'.format(util.get_sp()-1),
+ "2", display_result=False)
commands.put_frames()
self.visited.add(thread)
frame = util.selected_frame()
diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/hooks.py b/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/hooks.py
index 9910c3e5ca..4e0396c69a 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/hooks.py
+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/hooks.py
@@ -101,7 +101,7 @@ class InferiorState(object):
except gdb.MemoryError as e:
print(f"Couldn't record page with PC: {e}")
try:
- commands.putmem("$sp", "1", from_tty=False)
+ commands.putmem("$sp-1", "2", from_tty=False)
except gdb.MemoryError as e:
print(f"Couldn't record page with SP: {e}")
self.visited.add(hashable_frame)
diff --git a/Ghidra/Debug/Debugger-agent-lldb/src/main/py/src/ghidralldb/hooks.py b/Ghidra/Debug/Debugger-agent-lldb/src/main/py/src/ghidralldb/hooks.py
index 47a9495855..13a507643c 100644
--- a/Ghidra/Debug/Debugger-agent-lldb/src/main/py/src/ghidralldb/hooks.py
+++ b/Ghidra/Debug/Debugger-agent-lldb/src/main/py/src/ghidralldb/hooks.py
@@ -1,17 +1,17 @@
## ###
-# IP: GHIDRA
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
+# IP: GHIDRA
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
##
import threading
import time
@@ -80,7 +80,7 @@ class ProcessState(object):
except BaseException as e:
print(f"Couldn't record page with PC: {e}")
try:
- commands.putmem("$sp", "1", result=None)
+ commands.putmem("$sp-1", "2", result=None)
except BaseException as e:
print(f"Couldn't record page with SP: {e}")
self.visited.add(hashable_frame)