读取内存指针冻结进程

时间:2014-11-29 15:19:10

标签: c++ pointers integer compare

我试图在游戏过程中读取一些地址,然后用整数进行比较。

我的代码如下:

BOOL SCMemoryCheat::CheckDKHack()
{
        int *DkAddr1 = (int*)0x87016C + 0x11E4; // Pointer DK 1
        memcpy(DKBytesValues1, DkAddr1, 16);

        int *DkAddr2 = (int*)0x87016C + 0x1224; // Pointer DK 2
        memcpy(DKBytesValues2, DkAddr2, 16);

        if (   DKBytesValues1[0] == DKBytesValues1[1]
            && DKBytesValues1[1] == DKBytesValues1[2]
            && DKBytesValues1[2] == DKBytesValues1[3]
            && DKBytesValues1[3] == DKBytesValues1[4]
            && DKBytesValues1[4] == DKBytesValues1[5]
            && DKBytesValues1[0] == 0x00)
        {
            // DK Detected
            return TRUE;
        }

}

bool StartSCMemoryCheats()
{
    SCMemoryCheat* SCMemC = new SCMemoryCheat;

    while (TRUE)
    {
        int *ChannelIDAddr = (int*)0x8915AF;
        int *p = (int*)255;

        if (ChannelIDAddr == p)
        {
          if (SCMemC->CheckDKHack)
          {
            delete[] SCMemC;
            break;
          }
        }

        ExitProcess(0);
    }



}

和班级:

class SCMemoryCheat
{
    unsigned char *DKBytesValues1 = new unsigned char[16];
    unsigned char *DKBytesValues2 = new unsigned char[16];

    unsigned char *XFS = new unsigned char[4];

    public:
        SCMemoryCheat();
        virtual ~SCMemoryCheat();
        BOOL CheckDKHack();
};
使用线程调用

bool StartSCMemoryCheats(),这样:

DWORD dwSMCThreadId = 0;
    CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&StartSCMemoryCheats,(LPVOID) NULL, 0, &dwSMCThreadId);

它编译,但不起作用,并且该过程在CPU使用的+/- 30%时被冻结。

我怎么能做这个比较?

修改

固定一些东西

但现在这个条件总是返回TRUE,值为IS 255。

    **volatile int *ChannelIDAddr = (int*)0x8915AF;

    // Check world list
    if (*ChannelIDAddr != 255)
    {
       // ALWAYS TRUE
     }**

提前致谢。

1 个答案:

答案 0 :(得分:2)

我想这就是你想要的:

while (TRUE)
{
    volatile int *ChannelIDAddr = (int*)0x8915AF;
    const int p = 255;

    if (*ChannelIDAddr == p)
    {
      if (SCMemC->CheckDKHack())
      {
        delete[] SCMemC;
        break;
      }
    }

    ExitProcess(0);
}

如果要与整数255进行比较,则应将p声明为int,而不是指针。您需要通过ChannelIDAddr使用*前缀间接读取值。并且应该声明volatile,以便编译器不会优化对同一指针的重复读取。

最后,由于CheckDKHack是一个函数,因此您可以在其后面添加()来调用它。