TechnikEmpire / DivertPInvoke

PInvoke wrapper for WinDivert
GNU Lesser General Public License v3.0
25 stars 12 forks source link

error 126 #3

Closed Fiqow closed 7 years ago

Fiqow commented 7 years ago
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DivertSharp;
using PacketDotNet;
using System.Runtime.InteropServices;
using System.Net;

namespace firwall
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();

            try
            {
                // var dev = Diversion.WinDivertOpen("true", WinDivertLayer.Network, 100, 0);
                var dev = WinDivertMethods.WinDivertOpen("True", WINDIVERT_LAYER.WINDIVERT_LAYER_NETWORK, 100, 0);
                if (dev != null)
                {
                    TCPHeader tcp = new TCPHeader();
                    Address address = new Address();
                    byte[] Buffer = new byte[1];
                    ICMPv6Header icmp6 = new ICMPv6Header();
                    ICMPHeader icm = new ICMPHeader();
                    UDPHeader udp = new UDPHeader();
                    uint receiveLength = 0;
                    uint sendLength = 0;
                    IPHeader IP = new IPHeader();
                    IPv6Header ip6 = new IPv6Header();

                    string processName;
                    WINDIVERT_ADDRESS add = new WINDIVERT_ADDRESS();

                    uint pid = 0;
                    while (true)
                    {
                        var data = WinDivertMethods.WinDivertRecv(dev, Buffer, sendLength,ref add, ref receiveLength);

                        if (data == true)
                        {
                            MessageBox.Show(data.ToString());
                        }
                        else
                        {
                            MessageBox.Show("error " + Marshal.GetLastWin32Error());

                        }
                    }
                }
                else
                {
                    MessageBox.Show("Unable to open handle.Error: " + Marshal.GetLastWin32Error());
                    return;
                }

            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.ToString());
            }
        }
    }
}
TechnikEmpire commented 7 years ago

@Fiqow The error codes you get here are Windows errors codes. Googling "Windows error codes" will give you https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx, on which we can do a find on the page for 126 and see ERROR_MOD_NOT_FOUND, which means either the .dll or the .sys file or both are missing, which means you didn't set up a post build command to ensure that those files are always in the same directory as the executable trying to load them, AKA your program.