資源簡介
lsp注入(原理及其實現代碼)
代碼片段和文件信息
//?THIS?CODE?AND?INFORMATION?IS?PROVIDED?“AS?IS“?WITHOUT?WARRANTY?OF
//?ANY?KIND?EITHER?EXPRESSED?OR?IMPLIED?INCLUDING?BUT?NOT?LIMITED?TO
//?THE?IMPLIED?WARRANTIES?OF?MERCHANTABILITY?AND/OR?FITNESS?FOR?A
//?PARTICULAR?PURPOSE.
//
//?Copyright?(C)?2004??Microsoft?Corporation.??All?Rights?Reserved.
//
//?Module?Name:?provider.cpp
//
//?Description:
//
//????This?sample?illustrates?how?to?develop?a?layered?service?provider.
//????This?sample?is?a?pass?through?sample?which?only?counts?the?bytes
//????transfered?on?the?socket.
//
//????This?file?contains?support?functions?that?are?common?to?the?lsp?and
//????the?instlsp?sample?for?enumerating?the?Winsock?catalog?of?service
//????providers.
//
//????Note?all?allocations?made?in?this?routine?use?the?process?heap?and
//????not?the?LSP?heap?since?these?routines?are?also?used?by?the?LSP
//????installer?(which?doesn‘t?create?its?own?heap).
//????
#ifndef?_PSDK_BLD
#include?
#include?
#include?
#endif
#include?
#include?
#include?
#include?“lspcommon.h“
#include?
#include?
CRITICAL_SECTION????gDebugCritSec;
//?Handle?to?a?private?heap?used?by?the?LSP?and?the?installer
HANDLE?gLspHeap?=?NULL;
//
//?Function:?dbgprint
//
//?Description:
//????Format?and?print?a?message?to?the?debugger.
//
#ifdef?DBG
void?
dbgprint(
????char?*format
????...
????)
{
????static??DWORD?pid=0;
????va_list?vl;
????char????dbgbuf1[2048]
????????????dbgbuf2[2048];
????//?Prepend?the?process?ID?to?the?message
????if?(?0?==?pid?)
????{
????????pid?=?GetCurrentProcessId();
????}
????EnterCriticalSection(&gDebugCritSec);
????va_start(vl?format);
????StringCbVPrintf(dbgbuf1?sizeof(dbgbuf1)format?vl);
????StringCbPrintf(dbgbuf2?sizeof(dbgbuf2)“%lu:?%s\r\n“?pid?dbgbuf1);
????va_end(vl);
????OutputDebugString(dbgbuf2);
????LeaveCriticalSection(&gDebugCritSec);
}
#endif
//
//?Function:?GetProviders
//
//?Description:
//????This?enumerates?the?Winsock?catalog?via?the?global?variable?ProtocolInfo.
//
LPWSAPROTOCOL_INFOW?
EnumerateProviders(
????WINSOCK_CATALOG?Catalog?
????LPINT???????????TotalProtocols
????)
{
LPWSAPROTOCOL_INFOW?ProtocolInfo?=?NULL;
DWORD???????????????ProtocolInfoSize?=?0;
INT?????????????????ErrorCode?=?NO_ERROR
????????????????????????rc;
????
????if?(?NULL?==?TotalProtocols?)
????????goto?cleanup;
*TotalProtocols?=?0;
#ifdef?_WIN64
//?Find?out?how?many?entries?we?need?to?enumerate
????if?(?LspCatalog64Only?==?Catalog?)
????{
????????//?Find?the?size?of?the?buffer
????????rc?=?WSCEnumProtocols(?NULL?ProtocolInfo?&ProtocolInfoSize?&ErrorCode?);
????????if?(?SOCKET_ERROR?==?rc?)
????????{
????????????if?(?WSAENOBUFS?!=?ErrorCode?)
????????????????goto?cleanup;
????????????ErrorCode?=?NO_ERROR;
????????}
????????//?Allocate?the?buffer
????????ProtocolInfo?=?(LPWSAPROTOCOL_INFOW)?LspAlloc(
??????????????
評論
共有 條評論