HyperDbg Debugger
Loading...
Searching...
No Matches
tests.h File Reference

headers for test functions More...

Go to the source code of this file.

Macros

#define TEST_PROCESS_NAME   "hyperdbg-test.exe"
 exe name of test process
 

Functions

BOOLEAN CreateProcessAndOpenPipeConnection (PHANDLE ConnectionPipeHandle, PHANDLE ThreadHandle, PHANDLE ProcessHandle)
 Create a Process And Open Pipe Connection object.
 
VOID CloseProcessAndClosePipeConnection (HANDLE ConnectionPipeHandle, HANDLE ThreadHandle, HANDLE ProcessHandle)
 Close the pipe connection and the remote process.
 

Detailed Description

headers for test functions

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

Macro Definition Documentation

◆ TEST_PROCESS_NAME

#define TEST_PROCESS_NAME   "hyperdbg-test.exe"

exe name of test process

Function Documentation

◆ CloseProcessAndClosePipeConnection()

VOID CloseProcessAndClosePipeConnection ( HANDLE ConnectionPipeHandle,
HANDLE ThreadHandle,
HANDLE ProcessHandle )

Close the pipe connection and the remote process.

Parameters
ConnectionPipeHandleHandle of remote pipe connection
ThreadHandleHandle of test thread
ProcessHandleHandle of test process
Returns
VOID
314{
315 //
316 // Close the connection and handles
317 //
318 NamedPipeServerCloseHandle(ConnectionPipeHandle);
319 CloseHandle(ThreadHandle);
320 CloseHandle(ProcessHandle);
321}
VOID NamedPipeServerCloseHandle(HANDLE PipeHandle)
Close handle of server's named pipe.
Definition namedpipe.cpp:156

◆ CreateProcessAndOpenPipeConnection()

BOOLEAN CreateProcessAndOpenPipeConnection ( PHANDLE ConnectionPipeHandle,
PHANDLE ThreadHandle,
PHANDLE ProcessHandle )

Create a Process And Open Pipe Connection object.

