[00027]-[2015-09-20]-[02]-[Code injection Technology---2 direct code write]

Source: Internet
Author: User

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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.