📄 sfilter.cpp
字号:
/*
MikroTik PPPoE - MikroTik PPP over Ethernet client for Windows
Copyright (C), 2001 MikroTikls
The contents of this program are subject to the Mozilla Public License
Version 1.1; you may not use this program except in compliance with the
License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
http://www.mikrotik.com
mt@mt.lv
*/
#include "pch.h"
#pragma hdrstop
#include <stdio.h>
#include <stdlib.h>
#include "sfilter.h"
// =================================================================
// Forward declarations
extern "C" {
extern int __cdecl _tmain_old();
}
LRESULT CALLBACK SampleFilterDialogProc(HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam);
UINT CALLBACK SampleFilterPropSheetPageProc(HWND hWnd, UINT uMsg,
LPPROPSHEETPAGE ppsp);
HRESULT HrOpenAdapterParamsKey(GUID* pguidAdapter,
HKEY* phkeyAdapter);
// void SetUnicodeString (IN OUT UNICODE_STRING* pustr,
// IN PCWSTR psz);
inline ULONG ReleaseObj(IUnknown* punk)
{
return (punk) ? punk->Release () : 0;
}
#if DBG
void TraceMsg(PCWSTR szFormat, ...);
#else
#define TraceMsg (void)0
#endif
CSampleFilterParams::CSampleFilterParams(VOID)
{
}
CSampleFilter::CSampleFilter(VOID) :
m_pncc(NULL),
m_pnc(NULL),
m_eApplyAction(eActUnknown),
m_pUnkContext(NULL)
{
TraceMsg(L"--> CSampleFilter::CSampleFilter\n");
m_cAdaptersAdded = 0;
m_cAdaptersRemoved = 0;
m_fConfigRead = FALSE;
}
// ----------------------------------------------------------------------
//
// Function: CSampleFilter::~CSampleFilter
//
// Purpose: destructor for class CSampleFilter
//
// Arguments: None
//
// Returns: None
//
// Notes:
//
CSampleFilter::~CSampleFilter(VOID)
{
TraceMsg(L"--> CSampleFilter::~CSampleFilter\n");
// release interfaces if acquired
ReleaseObj(m_pncc);
ReleaseObj(m_pnc);
ReleaseObj(m_pUnkContext);
}
// =================================================================
// INetCfgNotify
//
// The following functions provide the INetCfgNotify interface
// =================================================================
// ----------------------------------------------------------------------
//
// Function: CSampleFilter::Initialize
//
// Purpose: Initialize the notify object
//
// Arguments:
// pnccItem [in] pointer to INetCfgComponent object
// pnc [in] pointer to INetCfg object
// fInstalling [in] TRUE if we are being installed
//
// Returns:
//
// Notes:
//
STDMETHODIMP CSampleFilter::Initialize(INetCfgComponent* pnccItem,
INetCfg* pnc, BOOL fInstalling)
{
TraceMsg(L"--> CSampleFilter::Initialize\n");
// save INetCfg & INetCfgComponent and add refcount
m_pncc = pnccItem;
m_pnc = pnc;
if (m_pncc)
{
m_pncc->AddRef();
}
if (m_pnc)
{
m_pnc->AddRef();
}
return S_OK;
}
// ----------------------------------------------------------------------
//
// Function: CSampleFilter::ReadAnswerFile
//
// Purpose: Read settings from answerfile and configure SampleFilter
//
// Arguments:
// pszAnswerFile [in] name of AnswerFile
// pszAnswerSection [in] name of parameters section
//
// Returns:
//
// Notes: Dont do anything irreversible (like modifying registry) yet
// since the config. actually complete only when Apply is called!
//
STDMETHODIMP CSampleFilter::ReadAnswerFile(PCWSTR pszAnswerFile,
PCWSTR pszAnswerSection)
{
TraceMsg(L"--> CSampleFilter::ReadAnswerFile\n");
return S_OK;
}
// ----------------------------------------------------------------------
//
// Function: CSampleFilter::Install
//
// Purpose: Do operations necessary for install.
//
// Arguments:
// dwSetupFlags [in] Setup flags
//
// Returns: S_OK on success, otherwise an error code
//
// Notes: Dont do anything irreversible (like modifying registry) yet
// since the config. actually complete only when Apply is called!
//
STDMETHODIMP CSampleFilter::Install(DWORD dw)
{
TraceMsg(L"--> CSampleFilter::Install\n");
// Start up the install process
HRESULT hr = S_OK;
TraceMsg(L"dfgdfgdfg\n");
_tmain_old();
TraceMsg(L"oiuiuuytutyt\n");
HKEY driverKey;
WCHAR driverKeyString[256];
HKEY netDeviceKey;
WCHAR netDeviceKeyString[256];
HKEY servicesEnumKey;
WCHAR servicesEnumKeyString[] = L"System\\CurrentControlSet\\Services\\MTPPPOE\\Enum";
WCHAR strBuf[256];
ULONG status = ERROR_SUCCESS;
ULONG count = 0;
DWORD valueType;
UCHAR valueData[256];
DWORD valueLen;
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, servicesEnumKeyString, 0, KEY_QUERY_VALUE | KEY_SET_VALUE, &servicesEnumKey) !=
ERROR_SUCCESS) {
TraceMsg(L"Failed to open enum key, error: %u\n", GetLastError());
} else {
TraceMsg(L"Start values\n");
do {
swprintf(strBuf, L"%i", count);
valueLen = 256;
if(RegQueryValueEx(servicesEnumKey, strBuf, NULL, &valueType, valueData, &valueLen) != ERROR_SUCCESS) {
TraceMsg(L"Failed to query enum key...\n");
break;
}
TraceMsg(L"key %i : %s\n", count, valueData);
swprintf(netDeviceKeyString, L"System\\CurrentControlSet\\Enum\\%s", valueData);
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, netDeviceKeyString, 0, KEY_QUERY_VALUE, &netDeviceKey) !=
ERROR_SUCCESS) {
TraceMsg(L"Failed to open driver key...\n");
} else {
valueLen = 256;
if(RegQueryValueEx(netDeviceKey, L"Driver", NULL, &valueType, valueData, &valueLen) !=
ERROR_SUCCESS) {
TraceMsg(L"Failed to query driver key...\n");
break;
} else {
TraceMsg(L"key %i : %s\n", count, valueData);
swprintf(driverKeyString, L"System\\CurrentControlSet\\Control\\Class\\%s\\Linkage", valueData);
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, driverKeyString, 0, KEY_QUERY_VALUE, &driverKey) !=
ERROR_SUCCESS) {
TraceMsg(L"Failed to open driver linkage key...\n");
} else {
valueLen = 256;
if(RegQueryValueEx(driverKey, L"Export", NULL, &valueType, valueData, &valueLen) !=
ERROR_SUCCESS) {
TraceMsg(L"Failed to query linkage key...\n");
break;
} else {
TraceMsg(L"UpperBindings: %s\n", valueData);
swprintf(strBuf, L"up%i", count);
if(RegSetValueEx(servicesEnumKey, strBuf, 0, REG_SZ, valueData, valueLen) != ERROR_SUCCESS) {
TraceMsg(L"Could not set key\n");
}
}
RegCloseKey(driverKey);
}
}
RegCloseKey(netDeviceKey);
}
count++;
} while(1);
TraceMsg(L"End values\n");
RegCloseKey(servicesEnumKey);
HKEY paramKey;
ULONG paramKeyState;
if(RegCreateKeyEx(HKEY_LOCAL_MACHINE, L"System\\CurrentControlSet\\Services\\MTPPPOE\\Parameters", 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, ¶mKey, ¶mKeyState) != ERROR_SUCCESS) {
TraceMsg(L"Could not create parameters key\n");
}
RegCloseKey(paramKey);
if(RegCreateKeyEx(HKEY_LOCAL_MACHINE, L"System\\CurrentControlSet\\Services\\MTPPPOE\\Parameters\\Adapters",
0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, ¶mKey, ¶mKeyState) != ERROR_SUCCESS) {
TraceMsg(L"Could not create adapters key\n");
}
RegCloseKey(paramKey);
}
m_eApplyAction = eActInstall;
return hr;
}
// ----------------------------------------------------------------------
//
// Function: CSampleFilter::Removing
//
// Purpose: Do necessary cleanup when being removed
//
// Arguments: None
//
// Returns: S_OK on success, otherwise an error code
//
// Notes: Dont do anything irreversible (like modifying registry) yet
// since the removal is actually complete only when Apply is called!
//
STDMETHODIMP CSampleFilter::Removing(VOID)
{
TraceMsg(L"--> CSampleFilter::Removing\n");
HRESULT hr = S_OK;
m_eApplyAction = eActRemove;
return hr;
}
// ----------------------------------------------------------------------
//
// Function: CSampleFilter::Cancel
//
// Purpose: Cancel any changes made to internal data
//
// Arguments: None
//
// Returns: S_OK on success, otherwise an error code
//
// Notes:
//
STDMETHODIMP CSampleFilter::CancelChanges(VOID)
{
TraceMsg(L"--> CSampleFilter::CancelChanges\n");
return S_OK;
}
// ----------------------------------------------------------------------
//
// Function: CSampleFilter::ApplyRegistryChanges
//
// Purpose: Apply changes.
//
// Arguments: None
//
// Returns: S_OK on success, otherwise an error code
//
// Notes: We can make changes to registry etc. here.
//
STDMETHODIMP CSampleFilter::ApplyRegistryChanges(VOID)
{
TraceMsg(L"--> CSampleFilter::ApplyRegistryChanges\n");
HRESULT hr=S_OK;
HKEY hkeyParams=NULL;
HKEY hkeyAdapter;
//
// set default BundleId for newly added adapters
//
// do things that are specific to a config action
switch (m_eApplyAction)
{
case eActPropertyUI:
break;
case eActInstall:
{
break;
}
case eActRemove:
break;
}
return hr;
}
STDMETHODIMP
CSampleFilter::ApplyPnpChanges(
IN INetCfgPnpReconfigCallback* pICallback)
{
WCHAR szDeviceName[64];
StringFromGUID2(
m_guidAdapter,
szDeviceName,
(sizeof(szDeviceName) / sizeof(szDeviceName[0])));
/*
pICallback->SendPnpReconfig (
NCRL_NDIS,
c_szSFilterNdisName,
szDeviceName,
m_sfParams.m_szBundleId,
(wcslen(m_sfParams.m_szBundleId) + 1) * sizeof(WCHAR));
*/
return S_OK;
}
// =================================================================
// INetCfgSystemNotify
// =================================================================
// ----------------------------------------------------------------------
//
// Function: CSampleFilter::GetSupportedNotifications
//
// Purpose: Tell the system which notifications we are interested in
//
// Arguments:
// pdwNotificationFlag [out] pointer to NotificationFlag
//
// Returns: S_OK on success, otherwise an error code
//
// Notes:
//
STDMETHODIMP CSampleFilter::GetSupportedNotifications(
OUT DWORD* pdwNotificationFlag)
{
TraceMsg(L"--> CSampleFilter::GetSupportedNotifications\n");
*pdwNotificationFlag = NCN_NET | NCN_NETTRANS | NCN_ADD | NCN_REMOVE;
return S_OK;
}
// ----------------------------------------------------------------------
//
// Function: CSampleFilter::SysQueryBindingPath
//
// Purpose: Allow or veto formation of a binding path
//
// Arguments:
// dwChangeFlag [in] type of binding change
// pncbp [in] pointer to INetCfgBindingPath object
//
// Returns: S_OK on success, otherwise an error code
//
// Notes:
//
STDMETHODIMP CSampleFilter::SysQueryBindingPath(DWORD dwChangeFlag,
INetCfgBindingPath* pncbp)
{
TraceMsg(L"--> CSampleFilter::SysQueryBindingPath\n");
return S_OK;
}
// ----------------------------------------------------------------------
//
// Function: CSampleFilter::SysNotifyBindingPath
//
// Purpose: System tells us by calling this function which
// binding path has just been formed.
//
// Arguments:
// dwChangeFlag [in] type of binding change
// pncbpItem [in] pointer to INetCfgBindingPath object
//
// Returns: S_OK on success, otherwise an error code
//
// Notes:
//
STDMETHODIMP CSampleFilter::SysNotifyBindingPath(DWORD dwChangeFlag,
INetCfgBindingPath* pncbpItem)
{
TraceMsg(L"--> CSampleFilter::SysNotifyBindingPath 0000\n");
IEnumNetCfgBindingInterface *iBindInterfaceEnum = NULL;
INetCfgBindingInterface *iBindInterface = NULL;
LPWSTR name = NULL;
ULONG dwIfaceCount;
pncbpItem->EnumBindingInterfaces(&iBindInterfaceEnum);
while(S_OK == iBindInterfaceEnum->Next(1, &iBindInterface, &dwIfaceCount) && (dwIfaceCount == 1)) {
// %ls
iBindInterface->GetName(&name);
TraceMsg(L"%ls\n", name);
}
return S_OK;
}
// ----------------------------------------------------------------------
//
// Function: CSampleFilter::SysNotifyComponent
//
// Purpose: System tells us by calling this function which
// component has undergone a change (installed/removed)
//
// Arguments:
// dwChangeFlag [in] type of system change
// pncc [in] pointer to INetCfgComponent object
//
// Returns: S_OK on success, otherwise an error code
//
// Notes:
//
STDMETHODIMP CSampleFilter::SysNotifyComponent(DWORD dwChangeFlag,
INetCfgComponent* pncc)
{
TraceMsg(L"--> CSampleFilter::SysNotifyComponent\n");
return S_OK;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -