分享
 
 
 

Windows 9x VPN源代码

王朝system·作者佚名  2006-04-26
窄屏简体版  字體: |||超大  

作者:huyuguang 文章出处:武汉白云黄鹤站 发布时间:2005-11-08 点击:

字体: 【

这个代码是17(oneseven)写的,我和他是源代码共享的,

由于前面友人向我要win9x下的vpn源代码,我相信肯定有

人看了我前面的简介还是不太明白,干脆贴在下面。

下文来自17的毕业论文,别的东西不好都贴上来,毕竟还有

点军队背景。

为了免得大家看的麻烦,我就不分成几块了,其实我是很喜欢

灌水的;-)

垫片模块的源程序:

1.Ndisshim.h,C语言头文件。

/****************************************************************************

* *

* 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. *

* *

****************************************************************************/

#define WANTVXDWRAPS

#include

#include

#include

#include

#include

#include

#include

#include

MAKE_HEADER(DWORD,_stdcall,VKD_Filter_Keyboard_Input, (VOID))

MAKE_HEADER(VOID,_cdecl,Ndis_Hook, ())

MAKE_HEADER(DWORD,_cdecl,_SHELL_PostMessage,(DWORD,DWORD,DWORD,DWORD,DWORD,DWORD

)

MAKE_HEADER(USHORT,_cdecl,Encrypt_reg,(PUCHAR,USHORT,USHORT))

MAKE_HEADER(USHORT,_cdecl,Decrypt_reg,(PUCHAR,USHORT,USHORT))

#define Ndis_Hook PREPEND(Ndis_Hoo

)

#define _SHELL_PostMessage PREPEND(_SHELL_PostMessage)

#define Encrypt_reg PREPEND(Encrypt_

eg)

#define Decrypt_reg PREPEND(Decrypt_

eg)

#define WM_NSHIM_NEW 3002

#define IP_PROTOCOL 0x0008

#define IP_HEADER_LEN 20

#define MAC_HEADER_LEN 14

#define NSHIM_VERSION 0x400

#define NSHIM_V86_FUNCTION1 1

#define NSHIM_V86_FUNCTION2 2

#define NSHIM_PM_FUNCTION1 1

#define NSHIM_PM_FUNCTION2 2

#define MAX_NSHIM_W32_API (sizeof(NSHIM_W32_Proc)/sizeof(DWORD))

#define MAX_SEND_BUF_LIST 10

#define MAX_SEND_PKT_LIST 10

#define MAX_SEND_APPEND_LEN 21

#define MAX_ADAPTER_NUM 5

#define PACKET_REFUSE 0

#define PACKET_MUD 1

#define PACKET_CLEAR 2

#define PACKET_D_REFUSE 3

#define PACKET_D_QUERY 4

#define PACKET_D_CLEAR 5

#define QUERY_SEND_PACKET 0

#define QUERY_RCV_PACKET 1

/*#define ENCRYPT_Service Declare_Service

#define ENCRYPT_DEVICE_ID 0x1800

Begin_Service_Table(ENCRYPT)

ENCRYPT_Service(Encrypt_reg)

ENCRYPT_Service(Decrypt_reg)

End_Service_Table(ENCRYPT)*/

typedef DIOCPARAMETERS *LPDIOC;

typedef struct _MAC_HEADER{

UCHAR MAC_DA[6];

UCHAR MAC_SA[6];

USHORT ProtocolType;

} MAC_HEADER, *PMAC_HEADER;

typedef struct _IP_HEADER{

UCHAR Ver;

UCHAR Service;

UCHAR LengthU;

UCHAR LengthL;

USHORT Identification;

USHORT FragmentOffset;

UCHAR LiveTime;

UCHAR Protocol;

USHORT HeaderCRC;

ULONG IP_SA;

ULONG IP_DA;

} IP_HEADER, *PIP_HEADER;

typedef struct _AC_ITEM

{

ULONG ip;

ULONG net_mask;

USHORT access;

USHORT sndkeyno;

} AC_ITEM, *PAC_ITEM;

typedef struct _EXCP_ITEM

{

ULONG ip;

USHORT tcp_port;

} EXCP_ITEM, *PEXCP_ITEM;

