framework.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #pragma once
  2. #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
  3. // Windows Header Files
  4. #include <windows.h>
  5. #pragma once
  6. #include <string>
  7. #include <shlobj.h>
  8. #include <set>
  9. #include "ModuleList.h"
  10. #include <intrin.h>
  11. #pragma intrinsic(_ReturnAddress)
  12. struct shared
  13. {
  14. FARPROC DllCanUnloadNow;
  15. FARPROC DllGetClassObject;
  16. FARPROC DllRegisterServer;
  17. FARPROC DllUnregisterServer;
  18. FARPROC DebugSetMute;
  19. void LoadOriginalLibrary(HMODULE dll)
  20. {
  21. DllCanUnloadNow = GetProcAddress(dll, "DllCanUnloadNow");
  22. DllGetClassObject = GetProcAddress(dll, "DllGetClassObject");
  23. DllRegisterServer = GetProcAddress(dll, "DllRegisterServer");
  24. DllUnregisterServer = GetProcAddress(dll, "DllUnregisterServer");
  25. DebugSetMute = GetProcAddress(dll, "DebugSetMute");
  26. }
  27. } shared;
  28. struct dnsapi_dll
  29. {
  30. HMODULE dll;
  31. // only some functions are implemented.
  32. // PDAFT doesn't use many, so this should hopefully be fine
  33. FARPROC DnsFree;
  34. FARPROC DnsQuery_A;
  35. FARPROC DnsQueryEx;
  36. FARPROC DnsCancelQuery;
  37. FARPROC DnsDhcpRegisterTerm;
  38. FARPROC DnsNotifyResolver;
  39. FARPROC DnsDhcpRegisterHostAddrs;
  40. FARPROC DnsQueryConfigDword;
  41. FARPROC DnsDhcpRemoveRegistrations;
  42. FARPROC DnsDhcpRegisterInit;
  43. FARPROC DnsDhcpRegisterAddrs;
  44. // DnsQueryEx and DnsCancelQuery take pointers to structs as parameters
  45. // (three for DnsQueryEx and one for DnsCancelQuery)
  46. // fortunately they should fit in registers so the stack doesn't matter
  47. // hopefully this works fine... I have no clue what I'm doing
  48. static LONG WINAPI DnsQueryExStub()
  49. {
  50. return 9004; // DNS_ERROR_RCODE_NOT_IMPLEMENTED
  51. }
  52. static LONG WINAPI DnsCancelQueryStub()
  53. {
  54. return 9004; // DNS_ERROR_RCODE_NOT_IMPLEMENTED
  55. }
  56. /*static LONG WINAPI DnsDhcpRegisterTermStub()
  57. {
  58. return 9004; // DNS_ERROR_RCODE_NOT_IMPLEMENTED
  59. }
  60. static LONG WINAPI DnsNotifyResolverStub()
  61. {
  62. return 9004; // DNS_ERROR_RCODE_NOT_IMPLEMENTED
  63. }
  64. static LONG WINAPI DnsDhcpRegisterHostAddrsStub()
  65. {
  66. return 9004; // DNS_ERROR_RCODE_NOT_IMPLEMENTED
  67. }
  68. static LONG WINAPI DnsQueryConfigDwordStub()
  69. {
  70. return 9004; // DNS_ERROR_RCODE_NOT_IMPLEMENTED
  71. }
  72. static LONG WINAPI DnsDhcpRemoveRegistrationsStub()
  73. {
  74. return 9004; // DNS_ERROR_RCODE_NOT_IMPLEMENTED
  75. }
  76. static LONG WINAPI DnsDhcpRegisterInitStub()
  77. {
  78. return 9004; // DNS_ERROR_RCODE_NOT_IMPLEMENTED
  79. }
  80. static LONG WINAPI DnsDhcpRegisterAddrsStub()
  81. {
  82. return 9004; // DNS_ERROR_RCODE_NOT_IMPLEMENTED
  83. }*/
  84. void LoadOriginalLibrary(HMODULE module)
  85. {
  86. dll = module;
  87. shared.LoadOriginalLibrary(dll);
  88. DnsFree = GetProcAddress(dll, "DnsFree");
  89. DnsQuery_A = GetProcAddress(dll, "DnsQuery_A");
  90. DnsQueryEx = GetProcAddress(dll, "DnsQueryEx");
  91. DnsCancelQuery = GetProcAddress(dll, "DnsCancelQuery");
  92. DnsDhcpRegisterTerm = GetProcAddress(dll, "DnsDhcpRegisterTerm");
  93. DnsNotifyResolver = GetProcAddress(dll, "DnsNotifyResolver");
  94. DnsDhcpRegisterHostAddrs = GetProcAddress(dll, "DnsDhcpRegisterHostAddrs");
  95. DnsQueryConfigDword = GetProcAddress(dll, "DnsQueryConfigDword");
  96. DnsDhcpRemoveRegistrations = GetProcAddress(dll, "DnsDhcpRemoveRegistrations");
  97. DnsDhcpRegisterInit = GetProcAddress(dll, "DnsDhcpRegisterInit");
  98. DnsDhcpRegisterAddrs = GetProcAddress(dll, "DnsDhcpRegisterAddrs");
  99. // if entry points aren't found, GetProcAddress should return null
  100. // I hope this is correct
  101. // Thanks to somewhatlurker
  102. if (DnsQueryEx == NULL) { DnsQueryEx = (FARPROC)& DnsQueryExStub; };
  103. if (DnsCancelQuery == NULL) { DnsCancelQuery = (FARPROC)& DnsCancelQueryStub; };
  104. /*if (DnsDhcpRegisterTerm == NULL) { DnsDhcpRegisterTerm = (FARPROC)& DnsDhcpRegisterTermStub; };
  105. if (DnsNotifyResolver == NULL) { DnsNotifyResolver = (FARPROC)& DnsNotifyResolverStub; };
  106. if (DnsDhcpRegisterHostAddrs == NULL) { DnsDhcpRegisterHostAddrs = (FARPROC)& DnsDhcpRegisterHostAddrsStub; };
  107. if (DnsQueryConfigDword == NULL) { DnsQueryConfigDword = (FARPROC)& DnsQueryConfigDwordStub; };
  108. if (DnsDhcpRemoveRegistrations == NULL) { DnsDhcpRemoveRegistrations = (FARPROC)& DnsDhcpRemoveRegistrationsStub; };
  109. if (DnsDhcpRegisterInit == NULL) { DnsDhcpRegisterInit = (FARPROC)& DnsDhcpRegisterInitStub; };
  110. if (DnsDhcpRegisterAddrs == NULL) { DnsDhcpRegisterAddrs = (FARPROC)& DnsDhcpRegisterAddrsStub; };*/
  111. }
  112. } dnsapi;
  113. void _DnsFree() { dnsapi.DnsFree(); }
  114. void _DnsQuery_A() { dnsapi.DnsQuery_A(); }
  115. void _DnsQueryEx() { dnsapi.DnsQueryEx(); }
  116. void _DnsCancelQuery() { dnsapi.DnsCancelQuery(); }
  117. void _DnsDhcpRegisterTerm() { dnsapi.DnsDhcpRegisterTerm(); }
  118. void _DnsNotifyResolver() { dnsapi.DnsNotifyResolver(); }
  119. void _DnsDhcpRegisterHostAddrs() { dnsapi.DnsDhcpRegisterHostAddrs(); }
  120. void _DnsQueryConfigDword() { dnsapi.DnsQueryConfigDword(); }
  121. void _DnsDhcpRemoveRegistrations() { dnsapi.DnsDhcpRemoveRegistrations(); }
  122. void _DnsDhcpRegisterInit() { dnsapi.DnsDhcpRegisterInit(); }
  123. void _DnsDhcpRegisterAddrs() { dnsapi.DnsDhcpRegisterAddrs(); }
  124. #pragma runtime_checks( "", off )
  125. #ifdef _DEBUG
  126. #pragma message ("You are compiling the code in Debug - be warned that wrappers for export functions may not have correct code generated")
  127. #endif
  128. void _DllRegisterServer() { shared.DllRegisterServer(); }
  129. void _DllUnregisterServer() { shared.DllUnregisterServer(); }
  130. void _DllCanUnloadNow() { shared.DllCanUnloadNow(); }
  131. void _DllGetClassObject() { shared.DllGetClassObject(); }
  132. #pragma runtime_checks( "", restore )