0

我有一个带有 2 个标签的 C++ 程序。这些标签之间的代码在二进制文件中加密(使用 3rd 方实用程序),然后在运行时解密。解密代码如下所示:

    int a = 0xBAD, b = 0xC0DE;
    std::cin >> a >> b;
    int c = static_cast<int>(pow(a, pow(b, b))) % static_cast<int>(pow(a, b));
    switch (c)
    {
    case 0:
        std::cout << "c = " << 0 << std::endl;
        break;
    case 1:
        std::cout << "c = " << 1 << std::endl;
        break;
    case 2:
        std::cout << "c = " << 2 << std::endl;
        break;
    case 3:
        std::cout << "c = " << 3 << std::endl;
        break;
    default:
        std::cout << "c = " << c << std::endl;
    }
_end:

解密过程如下:我调用VirtualAlloc以分配具有 PAGE_EXECUTE_READWRITE 权限的新内存缓冲区。然后我将加密的部分复制到这个缓冲区并解密。之后我只是调用这个缓冲区。

__asm
{
    lea eax, begin
    lea edx, _begin
    mov dword ptr[eax], edx
    lea eax, end
    lea edx, _end
    mov dword ptr[eax], edx
}
LPVOID ptr = VirtualAlloc(NULL, end - begin, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
memcpy(ptr, begin, end - begin);    
//decryption here
((void(*)(void))ptr)();

问题在于std::cinstd::cout调用call与相对偏移量接近,这使得该偏移量在我尝试执行的新分配的内存块中绝对不正确。

问题是如何计算解密代码的正确偏移量并在那里使用它?

4

0 回答 0