typedef struct _BINDING_INFO{

NDIS_HANDLE BindingHandle;

UCHAR CtrlActived;

NDIS_STRING Name;

} BINDING_INFO, *PBINDING_INFO;

typedef struct _PENDING_INFO{

NDIS_HANDLE ProtocolBindingContext;

PNDIS_HANDLE NdisBindingHandle;

NDIS_STRING Name;

} PENDING_INFO, *PPENDING_INFO;

DWORD _stdcall NSHIM_W32_DeviceIOControl(DWORD, DWORD, DWORD, LPDIOC);

DWORD _stdcall NSHIM_CleanUp(void);

DWORD _stdcall NSHIM_W32_OpenWnd(DWORD, DWORD, LPDIOC);

DWORD _stdcall NSHIM_W32_CloseWnd(DWORD, DWORD, LPDIOC);

DWORD _stdcall NSHIM_W32_GetAdapterInfo(DWORD, DWORD, LPDIOC);

DWORD _stdcall NSHIM_W32_SetAdapterState(DWORD, DWORD, LPDIOC);

DWORD _stdcall NSHIM_W32_SetACState(DWORD, DWORD, LPDIOC);

DWORD _stdcall NSHIM_W32_LoadAccList(DWORD, DWORD, LPDIOC);

DWORD _stdcall NSHIM_W32_LoadExcpList(DWORD, DWORD, LPDIOC);

VOID _stdcall NSHIM_Send(PNDIS_STATUS, NDIS_HANDLE, PNDIS_PACKET);

VOID _stdcall NSHIM_Request(

OUT PNDIS_STATUS Status,

IN NDIS_HANDLE NdisBindingHandle,

IN PNDIS_REQUEST Request

);

VOID NDIS_API

NSHIM_RegisterProtocol(

OUT PNDIS_STATUS Status,

OUT PNDIS_HANDLE NdisProtocolHandle,

IN PNDIS_PROTOCOL_CHARACTERISTICS ProtocolCharacteristics,

IN UINT CharacteristicsLength

);

NDIS_STATUS NDIS_API

NSHIM_IPReceive(

IN NDIS_HANDLE NdisBindingContext,

IN NDIS_HANDLE MacReceiveContext,

IN PVOID HeaderBuffer,

IN UINT HeaderBufferSize,

IN PVOID LookaheadBuffer,

IN UINT LookaheadBufferSize,

IN UINT PacketSize

);

VOID NDIS_API

VOID NDIS_API

NSHIM_IPSendComplete(

IN NDIS_HANDLE NdisBindingContext,

IN PNDIS_PACKET Packet,

IN NDIS_STATUS Status

);

VOID NDIS_API

NSHIM_IPOpenAdapterComplete(

IN NDIS_HANDLE ProtocolBindingContext,

IN NDIS_STATUS Status,

IN NDIS_STATUS OpenErrorStatus

);

UINT

CopyPacketToBuffer(

IN OUT PUCHAR Buf, // destination

IN PNDIS_PACKET Packet, // source packet

IN UINT Offset, // offset in packet

IN UINT Length // number of bytes to copy

);

VOID

VOID

CopyNdisString( PNDIS_STRING D_string,

PNDIS_STRING S_string

);

extern USHORT In_cksum( unsigned char *buf,

int len);

/*USHORT Encrypt_reg(PUCHAR buffer,

USHORT buflen,

USHORT sndkeyno

);

USHORT Decrypt_reg(PUCHAR buffer,

USHORT buflen,

USHORT sndkeyno

);*/

UCHAR QueryAccessList(PIP_HEADER Ip_header,

UCHAR QueryType,

PUSHORT sndkeyno

);

UCHAR LoadAccessList(PUCHAR buffer,

ULONG buflen

);

UCHAR LoadExceptList(PUCHAR buffer,

ULONG buflen

);

VOID UnloadLists();

extern DWORD NdisIndicateReceiveAddr;

extern DWORD NdisRequestAddr;

extern DWORD NdisCompleteSendAddr;

//extern DWORD NdisRegisterProtocolAddr;

