问题描述
对于我的课程项目,我必须使用几个按钮和标签将代码注入一个简单的随机分配的应用程序。经过一番研究,我能够将应用程序识别为C ++ MFC应用程序(仍然不能100%确定)。
For my class project, I have to inject code into a simple randomly assigned app with a couple buttons and labels. After some research, I was able to identify the app as a C++ MFC app (still not 100% sure).
我被教过如何将C#dll注入到.Net应用程序中以获取和设置数据。但是,我不知道它是否适用于MFC应用程序。我可以在MFC应用程序中注入一个C#dll,甚至启动一个消息框。我不知道C ++能够很好地获取/设置数据。
I was taught how to inject a C# dll into a .Net app to get and set data. However, I don't know if its applicable for a MFC app. I was able to inject a C# dll into the MFC app and even launch a messagebox. I don't know C++ well enough to get/set data.
我可以使用C#获取/设置C ++ MFC应用程序中的数据,还是将C ++ dll注入MFC应用程序,并以某种方式使用它来获取/设置几个按钮&标签?
Can I get/set data within a C++ MFC app using C# or do I have inject C++ dll into the MFC app and somehow use it to get/set couple buttons & labels?
更新1:我意识到我的C ++假设可能不正确。请参阅此。
Update 1: I realize I may be incorrect on my C++ assumptions. Please refer to this link.
推荐答案
听起来像一个奇怪的类项目,但是可以使用pinvoke从c#使用winapi将自己的dll注入其他进程。
Sounds like a strange class project but yes you can injection your own dlls into other process's using winapi from c# using pinvoke.
您将用于dll注入的主要方法是OpenProcess,WriteProcessMemory,CreateRemoteThreadEx,VirtualAllocEx,GetProcAddress。
The main methods you would use to dll inject are OpenProcess, WriteProcessMemory, CreateRemoteThreadEx, VirtualAllocEx, GetProcAddress.
PInvoke他们如下:
PInvoke them like below:
[DllImport("kernel32.dll")]
public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
请参阅
请参阅
这篇关于代码注入从MFC应用程序设置和提取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!