Parameters
ConnectionPipeHandlePointer to receive Pipe Handle
ThreadHandlePointer to receive Thread Handle
ProcessHandlePointer to receive Process Handle
Returns
BOOLEAN
114{
115 HANDLE PipeHandle;
116 BOOLEAN SentMessageResult;
117 UINT32 ReadBytes;
118 char * BufferToRead;
119 char * BufferToSend;
120 char HandshakeBuffer[] = "Hello, Dear Test Process... Yes, I'm HyperDbg Debugger :)";
121 PROCESS_INFORMATION ProcessInfo;
122 STARTUPINFO StartupInfo;
123 char CmdArgs[] = TEST_PROCESS_NAME " im-hyperdbg";
124
125 PipeHandle = NamedPipeServerCreatePipe("\\\\.\\Pipe\\HyperDbgTests",
128 if (!PipeHandle)
129 {
130 //
131 // Error in creating handle
132 //
133 return FALSE;
134 }
135
136 BufferToRead = (char *)malloc(TEST_CASE_MAXIMUM_BUFFERS_TO_COMMUNICATE);
137
138 if (!BufferToRead)
139 {
140 //
141 // Enable to allocate buffer
142 //
143 return FALSE;
144 }
145
146 BufferToSend = (char *)malloc(TEST_CASE_MAXIMUM_BUFFERS_TO_COMMUNICATE);
147
148 if (!BufferToSend)
149 {
150 //
151 // Enable to allocate buffer
152 //
153 free(BufferToSend);
154 return FALSE;
155 }
156
157 RtlZeroMemory(BufferToRead, TEST_CASE_MAXIMUM_BUFFERS_TO_COMMUNICATE);
158 RtlZeroMemory(BufferToSend, TEST_CASE_MAXIMUM_BUFFERS_TO_COMMUNICATE);
159
160 strcpy(BufferToSend, HandshakeBuffer);
161
162 //
163 // Create the Test Process
164 //
165
166 ZeroMemory(&StartupInfo, sizeof(StartupInfo));
167
168 //
169 // the only compulsory field
170 //
171 StartupInfo.cb = sizeof StartupInfo;
172
173 //
174 // Set-up path
175 //
177 {
178 //
179 // Test process not found
180 //
181 free(BufferToRead);
182 free(BufferToSend);
183
184 return FALSE;
185 }
186
187 if (CreateProcess(g_TestLocation, CmdArgs, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &StartupInfo, &ProcessInfo))
188 {
189 //
190 // Wait for message from the target process
191 //
193 {
194 //
195 // Error in connection
196 //
197 free(BufferToRead);
198 free(BufferToSend);
199
200 return FALSE;
201 }
202
203 ReadBytes =
205
206 if (!ReadBytes)
207 {
208 //
209 // Nothing to read
210 //
211
212 free(BufferToRead);
213 free(BufferToSend);
214
215 return FALSE;
216 }
217
218 if (strcmp(BufferToRead, "Hey there, Are you HyperDbg?") == 0)
219 {
220 //
221 // *** Connected to the remote process ***
222 //
223
224 //
225 // Send the hand shake message
226 //
227 SentMessageResult = NamedPipeServerSendMessageToClient(
228 PipeHandle,
229 BufferToSend,
230 (UINT32)strlen(BufferToSend) + 1);
231
232 if (!SentMessageResult)
233 {
234 //
235 // error in sending
236 //
237
238 free(BufferToRead);
239 free(BufferToSend);
240
241 return FALSE;
242 }
243
244 //
245 // Receive the request for the test case number
246 //
247 RtlZeroMemory(BufferToRead, TEST_CASE_MAXIMUM_BUFFERS_TO_COMMUNICATE);
248
250
251 if (!ReadBytes)
252 {
253 //
254 // Nothing to read
255 //
256
257 free(BufferToRead);
258 free(BufferToSend);
259
260 return FALSE;
261 }
262
263 if (strcmp(BufferToRead, "Wow! I miss you... Would you plz send test cases?") == 0)
264 {
265 //
266 // Set the output handles
267 //
268 *ConnectionPipeHandle = PipeHandle;
269 *ThreadHandle = ProcessInfo.hThread;
270 *ProcessHandle = ProcessInfo.hProcess;
271
272 free(BufferToRead);
273 free(BufferToSend);
274
275 return TRUE;
276 }
277
278 ShowMessages("err, could not handshake with the test process\n");
279
280 free(BufferToRead);
281 free(BufferToSend);
282
283 return FALSE;
284 }
285 else
286 {
287 ShowMessages("err, the process could not be started\n");
288
289 free(BufferToRead);
290 free(BufferToSend);
291
292 return FALSE;
293 }
294 }
295
296 free(BufferToRead);
297 free(BufferToSend);
298
299 return FALSE;
300}
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
#define TEST_CASE_MAXIMUM_BUFFERS_TO_COMMUNICATE
Maximum buffer to communicate between debugger and debuggee process.
Definition Definition.h:60
UINT32 NamedPipeServerReadClientMessage(HANDLE PipeHandle, char *BufferToSave, int MaximumReadBufferLength)
read client message from the named pipe
Definition namedpipe.cpp:88
BOOLEAN NamedPipeServerSendMessageToClient(HANDLE PipeHandle, char *BufferToSend, int BufferSize)
Definition namedpipe.cpp:123
BOOLEAN NamedPipeServerWaitForClientConntection(HANDLE PipeHandle)
wait for client connection
Definition namedpipe.cpp:58
HANDLE NamedPipeServerCreatePipe(LPCSTR PipeName, UINT32 OutputBufferSize, UINT32 InputBufferSize)
Create a named pipe server.
Definition namedpipe.cpp:27
VOID ShowMessages(const char *Fmt,...)
Show messages.
Definition libhyperdbg.cpp:96
TCHAR g_TestLocation[MAX_PATH]
Holds the location test-hyperdbg.exe.
Definition globals.h:441
BOOLEAN SetupTestName(_Inout_updates_bytes_all_(BufferLength) PCHAR TestLocation, ULONG BufferLength)
Definition tests.cpp:26
#define TEST_PROCESS_NAME
exe name of test process
Definition tests.h:22