extern DWORD IPReceiveAddr;

extern DWORD IPSendCompleteAddr;

extern PUCHAR RcvBuffer;

extern PUCHAR IndicateBuffer;

extern PUCHAR TransferBuffer;

extern NDIS_HANDLE RcvPacketPoolHandle;

extern PNDIS_PACKET RcvTransferPacket;

extern NDIS_HANDLE RcvBufferPoolHandle;

extern PNDIS_BUFFER RcvPacketBuffer;

extern PMAC_HEADER RcvMACHeader;

extern PIP_HEADER RcvIPHeader;

extern PUCHAR SendBuffer;

extern PUCHAR CurSendBuffer;

extern PMAC_HEADER SendMACHeader;

extern PIP_HEADER SendIPHeader;

extern NDIS_HANDLE SendBufferPoolHandle;

extern NDIS_HANDLE SendPacketPoolHandle;

extern PNDIS_PACKET SendPktList[MAX_SEND_PKT_LIST];

extern CHAR SendPktListHead;

extern CHAR SendPktListTail;

extern PNDIS_PACKET ReservedPkt[MAX_SEND_PKT_LIST];

extern NDIS_STATUS ReturnStatus;

extern PNDIS_BUFFER BUFFER;

extern DWORD CopiedLen;

extern UINT BytesTransfered;

extern USHORT Old_cksum,New_cksum;

extern DWORD ViewHandle;

extern BINDING_INFO BindingAdapterInfo[MAX_ADAPTER_NUM];

extern UCHAR BindingAdapterNum;

2.Nshim.c 垫片的C语言程序

#include "ndisshim.h"

UINT CurSendPktLen;

UINT MaxSendPktLen;

DWORD NdisIndicateReceiveAddr;

DWORD NdisRequestAddr;

DWORD NdisCompleteSendAddr;

//DWORD NdisRegisterProtocolAddr;

DWORD IPReceiveAddr;

DWORD IPSendCompleteAddr;

DWORD IPOpenAdapterCompleteAddr;

VOID (NDIS_API *NdisSendAddr )( PNDIS_STATUS, NDIS_HANDLE, PNDIS_PACKET);

VOID (NDIS_API *NdisOpenAdapterAddr)(

PNDIS_STATUS ,

PNDIS_STATUS ,

PNDIS_HANDLE ,

PUINT ,

PNDIS_MEDIUM ,

UINT ,

NDIS_HANDLE ,

NDIS_HANDLE ,

PNDIS_STRING ,

UINT ,

PSTRING

);

VOID (NDIS_API *NdisRegisterProtocolAddr)(

PNDIS_STATUS ,

PNDIS_HANDLE ,

PNDIS_PROTOCOL_CHARACTERISTICS ,

UINT

);

/*VOID (NDIS_API *NdisRegisterMacAddr)( PNDIS_STATUS ,

PNDIS_H

NDLE,

NDIS_HA

DLE ,

NDIS_HA

DLE ,

PNDIS_M

C_CHARACTERISTICS,

UINT

);*/

PUCHAR RcvBuffer;

PUCHAR IndicateBuffer;

PUCHAR TransferBuffer;

NDIS_HANDLE RcvPacketPoolHandle;

PNDIS_PACKET RcvTransferPacket;

NDIS_HANDLE RcvBufferPoolHandle;

PNDIS_BUFFER RcvPacketBuffer;

PMAC_HEADER RcvMACHeader;

PIP_HEADER RcvIPHeader;

PUCHAR SendBuffer;

PUCHAR CurSendBuffer;

PMAC_HEADER SendMACHeader;

PIP_HEADER SendIPHeader;

NDIS_HANDLE SendBufferPoolHandle;

NDIS_HANDLE SendPacketPoolHandle;

PNDIS_PACKET SendPktList[MAX_SEND_PKT_LIST];

CHAR SendPktListHead;

CHAR SendPktListTail;

PNDIS_PACKET ReservedPkt[MAX_SEND_PKT_LIST];

NDIS_STATUS ReturnStatus;

PNDIS_BUFFER BUFFER;

DWORD CopiedLen;

UINT BytesTransfered;

UCHAR ReadInfoOK=0;

