如何访问或授予进程从另一个进程读取受保护的内存的权限 [英] How to access or give permission to a process to read protected memory form another process

查看:96
本文介绍了如何访问或授予进程从另一个进程读取受保护的内存的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我正在使用visual studio c#构建一个应用程序来处理设备。

在某些时候我将设备句柄放在一个intptr变量中。



然后我有另一个需要使用相同句柄的进程。

我传递此信息的方式是在主应用程序中执行此操作:



IntPtr h =; //返回设备句柄的函数

ProcessStartInfo p = new ProcessStartInfo(otherapp.exe ,h.ToString());

Process.Start(p);



在另一个应用程序中我捕获字符串参数然后这样做:



IntPtr h = new IntPtr(Int32.Parse(args [0]));



到目前为止一切正常但当我尝试在第二个应用程序中使用新句柄时会抛出一个错误:

试图访问受保护的内存



有人可以帮我吗????



我尝试了什么:



我的方式通过在主应用程序中执行此操作来获取此信息:

IntPtr h =; //返回设备句柄的函数
ProcessStartInfo p = new ProcessStartInfo(otherapp.exe ,h.ToString());
Process.Start(p);

,在另一个应用程序中我捕获字符串参数然后执行此操作:

IntPtr h = new IntPtr(Int32.Parse(args [0]));

到目前为止一切正常但是当我尝试在第二个应用程序中使用新句柄时会抛出一个错误:
尝试访问受保护的内存

解决方案

不是很优雅,但你可以使用 unsafe 关键字。

这是一个解释:如何:使用指针复制字节数组(C#编程指南) [ ^ ]


< blockquote>我认为你是以错误的方式解决这个问题。而不是让两个不同的应用程序试图访问相同的句柄,这是通过安全方式阻止的,你只需要一个。



创建一个处理所有访问的应用程序到有问题的设备并执行所有关键功能。然后,您不会将句柄传递给其他应用程序。您的其他应用程序cal告诉此应用程序如何处理它具有的设备/句柄。进程间通信(比如命名管道)比使用安全性试图让它工作更容易。


hello
i'm building an application in visual studio c# to work with a device.
at some point i have my device handle in an intptr variable.

then i have another process that needs to use the same handle.
the way i passed this information was by doing this in the primary app:

IntPtr h = ;//"the function that returns the device handle"
ProcessStartInfo p = new ProcessStartInfo("otherapp.exe", h.ToString());
Process.Start(p);

and in the other app i catch the string parameter and then do this:

IntPtr h = new IntPtr(Int32.Parse(args[0]));

so far everything works but when i try to use the new handle in the second app it throws an error:
trying to access protected memory

can someone help me please????

What I have tried:

the way i passed this information was by doing this in the primary app:

IntPtr h = ;//"the function that returns the device handle"
ProcessStartInfo p = new ProcessStartInfo("otherapp.exe", h.ToString());
Process.Start(p);

and in the other app i catch the string parameter and then do this:

IntPtr h = new IntPtr(Int32.Parse(args[0]));

so far everything works but when i try to use the new handle in the second app it throws an error:
trying to access protected memory

解决方案

Not very elegant, but you could use the unsafe keyword.
Here is an explanation: How to: Use Pointers to Copy an Array of Bytes (C# Programming Guide)[^]


I think you're going about this the wrong way. Instead of having two different applications trying to access the same handle, which is prevented by security by the way, you only need one.

Create an application that handles all access to the device in question and performs all critical functions. Then you don't pass a handle around to other applications. You other applications cal tell this application what to do with the device/handle it has. interprocess communication (like named pipes) is quite a bit easier than screwing around with security trying to get this to work.


这篇关于如何访问或授予进程从另一个进程读取受保护的内存的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