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.

143 lines
3.6 KiB

  1. .586p
  2. .xlist
  3. include ks386.inc
  4. include callconv.inc ; calling convention macros
  5. .list
  6. EXTRNP StatTimerHook,1,,FASTCALL
  7. EXTRNP TimerHook,1,,FASTCALL
  8. extrn _KeUpdateSystemTimeThunk:DWORD
  9. extrn _KeUpdateRunTimeThunk:DWORD
  10. extrn _StatProcessorAccumulators:DWORD
  11. _TEXT$00 SEGMENT DWORD USE32 PUBLIC 'CODE'
  12. ASSUME CS:NOTHING, DS:FLAT, ES:FLAT, SS:NOTHING, FS:NOTHING, GS:NOTHING
  13. cPublicProc _CurrentPcr, 0
  14. mov eax, fs:[PcSelfPcr]
  15. stdRet _CurrentPcr
  16. stdENDP _CurrentPcr
  17. cPublicProc _StatSystemTimeHook, 0
  18. mov ecx, fs:[PcPrcb]
  19. push eax
  20. movzx ecx, byte ptr [ecx].PbNumber
  21. fstCall StatTimerHook
  22. pop eax
  23. jmp dword ptr [_KeUpdateSystemTimeThunk]
  24. stdENDP _StatSystemTimeHook
  25. cPublicProc _StatRunTimeHook, 0
  26. mov ecx, fs:[PcPrcb]
  27. movzx ecx, byte ptr [ecx].PbNumber
  28. fstCall StatTimerHook
  29. jmp dword ptr [_KeUpdateRunTimeThunk]
  30. stdENDP _StatRunTimeHook
  31. cPublicProc _SystemTimeHook, 0
  32. mov ecx, fs:[PcPrcb]
  33. push eax
  34. movzx ecx, byte ptr [ecx].PbNumber
  35. fstCall TimerHook
  36. pop eax
  37. jmp dword ptr [_KeUpdateSystemTimeThunk]
  38. stdENDP _SystemTimeHook
  39. cPublicProc _RunTimeHook, 0
  40. mov ecx, fs:[PcPrcb]
  41. movzx ecx, byte ptr [ecx].PbNumber
  42. fstCall TimerHook
  43. jmp dword ptr [_KeUpdateRunTimeThunk]
  44. stdENDP _RunTimeHook
  45. cPublicProc _WRMSR,3
  46. mov ecx, [esp+4]
  47. mov eax, [esp+8]
  48. mov edx, [esp+12]
  49. ; ecx = MSR
  50. ; edx:eax = value
  51. db 0fh, 30h
  52. stdRet _WRMSR
  53. stdENDP _WRMSR
  54. cPublicFastCall RDMSR,1
  55. db 0fh, 32h
  56. fstRet RDMSR
  57. fstENDP RDMSR
  58. HookTemplate proc
  59. push eax
  60. mov eax, fs:[PcPrcb]
  61. movzx eax, byte ptr [eax].PbNumber
  62. mov eax, _StatProcessorAccumulators [eax*4]
  63. db 0ffh, 80h ; inc dword ptr [eax + tt1]
  64. tt1: dd 0
  65. pop eax
  66. db 0e9h ; jmp near tt2
  67. tt2: dd ?
  68. HookTemplateEnd: dd 0
  69. HookTemplate endp
  70. cPublicProc _CreateHook, 4
  71. ;
  72. ; (ebp+8) = HookCode
  73. ; (ebp+12) = HookAddress
  74. ; (ebp+16) = HitCounters
  75. ; (ebp+20) = Type of hook
  76. ;
  77. push ebp
  78. mov ebp, esp
  79. push edi
  80. push esi
  81. push ebx
  82. mov edi, [ebp+8] ; spot to create hook code into
  83. mov esi, offset HookTemplate
  84. mov ecx, HookTemplateEnd - HookTemplate
  85. rep movsb ; copy template
  86. mov edi, [ebp+8] ; new hook
  87. mov eax, [ebp+16] ; hit counter offset
  88. mov ebx, tt1 - HookTemplate
  89. mov [edi+ebx], eax
  90. mov eax, [ebp+12] ; image's thunk
  91. mov eax, [eax] ; original thunk's value
  92. mov ebx, tt2 - HookTemplate
  93. sub eax, edi ; adjust address to be relative to eip
  94. sub eax, ebx
  95. sub eax, 4
  96. mov [edi+ebx], eax
  97. mov eax, [ebp+12] ; image's thunk
  98. mov [eax], edi ; patch it to be our hook
  99. pop ebx
  100. pop esi
  101. pop edi
  102. pop ebp
  103. stdRET _CreateHook
  104. stdENDP _CreateHook
  105. cPublicProc _GetCR4, 0
  106. mov eax, cr4
  107. stdRet _GetCR4
  108. stdENDP _GetCR4
  109. cPublicProc _SetCR4, 1
  110. mov eax, [esp+4]
  111. mov cr4, eax
  112. stdRet _SetCR4
  113. stdENDP _SetCR4
  114. _TEXT$00 ends
  115. end