简体   繁体   English

控制台中的C ++签名扫描器

[英]C++ Signature Scanner in Console

I would like to start out by saying I am very new to C++. 首先,我想说我是C ++的新手。 I am trying to build a simple console application to modify a paint tool's functionality by just changing a single array of bytes. 我正在尝试构建一个简单的控制台应用程序,以通过仅更改单个字节数组来修改绘画工具的功能。

I have found the array of bytes which I need to change, and have tried to follow this tutorial, but it ended up being for dll injection which is not what I want to do http://guidedhacking.com/showthread.php?3981 我找到了需要更改的字节数组,并尝试按照本教程进行操作,但最终是为了进行dll注入,这不是我想要执行的操作http://guidedhacking.com/showthread.php?3981

If anyone could help me out in any way as to how I could go about doing a signature scan in a console application that would be greatly appreciated. 如果有人能以任何方式帮助我解决如何在控制台应用程序中进行签名扫描,将不胜感激。

Since that tutorial was made I've made an external pattern scanning video tutorial as well. 自从制作了该教程以来,我还制作了一个外部模式扫描视频教程。 It's not perfect I'm sad to say. 它并不是完美的,我伤心地说。 But to get you started here is the code I am currently using that hasn't failed me yet: 但是让您开始使用的是我目前正在使用的代码,但现在还没有失败:

An internal pattern scanning function: 内部模式扫描功能:

char* ScanIn(char* pattern, char* mask, char* begin, unsigned int size)
{
    unsigned int patternLength = strlen(mask);

    for (unsigned int i = 0; i < size - patternLength; i++)
    {
        bool found = true;
        for (unsigned int j = 0; j < patternLength; j++)
        {
            if (mask[j] != '?' && pattern[j] != *(begin + i + j))
            {
                found = false;
                break;
            }
        }
        if (found)
        {
            return (begin + i);
        }
    }
    return nullptr;
}

A wrapper for external pattern scanning: 用于外部模式扫描的包装器:

char* ScanEx(char* pattern, char* mask, char* begin, char* end, HANDLE* hProc)
{
    char* currentChunk = begin;
    char* match = nullptr;
    SIZE_T bytesRead;

    while (currentChunk < end)
    {
        MEMORY_BASIC_INFORMATION mbi;

        //return nullptr if VirtualQuery fails
        if (!VirtualQueryEx(hProc, currentChunk, &mbi, sizeof(mbi)))
        {
            return nullptr;
        }

        char* buffer = new char[mbi.RegionSize];

        if (mbi.State == MEM_COMMIT && mbi.Protect != PAGE_NOACCESS)
        {
            DWORD oldprotect;
            if (VirtualProtectEx(hProc, mbi.BaseAddress, mbi.RegionSize, PAGE_EXECUTE_READWRITE, &oldprotect))
            {
                ReadProcessMemory(hProc, mbi.BaseAddress, buffer, mbi.RegionSize, &bytesRead);
                VirtualProtectEx(hProc, mbi.BaseAddress, mbi.RegionSize, oldprotect, &oldprotect);

                char* internalAddress = ScanIn(pattern, mask, buffer, bytesRead);

                if (internalAddress != nullptr)
                {
                    //calculate from internal to external
                    uintptr_t offsetFromBuffer = internalAddress - buffer;
                    match = currentChunk + offsetFromBuffer;
                    delete[] buffer;
                    break;
                }
            }
        }

        currentChunk = currentChunk + mbi.RegionSize;
        delete[] buffer;
    }
    return match;
}

Then you would call it like: 然后,您将这样称呼它:

ScanEx("\x29\x7b\x00\x8b\xc7", "xx?xx", moduleBase, moduleEnd, &hProc);

The idea I came up with is to use ReadProcessMemory to copy one region of memory at a time out of the target process, into the local process, and then run our ScanIn() internal scanning function on that buffer. 我想到的想法是使用ReadProcessMemory一次将一个内存区域从目标进程中复制到本地进程中,然后在该缓冲区上运行我们的ScanIn()内部扫描功能。 As you move through the target memory, you check if the memory pages have the correct protection and state that confirm it's a valid memory region. 在目标内存中移动时,请检查内存页是否具有正确的保护并声明其是有效的内存区域。

The single biggest caveat here is: if your pattern bridges across two regions, this function won't find it. 这里最大的警告是:如果您的模式跨两个区域进行桥接,则此功能将找不到它。 But I haven't had any issue using it in the past 3 years. 但是在过去的三年中,我使用它没有任何问题。

I would read ReadProcessMemory , it is a nice way of reading data externally without a need of DLL injection. 我将阅读ReadProcessMemory ,这是一种无需DLL注入即可从外部读取数据的好方法。

No answer a signature scanning problem. 没有回答签名扫描问题。 I would read the memory of the target process in chunks, let's say 1024 bytes, and would run a pattern matching function on the chunks. 我将以块的形式读取目标进程的内存,比如说1024个字节,然后在块上运行模式匹配功能。

But this field is really not for a C++ beginner, unless you have worked with it before in other languages. 但是,除非您以前曾使用其他语言来使用过该字段,否则该字段实际上并不适合C ++初学者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM