DWORD m_dwpid;voidCpurecode_injectdlg::onbtninject () {//Todo:add your control notification handler code hereUpdateData (TRUE); if(M_dwpid = =0) {MessageBox ("PID is unvalid!"); return ; } HANDLE hprocess=openprocess (process_all_access, FALSE, m_dwpid); if(hprocess = =NULL) {MessageBox ("Open Process Failed!"); return ; } data data; DWORD Dwwritenum=0; strcpy (Data.text,"Hello, World"); strcpy (Data.title,"Info"); Data.dwmessagebox= (DWORD) GetProcAddress (GetModuleHandle ("User32.dll"),"MessageBoxA"); LPVOID lpdata= VirtualAllocEx (hprocess, NULL,sizeof(DATA), mem_commit|Mem_reserve, Page_readwrite); WriteProcessMemory (hprocess, lpdata,&data,sizeof(DATA), &dwwritenum); LPVOID Lpcode= VirtualAllocEx (hprocess, NULL,0x200, Mem_commit, page_execute_readwrite); WriteProcessMemory (hprocess, Lpcode, Remotethreadproc,0x200, &dwwritenum); HANDLE Hthread=CreateRemoteThread (hprocess, NULL, 0, (lpthread_start_routine) Lpcode, lpdata , 0, NULL); WaitForSingleObject (Hthread, INFINITE); CloseHandle (Hthread); VirtualFreeEx (hprocess, Lpcode,0, mem_release);//free memory space after remote thread execution endsVirtualFreeEx (hprocess, lpdata,0, mem_release);//free memory space after remote thread execution endsCloseHandle (hprocess);} typedefstruct { Chartext[ -]; Chartitle[ -]; DWORD Dwmessagebox;} DATA,*Pdata;typedefint(__stdcall *My_messagebox) (HWND, LPCTSTR, LPCTSTR, DWORD); DWORD WINAPI Remotethreadproc (lpvoid pparam) {PDATA PDATA=(PDATA) Pparam; My_messagebox Mymessagebox; Mymessagebox= My_messagebox (pdata->Dwmessagebox); Mymessagebox (NULL, PData->text, pdata->title, MB_OK); //MessageBox (NULL, Pdata->text, Pdata->title, MB_OK); //the MessageBox () function cannot be called directly because the compiled address is not in the address space of the remote thread//MessageBox (NULL, "Hello", "Title", MB_OK); //nor can it be called directly, "Hello", "Title" and not access error in the address space of the remote thread return 0;}
[00027]-[2015-09-20]-[02]-[Code injection Technology---2 direct code write]