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

!rev command More...

#include "pch.h"

Functions

VOID CommandRevHelp ()
 help of the !rev command
 
VOID CommandRev (vector< string > SplitCommand, string Command)
 !rev command handler
 

Variables

BOOLEAN g_IsSerialConnectedToRemoteDebugger
 Shows if the debugger was connected to remote debugger (A remote host)
 
std::wstring g_StartCommandPath
 the start path used in .start command
 
std::wstring g_StartCommandPathAndArguments
 the start arguments used in .start command
 

Detailed Description

!rev command

Author
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
Version
0.2
Date
2023-03-22

Function Documentation

◆ CommandRev()

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

!rev command handler

Parameters
SplitCommand
Command
Returns
VOID
52{
53 /*
54 vector<string> PathAndArgs;
55 string Arguments = "";
56
57 //
58 // Disable user-mode debugger in this version
59 //
60#if ActivateUserModeDebugger == FALSE
61
62 if (!g_IsSerialConnectedToRemoteDebugger)
63 {
64 ShowMessages("the user-mode debugger in VMI Mode is still in the beta version and not stable. "
65 "we decided to exclude it from this release and release it in future versions. "
66 "if you want to test the user-mode debugger in VMI Mode, you should build "
67 "HyperDbg with special instructions. But starting processes is fully supported "
68 "in the Debugger Mode.\n"
69 "(it's not recommended to use it in VMI Mode yet!)\n");
70 return;
71 }
72
73#endif // !ActivateUserModeDebugger
74
75 if (SplitCommand.size() <= 2)
76 {
77 ShowMessages("incorrect use of the '.start'\n\n");
78 CommandStartHelp();
79 return;
80 }
81
82
83 if (!SplitCommand.at(1).compare("path"))
84 {
85 //
86 // *** It's a run of target PE file ***
87 //
88
89 //
90 // Trim the command
91 //
92 Trim(Command);
93
94 //
95 // Remove !rev from it
96 //
97 Command.erase(0, SplitCommand.at(0).size());
98
99 //
100 // Remove path + space
101 //
102 Command.erase(0, 4 + 1);
103
104 //
105 // Trim it again
106 //
107 Trim(Command);
108
109 //
110 // Split Path and args
111 //
112 SplitPathAndArgs(PathAndArgs, Command);
113
114 //
115 // Convert path to wstring
116 //
117 StringToWString(g_StartCommandPath, PathAndArgs.at(0));
118
119 if (PathAndArgs.size() != 1)
120 {
121 //
122 // There are arguments to this command
123 //
124
125 for (auto item : PathAndArgs)
126 {
127 //
128 // Append the arguments
129 //
130 // ShowMessages("Arg : %s\n", item.c_str());
131 Arguments += item + " ";
132 }
133
134 //
135 // Remove the latest space
136 //
137 Arguments.pop_back();
138
139 //
140 // Convert arguments to wstring
141 //
142 StringToWString(g_StartCommandPathAndArguments, Arguments);
143 }
144 }
145 else
146 {
147 ShowMessages("err, couldn't resolve error at '%s'\n\n",
148 SplitCommand.at(1).c_str());
149 CommandStartHelp();
150 return;
151 }
152
153 //
154 // Perform run of the target file
155 //
156 if (Arguments.empty())
157 {
158 UdAttachToProcess(NULL,
159 g_StartCommandPath.c_str(),
160 NULL,
161 TRUE);
162 }
163 else
164 {
165 UdAttachToProcess(NULL,
166 g_StartCommandPath.c_str(),
167 (WCHAR *)g_StartCommandPathAndArguments.c_str(),
168 TRUE);
169 }
170
172 return;
173
174 */
175
177 BOOLEAN SetPid = FALSE;
178 UINT32 TargetPid = NULL;
179 BOOLEAN IgnoreFirstCommand = TRUE;
182
183 //
184 // Interpret command specific details
185 //
186 for (auto Section : SplitCommand)
187 {
188 if (!Section.compare("!rev") && IgnoreFirstCommand)
189 {
190 IgnoreFirstCommand = FALSE;
191 continue;
192 }
193 else if (!Section.compare("pid") && !SetPid)
194 {
195 SetPid = TRUE;
196 }
197 else if (SetPid)
198 {
199 if (!ConvertStringToUInt32(Section, &TargetPid))
200 {
201 //
202 // couldn't resolve or unknown parameter
203 //
204 ShowMessages("err, couldn't resolve error at '%s'\n\n",
205 Section.c_str());
207 return;
208 }
209 SetPid = FALSE;
210 }
211 else if (!Section.compare("pattern"))
212 {
214 }
215 else if (!Section.compare("reconstruct"))
216 {
218 }
219 else
220 {
221 //
222 // Unknown parameter
223 //
224 ShowMessages("err, couldn't resolve error at '%s'\n\n",
225 Section.c_str());
227 return;
228 }
229 }
230
231 if (SetPid)
232 {
233 ShowMessages("err, please enter a valid process id in hex format, "
234 "or if you want to use it in decimal format, add '0n' "
235 "prefix to the number\n");
236 return;
237 }
238
239 RevRequest.ProcessId = TargetPid;
240
241 // ================================================================================
242
243 //
244 // Send the request to the hypervisor (kernel)
245 //
246 RevRequestService(&RevRequest);
247}
UCHAR BOOLEAN
Definition BasicTypes.h:39
#define TRUE
Definition BasicTypes.h:55
#define FALSE
Definition BasicTypes.h:54
unsigned int UINT32
Definition BasicTypes.h:48
@ REVERSING_MACHINE_RECONSTRUCT_MEMORY_TYPE_PATTERN
Definition RequestStructures.h:104
@ REVERSING_MACHINE_RECONSTRUCT_MEMORY_TYPE_UNKNOWN
Definition RequestStructures.h:102
@ REVERSING_MACHINE_RECONSTRUCT_MEMORY_TYPE_RECONSTRUCT
Definition RequestStructures.h:103
enum _REVERSING_MACHINE_RECONSTRUCT_MEMORY_TYPE REVERSING_MACHINE_RECONSTRUCT_MEMORY_TYPE
different types of reconstruct requests
@ REVERSING_MACHINE_RECONSTRUCT_MEMORY_MODE_UNKNOWN
Definition RequestStructures.h:91
enum _REVERSING_MACHINE_RECONSTRUCT_MEMORY_MODE REVERSING_MACHINE_RECONSTRUCT_MEMORY_MODE
different modes of reconstruct requests
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
VOID ShowMessages(const char *Fmt,...)
Show messages.
Definition libhyperdbg.cpp:96
NULL()
Definition test-case-generator.py:530
BOOLEAN RevRequestService(REVERSING_MACHINE_RECONSTRUCT_MEMORY_REQUEST *RevRequest)
Request service from the reversing machine.
Definition rev-ctrl.cpp:23
VOID CommandRevHelp()
help of the !rev command
Definition rev.cpp:28
requests for !rev command
Definition RequestStructures.h:115
UINT32 ProcessId
Definition RequestStructures.h:116

