1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| #include <windows.h> #include <stdio.h>
typedef struct tagParamCall { DWORD addr; UINT uType; HWND hWnd; char Caption[256]; char Text[256];
}ParamCall, * PParamCall;
void AddSun(PParamCall Addr) { int uType; const char* Caption; char* Text; DWORD addr; __asm { mov eax, [Addr] mov ecx, [eax] mov [addr], ecx mov ecx, [eax + 0x4] mov uType, ecx lea ecx, [eax + 0xc] mov Caption, ecx lea ecx, [eax + 0x10C] mov Text, ecx push uType push Caption push Text push 0 call addr
} }
void InjectCode(DWORD dwProcId, LPVOID mFunc) { HANDLE hProcess, hThread; LPVOID mFuncAddr, mParamAddr; DWORD NumberOfByte;
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcId); mFuncAddr = VirtualAllocEx(hProcess, NULL, 1024, MEM_COMMIT, PAGE_EXECUTE_READWRITE); WriteProcessMemory(hProcess, mFuncAddr, mFunc, 1024, &NumberOfByte); ParamCall mParam; mParam.addr = &MessageBoxA; mParam.hWnd = NULL; memcpy(mParam.Text, "Text", strlen("Text")+1); memcpy(mParam.Caption, "title", strlen("title")+1); mParam.uType = 2; printf("0x%X\n", sizeof(mParam.uType)); mParamAddr = VirtualAllocEx(hProcess, NULL, 1024, MEM_COMMIT, PAGE_EXECUTE_READWRITE); WriteProcessMemory(hProcess, mParamAddr, &mParam, 1024, &NumberOfByte); hThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)mFuncAddr, mParamAddr, 0, &NumberOfByte); WaitForSingleObject(hThread, INFINITE); VirtualFreeEx(hProcess, mFuncAddr, 1024, MEM_RELEASE); VirtualFreeEx(hProcess, mParamAddr, 1024, MEM_RELEASE); CloseHandle(hThread); CloseHandle(hProcess); }
int main(int argc, char** argv) {
InjectCode(93680, AddSun); return 0; }
|