SendHook.cs 857 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using Log;
  4. using EasyHook;
  5. namespace Hooks
  6. {
  7. [UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
  8. public delegate int DSend(IntPtr handle, IntPtr buf, int count, int flag);
  9. public class SendHook : IDisposable
  10. {
  11. [DllImport("Ws2_32.dll", EntryPoint = "send")]
  12. public static extern int Send(IntPtr handle, IntPtr buf, int count, int flag);
  13. private readonly LocalHook localHook;
  14. public SendHook(DSend dSend)
  15. {
  16. try
  17. {
  18. localHook = LocalHook.Create(LocalHook.GetProcAddress("Ws2_32.dll", "send"), new DSend(dSend), this);
  19. localHook.ThreadACL.SetInclusiveACL(new[] {0});
  20. }
  21. catch (Exception)
  22. {
  23. Logger.Debug("Error creating send Hook");
  24. throw;
  25. }
  26. }
  27. public void Dispose()
  28. {
  29. localHook.Dispose();
  30. }
  31. }
  32. }