0

我正在尝试创建一个对 licenseCheck 函数具有篡改保护的基本程序,但它总是说它是正确的,即使我在 Ollydbg 中 nop 整个 licenseCheck 函数或更改并重建代码。

我正在关注《秘密软件》一书,并编写了以下程序:

#include "stdafx.h"

#define HASH 5131241 

void BEGIN() {}

const std::string correctlicense("ABC");

bool licenseCheck() {

    std::cout << "Enter license: ";

    std::string license;
    std::cin >> license;

    volatile DWORD d;

    // Fingerprint
    __asm {
        lea ebx, d
        mov ebx, 0x050b072b
    }

    return license.compare(correctlicense) == 0;
}

UINT hash(UINT *beginAddress, UINT *endAddress) {

    UINT h = *beginAddress;

    for (; beginAddress <= endAddress; beginAddress++) {
        h ^= *beginAddress;
    }

    return h;
}
void END() {}


int main()
{

    UINT uHash = hash((UINT*)BEGIN, (UINT*)END);

    std::cout << "[Protection checks]" << std::endl;
    std::cout << "Tampering: ";

    if (uHash != HASH) {
        std::cout << "Tampering detected! ( " << uHash << " )" << std::endl;
        system("PAUSE");
        return 0;
    }
    else {
        std::cout << "Correct" << std::endl;
    }

    if (licenseCheck()) {
        std::cout << "Correct!" << std::endl;
    }
    else {
        std::cout << "Failed!" << std::endl;
    }


    system("PAUSE");
    return 0;
}

该程序基本上“散列”了 BEGIN 函数和 END 函数之间的代码,但它似乎不起作用。即使在篡改之后,哈希值也始终是正确的。

我正在使用 Windows 7 和 Visual Studio 2017 构建/运行程序。

4

0 回答 0