SendHook.cs 882 B

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