NDIS_HANDLE IPHandle;

UCHAR AdapterNameBuf[2*MAX_ADAPTER_NUM][10];

BINDING_INFO BindingAdapterInfo[MAX_ADAPTER_NUM];

PENDING_INFO PendingOpenAdapter[MAX_ADAPTER_NUM];

UCHAR BindingAdapterNum = 0;

UCHAR PendOpenNum = 0;

NDIS_STRING TcpName = NDIS_STRING_CONST("MSTCP");

//NDIS_HANDLE MacHandle;

//NDIS_HANDLE WrapperHandle;

//NDIS_HANDLE MacContext;

USHORT Old_cksum,New_cksum;

VOID _stdcall NSHIM_Send(

OUT PNDIS_STATUS Status,

IN NDIS_HANDLE NdisBindingHandle,

IN PNDIS_PACKET Packet

)

{

USHORT sndkeyno;

UCHAR i;

for(i=0;i

if(BindingAdapterInfo[i].BindingHandle==NdisBindingHandle&& Bind

ngAdapterInfo[i].CtrlActived)

break;

}

if(i==BindingAdapterNum) goto forward;

NdisQueryPacket(Packet, NULL, NULL, NULL, &CurSendPktLen);

if(CurSendPktLen>MaxSendPktLen) MaxSendPktLen=CurSendPktLen;

if(SendBuffer!=NULL){

CurSendBuffer=SendBuffer+1500*SendPktListHead;

SendMACHeader=(PMAC_HEADER)CurSendBuffer;

SendIPHeader=(PIP_HEADER)(CurSendBuffer+MAC_HEADER_LEN);

CopiedLen=CopyPacketToBuffer(

CurSendBuffer,

Packet,

0,

MAC_HEADER_LEN //+IP_HEADER_LEN

);

if(SendMACHeader->ProtocolType==IP_PROTOCOL){

CopiedLen = CopyPacketToBuffer(

CurSendBuffer+MAC_HEADER_LEN,//+IP_HEADE

_LEN,

Packet,

MAC_HEADER_LEN, //+IP_HEADER_LEN,

CurSendPktLen-MAC_HEADER_LEN //-IP_HEAD

R_LEN

);

switch( QueryAccessList(SendIPHeader,QUERY_SEND_PACKET,&

ndkeyno) ){

case PACKET_REFUSE :

*Status=NDIS_STATUS_SUCCESS;

return;

case PACKET_CLEAR :

break;

case PACKET_MUD :

CurSendPktLen = Encrypt_reg(

(PUCHAR)

endIPHeader+IP_HEADER_LEN,

CurSendP

tLen-MAC_HEADER_LEN-IP_HEADER_LEN,

sndkeyno

);

CurSendPktLen += (MAC_HEADER_LEN+IP_HEADER_LEN);

Old_cksum = SendIPHeader->HeaderCRC;

SendIPHeader->HeaderCRC = 0;

SendIPHeader->LengthL = (CurSendPktLen-MAC_HEADE

_LEN)&0xff;

SendIPHeader->LengthU = ((CurSendPktLen-MAC_HEAD

R_LEN)&0xff00)>>8;

New_cksum = In_cksum((PUCHAR)SendIPHeader,20);

SendIPHeader->HeaderCRC = New_cksum;

break;

}

NdisQueryPacket(SendPktList[SendPktListHead], NULL, NULL

&BUFFER, NULL);

if(BUFFER!=NULL){

NdisUnchainBufferAtBack( SendPktList[SendPktList

ead],&BUFFER);

NdisFreeBuffer(BUFFER);

}

NdisAllocateBuffer(

&ReturnStatus,

&BUFFER,

SendBufferPoolHandle,

CurSendBuffer, //VirtualAddress,

CurSendPktLen //Length

);

NdisChainBufferAtBack( SendPktList[SendPktListHead],BUFF

R);

R);

SendPktList[SendPktListHead]->ProtocolReserved[0]=SendPk

ListHead;

ReservedPkt[SendPktListHead]=Packet;

NdisSendAddr( Status,

NdisBindingHandle,

SendPktList[SendPktListHead]

);

if(*Status!=NDIS_STATUS_SUCCESS){

SendPktListHead++;

if(SendPktListHead==MAX_SEND_PKT_LIST)

SendPktListHead=0;

}

return;

}

}

}

