winapi.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #include "precompile.h"
  2. #include <assert.h>
  3. #include "internal.h"
  4. /* Ntdll function pointers */
  5. sRtlGetVersion pRtlGetVersion;
  6. sRtlNtStatusToDosError pRtlNtStatusToDosError;
  7. sNtDeviceIoControlFile pNtDeviceIoControlFile;
  8. sNtQueryInformationFile pNtQueryInformationFile;
  9. sNtSetInformationFile pNtSetInformationFile;
  10. sNtQueryVolumeInformationFile pNtQueryVolumeInformationFile;
  11. sNtQueryDirectoryFile pNtQueryDirectoryFile;
  12. sNtQuerySystemInformation pNtQuerySystemInformation;
  13. sNtQueryInformationProcess pNtQueryInformationProcess;
  14. /* Advapi32 function pointers */
  15. sRtlGenRandom pRtlGenRandom;
  16. /* Kernel32 function pointers */
  17. sGetQueuedCompletionStatusEx pGetQueuedCompletionStatusEx;
  18. /* Powrprof.dll function pointer */
  19. sPowerRegisterSuspendResumeNotification pPowerRegisterSuspendResumeNotification;
  20. /* User32.dll function pointer */
  21. sSetWinEventHook pSetWinEventHook;
  22. void toolkit_winapi_init(void)
  23. {
  24. HMODULE ntdll_module;
  25. HMODULE powrprof_module;
  26. HMODULE user32_module;
  27. HMODULE kernel32_module;
  28. HMODULE advapi32_module;
  29. ntdll_module = GetModuleHandleA("ntdll.dll");
  30. if (ntdll_module == NULL) {
  31. toolkit_fatal_error(GetLastError(), "GetModuleHandleA");
  32. }
  33. pRtlGetVersion = (sRtlGetVersion) GetProcAddress(ntdll_module,
  34. "RtlGetVersion");
  35. pRtlNtStatusToDosError = (sRtlNtStatusToDosError) GetProcAddress(
  36. ntdll_module,
  37. "RtlNtStatusToDosError");
  38. if (pRtlNtStatusToDosError == NULL) {
  39. toolkit_fatal_error(GetLastError(), "GetProcAddress");
  40. }
  41. pNtDeviceIoControlFile = (sNtDeviceIoControlFile) GetProcAddress(
  42. ntdll_module,
  43. "NtDeviceIoControlFile");
  44. if (pNtDeviceIoControlFile == NULL) {
  45. toolkit_fatal_error(GetLastError(), "GetProcAddress");
  46. }
  47. pNtQueryInformationFile = (sNtQueryInformationFile) GetProcAddress(
  48. ntdll_module,
  49. "NtQueryInformationFile");
  50. if (pNtQueryInformationFile == NULL) {
  51. toolkit_fatal_error(GetLastError(), "GetProcAddress");
  52. }
  53. pNtSetInformationFile = (sNtSetInformationFile) GetProcAddress(
  54. ntdll_module,
  55. "NtSetInformationFile");
  56. if (pNtSetInformationFile == NULL) {
  57. toolkit_fatal_error(GetLastError(), "GetProcAddress");
  58. }
  59. pNtQueryVolumeInformationFile = (sNtQueryVolumeInformationFile)
  60. GetProcAddress(ntdll_module, "NtQueryVolumeInformationFile");
  61. if (pNtQueryVolumeInformationFile == NULL) {
  62. toolkit_fatal_error(GetLastError(), "GetProcAddress");
  63. }
  64. pNtQueryDirectoryFile = (sNtQueryDirectoryFile)
  65. GetProcAddress(ntdll_module, "NtQueryDirectoryFile");
  66. if (pNtQueryVolumeInformationFile == NULL) {
  67. toolkit_fatal_error(GetLastError(), "GetProcAddress");
  68. }
  69. pNtQuerySystemInformation = (sNtQuerySystemInformation) GetProcAddress(
  70. ntdll_module,
  71. "NtQuerySystemInformation");
  72. if (pNtQuerySystemInformation == NULL) {
  73. toolkit_fatal_error(GetLastError(), "GetProcAddress");
  74. }
  75. pNtQueryInformationProcess = (sNtQueryInformationProcess) GetProcAddress(
  76. ntdll_module,
  77. "NtQueryInformationProcess");
  78. if (pNtQueryInformationProcess == NULL) {
  79. toolkit_fatal_error(GetLastError(), "GetProcAddress");
  80. }
  81. kernel32_module = GetModuleHandleA("kernel32.dll");
  82. if (kernel32_module == NULL) {
  83. toolkit_fatal_error(GetLastError(), "GetModuleHandleA");
  84. }
  85. pGetQueuedCompletionStatusEx = (sGetQueuedCompletionStatusEx) GetProcAddress(
  86. kernel32_module,
  87. "GetQueuedCompletionStatusEx");
  88. powrprof_module = LoadLibraryA("powrprof.dll");
  89. if (powrprof_module != NULL) {
  90. pPowerRegisterSuspendResumeNotification = (sPowerRegisterSuspendResumeNotification)
  91. GetProcAddress(powrprof_module, "PowerRegisterSuspendResumeNotification");
  92. }
  93. user32_module = LoadLibraryA("user32.dll");
  94. if (user32_module != NULL) {
  95. pSetWinEventHook = (sSetWinEventHook)
  96. GetProcAddress(user32_module, "SetWinEventHook");
  97. }
  98. advapi32_module = GetModuleHandleA("advapi32.dll");
  99. if (advapi32_module == NULL) {
  100. toolkit_fatal_error(GetLastError(), "GetModuleHandleA");
  101. }
  102. pRtlGenRandom =
  103. (sRtlGenRandom) GetProcAddress(advapi32_module, "SystemFunction036");
  104. }