内存修改器

// SoCool.cpp: 定义控制台应用程序的入口点。
//

#include "stdafx.h"

#include <Windows.h>
#include <TlHelp32.h>   // enum all process 


HANDLE  g_hProcess = INVALID_HANDLE_VALUE;
DWORD g_dwValueAddr[1024] = { 0 };
DWORD g_dwListCount = 0;
BOOL CompareAPage(DWORD dwAddr,DWORD dwValue)
{
    BYTE arrayByte[4096] = { 0 };

    ReadProcessMemory(g_hProcess,(LPCVOID)dwAddr, arrayByte, 4096, nullptr);
    
    DWORD *pDword = nullptr;
    for (int nIndex = 0; nIndex < 4096-3; nIndex++)
    {
        pDword = (DWORD*)&arrayByte[nIndex];
        if (*pDword==dwValue)
        {
            if (g_dwListCount>=1024)
            {
                return false;
            }
            g_dwValueAddr[g_dwListCount++] = dwAddr + nIndex;
        }
    }
    return TRUE;
}

BOOL FindFirstMemory(DWORD dwValue)
{
    const DWORD dwOneGB = 1024 * 1024 * 1024;
    if (nullptr==g_hProcess)
    {
        return false;
    }
    for (DWORD dwBase = 640*1024; dwBase < 2*dwOneGB; dwBase+=(4*1024))
    {
        CompareAPage(dwBase,dwValue);
    }
    return TRUE;
}

BOOL FindNext(DWORD dwValue)
{
    int nListCount = g_dwListCount;
    g_dwListCount = 0;
    DWORD dwFindValue = 0;
    BOOL bRet = false;
    for (int  nIndex = 0; nIndex < nListCount; nIndex++)
    {
        if (ReadProcessMemory(g_hProcess,(LPVOID)g_dwValueAddr[nIndex],&dwFindValue,sizeof(dwFindValue),nullptr))
        {
            if (dwFindValue==dwValue)
            {
                g_dwValueAddr[g_dwListCount++] = g_dwValueAddr[nIndex];
                bRet = true;
            }
        }
    }
    return bRet;
}

int main(int argc,char* argv[])
{    
    PROCESSENTRY32 pe32 = { 0 };
    pe32.dwSize = sizeof(pe32);

    HANDLE  hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);

    BOOL  bMore = Process32First(hProcessSnap, &pe32);
    while (bMore)
    {
        printf("ProcessName:%50ws\tPID:%d\r\n", pe32.szExeFile, pe32.th32ParentProcessID);
        bMore = Process32Next(hProcessSnap, &pe32);
    }

    printf("input target PID:\r\n");
    DWORD dwPID = 0;
    scanf("%d", &dwPID);
    g_hProcess =  OpenProcess(PROCESS_ALL_ACCESS, false, dwPID);
    if (INVALID_HANDLE_VALUE != g_hProcess)
    {
        printf("Please input the value your want to find:\r\n");
        DWORD dwValue = 0;
        scanf("%d", &dwValue);
        FindFirstMemory(dwValue);

        for (int  nIndex = 0; nIndex < g_dwListCount; nIndex++)
        {
            printf("find address:%08X\r\n", g_dwValueAddr[nIndex]);
        }
        printf("total find %d \r\n", g_dwListCount);
        while (1<g_dwListCount)
        {
            printf("Please input the value your want to find:\r\n");
            DWORD dwValue = 0;
            scanf("%d", &dwValue);
            FindNext(dwValue);
            for (int nIndex = 0; nIndex < g_dwListCount; nIndex++)
            {
                printf("find address:%08X\r\n", g_dwValueAddr[nIndex]);
            }
        }
        printf("Please input the value your want to find:\r\n");
        dwValue = 0;
        scanf("%d", &dwValue);
        WriteProcessMemory(g_hProcess, (LPVOID)g_dwValueAddr[0],&dwValue,sizeof(dwValue),nullptr);
    }


    //ReadProcessMemory()
    system("pause");
    return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小蚂蚁_CrkRes

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值