www.pudn.com > EthernetSpy.zip > packet32.bad.c


#define UNICODE 1 
 
#include  
#include  
 
#include  
#include  
 
#include "packet32.h" 
 
TCHAR   szWindowTitle[] = TEXT("PACKET32.DLL"); 
 
typedef struct _FRAMEETH 
{ 
	BYTE DestAddr[6]; 
	BYTE SrcAddr[6]; 
	USHORT Type; 
	BYTE Dati[1500]; 
}  
FRAMEETH, *PFRAMEETH; 
 
 
#define SWAP(p) (((p)<<8)|((p)>>8)) 
 
#if DBG 
 
#define ODS(_x) OutputDebugString(TEXT(_x)) 
 
#else 
 
#define ODS(_x) 
 
#endif 
 
 
 
 
BOOLEAN StartPacketDriver(LPTSTR ServiceName); 
 
 
 
BYTE Address[4][6] = {	{ 255, 255, 255, 255, 255, 255 }, 
						{ 123,  45, 187, 235,   0,   3 }, 
						{ 227,  35, 177,  25,  43,  23 }, 
						{ 103,  85,  67, 215,   0,  35 }   }; 
 
 
BYTE Type[10][2] = {	{ 0x08,	0x00},  
						{ 0x08, 0x01},  
						{ 0x08, 0x05},  
						{ 0x08, 0x06},  
						{ 0x0B, 0xAD}, 
						{ 0x60, 0x01},  
						{ 0x60, 0x02},	 
						{ 0x60, 0x03},  
						{ 0x60, 0x04},  
						{ 0x60, 0x05}  }; 
 
 
 
BOOL PacketInit(IN PVOID DllHandle, IN ULONG Reason,IN PCONTEXT Context OPTIONAL) 
/*++ 
 
Routine Description: 
 
 
Arguments: 
 
    DllHandle - Not Used 
 
    Reason - Attach or Detach 
 
    Context - Not Used 
 
Return Value: 
 
    SUCCESS - TRUE 
    FAILURE - FALSE 
 
--*/ 
{   
    return TRUE; 
} 
 
 
 
 
 
 
 
LPADAPTER PacketOpenAdapter(LPTSTR   AdapterName) 
 
/*++ 
 
Routine Description: 
 
    This rotine opens an instance of the adapter 
 
Arguments: 
 
    AdapterName - unicode name of the adapter to open 
 
Return Value: 
 
    SUCCESS - returns a pointer to an adapter object 
    FAILURE - NULL 
 
--*/ 
 
{ 
    return (LPADAPTER)(10); 
} 
 
 
VOID PacketCloseAdapter(LPADAPTER   lpAdapter) 
/*++ 
 
Routine Description: 
 
    This rotine closes a previouly opened adapter 
 
Arguments: 
 
    Adapter object returned from PacketOpenAdapter 
 
Return Value: 
 
 
--*/ 
{     
} 
 
 
 
 
LPPACKET PacketAllocatePacket(/*LPADAPTER   AdapterObject*/) 
/*++ 
 
Routine Description: 
 
    This rotine this routine allocates a packet object for use 
    in sending a receiveing packets 
 
Arguments: 
 
    Adapter object returned from PacketOpenAdapter 
 
Return Value: 
 
    SUCCESS - returns packet object 
    FAILURE - NULL 
 
--*/ 
{ 
    LPPACKET    lpPacket = malloc (sizeof (PACKET)); 
 
    return lpPacket; 
 
} 
 
 
 
 
 
VOID PacketFreePacket(LPPACKET    lpPacket) 
{ 
	free (lpPacket); 
} 
 
 
 
 
VOID PacketInitPacket(LPPACKET lpPacket,PVOID Buffer,UINT Length) 
/*++ 
 
Routine Description: 
 
    This rotine initializes a packet object to point to 
    a memory buffer described by Start address and length 
 
Arguments: 
 
    lpPacket   -  Packet object returned by PacketAllocatePacket 
 
    Buffer     -  Begining address of a memory buffer 
 
    Length     -  Length of memory buffer 
 
Return Value: 
 
 
--*/ 
 
{ 
 
	lpPacket->Buffer=Buffer; 
    lpPacket->Length=Length; 
 
} 
 
 
BOOLEAN PacketSendPacket(LPADAPTER   AdapterObject,LPPACKET    lpPacket,BOOLEAN     Sync) 
/*++ 
 
Routine Description: 
 
    This rotine sends a packet to the adapter 
 
Arguments: 
 
    AdapterObject  - AdapterObject return by PacketOpenAdapter 
 
    lpPacket       - Packet object returned by PacketAllocatePacket and initialized 
                     by PacketInitPacket 
 
    Sync           - TRUE if service should wait for packet to transmit 
 
 
Return Value: 
 
    SUCCESS - TRUE if succeeded and SYNC==TRUE 
    FAILURE - 
 
--*/ 
 
{ 
 
    return TRUE; 
 
} 
 
 
 
