├── drv ├── DrvShield │ ├── std.h │ ├── Cpprtl.cpp │ ├── HookSSDT.c │ ├── Sysmon.cpp │ ├── common.h │ ├── resource.h │ ├── DrvShield.rc │ ├── Arithmetic │ │ ├── node.h │ │ ├── array.h │ │ ├── avltree.h │ │ ├── dnode.h │ │ ├── binstree.h │ │ ├── hashtable.h │ │ ├── treenode.h │ │ ├── avltreenode.h │ │ ├── dclinkedlist.h │ │ └── linkedlist.h │ ├── DrvShield.vcproj │ ├── md5.h │ ├── Sysmon.h │ ├── DELTEMP.BAT │ ├── Hash.h │ ├── MAKEFILE │ ├── HookSSDT.h │ ├── DrvShield.h │ ├── sources │ ├── DrvShield.sln │ ├── Hash.cpp │ ├── Cpprtl.h │ ├── DrvShield.cpp │ └── md5.c └── kdarpshd │ ├── Inst │ ├── arpinst.bat │ ├── arprem.bat │ ├── KeydoneArpConfig.exe │ ├── kdarp_m.inf │ └── kdarp.inf │ ├── KNet.h │ ├── miniport.c │ ├── passthru.rc │ ├── passthru.htm │ ├── kdarpshd.vcproj │ ├── DELTEMP.BAT │ ├── makefile │ ├── precomp.h │ ├── kdarpshd.sln │ ├── sources │ ├── passthru.c │ ├── passthru.h │ └── protocol.c ├── exe ├── DrvShield │ ├── StdAfx.cpp │ ├── StdAfx.h │ ├── DrvShield.rc │ ├── TrayIcon.cpp │ ├── DrvShield.cpp │ ├── LoadDriver.cpp │ ├── DrvShieldDlg.cpp │ ├── res │ │ ├── DrvShield.ico │ │ ├── DrvShield.sys │ │ └── DrvShield.rc2 │ ├── LoadDriver.h │ ├── DrvShield.dsw │ ├── resource.h │ ├── DrvShield.clw │ ├── DrvShield.h │ ├── DrvShieldDlg.h │ ├── Subclass.h │ ├── TrayIcon.h │ ├── DrvShield.dsp │ └── Subclass.cpp └── MakePolicyFile │ ├── MakePolicyFile.rc │ ├── KdDrvAntiPolicy.dat │ ├── MakePolicyFile.exe │ ├── MakePolicyFileDlg.cpp │ ├── res │ ├── MakePolicyFile.ico │ └── MakePolicyFile.rc2 │ ├── md5.h │ ├── StdAfx.cpp │ ├── PathSelectDlg.h │ ├── resource.h │ ├── MakePolicyFile.dsw │ ├── MakePolicyFile.clw │ ├── StdAfx.h │ ├── MakePolicyFile.h │ ├── MakePolicyFile.cpp │ ├── MakePolicyFileDlg.h │ ├── PathSelectDlg.cpp │ ├── MakePolicyFile.dsp │ └── md5.cpp └── README.md /drv/DrvShield/std.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/drv/DrvShield/std.h -------------------------------------------------------------------------------- /drv/kdarpshd/Inst/arpinst.bat: -------------------------------------------------------------------------------- 1 | .\KeydoneArpConfig.exe -l ".\kdarp.inf" -c s -i ms_kdarpshd 2 | -------------------------------------------------------------------------------- /drv/kdarpshd/KNet.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/drv/kdarpshd/KNet.h -------------------------------------------------------------------------------- /drv/kdarpshd/Inst/arprem.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | .\KeydoneArpConfig.exe -u ms_kdarpshd 3 | @echo on 4 | -------------------------------------------------------------------------------- /drv/DrvShield/Cpprtl.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/drv/DrvShield/Cpprtl.cpp -------------------------------------------------------------------------------- /drv/DrvShield/HookSSDT.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/drv/DrvShield/HookSSDT.c -------------------------------------------------------------------------------- /drv/DrvShield/Sysmon.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/drv/DrvShield/Sysmon.cpp -------------------------------------------------------------------------------- /drv/DrvShield/common.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/drv/DrvShield/common.h -------------------------------------------------------------------------------- /drv/DrvShield/resource.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/drv/DrvShield/resource.h -------------------------------------------------------------------------------- /drv/kdarpshd/miniport.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/drv/kdarpshd/miniport.c -------------------------------------------------------------------------------- /drv/kdarpshd/passthru.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/drv/kdarpshd/passthru.rc -------------------------------------------------------------------------------- /exe/DrvShield/StdAfx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/exe/DrvShield/StdAfx.cpp -------------------------------------------------------------------------------- /exe/DrvShield/StdAfx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/exe/DrvShield/StdAfx.h -------------------------------------------------------------------------------- /drv/DrvShield/DrvShield.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/drv/DrvShield/DrvShield.rc -------------------------------------------------------------------------------- /drv/kdarpshd/passthru.htm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/drv/kdarpshd/passthru.htm -------------------------------------------------------------------------------- /exe/DrvShield/DrvShield.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/exe/DrvShield/DrvShield.rc -------------------------------------------------------------------------------- /exe/DrvShield/TrayIcon.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/exe/DrvShield/TrayIcon.cpp -------------------------------------------------------------------------------- /drv/kdarpshd/kdarpshd.vcproj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/drv/kdarpshd/kdarpshd.vcproj -------------------------------------------------------------------------------- /exe/DrvShield/DrvShield.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/exe/DrvShield/DrvShield.cpp -------------------------------------------------------------------------------- /exe/DrvShield/LoadDriver.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/exe/DrvShield/LoadDriver.cpp -------------------------------------------------------------------------------- /drv/DrvShield/Arithmetic/node.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/drv/DrvShield/Arithmetic/node.h -------------------------------------------------------------------------------- /drv/DrvShield/DrvShield.vcproj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/drv/DrvShield/DrvShield.vcproj -------------------------------------------------------------------------------- /exe/DrvShield/DrvShieldDlg.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/exe/DrvShield/DrvShieldDlg.cpp -------------------------------------------------------------------------------- /exe/DrvShield/res/DrvShield.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/exe/DrvShield/res/DrvShield.ico -------------------------------------------------------------------------------- /exe/DrvShield/res/DrvShield.sys: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/exe/DrvShield/res/DrvShield.sys -------------------------------------------------------------------------------- /drv/DrvShield/Arithmetic/array.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/drv/DrvShield/Arithmetic/array.h -------------------------------------------------------------------------------- /drv/DrvShield/Arithmetic/avltree.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/drv/DrvShield/Arithmetic/avltree.h -------------------------------------------------------------------------------- /drv/DrvShield/Arithmetic/dnode.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/drv/DrvShield/Arithmetic/dnode.h -------------------------------------------------------------------------------- /drv/DrvShield/Arithmetic/binstree.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/drv/DrvShield/Arithmetic/binstree.h -------------------------------------------------------------------------------- /drv/DrvShield/Arithmetic/hashtable.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/drv/DrvShield/Arithmetic/hashtable.h -------------------------------------------------------------------------------- /drv/DrvShield/Arithmetic/treenode.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/drv/DrvShield/Arithmetic/treenode.h -------------------------------------------------------------------------------- /exe/MakePolicyFile/MakePolicyFile.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/exe/MakePolicyFile/MakePolicyFile.rc -------------------------------------------------------------------------------- /drv/DrvShield/Arithmetic/avltreenode.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/drv/DrvShield/Arithmetic/avltreenode.h -------------------------------------------------------------------------------- /drv/DrvShield/Arithmetic/dclinkedlist.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/drv/DrvShield/Arithmetic/dclinkedlist.h -------------------------------------------------------------------------------- /drv/DrvShield/Arithmetic/linkedlist.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/drv/DrvShield/Arithmetic/linkedlist.h -------------------------------------------------------------------------------- /drv/kdarpshd/Inst/KeydoneArpConfig.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/drv/kdarpshd/Inst/KeydoneArpConfig.exe -------------------------------------------------------------------------------- /exe/MakePolicyFile/KdDrvAntiPolicy.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/exe/MakePolicyFile/KdDrvAntiPolicy.dat -------------------------------------------------------------------------------- /exe/MakePolicyFile/MakePolicyFile.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/exe/MakePolicyFile/MakePolicyFile.exe -------------------------------------------------------------------------------- /exe/MakePolicyFile/MakePolicyFileDlg.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/exe/MakePolicyFile/MakePolicyFileDlg.cpp -------------------------------------------------------------------------------- /exe/MakePolicyFile/res/MakePolicyFile.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phonegapX/DrvShield/HEAD/exe/MakePolicyFile/res/MakePolicyFile.ico -------------------------------------------------------------------------------- /exe/MakePolicyFile/md5.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __MD5_H__ 3 | #define __MD5_H__ 4 | 5 | void md5(PVOID Buf, ULONG BufLen, PCHAR Digest); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /drv/DrvShield/md5.h: -------------------------------------------------------------------------------- 1 | #ifndef __MD5_H__ 2 | #define __MD5_H__ 3 | 4 | EXTERN_C void md5(PVOID Buf, ULONG BufLen, PCHAR Digest); 5 | 6 | #endif 7 | 8 | -------------------------------------------------------------------------------- /exe/DrvShield/LoadDriver.h: -------------------------------------------------------------------------------- 1 | #ifndef __LOADDRIVER_H__ 2 | #define __LOADDRIVER_H__ 3 | 4 | bool LoadDriver(PCHAR szDrvName, PCHAR szDrvPath); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /drv/DrvShield/Sysmon.h: -------------------------------------------------------------------------------- 1 | #ifndef __SYSMON_H__ 2 | #define __SYSMON_H__ 3 | 4 | EXTERN_C NTSTATUS InstallSysMonHandler(); 5 | 6 | EXTERN_C VOID UnInstallSysMonHandler(); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /drv/DrvShield/DELTEMP.BAT: -------------------------------------------------------------------------------- 1 | rd /s /q objchk 2 | rd /s /q objfre 3 | rd /s /q objchk_wnet_x86 4 | rd /s /q objfre_wnet_x86 5 | rd /s /q obj 6 | rd /s /q Debug 7 | del *.opt 8 | del *.ncb 9 | del *.log 10 | del *.aps 11 | del *.err 12 | del *.plg 13 | del *.wrn -------------------------------------------------------------------------------- /drv/DrvShield/Hash.h: -------------------------------------------------------------------------------- 1 | #ifndef __HASH_H__ 2 | #define __HASH_H__ 3 | 4 | EXTERN_C void HashTableInit(ULONG Count); 5 | 6 | EXTERN_C void InsertHashTable(DRV_INFO & DrvInfo); 7 | 8 | EXTERN_C BOOLEAN LookupHashTable(DRV_INFO & DrvInfo); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /drv/kdarpshd/DELTEMP.BAT: -------------------------------------------------------------------------------- 1 | rd /s /q objchk 2 | rd /s /q objfre 3 | rd /s /q objchk_wnet_x86 4 | rd /s /q objfre_wnet_x86 5 | rd /s /q obj 6 | rd /s /q Debug 7 | del *.opt 8 | del *.ncb 9 | del *.log 10 | del *.aps 11 | del *.err 12 | del *.plg 13 | del *.wrn -------------------------------------------------------------------------------- /exe/MakePolicyFile/StdAfx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // MakePolicyFile.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /drv/kdarpshd/makefile: -------------------------------------------------------------------------------- 1 | # 2 | # DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source 3 | # file to this component. This file merely indirects to the real make file 4 | # that is shared by all the components of NT 5 | # 6 | !INCLUDE $(NTMAKEENV)\makefile.def 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /drv/DrvShield/MAKEFILE: -------------------------------------------------------------------------------- 1 | # 2 | # DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source 3 | # file to this component. This file merely indirects to the real make file 4 | # that is shared by all the driver components of the Windows NT DDK 5 | # 6 | 7 | BUILD_ALLOW_ALL_WARNINGS=1 8 | 9 | !INCLUDE $(NTMAKEENV)\makefile.def 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Windows安全防火墙 2 | 3 | 这是2008年开发的一个Windows安全组件,主要包括两个部分,一是内核驱动防火墙,通过白名单机制,阻止未授权的驱动的加载,并且通过HOOK SSDT的方式保护自身进程的安全,二是ARP防火墙,它通过NDIS中间层驱动捕获以太数据报文,过滤掉其中的恶意ARP报文。自夸一下,当年项目代码很工整,并且自定义了C++ stub,用于实现ddk下编译C++代码 :) 4 | 5 | drv文件夹: 6 | DrvShield文件夹:驱动防火墙内核模块 7 | kdarpshd文件夹:ARP防火墙内核模块 8 | 9 | exe文件夹: 10 | DrvShield文件夹:主执行程序 11 | MakePolicyFile文件夹:策略白名单制作工具 -------------------------------------------------------------------------------- /exe/MakePolicyFile/PathSelectDlg.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CPathSelectDlg 4 | { 5 | public: 6 | CPathSelectDlg(CWnd * hwndOwner = NULL, CString strTitle = ""); 7 | virtual ~CPathSelectDlg(void); 8 | BOOL DoModal(); 9 | public: 10 | CString m_strPath; 11 | CString m_strInitDir; 12 | CString m_strTitle; 13 | int m_iImageIndex; 14 | protected: 15 | HWND m_hwndOwner; 16 | }; 17 | -------------------------------------------------------------------------------- /drv/DrvShield/HookSSDT.h: -------------------------------------------------------------------------------- 1 | #ifndef __HOOKSSDT_H__ 2 | #define __HOOKSSDT_H__ 3 | 4 | EXTERN_C VOID AddProcessProtectList(ULONG ProcessID); 5 | 6 | EXTERN_C BOOLEAN ExistProcessIdInProtectList(ULONG ProcessID); 7 | 8 | EXTERN_C VOID DisableWriteProtect(PULONG Dr0); 9 | 10 | EXTERN_C VOID DisableIntermitAndSaveFlagRegister(PUSHORT FlagRegValue); 11 | 12 | EXTERN_C NTSTATUS SWHookInit(); 13 | 14 | EXTERN_C VOID SWHookSSDT(); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /exe/DrvShield/res/DrvShield.rc2: -------------------------------------------------------------------------------- 1 | // 2 | // DRVSHIELD.RC2 - resources Microsoft Visual C++ does not edit directly 3 | // 4 | 5 | #ifdef APSTUDIO_INVOKED 6 | #error this file is not editable by Microsoft Visual C++ 7 | #endif //APSTUDIO_INVOKED 8 | 9 | 10 | ///////////////////////////////////////////////////////////////////////////// 11 | // Add manually edited resources here... 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | -------------------------------------------------------------------------------- /drv/DrvShield/DrvShield.h: -------------------------------------------------------------------------------- 1 | #ifndef __DRVSHIELD_H__ 2 | #define __DRVSHIELD_H__ 3 | 4 | class KDrvShieldDriver:public KDriver 5 | { 6 | public: 7 | 8 | protected: 9 | virtual NTSTATUS DriverEntry(); 10 | virtual NTSTATUS IrpMajorCreate(PDEVICE_OBJECT DeviceObject, PIRP Irp); 11 | virtual NTSTATUS IrpMajorClose(PDEVICE_OBJECT DeviceObject, PIRP Irp); 12 | virtual NTSTATUS IrpMajorDeviceControl(PDEVICE_OBJECT DeviceObject, PIRP Irp); 13 | 14 | private: 15 | }; 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /exe/MakePolicyFile/res/MakePolicyFile.rc2: -------------------------------------------------------------------------------- 1 | // 2 | // MAKEPOLICYFILE.RC2 - resources Microsoft Visual C++ does not edit directly 3 | // 4 | 5 | #ifdef APSTUDIO_INVOKED 6 | #error this file is not editable by Microsoft Visual C++ 7 | #endif //APSTUDIO_INVOKED 8 | 9 | 10 | ///////////////////////////////////////////////////////////////////////////// 11 | // Add manually edited resources here... 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | -------------------------------------------------------------------------------- /drv/kdarpshd/precomp.h: -------------------------------------------------------------------------------- 1 | #pragma warning(disable:4214) // bit field types other than int 2 | 3 | #pragma warning(disable:4201) // nameless struct/union 4 | #pragma warning(disable:4115) // named type definition in parentheses 5 | #pragma warning(disable:4127) // conditional expression is constant 6 | #pragma warning(disable:4054) // cast of function pointer to PVOID 7 | #pragma warning(disable:4244) // conversion from 'int' to 'BOOLEAN', possible loss of data 8 | 9 | #include "KNet.h" 10 | #include "passthru.h" 11 | 12 | -------------------------------------------------------------------------------- /exe/MakePolicyFile/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by MakePolicyFile.rc 4 | // 5 | #define IDD_MAKEPOLICYFILE_DIALOG 102 6 | #define IDR_MAINFRAME 128 7 | #define IDC_MSGLIST 1000 8 | 9 | // Next default values for new objects 10 | // 11 | #ifdef APSTUDIO_INVOKED 12 | #ifndef APSTUDIO_READONLY_SYMBOLS 13 | #define _APS_NEXT_RESOURCE_VALUE 129 14 | #define _APS_NEXT_COMMAND_VALUE 32771 15 | #define _APS_NEXT_CONTROL_VALUE 1001 16 | #define _APS_NEXT_SYMED_VALUE 101 17 | #endif 18 | #endif 19 | -------------------------------------------------------------------------------- /drv/DrvShield/sources: -------------------------------------------------------------------------------- 1 | TARGETNAME=DrvShield 2 | TARGETPATH=obj 3 | TARGETTYPE=DRIVER 4 | 5 | # 6 | # The WinXP DDK has introduced the DDK_TARGET_OS environemnt variable 7 | # for conditional compilation. The test here is designed to make this 8 | # sources file portable to the standalone Win 2K DDK environment. Note, 9 | # however, that the required csq.h and csq.lib are not present in that 10 | # environment. 11 | # 12 | !if "$(DDK_TARGET_OS)"!="WinXP" 13 | C_DEFINES=$(C_DEFINES) -DW2K=1 14 | TARGETLIBS=$(DDK_LIB_PATH)\csq.lib 15 | !endif 16 | 17 | SOURCES=Cpprtl.cpp DrvShield.cpp Hash.cpp Sysmon.cpp HookSSDT.c md5.c DrvShield.rc 18 | 19 | USE_MAPSYM=1 20 | -------------------------------------------------------------------------------- /exe/DrvShield/DrvShield.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "DrvShield"=.\DrvShield.dsp - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /exe/MakePolicyFile/MakePolicyFile.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "MakePolicyFile"=.\MakePolicyFile.dsp - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /exe/DrvShield/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by DrvShield.rc 4 | // 5 | #define IDD_DRVSHIELD_DIALOG 102 6 | #define IDR_MAINFRAME 128 7 | #define IDR_DAT 130 8 | #define IDR_POP_MENU 132 9 | #define IDC_MSG_LIST 1000 10 | #define ID_MENU_SHOW 32771 11 | #define ID_MENU_ABOUT 32772 12 | 13 | // Next default values for new objects 14 | // 15 | #ifdef APSTUDIO_INVOKED 16 | #ifndef APSTUDIO_READONLY_SYMBOLS 17 | #define _APS_NEXT_RESOURCE_VALUE 133 18 | #define _APS_NEXT_COMMAND_VALUE 32773 19 | #define _APS_NEXT_CONTROL_VALUE 1001 20 | #define _APS_NEXT_SYMED_VALUE 101 21 | #endif 22 | #endif 23 | -------------------------------------------------------------------------------- /drv/kdarpshd/kdarpshd.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 9.00 3 | # Visual Studio 2005 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "kdarpshd", "kdarpshd.vcproj", "{41D9B6E8-7515-40A6-BE3A-E33160F8881C}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {41D9B6E8-7515-40A6-BE3A-E33160F8881C}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {41D9B6E8-7515-40A6-BE3A-E33160F8881C}.Debug|Win32.Build.0 = Debug|Win32 14 | {41D9B6E8-7515-40A6-BE3A-E33160F8881C}.Release|Win32.ActiveCfg = Release|Win32 15 | {41D9B6E8-7515-40A6-BE3A-E33160F8881C}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /drv/DrvShield/DrvShield.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 9.00 3 | # Visual Studio 2005 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DrvShield", "DrvShield.vcproj", "{0B418A61-D320-45B2-9BC1-36604B7F820A}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {0B418A61-D320-45B2-9BC1-36604B7F820A}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {0B418A61-D320-45B2-9BC1-36604B7F820A}.Debug|Win32.Build.0 = Debug|Win32 14 | {0B418A61-D320-45B2-9BC1-36604B7F820A}.Release|Win32.ActiveCfg = Release|Win32 15 | {0B418A61-D320-45B2-9BC1-36604B7F820A}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /drv/DrvShield/Hash.cpp: -------------------------------------------------------------------------------- 1 | #include "std.h" 2 | #include "Hash.h" 3 | #include "Arithmetic/hashtable.h" 4 | 5 | static HashTable obHashTable; 6 | 7 | inline bool operator==(DRV_INFO & lhs, const DRV_INFO & rhs) 8 | { 9 | if (memcmp(lhs.Md5Digest, rhs.Md5Digest, sizeof(lhs.Md5Digest)) == 0) 10 | { 11 | return true; 12 | } 13 | return false; 14 | } 15 | 16 | ULONG HashKey(const DRV_INFO & key) 17 | { 18 | ULONG nHash = 0; 19 | CHAR szBuf[128] = {0}; 20 | PCHAR strkey = szBuf; 21 | memcpy(szBuf, key.Md5Digest, sizeof(key.Md5Digest)); 22 | while (*strkey) 23 | { 24 | nHash = (nHash<<5) + nHash + *strkey++; 25 | } 26 | return nHash; 27 | } 28 | 29 | void HashTableInit(ULONG Count) 30 | { 31 | obHashTable.InitHashTable(Count, HashKey); 32 | } 33 | 34 | void InsertHashTable(DRV_INFO & DrvInfo) 35 | { 36 | obHashTable.Insert(DrvInfo); 37 | } 38 | 39 | BOOLEAN LookupHashTable(DRV_INFO & DrvInfo) 40 | { 41 | return obHashTable.Find(DrvInfo); 42 | } 43 | -------------------------------------------------------------------------------- /exe/DrvShield/DrvShield.clw: -------------------------------------------------------------------------------- 1 | ; CLW file contains information for the MFC ClassWizard 2 | 3 | [General Info] 4 | Version=1 5 | LastClass=CDrvShieldDlg 6 | LastTemplate=CDialog 7 | NewFileInclude1=#include "stdafx.h" 8 | NewFileInclude2=#include "DrvShield.h" 9 | 10 | ClassCount=2 11 | Class1=CDrvShieldApp 12 | Class2=CDrvShieldDlg 13 | 14 | ResourceCount=4 15 | Resource2=IDR_MAINFRAME 16 | Resource3=IDD_DRVSHIELD_DIALOG 17 | Resource4=IDR_POP_MENU 18 | 19 | [CLS:CDrvShieldApp] 20 | Type=0 21 | HeaderFile=DrvShield.h 22 | ImplementationFile=DrvShield.cpp 23 | Filter=N 24 | 25 | [CLS:CDrvShieldDlg] 26 | Type=0 27 | HeaderFile=DrvShieldDlg.h 28 | ImplementationFile=DrvShieldDlg.cpp 29 | Filter=D 30 | LastObject=CDrvShieldDlg 31 | BaseClass=CDialog 32 | VirtualFilter=dWC 33 | 34 | 35 | 36 | [DLG:IDD_DRVSHIELD_DIALOG] 37 | Type=1 38 | Class=CDrvShieldDlg 39 | ControlCount=2 40 | Control1=IDC_STATIC,button,1342177287 41 | Control2=IDC_MSG_LIST,SysListView32,1350631429 42 | 43 | [MNU:IDR_POP_MENU] 44 | Type=1 45 | Class=CDrvShieldDlg 46 | CommandCount=0 47 | 48 | -------------------------------------------------------------------------------- /exe/MakePolicyFile/MakePolicyFile.clw: -------------------------------------------------------------------------------- 1 | ; CLW file contains information for the MFC ClassWizard 2 | 3 | [General Info] 4 | Version=1 5 | LastClass=CMakePolicyFileDlg 6 | LastTemplate=CDialog 7 | NewFileInclude1=#include "stdafx.h" 8 | NewFileInclude2=#include "MakePolicyFile.h" 9 | 10 | ClassCount=2 11 | Class1=CMakePolicyFileApp 12 | Class2=CMakePolicyFileDlg 13 | 14 | ResourceCount=3 15 | Resource2=IDR_MAINFRAME 16 | Resource3=IDD_MAKEPOLICYFILE_DIALOG 17 | 18 | [CLS:CMakePolicyFileApp] 19 | Type=0 20 | HeaderFile=MakePolicyFile.h 21 | ImplementationFile=MakePolicyFile.cpp 22 | Filter=N 23 | 24 | [CLS:CMakePolicyFileDlg] 25 | Type=0 26 | HeaderFile=MakePolicyFileDlg.h 27 | ImplementationFile=MakePolicyFileDlg.cpp 28 | Filter=D 29 | BaseClass=CDialog 30 | VirtualFilter=dWC 31 | LastObject=IDC_LIST1 32 | 33 | 34 | 35 | [DLG:IDD_MAKEPOLICYFILE_DIALOG] 36 | Type=1 37 | Class=CMakePolicyFileDlg 38 | ControlCount=4 39 | Control1=IDOK,button,1342242817 40 | Control2=IDCANCEL,button,1342242816 41 | Control3=IDC_STATIC,button,1342177287 42 | Control4=IDC_MSGLIST,SysListView32,1350631429 43 | 44 | -------------------------------------------------------------------------------- /drv/kdarpshd/sources: -------------------------------------------------------------------------------- 1 | TARGETNAME=kdarpshd 2 | TARGETPATH=obj 3 | TARGETTYPE=DRIVER 4 | 5 | C_DEFINES=$(C_DEFINES) -DNDIS_MINIPORT_DRIVER -DNDIS_WDM=1 6 | 7 | 8 | !if !defined(DDK_TARGET_OS) || "$(DDK_TARGET_OS)"=="Win2K" 9 | # 10 | # The driver is built in the Win2K build environment 11 | # 12 | C_DEFINES=$(C_DEFINES) -DNDIS40_MINIPORT=1 13 | C_DEFINES=$(C_DEFINES) -DNDIS40=1 14 | !else 15 | # 16 | # The driver is built in the XP or .NET build environment 17 | # So let us build NDIS 5.1 version. 18 | # 19 | C_DEFINES=$(C_DEFINES) -DNDIS51_MINIPORT=1 20 | C_DEFINES=$(C_DEFINES) -DNDIS51=1 21 | !endif 22 | 23 | # Uncomment the following to build for Win98/SE/WinMe 24 | # This causes several APIs that are not present in Win9X to be 25 | # ifdef'ed out. 26 | # C_DEFINES=$(C_DEFINES) -DWIN9X=1 27 | 28 | PRECOMPILED_INCLUDE=precomp.h 29 | PRECOMPILED_PCH=precomp.pch 30 | PRECOMPILED_OBJ=precomp.obj 31 | 32 | TARGETLIBS=$(DDK_LIB_PATH)\ndis.lib 33 | 34 | USE_MAPSYM=1 35 | 36 | INCLUDES= 37 | 38 | SOURCES=\ 39 | miniport.c \ 40 | passthru.c \ 41 | passthru.rc \ 42 | protocol.c 43 | 44 | -------------------------------------------------------------------------------- /exe/MakePolicyFile/StdAfx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #if !defined(AFX_STDAFX_H__AD09EE91_D851_4F44_8A57_0925F5850F35__INCLUDED_) 7 | #define AFX_STDAFX_H__AD09EE91_D851_4F44_8A57_0925F5850F35__INCLUDED_ 8 | 9 | #if _MSC_VER > 1000 10 | #pragma once 11 | #endif // _MSC_VER > 1000 12 | 13 | #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers 14 | 15 | #include // MFC core and standard components 16 | #include // MFC extensions 17 | #include // MFC support for Internet Explorer 4 Common Controls 18 | #ifndef _AFX_NO_AFXCMN_SUPPORT 19 | #include // MFC support for Windows Common Controls 20 | #endif // _AFX_NO_AFXCMN_SUPPORT 21 | 22 | #include 23 | 24 | //{{AFX_INSERT_LOCATION}} 25 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line. 26 | 27 | #endif // !defined(AFX_STDAFX_H__AD09EE91_D851_4F44_8A57_0925F5850F35__INCLUDED_) 28 | -------------------------------------------------------------------------------- /exe/DrvShield/DrvShield.h: -------------------------------------------------------------------------------- 1 | // DrvShield.h : main header file for the DRVSHIELD application 2 | // 3 | 4 | #if !defined(AFX_DRVSHIELD_H__5AF52AB4_2536_41EF_8F54_ED0208871C57__INCLUDED_) 5 | #define AFX_DRVSHIELD_H__5AF52AB4_2536_41EF_8F54_ED0208871C57__INCLUDED_ 6 | 7 | #if _MSC_VER > 1000 8 | #pragma once 9 | #endif // _MSC_VER > 1000 10 | 11 | #ifndef __AFXWIN_H__ 12 | #error include 'stdafx.h' before including this file for PCH 13 | #endif 14 | 15 | #include "resource.h" // main symbols 16 | 17 | ///////////////////////////////////////////////////////////////////////////// 18 | // CDrvShieldApp: 19 | // See DrvShield.cpp for the implementation of this class 20 | // 21 | 22 | class CDrvShieldApp : public CWinApp 23 | { 24 | public: 25 | CDrvShieldApp(); 26 | 27 | // Overrides 28 | // ClassWizard generated virtual function overrides 29 | //{{AFX_VIRTUAL(CDrvShieldApp) 30 | public: 31 | virtual BOOL InitInstance(); 32 | //}}AFX_VIRTUAL 33 | 34 | // Implementation 35 | 36 | //{{AFX_MSG(CDrvShieldApp) 37 | //}}AFX_MSG 38 | DECLARE_MESSAGE_MAP() 39 | }; 40 | 41 | 42 | ///////////////////////////////////////////////////////////////////////////// 43 | 44 | //{{AFX_INSERT_LOCATION}} 45 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line. 46 | 47 | #endif // !defined(AFX_DRVSHIELD_H__5AF52AB4_2536_41EF_8F54_ED0208871C57__INCLUDED_) 48 | -------------------------------------------------------------------------------- /exe/MakePolicyFile/MakePolicyFile.h: -------------------------------------------------------------------------------- 1 | // MakePolicyFile.h : main header file for the MAKEPOLICYFILE application 2 | // 3 | 4 | #if !defined(AFX_MAKEPOLICYFILE_H__81BA8A1B_8B48_4B65_8581_5456EE39F0EA__INCLUDED_) 5 | #define AFX_MAKEPOLICYFILE_H__81BA8A1B_8B48_4B65_8581_5456EE39F0EA__INCLUDED_ 6 | 7 | #if _MSC_VER > 1000 8 | #pragma once 9 | #endif // _MSC_VER > 1000 10 | 11 | #ifndef __AFXWIN_H__ 12 | #error include 'stdafx.h' before including this file for PCH 13 | #endif 14 | 15 | #include "resource.h" // main symbols 16 | 17 | ///////////////////////////////////////////////////////////////////////////// 18 | // CMakePolicyFileApp: 19 | // See MakePolicyFile.cpp for the implementation of this class 20 | // 21 | 22 | class CMakePolicyFileApp : public CWinApp 23 | { 24 | public: 25 | CMakePolicyFileApp(); 26 | 27 | // Overrides 28 | // ClassWizard generated virtual function overrides 29 | //{{AFX_VIRTUAL(CMakePolicyFileApp) 30 | public: 31 | virtual BOOL InitInstance(); 32 | //}}AFX_VIRTUAL 33 | 34 | // Implementation 35 | 36 | //{{AFX_MSG(CMakePolicyFileApp) 37 | //}}AFX_MSG 38 | DECLARE_MESSAGE_MAP() 39 | }; 40 | 41 | 42 | ///////////////////////////////////////////////////////////////////////////// 43 | 44 | //{{AFX_INSERT_LOCATION}} 45 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line. 46 | 47 | #endif // !defined(AFX_MAKEPOLICYFILE_H__81BA8A1B_8B48_4B65_8581_5456EE39F0EA__INCLUDED_) 48 | -------------------------------------------------------------------------------- /exe/MakePolicyFile/MakePolicyFile.cpp: -------------------------------------------------------------------------------- 1 | // MakePolicyFile.cpp : Defines the class behaviors for the application. 2 | // 3 | 4 | #include "stdafx.h" 5 | #include "MakePolicyFile.h" 6 | #include "MakePolicyFileDlg.h" 7 | 8 | #ifdef _DEBUG 9 | #define new DEBUG_NEW 10 | #undef THIS_FILE 11 | static char THIS_FILE[] = __FILE__; 12 | #endif 13 | 14 | ///////////////////////////////////////////////////////////////////////////// 15 | // CMakePolicyFileApp 16 | 17 | BEGIN_MESSAGE_MAP(CMakePolicyFileApp, CWinApp) 18 | //{{AFX_MSG_MAP(CMakePolicyFileApp) 19 | //}}AFX_MSG 20 | ON_COMMAND(ID_HELP, CWinApp::OnHelp) 21 | END_MESSAGE_MAP() 22 | 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // CMakePolicyFileApp construction 25 | 26 | CMakePolicyFileApp::CMakePolicyFileApp() 27 | { 28 | } 29 | 30 | ///////////////////////////////////////////////////////////////////////////// 31 | // The one and only CMakePolicyFileApp object 32 | 33 | CMakePolicyFileApp theApp; 34 | 35 | ///////////////////////////////////////////////////////////////////////////// 36 | // CMakePolicyFileApp initialization 37 | 38 | BOOL CMakePolicyFileApp::InitInstance() 39 | { 40 | // Standard initialization 41 | 42 | CMakePolicyFileDlg dlg; 43 | m_pMainWnd = &dlg; 44 | int nResponse = dlg.DoModal(); 45 | if (nResponse == IDOK) 46 | { 47 | } 48 | else if (nResponse == IDCANCEL) 49 | { 50 | } 51 | 52 | // Since the dialog has been closed, return FALSE so that we exit the 53 | // application, rather than start the application's message pump. 54 | return FALSE; 55 | } 56 | -------------------------------------------------------------------------------- /exe/MakePolicyFile/MakePolicyFileDlg.h: -------------------------------------------------------------------------------- 1 | // MakePolicyFileDlg.h : header file 2 | // 3 | 4 | #if !defined(AFX_MAKEPOLICYFILEDLG_H__B3BB3A8D_9947_4D22_8CF9_D1BCF059E859__INCLUDED_) 5 | #define AFX_MAKEPOLICYFILEDLG_H__B3BB3A8D_9947_4D22_8CF9_D1BCF059E859__INCLUDED_ 6 | 7 | #if _MSC_VER > 1000 8 | #pragma once 9 | #endif // _MSC_VER > 1000 10 | 11 | ///////////////////////////////////////////////////////////////////////////// 12 | // CMakePolicyFileDlg dialog 13 | 14 | class CMakePolicyFileDlg : public CDialog 15 | { 16 | // Construction 17 | public: 18 | CMakePolicyFileDlg(CWnd* pParent = NULL); // standard constructor 19 | 20 | // Dialog Data 21 | //{{AFX_DATA(CMakePolicyFileDlg) 22 | enum { IDD = IDD_MAKEPOLICYFILE_DIALOG }; 23 | CListCtrl m_MsgList; 24 | //}}AFX_DATA 25 | 26 | // ClassWizard generated virtual function overrides 27 | //{{AFX_VIRTUAL(CMakePolicyFileDlg) 28 | protected: 29 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support 30 | //}}AFX_VIRTUAL 31 | 32 | // Implementation 33 | protected: 34 | HICON m_hIcon; 35 | 36 | // Generated message map functions 37 | //{{AFX_MSG(CMakePolicyFileDlg) 38 | virtual BOOL OnInitDialog(); 39 | afx_msg void OnPaint(); 40 | afx_msg HCURSOR OnQueryDragIcon(); 41 | virtual void OnOK(); 42 | afx_msg void OnDestroy(); 43 | //}}AFX_MSG 44 | DECLARE_MESSAGE_MAP() 45 | 46 | private: 47 | static VOID ThreadRouter(PVOID Context); 48 | BOOL AddDrvInfo(PCHAR FilePathName); 49 | ULONG MakeToMem(PCHAR lpPath); 50 | ULONG Make(PCHAR lpPath); 51 | BOOL LoadPolicyFile(); 52 | CMapStringToPtr m_DrvInfoMap; 53 | HANDLE m_ThreadWaitEvent; 54 | ULONG m_uCol; 55 | }; 56 | 57 | //{{AFX_INSERT_LOCATION}} 58 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line. 59 | 60 | #endif // !defined(AFX_MAKEPOLICYFILEDLG_H__B3BB3A8D_9947_4D22_8CF9_D1BCF059E859__INCLUDED_) 61 | -------------------------------------------------------------------------------- /exe/DrvShield/DrvShieldDlg.h: -------------------------------------------------------------------------------- 1 | // DrvShieldDlg.h : header file 2 | // 3 | 4 | #if !defined(AFX_DRVSHIELDDLG_H__67D611FD_FEAB_4FD5_894E_A99FFAE10351__INCLUDED_) 5 | #define AFX_DRVSHIELDDLG_H__67D611FD_FEAB_4FD5_894E_A99FFAE10351__INCLUDED_ 6 | 7 | #include "..\..\DRV\DrvShield\common.h" // Added by ClassView 8 | #include "TrayIcon.h" // Added by ClassView 9 | #if _MSC_VER > 1000 10 | #pragma once 11 | #endif // _MSC_VER > 1000 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // CDrvShieldDlg dialog 15 | 16 | class CDrvShieldDlg : public CDialog 17 | { 18 | // Construction 19 | public: 20 | CDrvShieldDlg(CWnd* pParent = NULL); // standard constructor 21 | 22 | // Dialog Data 23 | //{{AFX_DATA(CDrvShieldDlg) 24 | enum { IDD = IDD_DRVSHIELD_DIALOG }; 25 | CListCtrl m_MsgList; 26 | //}}AFX_DATA 27 | 28 | // ClassWizard generated virtual function overrides 29 | //{{AFX_VIRTUAL(CDrvShieldDlg) 30 | protected: 31 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support 32 | //}}AFX_VIRTUAL 33 | 34 | // Implementation 35 | protected: 36 | CTrayIcon m_trayIcon; 37 | HICON m_hIcon; 38 | 39 | // Generated message map functions 40 | //{{AFX_MSG(CDrvShieldDlg) 41 | virtual BOOL OnInitDialog(); 42 | afx_msg void OnPaint(); 43 | afx_msg HCURSOR OnQueryDragIcon(); 44 | afx_msg void OnClose(); 45 | afx_msg void OnDestroy(); 46 | afx_msg void OnNotifyIcon(WPARAM wParam, LPARAM lParam); 47 | afx_msg void OnTimer(UINT nIDEvent); 48 | afx_msg void OnMenuShow(); 49 | afx_msg void OnMenuAbout(); 50 | //}}AFX_MSG 51 | DECLARE_MESSAGE_MAP() 52 | private: 53 | BOOL DeviceIO(BOOL bReConn = FALSE); 54 | static VOID ThreadRouter(PVOID Context); 55 | BOOL LoadPolicyFile(); 56 | PDRV_ANTI_DATA m_DrvAntiData; 57 | ULONG m_DataSize; 58 | HANDLE m_hDriverEntryEvent; 59 | HANDLE m_hDriverClearedEvent; 60 | ULONG m_uCol; 61 | }; 62 | 63 | //{{AFX_INSERT_LOCATION}} 64 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line. 65 | 66 | #endif // !defined(AFX_DRVSHIELDDLG_H__67D611FD_FEAB_4FD5_894E_A99FFAE10351__INCLUDED_) 67 | -------------------------------------------------------------------------------- /exe/DrvShield/Subclass.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////// 2 | // If this code works, it was written by Paul DiLascia. 3 | // If not, I don't know who wrote it. 4 | // 5 | #ifndef _SUBCLASSW_H 6 | #define _SUBCLASSW_H 7 | 8 | ////////////////// 9 | // Generic class to hook messages on behalf of a CWnd. 10 | // Once hooked, all messages go to CSubclassWnd::WindowProc before going 11 | // to the window. Specific subclasses can trap messages and do something. 12 | // 13 | // To use: 14 | // 15 | // * Derive a class from CSubclassWnd. 16 | // 17 | // * Override CSubclassWnd::WindowProc to handle messages. Make sure you call 18 | // CSubclassWnd::WindowProc if you don't handle the message, or your 19 | // window will never get messages. If you write seperate message handlers, 20 | // you can call Default() to pass the message to the window. 21 | // 22 | // * Instantiate your derived class somewhere and call HookWindow(pWnd) 23 | // to hook your window, AFTER it has been created. 24 | // To unhook, call HookWindow(NULL). 25 | // 26 | // This is a very important class, crucial to many of the widgets Window 27 | // widgets implemented in PixieLib. To see how it works, look at the HOOK 28 | // sample program. 29 | // 30 | class CSubclassWnd : public CObject { 31 | public: 32 | DECLARE_DYNAMIC(CSubclassWnd); 33 | CSubclassWnd(); 34 | ~CSubclassWnd(); 35 | 36 | // Subclass a window. Hook(NULL) to unhook (automatic on WM_NCDESTROY) 37 | BOOL HookWindow(HWND hwnd); 38 | BOOL HookWindow(CWnd* pWnd) { return HookWindow(pWnd->GetSafeHwnd()); } 39 | BOOL IsHooked() { return m_hWnd!=NULL; } 40 | 41 | friend LRESULT CALLBACK HookWndProc(HWND, UINT, WPARAM, LPARAM); 42 | friend class CSubclassWndMap; 43 | 44 | #ifdef _DEBUG 45 | virtual void AssertValid() const; 46 | virtual void Dump(CDumpContext& dc) const; 47 | #endif 48 | 49 | protected: 50 | HWND m_hWnd; // the window hooked 51 | WNDPROC m_pOldWndProc; // ..and original window proc 52 | CSubclassWnd* m_pNext; // next in chain of hooks for this window 53 | 54 | // Override this to handle messages in specific handlers 55 | virtual LRESULT WindowProc(UINT msg, WPARAM wp, LPARAM lp); 56 | LRESULT Default(); // call this at the end of handler fns 57 | }; 58 | 59 | #endif // _SUBCLASSW_H 60 | 61 | -------------------------------------------------------------------------------- /exe/DrvShield/TrayIcon.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////// 2 | // MSDN Magazine -- November 2002 3 | // If this code works, it was written by Paul DiLascia. 4 | // If not, I don't know who wrote it. 5 | // Compiles with Visual Studio 6.0 on Windows XP. Tab size=3. 6 | // 7 | #pragma once 8 | #include "Subclass.h" 9 | 10 | //////////////// 11 | // CTrayIcon manages an icon in the Windows system tray. 12 | // The sample program TRAYTEST shows how to use it. 13 | // 14 | class CTrayIcon : public CCmdTarget { 15 | public: 16 | CTrayIcon(UINT uID); 17 | ~CTrayIcon(); 18 | 19 | // Call this to receive tray notifications 20 | void SetNotificationWnd(CWnd* pNotifyWnd, UINT uCbMsg); 21 | 22 | // SetIcon functions. To remove icon, call SetIcon(0) 23 | // 24 | BOOL SetIcon(UINT uID); // main variant you want to use 25 | BOOL SetIcon(HICON hicon, LPCTSTR lpTip); 26 | BOOL SetIcon(LPCTSTR lpResName, LPCTSTR lpTip) 27 | { return SetIcon(lpResName ? 28 | AfxGetApp()->LoadIcon(lpResName) : NULL, lpTip); } 29 | 30 | BOOL SetVersion(UINT uVersion); 31 | 32 | // Show balloon tip 33 | BOOL ShowBalloonTip(LPCTSTR szMsg, LPCTSTR szTitle, 34 | UINT uTimeout, DWORD dwInfoFlags=NIIF_INFO); 35 | 36 | // Show balloon tip: use resource ID instead of LPCSTR. 37 | BOOL ShowBalloonTip(UINT uID, LPCTSTR szTitle, 38 | UINT uTimeout, DWORD dwInfoFlags=NIIF_INFO); 39 | 40 | BOOL SetStandardIcon(LPCTSTR lpszIconName, LPCTSTR lpTip) 41 | { return SetIcon(::LoadIcon(NULL, lpszIconName), lpTip); } 42 | 43 | // Following is obsolete. CTrayIcon does default handling auotmatically. 44 | // virtual LRESULT OnTrayNotification(WPARAM uID, LPARAM lEvent); 45 | virtual LRESULT OnTrayNotify(WPARAM uID, LPARAM lEvent); 46 | virtual LRESULT OnTaskBarCreate(WPARAM wp, LPARAM lp); 47 | 48 | protected: 49 | NOTIFYICONDATA m_nid; // struct for Shell_NotifyIcon args 50 | 51 | // private class used to hook tray notification and taskbarcreated 52 | class CTrayHook : public CSubclassWnd { 53 | private: 54 | CTrayIcon* m_pTrayIcon; 55 | virtual LRESULT WindowProc(UINT msg, WPARAM wp, LPARAM lp); 56 | friend CTrayIcon; 57 | }; 58 | friend CTrayHook; 59 | CTrayHook m_notifyHook; // trap tray notifications 60 | CTrayHook m_parentHook; // trap taskbarcreated message 61 | DECLARE_DYNAMIC(CTrayIcon) 62 | }; 63 | -------------------------------------------------------------------------------- /exe/MakePolicyFile/PathSelectDlg.cpp: -------------------------------------------------------------------------------- 1 | #include "StdAfx.h" 2 | #include 3 | #include "PathSelectDlg.h" 4 | 5 | CPathSelectDlg::CPathSelectDlg(CWnd * hwndOwner /*=NULL*/, CString strTitle /*=L""*/) : m_hwndOwner(hwndOwner ? hwndOwner->m_hWnd : NULL), m_strTitle(strTitle) 6 | { 7 | } 8 | 9 | CPathSelectDlg::~CPathSelectDlg(void) 10 | { 11 | } 12 | 13 | BOOL CPathSelectDlg::DoModal() 14 | { 15 | LPMALLOC pMalloc; 16 | if (SHGetMalloc(&pMalloc) != NOERROR) 17 | { 18 | return FALSE; 19 | } 20 | BROWSEINFO bInfo; 21 | LPITEMIDLIST pidl; 22 | ZeroMemory((PVOID)&bInfo, sizeof(BROWSEINFO)); 23 | 24 | if (!m_strInitDir.IsEmpty()) 25 | { 26 | OLECHAR olePath[MAX_PATH]; 27 | ULONG chEaten; 28 | ULONG dwAttributes; 29 | HRESULT hr; 30 | LPSHELLFOLDER pDesktopFolder; 31 | // Get a pointer to the Desktop's IShellFolder interface. // 32 | if (SUCCEEDED(SHGetDesktopFolder(&pDesktopFolder))) 33 | { 34 | // 35 | // IShellFolder::ParseDisplayName requires the file name be in Unicode. 36 | // 37 | #ifdef UNICODE 38 | wcscpy_s(olePath, m_strInitDir.GetBuffer()); 39 | #else 40 | MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, m_strInitDir.GetBuffer(MAX_PATH), -1, olePath, MAX_PATH); 41 | m_strInitDir.ReleaseBuffer(-1); 42 | #endif 43 | // 44 | // Convert the path to an ITEMIDLIST. 45 | // 46 | hr = pDesktopFolder->ParseDisplayName(NULL, NULL, olePath, &chEaten, &pidl, &dwAttributes); 47 | if (FAILED(hr)) 48 | { 49 | pMalloc->Free(pidl); 50 | pMalloc->Release(); 51 | return FALSE; 52 | } 53 | bInfo.pidlRoot = pidl; 54 | } 55 | } 56 | 57 | bInfo.hwndOwner = (m_hwndOwner) ? m_hwndOwner : NULL; 58 | bInfo.pszDisplayName = m_strPath.GetBuffer(MAX_PATH); 59 | bInfo.lpszTitle = (m_strTitle.IsEmpty()) ? "Open" : m_strTitle; 60 | bInfo.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS; 61 | 62 | if ((pidl = ::SHBrowseForFolder(&bInfo)) == NULL) 63 | { 64 | return FALSE; 65 | } 66 | m_strPath.ReleaseBuffer(); 67 | m_iImageIndex = bInfo.iImage; 68 | 69 | if (::SHGetPathFromIDList(pidl, m_strPath.GetBuffer(MAX_PATH)) == FALSE) 70 | { 71 | pMalloc->Free(pidl); 72 | pMalloc->Release(); 73 | return FALSE; 74 | } 75 | 76 | m_strPath.ReleaseBuffer(); 77 | 78 | pMalloc->Free(pidl); 79 | pMalloc->Release(); 80 | return TRUE; 81 | } 82 | -------------------------------------------------------------------------------- /drv/kdarpshd/Inst/kdarp_m.inf: -------------------------------------------------------------------------------- 1 | ; -- KDARP_M.INF -- 2 | ; 3 | ; Passsthru Miniport INF file 4 | ; 5 | ; Copyright (c) 1993-1999, Microsoft Corporation 6 | 7 | ; ---------------------------------------------------------------------- 8 | ; Notes: 9 | ; 0. The term "filter" is used here to refer to an NDIS IM driver that 10 | ; implements a 1:1 relationship between upper and lower bindings. 11 | ; 1. Items specifically required for a filter have been marked with 12 | ; "!!--Filter Specific--!!" keyword 13 | ; 2. A filter DOES NOT require a notify object for proper installation. 14 | ; A notify object is only required if one wants to have better control 15 | ; over binding operations or if one wants to receive notifications 16 | ; when other components get installed/removed/bound/unbound. 17 | ; This sample uses a notify object as an example only. If you do not 18 | ; want to use a notify object, please comment out the lines that add 19 | ; ClsId and ComponentDll registry keys. 20 | ; ---------------------------------------------------------------------- 21 | 22 | [Version] 23 | signature = "$Windows NT$" 24 | Class = Net 25 | ClassGUID = {4d36e972-e325-11ce-bfc1-08002be10318} 26 | Provider = %Msft% 27 | DriverVer = 06/24/1999,5.00.2071.1 28 | 29 | [ControlFlags] 30 | ExcludeFromSelect = ms_kdarpshdmp 31 | 32 | [DestinationDirs] 33 | DefaultDestDir=12 34 | ; No files to copy 35 | 36 | [Manufacturer] 37 | %Msft% = MSFT 38 | 39 | [MSFT] 40 | %kdarpshdMP_Desc% = kdarpshdMP.ndi, ms_kdarpshdmp 41 | 42 | [kdarpshdMP.ndi] 43 | Characteristics = 0x29 ;NCF_NOT_USER_REMOVABLE | NCF_VIRTUAL | NCF_HIDDEN 44 | CopyFiles = 45 | 46 | [kdarpshdMP.ndi.Services] 47 | AddService = kdarpshd,0x2, kdarpshdMP.AddService 48 | 49 | 50 | [kdarpshdMP.AddService] 51 | DisplayName = %kdarpshdMP_Desc% 52 | ServiceType = 1 ;SERVICE_KERNEL_DRIVER 53 | StartType = 3 ;SERVICE_DEMAND_START 54 | ErrorControl = 1 ;SERVICE_ERROR_NORMAL 55 | ServiceBinary = %12%\kdarpshd.sys 56 | LoadOrderGroup = PNP_TDI 57 | AddReg = kdarpshdMP.AddService.AddReg 58 | 59 | 60 | [kdarpshdMP.AddService.AddReg] 61 | ; ---------------------------------------------------------------------- 62 | ; Add any miniport-specific parameters here. These are params that your 63 | ; filter device is going to use. 64 | ; 65 | ;HKR, Parameters, ParameterName, 0x10000, "MultiSz", "Parameter", "Value" 66 | ;HKR, Parameters, ParameterName2, 0x10001, 4 67 | 68 | [Strings] 69 | Msft = "Microsoft" 70 | kdarpshdMP_Desc = "kdarpshd Miniport" 71 | 72 | [SourceDisksNames] 73 | ;None 74 | 75 | [SourceDisksFiles] 76 | ;None 77 | 78 | 79 | -------------------------------------------------------------------------------- /drv/DrvShield/Cpprtl.h: -------------------------------------------------------------------------------- 1 | #ifndef __CPPRTL_H__ 2 | #define __CPPRTL_H__ 3 | 4 | EXTERN_C 5 | NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath); 6 | 7 | EXTERN_C 8 | VOID DriverUnload(IN PDRIVER_OBJECT DriverObject); 9 | 10 | EXTERN_C 11 | NTSTATUS MajorFunction(PDEVICE_OBJECT DeviceObject, PIRP Irp); 12 | 13 | class KDriver 14 | { 15 | friend NTSTATUS DriverEntry(IN PDRIVER_OBJECT, IN PUNICODE_STRING); 16 | friend VOID DriverUnload(IN PDRIVER_OBJECT DriverObject); 17 | friend NTSTATUS MajorFunction(PDEVICE_OBJECT DeviceObject, PIRP Irp); 18 | public: 19 | KDriver(); 20 | virtual ~KDriver(); 21 | protected: 22 | virtual NTSTATUS DriverEntry() = 0; 23 | virtual VOID DriverUnload(); 24 | virtual NTSTATUS MajorFunction(PDEVICE_OBJECT DeviceObject, PIRP Irp); 25 | virtual NTSTATUS IrpMajorCreate(PDEVICE_OBJECT DeviceObject, PIRP Irp); 26 | virtual NTSTATUS IrpMajorCreateNamedPipe(PDEVICE_OBJECT DeviceObject, PIRP Irp); 27 | virtual NTSTATUS IrpMajorClose(PDEVICE_OBJECT DeviceObject, PIRP Irp); 28 | virtual NTSTATUS IrpMajorRead(PDEVICE_OBJECT DeviceObject, PIRP Irp); 29 | virtual NTSTATUS IrpMajorWrite(PDEVICE_OBJECT DeviceObject, PIRP Irp); 30 | virtual NTSTATUS IrpMajorQueryInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp); 31 | virtual NTSTATUS IrpMajorSetInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp); 32 | virtual NTSTATUS IrpMajorQueryEa(PDEVICE_OBJECT DeviceObject, PIRP Irp); 33 | virtual NTSTATUS IrpMajorSetEa(PDEVICE_OBJECT DeviceObject, PIRP Irp); 34 | virtual NTSTATUS IrpMajorFlushBuffers(PDEVICE_OBJECT DeviceObject, PIRP Irp); 35 | virtual NTSTATUS IrpMajorQueryVolumeInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp); 36 | virtual NTSTATUS IrpMajorSetVolumeInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp); 37 | virtual NTSTATUS IrpMajorDirectoryControl(PDEVICE_OBJECT DeviceObject, PIRP Irp); 38 | virtual NTSTATUS IrpMajorFileSystemControl(PDEVICE_OBJECT DeviceObject, PIRP Irp); 39 | virtual NTSTATUS IrpMajorDeviceControl(PDEVICE_OBJECT DeviceObject, PIRP Irp); 40 | virtual NTSTATUS IrpMajorInternalDeviceControl(PDEVICE_OBJECT DeviceObject, PIRP Irp); 41 | virtual NTSTATUS IrpMajorShutdown(PDEVICE_OBJECT DeviceObject, PIRP Irp); 42 | virtual NTSTATUS IrpMajorLockControl(PDEVICE_OBJECT DeviceObject, PIRP Irp); 43 | virtual NTSTATUS IrpMajorCleanup(PDEVICE_OBJECT DeviceObject, PIRP Irp); 44 | virtual NTSTATUS IrpMajorCreateMailslot(PDEVICE_OBJECT DeviceObject, PIRP Irp); 45 | virtual NTSTATUS IrpMajorQuerySecurity(PDEVICE_OBJECT DeviceObject, PIRP Irp); 46 | virtual NTSTATUS IrpMajorSetSecurity(PDEVICE_OBJECT DeviceObject, PIRP Irp); 47 | virtual NTSTATUS IrpMajorPower(PDEVICE_OBJECT DeviceObject, PIRP Irp); 48 | virtual NTSTATUS IrpMajorSystemControl(PDEVICE_OBJECT DeviceObject, PIRP Irp); 49 | virtual NTSTATUS IrpMajorDeviceChange(PDEVICE_OBJECT DeviceObject, PIRP Irp); 50 | virtual NTSTATUS IrpMajorQueryQuota(PDEVICE_OBJECT DeviceObject, PIRP Irp); 51 | virtual NTSTATUS IrpMajorSetQuota(PDEVICE_OBJECT DeviceObject, PIRP Irp); 52 | virtual NTSTATUS IrpMajorPnp(PDEVICE_OBJECT DeviceObject, PIRP Irp); 53 | 54 | protected: 55 | PDRIVER_OBJECT m_DriverObject; 56 | UNICODE_STRING m_RegistryPath; 57 | WCHAR unStrBuf[512]; 58 | }; 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /exe/MakePolicyFile/MakePolicyFile.dsp: -------------------------------------------------------------------------------- 1 | # Microsoft Developer Studio Project File - Name="MakePolicyFile" - Package Owner=<4> 2 | # Microsoft Developer Studio Generated Build File, Format Version 6.00 3 | # ** DO NOT EDIT ** 4 | 5 | # TARGTYPE "Win32 (x86) Application" 0x0101 6 | 7 | CFG=MakePolicyFile - Win32 Debug 8 | !MESSAGE This is not a valid makefile. To build this project using NMAKE, 9 | !MESSAGE use the Export Makefile command and run 10 | !MESSAGE 11 | !MESSAGE NMAKE /f "MakePolicyFile.mak". 12 | !MESSAGE 13 | !MESSAGE You can specify a configuration when running NMAKE 14 | !MESSAGE by defining the macro CFG on the command line. For example: 15 | !MESSAGE 16 | !MESSAGE NMAKE /f "MakePolicyFile.mak" CFG="MakePolicyFile - Win32 Debug" 17 | !MESSAGE 18 | !MESSAGE Possible choices for configuration are: 19 | !MESSAGE 20 | !MESSAGE "MakePolicyFile - Win32 Release" (based on "Win32 (x86) Application") 21 | !MESSAGE "MakePolicyFile - Win32 Debug" (based on "Win32 (x86) Application") 22 | !MESSAGE 23 | 24 | # Begin Project 25 | # PROP AllowPerConfigDependencies 0 26 | # PROP Scc_ProjName "" 27 | # PROP Scc_LocalPath "" 28 | CPP=cl.exe 29 | MTL=midl.exe 30 | RSC=rc.exe 31 | 32 | !IF "$(CFG)" == "MakePolicyFile - Win32 Release" 33 | 34 | # PROP BASE Use_MFC 5 35 | # PROP BASE Use_Debug_Libraries 0 36 | # PROP BASE Output_Dir "Release" 37 | # PROP BASE Intermediate_Dir "Release" 38 | # PROP BASE Target_Dir "" 39 | # PROP Use_MFC 5 40 | # PROP Use_Debug_Libraries 0 41 | # PROP Output_Dir "Release" 42 | # PROP Intermediate_Dir "Release" 43 | # PROP Target_Dir "" 44 | # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /Yu"stdafx.h" /FD /c 45 | # ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /Yu"stdafx.h" /FD /c 46 | # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 47 | # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 48 | # ADD BASE RSC /l 0x804 /d "NDEBUG" 49 | # ADD RSC /l 0x804 /d "NDEBUG" 50 | BSC32=bscmake.exe 51 | # ADD BASE BSC32 /nologo 52 | # ADD BSC32 /nologo 53 | LINK32=link.exe 54 | # ADD BASE LINK32 /nologo /subsystem:windows /machine:I386 55 | # ADD LINK32 /nologo /subsystem:windows /machine:I386 56 | 57 | !ELSEIF "$(CFG)" == "MakePolicyFile - Win32 Debug" 58 | 59 | # PROP BASE Use_MFC 5 60 | # PROP BASE Use_Debug_Libraries 1 61 | # PROP BASE Output_Dir "Debug" 62 | # PROP BASE Intermediate_Dir "Debug" 63 | # PROP BASE Target_Dir "" 64 | # PROP Use_MFC 5 65 | # PROP Use_Debug_Libraries 1 66 | # PROP Output_Dir "Debug" 67 | # PROP Intermediate_Dir "Debug" 68 | # PROP Target_Dir "" 69 | # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /Yu"stdafx.h" /FD /GZ /c 70 | # ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "__RING_3__" /Yu"stdafx.h" /FD /GZ /c 71 | # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 72 | # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 73 | # ADD BASE RSC /l 0x804 /d "_DEBUG" 74 | # ADD RSC /l 0x804 /d "_DEBUG" 75 | BSC32=bscmake.exe 76 | # ADD BASE BSC32 /nologo 77 | # ADD BSC32 /nologo 78 | LINK32=link.exe 79 | # ADD BASE LINK32 /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept 80 | # ADD LINK32 /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept 81 | 82 | !ENDIF 83 | 84 | # Begin Target 85 | 86 | # Name "MakePolicyFile - Win32 Release" 87 | # Name "MakePolicyFile - Win32 Debug" 88 | # Begin Group "Source Files" 89 | 90 | # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" 91 | # Begin Source File 92 | 93 | SOURCE=.\MakePolicyFile.cpp 94 | # End Source File 95 | # Begin Source File 96 | 97 | SOURCE=.\MakePolicyFile.rc 98 | # End Source File 99 | # Begin Source File 100 | 101 | SOURCE=.\MakePolicyFileDlg.cpp 102 | # End Source File 103 | # Begin Source File 104 | 105 | SOURCE=.\md5.cpp 106 | # End Source File 107 | # Begin Source File 108 | 109 | SOURCE=.\PathSelectDlg.cpp 110 | # End Source File 111 | # Begin Source File 112 | 113 | SOURCE=.\StdAfx.cpp 114 | # ADD CPP /Yc"stdafx.h" 115 | # End Source File 116 | # End Group 117 | # Begin Group "Header Files" 118 | 119 | # PROP Default_Filter "h;hpp;hxx;hm;inl" 120 | # Begin Source File 121 | 122 | SOURCE=..\..\Drv\common.h 123 | # End Source File 124 | # Begin Source File 125 | 126 | SOURCE=.\MakePolicyFile.h 127 | # End Source File 128 | # Begin Source File 129 | 130 | SOURCE=.\MakePolicyFileDlg.h 131 | # End Source File 132 | # Begin Source File 133 | 134 | SOURCE=.\md5.h 135 | # End Source File 136 | # Begin Source File 137 | 138 | SOURCE=.\PathSelectDlg.h 139 | # End Source File 140 | # Begin Source File 141 | 142 | SOURCE=.\Resource.h 143 | # End Source File 144 | # Begin Source File 145 | 146 | SOURCE=.\StdAfx.h 147 | # End Source File 148 | # End Group 149 | # Begin Group "Resource Files" 150 | 151 | # PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" 152 | # Begin Source File 153 | 154 | SOURCE=.\res\MakePolicyFile.ico 155 | # End Source File 156 | # Begin Source File 157 | 158 | SOURCE=.\res\MakePolicyFile.rc2 159 | # End Source File 160 | # End Group 161 | # End Target 162 | # End Project 163 | -------------------------------------------------------------------------------- /exe/DrvShield/DrvShield.dsp: -------------------------------------------------------------------------------- 1 | # Microsoft Developer Studio Project File - Name="DrvShield" - Package Owner=<4> 2 | # Microsoft Developer Studio Generated Build File, Format Version 6.00 3 | # ** DO NOT EDIT ** 4 | 5 | # TARGTYPE "Win32 (x86) Application" 0x0101 6 | 7 | CFG=DrvShield - Win32 Debug 8 | !MESSAGE This is not a valid makefile. To build this project using NMAKE, 9 | !MESSAGE use the Export Makefile command and run 10 | !MESSAGE 11 | !MESSAGE NMAKE /f "DrvShield.mak". 12 | !MESSAGE 13 | !MESSAGE You can specify a configuration when running NMAKE 14 | !MESSAGE by defining the macro CFG on the command line. For example: 15 | !MESSAGE 16 | !MESSAGE NMAKE /f "DrvShield.mak" CFG="DrvShield - Win32 Debug" 17 | !MESSAGE 18 | !MESSAGE Possible choices for configuration are: 19 | !MESSAGE 20 | !MESSAGE "DrvShield - Win32 Release" (based on "Win32 (x86) Application") 21 | !MESSAGE "DrvShield - Win32 Debug" (based on "Win32 (x86) Application") 22 | !MESSAGE 23 | 24 | # Begin Project 25 | # PROP AllowPerConfigDependencies 0 26 | # PROP Scc_ProjName "" 27 | # PROP Scc_LocalPath "" 28 | CPP=cl.exe 29 | MTL=midl.exe 30 | RSC=rc.exe 31 | 32 | !IF "$(CFG)" == "DrvShield - Win32 Release" 33 | 34 | # PROP BASE Use_MFC 5 35 | # PROP BASE Use_Debug_Libraries 0 36 | # PROP BASE Output_Dir "Release" 37 | # PROP BASE Intermediate_Dir "Release" 38 | # PROP BASE Target_Dir "" 39 | # PROP Use_MFC 5 40 | # PROP Use_Debug_Libraries 0 41 | # PROP Output_Dir "Release" 42 | # PROP Intermediate_Dir "Release" 43 | # PROP Ignore_Export_Lib 0 44 | # PROP Target_Dir "" 45 | # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /Yu"stdafx.h" /FD /c 46 | # ADD CPP /MT /W3 /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /Yu"stdafx.h" /FD /c 47 | # SUBTRACT CPP /nologo 48 | # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 49 | # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 50 | # ADD BASE RSC /l 0x804 /d "NDEBUG" 51 | # ADD RSC /l 0x804 /d "NDEBUG" 52 | BSC32=bscmake.exe 53 | # ADD BASE BSC32 /nologo 54 | # ADD BSC32 /nologo 55 | LINK32=link.exe 56 | # ADD BASE LINK32 /nologo /subsystem:windows /machine:I386 57 | # ADD LINK32 /subsystem:windows /pdb:none /machine:I386 58 | # SUBTRACT LINK32 /nologo 59 | 60 | !ELSEIF "$(CFG)" == "DrvShield - Win32 Debug" 61 | 62 | # PROP BASE Use_MFC 5 63 | # PROP BASE Use_Debug_Libraries 1 64 | # PROP BASE Output_Dir "Debug" 65 | # PROP BASE Intermediate_Dir "Debug" 66 | # PROP BASE Target_Dir "" 67 | # PROP Use_MFC 5 68 | # PROP Use_Debug_Libraries 1 69 | # PROP Output_Dir "Debug" 70 | # PROP Intermediate_Dir "Debug" 71 | # PROP Target_Dir "" 72 | # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /Yu"stdafx.h" /FD /GZ /c 73 | # ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /Yu"stdafx.h" /FD /GZ /c 74 | # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 75 | # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 76 | # ADD BASE RSC /l 0x804 /d "_DEBUG" 77 | # ADD RSC /l 0x804 /d "_DEBUG" 78 | BSC32=bscmake.exe 79 | # ADD BASE BSC32 /nologo 80 | # ADD BSC32 /nologo 81 | LINK32=link.exe 82 | # ADD BASE LINK32 /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept 83 | # ADD LINK32 /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept 84 | 85 | !ENDIF 86 | 87 | # Begin Target 88 | 89 | # Name "DrvShield - Win32 Release" 90 | # Name "DrvShield - Win32 Debug" 91 | # Begin Group "Source Files" 92 | 93 | # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" 94 | # Begin Source File 95 | 96 | SOURCE=.\DrvShield.cpp 97 | # End Source File 98 | # Begin Source File 99 | 100 | SOURCE=.\DrvShield.rc 101 | # End Source File 102 | # Begin Source File 103 | 104 | SOURCE=.\DrvShieldDlg.cpp 105 | # End Source File 106 | # Begin Source File 107 | 108 | SOURCE=.\LoadDriver.cpp 109 | # End Source File 110 | # Begin Source File 111 | 112 | SOURCE=..\MakePolicyFile\md5.cpp 113 | # End Source File 114 | # Begin Source File 115 | 116 | SOURCE=.\StdAfx.cpp 117 | # ADD CPP /Yc"stdafx.h" 118 | # End Source File 119 | # Begin Source File 120 | 121 | SOURCE=.\Subclass.cpp 122 | # End Source File 123 | # Begin Source File 124 | 125 | SOURCE=.\TrayIcon.cpp 126 | # End Source File 127 | # End Group 128 | # Begin Group "Header Files" 129 | 130 | # PROP Default_Filter "h;hpp;hxx;hm;inl" 131 | # Begin Source File 132 | 133 | SOURCE=..\..\Drv\common.h 134 | # End Source File 135 | # Begin Source File 136 | 137 | SOURCE=.\DrvShield.h 138 | # End Source File 139 | # Begin Source File 140 | 141 | SOURCE=.\DrvShieldDlg.h 142 | # End Source File 143 | # Begin Source File 144 | 145 | SOURCE=.\LoadDriver.h 146 | # End Source File 147 | # Begin Source File 148 | 149 | SOURCE=..\MakePolicyFile\md5.h 150 | # End Source File 151 | # Begin Source File 152 | 153 | SOURCE=.\Resource.h 154 | # End Source File 155 | # Begin Source File 156 | 157 | SOURCE=.\StdAfx.h 158 | # End Source File 159 | # Begin Source File 160 | 161 | SOURCE=.\Subclass.h 162 | # End Source File 163 | # Begin Source File 164 | 165 | SOURCE=.\TrayIcon.h 166 | # End Source File 167 | # End Group 168 | # Begin Group "Resource Files" 169 | 170 | # PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" 171 | # Begin Source File 172 | 173 | SOURCE=.\res\DrvShield.ico 174 | # End Source File 175 | # Begin Source File 176 | 177 | SOURCE=.\res\DrvShield.rc2 178 | # End Source File 179 | # End Group 180 | # Begin Source File 181 | 182 | SOURCE=.\res\DrvShield.sys 183 | # End Source File 184 | # End Target 185 | # End Project 186 | -------------------------------------------------------------------------------- /drv/kdarpshd/Inst/kdarp.inf: -------------------------------------------------------------------------------- 1 | ; -- KDARP.INF -- 2 | ; 3 | ; kdarpshd driver INF file - this is the INF for the service (protocol) 4 | ; part. 5 | ; 6 | ; Copyright (c) 1993-2001, Microsoft Corporation 7 | ; 8 | ; ---------------------------------------------------------------------- 9 | ; Notes: 10 | ; 0. The term "filter" is used in this INF to refer to an NDIS IM driver that 11 | ; implements a 1:1 relationship between upper and lower bindings. 12 | ; 13 | ; 1. Items specifically required for a filter have been marked with 14 | ; "!!--Filter Specific--!!" keyword 15 | ; 2. In general a filter DOES NOT require a notify object for proper installation. 16 | ; A notify object is only required if one wants to have better control 17 | ; over binding operations or if one wants to receive notifications 18 | ; when other components get installed/removed/bound/unbound. 19 | ; Since Windows 2000 systems do not have support for CopyINF directive, 20 | ; a notify object is required to programmatically copy the miniport INF 21 | ; file to the system INF directory. Previous versions of this INF file 22 | ; erroneously used to copy the INF files directly by using the CopyFiles 23 | ; directive. 24 | ; On Windows XP, you can install a filter IM without a notify object. 25 | ; by following the instructions in (4). 26 | ; 27 | ; 3. If you want to use this INF file with your own IM driver, please 28 | ; make the following modifications: 29 | ; File kdarp.inf 30 | ; -------------- 31 | ; a. In section [SourceDiskFiles] and [kdarpshd.Files.Sys] 32 | ; change kdarpshd.sys to the name of your own driver binary. 33 | ; b. In section [kdarpshd.ndi.AddReg], change values of 34 | ; BindForm and MiniportId to appropriate values. 35 | ; File kdarp_m.inf 36 | ; ---------------- 37 | ; a. Replace MS_kdarpshdMP with InfId of your miniport. 38 | ; b. In section [kdarpshdMP.AddService], 39 | ; change ServiceBinary appropriately. 40 | ; c. In section [kdarpshdMP.ndi.AddReg], 41 | ; change "kdarpshd" in the line having "Service" 42 | ; to reflect the appropriate name 43 | ; 44 | ; 4. If you want to use this INF for installing the kdarpshd IM without 45 | ; the notify object, do the following: 46 | ; a. In section [kdarpshd.ndi.AddReg], 47 | ; Comment out lines having ClsId and ComponentDll 48 | ; b. In section [kdarpshd.ndi], 49 | ; change the value of Characteristics so that it does not have 50 | ; the NCF_HAS_UI flag 51 | ; c. In section [SourceDiskFiles], comment out the line having kdarpshd.dll 52 | ; d. In section [kdarpshd.ndi], remove kdarpshd.Files.Init from the 53 | ; CopyFiles line. 54 | ; 55 | ; ---------------------------------------------------------------------- 56 | 57 | [Version] 58 | Signature = "$Windows NT$" 59 | Class = NetService 60 | ClassGUID = {4D36E974-E325-11CE-BFC1-08002BE10318} 61 | Provider = %Msft% 62 | DriverVer = 06/24/1999,5.00.2071.1 63 | 64 | 65 | [Manufacturer] 66 | %Msft% = MSFT 67 | 68 | [ControlFlags] 69 | 70 | ;========================================================================= 71 | ; 72 | ;========================================================================= 73 | 74 | [MSFT] 75 | %kdarpshd_Desc% = kdarpshd.ndi, ms_kdarpshd 76 | 77 | 78 | [kdarpshd.ndi] 79 | AddReg = kdarpshd.ndi.AddReg, kdarpshd.AddReg 80 | Characteristics = 0x4410 ; NCF_FILTER | NCF_NO_SERVICE | NCF_NDIS_PROTOCOL !--Filter Specific--!! 81 | CopyFiles = kdarpshd.Files.Sys 82 | CopyInf = kdarp_m.inf 83 | 84 | [kdarpshd.ndi.Remove] 85 | DelFiles = kdarpshd.Files.Init, kdarpshd.Files.Sys 86 | 87 | [kdarpshd.ndi.Remove.Services] 88 | DelService = kdarpshd 89 | 90 | ; ---------------------------------------------------------------------- 91 | ; File copy 92 | ; 93 | [SourceDisksNames] 94 | 1=%DiskDescription%,"",, 95 | 96 | [SourceDisksFiles] 97 | kdarpshd.sys=1 98 | kdarp_m.inf=1 99 | 100 | [DestinationDirs] 101 | DefaultDestDir = 12 102 | kdarpshd.Files.Init = 11 ; %windir%\System32 103 | kdarpshd.Files.Sys = 12 ; %windir%\System32\drivers 104 | 105 | ; Copying of kdarpshd.dll is required only if the filter has a Notify object 106 | [kdarpshd.Files.Init] 107 | kdarpshd.dll,,,2 108 | 109 | [kdarpshd.Files.Sys] 110 | kdarpshd.sys,,,2 111 | 112 | [InfSourcePathInfo] 113 | ; Used by the notify object to figure out where the original media is 114 | ; located (so it can use SetupCopyOEMInf to install Net INF located 115 | ; there). 116 | 117 | OriginalInfSourcePath = %1% 118 | 119 | ; ---------------------------------------------------------------------- 120 | ; Filter Install 121 | ; 122 | 123 | [kdarpshd.ndi.AddReg] 124 | HKR, Ndi, HelpText, , %kdarpshd_HELP% 125 | 126 | ; ---------------------------------------------------------------------- 127 | ; Keys required if a Notify object is present 128 | ; These keys should be omitted if the Filter does not have any Notify object 129 | ; 130 | ; Note: 131 | ; 1. Only include the following lines if your filter has configuration UI 132 | ; that needs to be displayed. Otherwise, you should not need a notify 133 | ; object. 134 | ; 2. If you write your own notifyobject, use a different GUID for ClsID!! 135 | ; (Generate this with uuidgen.exe) 136 | ; 137 | ; ---------------------------------------------------------------------- 138 | ; !!--Filter Specific--!! 139 | ; 140 | ; Note: 141 | ; 1. Other components may also have UpperRange/LowerRange but for filters 142 | ; the value of both of them must be noupper/nolower 143 | ; 2. The value FilterClass is required. 144 | ; 3. The value Service is required 145 | ; 4. FilterDeviceInfId is the InfId of the filter device (miniport) that will 146 | ; be installed for each filtered adapter. 147 | ; In this case this is ms_kdarpshdmp (refer to kdarp_m.inf) 148 | ; 149 | HKR, Ndi, FilterClass, , failover 150 | HKR, Ndi, FilterDeviceInfId, , ms_kdarpshdmp 151 | HKR, Ndi, Service, , kdarpshd 152 | HKR, Ndi\Interfaces, UpperRange, , noupper 153 | HKR, Ndi\Interfaces, LowerRange, , nolower 154 | HKR, Ndi\Interfaces, FilterMediaTypes, , "ethernet, tokenring, fddi, wan" 155 | 156 | [kdarpshd.AddReg] 157 | ; The following key is Required 158 | ; The following key is kdarpshd specific 159 | HKR, Parameters, Param1, 0, 4 160 | 161 | ; ---------------------------------------------------------------------- 162 | [Strings] 163 | Msft = "Microsoft" 164 | DiskDescription = "Microsoft kdarpshd Driver Disk" 165 | 166 | kdarpshd_Desc = "kdarpshd Driver" 167 | kdarpshd_HELP = "kdarpshd Driver" 168 | 169 | 170 | -------------------------------------------------------------------------------- /exe/DrvShield/Subclass.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////// 2 | // If this code works, it was written by Paul DiLascia. 3 | // If not, I don't know who wrote it. 4 | // 5 | // CSubclassWnd is a generic class for hooking another window's messages. 6 | 7 | #include "StdAfx.h" 8 | #include "Subclass.h" 9 | 10 | #ifdef _DEBUG 11 | #define new DEBUG_NEW 12 | #undef THIS_FILE 13 | static char THIS_FILE[] = __FILE__; 14 | #endif 15 | 16 | ////////////////// 17 | // The message hook map is derived from CMapPtrToPtr, which associates 18 | // a pointer with another pointer. It maps an HWND to a CSubclassWnd, like 19 | // the way MFC's internal maps map HWND's to CWnd's. The first CSubclassWnd 20 | // attached to a window is stored in the map; all other CSubclassWnd's for that 21 | // window are then chained via CSubclassWnd::m_pNext. 22 | // 23 | class CSubclassWndMap : private CMapPtrToPtr { 24 | public: 25 | CSubclassWndMap(); 26 | ~CSubclassWndMap(); 27 | static CSubclassWndMap& GetHookMap(); 28 | void Add(HWND hwnd, CSubclassWnd* pSubclassWnd); 29 | void Remove(CSubclassWnd* pSubclassWnd); 30 | void RemoveAll(HWND hwnd); 31 | CSubclassWnd* Lookup(HWND hwnd); 32 | }; 33 | 34 | // This trick is used so the hook map isn't 35 | // instantiated until someone actually requests it. 36 | // 37 | #define theHookMap (CSubclassWndMap::GetHookMap()) 38 | 39 | IMPLEMENT_DYNAMIC(CSubclassWnd, CWnd); 40 | 41 | CSubclassWnd::CSubclassWnd() 42 | { 43 | m_pNext = NULL; 44 | m_pOldWndProc = NULL; 45 | m_hWnd = NULL; 46 | } 47 | 48 | CSubclassWnd::~CSubclassWnd() 49 | { 50 | if (m_hWnd) 51 | HookWindow((HWND)NULL); // unhook window 52 | } 53 | 54 | ////////////////// 55 | // Hook a window. 56 | // This installs a new window proc that directs messages to the CSubclassWnd. 57 | // pWnd=NULL to remove. 58 | // 59 | BOOL CSubclassWnd::HookWindow(HWND hwnd) 60 | { 61 | ASSERT_VALID(this); 62 | if (hwnd) { 63 | // Hook the window 64 | ASSERT(m_hWnd==NULL); 65 | ASSERT(::IsWindow(hwnd)); 66 | theHookMap.Add(hwnd, this); // Add to map of hooks 67 | 68 | } else if (m_hWnd) { 69 | // Unhook the window 70 | theHookMap.Remove(this); // Remove from map 71 | m_pOldWndProc = NULL; 72 | } 73 | m_hWnd = hwnd; 74 | return TRUE; 75 | } 76 | 77 | ////////////////// 78 | // Window proc-like virtual function which specific CSubclassWnds will 79 | // override to do stuff. Default passes the message to the next hook; 80 | // the last hook passes the message to the original window. 81 | // You MUST call this at the end of your WindowProc if you want the real 82 | // window to get the message. This is just like CWnd::WindowProc, except that 83 | // a CSubclassWnd is not a window. 84 | // 85 | LRESULT CSubclassWnd::WindowProc(UINT msg, WPARAM wp, LPARAM lp) 86 | { 87 | // ASSERT_VALID(this); // removed for speed 88 | ASSERT(m_pOldWndProc); 89 | return m_pNext ? m_pNext->WindowProc(msg, wp, lp) : 90 | ::CallWindowProc(m_pOldWndProc, m_hWnd, msg, wp, lp); 91 | } 92 | 93 | ////////////////// 94 | // Like calling base class WindowProc, but with no args, so individual 95 | // message handlers can do the default thing. Like CWnd::Default 96 | // 97 | LRESULT CSubclassWnd::Default() 98 | { 99 | // MFC stores current MSG in thread state 100 | MSG& curMsg = AfxGetThreadState()->m_lastSentMsg; 101 | // Note: must explicitly call CSubclassWnd::WindowProc to avoid infinte 102 | // recursion on virtual function 103 | return CSubclassWnd::WindowProc(curMsg.message, curMsg.wParam, curMsg.lParam); 104 | } 105 | 106 | #ifdef _DEBUG 107 | void CSubclassWnd::AssertValid() const 108 | { 109 | CObject::AssertValid(); 110 | ASSERT(m_hWnd==NULL || ::IsWindow(m_hWnd)); 111 | if (m_hWnd) { 112 | for (CSubclassWnd* p = theHookMap.Lookup(m_hWnd); p; p=p->m_pNext) { 113 | if (p==this) 114 | break; 115 | } 116 | ASSERT(p); // should have found it! 117 | } 118 | } 119 | 120 | void CSubclassWnd::Dump(CDumpContext& dc) const 121 | { 122 | CObject::Dump(dc); 123 | } 124 | 125 | #endif 126 | 127 | ////////////////// 128 | // Subclassed window proc for message hooks. Replaces AfxWndProc (or whatever 129 | // else was there before.) 130 | // 131 | LRESULT CALLBACK 132 | HookWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) 133 | { 134 | #ifdef _USRDLL 135 | // If this is a DLL, need to set up MFC state 136 | AFX_MANAGE_STATE(AfxGetStaticModuleState()); 137 | #endif 138 | 139 | // Set up MFC message state just in case anyone wants it 140 | // This is just like AfxCallWindowProc, but we can't use that because 141 | // a CSubclassWnd is not a CWnd. 142 | // 143 | MSG& curMsg = AfxGetThreadState()->m_lastSentMsg; 144 | MSG oldMsg = curMsg; // save for nesting 145 | curMsg.hwnd = hwnd; 146 | curMsg.message = msg; 147 | curMsg.wParam = wp; 148 | curMsg.lParam = lp; 149 | 150 | // Get hook object for this window. Get from hook map 151 | CSubclassWnd* pSubclassWnd = theHookMap.Lookup(hwnd); 152 | ASSERT(pSubclassWnd); 153 | 154 | LRESULT lr; 155 | if (msg==WM_NCDESTROY) { 156 | // Window is being destroyed: unhook all hooks (for this window) 157 | // and pass msg to orginal window proc 158 | // 159 | WNDPROC wndproc = pSubclassWnd->m_pOldWndProc; 160 | theHookMap.RemoveAll(hwnd); 161 | lr = ::CallWindowProc(wndproc, hwnd, msg, wp, lp); 162 | 163 | } else { 164 | // pass to msg hook 165 | lr = pSubclassWnd->WindowProc(msg, wp, lp); 166 | } 167 | curMsg = oldMsg; // pop state 168 | return lr; 169 | } 170 | 171 | //////////////////////////////////////////////////////////////// 172 | // CSubclassWndMap implementation 173 | // 174 | CSubclassWndMap::CSubclassWndMap() 175 | { 176 | } 177 | 178 | CSubclassWndMap::~CSubclassWndMap() 179 | { 180 | // This assert bombs when posting WM_QUIT, so I've deleted it. 181 | // ASSERT(IsEmpty()); // all hooks should be removed! 182 | } 183 | 184 | ////////////////// 185 | // Get the one and only global hook map 186 | // 187 | CSubclassWndMap& CSubclassWndMap::GetHookMap() 188 | { 189 | // By creating theMap here, C++ doesn't instantiate it until/unless 190 | // it's ever used! This is a good trick to use in C++, to 191 | // instantiate/initialize a static object the first time it's used. 192 | // 193 | static CSubclassWndMap theMap; 194 | return theMap; 195 | } 196 | 197 | ///////////////// 198 | // Add hook to map; i.e., associate hook with window 199 | // 200 | void CSubclassWndMap::Add(HWND hwnd, CSubclassWnd* pSubclassWnd) 201 | { 202 | ASSERT(hwnd && ::IsWindow(hwnd)); 203 | 204 | // Add to front of list 205 | pSubclassWnd->m_pNext = Lookup(hwnd); 206 | SetAt(hwnd, pSubclassWnd); 207 | 208 | if (pSubclassWnd->m_pNext==NULL) { 209 | // If this is the first hook added, subclass the window 210 | pSubclassWnd->m_pOldWndProc = 211 | (WNDPROC)SetWindowLong(hwnd, GWL_WNDPROC, (DWORD)HookWndProc); 212 | 213 | } else { 214 | // just copy wndproc from next hook 215 | pSubclassWnd->m_pOldWndProc = pSubclassWnd->m_pNext->m_pOldWndProc; 216 | } 217 | ASSERT(pSubclassWnd->m_pOldWndProc); 218 | } 219 | 220 | ////////////////// 221 | // Remove hook from map 222 | // 223 | void CSubclassWndMap::Remove(CSubclassWnd* pUnHook) 224 | { 225 | HWND hwnd = pUnHook->m_hWnd; 226 | ASSERT(hwnd && ::IsWindow(hwnd)); 227 | 228 | CSubclassWnd* pHook = Lookup(hwnd); 229 | ASSERT(pHook); 230 | if (pHook==pUnHook) { 231 | // hook to remove is the one in the hash table: replace w/next 232 | if (pHook->m_pNext) 233 | SetAt(hwnd, pHook->m_pNext); 234 | else { 235 | // This is the last hook for this window: restore wnd proc 236 | RemoveKey(hwnd); 237 | SetWindowLong(hwnd, GWL_WNDPROC, (DWORD)pHook->m_pOldWndProc); 238 | } 239 | } else { 240 | // Hook to remove is in the middle: just remove from linked list 241 | while (pHook->m_pNext!=pUnHook) 242 | pHook = pHook->m_pNext; 243 | ASSERT(pHook && pHook->m_pNext==pUnHook); 244 | pHook->m_pNext = pUnHook->m_pNext; 245 | } 246 | } 247 | 248 | ////////////////// 249 | // Remove all the hooks for a window 250 | // 251 | void CSubclassWndMap::RemoveAll(HWND hwnd) 252 | { 253 | CSubclassWnd* pSubclassWnd; 254 | while ((pSubclassWnd = Lookup(hwnd))!=NULL) 255 | pSubclassWnd->HookWindow((HWND)NULL); // (unhook) 256 | } 257 | 258 | ///////////////// 259 | // Find first hook associate with window 260 | // 261 | CSubclassWnd* CSubclassWndMap::Lookup(HWND hwnd) 262 | { 263 | CSubclassWnd* pFound = NULL; 264 | if (!CMapPtrToPtr::Lookup(hwnd, (void*&)pFound)) 265 | return NULL; 266 | ASSERT_KINDOF(CSubclassWnd, pFound); 267 | return pFound; 268 | } 269 | 270 | -------------------------------------------------------------------------------- /drv/DrvShield/DrvShield.cpp: -------------------------------------------------------------------------------- 1 | #include "std.h" 2 | #include "Cpprtl.h" 3 | #include "DrvShield.h" 4 | #include "Sysmon.h" 5 | #include "HookSSDT.h" 6 | #include "md5.h" 7 | #include "Hash.h" 8 | 9 | PDEVICE_OBJECT GlobalDeviceObject = NULL; 10 | 11 | KDrvShieldDriver theDriver; 12 | 13 | NTSTATUS KDrvShieldDriver::IrpMajorCreate(PDEVICE_OBJECT DeviceObject, PIRP Irp) 14 | { 15 | PDEVICE_EXTENSION DevExtsion = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension; 16 | if (!DevExtsion->DeviceOpen) 17 | { 18 | KIRQL Irql; 19 | KeAcquireSpinLock(&DevExtsion->SpinLock, &Irql); 20 | DevExtsion->DeviceOpen = TRUE; 21 | KeReleaseSpinLock(&DevExtsion->SpinLock, Irql); 22 | } 23 | Irp->IoStatus.Information = 0; 24 | Irp->IoStatus.Status = STATUS_SUCCESS; 25 | IoCompleteRequest(Irp, IO_NO_INCREMENT); 26 | return STATUS_SUCCESS; 27 | } 28 | 29 | NTSTATUS KDrvShieldDriver::IrpMajorClose(PDEVICE_OBJECT DeviceObject, PIRP Irp) 30 | { 31 | PDEVICE_EXTENSION DevExtsion = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension; 32 | if (DevExtsion->DeviceOpen) 33 | { 34 | KIRQL Irql; 35 | KeAcquireSpinLock(&DevExtsion->SpinLock, &Irql); 36 | DevExtsion->DeviceOpen = FALSE; 37 | KeReleaseSpinLock(&DevExtsion->SpinLock, Irql); 38 | } 39 | Irp->IoStatus.Information = 0; 40 | Irp->IoStatus.Status = STATUS_SUCCESS; 41 | IoCompleteRequest(Irp, IO_NO_INCREMENT); 42 | return STATUS_SUCCESS; 43 | } 44 | 45 | NTSTATUS KDrvShieldDriver::IrpMajorDeviceControl(PDEVICE_OBJECT DeviceObject, PIRP Irp) 46 | { 47 | KIRQL Irql; 48 | ULONG uInformation = 0; 49 | NTSTATUS status = STATUS_SUCCESS; 50 | PIO_STACK_LOCATION irpSp = IoGetCurrentIrpStackLocation(Irp); 51 | PDEVICE_EXTENSION DevExtsion = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension; 52 | 53 | switch(irpSp->Parameters.DeviceIoControl.IoControlCode) 54 | { 55 | case IOCTL_SYS_DRV_MON_SET: 56 | if (DevExtsion->DeviceOpen && !DevExtsion->StartSysMon) 57 | { 58 | CHAR Md5Digest[128] = {0}; 59 | ANSI_STRING anWorkPath; 60 | UNICODE_STRING unWorkPath; 61 | ULONG Length = irpSp->Parameters.DeviceIoControl.InputBufferLength; 62 | PPARAMETER_BLOCK_DATA ParamBlock = (PPARAMETER_BLOCK_DATA)Irp->AssociatedIrp.SystemBuffer; 63 | if ( 64 | Length >= sizeof(PARAMETER_BLOCK_DATA) + 32 && 65 | ParamBlock->ParamBlockMagic == ParamBlockMagicFlag && 66 | ParamBlock->DrvAntiData.DataMagic == FileMagicFlag 67 | ) 68 | { 69 | RtlInitAnsiString(&anWorkPath, ParamBlock->WorkPath); 70 | RtlAnsiStringToUnicodeString(&unWorkPath, &anWorkPath, TRUE); 71 | unWorkPath.Buffer[unWorkPath.Length/sizeof(WCHAR)] = 0; 72 | wcscpy(DevExtsion->WorkSavePath, L"\\??\\"); 73 | wcscat(DevExtsion->WorkSavePath, unWorkPath.Buffer); 74 | RtlFreeUnicodeString(&unWorkPath); 75 | 76 | DevExtsion->DrvAntiData = (PDRV_ANTI_DATA)ExAllocatePool(NonPagedPool, ParamBlock->DataSize); 77 | memcpy(DevExtsion->DrvAntiData, &ParamBlock->DrvAntiData, ParamBlock->DataSize); 78 | 79 | md5(DevExtsion->DrvAntiData, ParamBlock->DataSize-32, Md5Digest); 80 | 81 | if (memcmp(((PCHAR)DevExtsion->DrvAntiData)+(ParamBlock->DataSize-32), Md5Digest, 32) == 0) 82 | { 83 | ULONG i; 84 | HashTableInit(DevExtsion->DrvAntiData->Count); 85 | for (i = 0; i < DevExtsion->DrvAntiData->Count; i++) 86 | { 87 | InsertHashTable(DevExtsion->DrvAntiData->DrvInfoEntry[i]); 88 | } 89 | KeAcquireSpinLock(&DevExtsion->SpinLock, &Irql); 90 | DevExtsion->StartSysMon = TRUE; 91 | KeReleaseSpinLock(&DevExtsion->SpinLock, Irql); 92 | } 93 | } 94 | } 95 | else 96 | { 97 | status = STATUS_INVALID_PARAMETER; 98 | } 99 | break; 100 | 101 | case IOCTL_SYS_ADD_PROCESSID: 102 | if (DevExtsion->DeviceOpen) 103 | { 104 | PPARAMETER_BLOCK_PROCESS_ID ParamBlock = (PPARAMETER_BLOCK_PROCESS_ID)Irp->AssociatedIrp.SystemBuffer; 105 | if (ParamBlock->ParamBlockMagic == ParamBlockMagicFlag) 106 | { 107 | KeAcquireSpinLock(&DevExtsion->SpinLock, &Irql); 108 | AddProcessProtectList(ParamBlock->ProcessID); 109 | DevExtsion->StartHook = TRUE; 110 | KeReleaseSpinLock(&DevExtsion->SpinLock, Irql); 111 | } 112 | else 113 | { 114 | status = STATUS_INVALID_PARAMETER; 115 | } 116 | } 117 | break; 118 | 119 | case IOCTL_SYS_QUERY_DRIVER: 120 | if ( 121 | DevExtsion->StartSysMon && 122 | irpSp->Parameters.DeviceIoControl.OutputBufferLength >= sizeof(DevExtsion->CaptureDriverPathName) 123 | ) 124 | { 125 | strcpy((PCHAR)Irp->AssociatedIrp.SystemBuffer, DevExtsion->CaptureDriverPathName); 126 | uInformation = strlen(DevExtsion->CaptureDriverPathName); 127 | } 128 | else 129 | { 130 | status = STATUS_INVALID_PARAMETER; 131 | } 132 | break; 133 | 134 | case IOCTL_SYS_QUERY_COMPLETE: 135 | if (DevExtsion->StartSysMon) 136 | { 137 | KeSetEvent(DevExtsion->obDriverClearedEvent, IO_NO_INCREMENT, FALSE); 138 | } 139 | break; 140 | 141 | default: 142 | status = STATUS_INVALID_PARAMETER; 143 | break; 144 | } 145 | Irp->IoStatus.Information = uInformation; 146 | Irp->IoStatus.Status = status; 147 | IoCompleteRequest(Irp, IO_NO_INCREMENT); 148 | return status; 149 | } 150 | 151 | NTSTATUS KDrvShieldDriver::DriverEntry() 152 | { 153 | BOOLEAN bSymbolicLinkClear = FALSE; 154 | NTSTATUS status = STATUS_SUCCESS; 155 | PDEVICE_EXTENSION DevExtsion; 156 | DECLARE_UNICODE_STRING(unDeviceName, L"\\Device\\KeydoneSysMon") 157 | DECLARE_UNICODE_STRING(unSymbolicLinkName, L"\\DosDevices\\Global\\KeydoneSysMon") 158 | DECLARE_UNICODE_STRING(unDriverEntryEvent, L"\\BaseNamedObjects\\KDDriverEntryEvent") 159 | DECLARE_UNICODE_STRING(unDriverProcessedEvent, L"\\BaseNamedObjects\\KDDriverProcessedEvent") 160 | DECLARE_UNICODE_STRING(unDriverClearedEvent, L"\\BaseNamedObjects\\KDDriverClearedEvent") 161 | 162 | __try 163 | { 164 | ULONG uCount = 0; 165 | PPHYSICAL_MEMORY_RANGE CurPhyMemRange = NULL; 166 | PPHYSICAL_MEMORY_RANGE PhysicalMemoryRange = NULL; 167 | status = SWHookInit(); 168 | if (!NT_SUCCESS(status)) 169 | { 170 | __leave; 171 | } 172 | status = IoCreateDevice(m_DriverObject, sizeof(DEVICE_EXTENSION), &unDeviceName, FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN, FALSE, &GlobalDeviceObject); 173 | if (!NT_SUCCESS(status)) 174 | { 175 | __leave; 176 | } 177 | GlobalDeviceObject->Flags |= DO_DIRECT_IO; 178 | DevExtsion = (PDEVICE_EXTENSION)GlobalDeviceObject->DeviceExtension; 179 | memset(DevExtsion, 0, sizeof(DEVICE_EXTENSION)); 180 | KeInitializeSpinLock(&DevExtsion->SpinLock); 181 | DevExtsion->DriverObject = m_DriverObject; 182 | DevExtsion->DeviceOpen = FALSE; 183 | DevExtsion->StartSysMon = FALSE; 184 | DevExtsion->StartHook = FALSE; 185 | CurPhyMemRange = PhysicalMemoryRange = MmGetPhysicalMemoryRanges(); 186 | for (; CurPhyMemRange->BaseAddress.QuadPart!=0&&CurPhyMemRange->NumberOfBytes.QuadPart!=0; CurPhyMemRange++) 187 | { 188 | uCount++; 189 | } 190 | uCount++; 191 | DevExtsion->PhysicalMemoryRange = (PPHYSICAL_MEMORY_RANGE)ExAllocatePool(NonPagedPool, uCount*sizeof(PHYSICAL_MEMORY_RANGE)); 192 | if (DevExtsion->PhysicalMemoryRange == NULL) 193 | { 194 | status = STATUS_INSUFFICIENT_RESOURCES; 195 | __leave; 196 | } 197 | memcpy(DevExtsion->PhysicalMemoryRange, PhysicalMemoryRange, uCount*sizeof(PHYSICAL_MEMORY_RANGE)); 198 | status = IoCreateSymbolicLink(&unSymbolicLinkName, &unDeviceName); 199 | if (!NT_SUCCESS(status)) 200 | { 201 | __leave; 202 | } 203 | bSymbolicLinkClear = TRUE; 204 | status = InstallSysMonHandler(); 205 | if (!NT_SUCCESS(status)) 206 | { 207 | __leave; 208 | } 209 | DevExtsion->obDriverEntryEvent = IoCreateNotificationEvent(&unDriverEntryEvent, &DevExtsion->hDriverEntryEvent); 210 | DevExtsion->obDriverProcessedEvent = IoCreateNotificationEvent(&unDriverProcessedEvent, &DevExtsion->hDriverProcessedEvent); 211 | DevExtsion->obDriverClearedEvent = IoCreateNotificationEvent(&unDriverClearedEvent, &DevExtsion->hDriverClearedEvent); 212 | if ( 213 | DevExtsion->obDriverEntryEvent == NULL || 214 | DevExtsion->obDriverProcessedEvent == NULL || 215 | DevExtsion->obDriverClearedEvent == NULL 216 | ) 217 | { 218 | status = STATUS_INSUFFICIENT_RESOURCES; 219 | __leave; 220 | } 221 | KeClearEvent(DevExtsion->obDriverEntryEvent); 222 | KeClearEvent(DevExtsion->obDriverProcessedEvent); 223 | KeClearEvent(DevExtsion->obDriverClearedEvent); 224 | 225 | SWHookSSDT(); 226 | m_DriverObject->DriverUnload = NULL; 227 | } 228 | __finally 229 | { 230 | if (status != STATUS_SUCCESS) 231 | { 232 | UnInstallSysMonHandler(); 233 | if (DevExtsion->obDriverEntryEvent != NULL) 234 | { 235 | ZwClose(DevExtsion->hDriverEntryEvent); 236 | } 237 | if (DevExtsion->obDriverProcessedEvent != NULL) 238 | { 239 | ZwClose(DevExtsion->hDriverProcessedEvent); 240 | } 241 | if (DevExtsion->obDriverClearedEvent != NULL) 242 | { 243 | ZwClose(DevExtsion->hDriverClearedEvent); 244 | } 245 | if (DevExtsion->PhysicalMemoryRange != NULL) 246 | { 247 | ExFreePool(DevExtsion->PhysicalMemoryRange); 248 | } 249 | if (bSymbolicLinkClear) 250 | { 251 | IoDeleteSymbolicLink(&unSymbolicLinkName); 252 | } 253 | if (GlobalDeviceObject != NULL) 254 | { 255 | IoDeleteDevice(GlobalDeviceObject); 256 | } 257 | } 258 | } 259 | return status; 260 | } 261 | -------------------------------------------------------------------------------- /drv/DrvShield/md5.c: -------------------------------------------------------------------------------- 1 | #include "std.h" 2 | #include "md5.h" 3 | 4 | /* MD5 */ 5 | #pragma pack(push, 1) 6 | typedef union _md5_t 7 | { 8 | unsigned char md5_u8[16]; 9 | unsigned short md5_u16[8]; 10 | unsigned long md5_u32[4]; 11 | unsigned __int64 md5_u64[2]; 12 | } md5_t; 13 | #pragma pack(pop) 14 | 15 | typedef struct _MD5_CTX 16 | { 17 | unsigned long state[4]; /* state (ABCD) */ 18 | unsigned long count[2]; /* number of bits, modulo 2^64 (lsb first) */ 19 | unsigned char buffer[64]; /* input buffer */ 20 | } MD5_CTX, *PMD5_CTX; 21 | 22 | void MD5_Init(MD5_CTX *ctx); 23 | void MD5_Update(MD5_CTX *ctx, const unsigned char *input, unsigned long inputLen); 24 | void MD5_Final(md5_t *digest, MD5_CTX *ctx); 25 | void md5Impl(void *input, unsigned long inputLen, md5_t *digest); 26 | 27 | 28 | #define S11 7 29 | #define S12 12 30 | #define S13 17 31 | #define S14 22 32 | #define S21 5 33 | #define S22 9 34 | #define S23 14 35 | #define S24 20 36 | #define S31 4 37 | #define S32 11 38 | #define S33 16 39 | #define S34 23 40 | #define S41 6 41 | #define S42 10 42 | #define S43 15 43 | #define S44 21 44 | 45 | void MD5_Transform (unsigned long state[4], const unsigned char block[64]); 46 | void MD5_Encode(unsigned char *output, const unsigned long *input, unsigned long Length); 47 | void MD5_Decode(unsigned long *output, const unsigned char *input, unsigned long Length); 48 | 49 | static const unsigned char PADDING[64] = 50 | { 51 | 0x80, 0, 0, 0, 0, 0, 0, 0, 52 | 0, 0, 0, 0, 0, 0, 0, 0, 53 | 0, 0, 0, 0, 0, 0, 0, 0, 54 | 0, 0, 0, 0, 0, 0, 0, 0, 55 | 0, 0, 0, 0, 0, 0, 0, 0, 56 | 0, 0, 0, 0, 0, 0, 0, 0, 57 | 0, 0, 0, 0, 0, 0, 0, 0, 58 | 0, 0, 0, 0, 0, 0, 0, 0, 59 | }; 60 | 61 | /* 62 | ======================================================================================================================= 63 | F, G, H and I are basic MD5 functions. 64 | ======================================================================================================================= 65 | */ 66 | #define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 67 | #define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 68 | #define H(x, y, z) ((x) ^ (y) ^ (z)) 69 | #define I(x, y, z) ((y) ^ ((x) | (~z))) 70 | 71 | /* 72 | ======================================================================================================================= 73 | ROTATE_LEFT rotates x left n bits. 74 | ======================================================================================================================= 75 | */ 76 | #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) 77 | 78 | /* 79 | ======================================================================================================================= 80 | FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. Rotation is separate from addition to prevent 81 | recomputation. 82 | ======================================================================================================================= 83 | */ 84 | #define FF(a, b, c, d, x, s, ac) \ 85 | { \ 86 | (a) += F((b), (c), (d)) + (x) + (unsigned long)(ac); \ 87 | (a) = ROTATE_LEFT((a), (s)); \ 88 | (a) += (b); \ 89 | } 90 | 91 | #define GG(a, b, c, d, x, s, ac) \ 92 | { \ 93 | (a) += G((b), (c), (d)) + (x) + (unsigned long)(ac); \ 94 | (a) = ROTATE_LEFT((a), (s)); \ 95 | (a) += (b); \ 96 | } 97 | #define HH(a, b, c, d, x, s, ac) \ 98 | { \ 99 | (a) += H((b), (c), (d)) + (x) + (unsigned long)(ac); \ 100 | (a) = ROTATE_LEFT((a), (s)); \ 101 | (a) += (b); \ 102 | } 103 | #define II(a, b, c, d, x, s, ac) \ 104 | { \ 105 | (a) += I((b), (c), (d)) + (x) + (unsigned long)(ac); \ 106 | (a) = ROTATE_LEFT((a), (s)); \ 107 | (a) += (b); \ 108 | } 109 | 110 | /* 111 | ======================================================================================================================= 112 | MD5 initialization. Begins an MD5 operation, writing a new ctx. 113 | ======================================================================================================================= 114 | */ 115 | void MD5_Init(MD5_CTX *ctx) 116 | { 117 | ctx->count[0] = 0; 118 | ctx->count[1] = 0; 119 | 120 | /* Load magic initialization constants. */ 121 | ctx->state[0] = 0x67452301; 122 | ctx->state[1] = 0xefcdab89; 123 | ctx->state[2] = 0x98badcfe; 124 | ctx->state[3] = 0x10325476; 125 | } 126 | 127 | /* 128 | ======================================================================================================================= 129 | MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and 130 | updating the ctx. 131 | ======================================================================================================================= 132 | */ 133 | void MD5_Update(MD5_CTX *ctx, const unsigned char *input, unsigned long inputLen) 134 | { 135 | unsigned long i, index, partLen; 136 | 137 | /* Compute number of bytes mod 64 */ 138 | index = (unsigned int)((ctx->count[0] >> 3) & 0x3F); 139 | 140 | /* Update number of bits */ 141 | if ((ctx->count[0] += ((unsigned long)inputLen << 3)) < 142 | ((unsigned long)inputLen << 3)) 143 | { 144 | ctx->count[1]++; 145 | } 146 | 147 | ctx->count[1] += ((unsigned long)inputLen >> 29); 148 | partLen = 64 - index; 149 | 150 | /* Transform as many times as possible. */ 151 | if (inputLen >= partLen) 152 | { 153 | RtlCopyMemory(&ctx->buffer[index], input, partLen); 154 | MD5_Transform(ctx->state, ctx->buffer); 155 | 156 | for (i = partLen; i + 63 < inputLen; i += 64) 157 | { 158 | MD5_Transform(ctx->state, &input[i]); 159 | } 160 | 161 | index = 0; 162 | } 163 | else 164 | { 165 | i = 0; 166 | } 167 | 168 | /* Buffer remaining input */ 169 | RtlCopyMemory(&ctx->buffer[index], &input[i], inputLen - i); 170 | } 171 | 172 | /* 173 | ======================================================================================================================= 174 | MD5 finalization. Ends an MD5 message-digest operation, writing the the message digest and zeroizing the ctx. 175 | ======================================================================================================================= 176 | */ 177 | void MD5_Final(md5_t *digest, MD5_CTX *ctx) 178 | { 179 | unsigned char bits[8]; 180 | unsigned int index, padLen; 181 | 182 | /* Save number of bits */ 183 | MD5_Encode(bits, ctx->count, 8); 184 | 185 | /* Pad out to 56 mod 64. */ 186 | index = (unsigned int)((ctx->count[0] >> 3) & 0x3f); 187 | padLen = (index < 56) ? (56 - index) : (120 - index); 188 | MD5_Update(ctx, PADDING, padLen); 189 | 190 | /* Append length (before padding) */ 191 | MD5_Update(ctx, bits, 8); 192 | 193 | /* Store state in digest */ 194 | MD5_Encode(digest->md5_u8, ctx->state, 16); 195 | 196 | /* Zeroize sensitive information. */ 197 | RtlZeroMemory(ctx, sizeof(*ctx)); 198 | } 199 | 200 | /* 201 | ======================================================================================================================= 202 | MD5 basic transformation. Transforms state based on block. 203 | ======================================================================================================================= 204 | */ 205 | static void MD5_Transform(unsigned long state[4], const unsigned char block[64]) 206 | { 207 | 208 | unsigned long a, 209 | b, 210 | c, 211 | d, 212 | x[16]; 213 | 214 | a = state[0]; 215 | b = state[1]; 216 | c = state[2]; 217 | d = state[3]; 218 | 219 | MD5_Decode(x, block, 64); 220 | 221 | /* Round 1 */ 222 | FF(a, b, c, d, x[0], S11, 0xd76aa478); /* 1 */ 223 | FF(d, a, b, c, x[1], S12, 0xe8c7b756); /* 2 */ 224 | FF(c, d, a, b, x[2], S13, 0x242070db); /* 3 */ 225 | FF(b, c, d, a, x[3], S14, 0xc1bdceee); /* 4 */ 226 | FF(a, b, c, d, x[4], S11, 0xf57c0faf); /* 5 */ 227 | FF(d, a, b, c, x[5], S12, 0x4787c62a); /* 6 */ 228 | FF(c, d, a, b, x[6], S13, 0xa8304613); /* 7 */ 229 | FF(b, c, d, a, x[7], S14, 0xfd469501); /* 8 */ 230 | FF(a, b, c, d, x[8], S11, 0x698098d8); /* 9 */ 231 | FF(d, a, b, c, x[9], S12, 0x8b44f7af); /* 10 */ 232 | FF(c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */ 233 | FF(b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */ 234 | FF(a, b, c, d, x[12], S11, 0x6b901122); /* 13 */ 235 | FF(d, a, b, c, x[13], S12, 0xfd987193); /* 14 */ 236 | FF(c, d, a, b, x[14], S13, 0xa679438e); /* 15 */ 237 | FF(b, c, d, a, x[15], S14, 0x49b40821); /* 16 */ 238 | 239 | /* Round 2 */ 240 | GG(a, b, c, d, x[1], S21, 0xf61e2562); /* 17 */ 241 | GG(d, a, b, c, x[6], S22, 0xc040b340); /* 18 */ 242 | GG(c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */ 243 | GG(b, c, d, a, x[0], S24, 0xe9b6c7aa); /* 20 */ 244 | GG(a, b, c, d, x[5], S21, 0xd62f105d); /* 21 */ 245 | GG(d, a, b, c, x[10], S22, 0x2441453); /* 22 */ 246 | GG(c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */ 247 | GG(b, c, d, a, x[4], S24, 0xe7d3fbc8); /* 24 */ 248 | GG(a, b, c, d, x[9], S21, 0x21e1cde6); /* 25 */ 249 | GG(d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */ 250 | GG(c, d, a, b, x[3], S23, 0xf4d50d87); /* 27 */ 251 | 252 | GG(b, c, d, a, x[8], S24, 0x455a14ed); /* 28 */ 253 | GG(a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */ 254 | GG(d, a, b, c, x[2], S22, 0xfcefa3f8); /* 30 */ 255 | GG(c, d, a, b, x[7], S23, 0x676f02d9); /* 31 */ 256 | GG(b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */ 257 | 258 | /* Round 3 */ 259 | HH(a, b, c, d, x[5], S31, 0xfffa3942); /* 33 */ 260 | HH(d, a, b, c, x[8], S32, 0x8771f681); /* 34 */ 261 | HH(c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */ 262 | HH(b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */ 263 | HH(a, b, c, d, x[1], S31, 0xa4beea44); /* 37 */ 264 | HH(d, a, b, c, x[4], S32, 0x4bdecfa9); /* 38 */ 265 | HH(c, d, a, b, x[7], S33, 0xf6bb4b60); /* 39 */ 266 | HH(b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */ 267 | HH(a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */ 268 | HH(d, a, b, c, x[0], S32, 0xeaa127fa); /* 42 */ 269 | HH(c, d, a, b, x[3], S33, 0xd4ef3085); /* 43 */ 270 | HH(b, c, d, a, x[6], S34, 0x4881d05); /* 44 */ 271 | HH(a, b, c, d, x[9], S31, 0xd9d4d039); /* 45 */ 272 | HH(d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */ 273 | HH(c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */ 274 | HH(b, c, d, a, x[2], S34, 0xc4ac5665); /* 48 */ 275 | 276 | /* Round 4 */ 277 | II(a, b, c, d, x[0], S41, 0xf4292244); /* 49 */ 278 | II(d, a, b, c, x[7], S42, 0x432aff97); /* 50 */ 279 | II(c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */ 280 | II(b, c, d, a, x[5], S44, 0xfc93a039); /* 52 */ 281 | II(a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */ 282 | II(d, a, b, c, x[3], S42, 0x8f0ccc92); /* 54 */ 283 | II(c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */ 284 | II(b, c, d, a, x[1], S44, 0x85845dd1); /* 56 */ 285 | II(a, b, c, d, x[8], S41, 0x6fa87e4f); /* 57 */ 286 | II(d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */ 287 | II(c, d, a, b, x[6], S43, 0xa3014314); /* 59 */ 288 | II(b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */ 289 | II(a, b, c, d, x[4], S41, 0xf7537e82); /* 61 */ 290 | II(d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */ 291 | II(c, d, a, b, x[2], S43, 0x2ad7d2bb); /* 63 */ 292 | II(b, c, d, a, x[9], S44, 0xeb86d391); /* 64 */ 293 | 294 | state[0] += a; 295 | state[1] += b; 296 | state[2] += c; 297 | state[3] += d; 298 | 299 | /* Zeroize sensitive information. */ 300 | RtlZeroMemory(x, sizeof(x)); 301 | } 302 | 303 | /* 304 | ======================================================================================================================= 305 | Encodes input (unsigned long) into output (unsigned char). Assumes len is a multiple of 4. 306 | ======================================================================================================================= 307 | */ 308 | static void MD5_Encode(unsigned char *output, const unsigned long *input, 309 | unsigned long len) 310 | { 311 | 312 | unsigned long i, 313 | j; 314 | 315 | for (i = 0, j = 0; j < len; i++, j += 4) 316 | { 317 | output[j] = (unsigned char)(input[i] & 0xff); 318 | output[j + 1] = (unsigned char)((input[i] >> 8) & 0xff); 319 | output[j + 2] = (unsigned char)((input[i] >> 16) & 0xff); 320 | output[j + 3] = (unsigned char)((input[i] >> 24) & 0xff); 321 | } 322 | } 323 | 324 | /* 325 | ======================================================================================================================= 326 | Decodes input (unsigned char) into output (unsigned long). Assumes len is a multiple of 4. 327 | ======================================================================================================================= 328 | */ 329 | static void MD5_Decode(unsigned long *output, const unsigned char *input, 330 | unsigned long len) 331 | { 332 | 333 | unsigned int i, 334 | j; 335 | 336 | for (i = 0, j = 0; j < len; i++, j += 4) 337 | { 338 | output[i] = ((unsigned long)input[j]) | 339 | (((unsigned long)input[j + 1]) << 8) | 340 | (((unsigned long)input[j + 2]) << 16) | 341 | (((unsigned long)input[j + 3]) << 24); 342 | } 343 | } 344 | 345 | void md5Impl(void *input, unsigned long inputLen, md5_t *digest) 346 | { 347 | MD5_CTX ctx; 348 | MD5_Init(&ctx); 349 | MD5_Update(&ctx, input, inputLen); 350 | MD5_Final(digest, &ctx); 351 | } 352 | 353 | void md5(PVOID Buf, ULONG BufLen, PCHAR Digest) 354 | { 355 | int i; 356 | md5_t Md5Data; 357 | CHAR szBuf[64] = {0}; 358 | PCHAR lpAddress = szBuf; 359 | md5Impl(Buf, BufLen, &Md5Data); 360 | for (i = 0; i < sizeof(Md5Data.md5_u8); i++) 361 | { 362 | sprintf(lpAddress, "%02X", Md5Data.md5_u8[i]); 363 | lpAddress += 2; 364 | } 365 | strcpy(Digest, szBuf); 366 | } 367 | -------------------------------------------------------------------------------- /exe/MakePolicyFile/md5.cpp: -------------------------------------------------------------------------------- 1 | #include "StdAfx.h" 2 | #include "md5.h" 3 | 4 | /* MD5 */ 5 | #pragma pack(push, 1) 6 | typedef union _md5_t 7 | { 8 | unsigned char md5_u8[16]; 9 | unsigned short md5_u16[8]; 10 | unsigned long md5_u32[4]; 11 | unsigned __int64 md5_u64[2]; 12 | } md5_t; 13 | #pragma pack(pop) 14 | 15 | typedef struct _MD5_CTX 16 | { 17 | unsigned long state[4]; /* state (ABCD) */ 18 | unsigned long count[2]; /* number of bits, modulo 2^64 (lsb first) */ 19 | unsigned char buffer[64]; /* input buffer */ 20 | } MD5_CTX, *PMD5_CTX; 21 | 22 | void MD5_Init(MD5_CTX *ctx); 23 | void MD5_Update(MD5_CTX *ctx, const unsigned char *input, unsigned long inputLen); 24 | void MD5_Final(md5_t *digest, MD5_CTX *ctx); 25 | void md5Impl(void *input, unsigned long inputLen, md5_t *digest); 26 | 27 | 28 | #define S11 7 29 | #define S12 12 30 | #define S13 17 31 | #define S14 22 32 | #define S21 5 33 | #define S22 9 34 | #define S23 14 35 | #define S24 20 36 | #define S31 4 37 | #define S32 11 38 | #define S33 16 39 | #define S34 23 40 | #define S41 6 41 | #define S42 10 42 | #define S43 15 43 | #define S44 21 44 | 45 | void MD5_Transform (unsigned long state[4], const unsigned char block[64]); 46 | void MD5_Encode(unsigned char *output, const unsigned long *input, unsigned long Length); 47 | void MD5_Decode(unsigned long *output, const unsigned char *input, unsigned long Length); 48 | 49 | static const unsigned char PADDING[64] = 50 | { 51 | 0x80, 0, 0, 0, 0, 0, 0, 0, 52 | 0, 0, 0, 0, 0, 0, 0, 0, 53 | 0, 0, 0, 0, 0, 0, 0, 0, 54 | 0, 0, 0, 0, 0, 0, 0, 0, 55 | 0, 0, 0, 0, 0, 0, 0, 0, 56 | 0, 0, 0, 0, 0, 0, 0, 0, 57 | 0, 0, 0, 0, 0, 0, 0, 0, 58 | 0, 0, 0, 0, 0, 0, 0, 0, 59 | }; 60 | 61 | /* 62 | ======================================================================================================================= 63 | F, G, H and I are basic MD5 functions. 64 | ======================================================================================================================= 65 | */ 66 | #define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 67 | #define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 68 | #define H(x, y, z) ((x) ^ (y) ^ (z)) 69 | #define I(x, y, z) ((y) ^ ((x) | (~z))) 70 | 71 | /* 72 | ======================================================================================================================= 73 | ROTATE_LEFT rotates x left n bits. 74 | ======================================================================================================================= 75 | */ 76 | #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) 77 | 78 | /* 79 | ======================================================================================================================= 80 | FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. Rotation is separate from addition to prevent 81 | recomputation. 82 | ======================================================================================================================= 83 | */ 84 | #define FF(a, b, c, d, x, s, ac) \ 85 | { \ 86 | (a) += F((b), (c), (d)) + (x) + (unsigned long)(ac); \ 87 | (a) = ROTATE_LEFT((a), (s)); \ 88 | (a) += (b); \ 89 | } 90 | 91 | #define GG(a, b, c, d, x, s, ac) \ 92 | { \ 93 | (a) += G((b), (c), (d)) + (x) + (unsigned long)(ac); \ 94 | (a) = ROTATE_LEFT((a), (s)); \ 95 | (a) += (b); \ 96 | } 97 | #define HH(a, b, c, d, x, s, ac) \ 98 | { \ 99 | (a) += H((b), (c), (d)) + (x) + (unsigned long)(ac); \ 100 | (a) = ROTATE_LEFT((a), (s)); \ 101 | (a) += (b); \ 102 | } 103 | #define II(a, b, c, d, x, s, ac) \ 104 | { \ 105 | (a) += I((b), (c), (d)) + (x) + (unsigned long)(ac); \ 106 | (a) = ROTATE_LEFT((a), (s)); \ 107 | (a) += (b); \ 108 | } 109 | 110 | /* 111 | ======================================================================================================================= 112 | MD5 initialization. Begins an MD5 operation, writing a new ctx. 113 | ======================================================================================================================= 114 | */ 115 | void MD5_Init(MD5_CTX *ctx) 116 | { 117 | ctx->count[0] = 0; 118 | ctx->count[1] = 0; 119 | 120 | /* Load magic initialization constants. */ 121 | ctx->state[0] = 0x67452301; 122 | ctx->state[1] = 0xefcdab89; 123 | ctx->state[2] = 0x98badcfe; 124 | ctx->state[3] = 0x10325476; 125 | } 126 | 127 | /* 128 | ======================================================================================================================= 129 | MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and 130 | updating the ctx. 131 | ======================================================================================================================= 132 | */ 133 | void MD5_Update(MD5_CTX *ctx, const unsigned char *input, unsigned long inputLen) 134 | { 135 | unsigned long i, index, partLen; 136 | 137 | /* Compute number of bytes mod 64 */ 138 | index = (unsigned int)((ctx->count[0] >> 3) & 0x3F); 139 | 140 | /* Update number of bits */ 141 | if ((ctx->count[0] += ((unsigned long)inputLen << 3)) < 142 | ((unsigned long)inputLen << 3)) 143 | { 144 | ctx->count[1]++; 145 | } 146 | 147 | ctx->count[1] += ((unsigned long)inputLen >> 29); 148 | partLen = 64 - index; 149 | 150 | /* Transform as many times as possible. */ 151 | if (inputLen >= partLen) 152 | { 153 | RtlCopyMemory(&ctx->buffer[index], input, partLen); 154 | MD5_Transform(ctx->state, ctx->buffer); 155 | 156 | for (i = partLen; i + 63 < inputLen; i += 64) 157 | { 158 | MD5_Transform(ctx->state, &input[i]); 159 | } 160 | 161 | index = 0; 162 | } 163 | else 164 | { 165 | i = 0; 166 | } 167 | 168 | /* Buffer remaining input */ 169 | RtlCopyMemory(&ctx->buffer[index], &input[i], inputLen - i); 170 | } 171 | 172 | /* 173 | ======================================================================================================================= 174 | MD5 finalization. Ends an MD5 message-digest operation, writing the the message digest and zeroizing the ctx. 175 | ======================================================================================================================= 176 | */ 177 | void MD5_Final(md5_t *digest, MD5_CTX *ctx) 178 | { 179 | unsigned char bits[8]; 180 | unsigned int index, padLen; 181 | 182 | /* Save number of bits */ 183 | MD5_Encode(bits, ctx->count, 8); 184 | 185 | /* Pad out to 56 mod 64. */ 186 | index = (unsigned int)((ctx->count[0] >> 3) & 0x3f); 187 | padLen = (index < 56) ? (56 - index) : (120 - index); 188 | MD5_Update(ctx, PADDING, padLen); 189 | 190 | /* Append length (before padding) */ 191 | MD5_Update(ctx, bits, 8); 192 | 193 | /* Store state in digest */ 194 | MD5_Encode(digest->md5_u8, ctx->state, 16); 195 | 196 | /* Zeroize sensitive information. */ 197 | RtlZeroMemory(ctx, sizeof(*ctx)); 198 | } 199 | 200 | /* 201 | ======================================================================================================================= 202 | MD5 basic transformation. Transforms state based on block. 203 | ======================================================================================================================= 204 | */ 205 | static void MD5_Transform(unsigned long state[4], const unsigned char block[64]) 206 | { 207 | 208 | unsigned long a, 209 | b, 210 | c, 211 | d, 212 | x[16]; 213 | 214 | a = state[0]; 215 | b = state[1]; 216 | c = state[2]; 217 | d = state[3]; 218 | 219 | MD5_Decode(x, block, 64); 220 | 221 | /* Round 1 */ 222 | FF(a, b, c, d, x[0], S11, 0xd76aa478); /* 1 */ 223 | FF(d, a, b, c, x[1], S12, 0xe8c7b756); /* 2 */ 224 | FF(c, d, a, b, x[2], S13, 0x242070db); /* 3 */ 225 | FF(b, c, d, a, x[3], S14, 0xc1bdceee); /* 4 */ 226 | FF(a, b, c, d, x[4], S11, 0xf57c0faf); /* 5 */ 227 | FF(d, a, b, c, x[5], S12, 0x4787c62a); /* 6 */ 228 | FF(c, d, a, b, x[6], S13, 0xa8304613); /* 7 */ 229 | FF(b, c, d, a, x[7], S14, 0xfd469501); /* 8 */ 230 | FF(a, b, c, d, x[8], S11, 0x698098d8); /* 9 */ 231 | FF(d, a, b, c, x[9], S12, 0x8b44f7af); /* 10 */ 232 | FF(c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */ 233 | FF(b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */ 234 | FF(a, b, c, d, x[12], S11, 0x6b901122); /* 13 */ 235 | FF(d, a, b, c, x[13], S12, 0xfd987193); /* 14 */ 236 | FF(c, d, a, b, x[14], S13, 0xa679438e); /* 15 */ 237 | FF(b, c, d, a, x[15], S14, 0x49b40821); /* 16 */ 238 | 239 | /* Round 2 */ 240 | GG(a, b, c, d, x[1], S21, 0xf61e2562); /* 17 */ 241 | GG(d, a, b, c, x[6], S22, 0xc040b340); /* 18 */ 242 | GG(c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */ 243 | GG(b, c, d, a, x[0], S24, 0xe9b6c7aa); /* 20 */ 244 | GG(a, b, c, d, x[5], S21, 0xd62f105d); /* 21 */ 245 | GG(d, a, b, c, x[10], S22, 0x2441453); /* 22 */ 246 | GG(c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */ 247 | GG(b, c, d, a, x[4], S24, 0xe7d3fbc8); /* 24 */ 248 | GG(a, b, c, d, x[9], S21, 0x21e1cde6); /* 25 */ 249 | GG(d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */ 250 | GG(c, d, a, b, x[3], S23, 0xf4d50d87); /* 27 */ 251 | 252 | GG(b, c, d, a, x[8], S24, 0x455a14ed); /* 28 */ 253 | GG(a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */ 254 | GG(d, a, b, c, x[2], S22, 0xfcefa3f8); /* 30 */ 255 | GG(c, d, a, b, x[7], S23, 0x676f02d9); /* 31 */ 256 | GG(b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */ 257 | 258 | /* Round 3 */ 259 | HH(a, b, c, d, x[5], S31, 0xfffa3942); /* 33 */ 260 | HH(d, a, b, c, x[8], S32, 0x8771f681); /* 34 */ 261 | HH(c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */ 262 | HH(b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */ 263 | HH(a, b, c, d, x[1], S31, 0xa4beea44); /* 37 */ 264 | HH(d, a, b, c, x[4], S32, 0x4bdecfa9); /* 38 */ 265 | HH(c, d, a, b, x[7], S33, 0xf6bb4b60); /* 39 */ 266 | HH(b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */ 267 | HH(a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */ 268 | HH(d, a, b, c, x[0], S32, 0xeaa127fa); /* 42 */ 269 | HH(c, d, a, b, x[3], S33, 0xd4ef3085); /* 43 */ 270 | HH(b, c, d, a, x[6], S34, 0x4881d05); /* 44 */ 271 | HH(a, b, c, d, x[9], S31, 0xd9d4d039); /* 45 */ 272 | HH(d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */ 273 | HH(c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */ 274 | HH(b, c, d, a, x[2], S34, 0xc4ac5665); /* 48 */ 275 | 276 | /* Round 4 */ 277 | II(a, b, c, d, x[0], S41, 0xf4292244); /* 49 */ 278 | II(d, a, b, c, x[7], S42, 0x432aff97); /* 50 */ 279 | II(c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */ 280 | II(b, c, d, a, x[5], S44, 0xfc93a039); /* 52 */ 281 | II(a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */ 282 | II(d, a, b, c, x[3], S42, 0x8f0ccc92); /* 54 */ 283 | II(c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */ 284 | II(b, c, d, a, x[1], S44, 0x85845dd1); /* 56 */ 285 | II(a, b, c, d, x[8], S41, 0x6fa87e4f); /* 57 */ 286 | II(d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */ 287 | II(c, d, a, b, x[6], S43, 0xa3014314); /* 59 */ 288 | II(b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */ 289 | II(a, b, c, d, x[4], S41, 0xf7537e82); /* 61 */ 290 | II(d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */ 291 | II(c, d, a, b, x[2], S43, 0x2ad7d2bb); /* 63 */ 292 | II(b, c, d, a, x[9], S44, 0xeb86d391); /* 64 */ 293 | 294 | state[0] += a; 295 | state[1] += b; 296 | state[2] += c; 297 | state[3] += d; 298 | 299 | /* Zeroize sensitive information. */ 300 | RtlZeroMemory(x, sizeof(x)); 301 | } 302 | 303 | /* 304 | ======================================================================================================================= 305 | Encodes input (unsigned long) into output (unsigned char). Assumes len is a multiple of 4. 306 | ======================================================================================================================= 307 | */ 308 | static void MD5_Encode(unsigned char *output, const unsigned long *input, 309 | unsigned long len) 310 | { 311 | 312 | unsigned long i, 313 | j; 314 | 315 | for (i = 0, j = 0; j < len; i++, j += 4) 316 | { 317 | output[j] = (unsigned char)(input[i] & 0xff); 318 | output[j + 1] = (unsigned char)((input[i] >> 8) & 0xff); 319 | output[j + 2] = (unsigned char)((input[i] >> 16) & 0xff); 320 | output[j + 3] = (unsigned char)((input[i] >> 24) & 0xff); 321 | } 322 | } 323 | 324 | /* 325 | ======================================================================================================================= 326 | Decodes input (unsigned char) into output (unsigned long). Assumes len is a multiple of 4. 327 | ======================================================================================================================= 328 | */ 329 | static void MD5_Decode(unsigned long *output, const unsigned char *input, 330 | unsigned long len) 331 | { 332 | 333 | unsigned int i, 334 | j; 335 | 336 | for (i = 0, j = 0; j < len; i++, j += 4) 337 | { 338 | output[i] = ((unsigned long)input[j]) | 339 | (((unsigned long)input[j + 1]) << 8) | 340 | (((unsigned long)input[j + 2]) << 16) | 341 | (((unsigned long)input[j + 3]) << 24); 342 | } 343 | } 344 | 345 | void md5Impl(void *input, unsigned long inputLen, md5_t *digest) 346 | { 347 | MD5_CTX ctx; 348 | MD5_Init(&ctx); 349 | MD5_Update(&ctx, (const unsigned char *)input, inputLen); 350 | MD5_Final(digest, &ctx); 351 | } 352 | 353 | void md5(PVOID Buf, ULONG BufLen, PCHAR Digest) 354 | { 355 | int i; 356 | md5_t Md5Data; 357 | CHAR szBuf[64] = {0}; 358 | PCHAR lpAddress = szBuf; 359 | md5Impl(Buf, BufLen, &Md5Data); 360 | for (i = 0; i < sizeof(Md5Data.md5_u8); i++) 361 | { 362 | sprintf(lpAddress, "%02X", Md5Data.md5_u8[i]); 363 | lpAddress += 2; 364 | } 365 | strcpy(Digest, szBuf); 366 | } 367 | -------------------------------------------------------------------------------- /drv/kdarpshd/passthru.c: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 1992-2000 Microsoft Corporation 4 | 5 | Module Name: 6 | 7 | passthru.c 8 | 9 | Abstract: 10 | 11 | Ndis Intermediate Miniport driver sample. This is a passthru driver. 12 | 13 | Author: 14 | 15 | Environment: 16 | 17 | 18 | Revision History: 19 | 20 | 21 | --*/ 22 | 23 | 24 | #include "precomp.h" 25 | #pragma hdrstop 26 | 27 | #pragma NDIS_INIT_FUNCTION(DriverEntry) 28 | 29 | NDIS_HANDLE ProtHandle = NULL; 30 | NDIS_HANDLE DriverHandle = NULL; 31 | NDIS_MEDIUM MediumArray[4] = 32 | { 33 | NdisMedium802_3, // Ethernet 34 | NdisMedium802_5, // Token-ring 35 | NdisMediumFddi, // Fddi 36 | NdisMediumWan // NDISWAN 37 | }; 38 | 39 | NDIS_SPIN_LOCK GlobalLock; 40 | 41 | PADAPT pAdaptList = NULL; 42 | LONG MiniportCount = 0; 43 | 44 | NDIS_HANDLE NdisWrapperHandle; 45 | 46 | // 47 | // To support ioctls from user-mode: 48 | // 49 | 50 | #define LINKNAME_STRING L"\\DosDevices\\kdarpshd" 51 | #define NTDEVICE_STRING L"\\Device\\kdarpshd" 52 | 53 | NDIS_HANDLE NdisDeviceHandle = NULL; 54 | PDEVICE_OBJECT ControlDeviceObject = NULL; 55 | 56 | enum _DEVICE_STATE 57 | { 58 | PS_DEVICE_STATE_READY = 0, // ready for create/delete 59 | PS_DEVICE_STATE_CREATING, // create operation in progress 60 | PS_DEVICE_STATE_DELETING // delete operation in progress 61 | } ControlDeviceState = PS_DEVICE_STATE_READY; 62 | 63 | 64 | 65 | NTSTATUS 66 | DriverEntry( 67 | IN PDRIVER_OBJECT DriverObject, 68 | IN PUNICODE_STRING RegistryPath 69 | ) 70 | /*++ 71 | 72 | Routine Description: 73 | 74 | First entry point to be called, when this driver is loaded. 75 | Register with NDIS as an intermediate driver. 76 | 77 | Arguments: 78 | 79 | DriverObject - pointer to the system's driver object structure 80 | for this driver 81 | 82 | RegistryPath - system's registry path for this driver 83 | 84 | Return Value: 85 | 86 | STATUS_SUCCESS if all initialization is successful, STATUS_XXX 87 | error code if not. 88 | 89 | --*/ 90 | { 91 | NDIS_STATUS Status; 92 | NDIS_PROTOCOL_CHARACTERISTICS PChars; 93 | NDIS_MINIPORT_CHARACTERISTICS MChars; 94 | NDIS_STRING Name; 95 | 96 | Status = NDIS_STATUS_SUCCESS; 97 | NdisAllocateSpinLock(&GlobalLock); 98 | 99 | NdisMInitializeWrapper(&NdisWrapperHandle, DriverObject, RegistryPath, NULL); 100 | 101 | do 102 | { 103 | // 104 | // Register the miniport with NDIS. Note that it is the miniport 105 | // which was started as a driver and not the protocol. Also the miniport 106 | // must be registered prior to the protocol since the protocol's BindAdapter 107 | // handler can be initiated anytime and when it is, it must be ready to 108 | // start driver instances. 109 | // 110 | 111 | NdisZeroMemory(&MChars, sizeof(NDIS_MINIPORT_CHARACTERISTICS)); 112 | 113 | MChars.MajorNdisVersion = PASSTHRU_MAJOR_NDIS_VERSION; 114 | MChars.MinorNdisVersion = PASSTHRU_MINOR_NDIS_VERSION; 115 | 116 | MChars.InitializeHandler = MPInitialize; 117 | MChars.QueryInformationHandler = MPQueryInformation; 118 | MChars.SetInformationHandler = MPSetInformation; 119 | MChars.ResetHandler = NULL; 120 | MChars.TransferDataHandler = MPTransferData; 121 | MChars.HaltHandler = MPHalt; 122 | #ifdef NDIS51_MINIPORT 123 | MChars.CancelSendPacketsHandler = MPCancelSendPackets; 124 | MChars.PnPEventNotifyHandler = MPDevicePnPEvent; 125 | MChars.AdapterShutdownHandler = MPAdapterShutdown; 126 | #endif // NDIS51_MINIPORT 127 | 128 | // 129 | // We will disable the check for hang timeout so we do not 130 | // need a check for hang handler! 131 | // 132 | MChars.CheckForHangHandler = NULL; 133 | MChars.ReturnPacketHandler = MPReturnPacket; 134 | 135 | // 136 | // Either the Send or the SendPackets handler should be specified. 137 | // If SendPackets handler is specified, SendHandler is ignored 138 | // 139 | MChars.SendHandler = NULL; // MPSend; 140 | MChars.SendPacketsHandler = MPSendPackets; 141 | 142 | Status = NdisIMRegisterLayeredMiniport(NdisWrapperHandle, 143 | &MChars, 144 | sizeof(MChars), 145 | &DriverHandle); 146 | if (Status != NDIS_STATUS_SUCCESS) 147 | { 148 | break; 149 | } 150 | 151 | #ifndef WIN9X 152 | NdisMRegisterUnloadHandler(NdisWrapperHandle, PtUnload); 153 | #endif 154 | 155 | // 156 | // Now register the protocol. 157 | // 158 | NdisZeroMemory(&PChars, sizeof(NDIS_PROTOCOL_CHARACTERISTICS)); 159 | PChars.MajorNdisVersion = PASSTHRU_PROT_MAJOR_NDIS_VERSION; 160 | PChars.MinorNdisVersion = PASSTHRU_PROT_MINOR_NDIS_VERSION; 161 | 162 | // 163 | // Make sure the protocol-name matches the service-name 164 | // (from the INF) under which this protocol is installed. 165 | // This is needed to ensure that NDIS can correctly determine 166 | // the binding and call us to bind to miniports below. 167 | // 168 | NdisInitUnicodeString(&Name, L"Passthru"); // Protocol name 169 | PChars.Name = Name; 170 | PChars.OpenAdapterCompleteHandler = PtOpenAdapterComplete; 171 | PChars.CloseAdapterCompleteHandler = PtCloseAdapterComplete; 172 | PChars.SendCompleteHandler = PtSendComplete; 173 | PChars.TransferDataCompleteHandler = PtTransferDataComplete; 174 | 175 | PChars.ResetCompleteHandler = PtResetComplete; 176 | PChars.RequestCompleteHandler = PtRequestComplete; 177 | PChars.ReceiveHandler = PtReceive; 178 | PChars.ReceiveCompleteHandler = PtReceiveComplete; 179 | PChars.StatusHandler = PtStatus; 180 | PChars.StatusCompleteHandler = PtStatusComplete; 181 | PChars.BindAdapterHandler = PtBindAdapter; 182 | PChars.UnbindAdapterHandler = PtUnbindAdapter; 183 | PChars.UnloadHandler = PtUnloadProtocol; 184 | 185 | PChars.ReceivePacketHandler = PtReceivePacket; 186 | PChars.PnPEventHandler= PtPNPHandler; 187 | 188 | NdisRegisterProtocol(&Status, 189 | &ProtHandle, 190 | &PChars, 191 | sizeof(NDIS_PROTOCOL_CHARACTERISTICS)); 192 | 193 | if (Status != NDIS_STATUS_SUCCESS) 194 | { 195 | NdisIMDeregisterLayeredMiniport(DriverHandle); 196 | break; 197 | } 198 | 199 | NdisIMAssociateMiniport(DriverHandle, ProtHandle); 200 | } 201 | while (FALSE); 202 | 203 | if (Status != NDIS_STATUS_SUCCESS) 204 | { 205 | NdisTerminateWrapper(NdisWrapperHandle, NULL); 206 | } 207 | 208 | return(Status); 209 | } 210 | 211 | 212 | NDIS_STATUS 213 | PtRegisterDevice( 214 | VOID 215 | ) 216 | /*++ 217 | 218 | Routine Description: 219 | 220 | Register an ioctl interface - a device object to be used for this 221 | purpose is created by NDIS when we call NdisMRegisterDevice. 222 | 223 | This routine is called whenever a new miniport instance is 224 | initialized. However, we only create one global device object, 225 | when the first miniport instance is initialized. This routine 226 | handles potential race conditions with PtDeregisterDevice via 227 | the ControlDeviceState and MiniportCount variables. 228 | 229 | NOTE: do not call this from DriverEntry; it will prevent the driver 230 | from being unloaded (e.g. on uninstall). 231 | 232 | Arguments: 233 | 234 | None 235 | 236 | Return Value: 237 | 238 | NDIS_STATUS_SUCCESS if we successfully register a device object. 239 | 240 | --*/ 241 | { 242 | NDIS_STATUS Status = NDIS_STATUS_SUCCESS; 243 | UNICODE_STRING DeviceName; 244 | UNICODE_STRING DeviceLinkUnicodeString; 245 | PDRIVER_DISPATCH DispatchTable[IRP_MJ_MAXIMUM_FUNCTION+1]; 246 | 247 | DBGPRINT(("==>PtRegisterDevice\n")); 248 | 249 | NdisAcquireSpinLock(&GlobalLock); 250 | 251 | ++MiniportCount; 252 | 253 | if (1 == MiniportCount) 254 | { 255 | ASSERT(ControlDeviceState != PS_DEVICE_STATE_CREATING); 256 | 257 | // 258 | // Another thread could be running PtDeregisterDevice on 259 | // behalf of another miniport instance. If so, wait for 260 | // it to exit. 261 | // 262 | while (ControlDeviceState != PS_DEVICE_STATE_READY) 263 | { 264 | NdisReleaseSpinLock(&GlobalLock); 265 | NdisMSleep(1); 266 | NdisAcquireSpinLock(&GlobalLock); 267 | } 268 | 269 | ControlDeviceState = PS_DEVICE_STATE_CREATING; 270 | 271 | NdisReleaseSpinLock(&GlobalLock); 272 | 273 | 274 | NdisZeroMemory(DispatchTable, (IRP_MJ_MAXIMUM_FUNCTION+1) * sizeof(PDRIVER_DISPATCH)); 275 | 276 | DispatchTable[IRP_MJ_CREATE] = PtDispatch; 277 | DispatchTable[IRP_MJ_CLEANUP] = PtDispatch; 278 | DispatchTable[IRP_MJ_CLOSE] = PtDispatch; 279 | DispatchTable[IRP_MJ_DEVICE_CONTROL] = PtDispatch; 280 | 281 | 282 | NdisInitUnicodeString(&DeviceName, NTDEVICE_STRING); 283 | NdisInitUnicodeString(&DeviceLinkUnicodeString, LINKNAME_STRING); 284 | 285 | // 286 | // Create a device object and register our dispatch handlers 287 | // 288 | 289 | Status = NdisMRegisterDevice( 290 | NdisWrapperHandle, 291 | &DeviceName, 292 | &DeviceLinkUnicodeString, 293 | &DispatchTable[0], 294 | &ControlDeviceObject, 295 | &NdisDeviceHandle 296 | ); 297 | 298 | NdisAcquireSpinLock(&GlobalLock); 299 | 300 | ControlDeviceState = PS_DEVICE_STATE_READY; 301 | } 302 | 303 | NdisReleaseSpinLock(&GlobalLock); 304 | 305 | DBGPRINT(("<==PtRegisterDevice: %x\n", Status)); 306 | 307 | return (Status); 308 | } 309 | 310 | 311 | NTSTATUS 312 | PtDispatch( 313 | IN PDEVICE_OBJECT DeviceObject, 314 | IN PIRP Irp 315 | ) 316 | /*++ 317 | Routine Description: 318 | 319 | Process IRPs sent to this device. 320 | 321 | Arguments: 322 | 323 | DeviceObject - pointer to a device object 324 | Irp - pointer to an I/O Request Packet 325 | 326 | Return Value: 327 | 328 | NTSTATUS - STATUS_SUCCESS always - change this when adding 329 | real code to handle ioctls. 330 | 331 | --*/ 332 | { 333 | PIO_STACK_LOCATION irpStack; 334 | NTSTATUS status = STATUS_SUCCESS; 335 | 336 | UNREFERENCED_PARAMETER(DeviceObject); 337 | 338 | DBGPRINT(("==>Pt Dispatch\n")); 339 | irpStack = IoGetCurrentIrpStackLocation(Irp); 340 | 341 | 342 | switch (irpStack->MajorFunction) 343 | { 344 | case IRP_MJ_CREATE: 345 | break; 346 | 347 | case IRP_MJ_CLEANUP: 348 | break; 349 | 350 | case IRP_MJ_CLOSE: 351 | break; 352 | 353 | case IRP_MJ_DEVICE_CONTROL: 354 | // 355 | // Add code here to handle ioctl commands sent to passthru. 356 | // 357 | break; 358 | default: 359 | break; 360 | } 361 | 362 | Irp->IoStatus.Status = status; 363 | IoCompleteRequest(Irp, IO_NO_INCREMENT); 364 | 365 | DBGPRINT(("<== Pt Dispatch\n")); 366 | 367 | return status; 368 | 369 | } 370 | 371 | 372 | NDIS_STATUS 373 | PtDeregisterDevice( 374 | VOID 375 | ) 376 | /*++ 377 | 378 | Routine Description: 379 | 380 | Deregister the ioctl interface. This is called whenever a miniport 381 | instance is halted. When the last miniport instance is halted, we 382 | request NDIS to delete the device object 383 | 384 | Arguments: 385 | 386 | NdisDeviceHandle - Handle returned by NdisMRegisterDevice 387 | 388 | Return Value: 389 | 390 | NDIS_STATUS_SUCCESS if everything worked ok 391 | 392 | --*/ 393 | { 394 | NDIS_STATUS Status = NDIS_STATUS_SUCCESS; 395 | 396 | DBGPRINT(("==>PassthruDeregisterDevice\n")); 397 | 398 | NdisAcquireSpinLock(&GlobalLock); 399 | 400 | ASSERT(MiniportCount > 0); 401 | 402 | --MiniportCount; 403 | 404 | if (0 == MiniportCount) 405 | { 406 | // 407 | // All miniport instances have been halted. Deregister 408 | // the control device. 409 | // 410 | 411 | ASSERT(ControlDeviceState == PS_DEVICE_STATE_READY); 412 | 413 | // 414 | // Block PtRegisterDevice() while we release the control 415 | // device lock and deregister the device. 416 | // 417 | ControlDeviceState = PS_DEVICE_STATE_DELETING; 418 | 419 | NdisReleaseSpinLock(&GlobalLock); 420 | 421 | if (NdisDeviceHandle != NULL) 422 | { 423 | Status = NdisMDeregisterDevice(NdisDeviceHandle); 424 | NdisDeviceHandle = NULL; 425 | } 426 | 427 | NdisAcquireSpinLock(&GlobalLock); 428 | ControlDeviceState = PS_DEVICE_STATE_READY; 429 | } 430 | 431 | NdisReleaseSpinLock(&GlobalLock); 432 | 433 | DBGPRINT(("<== PassthruDeregisterDevice: %x\n", Status)); 434 | return Status; 435 | 436 | } 437 | 438 | VOID 439 | PtUnload( 440 | IN PDRIVER_OBJECT DriverObject 441 | ) 442 | // 443 | // PassThru driver unload function 444 | // 445 | { 446 | UNREFERENCED_PARAMETER(DriverObject); 447 | 448 | DBGPRINT(("PtUnload: entered\n")); 449 | PtUnloadProtocol(); 450 | NdisIMDeregisterLayeredMiniport(DriverHandle); 451 | DBGPRINT(("PtUnload: done!\n")); 452 | } 453 | 454 | -------------------------------------------------------------------------------- /drv/kdarpshd/passthru.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 1992-2000 Microsoft Corporation 4 | 5 | Module Name: 6 | 7 | passthru.h 8 | 9 | Abstract: 10 | 11 | Ndis Intermediate Miniport driver sample. This is a passthru driver. 12 | 13 | Author: 14 | 15 | Environment: 16 | 17 | 18 | Revision History: 19 | 20 | 21 | --*/ 22 | 23 | #ifdef NDIS51_MINIPORT 24 | #define PASSTHRU_MAJOR_NDIS_VERSION 5 25 | #define PASSTHRU_MINOR_NDIS_VERSION 1 26 | #else 27 | #define PASSTHRU_MAJOR_NDIS_VERSION 4 28 | #define PASSTHRU_MINOR_NDIS_VERSION 0 29 | #endif 30 | 31 | #ifdef NDIS51 32 | #define PASSTHRU_PROT_MAJOR_NDIS_VERSION 5 33 | #define PASSTHRU_PROT_MINOR_NDIS_VERSION 0 34 | #else 35 | #define PASSTHRU_PROT_MAJOR_NDIS_VERSION 4 36 | #define PASSTHRU_PROT_MINOR_NDIS_VERSION 0 37 | #endif 38 | 39 | #define MAX_BUNDLEID_LENGTH 50 40 | 41 | #define TAG 'ImPa' 42 | #define WAIT_INFINITE 0 43 | 44 | 45 | 46 | //advance declaration 47 | typedef struct _ADAPT ADAPT, *PADAPT; 48 | 49 | extern 50 | NTSTATUS 51 | DriverEntry( 52 | IN PDRIVER_OBJECT DriverObject, 53 | IN PUNICODE_STRING RegistryPath 54 | ); 55 | 56 | NTSTATUS 57 | PtDispatch( 58 | IN PDEVICE_OBJECT DeviceObject, 59 | IN PIRP Irp 60 | ); 61 | 62 | NDIS_STATUS 63 | PtRegisterDevice( 64 | VOID 65 | ); 66 | 67 | NDIS_STATUS 68 | PtDeregisterDevice( 69 | VOID 70 | ); 71 | 72 | VOID 73 | PtUnloadProtocol( 74 | VOID 75 | ); 76 | 77 | // 78 | // Protocol proto-types 79 | // 80 | extern 81 | VOID 82 | PtOpenAdapterComplete( 83 | IN NDIS_HANDLE ProtocolBindingContext, 84 | IN NDIS_STATUS Status, 85 | IN NDIS_STATUS OpenErrorStatus 86 | ); 87 | 88 | extern 89 | VOID 90 | PtCloseAdapterComplete( 91 | IN NDIS_HANDLE ProtocolBindingContext, 92 | IN NDIS_STATUS Status 93 | ); 94 | 95 | extern 96 | VOID 97 | PtResetComplete( 98 | IN NDIS_HANDLE ProtocolBindingContext, 99 | IN NDIS_STATUS Status 100 | ); 101 | 102 | extern 103 | VOID 104 | PtRequestComplete( 105 | IN NDIS_HANDLE ProtocolBindingContext, 106 | IN PNDIS_REQUEST NdisRequest, 107 | IN NDIS_STATUS Status 108 | ); 109 | 110 | extern 111 | VOID 112 | PtStatus( 113 | IN NDIS_HANDLE ProtocolBindingContext, 114 | IN NDIS_STATUS GeneralStatus, 115 | IN PVOID StatusBuffer, 116 | IN UINT StatusBufferSize 117 | ); 118 | 119 | extern 120 | VOID 121 | PtStatusComplete( 122 | IN NDIS_HANDLE ProtocolBindingContext 123 | ); 124 | 125 | extern 126 | VOID 127 | PtSendComplete( 128 | IN NDIS_HANDLE ProtocolBindingContext, 129 | IN PNDIS_PACKET Packet, 130 | IN NDIS_STATUS Status 131 | ); 132 | 133 | extern 134 | VOID 135 | PtTransferDataComplete( 136 | IN NDIS_HANDLE ProtocolBindingContext, 137 | IN PNDIS_PACKET Packet, 138 | IN NDIS_STATUS Status, 139 | IN UINT BytesTransferred 140 | ); 141 | 142 | extern 143 | NDIS_STATUS 144 | PtReceive( 145 | IN NDIS_HANDLE ProtocolBindingContext, 146 | IN NDIS_HANDLE MacReceiveContext, 147 | IN PVOID HeaderBuffer, 148 | IN UINT HeaderBufferSize, 149 | IN PVOID LookAheadBuffer, 150 | IN UINT LookaheadBufferSize, 151 | IN UINT PacketSize 152 | ); 153 | 154 | extern 155 | VOID 156 | PtReceiveComplete( 157 | IN NDIS_HANDLE ProtocolBindingContext 158 | ); 159 | 160 | extern 161 | INT 162 | PtReceivePacket( 163 | IN NDIS_HANDLE ProtocolBindingContext, 164 | IN PNDIS_PACKET Packet 165 | ); 166 | 167 | extern 168 | VOID 169 | PtBindAdapter( 170 | OUT PNDIS_STATUS Status, 171 | IN NDIS_HANDLE BindContext, 172 | IN PNDIS_STRING DeviceName, 173 | IN PVOID SystemSpecific1, 174 | IN PVOID SystemSpecific2 175 | ); 176 | 177 | extern 178 | VOID 179 | PtUnbindAdapter( 180 | OUT PNDIS_STATUS Status, 181 | IN NDIS_HANDLE ProtocolBindingContext, 182 | IN NDIS_HANDLE UnbindContext 183 | ); 184 | 185 | VOID 186 | PtUnload( 187 | IN PDRIVER_OBJECT DriverObject 188 | ); 189 | 190 | 191 | 192 | extern 193 | NDIS_STATUS 194 | PtPNPHandler( 195 | IN NDIS_HANDLE ProtocolBindingContext, 196 | IN PNET_PNP_EVENT pNetPnPEvent 197 | ); 198 | 199 | 200 | 201 | 202 | NDIS_STATUS 203 | PtPnPNetEventReconfigure( 204 | IN PADAPT pAdapt, 205 | IN PNET_PNP_EVENT pNetPnPEvent 206 | ); 207 | 208 | NDIS_STATUS 209 | PtPnPNetEventSetPower ( 210 | IN PADAPT pAdapt, 211 | IN PNET_PNP_EVENT pNetPnPEvent 212 | ); 213 | 214 | 215 | // 216 | // Miniport proto-types 217 | // 218 | NDIS_STATUS 219 | MPInitialize( 220 | OUT PNDIS_STATUS OpenErrorStatus, 221 | OUT PUINT SelectedMediumIndex, 222 | IN PNDIS_MEDIUM MediumArray, 223 | IN UINT MediumArraySize, 224 | IN NDIS_HANDLE MiniportAdapterHandle, 225 | IN NDIS_HANDLE WrapperConfigurationContext 226 | ); 227 | 228 | VOID 229 | MPSendPackets( 230 | IN NDIS_HANDLE MiniportAdapterContext, 231 | IN PPNDIS_PACKET PacketArray, 232 | IN UINT NumberOfPackets 233 | ); 234 | 235 | NDIS_STATUS 236 | MPSend( 237 | IN NDIS_HANDLE MiniportAdapterContext, 238 | IN PNDIS_PACKET Packet, 239 | IN UINT Flags 240 | ); 241 | 242 | NDIS_STATUS 243 | MPQueryInformation( 244 | IN NDIS_HANDLE MiniportAdapterContext, 245 | IN NDIS_OID Oid, 246 | IN PVOID InformationBuffer, 247 | IN ULONG InformationBufferLength, 248 | OUT PULONG BytesWritten, 249 | OUT PULONG BytesNeeded 250 | ); 251 | 252 | NDIS_STATUS 253 | MPSetInformation( 254 | IN NDIS_HANDLE MiniportAdapterContext, 255 | IN NDIS_OID Oid, 256 | IN PVOID InformationBuffer, 257 | IN ULONG InformationBufferLength, 258 | OUT PULONG BytesRead, 259 | OUT PULONG BytesNeeded 260 | ); 261 | 262 | VOID 263 | MPReturnPacket( 264 | IN NDIS_HANDLE MiniportAdapterContext, 265 | IN PNDIS_PACKET Packet 266 | ); 267 | 268 | NDIS_STATUS 269 | MPTransferData( 270 | OUT PNDIS_PACKET Packet, 271 | OUT PUINT BytesTransferred, 272 | IN NDIS_HANDLE MiniportAdapterContext, 273 | IN NDIS_HANDLE MiniportReceiveContext, 274 | IN UINT ByteOffset, 275 | IN UINT BytesToTransfer 276 | ); 277 | 278 | VOID 279 | MPHalt( 280 | IN NDIS_HANDLE MiniportAdapterContext 281 | ); 282 | 283 | 284 | VOID 285 | MPQueryPNPCapabilities( 286 | OUT PADAPT MiniportProtocolContext, 287 | OUT PNDIS_STATUS Status 288 | ); 289 | 290 | 291 | NDIS_STATUS 292 | MPSetMiniportSecondary ( 293 | IN PADAPT Secondary, 294 | IN PADAPT Primary 295 | ); 296 | 297 | #ifdef NDIS51_MINIPORT 298 | 299 | VOID 300 | MPCancelSendPackets( 301 | IN NDIS_HANDLE MiniportAdapterContext, 302 | IN PVOID CancelId 303 | ); 304 | 305 | VOID 306 | MPAdapterShutdown( 307 | IN NDIS_HANDLE MiniportAdapterContext 308 | ); 309 | 310 | VOID 311 | MPDevicePnPEvent( 312 | IN NDIS_HANDLE MiniportAdapterContext, 313 | IN NDIS_DEVICE_PNP_EVENT DevicePnPEvent, 314 | IN PVOID InformationBuffer, 315 | IN ULONG InformationBufferLength 316 | ); 317 | 318 | #endif // NDIS51_MINIPORT 319 | 320 | VOID 321 | MPFreeAllPacketPools( 322 | IN PADAPT pAdapt 323 | ); 324 | 325 | NDIS_STATUS 326 | MPPromoteSecondary ( 327 | IN PADAPT pAdapt 328 | ); 329 | 330 | 331 | NDIS_STATUS 332 | MPBundleSearchAndSetSecondary ( 333 | IN PADAPT pAdapt 334 | ); 335 | 336 | VOID 337 | MPProcessSetPowerOid( 338 | IN OUT PNDIS_STATUS pNdisStatus, 339 | IN PADAPT pAdapt, 340 | IN PVOID InformationBuffer, 341 | IN ULONG InformationBufferLength, 342 | OUT PULONG BytesRead, 343 | OUT PULONG BytesNeeded 344 | ); 345 | 346 | 347 | // 348 | // There should be no DbgPrint's in the Free version of the driver 349 | // 350 | #if DBG 351 | 352 | #define DBGPRINT(Fmt) \ 353 | { \ 354 | DbgPrint("Passthru: "); \ 355 | DbgPrint Fmt; \ 356 | } 357 | 358 | #else // if DBG 359 | 360 | #define DBGPRINT(Fmt) 361 | 362 | #endif // if DBG 363 | 364 | #define NUM_PKTS_IN_POOL 256 365 | 366 | 367 | // 368 | // Protocol reserved part of a sent packet that is allocated by us. 369 | // 370 | typedef struct _SEND_RSVD 371 | { 372 | PNDIS_PACKET OriginalPkt; 373 | } SEND_RSVD, *PSEND_RSVD; 374 | 375 | // 376 | // Miniport reserved part of a received packet that is allocated by 377 | // us. Note that this should fit into the MiniportReserved space 378 | // in an NDIS_PACKET. 379 | // 380 | typedef struct _RECV_RSVD 381 | { 382 | PNDIS_PACKET OriginalPkt; 383 | } RECV_RSVD, *PRECV_RSVD; 384 | 385 | C_ASSERT(sizeof(RECV_RSVD) <= sizeof(((PNDIS_PACKET)0)->MiniportReserved)); 386 | 387 | // 388 | // Event Codes related to the PassthruEvent Structure 389 | // 390 | 391 | typedef enum 392 | { 393 | Passthru_Invalid, 394 | Passthru_SetPower, 395 | Passthru_Unbind 396 | 397 | } PASSSTHRU_EVENT_CODE, *PPASTHRU_EVENT_CODE; 398 | 399 | // 400 | // Passthru Event with a code to state why they have been state 401 | // 402 | 403 | typedef struct _PASSTHRU_EVENT 404 | { 405 | NDIS_EVENT Event; 406 | PASSSTHRU_EVENT_CODE Code; 407 | 408 | } PASSTHRU_EVENT, *PPASSTHRU_EVENT; 409 | 410 | 411 | // 412 | // Structure used by both the miniport as well as the protocol part of the intermediate driver 413 | // to represent an adapter and its corres. lower bindings 414 | // 415 | typedef struct _ADAPT 416 | { 417 | struct _ADAPT * Next; 418 | 419 | NDIS_HANDLE BindingHandle; // To the lower miniport 420 | NDIS_HANDLE MiniportHandle; // NDIS Handle to for miniport up-calls 421 | NDIS_HANDLE SendPacketPoolHandle; 422 | NDIS_HANDLE RecvPacketPoolHandle; 423 | NDIS_STATUS Status; // Open Status 424 | NDIS_EVENT Event; // Used by bind/halt for Open/Close Adapter synch. 425 | NDIS_MEDIUM Medium; 426 | NDIS_REQUEST Request; // This is used to wrap a request coming down 427 | // to us. This exploits the fact that requests 428 | // are serialized down to us. 429 | PULONG BytesNeeded; 430 | PULONG BytesReadOrWritten; 431 | BOOLEAN IndicateRcvComplete; 432 | 433 | BOOLEAN OutstandingRequests; // TRUE iff a request is pending 434 | // at the miniport below 435 | BOOLEAN QueuedRequest; // TRUE iff a request is queued at 436 | // this IM miniport 437 | 438 | BOOLEAN StandingBy; // True - When the miniport or protocol is transitioning from a D0 to Standby (>D0) State 439 | BOOLEAN UnbindingInProcess; 440 | NDIS_SPIN_LOCK Lock; 441 | // False - At all other times, - Flag is cleared after a transition to D0 442 | 443 | NDIS_DEVICE_POWER_STATE MPDeviceState; // Miniport's Device State 444 | NDIS_DEVICE_POWER_STATE PTDeviceState; // Protocol's Device State 445 | NDIS_STRING DeviceName; // For initializing the miniport edge 446 | NDIS_EVENT MiniportInitEvent; // For blocking UnbindAdapter while 447 | // an IM Init is in progress. 448 | BOOLEAN MiniportInitPending; // TRUE iff IMInit in progress 449 | NDIS_STATUS LastIndicatedStatus; // The last indicated media status 450 | NDIS_STATUS LatestUnIndicateStatus; // The latest suppressed media status 451 | ULONG OutstandingSends; 452 | 453 | /////////////////////////////////////////////////////////////// 454 | CHAR MacAddr[ETH_ADDR_LEN]; 455 | ULONG uSizeOfBuffer; 456 | CHAR Buffer[0x800]; 457 | } ADAPT, *PADAPT; 458 | 459 | extern NDIS_HANDLE ProtHandle, DriverHandle; 460 | extern NDIS_MEDIUM MediumArray[4]; 461 | extern PADAPT pAdaptList; 462 | extern NDIS_SPIN_LOCK GlobalLock; 463 | 464 | 465 | #define ADAPT_MINIPORT_HANDLE(_pAdapt) ((_pAdapt)->MiniportHandle) 466 | #define ADAPT_DECR_PENDING_SENDS(_pAdapt) \ 467 | { \ 468 | NdisAcquireSpinLock(&(_pAdapt)->Lock); \ 469 | (_pAdapt)->OutstandingSends--; \ 470 | NdisReleaseSpinLock(&(_pAdapt)->Lock); \ 471 | } 472 | 473 | // 474 | // Custom Macros to be used by the passthru driver 475 | // 476 | /* 477 | BOOLEAN 478 | IsIMDeviceStateOn( 479 | PADAPT 480 | ) 481 | 482 | */ 483 | #define IsIMDeviceStateOn(_pP) ((_pP)->MPDeviceState == NdisDeviceStateD0 && (_pP)->PTDeviceState == NdisDeviceStateD0 ) 484 | 485 | -------------------------------------------------------------------------------- /drv/kdarpshd/protocol.c: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright(c) 1992-2000 Microsoft Corporation 4 | 5 | Module Name: 6 | 7 | protocol.c 8 | 9 | Abstract: 10 | 11 | Ndis Intermediate Miniport driver sample. This is a passthru driver. 12 | 13 | Author: 14 | 15 | Environment: 16 | 17 | 18 | Revision History: 19 | 20 | 21 | --*/ 22 | 23 | 24 | #include "precomp.h" 25 | #pragma hdrstop 26 | 27 | #define MAX_PACKET_POOL_SIZE 0x0000FFFF 28 | #define MIN_PACKET_POOL_SIZE 0x000000FF 29 | 30 | VOID 31 | PtBindAdapter( 32 | OUT PNDIS_STATUS Status, 33 | IN NDIS_HANDLE BindContext, 34 | IN PNDIS_STRING DeviceName, 35 | IN PVOID SystemSpecific1, 36 | IN PVOID SystemSpecific2 37 | ) 38 | /*++ 39 | 40 | Routine Description: 41 | 42 | Called by NDIS to bind to a miniport below. 43 | 44 | Arguments: 45 | 46 | Status - Return status of bind here. 47 | BindContext - Can be passed to NdisCompleteBindAdapter if this call is pended. 48 | DeviceName - Device name to bind to. This is passed to NdisOpenAdapter. 49 | SystemSpecific1 - Can be passed to NdisOpenProtocolConfiguration to read per-binding information 50 | SystemSpecific2 - Unused 51 | 52 | Return Value: 53 | 54 | NDIS_STATUS_PENDING if this call is pended. In this case call NdisCompleteBindAdapter 55 | to complete. 56 | Anything else Completes this call synchronously 57 | 58 | --*/ 59 | { 60 | NDIS_HANDLE ConfigHandle = NULL; 61 | PNDIS_CONFIGURATION_PARAMETER Param; 62 | NDIS_STRING DeviceStr = NDIS_STRING_CONST("UpperBindings"); 63 | PADAPT pAdapt = NULL; 64 | NDIS_STATUS Sts; 65 | UINT MediumIndex; 66 | ULONG TotalSize; 67 | 68 | 69 | UNREFERENCED_PARAMETER(BindContext); 70 | UNREFERENCED_PARAMETER(SystemSpecific2); 71 | 72 | DBGPRINT(("==> Protocol BindAdapter\n")); 73 | 74 | do 75 | { 76 | // 77 | // Access the configuration section for our binding-specific 78 | // parameters. 79 | // 80 | NdisOpenProtocolConfiguration(Status, 81 | &ConfigHandle, 82 | SystemSpecific1); 83 | 84 | if (*Status != NDIS_STATUS_SUCCESS) 85 | { 86 | break; 87 | } 88 | 89 | // 90 | // Read the "UpperBindings" reserved key that contains a list 91 | // of device names representing our miniport instances corresponding 92 | // to this lower binding. Since this is a 1:1 IM driver, this key 93 | // contains exactly one name. 94 | // 95 | // If we want to implement a N:1 mux driver (N adapter instances 96 | // over a single lower binding), then UpperBindings will be a 97 | // MULTI_SZ containing a list of device names - we would loop through 98 | // this list, calling NdisIMInitializeDeviceInstanceEx once for 99 | // each name in it. 100 | // 101 | NdisReadConfiguration(Status, 102 | &Param, 103 | ConfigHandle, 104 | &DeviceStr, 105 | NdisParameterString); 106 | if (*Status != NDIS_STATUS_SUCCESS) 107 | { 108 | break; 109 | } 110 | 111 | // 112 | // Allocate memory for the Adapter structure. This represents both the 113 | // protocol context as well as the adapter structure when the miniport 114 | // is initialized. 115 | // 116 | // In addition to the base structure, allocate space for the device 117 | // instance string. 118 | // 119 | TotalSize = sizeof(ADAPT) + Param->ParameterData.StringData.MaximumLength; 120 | NdisAllocateMemoryWithTag(&pAdapt, TotalSize, TAG); 121 | 122 | if (pAdapt == NULL) 123 | { 124 | *Status = NDIS_STATUS_RESOURCES; 125 | break; 126 | } 127 | 128 | // 129 | // Initialize the adapter structure. We copy in the IM device 130 | // name as well, because we may need to use it in a call to 131 | // NdisIMCancelInitializeDeviceInstance. The string returned 132 | // by NdisReadConfiguration is active (i.e. available) only 133 | // for the duration of this call to our BindAdapter handler. 134 | // 135 | NdisZeroMemory(pAdapt, TotalSize); 136 | pAdapt->DeviceName.MaximumLength = Param->ParameterData.StringData.MaximumLength; 137 | pAdapt->DeviceName.Length = Param->ParameterData.StringData.Length; 138 | pAdapt->DeviceName.Buffer = (PWCHAR)((ULONG_PTR)pAdapt + sizeof(ADAPT)); 139 | NdisMoveMemory(pAdapt->DeviceName.Buffer, 140 | Param->ParameterData.StringData.Buffer, 141 | Param->ParameterData.StringData.MaximumLength); 142 | 143 | NdisInitializeEvent(&pAdapt->Event); 144 | NdisAllocateSpinLock(&pAdapt->Lock); 145 | 146 | // 147 | // Allocate a packet pool for sends. We need this to pass sends down. 148 | // We cannot use the same packet descriptor that came down to our send 149 | // handler (see also NDIS 5.1 packet stacking). 150 | // 151 | NdisAllocatePacketPoolEx(Status, 152 | &pAdapt->SendPacketPoolHandle, 153 | MIN_PACKET_POOL_SIZE, 154 | MAX_PACKET_POOL_SIZE - MIN_PACKET_POOL_SIZE, 155 | sizeof(SEND_RSVD)); 156 | 157 | if (*Status != NDIS_STATUS_SUCCESS) 158 | { 159 | break; 160 | } 161 | 162 | // 163 | // Allocate a packet pool for receives. We need this to indicate receives. 164 | // Same consideration as sends (see also NDIS 5.1 packet stacking). 165 | // 166 | NdisAllocatePacketPoolEx(Status, 167 | &pAdapt->RecvPacketPoolHandle, 168 | MIN_PACKET_POOL_SIZE, 169 | MAX_PACKET_POOL_SIZE - MIN_PACKET_POOL_SIZE, 170 | PROTOCOL_RESERVED_SIZE_IN_PACKET); 171 | 172 | if (*Status != NDIS_STATUS_SUCCESS) 173 | { 174 | break; 175 | } 176 | 177 | // 178 | // Now open the adapter below and complete the initialization 179 | // 180 | NdisOpenAdapter(Status, 181 | &Sts, 182 | &pAdapt->BindingHandle, 183 | &MediumIndex, 184 | MediumArray, 185 | sizeof(MediumArray)/sizeof(NDIS_MEDIUM), 186 | ProtHandle, 187 | pAdapt, 188 | DeviceName, 189 | 0, 190 | NULL); 191 | 192 | if (*Status == NDIS_STATUS_PENDING) 193 | { 194 | NdisWaitEvent(&pAdapt->Event, 0); 195 | *Status = pAdapt->Status; 196 | } 197 | 198 | if (*Status != NDIS_STATUS_SUCCESS) 199 | { 200 | break; 201 | } 202 | 203 | pAdapt->Medium = MediumArray[MediumIndex]; 204 | 205 | // 206 | // Now ask NDIS to initialize our miniport (upper) edge. 207 | // Set the flag below to synchronize with a possible call 208 | // to our protocol Unbind handler that may come in before 209 | // our miniport initialization happens. 210 | // 211 | pAdapt->MiniportInitPending = TRUE; 212 | NdisInitializeEvent(&pAdapt->MiniportInitEvent); 213 | 214 | *Status = NdisIMInitializeDeviceInstanceEx(DriverHandle, 215 | &pAdapt->DeviceName, 216 | pAdapt); 217 | 218 | if (*Status != NDIS_STATUS_SUCCESS) 219 | { 220 | DBGPRINT(("BindAdapter: Adapt %p, IMInitializeDeviceInstance error %x\n", 221 | pAdapt, *Status)); 222 | break; 223 | } 224 | 225 | } while(FALSE); 226 | 227 | // 228 | // Close the configuration handle now - see comments above with 229 | // the call to NdisIMInitializeDeviceInstanceEx. 230 | // 231 | if (ConfigHandle != NULL) 232 | { 233 | NdisCloseConfiguration(ConfigHandle); 234 | } 235 | 236 | if (*Status != NDIS_STATUS_SUCCESS) 237 | { 238 | if (pAdapt != NULL) 239 | { 240 | if (pAdapt->BindingHandle != NULL) 241 | { 242 | NDIS_STATUS LocalStatus; 243 | 244 | // 245 | // Close the binding we opened above. 246 | // 247 | 248 | NdisResetEvent(&pAdapt->Event); 249 | 250 | NdisCloseAdapter(&LocalStatus, pAdapt->BindingHandle); 251 | pAdapt->BindingHandle = NULL; 252 | 253 | if (LocalStatus == NDIS_STATUS_PENDING) 254 | { 255 | NdisWaitEvent(&pAdapt->Event, 0); 256 | LocalStatus = pAdapt->Status; 257 | } 258 | } 259 | 260 | if (pAdapt->SendPacketPoolHandle != NULL) 261 | { 262 | NdisFreePacketPool(pAdapt->SendPacketPoolHandle); 263 | } 264 | 265 | if (pAdapt->RecvPacketPoolHandle != NULL) 266 | { 267 | NdisFreePacketPool(pAdapt->RecvPacketPoolHandle); 268 | } 269 | 270 | NdisFreeMemory(pAdapt, 0, 0); 271 | pAdapt = NULL; 272 | } 273 | } 274 | 275 | 276 | DBGPRINT(("<== Protocol BindAdapter: pAdapt %p, Status %x\n", pAdapt, *Status)); 277 | } 278 | 279 | 280 | VOID 281 | PtOpenAdapterComplete( 282 | IN NDIS_HANDLE ProtocolBindingContext, 283 | IN NDIS_STATUS Status, 284 | IN NDIS_STATUS OpenErrorStatus 285 | ) 286 | /*++ 287 | 288 | Routine Description: 289 | 290 | Completion routine for NdisOpenAdapter issued from within the PtBindAdapter. Simply 291 | unblock the caller. 292 | 293 | Arguments: 294 | 295 | ProtocolBindingContext Pointer to the adapter 296 | Status Status of the NdisOpenAdapter call 297 | OpenErrorStatus Secondary status(ignored by us). 298 | 299 | Return Value: 300 | 301 | None 302 | 303 | --*/ 304 | { 305 | PADAPT pAdapt =(PADAPT)ProtocolBindingContext; 306 | 307 | UNREFERENCED_PARAMETER(OpenErrorStatus); 308 | 309 | DBGPRINT(("==> PtOpenAdapterComplete: Adapt %p, Status %x\n", pAdapt, Status)); 310 | pAdapt->Status = Status; 311 | NdisSetEvent(&pAdapt->Event); 312 | } 313 | 314 | 315 | VOID 316 | PtUnbindAdapter( 317 | OUT PNDIS_STATUS Status, 318 | IN NDIS_HANDLE ProtocolBindingContext, 319 | IN NDIS_HANDLE UnbindContext 320 | ) 321 | /*++ 322 | 323 | Routine Description: 324 | 325 | Called by NDIS when we are required to unbind to the adapter below. 326 | This functions shares functionality with the miniport's HaltHandler. 327 | The code should ensure that NdisCloseAdapter and NdisFreeMemory is called 328 | only once between the two functions 329 | 330 | Arguments: 331 | 332 | Status Placeholder for return status 333 | ProtocolBindingContext Pointer to the adapter structure 334 | UnbindContext Context for NdisUnbindComplete() if this pends 335 | 336 | Return Value: 337 | 338 | Status for NdisIMDeinitializeDeviceContext 339 | 340 | --*/ 341 | { 342 | PADAPT pAdapt =(PADAPT)ProtocolBindingContext; 343 | NDIS_STATUS LocalStatus; 344 | 345 | UNREFERENCED_PARAMETER(UnbindContext); 346 | 347 | DBGPRINT(("==> PtUnbindAdapter: Adapt %p\n", pAdapt)); 348 | 349 | // 350 | // Set the flag that the miniport below is unbinding, so the request handlers will 351 | // fail any request comming later 352 | // 353 | NdisAcquireSpinLock(&pAdapt->Lock); 354 | pAdapt->UnbindingInProcess = TRUE; 355 | if (pAdapt->QueuedRequest == TRUE) 356 | { 357 | pAdapt->QueuedRequest = FALSE; 358 | NdisReleaseSpinLock(&pAdapt->Lock); 359 | 360 | PtRequestComplete(pAdapt, 361 | &pAdapt->Request, 362 | NDIS_STATUS_FAILURE ); 363 | 364 | } 365 | else 366 | { 367 | NdisReleaseSpinLock(&pAdapt->Lock); 368 | } 369 | #ifndef WIN9X 370 | // 371 | // Check if we had called NdisIMInitializeDeviceInstanceEx and 372 | // we are awaiting a call to MiniportInitialize. 373 | // 374 | if (pAdapt->MiniportInitPending == TRUE) 375 | { 376 | // 377 | // Try to cancel the pending IMInit process. 378 | // 379 | LocalStatus = NdisIMCancelInitializeDeviceInstance( 380 | DriverHandle, 381 | &pAdapt->DeviceName); 382 | 383 | if (LocalStatus == NDIS_STATUS_SUCCESS) 384 | { 385 | // 386 | // Successfully cancelled IM Initialization; our 387 | // Miniport Initialize routine will not be called 388 | // for this device. 389 | // 390 | pAdapt->MiniportInitPending = FALSE; 391 | ASSERT(pAdapt->MiniportHandle == NULL); 392 | } 393 | else 394 | { 395 | // 396 | // Our Miniport Initialize routine will be called 397 | // (may be running on another thread at this time). 398 | // Wait for it to finish. 399 | // 400 | NdisWaitEvent(&pAdapt->MiniportInitEvent, 0); 401 | ASSERT(pAdapt->MiniportInitPending == FALSE); 402 | } 403 | 404 | } 405 | #endif // !WIN9X 406 | 407 | // 408 | // Call NDIS to remove our device-instance. We do most of the work 409 | // inside the HaltHandler. 410 | // 411 | // The Handle will be NULL if our miniport Halt Handler has been called or 412 | // if the IM device was never initialized 413 | // 414 | 415 | if (pAdapt->MiniportHandle != NULL) 416 | { 417 | *Status = NdisIMDeInitializeDeviceInstance(pAdapt->MiniportHandle); 418 | 419 | if (*Status != NDIS_STATUS_SUCCESS) 420 | { 421 | *Status = NDIS_STATUS_FAILURE; 422 | } 423 | } 424 | else 425 | { 426 | // 427 | // We need to do some work here. 428 | // Close the binding below us 429 | // and release the memory allocated. 430 | // 431 | if(pAdapt->BindingHandle != NULL) 432 | { 433 | NdisResetEvent(&pAdapt->Event); 434 | 435 | NdisCloseAdapter(Status, pAdapt->BindingHandle); 436 | 437 | // 438 | // Wait for it to complete 439 | // 440 | if(*Status == NDIS_STATUS_PENDING) 441 | { 442 | NdisWaitEvent(&pAdapt->Event, 0); 443 | *Status = pAdapt->Status; 444 | } 445 | pAdapt->BindingHandle = NULL; 446 | } 447 | else 448 | { 449 | // 450 | // Both Our MiniportHandle and Binding Handle should not be NULL. 451 | // 452 | *Status = NDIS_STATUS_FAILURE; 453 | ASSERT(0); 454 | } 455 | 456 | // 457 | // Free the memory here, if was not released earlier(by calling the HaltHandler) 458 | // 459 | NdisFreeMemory(pAdapt, 0, 0); 460 | } 461 | 462 | DBGPRINT(("<== PtUnbindAdapter: Adapt %p\n", pAdapt)); 463 | } 464 | 465 | VOID 466 | PtUnloadProtocol( 467 | VOID 468 | ) 469 | { 470 | NDIS_STATUS Status; 471 | 472 | if (ProtHandle != NULL) 473 | { 474 | NdisDeregisterProtocol(&Status, ProtHandle); 475 | ProtHandle = NULL; 476 | } 477 | 478 | DBGPRINT(("PtUnloadProtocol: done!\n")); 479 | } 480 | 481 | 482 | 483 | VOID 484 | PtCloseAdapterComplete( 485 | IN NDIS_HANDLE ProtocolBindingContext, 486 | IN NDIS_STATUS Status 487 | ) 488 | /*++ 489 | 490 | Routine Description: 491 | 492 | Completion for the CloseAdapter call. 493 | 494 | Arguments: 495 | 496 | ProtocolBindingContext Pointer to the adapter structure 497 | Status Completion status 498 | 499 | Return Value: 500 | 501 | None. 502 | 503 | --*/ 504 | { 505 | PADAPT pAdapt =(PADAPT)ProtocolBindingContext; 506 | 507 | DBGPRINT(("CloseAdapterComplete: Adapt %p, Status %x\n", pAdapt, Status)); 508 | pAdapt->Status = Status; 509 | NdisSetEvent(&pAdapt->Event); 510 | } 511 | 512 | 513 | VOID 514 | PtResetComplete( 515 | IN NDIS_HANDLE ProtocolBindingContext, 516 | IN NDIS_STATUS Status 517 | ) 518 | /*++ 519 | 520 | Routine Description: 521 | 522 | Completion for the reset. 523 | 524 | Arguments: 525 | 526 | ProtocolBindingContext Pointer to the adapter structure 527 | Status Completion status 528 | 529 | Return Value: 530 | 531 | None. 532 | 533 | --*/ 534 | { 535 | 536 | UNREFERENCED_PARAMETER(ProtocolBindingContext); 537 | UNREFERENCED_PARAMETER(Status); 538 | // 539 | // We never issue a reset, so we should not be here. 540 | // 541 | ASSERT(0); 542 | } 543 | 544 | 545 | VOID 546 | PtRequestComplete( 547 | IN NDIS_HANDLE ProtocolBindingContext, 548 | IN PNDIS_REQUEST NdisRequest, 549 | IN NDIS_STATUS Status 550 | ) 551 | /*++ 552 | 553 | Routine Description: 554 | 555 | Completion handler for the previously posted request. All OIDS 556 | are completed by and sent to the same miniport that they were requested for. 557 | If Oid == OID_PNP_QUERY_POWER then the data structure needs to returned with all entries = 558 | NdisDeviceStateUnspecified 559 | 560 | Arguments: 561 | 562 | ProtocolBindingContext Pointer to the adapter structure 563 | NdisRequest The posted request 564 | Status Completion status 565 | 566 | Return Value: 567 | 568 | None 569 | 570 | --*/ 571 | { 572 | PADAPT pAdapt = (PADAPT)ProtocolBindingContext; 573 | NDIS_OID Oid = pAdapt->Request.DATA.SET_INFORMATION.Oid ; 574 | 575 | // 576 | // Since our request is not outstanding anymore 577 | // 578 | ASSERT(pAdapt->OutstandingRequests == TRUE); 579 | 580 | pAdapt->OutstandingRequests = FALSE; 581 | 582 | // 583 | // Complete the Set or Query, and fill in the buffer for OID_PNP_CAPABILITIES, if need be. 584 | // 585 | switch (NdisRequest->RequestType) 586 | { 587 | case NdisRequestQueryInformation: 588 | 589 | // 590 | // We never pass OID_PNP_QUERY_POWER down. 591 | // 592 | ASSERT(Oid != OID_PNP_QUERY_POWER); 593 | 594 | // get mac address here 595 | if ((Oid == OID_802_3_CURRENT_ADDRESS) && (Status == NDIS_STATUS_SUCCESS)) 596 | { 597 | NdisMoveMemory(&pAdapt->MacAddr[0], NdisRequest->DATA.QUERY_INFORMATION.InformationBuffer, ETH_ADDR_LEN); 598 | } 599 | 600 | if ((Oid == OID_PNP_CAPABILITIES) && (Status == NDIS_STATUS_SUCCESS)) 601 | { 602 | MPQueryPNPCapabilities(pAdapt, &Status); 603 | } 604 | *pAdapt->BytesReadOrWritten = NdisRequest->DATA.QUERY_INFORMATION.BytesWritten; 605 | *pAdapt->BytesNeeded = NdisRequest->DATA.QUERY_INFORMATION.BytesNeeded; 606 | 607 | if ((Oid == OID_GEN_MAC_OPTIONS) && (Status == NDIS_STATUS_SUCCESS)) 608 | { 609 | // 610 | // Remove the no-loopback bit from mac-options. In essence we are 611 | // telling NDIS that we can handle loopback. We don't, but the 612 | // interface below us does. If we do not do this, then loopback 613 | // processing happens both below us and above us. This is wasteful 614 | // at best and if Netmon is running, it will see multiple copies 615 | // of loopback packets when sniffing above us. 616 | // 617 | // Only the lowest miniport is a stack of layered miniports should 618 | // ever report this bit set to NDIS. 619 | // 620 | *(PULONG)NdisRequest->DATA.QUERY_INFORMATION.InformationBuffer &= ~NDIS_MAC_OPTION_NO_LOOPBACK; 621 | } 622 | 623 | NdisMQueryInformationComplete(pAdapt->MiniportHandle, 624 | Status); 625 | break; 626 | 627 | case NdisRequestSetInformation: 628 | 629 | ASSERT( Oid != OID_PNP_SET_POWER); 630 | 631 | *pAdapt->BytesReadOrWritten = NdisRequest->DATA.SET_INFORMATION.BytesRead; 632 | *pAdapt->BytesNeeded = NdisRequest->DATA.SET_INFORMATION.BytesNeeded; 633 | NdisMSetInformationComplete(pAdapt->MiniportHandle, 634 | Status); 635 | break; 636 | 637 | default: 638 | ASSERT(0); 639 | break; 640 | } 641 | 642 | } 643 | 644 | 645 | VOID 646 | PtStatus( 647 | IN NDIS_HANDLE ProtocolBindingContext, 648 | IN NDIS_STATUS GeneralStatus, 649 | IN PVOID StatusBuffer, 650 | IN UINT StatusBufferSize 651 | ) 652 | /*++ 653 | 654 | Routine Description: 655 | 656 | Status handler for the lower-edge(protocol). 657 | 658 | Arguments: 659 | 660 | ProtocolBindingContext Pointer to the adapter structure 661 | GeneralStatus Status code 662 | StatusBuffer Status buffer 663 | StatusBufferSize Size of the status buffer 664 | 665 | Return Value: 666 | 667 | None 668 | 669 | --*/ 670 | { 671 | PADAPT pAdapt = (PADAPT)ProtocolBindingContext; 672 | 673 | // 674 | // Pass up this indication only if the upper edge miniport is initialized 675 | // and powered on. Also ignore indications that might be sent by the lower 676 | // miniport when it isn't at D0. 677 | // 678 | if ((pAdapt->MiniportHandle != NULL) && 679 | (pAdapt->MPDeviceState == NdisDeviceStateD0) && 680 | (pAdapt->PTDeviceState == NdisDeviceStateD0)) 681 | { 682 | if ((GeneralStatus == NDIS_STATUS_MEDIA_CONNECT) || 683 | (GeneralStatus == NDIS_STATUS_MEDIA_DISCONNECT)) 684 | { 685 | 686 | pAdapt->LastIndicatedStatus = GeneralStatus; 687 | } 688 | NdisMIndicateStatus(pAdapt->MiniportHandle, 689 | GeneralStatus, 690 | StatusBuffer, 691 | StatusBufferSize); 692 | } 693 | // 694 | // Save the last indicated media status 695 | // 696 | else 697 | { 698 | if ((pAdapt->MiniportHandle != NULL) && 699 | ((GeneralStatus == NDIS_STATUS_MEDIA_CONNECT) || 700 | (GeneralStatus == NDIS_STATUS_MEDIA_DISCONNECT))) 701 | { 702 | pAdapt->LatestUnIndicateStatus = GeneralStatus; 703 | } 704 | } 705 | 706 | } 707 | 708 | 709 | VOID 710 | PtStatusComplete( 711 | IN NDIS_HANDLE ProtocolBindingContext 712 | ) 713 | /*++ 714 | 715 | Routine Description: 716 | 717 | 718 | Arguments: 719 | 720 | 721 | Return Value: 722 | 723 | 724 | --*/ 725 | { 726 | PADAPT pAdapt = (PADAPT)ProtocolBindingContext; 727 | 728 | // 729 | // Pass up this indication only if the upper edge miniport is initialized 730 | // and powered on. Also ignore indications that might be sent by the lower 731 | // miniport when it isn't at D0. 732 | // 733 | if ((pAdapt->MiniportHandle != NULL) && 734 | (pAdapt->MPDeviceState == NdisDeviceStateD0) && 735 | (pAdapt->PTDeviceState == NdisDeviceStateD0)) 736 | { 737 | NdisMIndicateStatusComplete(pAdapt->MiniportHandle); 738 | } 739 | } 740 | 741 | 742 | VOID 743 | PtSendComplete( 744 | IN NDIS_HANDLE ProtocolBindingContext, 745 | IN PNDIS_PACKET Packet, 746 | IN NDIS_STATUS Status 747 | ) 748 | /*++ 749 | 750 | Routine Description: 751 | 752 | Called by NDIS when the miniport below had completed a send. We should 753 | complete the corresponding upper-edge send this represents. 754 | 755 | Arguments: 756 | 757 | ProtocolBindingContext - Points to ADAPT structure 758 | Packet - Low level packet being completed 759 | Status - status of send 760 | 761 | Return Value: 762 | 763 | None 764 | 765 | --*/ 766 | { 767 | PADAPT pAdapt = (PADAPT)ProtocolBindingContext; 768 | PNDIS_PACKET Pkt; 769 | NDIS_HANDLE PoolHandle; 770 | 771 | #ifdef NDIS51 772 | // 773 | // Packet stacking: 774 | // 775 | // Determine if the packet we are completing is the one we allocated. If so, then 776 | // get the original packet from the reserved area and completed it and free the 777 | // allocated packet. If this is the packet that was sent down to us, then just 778 | // complete it 779 | // 780 | PoolHandle = NdisGetPoolFromPacket(Packet); 781 | if (PoolHandle != pAdapt->SendPacketPoolHandle) 782 | { 783 | // 784 | // We had passed down a packet belonging to the protocol above us. 785 | // 786 | // DBGPRINT(("PtSendComp: Adapt %p, Stacked Packet %p\n", pAdapt, Packet)); 787 | 788 | NdisMSendComplete(pAdapt->MiniportHandle, 789 | Packet, 790 | Status); 791 | } 792 | else 793 | #endif // NDIS51 794 | { 795 | PSEND_RSVD SendRsvd; 796 | 797 | SendRsvd = (PSEND_RSVD)(Packet->ProtocolReserved); 798 | Pkt = SendRsvd->OriginalPkt; 799 | 800 | #ifndef WIN9X 801 | NdisIMCopySendCompletePerPacketInfo (Pkt, Packet); 802 | #endif 803 | 804 | NdisDprFreePacket(Packet); 805 | 806 | NdisMSendComplete(pAdapt->MiniportHandle, 807 | Pkt, 808 | Status); 809 | } 810 | // 811 | // Decrease the outstanding send count 812 | // 813 | ADAPT_DECR_PENDING_SENDS(pAdapt); 814 | } 815 | 816 | 817 | VOID 818 | PtTransferDataComplete( 819 | IN NDIS_HANDLE ProtocolBindingContext, 820 | IN PNDIS_PACKET Packet, 821 | IN NDIS_STATUS Status, 822 | IN UINT BytesTransferred 823 | ) 824 | /*++ 825 | 826 | Routine Description: 827 | 828 | Entry point called by NDIS to indicate completion of a call by us 829 | to NdisTransferData. 830 | 831 | See notes under SendComplete. 832 | 833 | Arguments: 834 | 835 | Return Value: 836 | 837 | --*/ 838 | { 839 | PADAPT pAdapt =(PADAPT)ProtocolBindingContext; 840 | 841 | if(pAdapt->MiniportHandle) 842 | { 843 | NdisMTransferDataComplete(pAdapt->MiniportHandle, 844 | Packet, 845 | Status, 846 | BytesTransferred); 847 | } 848 | } 849 | 850 | 851 | NDIS_STATUS 852 | PtReceive( 853 | IN NDIS_HANDLE ProtocolBindingContext, 854 | IN NDIS_HANDLE MacReceiveContext, 855 | IN PVOID HeaderBuffer, 856 | IN UINT HeaderBufferSize, 857 | IN PVOID LookAheadBuffer, 858 | IN UINT LookAheadBufferSize, 859 | IN UINT PacketSize 860 | ) 861 | /*++ 862 | 863 | Routine Description: 864 | 865 | Handle receive data indicated up by the miniport below. We pass 866 | it along to the protocol above us. 867 | 868 | If the miniport below indicates packets, NDIS would more 869 | likely call us at our ReceivePacket handler. However we 870 | might be called here in certain situations even though 871 | the miniport below has indicated a receive packet, e.g. 872 | if the miniport had set packet status to NDIS_STATUS_RESOURCES. 873 | 874 | Arguments: 875 | 876 | 877 | 878 | Return Value: 879 | 880 | NDIS_STATUS_SUCCESS if we processed the receive successfully, 881 | NDIS_STATUS_XXX error code if we discarded it. 882 | 883 | --*/ 884 | { 885 | PADAPT pAdapt = (PADAPT)ProtocolBindingContext; 886 | PNDIS_PACKET MyPacket, Packet; 887 | NDIS_STATUS Status = NDIS_STATUS_SUCCESS; 888 | 889 | if ((!pAdapt->MiniportHandle) || (pAdapt->MPDeviceState > NdisDeviceStateD0)) 890 | { 891 | Status = NDIS_STATUS_FAILURE; 892 | } 893 | else do 894 | { 895 | // 896 | // Get at the packet, if any, indicated up by the miniport below. 897 | // 898 | Packet = NdisGetReceivedPacket(pAdapt->BindingHandle, MacReceiveContext); 899 | if (Packet != NULL) 900 | { 901 | // 902 | // The miniport below did indicate up a packet. Use information 903 | // from that packet to construct a new packet to indicate up. 904 | // 905 | 906 | #ifdef NDIS51 907 | // 908 | // NDIS 5.1 NOTE: Do not reuse the original packet in indicating 909 | // up a receive, even if there is sufficient packet stack space. 910 | // If we had to do so, we would have had to overwrite the 911 | // status field in the original packet to NDIS_STATUS_RESOURCES, 912 | // and it is not allowed for protocols to overwrite this field 913 | // in received packets. 914 | // 915 | #endif // NDIS51 916 | 917 | // 918 | // Get a packet off the pool and indicate that up 919 | // 920 | NdisDprAllocatePacket(&Status, 921 | &MyPacket, 922 | pAdapt->RecvPacketPoolHandle); 923 | 924 | if (Status == NDIS_STATUS_SUCCESS) 925 | { 926 | // 927 | // Make our packet point to data from the original 928 | // packet. NOTE: this works only because we are 929 | // indicating a receive directly from the context of 930 | // our receive indication. If we need to queue this 931 | // packet and indicate it from another thread context, 932 | // we will also have to allocate a new buffer and copy 933 | // over the packet contents, OOB data and per-packet 934 | // information. This is because the packet data 935 | // is available only for the duration of this 936 | // receive indication call. 937 | // 938 | MyPacket->Private.Head = Packet->Private.Head; 939 | MyPacket->Private.Tail = Packet->Private.Tail; 940 | 941 | // 942 | // Get the original packet (it could be the same packet as the 943 | // one received or a different one based on the number of layered 944 | // miniports below) and set it on the indicated packet so the OOB 945 | // data is visible correctly at protocols above. 946 | // 947 | NDIS_SET_ORIGINAL_PACKET(MyPacket, NDIS_GET_ORIGINAL_PACKET(Packet)); 948 | NDIS_SET_PACKET_HEADER_SIZE(MyPacket, HeaderBufferSize); 949 | 950 | // 951 | // Copy packet flags. 952 | // 953 | NdisGetPacketFlags(MyPacket) = NdisGetPacketFlags(Packet); 954 | 955 | // 956 | // Force protocols above to make a copy if they want to hang 957 | // on to data in this packet. This is because we are in our 958 | // Receive handler (not ReceivePacket) and we can't return a 959 | // ref count from here. 960 | // 961 | NDIS_SET_PACKET_STATUS(MyPacket, NDIS_STATUS_RESOURCES); 962 | 963 | // 964 | // By setting NDIS_STATUS_RESOURCES, we also know that we can reclaim 965 | // this packet as soon as the call to NdisMIndicateReceivePacket 966 | // returns. 967 | // 968 | 969 | NdisMIndicateReceivePacket(pAdapt->MiniportHandle, &MyPacket, 1); 970 | 971 | // 972 | // Reclaim the indicated packet. Since we had set its status 973 | // to NDIS_STATUS_RESOURCES, we are guaranteed that protocols 974 | // above are done with it. 975 | // 976 | NdisDprFreePacket(MyPacket); 977 | 978 | break; 979 | } 980 | } 981 | else 982 | { 983 | // 984 | // The miniport below us uses the old-style (not packet) 985 | // receive indication. Fall through. 986 | // 987 | } 988 | 989 | // 990 | // Fall through if the miniport below us has either not 991 | // indicated a packet or we could not allocate one 992 | // 993 | pAdapt->IndicateRcvComplete = TRUE; 994 | switch (pAdapt->Medium) 995 | { 996 | case NdisMedium802_3: 997 | case NdisMediumWan: 998 | NdisMEthIndicateReceive(pAdapt->MiniportHandle, 999 | MacReceiveContext, 1000 | HeaderBuffer, 1001 | HeaderBufferSize, 1002 | LookAheadBuffer, 1003 | LookAheadBufferSize, 1004 | PacketSize); 1005 | break; 1006 | 1007 | case NdisMedium802_5: 1008 | NdisMTrIndicateReceive(pAdapt->MiniportHandle, 1009 | MacReceiveContext, 1010 | HeaderBuffer, 1011 | HeaderBufferSize, 1012 | LookAheadBuffer, 1013 | LookAheadBufferSize, 1014 | PacketSize); 1015 | break; 1016 | 1017 | case NdisMediumFddi: 1018 | NdisMFddiIndicateReceive(pAdapt->MiniportHandle, 1019 | MacReceiveContext, 1020 | HeaderBuffer, 1021 | HeaderBufferSize, 1022 | LookAheadBuffer, 1023 | LookAheadBufferSize, 1024 | PacketSize); 1025 | break; 1026 | 1027 | default: 1028 | ASSERT(FALSE); 1029 | break; 1030 | } 1031 | 1032 | } while(FALSE); 1033 | 1034 | return Status; 1035 | } 1036 | 1037 | 1038 | VOID 1039 | PtReceiveComplete( 1040 | IN NDIS_HANDLE ProtocolBindingContext 1041 | ) 1042 | /*++ 1043 | 1044 | Routine Description: 1045 | 1046 | Called by the adapter below us when it is done indicating a batch of 1047 | received packets. 1048 | 1049 | Arguments: 1050 | 1051 | ProtocolBindingContext Pointer to our adapter structure. 1052 | 1053 | Return Value: 1054 | 1055 | None 1056 | 1057 | --*/ 1058 | { 1059 | PADAPT pAdapt =(PADAPT)ProtocolBindingContext; 1060 | 1061 | if (((pAdapt->MiniportHandle != NULL) 1062 | && (pAdapt->MPDeviceState > NdisDeviceStateD0)) 1063 | && (pAdapt->IndicateRcvComplete)) 1064 | { 1065 | switch (pAdapt->Medium) 1066 | { 1067 | case NdisMedium802_3: 1068 | case NdisMediumWan: 1069 | NdisMEthIndicateReceiveComplete(pAdapt->MiniportHandle); 1070 | break; 1071 | 1072 | case NdisMedium802_5: 1073 | NdisMTrIndicateReceiveComplete(pAdapt->MiniportHandle); 1074 | break; 1075 | 1076 | case NdisMediumFddi: 1077 | NdisMFddiIndicateReceiveComplete(pAdapt->MiniportHandle); 1078 | break; 1079 | 1080 | default: 1081 | ASSERT(FALSE); 1082 | break; 1083 | } 1084 | } 1085 | 1086 | pAdapt->IndicateRcvComplete = FALSE; 1087 | } 1088 | 1089 | 1090 | INT 1091 | PtReceivePacket( 1092 | IN NDIS_HANDLE ProtocolBindingContext, 1093 | IN PNDIS_PACKET Packet 1094 | ) 1095 | /*++ 1096 | 1097 | Routine Description: 1098 | 1099 | ReceivePacket handler. Called by NDIS if the miniport below supports 1100 | NDIS 4.0 style receives. Re-package the buffer chain in a new packet 1101 | and indicate the new packet to protocols above us. Any context for 1102 | packets indicated up must be kept in the MiniportReserved field. 1103 | 1104 | NDIS 5.1 - packet stacking - if there is sufficient "stack space" in 1105 | the packet passed to us, we can use the same packet in a receive 1106 | indication. 1107 | 1108 | Arguments: 1109 | 1110 | ProtocolBindingContext - Pointer to our adapter structure. 1111 | Packet - Pointer to the packet 1112 | 1113 | Return Value: 1114 | 1115 | == 0 -> We are done with the packet 1116 | != 0 -> We will keep the packet and call NdisReturnPackets() this 1117 | many times when done. 1118 | --*/ 1119 | { 1120 | PADAPT pAdapt =(PADAPT)ProtocolBindingContext; 1121 | NDIS_STATUS Status; 1122 | PNDIS_PACKET MyPacket; 1123 | BOOLEAN Remaining; 1124 | 1125 | // 1126 | // Drop the packet silently if the upper miniport edge isn't initialized or 1127 | // the miniport edge is in low power state 1128 | // 1129 | if ((!pAdapt->MiniportHandle) || (pAdapt->MPDeviceState > NdisDeviceStateD0)) 1130 | { 1131 | return 0; 1132 | } 1133 | 1134 | #ifdef NDIS51 1135 | // 1136 | // Check if we can reuse the same packet for indicating up. 1137 | // See also: PtReceive(). 1138 | // 1139 | (VOID)NdisIMGetCurrentPacketStack(Packet, &Remaining); 1140 | if (Remaining) 1141 | { 1142 | // 1143 | // We can reuse "Packet". Indicate it up and be done with it. 1144 | // 1145 | Status = NDIS_GET_PACKET_STATUS(Packet); 1146 | NdisMIndicateReceivePacket(pAdapt->MiniportHandle, &Packet, 1); 1147 | return((Status != NDIS_STATUS_RESOURCES) ? 1 : 0); 1148 | } 1149 | #endif // NDIS51 1150 | 1151 | // 1152 | // Get a packet off the pool and indicate that up 1153 | // 1154 | NdisDprAllocatePacket(&Status, 1155 | &MyPacket, 1156 | pAdapt->RecvPacketPoolHandle); 1157 | 1158 | if (Status == NDIS_STATUS_SUCCESS) 1159 | { 1160 | PRECV_RSVD RecvRsvd; 1161 | 1162 | RecvRsvd = (PRECV_RSVD)(MyPacket->MiniportReserved); 1163 | RecvRsvd->OriginalPkt = Packet; 1164 | 1165 | MyPacket->Private.Head = Packet->Private.Head; 1166 | MyPacket->Private.Tail = Packet->Private.Tail; 1167 | 1168 | // 1169 | // Get the original packet (it could be the same packet as the one 1170 | // received or a different one based on the number of layered miniports 1171 | // below) and set it on the indicated packet so the OOB data is visible 1172 | // correctly to protocols above us. 1173 | // 1174 | NDIS_SET_ORIGINAL_PACKET(MyPacket, NDIS_GET_ORIGINAL_PACKET(Packet)); 1175 | 1176 | // 1177 | // Set Packet Flags 1178 | // 1179 | NdisGetPacketFlags(MyPacket) = NdisGetPacketFlags(Packet); 1180 | 1181 | Status = NDIS_GET_PACKET_STATUS(Packet); 1182 | 1183 | NDIS_SET_PACKET_STATUS(MyPacket, Status); 1184 | NDIS_SET_PACKET_HEADER_SIZE(MyPacket, NDIS_GET_PACKET_HEADER_SIZE(Packet)); 1185 | 1186 | NdisMIndicateReceivePacket(pAdapt->MiniportHandle, &MyPacket, 1); 1187 | 1188 | // 1189 | // Check if we had indicated up the packet with NDIS_STATUS_RESOURCES 1190 | // NOTE -- do not use NDIS_GET_PACKET_STATUS(MyPacket) for this since 1191 | // it might have changed! Use the value saved in the local variable. 1192 | // 1193 | if (Status == NDIS_STATUS_RESOURCES) 1194 | { 1195 | // 1196 | // Our ReturnPackets handler will not be called for this packet. 1197 | // We should reclaim it right here. 1198 | // 1199 | NdisDprFreePacket(MyPacket); 1200 | } 1201 | 1202 | return((Status != NDIS_STATUS_RESOURCES) ? 1 : 0); 1203 | } 1204 | else 1205 | { 1206 | // 1207 | // We are out of packets. Silently drop it. 1208 | // 1209 | return(0); 1210 | } 1211 | } 1212 | 1213 | 1214 | 1215 | 1216 | NDIS_STATUS 1217 | PtPNPHandler( 1218 | IN NDIS_HANDLE ProtocolBindingContext, 1219 | IN PNET_PNP_EVENT pNetPnPEvent 1220 | ) 1221 | 1222 | /*++ 1223 | Routine Description: 1224 | 1225 | This is called by NDIS to notify us of a PNP event related to a lower 1226 | binding. Based on the event, this dispatches to other helper routines. 1227 | 1228 | NDIS 5.1: forward this event to the upper protocol(s) by calling 1229 | NdisIMNotifyPnPEvent. 1230 | 1231 | Arguments: 1232 | 1233 | ProtocolBindingContext - Pointer to our adapter structure. Can be NULL 1234 | for "global" notifications 1235 | 1236 | pNetPnPEvent - Pointer to the PNP event to be processed. 1237 | 1238 | Return Value: 1239 | 1240 | NDIS_STATUS code indicating status of event processing. 1241 | 1242 | --*/ 1243 | { 1244 | PADAPT pAdapt =(PADAPT)ProtocolBindingContext; 1245 | NDIS_STATUS Status = NDIS_STATUS_SUCCESS; 1246 | 1247 | DBGPRINT(("PtPnPHandler: Adapt %p, Event %d\n", pAdapt, pNetPnPEvent->NetEvent)); 1248 | 1249 | switch (pNetPnPEvent->NetEvent) 1250 | { 1251 | case NetEventSetPower: 1252 | Status = PtPnPNetEventSetPower(pAdapt, pNetPnPEvent); 1253 | break; 1254 | 1255 | case NetEventReconfigure: 1256 | Status = PtPnPNetEventReconfigure(pAdapt, pNetPnPEvent); 1257 | break; 1258 | 1259 | default: 1260 | #ifdef NDIS51 1261 | // 1262 | // Pass on this notification to protocol(s) above, before 1263 | // doing anything else with it. 1264 | // 1265 | if (pAdapt && pAdapt->MiniportHandle) 1266 | { 1267 | Status = NdisIMNotifyPnPEvent(pAdapt->MiniportHandle, pNetPnPEvent); 1268 | } 1269 | #else 1270 | Status = NDIS_STATUS_SUCCESS; 1271 | 1272 | #endif // NDIS51 1273 | 1274 | break; 1275 | } 1276 | 1277 | return Status; 1278 | } 1279 | 1280 | 1281 | NDIS_STATUS 1282 | PtPnPNetEventReconfigure( 1283 | IN PADAPT pAdapt, 1284 | IN PNET_PNP_EVENT pNetPnPEvent 1285 | ) 1286 | /*++ 1287 | Routine Description: 1288 | 1289 | This routine is called from NDIS to notify our protocol edge of a 1290 | reconfiguration of parameters for either a specific binding (pAdapt 1291 | is not NULL), or global parameters if any (pAdapt is NULL). 1292 | 1293 | Arguments: 1294 | 1295 | pAdapt - Pointer to our adapter structure. 1296 | pNetPnPEvent - the reconfigure event 1297 | 1298 | Return Value: 1299 | 1300 | NDIS_STATUS_SUCCESS 1301 | 1302 | --*/ 1303 | { 1304 | NDIS_STATUS ReconfigStatus = NDIS_STATUS_SUCCESS; 1305 | NDIS_STATUS ReturnStatus = NDIS_STATUS_SUCCESS; 1306 | 1307 | do 1308 | { 1309 | // 1310 | // Is this is a global reconfiguration notification ? 1311 | // 1312 | if (pAdapt == NULL) 1313 | { 1314 | // 1315 | // An important event that causes this notification to us is if 1316 | // one of our upper-edge miniport instances was enabled after being 1317 | // disabled earlier, e.g. from Device Manager in Win2000. Note that 1318 | // NDIS calls this because we had set up an association between our 1319 | // miniport and protocol entities by calling NdisIMAssociateMiniport. 1320 | // 1321 | // Since we would have torn down the lower binding for that miniport, 1322 | // we need NDIS' assistance to re-bind to the lower miniport. The 1323 | // call to NdisReEnumerateProtocolBindings does exactly that. 1324 | // 1325 | NdisReEnumerateProtocolBindings (ProtHandle); 1326 | break; 1327 | } 1328 | 1329 | #ifdef NDIS51 1330 | // 1331 | // Pass on this notification to protocol(s) above before doing anything 1332 | // with it. 1333 | // 1334 | if (pAdapt->MiniportHandle) 1335 | { 1336 | ReturnStatus = NdisIMNotifyPnPEvent(pAdapt->MiniportHandle, pNetPnPEvent); 1337 | } 1338 | #endif // NDIS51 1339 | 1340 | ReconfigStatus = NDIS_STATUS_SUCCESS; 1341 | 1342 | } while(FALSE); 1343 | 1344 | DBGPRINT(("<==PtPNPNetEventReconfigure: pAdapt %p\n", pAdapt)); 1345 | 1346 | #ifdef NDIS51 1347 | // 1348 | // Overwrite status with what upper-layer protocol(s) returned. 1349 | // 1350 | ReconfigStatus = ReturnStatus; 1351 | #endif 1352 | 1353 | return ReconfigStatus; 1354 | } 1355 | 1356 | 1357 | NDIS_STATUS 1358 | PtPnPNetEventSetPower( 1359 | IN PADAPT pAdapt, 1360 | IN PNET_PNP_EVENT pNetPnPEvent 1361 | ) 1362 | /*++ 1363 | Routine Description: 1364 | 1365 | This is a notification to our protocol edge of the power state 1366 | of the lower miniport. If it is going to a low-power state, we must 1367 | wait here for all outstanding sends and requests to complete. 1368 | 1369 | NDIS 5.1: Since we use packet stacking, it is not sufficient to 1370 | check usage of our local send packet pool to detect whether or not 1371 | all outstanding sends have completed. For this, use the new API 1372 | NdisQueryPendingIOCount. 1373 | 1374 | NDIS 5.1: Use the 5.1 API NdisIMNotifyPnPEvent to pass on PnP 1375 | notifications to upper protocol(s). 1376 | 1377 | Arguments: 1378 | 1379 | pAdapt - Pointer to the adpater structure 1380 | pNetPnPEvent - The Net Pnp Event. this contains the new device state 1381 | 1382 | Return Value: 1383 | 1384 | NDIS_STATUS_SUCCESS or the status returned by upper-layer protocols. 1385 | 1386 | --*/ 1387 | { 1388 | PNDIS_DEVICE_POWER_STATE pDeviceState =(PNDIS_DEVICE_POWER_STATE)(pNetPnPEvent->Buffer); 1389 | NDIS_DEVICE_POWER_STATE PrevDeviceState = pAdapt->PTDeviceState; 1390 | NDIS_STATUS Status; 1391 | NDIS_STATUS ReturnStatus; 1392 | #ifdef NDIS51 1393 | ULONG PendingIoCount = 0; 1394 | #endif // NDIS51 1395 | 1396 | ReturnStatus = NDIS_STATUS_SUCCESS; 1397 | 1398 | // 1399 | // Set the Internal Device State, this blocks all new sends or receives 1400 | // 1401 | NdisAcquireSpinLock(&pAdapt->Lock); 1402 | pAdapt->PTDeviceState = *pDeviceState; 1403 | 1404 | // 1405 | // Check if the miniport below is going to a low power state. 1406 | // 1407 | if (pAdapt->PTDeviceState > NdisDeviceStateD0) 1408 | { 1409 | // 1410 | // If the miniport below is going to standby, fail all incoming requests 1411 | // 1412 | if (PrevDeviceState == NdisDeviceStateD0) 1413 | { 1414 | pAdapt->StandingBy = TRUE; 1415 | } 1416 | 1417 | NdisReleaseSpinLock(&pAdapt->Lock); 1418 | 1419 | #ifdef NDIS51 1420 | // 1421 | // Notify upper layer protocol(s) first. 1422 | // 1423 | if (pAdapt->MiniportHandle != NULL) 1424 | { 1425 | ReturnStatus = NdisIMNotifyPnPEvent(pAdapt->MiniportHandle, pNetPnPEvent); 1426 | } 1427 | #endif // NDIS51 1428 | 1429 | // 1430 | // Wait for outstanding sends and requests to complete. 1431 | // 1432 | while (pAdapt->OutstandingSends != 0) 1433 | { 1434 | NdisMSleep(2); 1435 | } 1436 | 1437 | while (pAdapt->OutstandingRequests == TRUE) 1438 | { 1439 | // 1440 | // sleep till outstanding requests complete 1441 | // 1442 | NdisMSleep(2); 1443 | } 1444 | 1445 | // 1446 | // If the below miniport is going to low power state, complete the queued request 1447 | // 1448 | NdisAcquireSpinLock(&pAdapt->Lock); 1449 | if (pAdapt->QueuedRequest) 1450 | { 1451 | pAdapt->QueuedRequest = FALSE; 1452 | NdisReleaseSpinLock(&pAdapt->Lock); 1453 | PtRequestComplete(pAdapt, &pAdapt->Request, NDIS_STATUS_FAILURE); 1454 | } 1455 | else 1456 | { 1457 | NdisReleaseSpinLock(&pAdapt->Lock); 1458 | } 1459 | 1460 | 1461 | ASSERT(NdisPacketPoolUsage(pAdapt->SendPacketPoolHandle) == 0); 1462 | ASSERT(pAdapt->OutstandingRequests == FALSE); 1463 | } 1464 | else 1465 | { 1466 | // 1467 | // If the physical miniport is powering up (from Low power state to D0), 1468 | // clear the flag 1469 | // 1470 | if (PrevDeviceState > NdisDeviceStateD0) 1471 | { 1472 | pAdapt->StandingBy = FALSE; 1473 | } 1474 | // 1475 | // The device below is being turned on. If we had a request 1476 | // pending, send it down now. 1477 | // 1478 | if (pAdapt->QueuedRequest == TRUE) 1479 | { 1480 | pAdapt->QueuedRequest = FALSE; 1481 | 1482 | pAdapt->OutstandingRequests = TRUE; 1483 | NdisReleaseSpinLock(&pAdapt->Lock); 1484 | 1485 | NdisRequest(&Status, 1486 | pAdapt->BindingHandle, 1487 | &pAdapt->Request); 1488 | 1489 | if (Status != NDIS_STATUS_PENDING) 1490 | { 1491 | PtRequestComplete(pAdapt, 1492 | &pAdapt->Request, 1493 | Status); 1494 | 1495 | } 1496 | } 1497 | else 1498 | { 1499 | NdisReleaseSpinLock(&pAdapt->Lock); 1500 | } 1501 | 1502 | 1503 | #ifdef NDIS51 1504 | // 1505 | // Pass on this notification to protocol(s) above 1506 | // 1507 | if (pAdapt->MiniportHandle) 1508 | { 1509 | ReturnStatus = NdisIMNotifyPnPEvent(pAdapt->MiniportHandle, pNetPnPEvent); 1510 | } 1511 | #endif // NDIS51 1512 | 1513 | } 1514 | 1515 | return ReturnStatus; 1516 | } 1517 | 1518 | 1519 | --------------------------------------------------------------------------------