Source code of Windows XP (NT5)
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.

176 lines
4.3 KiB

  1. /*** binfmt.h - Format services definitions
  2. *
  3. * Copyright (c) 1995,1996 Microsoft Corporation
  4. * Author: Michael Tsang (MikeTs)
  5. * Created 11/06/95
  6. *
  7. * MODIFICATION HISTORY
  8. */
  9. #ifndef _BITFMT_H
  10. #define _BITFMT_H
  11. #ifndef ENTER
  12. #define ENTER(n,p)
  13. #endif
  14. #ifndef EXIT
  15. #define EXIT(n,p)
  16. #endif
  17. #ifndef TRACENAME
  18. #define TRACENAME(s)
  19. #endif
  20. #include <ctype.h>
  21. #ifdef USE_CRUNTIME
  22. #include <stdio.h>
  23. #include <string.h>
  24. #define PRINTF printf
  25. #define FPRINTF fprintf
  26. #define SPRINTF sprintf
  27. #define STRCPY strcpy
  28. #define STRCPYN strncpy
  29. #define STRCAT strcat
  30. #define STRLEN strlen
  31. #else
  32. #ifdef WINAPP
  33. #define SPRINTF wsprintf
  34. #define STRCPY lstrcpy
  35. #define STRCPYN lstrcpyn
  36. #define STRCAT lstrcat
  37. #define STRLEN lstrlen
  38. #else //assume VxD
  39. #define SPRINTF _Sprintf
  40. #define STRCPY(s1,s2) _lstrcpyn(s1,s2,(DWORD)(-1))
  41. #define STRCPYN(s1,s2,n) _lstrcpyn(s1,s2,(n)+1)
  42. #define STRCAT(s1,s2) _lstrcpyn((s1)+_lstrlen(s1),s2,(DWORD)(-1))
  43. #define STRLEN _lstrlen
  44. #endif
  45. #endif
  46. //
  47. // Error Codes
  48. //
  49. #define FERR_NONE 0
  50. #define FERR_INVALID_FORMAT -1
  51. #define FERR_INVALID_UNITSIZE -2
  52. //
  53. // String Constants
  54. //
  55. #define SZ_SEP_SPACE " "
  56. #define SZ_SEP_TAB "\t"
  57. #define SZ_SEP_COMMA ","
  58. #define SZ_SEP_SEMICOLON ";"
  59. #define SZ_SEP_COLON ":"
  60. #define SZ_FMT_DEC "%d"
  61. #define SZ_FMT_HEX "%x"
  62. #define SZ_FMT_HEX_BYTE "%02x"
  63. #define SZ_FMT_HEX_WORD "%04x"
  64. #define SZ_FMT_HEX_DWORD "%08lx"
  65. #define SZ_FMT_WORDOFFSET SZ_FMT_HEX_WORD SZ_SEP_COLON
  66. #define SZ_FMT_DWORDOFFSET SZ_FMT_HEX_DWORD SZ_SEP_COLON
  67. //
  68. // bFmtType Values
  69. //
  70. #define FMT_NUMBER 0
  71. #define FMT_ENUM 1
  72. #define FMT_BITS 2
  73. #define FMT_STRING 3
  74. //
  75. // bUnitSize Values
  76. //
  77. #define UNIT_BYTE sizeof(BYTE)
  78. #define UNIT_WORD sizeof(WORD)
  79. #define UNIT_DWORD sizeof(DWORD)
  80. //
  81. // dwfFormat Flags
  82. //
  83. #define FMTF_NO_EOL 0x80000000
  84. #define FMTF_NO_INC_OFFSET 0x40000000
  85. #define FMTF_NO_SEP 0x20000000
  86. #define FMTF_NO_PRINT_DATA 0x10000000
  87. #define FMTF_PRINT_OFFSET 0x08000000
  88. #define FMTF_NO_RAW_DATA 0x04000000
  89. #define FMTF_STR_ASCIIZ 0x00000001
  90. #define FMTF_FIRST_FIELD (FMTF_NO_EOL | FMTF_NO_INC_OFFSET | \
  91. FMTF_NO_PRINT_DATA)
  92. #define FMTF_MIDDLE_FIELD (FMTF_NO_EOL | FMTF_NO_INC_OFFSET | \
  93. FMTF_NO_PRINT_DATA)
  94. #define FMTF_LAST_FIELD FMTF_NO_PRINT_DATA
  95. //
  96. // Structure and Type Definitions
  97. //
  98. typedef VOID (*LPFN)(FILE *, BYTE *, DWORD);
  99. typedef struct fmthdr_s
  100. {
  101. BYTE bFmtType; //Format type: see FMT_*
  102. BYTE bUnitSize; //Data unit size: see UNIT_*
  103. BYTE bUnitCnt; //Data unit count for a format record
  104. DWORD dwfFormat; //Format flags: see FMTF_*
  105. int iRepeatCnt; //Repeat count for this format record
  106. char *pszOffsetFmt; //Offset format
  107. char *pszFieldSep; //Field separator between bUnitCnt of data
  108. char *pszLabel; //LHS label
  109. } FMTHDR, *PFMTHDR;
  110. typedef struct fmt_s
  111. {
  112. char *pszLabel;
  113. PFMTHDR pfmtType;
  114. LPFN lpfn;
  115. } FMT, *PFMT;
  116. typedef struct fmtnum_s
  117. {
  118. FMTHDR hdr;
  119. DWORD dwMask;
  120. BYTE bShiftCnt;
  121. char *pszNumFmt;
  122. } FMTNUM, *PFMTNUM;
  123. typedef struct fmtenum_s
  124. {
  125. FMTHDR hdr;
  126. DWORD dwMask;
  127. BYTE bShiftCnt;
  128. DWORD dwStartEnum;
  129. DWORD dwEndEnum;
  130. char **ppszEnumNames;
  131. char *pszOutOfRange;
  132. } FMTENUM, *PFMTENUM;
  133. typedef struct fmtbits_s
  134. {
  135. FMTHDR hdr;
  136. DWORD dwMask;
  137. char **ppszOnNames;
  138. char **ppszOffNames;
  139. } FMTBITS, *PFMTBITS;
  140. typedef struct fmtstr_s
  141. {
  142. FMTHDR hdr;
  143. } FMTSTR, *PFMTSTR;
  144. typedef struct fmtchar_s
  145. {
  146. FMTHDR hdr;
  147. } FMTCHAR, *PFMTCHAR;
  148. //
  149. // API Prototypes
  150. //
  151. #ifdef FPRINTF
  152. int BinFPrintf(FILE *pfile, char *pszBuffer, PFMT pfmt, BYTE *pb,
  153. DWORD *pdwOffset, char *pszOffsetFormat);
  154. #endif
  155. int BinSprintf(char *pszBuffer, PFMTHDR pfmt, BYTE *pb, DWORD *pdwOffset);
  156. #endif //ifndef _BINFMT_H