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.

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