Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

257 lines
9.5 KiB

  1. // --------------------------------------------------------------------------------
  2. // Binxhex.h
  3. // Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  4. // Steven J. Bailey
  5. // --------------------------------------------------------------------------------
  6. #ifndef __BINHEX_H
  7. #define __BINHEX_H
  8. // ---------------------------------------------------------------------------------------
  9. // MACBINARY Header
  10. // ---------------------------------------------------------------------------------------
  11. // Byte packing
  12. #pragma pack(1)
  13. typedef struct
  14. {
  15. BYTE bMustBeZero1;
  16. BYTE cchFileName;
  17. char rgchFileName[63];
  18. DWORD dwType;
  19. DWORD dwCreator;
  20. BYTE bFinderFlags;
  21. BYTE bMustBeZero2;
  22. WORD xIcon;
  23. WORD yIcon;
  24. WORD wFileID;
  25. BYTE fProtected;
  26. BYTE bMustBeZero3;
  27. DWORD lcbDataFork;
  28. DWORD lcbResourceFork;
  29. DWORD dwCreationDate;
  30. DWORD dwModificationDate;
  31. union
  32. {
  33. struct
  34. {
  35. WORD cbGetInfo;
  36. BYTE bFinderFlags2;
  37. BYTE wGap[14];
  38. DWORD lcbUnpacked;
  39. WORD cbSecondHeader;
  40. BYTE bVerMacBin2;
  41. BYTE bMinVerMacBin2;
  42. WORD wCRC;
  43. };
  44. struct
  45. {
  46. WORD wDummy;
  47. BYTE bByte101ToByte125[25];
  48. };
  49. BYTE Reserved[27];
  50. };
  51. WORD wMachineID;
  52. } MACBINARY, *LPMACBINARY;
  53. #pragma pack()
  54. // --------------------------------------------------------------------------------
  55. // Globals
  56. // --------------------------------------------------------------------------------
  57. // Non Mac Creator Types
  58. typedef struct _screatortype
  59. {
  60. char szCreator[5];
  61. char szType[5];
  62. } sCreatorType;
  63. extern sCreatorType * g_lpCreatorTypes;
  64. // --------------------------------------------------------------------------------
  65. // MAPI Types
  66. // --------------------------------------------------------------------------------
  67. typedef ULONG CB; // Count of bytes
  68. typedef ULONG C; // Count
  69. typedef LPBYTE PB; // pointer to bytes
  70. // --------------------------------------------------------------------------------
  71. // Defines
  72. // --------------------------------------------------------------------------------
  73. #define BINHEX_INVALID 0x7f
  74. #define BINHEX_REPEAT 0x90
  75. #define XXXX BINHEX_INVALID
  76. #define MIN(a,b) ( (a) > (b) ? (b) : (a) )
  77. #define hrSuccess S_OK
  78. // Uncomment for Binhex debugging support
  79. // #define BINHEX_TRACE 1
  80. #if defined(_X86_) || defined(_AMD64_) || defined(_IA64_)
  81. // host is little endian
  82. #define NATIVE_LONG_FROM_BIG(lpuch) ( (*(unsigned char *) (lpuch)) << 24 \
  83. | (*(unsigned char *)((lpuch) + 1)) << 16 \
  84. | (*(unsigned char *)((lpuch) + 2)) << 8 \
  85. | (*(unsigned char *)((lpuch) + 3)))
  86. #elif defined(_MPPC_)
  87. #define NATIVE_LONG_FROM_BIG(lpuch) (*(unsigned long *) (lpuch))
  88. #else
  89. #error "Must define NATIVE_LONG_FROM_BIG for this architecture!"
  90. #endif
  91. // --------------------------------------------------------------------------------
  92. // Constants
  93. // --------------------------------------------------------------------------------
  94. const CB cbLineLengthUnlimited = 0;
  95. const CB cbMIN_BINHEX_HEADER_SIZE = 21;
  96. const WORD wZero = 0;
  97. // --------------------------------------------------------------------------------
  98. // g_rgchBinHex8to6
  99. // --------------------------------------------------------------------------------
  100. const CHAR g_rgchBinHex8to6[] =
  101. "!\"#$%&'()*+,-012345689@ABCDEFGHIJKLMNPQRSTUVXYZ[`abcdefhijklmpqr";
  102. // --------------------------------------------------------------------------------
  103. // g_rgchBinHex6to8
  104. // --------------------------------------------------------------------------------
  105. const CHAR g_rgchBinHex6to8[] =
  106. {
  107. // 0x00
  108. XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX,
  109. XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX,
  110. XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX,
  111. XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX,
  112. // 0x20
  113. XXXX, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
  114. 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, XXXX, XXXX,
  115. // 0x30
  116. 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, XXXX,
  117. 0x14, 0x15, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX,
  118. // 0x40
  119. 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D,
  120. 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, XXXX,
  121. // 0x50
  122. 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, XXXX,
  123. 0x2C, 0x2D, 0x2E, 0x2F, XXXX, XXXX, XXXX, XXXX,
  124. // 0x60
  125. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, XXXX,
  126. 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, XXXX, XXXX,
  127. // 0x70
  128. 0x3D, 0x3E, 0x3F, XXXX, XXXX, XXXX, XXXX, XXXX,
  129. XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX,
  130. // 0x80
  131. XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX,
  132. XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX,
  133. XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX,
  134. XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX,
  135. XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX,
  136. XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX,
  137. XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX,
  138. XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX,
  139. XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX,
  140. XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX,
  141. XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX,
  142. XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX,
  143. XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX,
  144. XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX,
  145. XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX,
  146. XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX, XXXX,
  147. };
  148. // --------------------------------------------------------------------------------
  149. // BINHEX post processing data
  150. // --------------------------------------------------------------------------------
  151. typedef struct _sbinhexreturndata
  152. {
  153. MACBINARY macbinHdr;
  154. BOOL fIsMacFile;
  155. } BINHEXRETDATA;
  156. //-----------------------------------------------------------------------------
  157. // Apple Macintosh BinHex 4.0 encoder class.
  158. //-----------------------------------------------------------------------------
  159. class CBinhexEncoder
  160. {
  161. public:
  162. CBinhexEncoder(void);
  163. ~CBinhexEncoder(void);
  164. HRESULT HrConfig(IN CB cbLineLength, IN C cMaxLines, IN void * pvParms);
  165. HRESULT HrEmit(IN PB pbRead, IN OUT CB * pcbRead, OUT PB pbWrite, IN OUT CB * pcbWrite);
  166. private:
  167. // Binhex's the supplied buffer into m_pbWrite, modified m_cbProduced
  168. HRESULT HrBinHexBuffer( LPBYTE lpbIn, CB cbIn, CB * lpcbConsumed );
  169. // Binhex byte and outputs to m_pbWrite
  170. HRESULT HrBinHexByte( BYTE b );
  171. // Did we generate the maximum number of output lines?
  172. virtual BOOL FMaxLinesReached(void)
  173. { return (m_cMaxLines > 0 && m_cLines >= m_cMaxLines); }
  174. // Are we operating under restricted line length?
  175. virtual BOOL FLineLengthLimited(void)
  176. { return m_cbLineLength != cbLineLengthUnlimited; }
  177. LPMACBINARY m_lpmacbinHdr; // pointer to passed in Mac Binary header
  178. ULONG m_ulAccum; // acculator to store chars when converting from 6bytes to 8 bytes.
  179. ULONG m_cAccum; // count of characters accumulated (0 - 3)
  180. BYTE m_bRepeat; // repeat char
  181. CB m_cbRepeat; // amount to repeat
  182. BYTE m_bPrev; // Previous byte processed
  183. BYTE m_bCurr; // current byte being processed;
  184. WORD m_wCRC; // CRC used for data or Resource forks
  185. CB m_cbLine; // Number of chars currently encoded for a line of output
  186. CB m_cbFork; // Size of fork to process
  187. CB m_cbLeftInFork; // How much of current fork we've processed.
  188. CB m_cbProduced; // number of chars produces after decoding and RLE expansion
  189. CB m_cbLeftInOutputBuffer; // number of bytes left in passed in Output buffer
  190. CB m_cbConsumed; // number of bytes used from passed in input buffer
  191. CB m_cbLeftInInputBuffer; // number of bytes in passed in Input buffer
  192. CB m_cbWrite; // number of bytes written out to output buffer
  193. LPBYTE m_pbWrite; // pointer to output buffer.
  194. BOOL m_fHandledx90; // flag to preserve literal x90 processing across buffer resets.
  195. CB m_cbPad; // byte count of padding across buffer refreshes.
  196. CB m_cbLineLength; // Maximum length of output line
  197. BOOL m_fConfigured; // Has HrConfig been called successfully?
  198. CB m_cbLeftOnLastLine; // Number of bytes left on last line of output
  199. C m_cMaxLines; // Maximum number of output lines requested
  200. C m_cLines; // Lines of output generated
  201. // Encoding states
  202. enum _BinHexStateEnc
  203. {
  204. sHEADER, sDATA, sRESOURCE, sEND
  205. } m_eBinHexStateEnc;
  206. #if defined (DEBUG) && defined (BINHEX_TRACE)
  207. LPSTREAM m_lpstreamEncodeRLE; // trace of Run Length encoding of the raw source data
  208. LPSTREAM m_lpstreamEncodeRAW; // trace of raw data before RLE has been applied
  209. #endif
  210. };
  211. #endif // __BINHEX_H