BOOLEAN PacketReceivePacket(LPADAPTER AdapterObject,LPPACKET lpPacket,BOOLEAN Sync,PULONG BytesReceived) 
/*++ 
 
Routine Description: 
 
    This rotine issues a receive request from the adapter 
 
Arguments: 
 
    AdapterObject  - AdapterObject return by PacketOpenAdapter 
 
    lpPacket       - Packet object returned by PacketAllocatePacket and initialized 
                     by PacketInitPacket 
 
    Sync           - TRUE if service should wait for packet to transmit 
 
 
Return Value: 
 
    SUCCESS - TRUE if succeeded and SYNC==TRUE 
    FAILURE - 
 
--*/ 
 
 
{ 
    BOOLEAN   Result; 
	PFRAMEETH Buf = (PFRAMEETH)(lpPacket->Buffer); 
 
    lpPacket->OverLapped.Offset=0; 
    lpPacket->OverLapped.OffsetHigh=0; 
 
	*BytesReceived = rand() % 1500 + 15; 
  
    if (Sync)  
	{ 
		Sleep (1 + rand() % 50); 
 
		memcpy (Buf->SrcAddr, Address[rand() % 4], 6); 
		memcpy (Buf->DestAddr, Address[rand() % 4], 6); 
		memcpy (&Buf->Type, Type[rand() % 10], 2); 
    }  
	else  
	{ 
        Result=TRUE; 
    } 
 
    return TRUE; 
} 
 
 
BOOLEAN 
PacketWaitPacket( 
    LPADAPTER  AdapterObject, 
    LPPACKET   lpPacket, 
    PULONG     BytesReceived 
    ) 
/*++ 
 
Routine Description: 
 
    This routine waits for an overlapped IO on a packet to complete 
    Called if the send or receive call specified FALSE for the Sync parmeter 
 
Arguments: 
 
    AdapterObject  - AdapterObject return by PacketOpenAdapter 
 
    lpPacket       - Packet object returned by PacketAllocatePacket and initialized 
                     by PacketInitPacket 
 
Return Value: 
 
    SUCCESS - TRUE if overlapped call succeeded 
    FAILURE - 
 
--*/ 
 
{ 
	PFRAMEETH Buf = (PFRAMEETH)(lpPacket->Buffer); 
 
	*BytesReceived = rand() % 1500 + 15; 
 
	memcpy (Buf->SrcAddr, Address[rand() % 4], 6); 
	memcpy (Buf->DestAddr, Address[rand() % 4], 6); 
	memcpy (&Buf->Type, Type[rand() % 10], 2); 
		 
    Sleep (1 + rand() % 50); 
 
	return TRUE; 
 
} 
 
 
BOOLEAN 
PacketResetAdapter( 
    LPADAPTER  AdapterObject 
    ) 
/*++ 
 
Routine Description: 
 
    This rotuine resets the adapter. This will complete all pending sends receives and requests 
 
Arguments: 
 
    AdapterObject  - AdapterObject return by PacketOpenAdapter 
 
Return Value: 
 
    SUCCESS - TRUE if overlapped call succeeded 
    FAILURE - 
 
--*/ 
 
{ 
    
 
    return TRUE; 
 
} 
 
 
BOOLEAN 
PacketRequest( 
    LPADAPTER  AdapterObject, 
    BOOLEAN    Set, 
    PPACKET_OID_DATA  OidData 
    ) 
/*++ 
 
Routine Description: 
 
    This routine sends issues a request to and adapter 
 
Arguments: 
 
    AdapterObject  - AdapterObject return by PacketOpenAdapter 
 
    Set            - True means that the request is SET otherwise it is a query 
 
    OidData        - Structure containing the details of the OID 
 
Return Value: 
 
    SUCCESS - 
    FAILURE - 
 
--*/ 
 
{ 
    
 
    return TRUE; 
} 
 
 
 
BOOLEAN 
PacketSetFilter( 
    LPADAPTER  AdapterObject, 
    ULONG      Filter 
    ) 
/*++ 
 
Routine Description: 
 
    This rotine sets the adapters packet filter 
 
Arguments: 
 
    AdapterObject  - AdapterObject return by PacketOpenAdapter 
 
    Filter         - filter to be set 
 
Return Value: 
 
    SUCCESS - 
    FAILURE - 
 
--*/ 
 
{ 
 
     
    return TRUE; 
 
} 
 
 
BOOLEAN 
StartPacketDriver( 
    LPTSTR     ServiceName 
    ) 
/*++ 
 
Routine Description: 
 
    This routine Atempts to start the kernel mode packet driver 
 
Arguments: 
 
    ServiceName  - Name of service to try to start 
 
Return Value: 
 
    SUCCESS - 
    FAILURE - 
 
--*/ 
 
{ 
 
 
    return TRUE; 
 
} 
 
 
 
 
ULONG 
PacketGetAdapterNames( 
    PTSTR   pStr, 
    PULONG  BufferSize 
    ) 
/*++ 
 
Routine Description: 
 
    This routine returns the names all adapters availible 
 
Arguments: 
 
    Pstr       -  Pointer to a buffer which recieves the UNICODE names 
                  Each name is NULL terminated with a second NULL at the end 
                  of the list. 
 
    BufferSize -  Size of the buffer passed in 
 
 
Return Value: 
 
 
    SUCCESS - 
    FAILURE - 
 
--*/ 
 
{ 
 
    
 
    return TRUE; 
 
} 
 
 
BOOLEAN PacketQueryHardwareAddress( LPADAPTER  AdapterObject, PBYTE Addr) 
/*++ 
 
Routine Description: 
 
    This rotine querys the adapters hardware address 
 
Arguments: 
 
    AdapterObject  - AdapterObject return by PacketOpenAdapter 
 
    Addr           - returned hardware address 
 
Return Value: 
 
    SUCCESS - 
    FAILURE - 
 
--*/ 
 
{ 
    return TRUE; 
}