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

show and change process More...

#include "pch.h"

Functions

VOID CommandProcessHelp ()
 help of the .process command
VOID CommandProcess (vector< CommandToken > CommandTokens, string Command)
 .process command handler

Variables

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

Detailed Description

show and change process

Author
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
Version
0.1
Date
2021-02-02

Function Documentation

◆ CommandProcess()

VOID CommandProcess ( vector< CommandToken > CommandTokens,
string Command )

.process command handler

Parameters
CommandTokens
Command
Returns
VOID
58{
59 UINT32 TargetProcessId = 0;
60 UINT64 TargetProcess = 0;
61 UINT64 AddressOfActiveProcessHead = 0; // nt!PsActiveProcessHead
62 UINT32 OffsetOfImageFileName = 0; // nt!_EPROCESS.ImageFileName
63 UINT32 OffsetOfUniqueProcessId = 0; // nt!_EPROCESS.UniqueProcessId
64 UINT32 OffsetOfActiveProcessLinks = 0; // nt!_EPROCESS.ActiveProcessLinks
65 BOOLEAN ResultOfGettingOffsets = FALSE;
66 BOOLEAN IsSetByClkIntr = FALSE;
67 DEBUGGEE_PROCESS_LIST_NEEDED_DETAILS ProcessListNeededItems = {0};
68
69 if (CommandTokens.size() >= 4)
70 {
71 ShowMessages("incorrect use of the '%s'\n\n",
72 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
74 return;
75 }
76
77 if (CommandTokens.size() == 1)
78 {
79 //
80 // Check if it's connected to a remote debuggee or not
81 //
83 {
84 //
85 // Get the process details in VMI mode
86 //
88 }
89 else
90 {
91 //
92 // Send the packet to get current process
93 //
95 NULL,
96 NULL,
97 FALSE,
98 NULL);
99 }
100 }
101 else if (CommandTokens.size() == 2)
102 {
103 if (CompareLowerCaseStrings(CommandTokens.at(1), "list"))
104 {
105 //
106 // Query for nt!_EPROCESS.ImageFileName, nt!_EPROCESS.UniqueProcessId,
107 // nt!_EPROCESS.UniqueProcessId offset from the top of nt!_EPROCESS,
108 // and nt!PsActiveProcessHead address and check if we find them or not,
109 // otherwise, it means that the PDB for ntoskrnl.exe is not available
110 //
111 if (ScriptEngineGetFieldOffsetWrapper((CHAR *)"nt!_EPROCESS", (CHAR *)"ActiveProcessLinks", &OffsetOfActiveProcessLinks) &&
112 ScriptEngineGetFieldOffsetWrapper((CHAR *)"nt!_EPROCESS", (CHAR *)"ImageFileName", &OffsetOfImageFileName) &&
113 ScriptEngineGetFieldOffsetWrapper((CHAR *)"nt!_EPROCESS", (CHAR *)"UniqueProcessId", &OffsetOfUniqueProcessId) &&
114 SymbolConvertNameOrExprToAddress("nt!PsActiveProcessHead", &AddressOfActiveProcessHead))
115 {
116 //
117 // For test offsets and addresses
118 //
119
120 /*
121 ShowMessages("Address of ActiveProcessHead : %llx\n", AddressOfActiveProcessHead);
122 ShowMessages("Offset Of ActiveProcessLinks : 0x%x\n", OffsetOfActiveProcessLinks);
123 ShowMessages("Offset Of ImageFileName : 0x%x\n", OffsetOfImageFileName);
124 ShowMessages("Offset Of UniqueProcessId : 0x%x\n", OffsetOfUniqueProcessId);
125 */
126
127 ProcessListNeededItems.PsActiveProcessHead = AddressOfActiveProcessHead;
128 ProcessListNeededItems.ActiveProcessLinksOffset = OffsetOfActiveProcessLinks;
129 ProcessListNeededItems.ImageFileNameOffset = OffsetOfImageFileName;
130 ProcessListNeededItems.UniquePidOffset = OffsetOfUniqueProcessId;
131
133 {
134 //
135 // Get list of processes in VMI mode
136 //
138 &ProcessListNeededItems,
139 NULL,
140 NULL);
141 }
142 else
143 {
144 //
145 // Send the packet to show list of process
146 //
148 NULL,
149 NULL,
150 FALSE,
151 &ProcessListNeededItems);
152 }
153 }
154 else
155 {
156 ShowMessages("err, the need offset to iterate over processes not found, "
157 "make sure to load ntoskrnl.exe's PDB file. use '.help .sym' for "
158 "more information\n");
159 return;
160 }
161 }
162 else
163 {
164 ShowMessages(
165 "err, unknown parameter at '%s'\n\n",
166 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(1)).c_str());
168 return;
169 }
170 }
171 else if (CommandTokens.size() == 3)
172 {
173 //
174 // Check if it's connected to a remote debuggee or not
175 //
177 {
178 ShowMessages("err, you're not connected to any debuggee in Debugger Mode, "
179 "you can use the '.attach', or the '.detach' commands if you're "
180 "operating in VMI Mode\n");
181 return;
182 }
183
184 if (CompareLowerCaseStrings(CommandTokens.at(1), "pid"))
185 {
186 if (!ConvertTokenToUInt32(CommandTokens.at(2), &TargetProcessId))
187 {
188 ShowMessages(
189 "please specify a correct hex value for the process id that you "
190 "want to operate on it\n\n");
192 return;
193 }
194 }
195 else if (CompareLowerCaseStrings(CommandTokens.at(1), "process"))
196 {
197 if (!SymbolConvertNameOrExprToAddress(GetCaseSensitiveStringFromCommandToken(CommandTokens.at(2)), &TargetProcess))
198 {
199 ShowMessages(
200 "please specify a correct hex value for the process (nt!_EPROCESS) that you "
201 "want to operate on it\n\n");
203 return;
204 }
205 }
206 else
207 {
208 ShowMessages(
209 "err, unknown parameter at '%s'\n\n",
210 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(2)).c_str());
212 return;
213 }
214
215 //
216 // Check for switching method
217 //
218 if (CompareLowerCaseStrings(CommandTokens.at(0), ".process2"))
219 {
220 IsSetByClkIntr = FALSE;
221 }
222 else
223 {
224 IsSetByClkIntr = TRUE;
225 }
226
227 //
228 // Send the packet to change process
229 //
231 TargetProcessId,
232 TargetProcess,
233 IsSetByClkIntr,
234 NULL);
235 }
236 else
237 {
238 ShowMessages("invalid parameter\n\n");
240 return;
241 }
242}
BOOLEAN g_IsSerialConnectedToRemoteDebuggee
Shows if the debugger was connected to remote debuggee over (A remote guest).
Definition globals.h:253
UCHAR BOOLEAN
Definition BasicTypes.h:35
#define TRUE
Definition BasicTypes.h:114
#define FALSE
Definition BasicTypes.h:113
unsigned int UINT32
Definition BasicTypes.h:54
char CHAR
Definition BasicTypes.h:33
struct _DEBUGGEE_PROCESS_LIST_NEEDED_DETAILS DEBUGGEE_PROCESS_LIST_NEEDED_DETAILS
The structure of needed information to get the details of the process from nt!_EPROCESS and location ...
@ DEBUGGEE_DETAILS_AND_SWITCH_PROCESS_GET_PROCESS_DETAILS
Definition RequestStructures.h:968
@ DEBUGGEE_DETAILS_AND_SWITCH_PROCESS_GET_PROCESS_LIST
Definition RequestStructures.h:969
@ DEBUGGEE_DETAILS_AND_SWITCH_PROCESS_PERFORM_SWITCH
Definition RequestStructures.h:970
std::string GetCaseSensitiveStringFromCommandToken(CommandToken TargetToken)
Get case sensitive string from command token.
Definition common.cpp:467
BOOLEAN CompareLowerCaseStrings(CommandToken TargetToken, const CHAR *StringToCompare)
Compare lower case strings.
Definition common.cpp:503
BOOLEAN ConvertTokenToUInt32(CommandToken TargetToken, PUINT32 Result)
check and convert command token to a 32 bit unsigned integer
Definition common.cpp:546
BOOLEAN KdSendSwitchProcessPacketToDebuggee(DEBUGGEE_DETAILS_AND_SWITCH_PROCESS_TYPE ActionType, UINT32 NewPid, UINT64 NewProcess, BOOLEAN SetChangeByClockInterrupt, PDEBUGGEE_PROCESS_LIST_NEEDED_DETAILS SymDetailsForProcessList)
Sends a change process or show process details packet to the debuggee.
Definition kd.cpp:805
BOOLEAN ObjectShowProcessesOrThreadList(BOOLEAN IsProcess, PDEBUGGEE_PROCESS_LIST_NEEDED_DETAILS SymDetailsForProcessList, UINT64 Eprocess, PDEBUGGEE_THREAD_LIST_NEEDED_DETAILS SymDetailsForThreadList)
Get details about processes or threads.
Definition objects.cpp:138
BOOLEAN ObjectShowProcessesOrThreadDetails(BOOLEAN IsProcess)
Get details about processes or threads.
Definition objects.cpp:26
VOID CommandProcessHelp()
help of the .process command
Definition process.cpp:25
BOOLEAN ScriptEngineGetFieldOffsetWrapper(CHAR *TypeName, CHAR *FieldName, UINT32 *FieldOffset)
ScriptEngineGetFieldOffset wrapper.
Definition script-engine-wrapper.cpp:132
ULONG UniquePidOffset
Definition RequestStructures.h:739
ULONG ImageFileNameOffset
Definition RequestStructures.h:738
ULONG ActiveProcessLinksOffset
Definition RequestStructures.h:740
UINT64 PsActiveProcessHead
Definition RequestStructures.h:737
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:359

