static PPEB GetCurrentPeb(VOID) { NTSTATUS (*ZwQueryInformationProcess)(HANDLE ProcessHandle, PROCESSINFOCLASS ProcessInformationClass, PVOID ProcessInformation, ULONG ProcessInformationLength, PULONG ReturnLength); PROCESS_BASIC_INFORMATION ProcessInformation; ULONG ReturnLength; HMODULE library; library = LoadLibrary("ntdll.dll"); if (library == NULL) { return NULL; } ZwQueryInformationProcess = (VOID *)GetProcAddress(library, "ZwQueryInformationProcess"); if (ZwQueryInformationProcess == NULL) { return NULL; } if (ZwQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, &ProcessInformation, sizeof(ProcessInformation), &ReturnLength) != 0) { return NULL; } return ProcessInformation.PebBaseAddress; }
NTSTATUS LpxRegisterProtocol ( IN PUNICODE_STRING NameString ) /*++ Routine Description: This routine introduces this transport to the NDIS interface. Arguments: Irp - Pointer to the request packet representing the I/O request. Return Value: The function value is the status of the operation. STATUS_SUCCESS if all goes well, Failure status if we tried to register and couldn't, STATUS_INSUFFICIENT_RESOURCES if we couldn't even try to register. --*/ { NDIS_STATUS ndisStatus; UNICODE_STRING functionName; PNDIS_PROTOCOL_CHARACTERISTICS ProtChars; UINT ProtCharsLen; ULONG lpxMajorVersion; ULONG lpxMinorVersion; NTSTATUS (*GetVersion) (PRTL_OSVERSIONINFOW); RtlInitUnicodeString( &functionName, L"RtlGetVersion" ); GetVersion = MmGetSystemRoutineAddress( &functionName ); if (GetVersion != NULL) { NTSTATUS status; RTL_OSVERSIONINFOW versionInfo; versionInfo.dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOW); status = GetVersion(&versionInfo); NDAS_ASSERT( NT_SUCCESS(status) ); lpxMajorVersion = versionInfo.dwMajorVersion; lpxMinorVersion = versionInfo.dwMinorVersion; } else { PsGetVersion( &lpxMajorVersion, &lpxMinorVersion, NULL, NULL ); } // Set up the characteristics of this protocol // NDIS 3.0 field if (1) { //if (lpxMajorVersion == 5 && lpxMinorVersion >= 1 || lpxMajorVersion > 5) { ProtChars = (PNDIS_PROTOCOL_CHARACTERISTICS)&Ndis50ProtChars; ProtCharsLen = sizeof(Ndis50ProtChars); ProtChars->MajorNdisVersion = 4; ProtChars->MinorNdisVersion = 0; } else { ProtChars = (PNDIS_PROTOCOL_CHARACTERISTICS)&Ndis40ProtChars; ProtCharsLen = sizeof(Ndis40ProtChars); ProtChars->MajorNdisVersion = 4; ProtChars->MinorNdisVersion = 0; } ProtChars->Filler; ProtChars->Flags; ProtChars->OpenAdapterCompleteHandler = LpxOpenAdapterComplete; ProtChars->CloseAdapterCompleteHandler = LpxCloseAdapterComplete; #ifdef LPX_LOCKS ProtChars->SendCompleteHandler = LpxFakeSendCompletionHandler; ProtChars->TransferDataCompleteHandler = LpxFakeTransferDataComplete; #else ProtChars->SendCompleteHandler = LpxSendCompletionHandler; ProtChars->TransferDataCompleteHandler = LpxTransferDataComplete; #endif ProtChars->ResetCompleteHandler = LpxResetComplete; ProtChars->RequestCompleteHandler = LpxRequestComplete; ProtChars->ReceiveHandler = LpxReceiveIndication; ProtChars->ReceiveCompleteHandler = LpxReceiveComplete; ProtChars->StatusHandler = LpxStatusIndication; ProtChars->StatusCompleteHandler = LpxStatusComplete; ProtChars->Name.Length = NameString->Length; ProtChars->Name.MaximumLength = NameString->MaximumLength; ProtChars->Name.Buffer = NameString->Buffer; // NDIS 4.0 fields ProtChars->ReceivePacketHandler = LpxProtocolReceivePacket; ProtChars->BindAdapterHandler = LpxProtocolBindAdapter; ProtChars->UnbindAdapterHandler = LpxProtocolUnbindAdapter; ProtChars->PnPEventHandler = LpxProtocolPnPEventHandler; ProtChars->UnloadHandler; #if (defined(NDIS50) || defined(NDIS51)) if (1) { //if (ProtChars->MajorNdisVersion == 5) { // Start of NDIS 5.0 extensions. ProtChars->ReservedHandlers; ProtChars->CoSendCompleteHandler = LpxCoSendCompleteHandler; ProtChars->CoStatusHandler = LpxCoStatusHandler; ProtChars->CoReceivePacketHandler = LpxCoReceivePacketHandler; ProtChars->CoAfRegisterNotifyHandler = LpxCoAfRegisterNotifyHandler; } #endif //NDAS_ASSERT( ProtChars->CoSendCompleteHandler == LpxCoSendCompleteHandler ); NdisRegisterProtocol( &ndisStatus, &LpxNdisProtocolHandle, ProtChars, ProtCharsLen ); if (ndisStatus != NDIS_STATUS_SUCCESS) { NDAS_ASSERT(FALSE); #if DBG IF_LPXDBG (LPX_DEBUG_RESOURCE) { LpxPrint1( "LpxInitialize: NdisRegisterProtocol failed: %s\n", LpxGetNdisStatus(ndisStatus) ); } #endif return (NTSTATUS)ndisStatus; }