[C ++ TlHelp32.h程序在写入后关闭

问题描述 投票:0回答:1

我正在从称为“空”的渠道学习如何与流程进行交互。我写了他的程序,试图理解一切。但是当我执行它时,wpm函数确实起作用了,但是目标程序在增加了我正在写入的相同变量之后立即关闭了它。

无论如何,这是代码。

#include <iostream>
#include <Windows.h>
#include <TlHelp32.h>

HANDLE  hProc = NULL;
DWORD   ProcId;

bool attatchProc(const char* ProcName) 
{

    PROCESSENTRY32 procEntry;

    procEntry.dwSize = sizeof(PROCESSENTRY32);

    auto hProcSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

    if (hProcSnap == INVALID_HANDLE_VALUE)
        return false;

    while (Process32Next(hProcSnap, &procEntry)) {
        std::cout << procEntry.szExeFile << std::endl;
        if (!strcmp(ProcName, procEntry.szExeFile)) {
            std::cout << "Process Found!\n Heres the Process ID" << procEntry.th32ProcessID << std::endl;

            ProcId = procEntry.th32ProcessID;
            hProc = OpenProcess(PROCESS_ALL_ACCESS, false, ProcId);

            if (hProc == NULL)
                std::cout << "Sike you thought lmao" << std::endl;

            CloseHandle(hProcSnap);
            return true;
        }
    }
    std::cout << "Process not found or other issue";
}

template <class DataType>

void wpm(DataType VarToWrite, DWORD addressToWrite) 

{

    WriteProcessMemory(hProc, (PVOID)addressToWrite, &VarToWrite, sizeof(DataType), 0);

}

int main()
{
    DWORD memAddr = 0x012FF848;
    attatchProc((char*)"Testing.exe");

    while (1)
    {
        wpm<int>(68, memAddr);
    }
}
c++ windows winapi c++17
1个回答
0
投票

有什么例外?您确定地址有效吗?可执行文件不使用ASLR吗?

© www.soinside.com 2019 - 2024. All rights reserved.