Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-7121: post-review GP-7121: info proc mappings for winedbg GP-7121: info proc mappings for winedbg

d-millar42539cd16bf4
diff --git a/Ghidra/Debug/Debugger-agent-gdb/certification.manifest b/Ghidra/Debug/Debugger-agent-gdb/certification.manifest
index c664cf0093..f92998511c 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/certification.manifest
+++ b/Ghidra/Debug/Debugger-agent-gdb/certification.manifest
@@ -5,6 +5,7 @@ data/scripts/fallback_info_proc_mappings.gdb||GHIDRA||||END|
data/scripts/fallback_maintenance_info_sections.gdb||GHIDRA||||END|
data/scripts/getpid-linux-i386.gdb||GHIDRA||||END|
data/scripts/wine32_info_proc_mappings.gdb||GHIDRA||||END|
+data/scripts/winedbg_info_proc_mappings.gdb||GHIDRA||||END|
data/support/gdbinit_template||GHIDRA||||END|
src/main/help/help/TOC_Source.xml||GHIDRA||||END|
src/main/help/help/topics/gdb/gdb.html||GHIDRA||||END|
diff --git a/Ghidra/Debug/Debugger-agent-gdb/data/scripts/winedbg-proc-mappings.py b/Ghidra/Debug/Debugger-agent-gdb/data/scripts/winedbg-proc-mappings.py
new file mode 100644
index 0000000000..0cc0460cd0
--- /dev/null
+++ b/Ghidra/Debug/Debugger-agent-gdb/data/scripts/winedbg-proc-mappings.py
@@ -0,0 +1,65 @@
+## ###
+# 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.
+##
+# A winedbg/GDB command for fetching regions using "monitor mem",
+# formatted in the style of `info proc mappings`.
+#
+# usage: winedbg-proc-mappings
+
+import os
+
+def reformat_line(raw_line):
+ split = raw_line.split(None, 5)
+ # split[0] start
+ # split[1] len
+ # split[2] commit
+ # split[3] type
+ # split[4] mode
+ # split[5] object name
+ start_addr_s = split[0]
+ start_addr = int(start_addr_s, 16)
+ len_s = split[1]
+ length = int(len_s, 16)
+ end_addr = start_addr + length
+ if len(split) > 4:
+ rwx = split[4].lower().replace("c", "w")
+ else:
+ rwx = ""
+ if len(split) == 6:
+ objfile = split[5]
+ else:
+ objfile = split[2]
+ if len(split) > 3:
+ objfile += "_" + split[3]
+
+ return "0x{:X} 0x{:X} 0x{:X} 0x{:X} {} {}\n".format(
+ start_addr, end_addr,
+ length,
+ 0,
+ rwx,
+ objfile,
+ )
+
+class WinedbgProcMappings(gdb.Command):
+ def __init__(self):
+ super(WinedbgProcMappings, self).__init__("winedbg-proc-mappings", gdb.COMMAND_STATUS)
+
+ def invoke(self, arg, from_tty):
+
+ for raw_line in gdb.execute("monitor mem", to_string=True).split("\n")[1:]:
+ if raw_line:
+ gdb.write(reformat_line(raw_line))
+
+WinedbgProcMappings()
diff --git a/Ghidra/Debug/Debugger-agent-gdb/data/scripts/winedbg_info_proc_mappings.gdb b/Ghidra/Debug/Debugger-agent-gdb/data/scripts/winedbg_info_proc_mappings.gdb
new file mode 100644
index 0000000000..8557f154b9
--- /dev/null
+++ b/Ghidra/Debug/Debugger-agent-gdb/data/scripts/winedbg_info_proc_mappings.gdb
@@ -0,0 +1,18 @@
+# Override the "info proc mappings" command in GDB to fetch them from a winedbg target
+#
+# To use:
+# 1. Use winedbg on Linux to launch gdbserver.exe with your target binary:
+# winedbg --gdb --no-start --port 54321 target.exe
+# 2. Connect Ghidra to winedbg on Linux using gdb-remote
+# 3. From the interpreter, run:
+#
+# source winedbg-proc-mappings.py
+# source winedbg_info_proc_mappings.gdb
+#
+# Note that you may need to provide full paths to the scripts
+
+define info proc mappings
+ python
+gdb.execute("winedbg-proc-mappings")
+ end
+end