Tool to find native module’s pipeline events registration (source code)
//
// Filename – getmreg.cxx
// Build this as an executable.
// Keep this exe and module dll
// in the same folder
//
// Run using "getmreg.exe <path to module>"
//
// This tool uses hostable web core functionality
// of IIS7. So this will only run on machine with
// IIS7 installed. You don’t need to have w3svc running.
//
#include <stdio.h>
#include <windows.h>
#include "httpserv.h"
#include "hwebcore.h"
extern "C"
HRESULT hr = S_OK;
if(argc != 2)
//
pszSystemDir = (PWSTR)malloc((dwSize + 1)* sizeof(WCHAR));
if(GetSystemDirectory(pszSystemDir, dwSize + 1) == 0)
PWSTR hwebcore = (PWSTR)malloc(MAX_PATH * sizeof(WCHAR));
}
if(wcslen(pszSystemDir) > MAX_PATH – 22)
pfnWebcoreActivate = (PFN_WEB_CORE_ACTIVATE)GetProcAddress(
pfnWebcoreShutdown = (PFN_WEB_CORE_SHUTDOWN) GetProcAddress(
if(pfnWebcoreActivate == NULL ||
//
if(dwSize == 0)
//
*(pszLastSlash + 1) = 0;
//
DWORD dwPort = 31212;
if(dwSize == 0)
pszTempPath = (PWSTR)malloc((dwSize + 1)* sizeof(WCHAR));
if(GetTempPath(dwSize + 1, pszTempPath) == 0)
PWSTR configPath = (PWSTR)malloc(MAX_PATH * sizeof(WCHAR));
hr = WriteContentToConfigFile(
if(hConfigFile != NULL)
//
//
finished:
//
if(hwebcore != NULL)
if(pszHelperModulePath != NULL)
if(pszTempPath != NULL)
if(configPath != NULL)
return 0;
HRESULT
HRESULT hr = S_OK;
PCSTR pszConfigContent3 =
//
strcpy(pszConfigContent, pszConfigContent1);
//
hr = E_FAIL;
goto finished;
finished:
if(pszPort != NULL)
#include "httpserv.h"
#include "http.h"
#include <stdio.h>
class MyRegistrationProvider : IHttpModuleRegistrationInfo
{
public:
MyRegistrationProvider(
IHttpModuleRegistrationInfo *pModuleInfo
)
{
_pModuleInfo = pModuleInfo;
_pModuleFactory = NULL;
_pGlobalModule = NULL;
}
~MyRegistrationProvider()
{
if(_pModuleFactory != NULL)
{
_pModuleFactory->Terminate();
}
if(_pGlobalModule != NULL)
{
_pGlobalModule->Terminate();
}
}
PCWSTR
GetName(
VOID
) const
{
return _pModuleInfo->GetName();
}
HTTP_MODULE_ID
GetId(
VOID
) const
{
return _pModuleInfo->GetId();
}
HRESULT
SetRequestNotifications(
IN IHttpModuleFactory * pModuleFactory,
IN DWORD dwRequestNotifications,
IN DWORD dwPostRequestNotifications
)
{
//
// Print request notifications
//
_pModuleFactory = pModuleFactory;
wprintf(L"Request notifications\r\n");
PrintRequestNotifications(dwRequestNotifications, dwPostRequestNotifications);
wprintf(L"\r\n");
//
// Blindly return S_OK. We don’t actually want to
// the notifications
//
return S_OK;
}
HRESULT
SetGlobalNotifications(
IN CGlobalModule * pGlobalModule,
IN DWORD dwGlobalNotifications
)
{
//
// Print global notifications
//
_pGlobalModule = pGlobalModule;
wprintf(L"Global notifications\r\n");
PrintGlobalNotifications(dwGlobalNotifications);
wprintf(L"\r\n");
//
// Blindly return S_OK
//
return S_OK;
}
HRESULT
SetPriorityForRequestNotification(
IN DWORD dwRequestNotification,
IN PCWSTR pszPriority
)
{
//
// Print request notification priority information
//
wprintf(L"Setting priority for request notifications\r\n");
PrintRequestNotifications(dwRequestNotification, 0);
wprintf(L"%s\r\n", pszPriority);
wprintf(L"\r\n");
//
// Blindly return S_OK
//
return S_OK;
}
HRESULT
SetPriorityForGlobalNotification(
IN DWORD dwGlobalNotification,
IN PCWSTR pszPriority
)
{
//
// Print global notification priority information
//
wprintf(L"Setting priority for request notifications\r\n");
PrintGlobalNotifications(dwGlobalNotification);
wprintf(L"%s\r\n", pszPriority);
wprintf(L"\r\n");
//
// Blindly return S_OK
//
return S_OK;
}
private:
IHttpModuleRegistrationInfo * _pModuleInfo;
IHttpModuleFactory * _pModuleFactory;
CGlobalModule * _pGlobalModule;
VOID PrintRequestNotifications(
DWORD dwRequestNotifications,
DWORD dwPostRequestNotifications
);
VOID PrintGlobalNotifications(
DWORD dwGlobalNotifications
);
};
VOID MyRegistrationProvider::PrintRequestNotifications(
DWORD dwRequestNotifications,
DWORD dwPostRequestNotifications
)
{
DWORD count = 0;
PCWSTR rnNames[16] = {
L"RQ_BEGIN_REQUEST",
L"RQ_AUTHENTICATE_REQUEST",
L"RQ_AUTHORIZE_REQUEST",
L"RQ_RESOLVE_REQUEST_CACHE",
L"RQ_MAP_REQUEST_HANDLER",
L"RQ_ACQUIRE_REQUEST_STATE",
L"RQ_PRE_EXECUTE_REQUEST_HANDLER",
L"RQ_EXECUTE_REQUEST_HANDLER",
L"RQ_RELEASE_REQUEST_STATE",
L"RQ_UPDATE_REQUEST_CACHE",
L"RQ_LOG_REQUEST",
L"RQ_END_REQUEST",
L"RQ_MAP_PATH",
L"RQ_READ_ENTITY",
L"RQ_SEND_RESPONSE",
L"RQ_CUSTOM_NOTIFICATION"
};
//
// Print request registration information
//
for(DWORD i = 0; i <= 11; i++)
{
count = (1 << i);
if((dwRequestNotifications & count) != 0)
{
wprintf(L"%s\r\n", rnNames[i]);
}
}
//
// Print asynchronous request registration information
//
for(DWORD i = 0; i <= 3; i++)
{
count = (1 << (31 – i));
if((dwRequestNotifications & count) != 0)
{
wprintf(L"%s\r\n", rnNames[12 + i]);
}
}
//
// Print POST request registration information
//
for(DWORD i = 0; i <= 11; i++)
{
count = (1 << i);
if((dwPostRequestNotifications & count) != 0)
{
wprintf(L"POST_%s\r\n", rnNames[i]);
}
}
//
// Print asynchronous POST request registration information
//
for(DWORD i = 0; i <= 3; i++)
{
count = (1 << (31 – i));
if((dwPostRequestNotifications & count) != 0)
{
wprintf(L"POST_%s\r\n", rnNames[12 + i]);
}
}
}
VOID MyRegistrationProvider::PrintGlobalNotifications(
DWORD dwGlobalNotifications
)
{
DWORD count = 0;
PCWSTR gnNames[16] = {
L"",
L"GL_STOP_LISTENING",
L"GL_CACHE_CLEANUP",
L"",
L"GL_CACHE_OPERATION",
L"GL_HEALTH_CHECK",
L"GL_CONFIGURATION_CHANGE",
L"GL_FILE_CHANGE",
L"GL_PRE_BEGIN_REQUEST",
L"GL_APPLICATION_START",
L"GL_APPLICATION_RESOLVE_MODULES",
L"GL_APPLICATION_STOP",
L"GL_RSCA_QUERY",
L"GL_TRACE_EVENT",
L"GL_CUSTOM_NOTIFICATION",
L"GL_THREAD_CLEANUP"
};
//
// Print global registration information
//
for(DWORD i = 0; i <= 15; i++)
{
count = (1 << i);
if((dwGlobalNotifications & count) != 0)
{
wprintf(L"%s\r\n", gnNames[i]);
}
}
}
HRESULT
RegisterModule(
DWORD dwServerVersion,
IHttpModuleRegistrationInfo * pModuleInfo,
IHttpServer * pGlobalInfo
)
{
HRESULT hr = S_OK;
//
// Load another module
//
HINSTANCE hModule = NULL;
PWSTR pszModulePath = NULL;
DWORD dwSize = 0;
//
// Get the size of the buffer to be allocated
//
dwSize = GetEnvironmentVariable(
L"MODULEPATH",
pszModulePath,
0);
if(dwSize == 0)
{
wprintf(L"Environment variable MODULEPATH should point to module\r\n");
goto finished;
}
//
// Allocate buffer and call again
//
pszModulePath = (PWSTR)malloc(dwSize * sizeof(WCHAR));
if(GetEnvironmentVariable(
L"MODULEPATH",
pszModulePath,
dwSize) == 0)
{
wprintf(L"Error getting environment variable MODULEPATH\r\n");
goto finished;
}
wprintf(L"Registration information for module %s\r\n\r\n", pszModulePath);
//
// Load the module whose registrations need to be found
//
hModule = LoadLibraryEx(
pszModulePath,
NULL,
0);
if(hModule == NULL)
{
wprintf(L"Couldn’t load module\r\n");
wprintf(L"Aborting\r\n");
goto finished;
}
//
// Get RegisterModule entry point
//
PFN_REGISTERMODULE pfnRegisterModule;
pfnRegisterModule = (PFN_REGISTERMODULE)GetProcAddress(hModule, "RegisterModule" );
if(pfnRegisterModule == NULL)
{
wprintf(L"RegisterModule entry point not found\r\n");
wprintf(L"Aborting\r\n");
goto finished;
}
//
// Call register module now
//
MyRegistrationProvider * pRegProvider = new MyRegistrationProvider(pModuleInfo);
hr = pfnRegisterModule(
dwServerVersion,
(IHttpModuleRegistrationInfo *)pRegProvider,
pGlobalInfo);
if(FAILED(hr))
{
wprintf(L"RegisterModule returned error\r\n");
goto finished;
}
finished:
if(pRegProvider != NULL)
{
delete pRegProvider;
pRegProvider = NULL;
}
if(hModule != NULL)
{
FreeLibrary(hModule);
hModule = NULL;
}
if(pszModulePath != NULL)
{
free(pszModulePath);
pszModulePath = NULL;
}
return S_OK;
}
Use attached GetMRegInstall.zip containing GetMRegInstall.exe to install the program.
-Kanwal