将第二个程序的进程号写入第一个的ID中,同时将&i地址写在WriteProcessMemory中,调试可以发现,改变了第二个程序的i的值

    1. #include<windows.h>
    2. #include<tchar.h>
    3. #include<Tlhelp32.h>
    4. #define ID 4368
    5. int _tmain()
    6. {
    7. HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPHEAPLIST,ID);
    8. if (hSnapshot == INVALID_HANDLE_VALUE)
    9. {
    10. _tprintf(L"%d\n", GetLastError());
    11. return 0;
    12. }
    13. HEAPLIST32 hl = {0};
    14. hl.dwSize = sizeof(hl);
    15. Heap32ListFirst(hSnapshot,&hl);
    16. do{
    17. _tprintf(L"------------------------------------------------\n");
    18. _tprintf(TEXT("ProcessID=%d,HeapID=%d\n"),hl.th32ProcessID,hl.th32HeapID);
    19. HEAPENTRY32 he = {0};
    20. he.dwSize = sizeof(he);
    21. Heap32First(&he,hl.th32ProcessID,hl.th32HeapID);
    22. do{
    23. _tprintf(TEXT("Address=%0x\tSize=%0x\tflages=%0x\n"),he.dwAddress,he.dwBlockSize,
    24. he.dwFlags);
    25. } while (Heap32Next(&he));
    26. } while (Heap32ListNext(hSnapshot, &hl));
    27. HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS,FALSE,ID);
    28. int i = 0;
    29. ReadProcessMemory(hProcess,(LPCVOID)(0x13b0818),&i,4,NULL);
    30. i = 0;
    31. WriteProcessMemory(hProcess, (LPVOID)(0x13b0818), &i, 4, NULL);//往内存中写数据,将i=0赋给它
    32. CloseHandle(hSnapshot);
    33. CloseHandle(hProcess);
    34. _gettchar();
    35. return 0;
    36. }
    37. /*
    38. 这种列举方法,只能列举其他进程中堆内存的信息
    39. 线程栈的内存信息,没法列出来
    40. 我们可以获得其他进程中内存数据,也可以修改其他进程中的数据
    41. */
    1. #include<windows.h>
    2. #include<tchar.h>
    3. int _tmain()
    4. {
    5. int i = 2000;
    6. while (1)
    7. {
    8. _tprintf(L"%d\n", i);
    9. }
    10. _gettchar();
    11. return 0;
    12. }