The divert.dll library can now be build with MinGW Linux cross-compilation.

This is useful for projects that use MinGW instead of MSVC.  Otherwise, the
.dlls are incompatible.
This commit is contained in:
basil00
2011-10-15 17:40:18 +08:00
parent 8906eaa02c
commit f1b7ead828
4 changed files with 94 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
#!/bin/bash
#
# build.sh
# (C) 2011, all rights reserved,
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Script for MinGW/Linux cross compilation.
# NOTE: This script only builds divert.dll, not the driver divert.sys
ENVS="i586-mingw32msvc amd64-mingw32msvc"
for ENV in $ENVS
do
CC="$ENV-gcc"
if [ -x "`which $CC`" ]
then
mkdir -p "install/$ENV"
echo "$CC -Iinclude/ -c divert.o dll/divert.c"
$CC -Iinclude/ -c divert.o dll/divert.c
echo "$CC -shared -o install/$ENV/divert.dll divert.o"
$CC -shared -o "install/$ENV/divert.dll" divert.o
else
echo "$CC: not found"
fi
done
+42
View File
@@ -26,7 +26,36 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef __MINGW32__
// Mingw does not have wdfinstaller.h
typedef struct _WDF_COINSTALLER_INSTALL_OPTIONS
{
ULONG Size;
BOOL ShowRebootPrompt;
} WDF_COINSTALLER_INSTALL_OPTIONS, *PWDF_COINSTALLER_INSTALL_OPTIONS;
VOID FORCEINLINE WDF_COINSTALLER_INSTALL_OPTIONS_INIT(
PWDF_COINSTALLER_INSTALL_OPTIONS ClientOptions)
{
RtlZeroMemory(ClientOptions, sizeof(WDF_COINSTALLER_INSTALL_OPTIONS));
ClientOptions->Size = sizeof(WDF_COINSTALLER_INSTALL_OPTIONS);
}
typedef ULONG (WINAPI *PFN_WDFPREDEVICEINSTALLEX)(
LPCWSTR inf_path,
LPCWSTR inf_sec_name,
PWDF_COINSTALLER_INSTALL_OPTIONS options
);
typedef ULONG (WINAPI *PFN_WDFPOSTDEVICEINSTALL)(
LPCWSTR inf_path,
LPCWSTR inf_sec_name
);
// Mingw does not support UINT8 and UINT16 ???
#define UINT8 unsigned char
#define UINT16 unsigned short
#else /* __MINGW32__ */
#include <wdfinstaller.h>
#endif /* __MINGW32__ */
// #define DIVERT_DEBUG
@@ -39,6 +68,19 @@
#define DIVERT_DRIVER_INF L"\\" DIVERT_DRIVER_NAME L".inf"
#define DIVERT_DRIVER_MATCH_DLL L"\\WdfCoInstaller*.dll"
/*
* ntoh and hton implementation to remove winsock dependency.
*/
#define BYTESWAP16(x) \
((((x) >> 8) & 0x00FF) | (((x) << 8) & 0xFF00))
#define BYTESWAP32(x) \
((((x) >> 24) & 0x000000FF) | (((x) >> 8) & 0x0000FF00) | \
(((x) << 8) & 0x00FF0000) | (((x) << 24) & 0xFF000000))
#define ntohs(x) BYTESWAP16(x)
#define htons(x) BYTESWAP16(x)
#define ntohl(x) BYTESWAP32(x)
#define htonl(x) BYTESWAP32(x)
/*
* Filter parsing.
*/
+7
View File
@@ -109,6 +109,13 @@ This will build the following files and place them in the
</ul>
</ol>
</p>
<p>
MinGW version of <tt>divert.dll</tt> may be built in Linux using the
<tt>build.sh</tt> script in the root directory.
This is useful for projects that use MinGW instead of MSVC.
Otherwise, the <tt>.dll</tt>s from different compilers are generally
incompatible.
</p>
<a name="driver_signing"><h3>2.2 Driver Signing</h3></a>
<p>
+7
View File
@@ -25,6 +25,13 @@
#define DIVERTEXPORT __declspec(dllimport)
#endif /* DIVERTEXPORT */
#ifdef __MINGW32__
#define __in
#define __out
#define __out_opt
#define __inout
#endif /* __MINGW32__ */
#ifdef __cplusplus
extern "C" {
#endif