◆ CommandRevHelp()

VOID CommandRevHelp ( )

help of the !rev command

Returns
VOID
29{
30 ShowMessages("!rev : uses the reversing machine module in order to reconstruct the programmer/memory assumptions.\n\n");
31
32 ShowMessages("syntax : \t!rev [config] [pid ProcessId (hex)]\n");
33 ShowMessages("syntax : \t!rev [path Path (string)] [Parameters (string)]\n");
34
35 ShowMessages("\n");
36 ShowMessages("\t\te.g : !rev path c:\\reverse eng\\my_file.exe\n");
37 ShowMessages("\t\te.g : !rev pattern\n");
38 ShowMessages("\t\te.g : !rev reconstruct\n");
39 ShowMessages("\t\te.g : !rev pattern pid 1c0\n");
40 ShowMessages("\t\te.g : !rev reconstruct pid 1c0\n");
41}

Variable Documentation

◆ g_IsSerialConnectedToRemoteDebugger

BOOLEAN g_IsSerialConnectedToRemoteDebugger
extern

Shows if the debugger was connected to remote debugger (A remote host)

◆ g_StartCommandPath

std::wstring g_StartCommandPath
extern

the start path used in .start command

◆ g_StartCommandPathAndArguments

std::wstring g_StartCommandPathAndArguments
extern

the start arguments used in .start command