forward:

_asm pop edi

_asm pop esi

_asm pop ebx

//_asm pop ebp

_asm leave

_asm jmp [NdisSendAddr]

}

VOID NDIS_API

NSHIM_IPSendComplete(

IN NDIS_HANDLE NdisBindingContext,

IN PNDIS_PACKET Packet,

IN NDIS_STATUS Status

)

{

UCHAR i;

for(i=0;i

if(BindingAdapterInfo[i].BindingHandle==(*((PUINT)NdisBindingCon

ext+1)) &&

BindingAdapterInfo[i].CtrlActived)

break;

}

if(i==BindingAdapterNum) goto forward;

if(SendBuffer!= NULL){

CurSendBuffer = SendBuffer+SendPktListHead*1500;

SendMACHeader = (PMAC_HEADER)CurSendBuffer;

CopiedLen = CopyPacketToBuffer(

CurSendBuffer,

Packet,

0,

MAC_HEADER_LEN //+IP_HEADER_LEN

);

if(SendMACHeader->ProtocolType==IP_PROTOCOL){

Packet=ReservedPkt[Packet->ProtocolReserved[0]];

}

}

forward:

_asm pop edi

_asm pop esi

_asm pop ebx

_asm leave

_asm jmp [IPSendCompleteAddr]

}

VOID NDIS_API

NSHIM_Request(

OUT PNDIS_STATUS Status,

IN NDIS_HANDLE NdisBindingHandle,

IN PNDIS_REQUEST Request

)

