利用特征码快速定位某段地址

首先定义一个数据结构,方便我们调用某个子程序要查询的地址。

typedef struct SearchInfo
{
    DWORD PlugAddress;            //返回特征码地址
    DWORD GetAddress;
    SearchInfo *GetGameaddress(DWORD dwdwAdd, DWORD dwLen);
    DWORD GetPlugInfo();
} _SearchInfo;
BOOL bCompare(const BYTE* pData, const BYTE* bMask, const char* szMask)
{
    for (; *szMask; ++szMask, ++pData, ++bMask)
        if (*szMask == 'x' && *pData != *bMask)
            return 0;
    return (*szMask) == NULL;
}

DWORD FindPattern(DWORD dwdwAdd, DWORD dwLen, BYTE *bMask, char * szMask)
{
    for (DWORD i = 0; i<dwLen; i++)
        if (bCompare((BYTE*)(dwdwAdd + i), bMask, szMask))
            return (DWORD)(dwdwAdd + i);
    return 0;
}

SearchInfo*SearchInfo::GetGameaddress(DWORD dwdwAdd, DWORD dwLen){
    PlugAddress = FindPattern(dwdwAdd, dwLen, (PBYTE)"\x8B\x00\x8A\x40\x08\x84\xC0", "xxxxxxx"); // 取特征地址
    TRACE("特征码地址: %x \n", PlugAddress);
    return this;
}

DWORD SearchInfo::GetPlugInfo(){
    PlugAddress = PlugAddress - 0x7;
    return this->PlugAddress;
}

 

posted @ 2015-05-04 03:42  ゅ如影相随  阅读(1003)  评论(0)    收藏  举报