HyperDbg Debugger
Loading...
Searching...
No Matches
hyperdbg-test.cpp File Reference

perform tests on a remote process (this is the remote process) More...

#include "pch.h"

Functions

int main (int argc, char *argv[])
 Main function of test process.
 

Detailed Description

perform tests on a remote process (this is the remote process)

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

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Main function of test process.

Parameters
argc
argv
Returns
int

TestCreateLookupTable(PipeHandle, (PVOID)Buffer, ReadBytes);

25{
26 HANDLE PipeHandle;
27 BOOLEAN SentMessageResult;
28 UINT32 ReadBytes;
29 char * Buffer;
30
31 if (argc != 2)
32 {
33 printf("you should not test functionalities directly, instead use 'test' "
34 "command from HyperDbg...\n");
35 return 1;
36 }
37
38 Buffer = (char *)malloc(TEST_CASE_MAXIMUM_BUFFERS_TO_COMMUNICATE);
39
40 if (!Buffer)
41 {
42 printf("err, could not allocate communication buffer\n");
43 _getch();
44 return 1;
45 }
46
47 RtlZeroMemory(Buffer, TEST_CASE_MAXIMUM_BUFFERS_TO_COMMUNICATE);
48 strcpy_s(Buffer, TEST_CASE_MAXIMUM_BUFFERS_TO_COMMUNICATE, "Hey there, Are you HyperDbg?");
49
50 if (!strcmp(argv[1], "im-hyperdbg"))
51 {
52 //
53 // Perform our shaking with HyperDbg
54 //
55
56 //
57 // It's not called directly, it's probably from HyperDbg
58 //
59 PipeHandle = NamedPipeClientCreatePipe("\\\\.\\Pipe\\HyperDbgTests");
60
61 if (!PipeHandle)
62 {
63 //
64 // Unable to create handle
65 //
66 free(Buffer);
67
68 printf("err, unable to create handle\n");
69 _getch();
70 return 1;
71 }
72
73 SentMessageResult =
74 NamedPipeClientSendMessage(PipeHandle, Buffer, (int)strlen(Buffer) + 1);
75
76 if (!SentMessageResult)
77 {
78 //
79 // Sending error
80 //
81 free(Buffer);
82
83 printf("err, unable to send message\n");
84 _getch();
85 return 1;
86 }
87
89
90 if (!ReadBytes)
91 {
92 //
93 // Nothing to read
94 //
95 free(Buffer);
96
97 printf("err, unable to read message\n");
98 _getch();
99 return 1;
100 }
101
102 if (strcmp(Buffer,
103 "Hello, Dear Test Process... Yes, I'm HyperDbg Debugger :)") ==
104 0)
105 {
106 //
107 // *** Connected to the HyperDbg debugger ***
108 //
109
110 //
111 // Now we should request the test case number from the HyperDbg Debugger
112 //
113 RtlZeroMemory(Buffer, TEST_CASE_MAXIMUM_BUFFERS_TO_COMMUNICATE);
114
115 strcpy_s(
116 Buffer,
118 "Wow! I miss you... Would you plz send test cases?");
119
120 SentMessageResult =
121 NamedPipeClientSendMessage(PipeHandle, Buffer, (int)strlen(Buffer) + 1);
122
123 if (!SentMessageResult)
124 {
125 //
126 // Sending error
127 //
128 free(Buffer);
129
130 printf("err, sending error\n");
131 _getch();
132 return 1;
133 }
134
135 //
136 // Read the test case number
137 //
138 RtlZeroMemory(Buffer, TEST_CASE_MAXIMUM_BUFFERS_TO_COMMUNICATE);
140
141 if (!ReadBytes)
142 {
143 //
144 // Nothing to read
145 //
146 free(Buffer);
147
148 printf("err, nothing to read\n");
149 _getch();
150 return 1;
151 }
152
153 //
154 // Dispatch the test case number
155 //
156
158 printf("!!!! Read to run the test cases !!!!");
159 _getch();
160
161 //
162 // Close the pipe connection
163 //
164 NamedPipeClientClosePipe(PipeHandle);
165
166 //
167 // Make sure to exit the test program
168 //
169 exit(0);
170 }
171 }
172 else
173 {
174 printf("you should not test functionalities directly, instead use 'test' "
175 "command from HyperDbg...\n");
176
177 free(Buffer);
178 return 1;
179 }
180
181 free(Buffer);
182 return 0;
183}
UCHAR BOOLEAN
Definition BasicTypes.h:39
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 NamedPipeClientReadMessage(HANDLE PipeHandle, char *BufferToRead, int MaximumSizeOfBuffer)
Definition namedpipe.cpp:268
HANDLE NamedPipeClientCreatePipe(LPCSTR PipeName)
Create a client named pipe.
Definition namedpipe.cpp:179
VOID NamedPipeClientClosePipe(HANDLE PipeHandle)
close named pipe handle of client
Definition namedpipe.cpp:302
BOOLEAN NamedPipeClientSendMessage(HANDLE PipeHandle, char *BufferToSend, int BufferSize)
send client message over named pipe
Definition namedpipe.cpp:225
char ** argv
Definition symbol-parser.h:46