Source code of Windows XP (NT5)
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.

234 lines
5.8 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993-1998
  5. //
  6. // File: ldrapeng.h
  7. //
  8. // Contents: App compat backend code
  9. //
  10. // History: 13-Oct-99 v-johnwh created
  11. //
  12. //---------------------------------------------------------------------------
  13. #ifndef _SHIMENG_VEH_H_
  14. #define _SHIMENG_VEH_H_
  15. typedef struct _SETACTIVATEADDRESS {
  16. RELATIVE_MODULE_ADDRESS rva; // relative address where this patch data is to be applied.
  17. } SETACTIVATEADDRESS, *PSETACTIVATEADDRESS;
  18. typedef struct _HOOKPATCHINFO {
  19. DWORD dwHookAddress; // Address of a hooked function
  20. PSETACTIVATEADDRESS pData; // Pointer to the real patch data
  21. PVOID pThunkAddress; // Pointer to the call thunk
  22. struct _HOOKPATCHINFO* pNextHook;
  23. } HOOKPATCHINFO, *PHOOKPATCHINFO;
  24. //
  25. // Flags used in the shim HOOKAPIs to track chaining
  26. //
  27. #define HOOK_CHAIN_TOP 0x40000000
  28. #define HOOK_CHAINED 0x80000000
  29. #define HOOK_INDEX_MASK ~(HOOK_CHAINED | HOOK_CHAIN_TOP)
  30. //
  31. // x86 opcodes and sizes used in the thunk generation process
  32. //
  33. #define CLI_OR_STI_SIZE 1
  34. #define CALL_REL_SIZE 5
  35. #define JMP_SIZE 7
  36. #define X86_ABSOLUTE_FAR_JUMP 0xEA
  37. #define X86_REL_CALL_OPCODE 0xE8
  38. #define X86_CALL_OPCODE 0xFF
  39. #define X86_CALL_OPCODE2 0x15
  40. #define REASON_APIHOOK 0xFA
  41. #define REASON_PATCHHOOK 0xFB
  42. //
  43. // Flags used in maintaining state information about our module/DLL filtering
  44. //
  45. #define MODFILTER_INCLUDE 0x01
  46. #define MODFILTER_EXCLUDE 0x02
  47. #define MODFILTER_DLL 0x04
  48. #define MODFILTER_GLOBAL 0x08
  49. typedef struct _MODULEFILTER
  50. {
  51. DWORD dwModuleStart; // Starting address of the module to filter
  52. DWORD dwModuleEnd; // Ending address of the module to filter
  53. DWORD dwCallerOffset; // Offset added to beginning of module to form the caller's address
  54. DWORD dwCallerAddress; // Caller address to operate upon
  55. DWORD dwFlags; // Flags which define what this filter does
  56. WCHAR wszModuleName[96];
  57. struct _MODULEFILTER *pNextFilter; // Used to iterate the module filter normally
  58. struct _MODULEFILTER *pNextLBFilter; // Used to iterate the late bound DLLs
  59. } MODULEFILTER, *PMODULEFILTER;
  60. typedef struct _CHAININFO
  61. {
  62. PVOID pAPI;
  63. PVOID pReturn;
  64. struct _CHAININFO *pNextChain;
  65. } CHAININFO, *PCHAININFO;
  66. typedef struct _HOOKAPIINFO
  67. {
  68. DWORD dwAPIHookAddress; // Address of a hooked function
  69. PHOOKAPI pTopLevelAPIChain; // Top level hook address
  70. PVOID pCallThunkAddress;
  71. WCHAR wszModuleName[32];
  72. struct _HOOKAPIINFO *pNextHook;
  73. struct _HOOKAPIINFO *pPrevHook;
  74. } HOOKAPIINFO, *PHOOKAPIINFO;
  75. #pragma pack(push, 1)
  76. typedef struct _SHIMJMP
  77. {
  78. BYTE PUSHAD; //pushad (60)
  79. BYTE MOVEBPESP[2]; //mov ebp, esp (8b, ec)
  80. BYTE MOVEAXDWVAL[5]; //mov eax, dwval (b8 dword val)
  81. BYTE PUSHEAX; //push eax (50)
  82. BYTE LEAEAXEBPPLUS20[3]; //lea eax, [ebp + 20] (8f 45 20)
  83. BYTE PUSHEAX2; //push eax (50)
  84. BYTE CALLROUTINE[6]; //call [address] (ff15 dword address)
  85. BYTE MOVESPPLUS1CEAX[4]; //mov [esp+0x1c],eax (89 44 24 1c)
  86. BYTE POPAD; //popad (61)
  87. BYTE ADDESPPLUS4[3]; //add esp, 0x4 (83 c4 04)
  88. BYTE JMPEAX[2]; //jmp eax (ff e0)
  89. } SHIMJMP, *PSHIMJMP;
  90. typedef struct _SHIMRET
  91. {
  92. BYTE PUSHEAX; //push eax (50)
  93. BYTE PUSHAD; //pushad (60)
  94. BYTE CALLROUTINE[6]; //call [address] (ff15 dword address)
  95. BYTE MOVESPPLUS20EAX[4]; //mov [esp+0x20],eax (89 44 24 20)
  96. BYTE POPAD; //popad (61)
  97. BYTE RET; //ret (c3)
  98. } SHIMRET, *PSHIMRET;
  99. #pragma pack(pop)
  100. typedef NTSTATUS (*PFNLDRLOADDLL)(
  101. IN PWSTR DllPath OPTIONAL,
  102. IN PULONG DllCharacteristics OPTIONAL,
  103. IN PUNICODE_STRING DllName,
  104. OUT PVOID *DllHandle
  105. );
  106. typedef NTSTATUS (*PFNLDRUNLOADDLL) (
  107. IN PVOID DllHandle
  108. );
  109. typedef PVOID (*PFNRTLALLOCATEHEAP)(
  110. IN PVOID HeapHandle,
  111. IN ULONG Flags,
  112. IN SIZE_T Size
  113. );
  114. typedef BOOLEAN (*PFNRTLFREEHEAP)(
  115. IN PVOID HeapHandle,
  116. IN ULONG Flags,
  117. IN PVOID BaseAddress
  118. );
  119. NTSTATUS
  120. SevInitializeData(
  121. PAPP_COMPAT_SHIM_INFO *pShimData);
  122. NTSTATUS
  123. SevExecutePatchPrimitive(
  124. PBYTE pPatch);
  125. DWORD
  126. SevGetPatchAddress(
  127. PRELATIVE_MODULE_ADDRESS pRelAddress);
  128. VOID
  129. SevValidateGlobalFilter(
  130. VOID);
  131. NTSTATUS
  132. SevFinishThunkInjection(
  133. DWORD dwAddress,
  134. PVOID pThunk,
  135. DWORD dwThunkSize,
  136. BYTE jReason);
  137. NTSTATUS
  138. SevBuildFilterException(
  139. HSDB hSDB,
  140. TAGREF trInclude,
  141. PMODULEFILTER pModFilter,
  142. BOOL* pbLateBound);
  143. NTSTATUS
  144. SevBuildExeFilter(
  145. HSDB hSDB,
  146. TAGREF trExe,
  147. DWORD dwDllCount);
  148. PVOID
  149. SevBuildInjectionCode(
  150. PVOID pAddress,
  151. PDWORD pdwThunkSize);
  152. NTSTATUS
  153. SevAddShimFilterException(
  154. WCHAR* wszDLLPath,
  155. PMODULEFILTER pModFilter);
  156. NTSTATUS
  157. SevChainAPIHook(
  158. DWORD dwHookEntryPoint,
  159. PVOID pThunk,
  160. PHOOKAPI pAPIHook);
  161. PVOID
  162. SevFilterCaller(
  163. PMODULEFILTER pFilterList,
  164. PVOID pFunctionAddress,
  165. PVOID pExceptionAddress,
  166. PVOID pStubAddress,
  167. PVOID pCallThunkAddress);
  168. NTSTATUS
  169. SevPushCaller(
  170. PVOID pAPIAddress,
  171. PVOID pReturnAddress);
  172. PVOID
  173. SevPopCaller(
  174. VOID);
  175. NTSTATUS
  176. StubLdrLoadDll(
  177. IN PWSTR DllPath OPTIONAL,
  178. IN PULONG DllCharacteristics OPTIONAL,
  179. IN PUNICODE_STRING DllName,
  180. OUT PVOID* DllHandle);
  181. NTSTATUS
  182. StubLdrUnloadDll(
  183. IN PVOID DllHandle);
  184. NTSTATUS
  185. SevFixupAvailableProcs(
  186. DWORD dwHookCount,
  187. PHOOKAPI* pHookArray,
  188. PDWORD pdwNumberHooksArray,
  189. PDWORD pdwUnhookedCount);
  190. LONG
  191. SevExceptionHandler(
  192. struct _EXCEPTION_POINTERS *ExceptionInfo);
  193. #endif // _SHIMENG_VEH_H_