当前位置: 动力学知识库 > 问答 > 编程问答 >

c++ - OpenPrinterAPI Hooking

问题描述:

I am Hooking to OpenPrinter API but it is not getting Hook , my code is as below.

i am not able to hook this function please help me if some parameters(signature) are not correct....

typedef BOOL (WINAPI *OpenPrinterANext)(__in_opt LPSTR pPrinterName,__out LPHANDLE phPrinter,__in_opt LPPRINTER_DEFAULTSA pDefault);

OpenPrinterANext Real_OpenPrinterA = NULL;

typedef BOOL (WINAPI *OpenPrinterWNext)(__in_opt LPWSTR pPrinterName,__out LPHANDLE phPrinter,__in_opt LPPRINTER_DEFAULTSW pDefault);

OpenPrinterWNext Real_OpenPrinterW = NULL;

BOOL WINAPI OpenPrinterACallback(__in_opt LPSTR pPrinterName,__out LPHANDLE phPrinter,__in_opt LPPRINTER_DEFAULTSA pDefault)

{

MessageBoxA(NULL,"OpenPrinterA Function Called","Info",MB_OK);

return Real_OpenPrinterA(pPrinterName,phPrinter, pDefault);

}

BOOL WINAPI OpenPrinterWCallback(__in_opt LPWSTR pPrinterName,__out LPHANDLE phPrinter,__in_opt LPPRINTER_DEFAULTSW pDefault)

{

MessageBoxA(NULL,"OpenPrinterW Function Called","Info",MB_OK);

return Real_OpenPrinterW(pPrinterName,phPrinter, pDefault);

}

BOOL APIENTRY DllMain( HMODULE hModule,

DWORD ul_reason_for_call,

LPVOID lpReserved

)

{

switch (ul_reason_for_call)

{

case DLL_PROCESS_ATTACH:

if (MH_Initialize() != MH_OK)

{

MessageBoxW(NULL,L"Failed Initialize",L"Info!",MB_ICONWARNING|MB_OK);

}

if

if (MH_CreateHook(&OpenPrinterA, &OpenPrinterACallback, reinterpret_cast<void**>(&Real_OpenPrinterA)) != MH_OK)

{

MessageBoxW(NULL,L"Printing Disabled by hooking",L"Info!",MB_ICONWARNING|MB_OK);

}

if (MH_EnableHook(&OpenPrinterA) != MH_OK)

{

MessageBoxW(NULL,L"Failed EnableHook Printing",L"Info!",MB_ICONWARNING|MB_OK);

}

if (MH_CreateHook(&OpenPrinterW, &OpenPrinterWCallback, reinterpret_cast<void**>(&Real_OpenPrinterW)) != MH_OK)

{

MessageBoxW(NULL,L"Printing Disabled by hooking",L"Info!",MB_ICONWARNING|MB_OK);

}

if (MH_EnableHook(&OpenPrinterW) != MH_OK)

{

MessageBoxW(NULL,L"Failed EnableHook Printing",L"Info!",MB_ICONWARNING|MB_OK);

}

break ;

case DLL_PROCESS_DETACH:

if (MH_DisableHook(&OpenPrinterA) != MH_OK)

{

}

if (MH_DisableHook(&OpenPrinterW) != MH_OK)

{

}

if (MH_Uninitialize() != MH_OK)

{

}

break;

}

return TRUE;

}

Please Help me any one

Thanks in Advance

分享给朋友:
您可能感兴趣的文章:
随机阅读: