c#基本的内存读取

本文关键字:内存 读取 | 更新日期: 2023-09-27 18:15:21

我放弃了字符串,我不知道我没有得到任何值,但现在还好。

我想读取一个简单的4字节整型值。我在内存中查找精确值42,我取了第一个地址。

我已经知道数组的大小必须是4。但是我得到了非常疯狂的值。

像-12732139

所以我写了一个for循环告诉我存储在字节数组

中的值
for (int j = 0; j < bytes.Length; ++j ) {
                 svalue += "+" + bytes[j];
           }

我从中得到非常奇怪的数字

216 184 93 255 // these are stored inside the bytearray which should be 42 dec.

i guess something really wrong ?

读取这些值
ReadProcessMemory(readHandle, ((IntPtr)baseAddress + 0x000D3A10), bytes, (UIntPtr)4, ref rw);

int test = BitConverter.ToInt32(new_bytes,0);

有什么想法吗?

//老了我的完整代码:

private void button1_Click(object sender, EventArgs e) {
    Process[] iexp = Process.GetProcessesByName("iexplore");
    if (iexp.Length == 0) {
        listBox1.Items.Add("NOT FOUND");
    }
    Process internet = iexp[0];
    uint baseAddress = (uint)internet.MainModule.BaseAddress.ToInt32();
    IntPtr readHandle = OpenProcess(0x0010, false, (uint)internet.Id);
    byte[] bytes = new byte[24];
    uint rw = 0;
    uint size=sizeof(int);
    ReadProcessMemory(readHandle, ((IntPtr)baseAddress + 0x00581CCE), bytes, 
        (UIntPtr)24, ref rw);
    string sname= Encoding.ASCII.GetString(bytes);
    ReadProcessMemory(readHandle, (IntPtr)baseAddress + 0x00528744, bytes, 
        (UIntPtr)size, ref rw);
    int someNumber = BitConverter.ToInt32(bytes, 0);
    listBox1.Items.Add(sname);
    listBox1.Items.Add(someNumber);
}

c#基本的内存读取

您应该能够通过自动连接到正在运行的Internet Explorer实例。

你必须使用COM互操作,但是上面的解决方案将允许你在当前桌面会话中访问任何正在运行的Internet Explorer实例,并且从那里你可以访问完整的窗口/文档对象模型。

这个函数只是读取普通内存。它没有类型的概念,因此不知道字符串是什么,甚至不知道它们有长度。如果你进入进程内存去读东西,你就只能靠自己了。你需要确切地知道你想读什么,以及如何处理这些数据。

虽然当你试图读取字符串时:你可以尝试在循环中读取字节,并在遇到0字节时停止,这是C用来表示字符串(NULL终止字符串)的结束