/*++ Copyright (c) 2000 Microsoft Corporation. All rights reserved. --*/ // socksfltr.cpp : Implementation of DLL Exports. // Note: Proxy/Stub Information // To build a separate proxy/stub DLL, // run nmake -f socksfltrps.mk in the project directory. #include "stdafx.h" #include "resource.h" #include #include "socksfltr.h" #include "socksfilter.h" #include "socksfltr_i.c" #include "wspfwext_i.c" #include "socksfilter.h" CComModule _Module; BEGIN_OBJECT_MAP(ObjectMap) OBJECT_ENTRY(CLSID_socksfilter, Csocksfilter) END_OBJECT_MAP() ///////////////////////////////////////////////////////////////////////////// // DLL Entry Point extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/) { if (dwReason == DLL_PROCESS_ATTACH) { _Module.Init(ObjectMap, hInstance, &LIBID_SOCKSFLTRLib); DisableThreadLibraryCalls(hInstance); } else if (dwReason == DLL_PROCESS_DETACH) _Module.Term(); return TRUE; // ok } ///////////////////////////////////////////////////////////////////////////// // Used to determine whether the DLL can be unloaded by OLE STDAPI DllCanUnloadNow(void) { return (_Module.GetLockCount()==0) ? S_OK : S_FALSE; } ///////////////////////////////////////////////////////////////////////////// // Returns a class factory to create an object of the requested type STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) { return _Module.GetClassObject(rclsid, riid, ppv); } //Prototype HRESULT RegisterApplicationFilter(BOOL fRegister); ///////////////////////////////////////////////////////////////////////////// // DllRegisterServer - Adds entries to the system registry STDAPI DllRegisterServer(void) { HRESULT hr; // registers object, typelib and all interfaces in typelib hr = _Module.RegisterServer(TRUE); return hr; } ///////////////////////////////////////////////////////////////////////////// // DllUnregisterServer - Removes entries from the system registry STDAPI DllUnregisterServer(void) { return _Module.UnregisterServer(TRUE); } ///////////////////////////////////////////////////////////////////////////// // DllInstall - Application filter installation STDAPI DllInstall( BOOL bInstall, LPCWSTR ) { return RegisterApplicationFilter(bInstall); } HRESULT RegisterApplicationFilter(BOOL fRegister) { HRESULT hr; IFWXFilterAdmin *ifa = NULL; // Get instance of filter admin object. hr = CoCreateInstance( CLSID_FWXFilterAdmin, NULL, CLSCTX_INPROC_SERVER, IID_IFWXFilterAdmin, (void**)&ifa); if (FAILED(hr)) { return hr; } // Register / unregister if (fRegister) { hr = ifa->InstallFilter( CLSID_socksfilter, // GUID L"SOCKS V5 Sample Filter", //name L"This filter simulate the socks 5 protocol. ", // Description L"Microsoft", //vendor L"4.0",// Version NULL, NULL, 0 ); // It is OK if already installed. if (hr == HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS)) { hr = S_OK; } } else { hr = ifa->UninstallFilter(CLSID_socksfilter); } ifa->Release(); return hr; } #include "SocksConnection.h"