Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#基本内存读取_C#_Memory - Fatal编程技术网

c#基本内存读取

c#基本内存读取,c#,memory,C#,Memory,好吧,我放弃了字符串,我不知道我没有得到任何值,但现在还可以 我想读取一个简单的4字节int值。我在内存中搜索了一个精确的值42,我得到了第一个地址 我已经知道数组大小必须是4。但我得到了真正疯狂的价值观 类似-12732139 所以我写了一个for循环,它告诉我存储在字节数组中的值 for (int j = 0; j < bytes.Length; ++j ) { svalue += "+" + bytes[j]; } 我想一定是

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

我想读取一个简单的4字节int值。我在内存中搜索了一个精确的值42,我得到了第一个地址

我已经知道数组大小必须是4。但我得到了真正疯狂的价值观

类似-12732139

所以我写了一个for循环,它告诉我存储在字节数组中的值

for (int j = 0; j < bytes.Length; ++j ) {
                 svalue += "+" + bytes[j];
           }
我想一定是出了什么事

我阅读这些价值观的时候

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);

}
你应该能够


您必须使用,但上述解决方案将允许您在当前桌面会话中访问Internet Explorer的任何运行实例,并从中访问完整的窗口/文档对象模型。

此功能仅用于读取普通内存。它没有类型的概念,因此不知道字符串是什么,甚至不知道它们有长度。如果你把手伸进一个过程的记忆中去读东西,你就只能靠自己了。您需要确切地知道您想要读取什么以及如何利用这些数据


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

所以我必须读取类似的内容@MaikKlein:不一定,虽然这会有帮助,但是的,网络上有很多COM互操作资源。我发布的链接是一个很好的开始。我想我不是第一个想从记忆中阅读的人。你知道有没有用c#从程序中读取基本信息的例子吗?这将给我一个更好的概述,我应该看什么。这对我来说很困惑。或者,如果不是太多的工作,你能给我一个如何做的例子吗?不需要太多。只够了解整个情况concept@MaikKlein:读取其他程序的内存空间通常是一件坏事,无法保证您正在读取的地址是稳定的,而且代码非常非常脆弱。通常,您应该查找应用程序提供的API并使用这些API。这很有意义!好的,我现在试试这个。但是我有点困惑。我还需要com吗?@MaikKlein:casperOne的解决方案是访问IE运行实例的另一种方式。因此,您可以尝试按照问题中的指示直接读取进程内存,也可以尝试caspers的建议,使用com interop以这种方式访问IE并获取所需数据。您有什么建议吗怎么办?坚持我的方法还是切换到互操作?它们的限制是否与互操作方法有关?顺便说一句,感谢您的患者:)@MaikKlein记忆读取功能更强大,但也更麻烦,更不可靠。互操作API更稳定,但可能无法提供所需的信息。不知道你想做什么很难说。
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);

}