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.

103 lines
2.8 KiB

  1. #include <minidrv.h>
  2. #include <stdio.h>
  3. #include <process.h>
  4. #include <stdarg.h>
  5. #include "debug2.h"
  6. #include "strsafe.h" // Security-Code 2002.3.6
  7. //
  8. // Functions for outputting debug messages
  9. //
  10. #ifdef DEBUG2_FILE
  11. #if (DBG)
  12. VOID DbgFPrint(LPCSTR pstrFormat, ...)
  13. {
  14. FILE *stream;
  15. va_list ap;
  16. char wbuff[512];
  17. va_start(ap, pstrFormat);
  18. if ((stream = fopen( DEBU2_FNAME, "a" )) == NULL) {
  19. return;
  20. }
  21. vfprintf(stream, pstrFormat, ap);
  22. fclose(stream);
  23. va_end(ap);
  24. }
  25. #ifdef DEBUG2_DUMP_USE
  26. VOID DbgFDump(LPBYTE src, UINT src_size)
  27. {
  28. FILE *stream;
  29. LPBYTE cur_ptr;
  30. UINT cnt01;
  31. UINT cnt02;
  32. UINT line_max;
  33. UINT line_rem;
  34. BYTE d_dump_buff[256];
  35. if ((stream = fopen( DEBU2_FNAME, "a" )) == NULL) {
  36. return;
  37. }
  38. cur_ptr = src;
  39. line_max = src_size / 16;
  40. line_rem = src_size % 16;
  41. for (cnt01=0; cnt01 < line_max; cnt01++) {
  42. memset(d_dump_buff, 0x00, sizeof(d_dump_buff));
  43. for (cnt02=0; cnt02 < 16; cnt02++) {
  44. // Replacement of strsafe-api 2002.3.6 >>>
  45. // sprintf(d_dump_buff+(3*cnt02), " %02X", *(cur_ptr + cnt02));
  46. if (S_OK != StringCbPrintfExA(d_dump_buff+(3*cnt02), sizeof(d_dump_buff)-(3*cnt02),
  47. &pDestEnd, &szRemLen,
  48. STRSAFE_IGNORE_NULLS | STRSAFE_NULL_ON_FAILURE,
  49. " %02X", *(cur_ptr + cnt02))) {
  50. fclose(stream);
  51. return;
  52. }
  53. // Replacement of strsafe-api 2002.3.6 >>>
  54. + }
  55. fprintf(stream, d_dump_buff);
  56. fprintf(stream, "\n");
  57. cur_ptr += 16;
  58. }
  59. if (line_rem > 0) {
  60. memset(d_dump_buff, 0x00, sizeof(d_dump_buff));
  61. for (cnt02=0; cnt02 < 16 && cnt02 < line_rem; cnt02++) {
  62. // Replacement of strsafe-api 2002.3.6 >>>
  63. // sprintf(d_dump_buff+(3*cnt02), " %02X ", *(cur_ptr + cnt02));
  64. if (S_OK != StringCbPrintfExA(d_dump_buff+(3*cnt02), sizeof(d_dump_buff)-(3*cnt02),
  65. &pDestEnd, &szRemLen,
  66. STRSAFE_IGNORE_NULLS | STRSAFE_NULL_ON_FAILURE,
  67. " %02X", *(cur_ptr + cnt02))) {
  68. fclose(stream);
  69. return;
  70. }
  71. // Replacement of strsafe-api 2002.3.6 <<<
  72. }
  73. fprintf(stream, d_dump_buff);
  74. fprintf(stream, "\n");
  75. }
  76. fclose(stream);
  77. }
  78. #else // DEBUG2_DUMP_USE
  79. VOID DbgFDump(LPBYTE src, UINT src_size)
  80. {
  81. ;
  82. }
  83. #endif // DEBUG2_DUMP_USE
  84. #else // DBG
  85. VOID DbgFPrint(LPCSTR pstrFormat, ...)
  86. {
  87. ;
  88. }
  89. VOID DbgFDump(LPBYTE src, UINT src_size)
  90. {
  91. ;
  92. }
  93. #endif // DBG
  94. #endif // DEBUG2_FILE