public static bool ExcuteRemoteFunction(int processId, IntPtr lpFuncAddress, byte[] param) { var hndProc = ProcessAPI.OpenProcess( ProcessAPI.ProcessAccessFlags.CreateThread | ProcessAPI.ProcessAccessFlags.VirtualMemoryOperation | ProcessAPI.ProcessAccessFlags.VirtualMemoryRead | ProcessAPI.ProcessAccessFlags.VirtualMemoryWrite | ProcessAPI.ProcessAccessFlags.QueryInformation , true, processId); if (hndProc == IntPtr.Zero) { return(false); } var lpAddress = MemoryAPI.VirtualAllocEx(hndProc, (IntPtr)null, (IntPtr)param.Length, (0x1000 | 0x2000), 0X40); if (lpAddress == IntPtr.Zero) { ProcessAPI.CloseHandle(hndProc); return(false); } if (MemoryAPI.WriteProcessMemory(hndProc, lpAddress, param, (uint)param.Length, 0) == 0) { ProcessAPI.CloseHandle(hndProc); return(false); } if (ProcessAPI.CreateRemoteThread(hndProc, (IntPtr)null, IntPtr.Zero, lpFuncAddress, lpAddress, 0, (IntPtr)null) == IntPtr.Zero) { ProcessAPI.CloseHandle(hndProc); return(false); } return(true); }
/// <summary> /// 执行远程进程上的函数 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="hndProc">进程句柄</param> /// <param name="moduleName">模块名称</param> /// <param name="lpFuncAddress">远程函数地址</param> /// <param name="lpParamAddress">远程参数地址</param> /// <param name="param"></param> /// <returns></returns> public static bool ExcuteRemoteFunction(IntPtr hndProc, IntPtr lpFuncAddress, IntPtr lpParamAddress) { if (hndProc == IntPtr.Zero) { return(false); } if (lpFuncAddress == IntPtr.Zero) { return(false); } return(ProcessAPI.CreateRemoteThread(hndProc, (IntPtr)null, IntPtr.Zero, lpFuncAddress, lpParamAddress, 0, (IntPtr)null) != IntPtr.Zero); }