{

{

UCHAR i;

for(i=0;i

if(BindingAdapterInfo[i].BindingHandle==NdisBindingHandle )

break;

}

if(i==BindingAdapterNum) goto forward;

if( Request->RequestType == NdisRequestQueryInformation){

switch ( Request->DATA.QUERY_INFORMATION.Oid ){

case OID_GEN_MAXIMUM_FRAME_SIZE:

*(PULONG)Request->DATA.QUERY_INFORMATION.InformationBuff

r=1024-14;

break;

case OID_GEN_MAXIMUM_TOTAL_SIZE:

*(PULONG)Request->DATA.QUERY_INFORMATION.InformationBuff

r=1024;

break;

default:

goto forward;

}

Request->DATA.QUERY_INFORMATION.BytesWritten=4;

Request->DATA.QUERY_INFORMATION.BytesNeeded=4;

*Status=NDIS_STATUS_SUCCESS;

return;

}

forward:

_asm pop edi

_asm pop esi

_asm pop ebx

_asm leave

_asm jmp [NdisRequestAddr]

}

VOID NDIS_API

NSHIM_RegisterProtocol(

OUT PNDIS_STATUS Status,

OUT PNDIS_HANDLE NdisProtocolHandle,

IN PNDIS_PROTOCOL_CHARACTERISTICS ProtocolCharacteristics,

IN UINT CharacteristicsLength

)

{

if( !(NdisEqualString(

&TcpName,

&ProtocolCharacteristics->Name,

FALSE

)) )

goto forward;

IPReceiveAddr = ProtocolCharacteristics->ReceiveHandler;

ProtocolCharacteristics->ReceiveHandler = NSHIM_IPReceive;

IPSendCompleteAddr = ProtocolCharacteristics->SendCompleteHandler;

ProtocolCharacteristics->SendCompleteHandler = NSHIM_IPSendComplete;

IPOpenAdapterCompleteAddr = ProtocolCharacteristics->OpenAdapterComplete

andler;

ProtocolCharacteristics->OpenAdapterCompleteHandler = NSHIM_IPOpenAdapte

Complete;

NdisRegisterProtocolAddr(

Status,

NdisProtocolHandle,

ProtocolCharacteristics,

CharacteristicsLength

);

if( *Status==NDIS_STATUS_SUCCESS)

IPHandle = *NdisProtocolHandle;

return;

forward:

_asm pop edi

_asm pop esi

_asm pop ebx

_asm leave

_asm jmp [NdisRegisterProtocolAddr]

}

VOID NDIS_API

NSHIM_OpenAdapter(

OUT PNDIS_STATUS Status,

OUT PNDIS_STATUS OpenErrorStatus,

OUT PNDIS_HANDLE NdisBindingHandle,

OUT PUINT SelectedMediumIndex,

IN PNDIS_MEDIUM MediumArray,

IN UINT MediumArraySize,

IN NDIS_HANDLE NdisProtocolHandle,

IN NDIS_HANDLE ProtocolBindingContext,

IN PNDIS_STRING AdapterName,

IN UINT OpenOptions,

IN PSTRING AddressingInformation OPTIONAL

)

{

{

if( NdisProtocolHandle!=IPHandle ) goto forward;

PendingOpenAdapter[PendOpenNum].ProtocolBindingContext = ProtocolBinding

ontext;

PendingOpenAdapter[PendOpenNum].NdisBindingHandle = NdisBindingHandle;

PendingOpenAdapter[PendOpenNum].Name.Buffer = AdapterNameBuf[PendOpenNum

MAX_ADAPTER_NUM];

CopyNdisString(

&PendingOpenAdapter[PendOpenNum].Name,

AdapterName

);

PendOpenNum++;

NdisOpenAdapterAddr(

Status,

OpenErrorStatus,

NdisBindingHandle,

SelectedMediumIndex,

MediumArray,

MediumArraySize,

NdisProtocolHandle,

ProtocolBindingContext,

AdapterName,

OpenOptions,

AddressingInformation

);

if(*Status==NDIS_STATUS_SUCCESS){

BindingAdapterInfo[BindingAdapterNum].BindingHandle = *NdisBindi

gHandle;

BindingAdapterInfo[BindingAdapterNum].Name.Buffer = AdapterNameB

f[BindingAdapterNum];

CopyNdisString(

&BindingAdapterInfo[BindingAdapterNum].Name,

AdapterName

);

BindingAdapterNum++;

}

return;

forward:

_asm pop edi

_asm pop esi

_asm pop ebx

_asm leave

_asm jmp [NdisOpenAdapterAddr]

}

VOID NDIS_API

NSHIM_IPOpenAdapterComplete(

IN NDIS_HANDLE ProtocolBindingContext,

IN NDIS_STATUS Status,

IN NDIS_STATUS OpenErrorStatus

)

{

UCHAR i;

for(i=0;i

if(PendingOpenAdapter[i].ProtocolBindingContext==ProtocolBinding

ontext)

ontext)

break;

}

if(i==PendOpenNum) goto forward;

if(Status==NDIS_STATUS_SUCCESS){

BindingAdapterInfo[BindingAdapterNum].BindingHandle = *PendingOp

nAdapter[i].NdisBindingHandle;

BindingAdapterInfo[BindingAdapterNum].Name.Buffer = AdapterNameB

f[BindingAdapterNum];

CopyNdisString(

&BindingAdapterInfo[BindingAdapterNum].Name,

&PendingOpenAdapter[i].Name

);

BindingAdapterNum++;

}

forward:

forward:

_asm pop edi

_asm pop esi

_asm pop ebx

_asm leave

_asm jmp [IPOpenAdapterCompleteAddr]

}

NDIS_STATUS NDIS_API

NSHIM_IPReceive(

IN NDIS_HANDLE NdisBindingContext,

IN NDIS_HANDLE MacReceiveContext,

IN PVOID HeaderBuffer,

IN UINT HeaderBufferSize,

IN PVOID LookaheadBuffer,

IN UINT LookaheadBufferSize,

IN UINT PacketSize

)

{

USHORT sndkeyno;

UCHAR i;

for(i=0;i

if(BindingAdapterInfo[i].BindingHandle==(*((PUINT)NdisBindingCon

ext+1)) &&

BindingAdapterInfo[i].CtrlActived)

break;

}

if(i==BindingAdapterNum) goto forward;

if(LookaheadBufferSize!=PacketSize){

IndicateBuffer=TransferBuffer-HeaderBufferSize-LookaheadBufferSi

e;

NdisMoveMemory( IndicateBuffer, HeaderBuffer, HeaderBufferSize);

NdisMoveMemory( IndicateBuffer+HeaderBufferSize, LookaheadBuffer

LookaheadBufferSize);

NdisTransferData(

&ReturnStatus,

*((PUINT)NdisBindingContext+1),

MacReceiveContext,

LookaheadBufferSize, // ByteOffset,

PacketSize-LookaheadBufferSize, //BytesT

Transfer,

RcvTransferPacket,

&BytesTransfered

);

HeaderBuffer=IndicateBuffer;

LookaheadBuffer=IndicateBuffer+HeaderBufferSize;

LookaheadBufferSize = PacketSize;

}else{

IndicateBuffer=HeaderBuffer;

}

RcvMACHeader=(PMAC_HEADER)IndicateBuffer;

if(RcvMACHeader->ProtocolType==IP_PROTOCOL){

RcvIPHeader=(PIP_HEADER)(IndicateBuffer+MAC_HEADER_LEN);

switch( QueryAccessList(RcvIPHeader,QUERY_RCV_PACKET,&sndkeyno)

{

case PACKET_REFUSE:

return NDIS_STATUS_SUCCESS;

case PACKET_CLEAR:

goto forward;

case PACKET_MUD:

PacketSize = Decrypt_reg(

(PUCHAR)RcvIPHea

er+IP_HEADER_LEN,

(USHORT)PacketSi

e-IP_HEADER_LEN,

sndkeyno

);

PacketSize += IP_HEADER_LEN;

Old_cksum = RcvIPHeader->HeaderCRC;

RcvIPHeader->HeaderCRC = 0;

RcvIPHeader->LengthL = (USHORT)(PacketSize)&0x00ff;

RcvIPHeader->LengthU = ((USHORT)(PacketSize)&0xff00)>>8;

New_cksum=In_cksum((PUCHAR)RcvIPHeader,IP_HEADER_LEN);

RcvIPHeader->HeaderCRC=New_cksum;

LookaheadBufferSize=PacketSize;

break;

}

}

forward:

_asm pop edi

_asm pop esi

_asm pop ebx

_asm leave

_asm jmp [IPReceiveAddr]

}

/*VOID NDIS_API

NSHIM_RegisterMac(

OUT PNDIS_STATUS Status,

OUT PNDIS_HANDLE NdisMacHandle,

IN NDIS_HANDLE NdisWrapperHandle,

IN NDIS_HANDLE MacMacContext,

IN PNDIS_MAC_CHARACTERISTICS MacCharacteristics,

IN UINT CharacteristicsLength

)

{

WrapperHandle = NdisWrapperHandle;

MacContext = MacMacContext;

NdisRegisterMacAddr(

Status,

NdisMacHandle,

NdisWrapperHandle,

MacMacContext,

MacCharacteristics,

CharacteristicsLength

);

if(*Status==NDIS_STATUS_SUCCESS){

MacHandle = *NdisMacHandle;

}

return;

}*/

UINT

CopyPacketToBuffer(

IN OUT PUCHAR Buf, // destination

IN PNDIS_PACKET Packet, // source packet

IN UINT Offset, // offset in packet

IN UINT Length // number of bytes to copy

)

/*++

Routine Description:

Copies bytes from a packet into a buffer. Used to copy data

out of a packet during loopback indications.

Arguments:

Buf - the destination buffer

Packet - the source packet

Offset - the offset in the packet to start copying at

Length - the number of bytes to copy

Return Value:

The actual number of bytes copied; will be less than Length if

the packet length is less than Offset+Length.

--*/

--*/

{

PNDIS_BUFFER CurBuffer;

UINT BytesCopied;

PUCHAR BufVA;

UINT BufLen;

UINT ToCopy;

UINT CurOffset;

BytesCopied = 0;

//

// First find a spot Offset bytes into the packet.

//

CurOffset = 0;

NdisQueryPacket(Packet, NULL, NULL, &CurBuffer, NULL);

while (CurBuffer != (PNDIS_BUFFER)NULL) {

NdisQueryBuffer(CurBuffer, (PVOID *)&BufVA, &BufLen);

if (CurOffset + BufLen > Offset) {

break;

}

CurOffset += BufLen;

NdisGetNextBuffer(CurBuffer, &CurBuffer);

}

//

// See if the end of the packet has already been passed.

//

if (CurBuffer == (PNDIS_BUFFER)NULL) {

return 0;

}

}

//

// Now copy over Length bytes.

//

BufVA += (Offset - CurOffset);

BufLen -= (Offset - CurOffset);

for (;;) {

ToCopy = (BytesCopied+BufLen > Length) ? Length - BytesCopied : BufLen;

NdisMoveMemory(Buf+BytesCopied, BufVA, ToCopy);

BytesCopied += ToCopy;

if (BytesCopied == Length) {

return BytesCopied;

}

}

NdisGetNextBuffer(CurBuffer, &CurBuffer);

if (CurBuffer == (PNDIS_BUFFER)NULL) {

break;

}

NdisQueryBuffer(CurBuffer, (PVOID *)&BufVA, &BufLen);

}

return BytesCopied;

}

