Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

An Adventure: How to implement a Firewall-Hook Driver?

, 28 Oct 2004
Firewall-Hook driver is a completely unknown method to develop simple packet filtering applications. With this article, I want to tell you how this driver works and what you need to do to use it in your applications.
fwhookdrv_bin.zip
FirewallApp.exe
FwHookDrv.sys
fwhookdrv_src.zip
FirewallHooK
FirewallApp.dsp
FirewallApp.dsw
res
CVS
Entries
Entries.Extra
Repository
Root
FirewallApp.ico
FirewallAppDoc.ico
newtoolbar.bmp
Toolbar.bmp
Driver
buildchk_wxp_x86.log
Debug
FwHookDrv.sys
vc60.idb
FwHookDrv.dsp
FwHookDrv.dsw
makefile
objchk_wxp_x86
i386
fwhookdrv.obj
FwHookDrv.pdb
FwHookDrv.sys
_objects.mac
sources
FwHookDrv.sys
FirewallApp.exe
#if !defined(TDRIVER_CLASS)
#define TDRIVER_CLASS

#pragma once

#include "winsvc.h"


//ERROR CODES
#define DRV_SUCCESS						 (DWORD)0		// Todo bien

#define DRV_ERROR_SCM					 (DWORD)-1		// ERROR al abrir el service manager
#define DRV_ERROR_SERVICE				 (DWORD)-2		// ERROR al crear el servicio
#define DRV_ERROR_MEMORY				 (DWORD)-3		// ERROR al reservar memoria
#define DRV_ERROR_INVALID_PATH_OR_FILE	 (DWORD)-4		// ERROR, Path no valido
#define DRV_ERROR_INVALID_HANDLE		 (DWORD)-5		// ERROR, driver handle no valido
#define DRV_ERROR_STARTING				 (DWORD)-6		// ERROR al poner en Start el driver
#define DRV_ERROR_STOPPING				 (DWORD)-7		// ERROR al parar el driver
#define DRV_ERROR_REMOVING				 (DWORD)-8		// ERROR eliminando el "servicio"
#define DRV_ERROR_IO					 (DWORD)-9		// ERROR en operacion de E/S
#define DRV_ERROR_NO_INITIALIZED		 (DWORD)-10		// ERROR, clase no inicializada
#define DRV_ERROR_ALREADY_INITIALIZED	 (DWORD)-11		// ERROR, clase ya inicializada
#define DRV_ERROR_NULL_POINTER			 (DWORD)-12		// ERROR, puntero a null como parametro
#define DRV_ERROR_UNKNOWN				 (DWORD)-13		// ERROR desconocido



class TDriver
{
public:
	TDriver(void);		//constructor
	~TDriver(void);		//destructor

	// Funciones para inicializar las variables del driver
	DWORD InitDriver(LPCTSTR name, LPCTSTR path, LPCTSTR dosName=NULL);
	DWORD InitDriver(LPCTSTR path);


	// Funciones para carga/descarga del driver. Si start = TRUE, el driver sera puesto en estado Start.
	DWORD LoadDriver(BOOL start = TRUE);
	DWORD LoadDriver(LPCTSTR name, LPCTSTR path, LPCTSTR dosName=NULL, BOOL start=TRUE);
	DWORD LoadDriver(LPCTSTR path, BOOL start=TRUE);

	// Si forceClearData == TRUE, las variables seran eliminadas aunque no podamos eliminar el servicio
	DWORD UnloadDriver(BOOL forceClearData = FALSE);
	
	// Funciones parar comenzar/Parar el servicio
	DWORD StartDriver(void);
	DWORD StopDriver(void);

	// Si vale TRUE, el driver sera eliminado en el destructor
	void SetRemovable(BOOL value);


	// Informacion de estado del driver
	BOOL IsInitialized();
	BOOL IsStarted();
	BOOL IsLoaded();


	// Funcion para obtener un handle al driver
	HANDLE GetDriverHandle(void);

	// Funciones para realizar operaciones de E/S con el driver
	DWORD WriteIo(DWORD code, PVOID buffer, DWORD count);
	DWORD ReadIo(DWORD code, PVOID buffer, DWORD count);
	DWORD RawIo(DWORD code, PVOID inBuffer, DWORD inCount, PVOID outBuffer, DWORD outCount);
	
private:
	HANDLE driverHandle;	// driver handle
	
	LPTSTR driverName;		// Nombre del driver
	LPTSTR driverPath;		// Path del driver
	LPTSTR driverDosName;	// Nombre DOS del driver

	BOOL initialized;		// Variables donde almacenar el estado del driver
	BOOL started;
	BOOL loaded;
	BOOL removable;

	DWORD OpenDevice(void);	// Obtiene un handle al driver	
};

#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Jesus Oliva
Chief Technology Officer
Spain Spain
To summarize: learn, learn, learn... and then try to remember something I.... I don't Know what i have to remember...
 
http://www.olivacorner.com

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150302.1 | Last Updated 28 Oct 2004
Article Copyright 2004 by Jesus Oliva
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid