basil00 / WinDivert

WinDivert: Windows Packet Divert
https://reqrypt.org/windivert.html
Other
2.46k stars 500 forks source link

consuming Windivert.dll #96

Closed winnieaj closed 7 years ago

winnieaj commented 7 years ago

My project design (1) THE WINDOWS SERVICE TALKS TO THE DLL (consumes the dll, use the dll, running in the background), the windows is installed by a setup installer, implemented in C#. (2)THE DLL TALKS TO THE DRIVER (3) THE DRIVER DOES THE FILTERING

I built divert in Visual Studio 2015, it gave me WinDivert.dll. I want to consume the dll in a windows service (C#).....I want to know how do i call this WinDivert.dll in the C# windows service, I DONT KNOW HOW TO...do i need to break the WinDivert.dll down ...and what function in DIVERT is available for windows service usage

TechnikEmpire commented 7 years ago

@winnieaj You can use all of WinDivert from a Windows service, I'm doing this myself. WinDivert is a native library so to use it from C#/.NET you need either a Pinvoke wrapper or a managed C++/CLI wrapper. I have written both but they are of course unofficial.

https://github.com/TechnikEmpire/Divert.Net

https://github.com/TechnikEmpire/DivertPInvoke

I'd recommend just going with the DivertPInvoke and use unsafe code. The Divert.Net project requires some setup described in the Wiki that is a bit of a pain. Also, by using the PInvoke version you're almost identical in code to the native examples, so you can follow example code much easier. Just use unsafe code, use topshelf and use Pinvoke version in your service and you'll see it works just fine. Don't forget you need the .sys as well.

basil00 commented 7 years ago

I don't know anything about C#, so please refer to @TechnikEmpire's answer.