Question

I have been write my c# wrapper for WFP (windows filtering platform ) , i use WinDivert 1.0.5 , this import syntax

[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);

and this function call syntax

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);
}

but the function return false with every call , and the GetLastWin32Error() get error code 998 . plz help me .

Was it helpful?

Solution

998 = ERROR_NOACCESS (Invalid access to memory location). This is likely caused by passing an invalid pointer to DivertRecv.

Is the pPacket parameter a pointer to a pre-allocated buffer of size packetLen?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top