VOID

CopyNdisString( PNDIS_STRING D_string,

PNDIS_STRING S_string

)

{

{

D_string->Length = S_string->Length;

D_string->MaximumLength = S_string->MaximumLength;

NdisMoveMemory( D_string->Buffer, S_string->Buffer, S_string->Length);

return;

}

#pragma VxD_ICODE_SEG

#pragma VxD_IDATA_SEG

DWORD _stdcall NSHIM_Device_Init(void)

{

Out_Debug_String("NSHIMSAMP: Dynamic Init\n\r");

return(VXD_SUCCESS);

}

DWORD _stdcall NSHIM_Sys_Crit_Init(void)

{

UCHAR i;

Ndis_Hook();

if((SendBuffer=(PUCHAR)_HeapAllocate(15000,HEAPLOCKEDIFDP|HEAPZEROINIT))

=NULL){

// SendMACHeader=(PMAC_HEADER)SendBuffer;

// SendIPHeader =(PIP_HEADER)(SendBuffer+14);

NdisAllocateBufferPool(

&ReturnStatus,

&SendBufferPoolHandle,

MAX_SEND_BUF_LIST //* NumberOfD

scriptors

);

if(ReturnStatus!=NDIS_STATUS_SUCCESS){}

NdisAllocatePacketPool(

&ReturnStatus,

&SendPacketPoolHandle,

MAX_SEND_PKT_LIST, //NumberOfDes

riptors,

1 //ProtocolReservedLength

);

if(ReturnStatus!=NDIS_STATUS_SUCCESS){}

for(i=0;i

NdisAllocatePacket(

&ReturnStatus,

&SendPktList[i],

SendPacketPoolHandle

);

if(ReturnStatus!=NDIS_STATUS_SUCCESS){}

}

SendPktListHead=SendPktListTail=0;

}

if((RcvBuffer=(PUCHAR)_HeapAllocate(2000,HEAPLOCKEDIFDP|HEAPZEROINIT))!=

ULL){

TransferBuffer=RcvBuffer+500;

NdisAllocatePacketPool(

&ReturnStatus,

&RcvPacketPoolHandle,

1, //NumberOfDescriptors,

0 //ProtocolReservedLength

);

if(ReturnStatus!=NDIS_STATUS_SUCCESS){}

NdisAllocatePacket(

&ReturnStatus,

&RcvTransferPacket,

RcvPacketPoolHandle

);

if(ReturnStatus!=NDIS_STATUS_SUCCESS){}

NdisAllocateBufferPool(

&ReturnStatus,

&RcvBufferPoolHandle,

1 //* NumberOfDescriptors

);

if(ReturnStatus!=NDIS_STATUS_SUCCESS){}

NdisAllocateBuffer(

&ReturnStatus,

&RcvPacketBuffer,

RcvBufferPoolHandle,

TransferBuffer, //VirtualAddress

1500 //Length

);

if(ReturnStatus!=NDIS_STATUS_SUCCESS){}

NdisChainBufferAtBack(

RcvTransferPacket,

RcvPacketBuffer

);

}

// InitAccessList();

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有