From 7cfc3e2e723b966de49b21b9918711263084237e Mon Sep 17 00:00:00 2001
From: basil00
Date: Tue, 19 Jan 2016 10:57:47 +0800
Subject: [PATCH] Further integrate the streamdump sample.
Untested.
---
doc/windivert.html | 7 ++++
examples/dirs | 3 +-
examples/streamdump/Makefile | 1 +
examples/streamdump/sources | 36 +++++++++++++++++
examples/streamdump/streamdump.vcproj | 58 +++++++++++++++++++++++++++
mingw-build.sh | 6 ++-
msvc-build.bat | 7 ++++
7 files changed, 116 insertions(+), 2 deletions(-)
create mode 100644 examples/streamdump/Makefile
create mode 100644 examples/streamdump/sources
create mode 100644 examples/streamdump/streamdump.vcproj
diff --git a/doc/windivert.html b/doc/windivert.html
index d7ff45a..2a8a5f5 100644
--- a/doc/windivert.html
+++ b/doc/windivert.html
@@ -1561,6 +1561,13 @@ The sample programs are:
packets from a single handle.
This example is useful for performance testing, and as a starting point
for more interesting applications.
+
streamdump.exe: A simple program that demonstrates how to
+ handle streams using WinDivert.
+ The basic idea is to divert outbound TCP connections to a local proxy
+ server which can capture or manipulate the stream.
+ The streamdump sample program also demonstrates usage of the
+ WinDivertRecvEx() and
+ WinDivertSendEx() functions.
The samples are intended for educational purposes only, and are not
diff --git a/examples/dirs b/examples/dirs
index 860b108..c11e553 100644
--- a/examples/dirs
+++ b/examples/dirs
@@ -2,4 +2,5 @@ DIRS= \
netdump \
netfilter \
passthru \
- webfilter
+ webfilter \
+ streamdump
diff --git a/examples/streamdump/Makefile b/examples/streamdump/Makefile
new file mode 100644
index 0000000..53b9a3d
--- /dev/null
+++ b/examples/streamdump/Makefile
@@ -0,0 +1 @@
+!INCLUDE $(NTMAKEENV)\makefile.def
diff --git a/examples/streamdump/sources b/examples/streamdump/sources
new file mode 100644
index 0000000..fab89e6
--- /dev/null
+++ b/examples/streamdump/sources
@@ -0,0 +1,36 @@
+# sources
+# (C) 2016 basil, all rights reserved,
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program. If not, see .
+
+!IF "$(_BUILDARCH)" == "x86"
+CPU=i386
+!ELSE
+CPU=$(_BUILDARCH)
+!ENDIF
+
+TARGETNAME=streamdump
+TARGETTYPE=PROGRAM
+TARGETPATH=..\..\install\WDDK
+TARGETLIBS=\
+ $(SDK_LIB_PATH)\setupapi.lib \
+ $(SDK_LIB_PATH)\user32.lib \
+ $(SDK_LIB_PATH)\ws2_32.lib \
+ $(TARGETPATH)\$(CPU)\WinDivert.lib
+UMTYPE=console
+UMENTRY=main
+USE_MSVCRT=1
+INCLUDES=$(DDK_INC_PATH);$(KMDF_INC_PATH)\$(KMDF_VER_PATH);..\..\include
+SOURCES=streamdump.c
+
diff --git a/examples/streamdump/streamdump.vcproj b/examples/streamdump/streamdump.vcproj
new file mode 100644
index 0000000..f254766
--- /dev/null
+++ b/examples/streamdump/streamdump.vcproj
@@ -0,0 +1,58 @@
+
+
+
+
+ Release
+ x64
+
+
+ Debug
+ x64
+
+
+ Release
+ Win32
+
+
+ Debug
+ Win32
+
+
+
+ Application
+ streamdump
+ Release
+
+
+
+ ..\..\include;%(AdditionalIncludeDirectories)
+
+
+ ws2_32.lib;..\..\install\MSVC\WinDivert.lib
+
+
+
+
+ v110
+
+
+ v110
+
+
+ v110
+
+
+ v110
+
+
+ True
+
+
+ False
+
+
+
+
+
+
+
diff --git a/mingw-build.sh b/mingw-build.sh
index 18b2b25..3637908 100644
--- a/mingw-build.sh
+++ b/mingw-build.sh
@@ -71,7 +71,11 @@ do
echo "\tbuild install/MINGW/$CPU/webfilter.exe..."
$CC -s -O2 -Iinclude/ examples/webfilter/webfilter.c \
-o "install/MINGW/$CPU/webfilter.exe" -lWinDivert -lws2_32 \
- -L"install/MINGW/$CPU/"
+ -L"install/MINGW/$CPU/"
+ echo "\tbuild install/MINGW/$CPU/streamdump.exe..."
+ $CC -s -O2 -Iinclude/ examples/streamdump/streamdump.c \
+ -o "install/MINGW/$CPU/streamdump.exe" -lWinDivert -lws2_32 \
+ -L"install/MINGW/$CPU/"
echo "\tcopy install/MINGW/$CPU/WinDivert$BITS.sys..."
cp install/WDDK/$CPU/WinDivert$BITS.sys install/MINGW/$CPU
else
diff --git a/msvc-build.bat b/msvc-build.bat
index 519b537..1f6adac 100644
--- a/msvc-build.bat
+++ b/msvc-build.bat
@@ -79,6 +79,13 @@ copy /Y build\webfilter.exe ..\..\%MSVC_INSTALL%
rd /s /q build\
cd ..\..
+:: Build streamdump
+cd examples\streamdump
+msbuild /p:Platform=%PLATFORM% /p:OutDir=build\
+copy /Y build\streamdump.exe ..\..\%MSVC_INSTALL%
+rd /s /q build\
+cd ..\..
+
:: Copy files
copy /Y %WDDK_INSTALL%\WinDivert%BITS%.sys %MSVC_INSTALL%