using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;

class Program {

	[DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
	static extern IntPtr GetProcAddress(IntPtr hModule, string procName);

	[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Ansi)]
	static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)]string lpFileName);

	static void Main(string[] args) {
		//Read Data from file
		var data = File.ReadAllBytes(@"app.bin");
		//Patch end bytes with messagebox
		var msg = GetProcAddress(LoadLibrary("user32"), "MessageBoxA");
		var mdx = BitConverter.GetBytes((int)msg);
		mdx.CopyTo(data, data.Length - 4);
		var proc = Process.GetProcessesByName("notepad++")[0];
		//Allocate data pointer
		var ptr = proc.Alloc(data.Length);
		//Write data to pointer
		proc.Write(ptr, data);
		//Call function
		proc.Call(ptr, IntPtr.Zero);
		//Free Data
		proc.Free(ptr);

	}
}