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.

179 lines
5.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1996 - 2000
  6. //
  7. // File: timebomb.c
  8. //
  9. //--------------------------------------------------------------------------
  10. //
  11. // -- Add these lines after the #include's in the file that handles DriverEntry:
  12. //
  13. // #ifdef TIME_BOMB
  14. // #include "..\..\timebomb\timebomb.c"
  15. // #endif
  16. //
  17. // -- Add the following lines to the beginning of DriverEntry:
  18. //
  19. // #ifdef TIME_BOMB
  20. // if (HasEvaluationTimeExpired()) {
  21. // return STATUS_EVALUATION_EXPIRATION;
  22. // }
  23. // #endif
  24. //
  25. // -- If you want to override the default expiration value of 31 days after
  26. // compile, define the constant DAYS_UNTIL_EXPIRATION before you include
  27. // timebomb.c
  28. //
  29. // -- Add -DTIME_BOMB to the $(C_DEFINES) line in the sources file. If you haven't
  30. // already done so, you may also want to add -DDEBUG_LEVEL=DEBUGLVL_TERSE.
  31. //
  32. // -- "Cleanly" recompile your binary with 'build -cZ'
  33. //
  34. // -- NOTE: This uses the __DATE__ preprocessor directive which inserts a _very_
  35. // clear-text string into the binary which is easily modifiable with a
  36. // hex editor. Suggestions on making this more secure are welcome.
  37. //
  38. #if !defined(_KSDEBUG_)
  39. #include <ksdebug.h>
  40. #endif
  41. #ifndef DAYS_UNTIL_EXPIRATION
  42. #define DAYS_UNTIL_EXPIRATION 31
  43. #endif
  44. typedef enum {
  45. Jan=1,
  46. Feb,
  47. Mar,
  48. Apr,
  49. May,
  50. Jun,
  51. Jul,
  52. Aug,
  53. Sep,
  54. Oct,
  55. Nov,
  56. Dec
  57. } MONTH;
  58. MONTH GetMonthFromDateString
  59. (
  60. char *_BuildDate_
  61. )
  62. {
  63. MONTH BuildMonth = (MONTH)0;
  64. ASSERT(_BuildDate_);
  65. switch (_BuildDate_[0]) {
  66. case 'A':
  67. if (_BuildDate_[1] == 'u') {
  68. BuildMonth = Aug;
  69. }
  70. else {
  71. BuildMonth = Apr;
  72. }
  73. break;
  74. case 'D':
  75. BuildMonth = Dec;
  76. break;
  77. case 'F':
  78. BuildMonth = Feb;
  79. break;
  80. case 'J':
  81. if (_BuildDate_[1] == 'u') {
  82. if (_BuildDate_[2] == 'l') {
  83. BuildMonth = Jul;
  84. } else {
  85. BuildMonth = Jun;
  86. }
  87. } else {
  88. BuildMonth = Jan;
  89. }
  90. break;
  91. case 'M':
  92. if (_BuildDate_[2] == 'r') {
  93. BuildMonth = Mar;
  94. }
  95. else {
  96. BuildMonth = May;
  97. }
  98. break;
  99. case 'N':
  100. BuildMonth = Nov;
  101. break;
  102. case 'O':
  103. BuildMonth = Oct;
  104. break;
  105. case 'S':
  106. BuildMonth = Sep;
  107. break;
  108. default:
  109. ASSERT(0);
  110. break;
  111. }
  112. return BuildMonth;
  113. }
  114. BOOL HasEvaluationTimeExpired()
  115. {
  116. // Get the time that this file was compiled
  117. char _BuildDate_[] = __DATE__;
  118. CSHORT BuildYear,
  119. BuildMonth,
  120. BuildDay,
  121. ThousandsDigit,
  122. HundredsDigit,
  123. TensDigit,
  124. Digit;
  125. ULONG BuildDays,
  126. CurrentDays;
  127. LARGE_INTEGER CurrentSystemTime;
  128. TIME_FIELDS CurrentSystemTimeFields;
  129. // Convert _BuildDate_ into something a little more palatable
  130. _DbgPrintF( DEBUGLVL_TERSE, ("Driver Build Date: %s",_BuildDate_) );
  131. BuildMonth = GetMonthFromDateString(_BuildDate_);
  132. // Compensate for a ' ' in the tens digit
  133. if ( (_BuildDate_[4] >= '0') && (_BuildDate_[4] <= '9') ) {
  134. TensDigit = _BuildDate_[4] - '0';
  135. } else {
  136. TensDigit = 0;
  137. }
  138. Digit = _BuildDate_[5] - '0';
  139. BuildDay = (TensDigit * 10) + Digit;
  140. ThousandsDigit = _BuildDate_[7] - '0';
  141. HundredsDigit = _BuildDate_[8] - '0';
  142. TensDigit = _BuildDate_[9] - '0';
  143. Digit = _BuildDate_[10] - '0';
  144. BuildYear = (ThousandsDigit * 1000) + (HundredsDigit * 100) + (TensDigit * 10) + Digit;
  145. // Get the current system time and convert to local time
  146. KeQuerySystemTime( &CurrentSystemTime ); // returns GMT
  147. RtlTimeToTimeFields( &CurrentSystemTime, &CurrentSystemTimeFields );
  148. // For now, only let this binary float for 31 days
  149. BuildDays = (BuildYear * 365) +
  150. (BuildMonth * 31) +
  151. BuildDay;
  152. CurrentDays = (CurrentSystemTimeFields.Year * 365) +
  153. (CurrentSystemTimeFields.Month * 31) +
  154. CurrentSystemTimeFields.Day;
  155. _DbgPrintF( DEBUGLVL_VERBOSE, ("CurrentDays: %d BuildDays: %d",CurrentDays, BuildDays) );
  156. if (CurrentDays > BuildDays + DAYS_UNTIL_EXPIRATION) {
  157. _DbgPrintF( DEBUGLVL_TERSE, ("Evaluation period expired!") );
  158. return TRUE;
  159. }
  160. else {
  161. _DbgPrintF( DEBUGLVL_TERSE, ("Evaluation days left: %d", (BuildDays + 31) - CurrentDays) );
  162. return FALSE;
  163. }
  164. }