Exemple #1
0
        private int CheckTouring(ref Message m, ref Copydatastruct ptr)
        {
            var id = m.WParam.ToInt32();

            if (id > 0x7FFFF && idx++ % 2 == 0)
            {
                if (ptr.DwData == 2)
                {
                    if (Collections.AttachedClients.ContainsKey(previd))
                    {
                        Collections.AttachedClients[previd].SendPointer = id;
                    }
                }
                if (ptr.DwData != 1)
                {
                    return(id);
                }
                if (Collections.AttachedClients.ContainsKey(previd))
                {
                    Collections.AttachedClients[previd].RecvPointer = id;
                }
            }
            else
            {
                previd = id;
            }
            return(id);
        }
Exemple #2
0
        private int CheckTouring(ref Message m, ref Copydatastruct ptr)
        {
            var id = m.WParam.ToInt32();

            if (id > 0x7FFFF && idx++ % 2 == 0)
            {
                if (ptr.DwData == 2)
                {
                    if (DarkagesProcess.ProcessMonitor.Processes.ContainsKey(previd))
                    {
                        DarkagesProcess.ProcessMonitor.Processes[previd].SendPointer = id;
                    }
                }
                if (ptr.DwData != 1)
                {
                    return(id);
                }
                if (DarkagesProcess.ProcessMonitor.Processes.ContainsKey(previd))
                {
                    DarkagesProcess.ProcessMonitor.Processes[previd].RecvPointer = id;
                }
            }
            else
            {
                previd = id;
            }
            return(id);
        }
Exemple #3
0
        private static void Intercept(Copydatastruct ptr, Packet packet, int id)
        {
            if (packet.Data.Length <= 0 || packet.Data.Length != ptr.CbData)
            {
                return;
            }

            var c = Collections.AttachedClients[id];

            if (c.ServerPacketHandler == null)
            {
                return;
            }
            if (c.ClientPacketHandler == null)
            {
                return;
            }

            if (packet.Type == 2)
            {
                Console.WriteLine($"Client->Server: {packet.ToString()}");
                c.ClientPacketHandler[packet.Data[0]]?.Invoke(id, packet);
            }
            else if (packet.Type == 1)
            {
                Console.WriteLine($"Server->Client: {packet.ToString()}");
                c.ServerPacketHandler[packet.Data[0]]?.Invoke(id, packet);
            }
            else if (packet.Type == 3)
            {
            }
        }
Exemple #4
0
        public static void SendDataMessage(Process targetProcess, string msg)
        {
            var stringMessageBuffer = Marshal.StringToHGlobalUni(msg);

            var copyData = new Copydatastruct
            {
                dwData = IntPtr.Zero,
                lpData = stringMessageBuffer,
                cbData = msg.Length * 2
            };
            var copyDataBuff = IntPtrAlloc(copyData);

            SendMessage(targetProcess.MainWindowHandle, WmCopydata, IntPtr.Zero, copyDataBuff);

            Marshal.FreeHGlobal(copyDataBuff);
            Marshal.FreeHGlobal(stringMessageBuffer);
        }
Exemple #5
0
        private static void Intercept(Copydatastruct ptr, Packet packet, int id)
        {
            if (packet.Data.Length <= 0 || packet.Data.Length != ptr.CbData)
            {
                return;
            }

            var c = DarkagesProcess.ProcessMonitor.Processes[id];

            if (packet.Type == 2)
            {
                Console.WriteLine($"Client->Server: {packet.ToString()}");
                //c.ClientPacketHandler[packet.Data[0]]?.Invoke(id, packet);
            }
            else if (packet.Type == 1)
            {
                Console.WriteLine($"Server->Client: {packet.ToString()}");
                //c.ServerPacketHandler[packet.Data[0]]?.Invoke(id, packet);
            }
            else if (packet.Type == 3)
            {
            }
        }
 static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, ref Copydatastruct lParam);
    /// <summary>
    /// Send a close request to the main window.
    /// </summary>
    public bool Close()
    {
      var hWindow = ConnectedWindow;
      if( IntPtr.Zero == hWindow )
      {
        return false;
      }

      var myStruct = new MyStruct
      {
        uMsg = WmClose,
        wParam = 0,
        lParam = 0
      };

      var myStructSize = Marshal.SizeOf(myStruct);
      var pMyStruct = Marshal.AllocHGlobal(myStructSize);

      try
      {
        Marshal.StructureToPtr(myStruct, pMyStruct, true);

        var cds = new Copydatastruct
        {
          dwData = (IntPtr)MessageType.Send, //  send message
          cbData = myStructSize,
          lpData = pMyStruct
        };

        // cast to IntPtr because we know it is not null.
        SendMessage( hWindow, WmCopyData, IntPtr.Zero, ref cds);
      }
      finally
      {
        Marshal.FreeHGlobal(pMyStruct);
      }
      // success
      return true;
    }
    /// <summary>
    /// Send a message as a reconstructed string.
    /// </summary>
    /// <param name="msg">The IpcData we want to send.</param>
    /// <returns>The IpcData response data</returns>
    public IpcData Send( IpcData msg )
    {
      // look for the listener.
      var hWindow = ConnectedWindow;
      if (IntPtr.Zero == hWindow)
      {
        return null;
      }

      // the message we want to send.
      var cds = new Copydatastruct
      {
        dwData = (IntPtr)MessageType.Copy, //  copy message...
        cbData = msg.GetSize(),
        lpData = msg.GetPtr()
      };

      // open the shared memory that should have been created.
      using (var mmf = MemoryMappedFile.CreateNew( msg.Guid, 10000))
      {
        // cast to IntPtr because we know it is not null.
        if (0 == (int) SendMessage( hWindow, WmCopyData, IntPtr.Zero, ref cds))
        {
          return null;
        }

        // open the shared memory that should have been created.
        using (var mmfvs = mmf.CreateViewStream())
        {
          using (var reader = new BinaryReader(mmfvs))
          {
            // read the first 4 bytes for the size.
            var dataSize = BitConverter.ToInt32( reader.ReadBytes( sizeof(int)), 0 );

            // all the byes 
            var bytes = reader.ReadBytes( dataSize );

            // parse the response data into an IpcData
            return new IpcData( bytes );
          }
        }
      }
    }