繁体   English   中英

如何在内存转储字节数组中找到转换为UTF8编码字符串的字符串?

[英]How do I find strings inside a memory dumped byte array converted to UTF8 encoded string?

我正在研究一种视频游戏作弊引擎,该引擎利用简单的内存操作来实现其目标。 我已经成功编写了一段代码,该代码将进程的内存转储到byte []中,并在这些数组上进行迭代以查找所需的字符串。 因此,搜索的代码片段为:

    public bool FindString(byte[] bytes, string pName, long offset)
    {
        string s = System.Text.Encoding.UTF8.GetString(bytes);
        var match = Regex.Match(s, "test");
        if (match.Success)
            return true;
        return false;
    }

然后,我打开32位版本的记事本(因为这是我的转储方法所要满足的条件),并在其中键入单词“ test”,并在调试模式下运行程序,以查看是否满足条件。 它不是。

经过进一步检查,我在其中一个迭代中检查了's'字符串的内容,因此为:

\0\0\0\0\0\0\0\0���\f\0\u0001����\u0001\0\0\0 \u0001�\0\0\0\0\0          \u0001�\0\0\0\0\0\0\0�\0\0\0\0\0\0\0�\0\0\0\0\0\u0010\0\0\0\0\0\0\0 \a�\0\0\0\0\0\0\0�\0\0\0\0\0\u000f\0\0\0\u0001\0\0\0\0\0\0\0\0\0\0\0�\u000f�\0\0\0\0\0�\u000f�\0\0\0\0\0\0�\0\0\0\0\0\0\0\0\0\0\0\0\u0010\0\0\0\0\0\0\0\0\0����\f\0\0\0\0\0\0\0�\0\0����\0\0\0\0\0\0\u0010\0\0\0\0\0\0 \0\0\0\0\0\0\0\u0001\0\0\0\0\0\0\0\u0010\0\0\0\0\0\0�\0\0\0\0\0\0\0�����\u007f\0\0\u0002\0�\u0002\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0�\u000f�\0\0\0\0\0�\u000f�\0\0\0\0\0\u001f\0\0\0\0\0\0\0��������\u0010\u0001�\0\0\0\0\0\u0010\u0001�\0\0\0\0\0\u0018\0�\0\0\0\0\0\u0018\0�\0\0\0\0\0\0\0\0\0\0\0\0\0�\u0002�\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\00\a�\0\0\0\0\00\a�\0\0\0\0\0�\u0002�\0\0\0\0\0�M�^\u000e\u000e_\u007f\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\u0001\0\0\0\0\0\0\u0010\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\u0001\0\0\0\u0001\0\0\0\0\0\0\0\0\0\0\0\b\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\u0001\0\0\0\b\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0`\a\0\0\0\0\0\0`\a\0\0\0\0\0\0\u0004\0\0\0\0\0\0\0\0�\u001f\0\0\0\0\0�\u001d\u0014)�\u007f\0\0����\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0�\a\0\u0002\0\0\0\0\0\0\0\0\0\0\0\0�\0\0\0\0\0\0\0\u0001\0\0\0\u0001\0\0\0\0\0\0\0\0\0\0\0P\u0001�\0\0\0\0\0\0\u0003�\0\0\0\0\0\u0010\u0003�\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0�

我继续检查此方法的每个传递参数是否存在's'变量,发现找不到这种格式的任何字符串。

我的问题很简单。 我找不到该字符串,这是在做什么错? 转储成功了,但是与我的解析方法有关的问题给我带来了麻烦。

UPDATE(转储内存的代码)

    void ScanProcess(Process process)
    {
        // getting minimum & maximum address
        var sys_info = new SYSTEM_INFO();
        GetSystemInfo(out sys_info);
        var proc_min_address = sys_info.minimumApplicationAddress;
        var proc_max_address = sys_info.maximumApplicationAddress;
        var proc_min_address_l = (long)proc_min_address;
        var proc_max_address_l = (long)proc_max_address;

        //Opening the process with desired access level
        var processHandle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_WM_READ, false, process.Id);
        var mem_basic_info = new MEMORY_BASIC_INFORMATION();
        var bytesRead = 0;  // number of bytes read with ReadProcessMemory

        while (proc_min_address_l < proc_max_address_l)
        {
            VirtualQueryEx(processHandle, proc_min_address, out mem_basic_info, 28); //28 = sizeof(MEMORY_BASIC_INFORMATION)

            //If this memory chunk is accessible
            if (mem_basic_info.Protect == PAGE_READWRITE && mem_basic_info.State == MEM_COMMIT)
            {
                //Read everything into a buffer
                byte[] buffer = new byte[mem_basic_info.RegionSize];
                ReadProcessMemory((int)processHandle, mem_basic_info.BaseAddress, buffer, mem_basic_info.RegionSize, ref bytesRead);

                var MemScanner = new MemScan();
                Memscanner.FindString(buffer, process.ProcessName, proc_max_address_l);
            }

            // move to the next memory chunk
            proc_min_address_l += mem_basic_info.RegionSize;
            proc_min_address = new IntPtr(proc_min_address_l);

            if (mem_basic_info.RegionSize == 0)
            {
                break;
                mem_basic_info.RegionSize = 4096;
            }
        }
    }

我不知道MemScan.FindString()作用,但是我想问题是您正在字符串中搜索字符串,而不是在字节数组中搜索字节数组。

通过使用System.Text.Encoding.UTF8.GetString(bytes);转换内存内容 您假定可以将存储在内存中的所有内容解释为有效的UTF8编码。

FindString()必须将参数接受为byte[]而不是string ,并且您需要弄清楚进程名称如何存储在内存中(很可能是UTF-16)。

non-binary capable viewing tool to look at your bytes). 对于初学者,您不能使用NotePad(或不具有二进制功能的查看工具来查看您的字节)。

您需要使用BitConverter API:

https://msdn.microsoft.com/zh-CN/library/system.bitconverter(v=vs.110).aspx

...遍历数据并撰写/搜索数据以查找所需内容(请记住要转储数据的任何编码)。

顺便说一句-这是一个有用的HexEditor: http : //www.hexworkshop.com/

暂无
暂无

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

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