◆ CommandProcessHelp()

VOID CommandProcessHelp ( )

help of the .process command

Returns
VOID
26{
27 ShowMessages(".process, .process2 : shows and changes the processes. "
28 "This command needs public symbols for ntoskrnl.exe if "
29 "you want to see the processes list. Please visit the "
30 "documentation to know about the difference between '.process' "
31 "and '.process2'.\n\n");
32
33 ShowMessages("syntax : \t.process\n");
34 ShowMessages("syntax : \t.process [list]\n");
35 ShowMessages("syntax : \t.process [pid ProcessId (hex)]\n");
36 ShowMessages("syntax : \t.process [process Eprocess (hex)]\n");
37 ShowMessages("syntax : \t.process2 [pid ProcessId (hex)]\n");
38 ShowMessages("syntax : \t.process2 [process Eprocess (hex)]\n");
39
40 ShowMessages("\n");
41 ShowMessages("\t\te.g : .process\n");
42 ShowMessages("\t\te.g : .process list\n");
43 ShowMessages("\t\te.g : .process pid 4\n");
44 ShowMessages("\t\te.g : .process2 pid 4\n");
45 ShowMessages("\t\te.g : .process process ffff948c`c2349280\n");
46}

Variable Documentation

◆ g_IsSerialConnectedToRemoteDebuggee

BOOLEAN g_IsSerialConnectedToRemoteDebuggee
extern

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