Skip to content

Commit 3de99ea

Browse files
committed
DBG: Display TEB/stack ranges in the memory map
1 parent 923f7c5 commit 3de99ea

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

src/dbg/memory.cpp

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "debugger.h"
99
#include "patches.h"
1010
#include "threading.h"
11+
#include "thread.h"
1112
#include "module.h"
1213

1314
#define PAGE_SHIFT (12)
@@ -70,7 +71,7 @@ void MemUpdateMap()
7071
while(numBytes);
7172
}
7273

73-
//process file sections
74+
// Process file sections
7475
int pagecount = (int)pageVector.size();
7576
char curMod[MAX_MODULE_SIZE] = "";
7677
for(int i = pagecount - 1; i > -1; i--)
@@ -140,6 +141,50 @@ void MemUpdateMap()
140141
}
141142
}
142143

144+
// Get a list of threads for information about Kernel/PEB/TEB/Stack ranges
145+
THREADLIST threadList;
146+
ThreadGetList(&threadList);
147+
148+
for (auto & page : pageVector)
149+
{
150+
const duint pageBase = (duint)page.mbi.BaseAddress;
151+
const duint pageSize = (duint)page.mbi.RegionSize;
152+
153+
// Check for windows specific data
154+
if (pageBase == 0x7FFE0000)
155+
{
156+
strcpy_s(page.info, "KUSER_SHARED_DATA");
157+
continue;
158+
}
159+
160+
// Check in threads
161+
for (int i = 0; i < threadList.count; i++)
162+
{
163+
duint tebBase = threadList.list[i].BasicInfo.ThreadLocalBase;
164+
DWORD threadId = threadList.list[i].BasicInfo.ThreadId;
165+
166+
// Mark TEB
167+
if (pageBase == tebBase)
168+
{
169+
sprintf_s(page.info, "Thread %X TEB", threadId);
170+
break;
171+
}
172+
173+
// Read the TEB to get stack information
174+
TEB teb;
175+
if (!ThreadGetTeb(tebBase, &teb))
176+
continue;
177+
178+
// The stack will be a specific range only, not always the base address
179+
duint stackAddr = (duint)teb.Tib.StackLimit;
180+
181+
if (stackAddr >= pageBase && stackAddr < (pageBase + pageSize))
182+
sprintf_s(page.info, "Thread %X Stack", threadId);
183+
}
184+
}
185+
186+
BridgeFree(threadList.list);
187+
143188
// Convert the vector to a map
144189
EXCLUSIVE_ACQUIRE(LockMemoryPages);
145190
memoryPages.clear();

0 commit comments

Comments
 (0)