Code Injection to set and extract data from MFC Ap

2019-08-29 06:48发布

问题:

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