HyperDbg Debugger
Loading...
Searching...
No Matches
pte.cpp File Reference

!pte command More...

#include "pch.h"

Functions

VOID CommandPteHelp ()
 help of the !pte command
 
VOID CommandPteShowResults (UINT64 TargetVa, PDEBUGGER_READ_PAGE_TABLE_ENTRIES_DETAILS PteRead)
 show results of !pte command
 
VOID CommandPte (vector< string > SplitCommand, string Command)
 !pte command handler
 

Variables

BOOLEAN g_IsSerialConnectedToRemoteDebuggee
 Shows if the debugger was connected to remote debuggee over (A remote guest)
 
ACTIVE_DEBUGGING_PROCESS g_ActiveProcessDebuggingState
 State of active debugging thread.
 

Detailed Description

!pte command

Author
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
Version
0.1
Date
2020-05-27

Function Documentation

◆ CommandPte()

VOID CommandPte ( vector< string > SplitCommand,
string Command )

!pte command handler

Parameters
SplitCommand
Command
Returns
VOID
92{
93 BOOL Status;
94 ULONG ReturnedLength;
95 UINT64 TargetVa;
96 UINT32 Pid = 0;
98 vector<string> SplitCommandCaseSensitive {Split(Command, ' ')};
99
100 if (SplitCommand.size() == 1 || SplitCommand.size() >= 5 ||
101 SplitCommand.size() == 3)
102 {
103 ShowMessages("incorrect use of the '!pte'\n\n");
105 return;
106 }
107
108 //
109 // By default if the user-debugger is active, we use these commands
110 // on the memory layout of the debuggee process
111 //
113 {
115 }
116
117 if (SplitCommand.size() == 2)
118 {
119 //
120 // It's just an address for current process
121 //
122 if (!SymbolConvertNameOrExprToAddress(SplitCommandCaseSensitive.at(1), &TargetVa))
123 {
124 //
125 // Couldn't resolve or unknown parameter
126 //
127 ShowMessages("err, couldn't resolve error at '%s'\n",
128 SplitCommandCaseSensitive.at(1).c_str());
129 return;
130 }
131 }
132 else
133 {
134 //
135 // It might be address + pid
136 //
137 if (!SplitCommand.at(1).compare("pid"))
138 {
139 if (!ConvertStringToUInt32(SplitCommand.at(2), &Pid))
140 {
141 ShowMessages("incorrect address, please enter a valid process id\n");
142 return;
143 }
144
145 if (!SymbolConvertNameOrExprToAddress(SplitCommandCaseSensitive.at(3), &TargetVa))
146 {
147 //
148 // Couldn't resolve or unknown parameter
149 //
150 ShowMessages("err, couldn't resolve error at '%s'\n",
151 SplitCommandCaseSensitive.at(3).c_str());
152 return;
153 }
154 }
155 else if (!SplitCommand.at(2).compare("pid"))
156 {
157 if (!SymbolConvertNameOrExprToAddress(SplitCommandCaseSensitive.at(1), &TargetVa))
158 {
159 //
160 // Couldn't resolve or unknown parameter
161 //
162 ShowMessages("err, couldn't resolve error at '%s'\n\n",
163 SplitCommandCaseSensitive.at(1).c_str());
164 return;
165 }
166
167 if (!ConvertStringToUInt32(SplitCommand.at(3), &Pid))
168 {
169 ShowMessages("incorrect address, please enter a valid process id\n");
170 return;
171 }
172 }
173 else
174 {
175 ShowMessages("incorrect use of the '!pte'\n\n");
177 return;
178 }
179 }
180
181 //
182 // Prepare the buffer
183 // We use same buffer for input and output
184 //
185 AddressDetails.VirtualAddress = TargetVa;
186 AddressDetails.ProcessId = Pid; // null in debugger mode
187
189 {
190 //
191 // Check to prevent using process id in !pte command
192 //
193 if (Pid != 0)
194 {
196 return;
197 }
198
199 //
200 // Send the request over serial kernel debugger
201 //
202
203 KdSendPtePacketToDebuggee(&AddressDetails);
204 }
205 else
206 {
208
209 if (Pid == 0)
210 {
211 Pid = GetCurrentProcessId();
212 AddressDetails.ProcessId = Pid;
213 }
214
215 //
216 // Send IOCTL
217 //
218 Status = DeviceIoControl(
219 g_DeviceHandle, // Handle to device
220 IOCTL_DEBUGGER_READ_PAGE_TABLE_ENTRIES_DETAILS, // IO Control Code (IOCTL)
221 &AddressDetails, // Input Buffer to driver.
223 &AddressDetails, // Output Buffer from driver.
225 // buffer in bytes.
226 &ReturnedLength, // Bytes placed in buffer.
227 NULL // synchronous call
228 );
229
230 if (!Status)
231 {
232 ShowMessages("ioctl failed with code 0x%x\n", GetLastError());
233 return;
234 }
235
237 {
238 ShowErrorMessage(AddressDetails.KernelStatus);
239 return;
240 }
241
242 //
243 // Show the results
244 //
245 CommandPteShowResults(TargetVa, &AddressDetails);
246 }
247}
int BOOL
Definition BasicTypes.h:23
unsigned __int64 UINT64
Definition BasicTypes.h:21
unsigned int UINT32
Definition BasicTypes.h:48
unsigned long ULONG
Definition BasicTypes.h:37
#define DEBUGGER_OPERATION_WAS_SUCCESSFUL
General value to indicate that the operation or request was successful.
Definition ErrorCodes.h:23
#define IOCTL_DEBUGGER_READ_PAGE_TABLE_ENTRIES_DETAILS
ioctl, request to read page table entries
Definition Ioctls.h:99
#define SIZEOF_DEBUGGER_READ_PAGE_TABLE_ENTRIES_DETAILS
Definition RequestStructures.h:14
const vector< string > Split(const string &s, const char &c)
general split command
Definition common.cpp:117
BOOLEAN ConvertStringToUInt32(string TextToConvert, PUINT32 Result)
check and convert string to a 32 bit unsigned it and also check for special notations like 0x etc.
Definition common.cpp:347
BOOLEAN ShowErrorMessage(UINT32 Error)
shows the error message
Definition debugger.cpp:38
BOOLEAN KdSendPtePacketToDebuggee(PDEBUGGER_READ_PAGE_TABLE_ENTRIES_DETAILS PtePacket)
Sends a PTE or '!pte' command packet to the debuggee.
Definition kd.cpp:907
#define AssertShowMessageReturnStmt(expr, message, rc)
Definition common.h:51
#define ASSERT_MESSAGE_CANNOT_SPECIFY_PID
Definition common.h:31
#define AssertReturn
Definition common.h:19
#define ASSERT_MESSAGE_DRIVER_NOT_LOADED
Definition common.h:25
HANDLE g_DeviceHandle
Holds the global handle of device which is used to send the request to the kernel by IOCTL,...
Definition globals.h:471
VOID ShowMessages(const char *Fmt,...)
Show messages.
Definition libhyperdbg.cpp:96
VOID CommandPteHelp()
help of the !pte command
Definition pte.cpp:26
VOID CommandPteShowResults(UINT64 TargetVa, PDEBUGGER_READ_PAGE_TABLE_ENTRIES_DETAILS PteRead)
show results of !pte command
Definition pte.cpp:47
BOOLEAN g_IsSerialConnectedToRemoteDebuggee
Shows if the debugger was connected to remote debuggee over (A remote guest)
Definition globals.h:231
ACTIVE_DEBUGGING_PROCESS g_ActiveProcessDebuggingState
State of active debugging thread.
Definition globals.h:362
UINT32 ProcessId
Definition ud.h:51
BOOLEAN IsActive
Definition ud.h:49
request for !pte command
Definition RequestStructures.h:22
UINT64 VirtualAddress
Definition RequestStructures.h:23
UINT32 ProcessId
Definition RequestStructures.h:24
UINT32 KernelStatus
Definition RequestStructures.h:38
BOOLEAN SymbolConvertNameOrExprToAddress(const string &TextToConvert, PUINT64 Result)
check and convert string to a 64 bit unsigned integer and also check for symbol object names and eval...
Definition symbol.cpp:360

