home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / include / parser.h < prev    next >
C/C++ Source or Header  |  1998-04-25  |  11KB  |  274 lines

  1.  
  2. //=============================================================================
  3. //  Microsoft (R) Bloodhound (tm). Copyright (C) 1991-1994.
  4. //
  5. //  MODULE: parser.h
  6. //
  7. //  This header file defines helper functions for use by Bloodhound parser DLL's.
  8. //=============================================================================
  9.  
  10. #include "bhtypes.h"
  11. #include "frame.h"
  12.  
  13. #if !defined(_PARSER_)
  14.  
  15. #define _PARSER_
  16.  
  17. #pragma pack(1)
  18.  
  19.  
  20. //=============================================================================
  21. //  Format Procedure Type.
  22. //
  23. //  NOTE: All format functions *must* be decalred as WINAPIV not WINAPI!
  24. //=============================================================================
  25.  
  26. typedef VOID (WINAPIV *FORMAT)(LPPROPERTYINST, ...);
  27.  
  28. //=============================================================================
  29. //  PROTOCOL_STATUS_RECOGNIZED:
  30. //
  31. //  The protocol recognized the frame and moved the pointer to end of its
  32. //  protocol header. Bloodhound uses the protocols follow set to continue
  33. //  parsing.
  34. //=============================================================================
  35.  
  36. #define PROTOCOL_STATUS_RECOGNIZED                        0
  37.  
  38. //=============================================================================
  39. //  PROTOCOL_STATUS_NOT_RECOGNIZED:
  40. //
  41. //  The protocol did not recognized the frame and did not move the pointer
  42. //  (i.e. the start data pointer which was passed in). Bloodhound uses the
  43. //  protocols follow set to continue parsing.
  44. //=============================================================================
  45.  
  46. #define PROTOCOL_STATUS_NOT_RECOGNIZED                    1
  47.  
  48. //=============================================================================
  49. //  PROTOCOL_STATUS_CLAIMED:
  50. //
  51. //  The protocol recognized the frame and claimed it all for itself,
  52. //  and parsing terminates.
  53. //=============================================================================
  54.  
  55. #define PROTOCOL_STATUS_CLAIMED                           2
  56.  
  57. //=============================================================================
  58. //  PROTOCOL_STATUS_NEXT_PROTOCOL:
  59. //
  60. //  The protocol recognized the frame and moved the pointer to end of its
  61. //  protocol header. The current protocol requests that Bloodhound continue
  62. //  parsing at a known next protocol by returning the next protocols handle back
  63. //  to Bloodhound. In this case, the follow of the current protocol, if any,
  64. //  is not used.
  65. //=============================================================================
  66.  
  67. #define PROTOCOL_STATUS_NEXT_PROTOCOL                     3
  68.  
  69. //=============================================================================
  70. //  Macros.
  71. //=============================================================================
  72.  
  73. extern  BYTE HexTable[];
  74.  
  75. #define XCHG(x)         MAKEWORD( HIBYTE(x), LOBYTE(x) )
  76.  
  77. #define DXCHG(x)        MAKELONG( XCHG(HIWORD(x)), XCHG(LOWORD(x)) )
  78.  
  79. #define LONIBBLE(b) ((BYTE) ((b) & 0x0F))
  80.  
  81. #define HINIBBLE(b)     ((BYTE) ((b) >> 4))
  82.  
  83. #define HEX(b)          (HexTable[LONIBBLE(b)])
  84.  
  85. #define SWAPBYTES(w)    ((w) = XCHG(w))
  86.  
  87. #define SWAPWORDS(d)    ((d) = DXCHG(d))
  88.  
  89. //=============================================================================
  90. //  All the MAC frame types combined.
  91. //=============================================================================
  92.  
  93. typedef union _MACFRAME
  94. {
  95.     LPBYTE      MacHeader;              //... generic pointer.
  96.     LPETHERNET  Ethernet;               //... ethernet pointer.
  97.     LPTOKENRING Tokenring;              //... tokenring pointer.
  98.     LPFDDI      Fddi;                   //... FDDI pointer.
  99. } MACFRAME;
  100.  
  101. typedef MACFRAME *LPMACFRAME;
  102.  
  103. #define HOT_SIGNATURE       MAKE_IDENTIFIER('H', 'O', 'T', '$')
  104. #define HOE_SIGNATURE       MAKE_IDENTIFIER('H', 'O', 'E', '$')
  105.  
  106. typedef struct _HANDOFFENTRY
  107. {
  108. #ifdef DEBUGNEVER  // remove retail/debug mixing nightmare.
  109.     DWORD       hoe_sig;                    //... 'HOE$'
  110. #endif
  111.  
  112.    DWORD        hoe_ProtIdentNumber;        //Port/Socket number used to determine who to handoff to
  113.    HPROTOCOL    hoe_ProtocolHandle;         //Handle of Protocol to hand off to
  114.    DWORD        hoe_ProtocolData;           //Additional Data to pass to protocol when handed off
  115. } HANDOFFENTRY;
  116.  
  117. typedef HANDOFFENTRY * LPHANDOFFENTRY;    
  118.  
  119. typedef struct _HANDOFFTABLE
  120. {
  121. #ifdef DEBUGNEVER  // remove retail/debug mixing nightmare.
  122.     DWORD           hot_sig;                //... 'HOT$'
  123. #endif
  124.  
  125.     DWORD           hot_NumEntries;
  126.     LPHANDOFFENTRY  hot_Entries;
  127. } HANDOFFTABLE, *LPHANDOFFTABLE;
  128.  
  129. //=============================================================================
  130. //  Parser helper macros.
  131. //=============================================================================
  132.  
  133. INLINE LPVOID GetPropertyInstanceData(LPPROPERTYINST PropertyInst)
  134. {
  135.     if ( PropertyInst->DataLength != (WORD) -1 )
  136.     {
  137.         return PropertyInst->lpData;
  138.     }
  139.  
  140.     return (LPVOID) PropertyInst->lpPropertyInstEx->Byte;
  141. }
  142.  
  143. #define GetPropertyInstanceDataValue(p, type)  ((type *) GetPropertyInstanceData(p))[0]
  144.  
  145. INLINE DWORD GetPropertyInstanceFrameDataLength(LPPROPERTYINST PropertyInst)
  146. {
  147.     if ( PropertyInst->DataLength != (WORD) -1 )
  148.     {
  149.         return PropertyInst->DataLength;
  150.     }
  151.  
  152.     return PropertyInst->lpPropertyInstEx->Length;
  153. }
  154.  
  155. INLINE DWORD GetPropertyInstanceExDataLength(LPPROPERTYINST PropertyInst)
  156. {
  157.     if ( PropertyInst->DataLength == (WORD) -1 )
  158.     {
  159.         PropertyInst->lpPropertyInstEx->Length;
  160.     }
  161.  
  162.     return (WORD) -1;
  163. }
  164.  
  165. //=============================================================================
  166. //  Parser helper functions.
  167. //=============================================================================
  168.  
  169. extern LPLABELED_WORD  WINAPI GetProtocolDescriptionTable(LPDWORD TableSize);
  170.  
  171. extern LPLABELED_WORD  WINAPI GetProtocolDescription(DWORD ProtocolID);
  172.  
  173. extern DWORD        WINAPI GetMacHeaderLength(LPVOID MacHeader, DWORD MacType);
  174.  
  175. extern DWORD        WINAPI GetLLCHeaderLength(LPLLC Frame);
  176.  
  177. extern DWORD        WINAPI GetEtype(LPVOID MacHeader, DWORD MacType);
  178.  
  179. extern DWORD        WINAPI GetSaps(LPVOID MacHeader, DWORD MacType);
  180.  
  181. extern BOOL         WINAPI IsLLCPresent(LPVOID MacHeader, DWORD MacType);
  182.  
  183. extern VOID         WINAPI CanonicalizeHexString(LPSTR hex, LPSTR dest, DWORD len);
  184.  
  185. extern void         WINAPI CanonHex(UCHAR * pDest, UCHAR * pSource, int iLen, BOOL fOx );
  186.  
  187. extern DWORD        WINAPI ByteToBinary(LPSTR string, DWORD ByteValue);
  188.  
  189. extern DWORD        WINAPI WordToBinary(LPSTR string, DWORD WordValue);
  190.  
  191. extern DWORD        WINAPI DwordToBinary(LPSTR string, DWORD DwordValue);
  192.  
  193. extern LPSTR        WINAPI AddressToString(LPSTR string, BYTE *lpAddress);
  194.  
  195. extern LPBYTE       WINAPI StringToAddress(BYTE *lpAddress, LPSTR string);
  196.  
  197. extern LPDWORD      WINAPI VarLenSmallIntToDword( LPBYTE  pValue, 
  198.                                                   WORD    ValueLen, 
  199.                                                   BOOL    fIsByteswapped,
  200.                                                   LPDWORD lpDword );
  201.  
  202. extern LPBYTE       WINAPI LookupByteSetString (LPSET lpSet, BYTE Value);
  203.  
  204. extern LPBYTE       WINAPI LookupWordSetString (LPSET lpSet, WORD Value);
  205.  
  206. extern LPBYTE       WINAPI LookupDwordSetString (LPSET lpSet, DWORD Value);
  207.  
  208. extern DWORD        WINAPIV FormatByteFlags(LPSTR string, DWORD ByteValue, DWORD BitMask);
  209.  
  210. extern DWORD        WINAPIV FormatWordFlags(LPSTR string, DWORD WordValue, DWORD BitMask);
  211.  
  212. extern DWORD        WINAPIV FormatDwordFlags(LPSTR string, DWORD DwordValue, DWORD BitMask);
  213.  
  214. extern LPSTR        WINAPIV FormatTimeAsString(SYSTEMTIME *time, LPSTR string);
  215.  
  216. extern VOID         WINAPIV FormatLabeledByteSetAsFlags(LPPROPERTYINST lpPropertyInst);
  217.  
  218. extern VOID         WINAPIV FormatLabeledWordSetAsFlags(LPPROPERTYINST lpPropertyInst);
  219.  
  220. extern VOID         WINAPIV FormatLabeledDwordSetAsFlags(LPPROPERTYINST lpPropertyInst);
  221.  
  222. extern VOID         WINAPIV FormatPropertyDataAsByte(LPPROPERTYINST lpPropertyInst, DWORD Base);
  223.  
  224. extern VOID         WINAPIV FormatPropertyDataAsWord(LPPROPERTYINST lpPropertyInst, DWORD Base);
  225.  
  226. extern VOID         WINAPIV FormatPropertyDataAsDword(LPPROPERTYINST lpPropertyInst, DWORD Base);
  227.  
  228. extern VOID         WINAPIV FormatLabeledByteSet(LPPROPERTYINST lpPropertyInst);
  229.  
  230. extern VOID         WINAPIV FormatLabeledWordSet(LPPROPERTYINST lpPropertyInst);
  231.  
  232. extern VOID         WINAPIV FormatLabeledDwordSet(LPPROPERTYINST lpPropertyInst);
  233.  
  234. extern VOID         WINAPIV FormatPropertyDataAsInt64(LPPROPERTYINST lpPropertyInst, DWORD Base);
  235.  
  236. extern VOID         WINAPIV FormatPropertyDataAsTime(LPPROPERTYINST lpPropertyInst);
  237.  
  238. extern VOID         WINAPIV FormatPropertyDataAsString(LPPROPERTYINST lpPropertyInst);
  239.  
  240. extern VOID         WINAPIV FormatPropertyDataAsHexString(LPPROPERTYINST lpPropertyInst);
  241.  
  242.  
  243. // Parsers should NOT call LockFrame().  If a parser takes a lock and then gets
  244. // faulted or returns without unlocking, it leaves the system in a state where
  245. // it cannot change protocols or cut/copy frames.  Parsers should use ParserTemporaryLockFrame
  246. // which grants a lock ONLY during the context of the api entry into the parser.  The 
  247. // lock is released on exit from the parser for that frame.
  248. extern LPBYTE       WINAPI ParserTemporaryLockFrame(HFRAME hFrame);
  249.  
  250. extern LPVOID       WINAPI GetCCInstPtr(VOID);
  251. extern VOID         WINAPI SetCCInstPtr(LPVOID lpCurCaptureInst);
  252. extern LPVOID       WINAPI CCHeapAlloc(DWORD dwBytes, BOOL bZeroInit);
  253. extern LPVOID       WINAPI CCHeapReAlloc(LPVOID lpMem, DWORD dwBytes, BOOL bZeroInit);
  254. extern BOOL         WINAPI CCHeapFree(LPVOID lpMem);
  255. extern DWORD        WINAPI CCHeapSize(LPVOID lpMem);
  256.  
  257. extern BOOL BERGetInteger( LPBYTE  pCurrentPointer,
  258.                            LPBYTE *ppValuePointer,
  259.                            LPDWORD pHeaderLength,
  260.                            LPDWORD pDataLength,
  261.                            LPBYTE *ppNext);
  262. extern BOOL BERGetString( LPBYTE  pCurrentPointer,
  263.                           LPBYTE *ppValuePointer,
  264.                           LPDWORD pHeaderLength,
  265.                           LPDWORD pDataLength,
  266.                           LPBYTE *ppNext);
  267. extern BOOL BERGetHeader( LPBYTE  pCurrentPointer,
  268.                           LPBYTE  pTag,
  269.                           LPDWORD pHeaderLength,
  270.                           LPDWORD pDataLength,
  271.                           LPBYTE *ppNext);
  272. #pragma pack()
  273. #endif
  274.