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.

362 lines
10 KiB

  1. // --------------------------------------------------------------------------
  2. //
  3. // AS16.H
  4. //
  5. // Defines for 16-bit patching dll, the vestigial pieces of the dclwin95
  6. // code we still need in the 32-bit port.
  7. //
  8. // NOTE ON VARIABLE NAMING CONVENTION:
  9. // c_ is codeseg (constant)
  10. // s_ is local (writeable, static to file)
  11. // g_ is global (writeable, accessed by any file)
  12. //
  13. // --------------------------------------------------------------------------
  14. #ifndef _H_AS16
  15. #define _H_AS16
  16. #define DLL_PROCESS_DETACH 0
  17. #define DLL_PROCESS_ATTACH 1
  18. #define FAR_NULL ((void FAR*)0L)
  19. #define CODESEG _based(_segname("_CODE"))
  20. //
  21. // SYSTEM & APP SHARING HEADERS
  22. //
  23. #include <dcg.h>
  24. #include <ut.h>
  25. #include <dcs.h>
  26. #include <osi.h>
  27. #include <shm.h>
  28. #include <sbc.h>
  29. #include <oe.h>
  30. #include <ssi.h>
  31. #include <host.h>
  32. #include <im.h>
  33. #include <usr.h>
  34. #include <asthk.h>
  35. //
  36. // WINDOWS FUNCTIONS
  37. //
  38. int MyStrcmp(LPCSTR lp1, LPCSTR lp2);
  39. /////////////////////////////////////////////////////////////////////////////
  40. // KERNEL
  41. /////////////////////////////////////////////////////////////////////////////
  42. // Pointer mapping 16<->32
  43. LPVOID WINAPI MapSL(LPVOID lp16BitPtr);
  44. LPVOID WINAPI MapLS(LPVOID lp32BitPtr);
  45. void WINAPI UnMapLS(LPVOID lp16BitMappedPtr);
  46. DWORD WINAPI GetModuleHandle32(LPSTR);
  47. DWORD WINAPI GetProcAddress32(DWORD, LPSTR);
  48. HANDLE WINAPI GetExePtr(HANDLE);
  49. HINSTANCE WINAPI MapInstance32(DWORD); // Our wrapper around MaphInstLS
  50. // GetCodeInfo() flags
  51. #define NSTYPE 0x0007
  52. #define NSCODE 0x0000
  53. #define NSDATA 0x0001
  54. #define NSITER 0x0008
  55. #define NSMOVE 0x0010
  56. #define NSSHARE 0x0020
  57. #define HSPRELOAD 0x0040
  58. #define NSERONLY 0x0080
  59. #define NSRELOC 0x0100
  60. #define NSDPL 0x0C00
  61. #define NSDISCARD 0x1000
  62. #define NS286DOS 0xCE06
  63. #define NSALLOCED 0x0002
  64. #define NSLOADED 0x0004
  65. #define NSCOMPR 0x0200
  66. #define NSUSESDATA 0x0400
  67. #define NSKCACHED 0x0800
  68. #define NSUSE32 0x2000
  69. #define NSWINCODE 0x4000
  70. #define NSINROM 0x8000
  71. // Process info
  72. #define GPD_PPI 0
  73. #define GPD_FLAGS -4
  74. #define GPD_PARENT -8
  75. #define GPD_STARTF_FLAGS -12
  76. #define GPD_STARTF_POS -16
  77. #define GPD_STARTF_SIZE -20
  78. #define GPD_STARTF_SHOWCMD -24
  79. #define GPD_STARTF_HOTKEY -28
  80. #define GPD_STARTF_SHELLDATA -32
  81. #define GPD_CURR_PROCESS_ID -36
  82. #define GPD_CURR_THREAD_ID -40
  83. #define GPD_EXP_WINVER -44
  84. #define GPD_EXP_WINVER -44
  85. #define GPD_HINST -48
  86. #define GPD_HUTSTATE -52
  87. #define GPD_COMPATFLAGS -56
  88. //
  89. // GPD_FLAGS
  90. //
  91. #define GPF_DEBUG_PROCESS 0x00000001
  92. #define GPF_WIN16_PROCESS 0x00000008
  93. #define GPF_DOS_PROCESS 0x00000010
  94. #define GPF_CONSOLE_PROCESS 0x00000020
  95. #define GPF_SERVICE_PROCESS 0x00000100
  96. //
  97. // GPD_STARTF_FLAGS
  98. //
  99. #define STARTF_USESHOWWINDOW 0x00000001
  100. #define STARTF_USESIZE 0x00000002
  101. #define STARTF_USEPOSITION 0x00000004
  102. #define STARTF_FORCEONFEEDBACK 0x00000040
  103. #define STARTF_FORCEOFFFEEDBACK 0x00000080
  104. #define STARTF_USEHOTKEY 0x00000200
  105. #define STARTF_HASSHELLDATA 0x00000400
  106. DWORD WINAPI GetProcessDword(DWORD idProcess, int iIndex);
  107. BOOL WINAPI SetProcessDword(DWORD idProcess, int iIndex, DWORD dwValue);
  108. void WINAPI _EnterWin16Lock(void);
  109. void WINAPI _LeaveWin16Lock(void);
  110. //
  111. // Special krnl386 routine to map unicode to ansi. We only need thunk for
  112. // converting back.
  113. //
  114. int WINAPI UniToAnsi(LPWSTR lpwszSrc, LPSTR lpszDst, int cch);
  115. //
  116. // kernel32.dll routine to map back to unicode from ansi.
  117. //
  118. typedef LONG (WINAPI * ANSITOUNIPROC)(DWORD codePage, DWORD dwFlags,
  119. LPCSTR lpMb, LONG cchMb, LPWSTR lpUni, LONG cchUni);
  120. int AnsiToUni(LPSTR lpMb, int cchMb, LPWSTR lpUni, int cchUni);
  121. //
  122. // dwMask is bitfields, where 1 means that parameter should be thunked as
  123. // a pointer. 0x00000001 means the 1st param, 0x00000002 means the 2nd,
  124. // and so on.
  125. //
  126. // The caller is responsible for making sure that the 32-bit address is
  127. // valid to call.
  128. //
  129. DWORD FAR _cdecl CallProcEx32W(DWORD numParams, DWORD dwMask, DWORD lpfn32, ...);
  130. /////////////////////////////////////////////////////////////////////////////
  131. // GDI
  132. /////////////////////////////////////////////////////////////////////////////
  133. //
  134. // Useful DIB def
  135. //
  136. typedef struct tagDIB4
  137. {
  138. BITMAPINFOHEADER bi;
  139. DWORD ct[16];
  140. } DIB4;
  141. BOOL WINAPI MakeObjectPrivate(HANDLE, BOOL);
  142. UINT WINAPI CreateSpb(HDC, int, int);
  143. BOOL WINAPI SysDeleteObject(HANDLE);
  144. HRGN WINAPI GetClipRgn(HDC);
  145. UINT WINAPI Death(HDC);
  146. UINT WINAPI Resurrection(HDC, DWORD, DWORD, DWORD);
  147. void WINAPI RealizeDefaultPalette(HDC);
  148. DWORD WINAPI GDIRealizePalette(HDC);
  149. extern DWORD FAR FT_GdiFThkThkConnectionData[];
  150. typedef BOOL (WINAPI* REALPATBLTPROC)(HDC, int, int, int, int, DWORD);
  151. typedef BOOL (WINAPI* TEXTOUTWPROC)(HDC, int, int, LPCWSTR, int);
  152. typedef BOOL (WINAPI* EXTTEXTOUTWPROC)(HDC, int, int, UINT, LPCRECT, LPCWSTR, UINT, LPINT);
  153. typedef BOOL (WINAPI* POLYLINETOPROC)(HDC, LPCPOINT, int);
  154. typedef BOOL (WINAPI* POLYPOLYLINEPROC)(DWORD, HDC, LPCPOINT, LPINT, int);
  155. typedef BOOL (WINAPI* SETCURSORPROC)(LPCURSORSHAPE lpcurs);
  156. typedef BOOL (WINAPI* SAVEBITSPROC)(LPRECT lprcSave, UINT uCmd);
  157. /////////////////////////////////////////////////////////////////////////////
  158. // USER
  159. /////////////////////////////////////////////////////////////////////////////
  160. #define WOAHACK_CHECKALTKEYSTATE 1
  161. #define WOAHACK_IGNOREALTKEYDOWN 2
  162. #define WOAHACK_DISABLEREPAINTSCREEN 3
  163. #define WOAHACK_LOSINGDISPLAYFOCUS 4
  164. #define WOAHACK_GAININGDISPLAYFOCUS 5
  165. #define WOAHACK_IAMAWINOLDAPPSORTOFGUY 6
  166. #define WOAHACK_SCREENSAVER 7
  167. BOOL WINAPI RealGetCursorPos(LPPOINT);
  168. void WINAPI PostPostedMessages(void);
  169. void WINAPI DispatchInput(void);
  170. LONG WINAPI WinOldAppHackoMatic(LONG flags);
  171. typedef DWORD (WINAPI* GETWINDOWTHREADPROCESSIDPROC)(HWND, LPDWORD);
  172. typedef LONG (WINAPI* CDSEXPROC)(LPCSTR, LPDEVMODE, HWND, DWORD, LPVOID);
  173. typedef struct tagCWPSTRUCT
  174. {
  175. LPARAM lParam;
  176. WPARAM wParam;
  177. UINT message;
  178. HWND hwnd;
  179. } CWPSTRUCT, FAR* LPCWPSTRUCT;
  180. //
  181. // Cursor stuff
  182. //
  183. #define BitmapWidth(cx, bits)\
  184. ((((cx)*(bits) + 0x0F) & ~0x0F) >> 3)
  185. #define BitmapSize(cx, cy, planes, bits)\
  186. (BitmapWidth(cx, bits) * (cy) * (planes))
  187. extern DWORD FAR FT_UsrFThkThkConnectionData[];
  188. void PostMessageNoFail(HWND, UINT, WPARAM, LPARAM);
  189. //
  190. // Mouse_ and Keybd_ Event stuf
  191. //
  192. //
  193. // For keyboard events, the app API and USER intterrupt flags are different.
  194. // For mouse events, they are the same.
  195. //
  196. #define KEYEVENTF_EXTENDEDKEY 0x0001
  197. #define KEYEVENTF_KEYUP 0x0002
  198. #define USERKEYEVENTF_EXTENDEDKEY 0x0100
  199. #define USERKEYEVENTF_KEYUP 0x8000
  200. #define MOUSEEVENTF_MOVE 0x0001
  201. #define MOUSEEVENTF_LEFTDOWN 0x0002
  202. #define MOUSEEVENTF_LEFTUP 0x0004
  203. #define MOUSEEVENTF_RIGHTDOWN 0x0008
  204. #define MOUSEEVENTF_RIGHTUP 0x0010
  205. #define MOUSEEVENTF_MIDDLEDOWN 0x0020
  206. #define MOUSEEVENTF_MIDDLEUP 0x0040
  207. #define MOUSEEVENTF_WHEEL 0x0800
  208. #define MOUSEEVENTF_ABSOLUTE 0x8000
  209. void FAR mouse_event(void);
  210. void FAR ASMMouseEvent(void);
  211. void CallMouseEvent(UINT regAX, UINT regBX, UINT regCX, UINT regDX,
  212. UINT regSI, UINT regDI);
  213. void FAR keybd_event(void);
  214. void FAR ASMKeyboardEvent(void);
  215. void CallKeyboardEvent(UINT regAX, UINT regBX, UINT regSI, UINT regDI);
  216. //
  217. // Signals
  218. //
  219. #define SIG_PRE_FORCE_LOCK 0x0003
  220. #define SIG_POST_FORCE_LOCK 0x0004
  221. BOOL WINAPI SignalProc32(DWORD dwSignal, DWORD dwID, DWORD dwFlags, WORD hTask16);
  222. //
  223. // PATCHING
  224. //
  225. #define OPCODE32_PUSH 0x68
  226. #define OPCODE32_CALL 0xE8
  227. #define OPCODE32_MOVCL 0xB1
  228. #define OPCODE32_MOVCX 0xB966
  229. #define OPCODE32_JUMP4 0xE9
  230. #define OPCODE_MOVAX 0xB8
  231. #define OPCODE_FARJUMP16 0xEA
  232. #define OPCODE32_16OVERRIDE 0x66
  233. #define CB_PATCHBYTES16 5
  234. #define CB_PATCHBYTES32 6
  235. #define CB_PATCHBYTESMAX max(CB_PATCHBYTES16, CB_PATCHBYTES32)
  236. typedef struct tagFN_PATCH
  237. {
  238. BYTE rgbOrg[CB_PATCHBYTESMAX]; // Original function bytes
  239. BYTE rgbPatch[CB_PATCHBYTESMAX]; // Patch bytes
  240. UINT wSegOrg; // Original code segment (we fix it)
  241. UINT fActive:1; // Patch has been activated
  242. UINT fEnabled:1; // Patch is currently enabled
  243. UINT fSharedAlias:1; // Don't free selector on destroy
  244. UINT fInterruptable:1; // Interrupt handler
  245. UINT f32Bit:1; // 32-bit code segment
  246. LPBYTE lpCodeAlias; // We keep an alias around to quickly enable/disable
  247. } FN_PATCH, FAR* LPFN_PATCH;
  248. #define ENABLE_OFF 0x0000 // disable end
  249. #define ENABLE_ON 0x0001 // enable start
  250. #define ENABLE_FORCALL 0x8000 // disable/enable for org call
  251. #define ENABLE_MASK 0x8001
  252. #define PATCH_ACTIVATE (ENABLE_ON)
  253. #define PATCH_DEACTIVATE (ENABLE_OFF)
  254. #define PATCH_ENABLE (ENABLE_ON | ENABLE_FORCALL)
  255. #define PATCH_DISABLE (ENABLE_OFF | ENABLE_FORCALL)
  256. //
  257. // NOTE: If the function being patched can be called at interrupt time,
  258. // the caller must make sure the jump to function can handle it.
  259. //
  260. // When your patch is called you:
  261. // * disable your patch with ENABLE_CALLOFF
  262. // * call the original function
  263. // * enable your patch with ENABLE_CALLON
  264. //
  265. UINT CreateFnPatch(LPVOID lpfnToPatch, LPVOID lpfnJumpTo, LPFN_PATCH lpbPatch, UINT selCodeAlias);
  266. void DestroyFnPatch(LPFN_PATCH lpbPatch);
  267. void EnableFnPatch(LPFN_PATCH lpbPatch, UINT flags);
  268. BOOL GetGdi32OnlyExport(LPSTR lpszExport, UINT cbJmpOffset, FARPROC FAR* lplpfn16);
  269. BOOL GetUser32OnlyExport(LPSTR lpszExport, FARPROC FAR* lplpfn16);
  270. BOOL Get32BitOnlyExport(DWORD lpfn32, UINT cbJmpOffset, LPDWORD lpThunkTable, FARPROC FAR * lplpfn16);
  271. LPCURSORSHAPE XformCursorBits(LPCURSORSHAPE lpOrg);
  272. // #define OTRACE WARNING_OUT
  273. #define OTRACE TRACE_OUT
  274. #include <globals.h>
  275. #endif // !_H_AS16