Example #1
0
        /// <summary>
        /// 将值写入指定内存地址中
        /// </summary>
        /// <param name="baseAddress">内存地址</param>
        /// <param name="PId">进程Id</param>
        /// <param name="value">要写入的值</param>
        public static void WriteMemoryValue(int baseAddress, int PId, int value)
        {
            IntPtr hProcess = Kernel32Api.OpenProcess(0x1F0FFF, false, PId); //0x1F0FFF 最高权限

            Kernel32Api.WriteProcessMemory(hProcess, (IntPtr)baseAddress, new int[] { value }, 4, IntPtr.Zero);
            Kernel32Api.CloseHandle(hProcess);
        }
Example #2
0
 //读取内存中的值
 /// <summary>
 /// 读取内存中的值
 /// </summary>
 /// <param name="baseAddress">内存地址</param>
 /// <param name="processName">进程名</param>
 /// <returns>值</returns>
 public static int ReadMemoryValue(int baseAddress, string processName)
 {
     try
     {
         byte[] buffer      = new byte[4];
         IntPtr byteAddress = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0);                    //获取缓冲区地址
         IntPtr hProcess    = Kernel32Api.OpenProcess(0x1F0FFF, false, GetPidByProcessName(processName));
         Kernel32Api.ReadProcessMemory(hProcess, (IntPtr)baseAddress, byteAddress, 4, IntPtr.Zero); //将制定内存中的值读入缓冲区
         Kernel32Api.CloseHandle(hProcess);
         return(Marshal.ReadInt32(byteAddress));
     }
     catch
     {
         return(0);
     }
 }
Example #3
0
        /// <summary>
        /// 关闭进程
        /// </summary>
        /// <param name="ProcessId"></param>
        public static void CloseProcess(IntPtr ProcessId, int exitCode = 0)
        {
            IntPtr ip = Kernel32Api.OpenProcess(1, false, ProcessId.ToInt32());

            Kernel32Api.TerminateProcess(ip, exitCode);
        }