예제 #1
0
        private unsafe IntPtr GetHookProc(int code, IntPtr wparam, ref CWPSTRUCT cwp)
        {
            if (CurrentProcess == 0)
            {
                CurrentProcess = GetCurrentProcess();
                int    hdwd = findwin(_windowName);
                IntPtr PID  = (IntPtr)pid(hdwd);
                PID  = (IntPtr)OpenProcess(PROCESS_ALL_ACCESS, false, (int)PID);
                hdwd = (int)PID;
                // if (hdwd == CurrentProcess || PID ==(IntPtr) CurrentProcess)
                //{
                MEMORY_BASIC_INFORMATION mbi = new MEMORY_BASIC_INFORMATION();
                IntPtr dwOldProtect          = IntPtr.Zero;
                pfnMsgBox = GetProcAddress(LoadLibrary("ws2_32.dll"), "send");
                VirtualQuery(pfnMsgBox, out mbi, 255);
                VirtualProtect(pfnMsgBox, 8, PAGE_READWRITE, dwOldProtect);



                ReadProcessMemory(PID, pfnMsgBox, add_old, sizeof(uint) * 2, IntPtr.Zero);
                GetSend mb      = new GetSend(MySend);
                IntPtr  new_add = Marshal.GetFunctionPointerForDelegate(mb);
                byte[]  b       = BitConverter.GetBytes((int)new_add);
                addr_new[1] = b[0];
                addr_new[2] = b[1];
                addr_new[3] = b[2];
                addr_new[4] = b[3];
                WriteProcessMemory(PID, pfnMsgBox, addr_new, sizeof(uint) * 2, IntPtr.Zero);
                // VirtualProtect(pfnMsgBox, 8, mbi.Protect, IntPtr.Zero);
                VirtualProtect(pfnMsgBox, 8, PAGE_READWRITE, dwOldProtect);
            }
            //当调用这个函数的时候就跳到我的函数上面了
            //  }
            return(CallNextHookEx(_nextHookPtr, code, wparam, cwp));

            // return (IntPtr)0;
        }
예제 #2
0
 static extern int WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, GetSend gs, UInt32 nSize, IntPtr lpNumberOfBytesWritten);