ffalcinelli / pydivert

A Python binding for WinDivert driver
GNU Lesser General Public License v3.0
200 stars 36 forks source link

OSError: [WinError 127] The specified procedure could not be found. #37

Open joveice opened 6 years ago

joveice commented 6 years ago
with pydivert.WinDivert("tcp.DstPort == 80 and tcp.PayloadLength > 0") as w:
    for packet in w:
        print(packet.src_addr)
        w.send(packet)

Error:

Traceback (most recent call last):
  File "tester.py", line 7, in <module>
    w.send(packet)
  File "pydivert\windivert.py", line 227, in send
    packet.recalculate_checksums()
  File "pydivert\packet\__init__.py", line 308, in recalculate_checksums
    num = windivert_dll.WinDivertHelperCalcChecksums(ctypes.byref(buff_), len(self.raw), flags)
  File "pydivert\windivert_dll\__init__.py", line 54, in wrapper
    raise err
OSError: [WinError 127] The specified procedure could not be found.

Whats this? Why can't I get the IP?

joveice commented 6 years ago

Turns out, I get the IP but I can't send it again unless I do w.send(packet, False) and when I do that the packet doesn't get sendt / ends up somewhere else.

joveice commented 6 years ago

More info. It seems to be different from time to time, sometimes I can print the IP and send it, sometimes I can't print and send it.

ly3too commented 5 years ago

I got the same bug

mhils commented 5 years ago

This seems to be due to changes in WinDivert 1.4: https://reqrypt.org/windivert-changelog.txt. The PyPI wheel bundles 1.3, so not sure how you are getting that. Are you installing from source?

joveice commented 5 years ago

Installed from pip and it's including 1.3 not 1.4. I noticed if you access both src and dst address it works 10 of 10 times.

ly3too commented 5 years ago

I found if I call some other function, that could set the LastError. and w.send() calls checksum helper function, which checks it. I tryed windll.kernel32.SetLastError(0) before w.send(). it helped.

I had this problem in this code:

for itm in psutil.net_connections():
    if itm.laddr.port == lport: # and itm.laddr.ip == lip:
            pname = psutil.Process(itm.pid).name()
print("pkt from process {}".format(pname))
windll.kernel32.SetLastError(0)  # this helped 
wd.send(pkt)