WinDivert 1.0.5 DivertRecv() 方法 获取最后一个错误 998

本文关键字:获取 方法 最后一个 错误 DivertRecv WinDivert | 更新日期: 2023-09-27 18:34:25

我一直在为WFP(Windows过滤平台)编写我的c#包装器,我使用WinDivert 1.0.5,此导入语法

[DllImportAttribute("WinDivert.dll", EntryPoint = "DivertRecv",SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
            [return: MarshalAsAttribute(UnmanagedType.Bool)]
            public static extern bool DivertRecv([InAttribute()] System.IntPtr handle,
                                                  [OutAttribute()]  System.IntPtr pPacket, 
                                                  [InAttribute()]  uint packetLen,
                                      [ OutAttribute()]  System.IntPtr pAddr,
                                      [OutAttribute()]  System.IntPtr readLen);

和这个函数调用语法

if( DivertRecv(handle, Ppacket, (uint)(8 * packet.Length-1),
                 Paddr,  Ppacket_len) == false)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("warning: failed to read packet {0} .", Marshal.GetLastWin32Error());
                    Console.ResetColor();
                    Console.WriteLine(" Press any key to Exit ...");
                    Console.ReadKey();
                    Environment.Exit(1);
}

但是该函数每次调用都返回 false,并且 GetLastWin32Error() 得到错误代码 998 .请帮助我。

WinDivert 1.0.5 DivertRecv() 方法 获取最后一个错误 998

998 = ERROR_NOACCESS(对内存位置的无效访问)。 这可能是由于将无效指针传递给 DivertRecv 导致的。

pPacket 参数是否指向大小为 packetLen 的预分配缓冲区的指针?