码迷,mamicode.com
首页 > 编程语言 > 详细

C++注入记事本升级版,给记事本弄爱心

时间:2019-01-31 13:32:28      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:art   success   snap   amp   system   display   任务   xen   note   

技术分享图片
  1 #include <iostream>;
  2 using namespace std;
  3 #include <windows.h>;
  4 #include <tlhelp32.h>;
  5 #include <tchar.h>;
  6 
  7 BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam);
  8 HWND GetMainWindow();
  9 void MyPostMessage(HWND hWnd);
 10 
 11 extern "C" BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
 12 {
 13     HWND hWnd;
 14     HWND hParWnd, hButWnd;
 15     int d, d1;
 16     switch (fdwReason)
 17     {
 18     case DLL_PROCESS_ATTACH:
 19 
 20         hWnd = GetMainWindow();
 21         if (hWnd)
 22             hWnd = ::FindWindowEx(hWnd, 0, TEXT("EDIT"), NULL);
 23         if (hWnd)
 24         {
 25             ::MessageBox(hWnd, TEXT("开始注入"), TEXT("提示"), MB_OK);
 26             MyPostMessage(hWnd);
 27         }
 28         else
 29         {
 30             ::MessageBox(hWnd, TEXT("记事本不存在"), TEXT("提示"), MB_OK);
 31         }
 32         break;
 33     case DLL_PROCESS_DETACH:
 34         // detach from process
 35         break;
 36 
 37     case DLL_THREAD_ATTACH:
 38         // attach to thread
 39         break;
 40 
 41     case DLL_THREAD_DETACH:
 42         // detach from thread
 43         break;
 44     }
 45     return TRUE; // succesful
 46 }
 47 
 48 BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
 49 {
 50     DWORD dwCurProcessId = *((DWORD*)lParam);
 51     DWORD dwProcessId = 0;
 52 
 53     GetWindowThreadProcessId(hwnd, &dwProcessId);
 54     if (dwProcessId == dwCurProcessId && GetParent(hwnd) == NULL)
 55     {
 56         *((HWND *)lParam) = hwnd;
 57         return FALSE;
 58     }
 59     return TRUE;
 60 }
 61 
 62 
 63 HWND GetMainWindow()
 64 {
 65     DWORD dwCurrentProcessId = GetCurrentProcessId();
 66     if (!EnumWindows(EnumWindowsProc, (LPARAM)&dwCurrentProcessId))
 67     {
 68         return (HWND)dwCurrentProcessId;
 69     }
 70     return NULL;
 71 }
 72 
 73 void MyPostMessage(HWND hWnd)
 74 {
 75     for (int i = 0; i < 25; i++) {
 76         PostMessageW(hWnd, WM_CHAR, L , 1);
 77     }
 78     PostMessageW(hWnd, WM_CHAR, L., 1);
 79     PostMessageW(hWnd, WM_CHAR, L,, 1);
 80     PostMessageW(hWnd, WM_CHAR, L], 1);
 81     PostMessageW(hWnd, WM_CHAR, L], 1);
 82     PostMessageW(hWnd, WM_CHAR, L., 1);
 83     for (int i = 0; i < 33; i++) {
 84         PostMessageW(hWnd, WM_CHAR, L , 1);
 85     }
 86     PostMessageW(hWnd, WM_CHAR, L,, 1);
 87     PostMessageW(hWnd, WM_CHAR, L/, 1);
 88     for (int i = 0; i < 7; i++) {
 89         PostMessageW(hWnd, WM_CHAR, LO, 1);
 90     }
 91     PostMessageW(hWnd, WM_CHAR, L\\, 1);
 92     PostMessageW(hWnd, WM_CHAR, L], 1);
 93     PostMessageW(hWnd, WM_CHAR, L], 1);
 94     PostMessageW(hWnd, WM_CHAR, L], 1);
 95     PostMessageW(hWnd, WM_CHAR, L., 1);
 96     for (int i = 0; i < 17; i++) {
 97         PostMessageW(hWnd, WM_CHAR, L , 1);
 98     }
 99     PostMessageW(hWnd, WM_CHAR, L\n, 1);
