你好,我的C#项目有这个问题 [英] Hello I have this problem in my C# project
本文介绍了你好,我的C#项目有这个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private void btnCallDriver_Click(object sender, RoutedEventArgs e)
{
System.Diagnostics.Process[] wordProcesses =
System.Diagnostics.Process.GetProcessesByName("notepad");
Int32 id = wordProcesses.Last().Id;
var Addres = 0xC304F5B620;
String buf = ("AAAAA");
Driver.WriteMemory(id, Addres, buf.Length, buf);
}
我在记事本内存中使用驱动程序写AAAAA,问题是我只得到A写在内存中。
我的IO控制。
I using a driver to Write "AAAAA" in notepad memory, the problem is i get only "A" write in memory.
My IO Control.
public static Native.NTSTATUS WriteMemory(int pid, Int64 addr, Int64 size, object buffer)
{
if (Driver.Handle == null || Driver.Handle.IsInvalid)
{
return Native.NTSTATUS.DeviceDoesNotExist;
}
var info = new COPY_MEM();
var pinned = GCHandle.Alloc(buffer, GCHandleType.Pinned);
info.pid = (uint)pid;
info.size = size;
info.write = 1;
info.localbuf = pinned.AddrOfPinnedObject().ToInt64();
info.targetPtr = addr;
int bytes = 0;
if (!Native.DeviceIoControl(Driver.Handle, ReadMemCtlCode, info, (uint)Marshal.SizeOf(info), null, 0, ref bytes, IntPtr.Zero))
{
return (Native.NTSTATUS)Marshal.GetLastWin32Error();
}
return Native.NTSTATUS.Success;
}
我的尝试:
我测试发送字节数组,并手动更改长度
What I have tried:
I test sending array of Bytes, and changing the length manually
推荐答案
我不知道任何高级细节而且不想;我只能从一开始就解释为什么这一切都是错的。查看你的函数WriteMemory
。谁告诉你字符串是长度System.String.Length
的对象?不,此对象是对某个对象的托管引用。 String是引用类型。不,它的大小不是长度,甚至不是长度* 2(因为这是UTF16,而不是单字节字符)。不,这是一个引用,或托管指针。也许引用的对象是包含AAAAA的内存区域?差远了。 String是一个非常复杂且自包含的对象。根据定义,它不能以字符串的内容开头。我甚至要解释原因吗?这里有一些提示:因为这不是灾难性的C类空终止字符串,是所有技术史上最具破坏性的发明之一。
现在,你正在尝试用硬编码的固定地址写一些东西0xC304F5B620
。你是认真的吗?
我认为提到的问题绰绰有余,不再考虑其余部分了。
并且,无论如何,将某些内容写入另一个进程(如记事本),即一个单独的进程,只有一个名称:滥用。
-SA
I don't know any advanced detail and don't want to; I only can explain why it's all wrong, from the very beginning. Look at your functionWriteMemory
. Who told you that string is an object with lengthSystem.String.Length
? No, this object is a managed reference to some object. String is a reference type. No, it's size not length and not even length * 2 (because this is UTF16, not single-byte character). No, this is a reference, or managed pointer. Maybe the referenced object is the memory area containing "AAAAA"? Not even close. String is a pretty complicated and self-containing object. It cannot start with the content of string, by definition. Do I even have to explain why? Here is some hint: because this is not disastrous C-like null-terminated string, one of the most destructive inventions in all the history of technology.
Now, you are trying to write something by hard-coded fixed address0xC304F5B620
. Are you serious?
I think mentioned problems are more than enough to stop considering the rest.
And, anyway, writing something into another process such as notepad, that is, a separate process, has only one name: abuse.
—SA
private void btnCallDriver_Click(object sender,RoutedEventArgs e)
{
const string input =AAAAA;
byte [] array = Encoding.ASCII.GetBytes(输入);
System.Diagnostics.Process [] wordProcesses =
System.Diagnostics.Process.GetProcessesByName(notepad);
Int32 id = wordProcesses.Last()。Id;
var Addres = 0x1A2DA5F4CD8;
var buf = array;
;
Driver.WriteMemory(id,Addres,buf.Length,buf);
}
private void btnCallDriver_Click(object sender, RoutedEventArgs e)
{
const string input = "AAAAA";
byte[] array = Encoding.ASCII.GetBytes(input);
System.Diagnostics.Process[] wordProcesses =
System.Diagnostics.Process.GetProcessesByName("notepad");
Int32 id = wordProcesses.Last().Id;
var Addres = 0x1A2DA5F4CD8;
var buf = array;
;
Driver.WriteMemory(id, Addres, buf.Length, buf);
}
这篇关于你好,我的C#项目有这个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文