◆ CommandPteHelp()

VOID CommandPteHelp ( )

help of the !pte command

Returns
VOID
27{
28 ShowMessages("!pte : finds virtual addresses of different paging-levels.\n\n");
29
30 ShowMessages("syntax : \t!pte [VirtualAddress (hex)] [pid ProcessId (hex)]\n");
31
32 ShowMessages("\n");
33 ShowMessages("\t\te.g : !pte nt!ExAllocatePoolWithTag\n");
34 ShowMessages("\t\te.g : !pte nt!ExAllocatePoolWithTag+5\n");
35 ShowMessages("\t\te.g : !pte fffff801deadbeef\n");
36 ShowMessages("\t\te.g : !pte 0x400021000 pid 1c0\n");
37}

◆ CommandPteShowResults()

VOID CommandPteShowResults ( UINT64 TargetVa,
PDEBUGGER_READ_PAGE_TABLE_ENTRIES_DETAILS PteRead )

show results of !pte command

Parameters
TargetVa
PteRead
Returns
VOID
48{
49 /*
50 VA fffff8003abc9370
51 PXE at FFFF83C1E0F07F80 PPE at FFFF83C1E0FF0000 PDE at
52 FFFF83C1FE000EA8 PTE at FFFF83FC001D5E48 contains 0000000004108063
53 contains 0000000004109063 contains 00000000026008E3 contains
54 0000000000000000 pfn 4108 ---DA--KWEV pfn 4109 ---DA--KWEV pfn
55 2600 --LDA--KWEV LARGE PAGE pfn 27c9
56 */
57 ShowMessages("VA %llx\n", TargetVa);
58 ShowMessages("PML4E (PXE) at %016llx\tcontains %016llx\nPDPTE (PPE) at "
59 "%016llx\tcontains "
60 "%016llx\nPDE at %016llx\tcontains %016llx\n",
61 PteRead->Pml4eVirtualAddress,
62 PteRead->Pml4eValue,
63 PteRead->PdpteVirtualAddress,
64 PteRead->PdpteValue,
65 PteRead->PdeVirtualAddress,
66 PteRead->PdeValue);
67
68 //
69 // Check if it's a large PDE
70 //
71 if (PteRead->PdeVirtualAddress == PteRead->PteVirtualAddress)
72 {
73 ShowMessages("PDE is a large page, so it doesn't have a PTE\n");
74 }
75 else
76 {
77 ShowMessages("PTE at %016llx\tcontains %016llx\n",
78 PteRead->PteVirtualAddress,
79 PteRead->PteValue);
80 }
81}
UINT64 PdeValue
Definition RequestStructures.h:33
UINT64 PdpteValue
Definition RequestStructures.h:30
UINT64 PdpteVirtualAddress
Definition RequestStructures.h:29
UINT64 PteVirtualAddress
Definition RequestStructures.h:35
UINT64 Pml4eValue
Definition RequestStructures.h:27
UINT64 Pml4eVirtualAddress
Definition RequestStructures.h:26
UINT64 PteValue
Definition RequestStructures.h:36
UINT64 PdeVirtualAddress
Definition RequestStructures.h:32

Variable Documentation

◆ g_ActiveProcessDebuggingState

ACTIVE_DEBUGGING_PROCESS g_ActiveProcessDebuggingState
extern

State of active debugging thread.

362{0};

◆ g_IsSerialConnectedToRemoteDebuggee

BOOLEAN g_IsSerialConnectedToRemoteDebuggee
extern

Shows if the debugger was connected to remote debuggee over (A remote guest)