100     for (int i = 0; i < 16; i++) {
101         PostMessageW(hWnd, WM_CHAR, L , 1);
102     }
103     PostMessageW(hWnd, WM_CHAR, L,, 1);
104     PostMessageW(hWnd, WM_CHAR, L/, 1);
105     for (int i = 0; i < 15; i++) {
106         PostMessageW(hWnd, WM_CHAR, LO, 1);
107     }
108     PostMessageW(hWnd, WM_CHAR, L], 1);
109     PostMessageW(hWnd, WM_CHAR, L`, 1);
110     for (int i = 0; i < 23; i++) {
111         PostMessageW(hWnd, WM_CHAR, L , 1);
112     }
113     PostMessageW(hWnd, WM_CHAR, L., 1);
114     PostMessageW(hWnd, WM_CHAR, L], 1);
115     for (int i = 0; i < 19; i++) {
116         PostMessageW(hWnd, WM_CHAR, LO, 1);
117     }
118     PostMessageW(hWnd, WM_CHAR, L], 1);
119     PostMessageW(hWnd, WM_CHAR, L., 1);
120     for (int i = 0; i < 13; i++) {
121         PostMessageW(hWnd, WM_CHAR, L , 1);
122     }
123     PostMessageW(hWnd, WM_CHAR, L\n, 1);
124     for (int i = 0; i < 12; i++) {
125         PostMessageW(hWnd, WM_CHAR, L , 1);
126     }
127     PostMessageW(hWnd, WM_CHAR, L], 1);
128     PostMessageW(hWnd, WM_CHAR, L/, 1);
129     for (int i = 0; i < 24; i++) {
130         PostMessageW(hWnd, WM_CHAR, LO, 1);
131     }
132     PostMessageW(hWnd, WM_CHAR, L\\, 1);
133     PostMessageW(hWnd, WM_CHAR, L., 1);
134     for (int i = 0; i < 15; i++) {
135         PostMessageW(hWnd, WM_CHAR, L , 1);
136     }
137     PostMessageW(hWnd, WM_CHAR, L,, 1);
138     for (int i = 0; i < 27; i++) {
139         PostMessageW(hWnd, WM_CHAR, LO, 1);
140     }
141     PostMessageW(hWnd, WM_CHAR, L], 1);
142     for (int i = 0; i < 10; i++) {
143         PostMessageW(hWnd, WM_CHAR, L , 1);
144     }
145     PostMessageW(hWnd, WM_CHAR, L\n, 1);
146     for (int i = 0; i < 9; i++) {
147         PostMessageW(hWnd, WM_CHAR, L , 1);
148     }
149     PostMessageW(hWnd, WM_CHAR, L,, 1);
150     for (int i = 0; i < 31; i++) {
151         PostMessageW(hWnd, WM_CHAR, LO, 1);
152     }
153     PostMessageW(hWnd, WM_CHAR, L`, 1);
154     for (int i = 0; i < 11; i++) {
155         PostMessageW(hWnd, WM_CHAR, L , 1);
156     }
157     PostMessageW(hWnd, WM_CHAR, L,, 1);
158     for (int i = 0; i < 31; i++) {
159         PostMessageW(hWnd, WM_CHAR, LO, 1);
160     }
161     PostMessageW(hWnd, WM_CHAR, L\\, 1);
162     for (int i = 0; i < 8; i++) {
163         PostMessageW(hWnd, WM_CHAR, L , 1);
164     }
165     PostMessageW(hWnd, WM_CHAR, L\n, 1);
166     for (int i = 0; i < 7; i++) {
167         PostMessageW(hWnd, WM_CHAR, L , 1);
168     }
169     PostMessageW(hWnd, WM_CHAR, L,, 1);
170     for (int i = 0; i < 35; i++) {
171         PostMessageW(hWnd, WM_CHAR, LO, 1);
172     }
173     PostMessageW(hWnd, WM_CHAR, L\\, 1);
174     for (int i = 0; i < 7; i++) {
175         PostMessageW(hWnd, WM_CHAR, L , 1);
176     }
177     PostMessageW(hWnd, WM_CHAR, L,, 1);
178     for (int i = 0; i < 35; i++) {
179         PostMessageW(hWnd, WM_CHAR, LO, 1);
180     }
181     PostMessageW(hWnd, WM_CHAR, L\\, 1);
182     for (int i = 0; i < 6; i++) {
183         PostMessageW(hWnd, WM_CHAR, L , 1);
184     }
185     PostMessageW(hWnd, WM_CHAR, L\n, 1);
186     for (int i = 0; i < 5; i++) {
187         PostMessageW(hWnd, WM_CHAR, L , 1);
188     }
189     PostMessageW(hWnd, WM_CHAR, L,, 1);
190     for (int i = 0; i < 39; i++) {
191         PostMessageW(hWnd, WM_CHAR, LO, 1);
192     }
193     PostMessageW(hWnd, WM_CHAR, L\\, 1);
194     PostMessageW(hWnd, WM_CHAR, L., 1);
195     PostMessageW(hWnd, WM_CHAR, L , 1);
196     PostMessageW(hWnd, WM_CHAR, L , 1);
197     PostMessageW(hWnd, WM_CHAR, L,, 1);
198     for (int i = 0; i < 39; i++) {
199         PostMessageW(hWnd, WM_CHAR, LO, 1);
200     }
201     PostMessageW(hWnd, WM_CHAR, L\\, 1);
202     for (int i = 0; i < 4; i++) {
203         PostMessageW(hWnd, WM_CHAR, L , 1);
204     }
205     PostMessageW(hWnd, WM_CHAR, L\n, 1);
206     for (int i = 0; i < 3; i++) {
207         PostMessageW(hWnd, WM_CHAR, L , 1);
208     }
209     PostMessageW(hWnd, WM_CHAR, L,, 1);
210     for (int i = 0; i < 87; i++) {
211         PostMessageW(hWnd, WM_CHAR, LO, 1);
212     }
213     PostMessageW(hWnd, WM_CHAR, L., 1);
214     PostMessageW(hWnd, WM_CHAR, L , 1);
215     PostMessageW(hWnd, WM_CHAR, L , 1);
216     PostMessageW(hWnd, WM_CHAR, L\n, 1);
217     PostMessageW(hWnd, WM_CHAR, L , 1);
218     PostMessageW(hWnd, WM_CHAR, L , 1);
219     PostMessageW(hWnd, WM_CHAR, L., 1);
220     for (int i = 0; i < 89; i++) {
221         PostMessageW(hWnd, WM_CHAR, LO, 1);
222     }
223     PostMessageW(hWnd, WM_CHAR, L., 1);
224     PostMessageW(hWnd, WM_CHAR, L , 1);
225     PostMessageW(hWnd, WM_CHAR, L\n, 1);
226     PostMessageW(hWnd, WM_CHAR, L , 1);
227     PostMessageW(hWnd, WM_CHAR, L , 1);
228     PostMessageW(hWnd, WM_CHAR, L/, 1);
229     for (int i = 0; i < 90; i++) {
230         PostMessageW(hWnd, WM_CHAR, LO, 1);
231     }
232     PostMessageW(hWnd, WM_CHAR, L , 1);
233     PostMessageW(hWnd, WM_CHAR, L\n, 1);
234     PostMessageW(hWnd, WM_CHAR, L , 1);
235     PostMessageW(hWnd, WM_CHAR, L=, 1);
236     for (int i = 0; i < 91; i++) {
237         PostMessageW(hWnd, WM_CHAR, LO, 1);
238     }
239     PostMessageW(hWnd, WM_CHAR, L\\, 1);
240     PostMessageW(hWnd, WM_CHAR, L\n, 1);
241     PostMessageW(hWnd, WM_CHAR, L=, 1);
242     for (int i = 0; i < 93; i++) {
243         PostMessageW(hWnd, WM_CHAR, LO, 1);
244     }
245     PostMessageW(hWnd, WM_CHAR, L\n, 1);
246     for (int i = 0; i < 94; i++) {
247         PostMessageW(hWnd, WM_CHAR, LO, 1);
248     }
249     PostMessageW(hWnd, WM_CHAR, L\n, 1);
250     PostMessageW(hWnd, WM_CHAR, L=, 1);
251     for (int i = 0; i < 93; i++) {
252         PostMessageW(hWnd, WM_CHAR, LO, 1);
253     }
254     PostMessageW(hWnd, WM_CHAR, L\n, 1);
255     PostMessageW(hWnd, WM_CHAR, L=, 1);
256     for (int i = 0; i < 93; i++) {
257         PostMessageW(hWnd, WM_CHAR, LO, 1);
258     }
259     PostMessageW(hWnd, WM_CHAR, L\n, 1);
260     PostMessageW(hWnd, WM_CHAR, L=, 1);
261     for (int i = 0; i < 93; i++) {
262         PostMessageW(hWnd, WM_CHAR, LO, 1);
263     }
264     PostMessageW(hWnd, WM_CHAR, L\n, 1);
265     PostMessageW(hWnd, WM_CHAR, L., 1);
266     for (int i = 0; i < 93; i++) {
267         PostMessageW(hWnd, WM_CHAR, LO, 1);
268     }
269     PostMessageW(hWnd, WM_CHAR, L\n, 1);
270     PostMessageW(hWnd, WM_CHAR, L , 1);
271     for (int i = 0; i < 93; i++) {
272         PostMessageW(hWnd, WM_CHAR, LO, 1);
273     }
274     PostMessageW(hWnd, WM_CHAR, L\n, 1);
275     PostMessageW(hWnd, WM_CHAR, L , 1);
276     PostMessageW(hWnd, WM_CHAR, L,, 1);
277     for (int i = 0; i < 92; i++) {
278         PostMessageW(hWnd, WM_CHAR, LO, 1);
279     }
280     PostMessageW(hWnd, WM_CHAR, L\n, 1);
281     PostMessageW(hWnd, WM_CHAR, L , 1);
282     PostMessageW(hWnd, WM_CHAR, L , 1);
283     PostMessageW(hWnd, WM_CHAR, L=, 1);
284     for (int i = 0; i < 90; i++) {
285         PostMessageW(hWnd, WM_CHAR, LO, 1);
286     }
287     PostMessageW(hWnd, WM_CHAR, L^, 1);
288     PostMessageW(hWnd, WM_CHAR, L\n, 1);
289     for (int i = 0; i < 3; i++) {
290         PostMessageW(hWnd, WM_CHAR, L , 1);
291     }
292     PostMessageW(hWnd, WM_CHAR, L\\, 1);
293     for (int i = 0; i < 88; i++) {
294         PostMessageW(hWnd, WM_CHAR, LO, 1);
295     }
296     PostMessageW(hWnd, WM_CHAR, L/, 1);
297     PostMessageW(hWnd, WM_CHAR, L , 1);
298     PostMessageW(hWnd, WM_CHAR, L\n, 1);
299     for (int i = 0; i < 4; i++) {
300         PostMessageW(hWnd, WM_CHAR, L , 1);
301     }
302     for (int i = 0; i < 88; i++) {
303         PostMessageW(hWnd, WM_CHAR, LO, 1);
304     }
305     PostMessageW(hWnd, WM_CHAR, L , 1);
306     PostMessageW(hWnd, WM_CHAR, L , 1);
307     PostMessageW(hWnd, WM_CHAR, L\n, 1);
308     for (int i = 0; i < 4; i++) {
309         PostMessageW(hWnd, WM_CHAR, L , 1);
310     }
311     PostMessageW(hWnd, WM_CHAR, L., 1);
312     for (int i = 0; i < 86; i++) {
313         PostMessageW(hWnd, WM_CHAR, LO, 1);
314     }
315     PostMessageW(hWnd, WM_CHAR, L., 1);
316     PostMessageW(hWnd, WM_CHAR, L , 1);
317     PostMessageW(hWnd, WM_CHAR, L , 1);
318     PostMessageW(hWnd, WM_CHAR, L\n, 1);
319     for (int i = 0; i < 5; i++) {
320         PostMessageW(hWnd, WM_CHAR, L , 1);
321     }
322     PostMessageW(hWnd, WM_CHAR, L,, 1);
323     for (int i = 0; i < 84; i++) {
324         PostMessageW(hWnd, WM_CHAR, LO, 1);
325     }
326     PostMessageW(hWnd, WM_CHAR, L., 1);
327     for (int i = 0; i < 3; i++) {
328         PostMessageW(hWnd, WM_CHAR, L , 1);
329     }
330     PostMessageW(hWnd, WM_CHAR, L\n, 1);
331     for (int i = 0; i < 7; i++) {
332         PostMessageW(hWnd, WM_CHAR, L , 1);
333     }
334     PostMessageW(hWnd, WM_CHAR, L\\, 1);
335     for (int i = 0; i < 80; i++) {
336         PostMessageW(hWnd, WM_CHAR, LO, 1);
337     }
338     PostMessageW(hWnd, WM_CHAR, L/, 1);
339     for (int i = 0; i < 5; i++) {
340         PostMessageW(hWnd, WM_CHAR, L , 1);
341     }
342     PostMessageW(hWnd, WM_CHAR, L\n, 1);
343     for (int i = 0; i < 8; i++) {
344         PostMessageW(hWnd, WM_CHAR, L , 1);
345     }
346     PostMessageW(hWnd, WM_CHAR, L,, 1);
347     for (int i = 0; i < 78; i++) {
348         PostMessageW(hWnd, WM_CHAR, LO, 1);
349     }
350     PostMessageW(hWnd, WM_CHAR, L`, 1);
351     for (int i = 0; i < 6; i++) {
352         PostMessageW(hWnd, WM_CHAR, L , 1);
353     }
354     PostMessageW(hWnd, WM_CHAR, L\n, 1);
355     for (int i = 0; i < 9; i++) {
356         PostMessageW(hWnd, WM_CHAR, L , 1);
357     }
358     PostMessageW(hWnd, WM_CHAR, L,, 1);
359     for (int i = 0; i < 76; i++) {
360         PostMessageW(hWnd, WM_CHAR, LO, 1);
361     }
362     PostMessageW(hWnd, WM_CHAR, L`, 1);
363     for (int i = 0; i < 7; i++) {
364         PostMessageW(hWnd, WM_CHAR, L , 1);
365     }
366     PostMessageW(hWnd, WM_CHAR, L\n, 1);
367     for (int i = 0; i < 11; i++) {
368         PostMessageW(hWnd, WM_CHAR, L , 1);
369     }
370     PostMessageW(hWnd, WM_CHAR, L\\, 1);
371     for (int i = 0; i < 72; i++) {
372         PostMessageW(hWnd, WM_CHAR, LO, 1);
373     }
374     PostMessageW(hWnd, WM_CHAR, L/, 1);
375     for (int i = 0; i < 9; i++) {
376         PostMessageW(hWnd, WM_CHAR, L , 1);
377     }
378     PostMessageW(hWnd, WM_CHAR, L\n, 1);
379     for (int i = 0; i < 12; i++) {
380         PostMessageW(hWnd, WM_CHAR, L , 1);
381     }
382     PostMessageW(hWnd, WM_CHAR, L=, 1);
383     for (int i = 0; i < 70; i++) {
384         PostMessageW(hWnd, WM_CHAR, LO, 1);
385     }
386     PostMessageW(hWnd, WM_CHAR, L^, 1);
387     for (int i = 0; i < 10; i++) {
388         PostMessageW(hWnd, WM_CHAR, L , 1);
389     }
390     PostMessageW(hWnd, WM_CHAR, L\n, 1);
391     for (int i = 0; i < 13; i++) {
392         PostMessageW(hWnd, WM_CHAR, L , 1);
393     }
394     PostMessageW(hWnd, WM_CHAR, L., 1);
395     for (int i = 0; i < 67; i++) {
396         PostMessageW(hWnd, WM_CHAR, LO, 1);
397     }
398     PostMessageW(hWnd, WM_CHAR, L/, 1);
399     PostMessageW(hWnd, WM_CHAR, L., 1);
400     for (int i = 0; i < 11; i++) {
401         PostMessageW(hWnd, WM_CHAR, L , 1);
402     }
403     PostMessageW(hWnd, WM_CHAR, L\n, 1);
404     for (int i = 0; i < 15; i++) {
405         PostMessageW(hWnd, WM_CHAR, L , 1);
406     }
407     PostMessageW(hWnd, WM_CHAR, L,, 1);
408     for (int i = 0; i < 64; i++) {
409         PostMessageW(hWnd, WM_CHAR, LO, 1);
410     }
411     PostMessageW(hWnd, WM_CHAR, L`, 1);
412     for (int i = 0; i < 13; i++) {
413         PostMessageW(hWnd, WM_CHAR, L , 1);
414     }
415     PostMessageW(hWnd, WM_CHAR, L\n, 1);
416     for (int i = 0; i < 17; i++) {
417         PostMessageW(hWnd, WM_CHAR, L , 1);
418     }
419     PostMessageW(hWnd, WM_CHAR, L\\, 1);
420     for (int i = 0; i < 60; i++) {
421         PostMessageW(hWnd, WM_CHAR, LO, 1);
422     }
423     PostMessageW(hWnd, WM_CHAR, L/, 1);
424     for (int i = 0; i < 15; i++) {
425         PostMessageW(hWnd, WM_CHAR, L , 1);
426     }
427     PostMessageW(hWnd, WM_CHAR, L\n, 1);
428     for (int i = 0; i < 18; i++) {
429         PostMessageW(hWnd, WM_CHAR, L , 1);
430     }
431     PostMessageW(hWnd, WM_CHAR, L,, 1);
432     for (int i = 0; i < 58; i++) {
433         PostMessageW(hWnd, WM_CHAR, LO, 1);
434     }
435     PostMessageW(hWnd, WM_CHAR, L., 1);
436     for (int i = 0; i < 16; i++) {
437         PostMessageW(hWnd, WM_CHAR, L , 1);
438     }
439     PostMessageW(hWnd, WM_CHAR, L\n, 1);
440     for (int i = 0; i < 20; i++) {
441         PostMessageW(hWnd, WM_CHAR, L , 1);
442     }
443     PostMessageW(hWnd, WM_CHAR, L,, 1);
444     for (int i = 0; i < 54; i++) {
445         PostMessageW(hWnd, WM_CHAR, LO, 1);
446     }
447     PostMessageW(hWnd, WM_CHAR, L`, 1);
448     for (int i = 0; i < 18; i++) {
449         PostMessageW(hWnd, WM_CHAR, L , 1);
450     }
451     PostMessageW(hWnd, WM_CHAR, L\n, 1);
452     for (int i = 0; i < 22; i++) {
453         PostMessageW(hWnd, WM_CHAR, L , 1);
454     }
455     PostMessageW(hWnd, WM_CHAR, L,, 1);
456     for (int i = 0; i < 50; i++) {
457         PostMessageW(hWnd, WM_CHAR, LO, 1);
458     }
459     PostMessageW(hWnd, WM_CHAR, L`, 1);
460     for (int i = 0; i < 20; i++) {
461         PostMessageW(hWnd, WM_CHAR, L , 1);
462     }
463     PostMessageW(hWnd, WM_CHAR, L\n, 1);
464     for (int i = 0; i < 24; i++) {
465         PostMessageW(hWnd, WM_CHAR, L , 1);
466     }
467     PostMessageW(hWnd, WM_CHAR, L\\, 1);
468     for (int i = 0; i < 46; i++) {
469         PostMessageW(hWnd, WM_CHAR, LO, 1);
470     }
471     PostMessageW(hWnd, WM_CHAR, L`, 1);
472     for (int i = 0; i < 22; i++) {
473         PostMessageW(hWnd, WM_CHAR, L , 1);
474     }
475     PostMessageW(hWnd, WM_CHAR, L\n, 1);
476     for (int i = 0; i < 26; i++) {
477         PostMessageW(hWnd, WM_CHAR, L , 1);
478     }
479     PostMessageW(hWnd, WM_CHAR, L\\, 1);
480     for (int i = 0; i < 42; i++) {
481         PostMessageW(hWnd, WM_CHAR, LO, 1);
482     }
483     PostMessageW(hWnd, WM_CHAR, L`, 1);
484     for (int i = 0; i < 24; i++) {
485         PostMessageW(hWnd, WM_CHAR, L , 1);
486     }
487     PostMessageW(hWnd, WM_CHAR, L\n, 1);
488     for (int i = 0; i < 28; i++) {
489         PostMessageW(hWnd, WM_CHAR, L , 1);
490     }
491     PostMessageW(hWnd, WM_CHAR, L,, 1);
492     for (int i = 0; i < 37; i++) {
493         PostMessageW(hWnd, WM_CHAR, LO, 1);
494     }
495     PostMessageW(hWnd, WM_CHAR, L/, 1);
496     PostMessageW(hWnd, WM_CHAR, L., 1);
497     for (int i = 0; i < 26; i++) {
498         PostMessageW(hWnd, WM_CHAR, L , 1);
499     }
500     PostMessageW(hWnd, WM_CHAR, L\n, 1);
501     for (int i = 0; i < 30; i++) {
502         PostMessageW(hWnd, WM_CHAR, L , 1);
503     }
504     PostMessageW(hWnd, WM_CHAR, L., 1);
505     PostMessageW(hWnd, WM_CHAR, L\\, 1);
506     for (int i = 0; i < 32; i++) {
507         PostMessageW(hWnd, WM_CHAR, LO, 1);
508     }
509     PostMessageW(hWnd, WM_CHAR, L[, 1);
510     for (int i = 0; i < 29; i++) {
511         PostMessageW(hWnd, WM_CHAR, L , 1);
512     }
513     PostMessageW(hWnd, WM_CHAR, L\n, 1);
514     for (int i = 0; i < 33; i++) {
515         PostMessageW(hWnd, WM_CHAR, L , 1);
516     }
517     PostMessageW(hWnd, WM_CHAR, L,, 1);
518     for (int i = 0; i < 27; i++) {
519         PostMessageW(hWnd, WM_CHAR, LO, 1);
520     }
521     PostMessageW(hWnd, WM_CHAR, L/, 1);
522     PostMessageW(hWnd, WM_CHAR, L`, 1);
523     for (int i = 0; i < 31; i++) {
524         PostMessageW(hWnd, WM_CHAR, L , 1);
525     }
526     PostMessageW(hWnd, WM_CHAR, L\n, 1);
527     for (int i = 0; i < 36; i++) {
528         PostMessageW(hWnd, WM_CHAR, L , 1);
529     }
530     PostMessageW(hWnd, WM_CHAR, L,, 1);
531     for (int i = 0; i < 22; i++) {
532         PostMessageW(hWnd, WM_CHAR, LO, 1);
533     }
534     PostMessageW(hWnd, WM_CHAR, L`, 1);
535     for (int i = 0; i < 34; i++) {
536         PostMessageW(hWnd, WM_CHAR, L , 1);
537     }
538     PostMessageW(hWnd, WM_CHAR, L\n, 1);
539     for (int i = 0; i < 39; i++) {
540         PostMessageW(hWnd, WM_CHAR, L , 1);
541     }
542     PostMessageW(hWnd, WM_CHAR, L,, 1);
543     for (int i = 0; i < 16; i++) {
544         PostMessageW(hWnd, WM_CHAR, LO, 1);
545     }
546     PostMessageW(hWnd, WM_CHAR, L[, 1);
547     for (int i = 0; i < 37; i++) {
548         PostMessageW(hWnd, WM_CHAR, L , 1);
549     }
550     PostMessageW(hWnd, WM_CHAR, L\n, 1);
551     for (int i = 0; i < 42; i++) {
552         PostMessageW(hWnd, WM_CHAR, L , 1);
553     }
554     PostMessageW(hWnd, WM_CHAR, L\\, 1);
555     for (int i = 0; i < 10; i++) {
556         PostMessageW(hWnd, WM_CHAR, LO, 1);
557     }
558     PostMessageW(hWnd, WM_CHAR, L/, 1);
559     PostMessageW(hWnd, WM_CHAR, L., 1);
560     for (int i = 0; i < 39; i++) {
561         PostMessageW(hWnd, WM_CHAR, L , 1);
562     }
563     PostMessageW(hWnd, WM_CHAR, L\n, 1);
564     for (int i = 0; i < 44; i++) {
565         PostMessageW(hWnd, WM_CHAR, L , 1);
566     }
567     PostMessageW(hWnd, WM_CHAR, L,, 1);
568     for (int i = 0; i < 6; i++) {
569         PostMessageW(hWnd, WM_CHAR, LO, 1);
570     }
571     PostMessageW(hWnd, WM_CHAR, L`, 1);
572     for (int i = 0; i < 42; i++) {
573         PostMessageW(hWnd, WM_CHAR, L , 1);
574     }
575     PostMessageW(hWnd, WM_CHAR, L\n, 1);
576     for (int i = 0; i < 46; i++) {
577         PostMessageW(hWnd, WM_CHAR, L , 1);
578     }
579     PostMessageW(hWnd, WM_CHAR, L., 1);
580     PostMessageW(hWnd, WM_CHAR, L\\, 1);
581     PostMessageW(hWnd, WM_CHAR, LO, 1);
582     PostMessageW(hWnd, WM_CHAR, L`, 1);
583     for (int i = 0; i < 44; i++) {
584         PostMessageW(hWnd, WM_CHAR, L , 1);
585     }
586     PostMessageW(hWnd, WM_CHAR, L\n, 1);
587 }
Dll文件
技术分享图片
  1 #include <iostream>;
  2 using namespace std;
  3 #include <windows.h>;
  4 #include <tlhelp32.h>;
  5 #include <tchar.h>;
  6 
  7 HANDLE hThread = NULL;
  8 //进程名称查找进程ID
  9 DWORD ProcessFind(LPCTSTR Exename) //进程名称
 10 {
 11     HANDLE hProcess = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
 12     if (!hProcess)
 13     {
 14         return FALSE;
 15     }
 16     PROCESSENTRY32 info;
 17     info.dwSize = sizeof(PROCESSENTRY32);
 18     if (!Process32First(hProcess, &info))
 19     {
 20         return FALSE;
 21     }
 22     while (TRUE)
 23     {
 24         cout << endl;
 25         if (_tcscmp(info.szExeFile, Exename) == 0)
 26         {
 27             return info.th32ProcessID;//返回进程的ID
 28         }
 29         if (!Process32Next(hProcess, &info))
 30         {
 31             return FALSE;
 32         }
 33     }
 34     return FALSE;
 35 
 36 }
 37 
 38 int dll_inject() {
 39     //Dll文件地址,改成你自己的地址
 40     const TCHAR *pLocDll = TEXT("F:\\工作\\项目\\控制台\\injection\\injection\\x64\\Release\\injectionDll.dll");
 41 
 42     HANDLE hThread = NULL;
 43 
 44     //记事本进程名称
 45     DWORD ProcessID = ProcessFind(TEXT("notepad.exe"));
 46     if (!ProcessID) {
 47         cout << "查找不到当前程序" << endl;
 48     }
 49     else {
 50         //获取进程ID
 51         HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, ProcessID);
 52 
 53         //获取dll大小
 54         SIZE_T PathSize = (_tcslen(TEXT("injectionDll.dll")) + 1) * sizeof(TCHAR);
 55 
 56         //申请内存
 57         LPVOID StartAddress = VirtualAllocEx(hProcess, NULL, PathSize, MEM_COMMIT, PAGE_READWRITE);
 58 
 59         //写入内存
 60         bool bSuccess = WriteProcessMemory(hProcess, StartAddress, TEXT("injectionDll.dll"), PathSize, 0);
 61         if (!bSuccess)
 62         {
 63             cout << "写入失败" << endl;
 64         }
 65         else {
 66             //在寄主申请内存
 67             LPVOID strRmt = VirtualAllocEx(hProcess, nullptr, MAX_PATH, MEM_COMMIT, PAGE_READWRITE);
 68             //获得注入DLL大小
 69             size_t lenLocDll = 2 * _tcslen(pLocDll);
 70             //判断寄主申请内存是否成功
 71             if (strRmt) {
 72                 //把DLL写入寄主内存
 73                 BOOL ret = WriteProcessMemory(hProcess, strRmt, pLocDll, lenLocDll, nullptr);
 74                 //获得LoadLibraryW的函数地址以使用LoadLibrary函数
 75                 LPTHREAD_START_ROUTINE loadlib = LPTHREAD_START_ROUTINE(GetProcAddress(GetModuleHandle(TEXT("Kernel32")), "LoadLibraryW"));
 76                 //注入
 77                 hThread = CreateRemoteThread(hProcess, nullptr, 0, loadlib, LPVOID(strRmt), 0, nullptr);
 78             }
 79             
 80             /*
 81             HANDLE hThread = CreateRemoteThread(hProcess, 0, 0, (LPTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandle(_T("kernel32.dll")), "LoadLibrary"), StartAddress, 0, 0);*/
 82 
 83             if (hThread == NULL)
 84             {
 85                 cout << "在进程中注入失败:";
 86                 cout << GetLastError() << endl;
 87                 return -1;
 88             }
 89 
 90             WaitForSingleObject(hThread, INFINITE);
 91             //到这里已经完成dll的加载即注入了,通过dll函数执行我们要完成的任务
 92             //释放
 93             VirtualFreeEx(hProcess, StartAddress,0, MEM_RELEASE);
 94             CloseHandle(hThread);
 95             CloseHandle(hProcess);
 96         }
 97     }
 98 }
 99 int main()
100 {
101     dll_inject();
102     system("pause");
103 }
主程序

 

C++注入记事本升级版,给记事本弄爱心

标签:art   success   snap   amp   system   display   任务   xen   note   

原文地址:https://www.cnblogs.com/weijunyu/p/10341211.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!