Code Injection to set and extract data from MFC Application

走远了吗. 提交于 2019-12-12 01:51:54

问题


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

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.

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?


Update 1: I realize I may be incorrect on my C++ assumptions. Please refer to this link.


回答1:


Sounds like a strange class project but yes you can injection your own dlls into other process's using winapi from c# using pinvoke.

The main methods you would use to dll inject are OpenProcess, WriteProcessMemory, CreateRemoteThreadEx, VirtualAllocEx, GetProcAddress.

PInvoke them like below:

[DllImport("kernel32.dll")]
public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);

See How to inject a dll into a remote process c#

See How to inject a managed assembly DLL



来源:https://stackoverflow.com/questions/29660057/code-injection-to-set-and-extract-data-from-mfc-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!