private unsafe UOHooks(int pId, IntPtr sharedMemory, OnUOMessage handler) { ProcessId = pId; FileVersionInfo v = Process.GetProcessById(pId).MainModule.FileVersionInfo; Version = new Version(v.FileMajorPart, v.FileMinorPart, v.FileBuildPart, v.FilePrivatePart); dataIn = (byte *)sharedMemory.ToPointer(); dataOut = dataIn + BufferSize; msgIn = (int *)(dataOut + BufferSize); msgOut = msgIn + 4; uint[] packetTable = new uint[0x100]; fixed(uint *p = packetTable) memcpy(p, dataIn, packetTable.Length * sizeof(uint)); PacketTable = packetTable; sentIn = new IntPtr(msgIn[0]); handledIn = new IntPtr(msgIn[1]); sentOut = new IntPtr(msgIn[2]); handledOut = new IntPtr(msgIn[3]); new Thread(MessagePump) { IsBackground = true }.Start(handler); }
private unsafe void MessagePump(object handler) { OnUOMessage h = (OnUOMessage)handler; UOMessage msg; WaitForSingleObject(sentIn); do { msg = (UOMessage)msgIn[0]; msgIn[0] = h(msg, msgIn[1], msgIn[2], msgIn[3], dataIn); SignalObjectAndWait(handledIn, sentIn); } while (msg != UOMessage.Closing); }
public static unsafe UOHooks Start(string client, OnUOMessage handler, bool patchEncryption) { PROCESS_INFORMATION pi = CreateSuspendedProcess(client, null); try { int id = Process.GetCurrentProcess().Id; IntPtr mmf = InjectLibrary(pi.processId, "UOHooks.dll", "OnAttach", id, patchEncryption ? 1 : 0); const int FILE_MAP_WRITE = 0x0002; IntPtr sharedMemory = MapViewOfFile(mmf, FILE_MAP_WRITE, 0, 0, IntPtr.Zero); if (sharedMemory == IntPtr.Zero) { throw new Win32Exception("MapViewOfFile"); } return(new UOHooks(pi.processId, sharedMemory, handler)); } finally { ResumeThread(pi.hThread); } }
private unsafe UOHooks(int pId, IntPtr sharedMemory, OnUOMessage handler) { ProcessId = pId; FileVersionInfo v = Process.GetProcessById(pId).MainModule.FileVersionInfo; Version = new Version(v.FileMajorPart, v.FileMinorPart, v.FileBuildPart, v.FilePrivatePart); dataIn = (byte*)sharedMemory.ToPointer(); dataOut = dataIn + BufferSize; msgIn = (int*)(dataOut + BufferSize); msgOut = msgIn + 4; uint[] packetTable = new uint[0x100]; fixed (uint* p = packetTable) memcpy(p, dataIn, packetTable.Length * sizeof(uint)); PacketTable = packetTable; sentIn = new IntPtr(msgIn[0]); handledIn = new IntPtr(msgIn[1]); sentOut = new IntPtr(msgIn[2]); handledOut = new IntPtr(msgIn[3]); new Thread(MessagePump) { IsBackground = true }.Start(handler); }
public static unsafe UOHooks Start(string client, OnUOMessage handler, bool patchEncryption) { PROCESS_INFORMATION pi = CreateSuspendedProcess(client, null); try { int id = Process.GetCurrentProcess().Id; IntPtr mmf = InjectLibrary(pi.processId, "UOHooks.dll", "OnAttach", id, patchEncryption ? 1 : 0); const int FILE_MAP_WRITE = 0x0002; IntPtr sharedMemory = MapViewOfFile(mmf, FILE_MAP_WRITE, 0, 0, IntPtr.Zero); if (sharedMemory == IntPtr.Zero) throw new Win32Exception("MapViewOfFile"); return new UOHooks(pi.processId, sharedMemory, handler); } finally { ResumeThread(pi.hThread); } }