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.

535 lines
16 KiB

  1. CodeData equ <THUNK16BCodeData>
  2. include thkframe.inc
  3. include thkrp.inc
  4. include cbcheck.inc
  5. include public.inc
  6. include cbcid.inc
  7. include dlgcbid.inc
  8. externDef FreeCallback:far16
  9. externDef AllocCallback:far16
  10. externDef ConvertDevModeHandleSL:far16
  11. externDef ConvertDevNamesHandleSL:far16
  12. externDef ConvertDevModeHandleLS:far16
  13. externDef ConvertDevNamesHandleLS:far16
  14. fLocalFlag equ fDlgLog16
  15. ; note: following size should be the same as in thunkcom\pack.h
  16. OPENFILENAME16_SIZE EQU 72
  17. OPENFILENAME32_SIZE EQU 76 ;4Ch
  18. CHOOSECOLOR16_SIZE EQU 32
  19. CHOOSECOLOR32_SIZE EQU 36 ;24h
  20. CHOOSEFONT16_SIZE EQU 46
  21. CHOOSEFONT32_SIZE EQU 60 ;3Ch
  22. PRINTDLG16_SIZE EQU 52
  23. PRINTDLG32_SIZE EQU 66 ;42h
  24. LOGFONT16_SIZE EQU 50
  25. OFN16_Flags_OFFSET EQU 48 ;30h
  26. CC16_rgbResult_OFFSET EQU 8 ;08h
  27. CF16_iPointSize_OFFSET EQU 12 ;0Ch
  28. CF16_Flags_OFFSET EQU 14 ;0Dh
  29. CF16_rgbColors_OFFSET EQU 18 ;12h
  30. CF16_nFontType_OFFSET EQU 40 ;28h
  31. PD16_hDevMode_OFFSET EQU 6 ;06h
  32. PD16_hDevNames_OFFSET EQU 8 ;08h
  33. OFN32_Flags_OFFSET EQU 52 ;34h
  34. OFN32_lpfnHook_OFFSET EQU 68 ;44h
  35. CC32_rgbResult_OFFSET EQU 12 ;0Ch
  36. CC32_Flags_OFFSET EQU 20 ;14h
  37. CC32_lpfnHook_OFFSET EQU 28 ;1Ch
  38. FR32_Flags_OFFSET EQU 12 ;0CH
  39. FR32_lpfnHook_OFFSET EQU 32 ;20h
  40. CF32_lpLogFont_OFFSET EQU 12 ;0Ch
  41. CF32_iPointSize_OFFSET EQU 16 ;10h
  42. CF32_Flags_OFFSET EQU 20 ;14h
  43. CF32_rgbColors_OFFSET EQU 24 ;18h
  44. CF32_lpfnHook_OFFSET EQU 32 ;20h
  45. CF32_nFontType_OFFSET EQU 48 ;30h
  46. PD32_Flags_OFFSET EQU 20 ;1Ch
  47. PD32_hDevMode_OFFSET EQU 8 ;08h
  48. PD32_hDevNames_OFFSET EQU 12 ;0Ch
  49. PD32_lpfnPrintHook_OFFSET EQU 42 ;2Ah
  50. PD32_lpfnSetupHook_OFFSET EQU 46 ;2Eh
  51. ;---------------------------------------------------------------------------
  52. ; This macro does the work for GetOpenFilename() and GetSaveFilename().
  53. ; The argument "Flags" is a dword ptr expression denoting a thunk-compiler
  54. ; temporary that holds the Flags field of the OPENFILENAME struct.
  55. ;
  56. ; Assumption: If the hInst field is a global handle, the Win32 wrapper
  57. ; guaratees it's a (zero-extended) Win16 handle.
  58. ;---------------------------------------------------------------------------
  59. RAWPACK__THKGETOPENORSAVEFILENAME_lpOfn macro iOffset,iTempOffset,Flags
  60. local skip_it
  61. local nohook,hook_done
  62. local notemplate,template_done
  63. sub sp,OPENFILENAME16_SIZE ; alloc space for MapLS sels
  64. sub sp,OPENFILENAME16_SIZE ; alloc space on stack
  65. mov eax,[bp+iOffset] ; base address
  66. or eax,eax ; check structure pointer
  67. jz skip_it ; skip if null
  68. mov [bp-iTempOffset],sp ; save offset to buffer
  69. mov [bp-iTempOffset+2],ss ; save selector to buffer
  70. mov di,ss
  71. mov es,di
  72. movzx edi,sp ; es:edi == destination address
  73. mov esi,eax
  74. mov ds,cs:CodeData ; need access to FlatData
  75. mov ds,FlatData ; ds:esi == source address
  76. mov eax,ds:[esi + OFN32_Flags_OFFSET]
  77. mov Flags,eax
  78. cld
  79. lodsd ds:[esi] ;BUGBUG lStructSize should be checked here
  80. mov eax,OPENFILENAME16_SIZE ;sizeof(OPENFILENAME16)
  81. stosd es:[edi] ;lStructSize same size
  82. ; comments refer to action going 16->32
  83. ;hwndOwner
  84. copyt
  85. mov ecx,Flags
  86. and ecx,OFN_ENABLETEMPLATE
  87. lodsd ds:[esi] ;hInst
  88. MAP_CD_NULL_HINST eax,ecx
  89. stosw es:[edi]
  90. MAP_POINTER es:[di+OPENFILENAME16_SIZE] ;PLUGGED lpstrFilter
  91. MAP_POINTER es:[di+OPENFILENAME16_SIZE] ;PLUGGED lpstrCustomFilter
  92. ncopyd 2 ;nMaxCustFilter,nFilterIndex
  93. MAP_POINTER es:[di+OPENFILENAME16_SIZE] ;PLUGGED lpstrFile
  94. copyd ;nMaxFile
  95. MAP_POINTER es:[di+OPENFILENAME16_SIZE] ;PLUGGED lpstrFileTitle
  96. copyd ;nMaxFileTitle
  97. MAP_POINTER es:[di+OPENFILENAME16_SIZE] ;PLUGGED lpstrInitialDir
  98. MAP_POINTER es:[di+OPENFILENAME16_SIZE] ;PLUGGED lpstrTitle
  99. copyd ;Flags
  100. ncopyw 2 ;nFileOffset,nFileExtension
  101. MAP_POINTER es:[di+OPENFILENAME16_SIZE];PLUGGED lpstrDefExt
  102. copyd ;lCustData
  103. test Flags,OFN_ENABLEHOOK
  104. jz nohook
  105. MAP_CALLBACK CBID_OPENFILENAME ;PLUGGED lpfnHook
  106. jmp short hook_done
  107. nohook:
  108. copyd
  109. hook_done:
  110. ;lpTemplate must be mapped only if OFN_ENABLETEMPLATE is set
  111. xor eax,eax
  112. mov es:[di+OPENFILENAME16_SIZE],eax ;in case we skip mapping
  113. test Flags, OFN_ENABLETEMPLATE ; if OFN_ENABLETEMPLATE is set
  114. jz notemplate
  115. MAP_POINTER es:[di+OPENFILENAME16_SIZE] ;PLUGGED lpTemplateName
  116. jmp short template_done
  117. notemplate:
  118. copyd ;lpTemplate
  119. template_done:
  120. skip_it:
  121. endm
  122. RAWUNPACK__THKGETOPENORSAVEFILENAME_lpOfn macro iOffset,iTempOffset,Flags
  123. local skip_it
  124. local nohook,hook_done
  125. local notemplate,template_done
  126. mov eax,[bp+iOffset] ; base address
  127. or eax,eax ; check structure pointer
  128. jz skip_it ; skip if null
  129. mov es,cs:CodeData
  130. mov es,es:FlatData
  131. mov edi,eax ; source in es:edi
  132. push ds
  133. lds si,[bp-iTempOffset]
  134. movzx esi,si ;in case code uses esi by accident
  135. cld
  136. lods dword ptr ds:[si] ;BUGBUG lStructSize should be checked here
  137. mov eax,OPENFILENAME32_SIZE ;sizeof(OPENFILENAME32)
  138. stos dword ptr es:[edi] ;lStructSize same size
  139. ; comments refer to action going 16->32
  140. copyzx
  141. mov ecx,Flags
  142. and ecx,OFN_ENABLETEMPLATE
  143. lodsw ds:[si] ;hInst
  144. UMAP_CD_NULL_HINST ax,ecx
  145. stosd es:[edi]
  146. UMAP_POINTER ds:[si+OPENFILENAME16_SIZE] ;lpstrFilter must be mapped
  147. UMAP_POINTER ds:[si+OPENFILENAME16_SIZE] ;lpstrCustomFilter must be mapped
  148. ncopyd 2
  149. UMAP_POINTER ds:[si+OPENFILENAME16_SIZE] ;lpstrFile must be mapped
  150. copyd
  151. UMAP_POINTER ds:[si+OPENFILENAME16_SIZE] ;lpstrFileTitle must be mapped
  152. copyd
  153. UMAP_POINTER ds:[si+OPENFILENAME16_SIZE] ;lpstrInitialDir must be mapped
  154. UMAP_POINTER ds:[si+OPENFILENAME16_SIZE] ;lpstrTitle must be mapped
  155. copyd
  156. ncopyw 2
  157. UMAP_POINTER ds:[si+OPENFILENAME16_SIZE] ;lpstrDefExt must be mapped
  158. copyd
  159. test Flags,OFN_ENABLEHOOK
  160. jz nohook
  161. lodsd ds:[si]
  162. FREE_CALLBACK CBID_OPENFILENAME
  163. stos dword ptr es:[edi]
  164. jmp short hook_done
  165. nohook:
  166. copyd
  167. hook_done:
  168. test Flags,OFN_ENABLETEMPLATE
  169. jz notemplate
  170. UMAP_POINTER ds:[si+OPENFILENAME16_SIZE] ;lpTemplateName must be mapped
  171. jmp short template_done
  172. notemplate:
  173. copyd
  174. template_done:
  175. pop ds
  176. skip_it:
  177. endm
  178. ;-----------------------------------------------------------------------------
  179. ; Pack/unpack OPENFILENAME struct for GetOpenFilename().
  180. ;-----------------------------------------------------------------------------
  181. RAWPACK__THKGETOPENFILENAME_lpOfn macro iOffset,iTempOffset
  182. RAWPACK__THKGETOPENORSAVEFILENAME_lpOfn iOffset,iTempOffset,dword ptr LOCAL__THKGETOPENFILENAME_Flags
  183. endm
  184. RAWUNPACK__THKGETOPENFILENAME_lpOfn macro iOffset,iTempOffset
  185. RAWUNPACK__THKGETOPENORSAVEFILENAME_lpOfn iOffset,iTempOffset,dword ptr LOCAL__THKGETOPENFILENAME_Flags
  186. endm
  187. ;-----------------------------------------------------------------------------
  188. ; Pack/unpack OPENFILENAME struct for GetSaveFilename().
  189. ;-----------------------------------------------------------------------------
  190. RAWPACK__THKGETSAVEFILENAME_lpOfn macro iOffset,iTempOffset
  191. RAWPACK__THKGETOPENORSAVEFILENAME_lpOfn iOffset,iTempOffset,dword ptr LOCAL__THKGETSAVEFILENAME_Flags
  192. endm
  193. RAWUNPACK__THKGETSAVEFILENAME_lpOfn macro iOffset,iTempOffset
  194. RAWUNPACK__THKGETOPENORSAVEFILENAME_lpOfn iOffset,iTempOffset,dword ptr LOCAL__THKGETSAVEFILENAME_Flags
  195. endm
  196. ;-----------------------------------------------------------------------------
  197. ; Pack CHOOSECOLOR struct for ChooseColor().
  198. ;
  199. ; Assumption: If the hInst field is a global handle, the Win32 wrapper
  200. ; guaratees it's a (zero-extended) Win16 handle.
  201. ;-----------------------------------------------------------------------------
  202. RAWPACK__THKCHOOSECOLOR_lpcc macro iOffset,iTempOffset
  203. local nohook,hook_done
  204. local notemplate,template_done
  205. local skip_it
  206. sub sp,CHOOSECOLOR16_SIZE ;Alloc space on stack
  207. mov eax,[bp+iOffset]
  208. or eax,eax
  209. jz skip_it
  210. mov [bp-iTempOffset],sp ;Save offset to buffer
  211. mov [bp-iTempOffset+2],ss ;Save selector to buffer
  212. mov di,ss
  213. mov es,di
  214. movzx edi,sp
  215. mov esi,eax
  216. mov ds,cs:CodeData
  217. mov ds,FlatData
  218. mov eax,ds:[esi + CC32_Flags_OFFSET]
  219. mov LOCAL__THKCHOOSECOLOR_Flags,eax
  220. lodsd ds:[esi]
  221. mov eax,CHOOSECOLOR16_SIZE
  222. stosd es:[di] ;lStructSize
  223. ;hwndOwner
  224. copyt
  225. ;hInstance
  226. mov ecx,LOCAL__THKCHOOSECOLOR_Flags
  227. and ecx,CC_ENABLETEMPLATE
  228. lodsd ds:[esi] ;hInst
  229. MAP_CD_NULL_HINST eax,ecx
  230. stosw es:[di]
  231. ;rgbResult
  232. copyd
  233. MAP_POINTER LOCAL__THKCHOOSECOLOR_lpCustColorsSeg ;PLUGGED lpCustColors
  234. ;Flags, lCustData
  235. ncopyd 2
  236. ; Map hook function (only do the mapping if CC_ENABLEHOOK flag set).
  237. mov eax,LOCAL__THKCHOOSECOLOR_Flags
  238. test eax,CC_ENABLEHOOK
  239. jz nohook
  240. MAP_CALLBACK CBID_CHOOSECOLOR ;PLUGGED lpfnHook
  241. jmp short hook_done
  242. nohook:
  243. copyd
  244. hook_done:
  245. ; Map template name (only if CC_ENABLETEMPLATE flag set).
  246. mov eax,LOCAL__THKCHOOSECOLOR_Flags
  247. test eax,CC_ENABLETEMPLATE
  248. jz notemplate
  249. MAP_POINTER LOCAL__THKCHOOSECOLOR_lpTemplateNameSeg ;PLUGGED
  250. jmp short template_done ;lpTemplate
  251. notemplate:
  252. copyd
  253. template_done:
  254. ; Finished
  255. skip_it:
  256. endm
  257. ;-----------------------------------------------------------------------------
  258. ; Unpack CHOOSECOLOR struct for ChooseColor().
  259. ;-----------------------------------------------------------------------------
  260. RAWUNPACK__THKCHOOSECOLOR_lpcc macro iOffset,iTempOffset
  261. local skip_it
  262. local nohook
  263. mov eax,[bp+iOffset] ; base address
  264. or eax,eax ; check structure pointer
  265. jz skip_it ; skip if null
  266. mov es,cs:CodeData
  267. mov es,es:FlatData
  268. mov edi,eax ; source in es:edi
  269. ; Free callback (if CC_ENABLEHOOK flag set).
  270. mov eax,LOCAL__THKCHOOSECOLOR_Flags
  271. test eax,CC_ENABLEHOOK
  272. jz nohook
  273. mov eax,es:[edi+CC32_lpfnHook_OFFSET]
  274. FREE_CALLBACK CBID_CHOOSECOLOR
  275. nohook:
  276. ; Propagate copy-outs field back to caller's struct.
  277. mov si, [bp-iTempOffset]
  278. mov eax,ss:[si+CC16_rgbResult_OFFSET]
  279. mov es:[edi+CC32_rgbResult_OFFSET], eax
  280. ; Free up selectors (if no mapping happened, UnmapLS safely ignores
  281. ; NULL segments).
  282. pushd LOCAL__THKCHOOSECOLOR_lpCustColorsSeg
  283. call UnmapLS
  284. pushd LOCAL__THKCHOOSECOLOR_lpTemplateNameSeg
  285. call UnmapLS
  286. skip_it:
  287. endm
  288. ;-----------------------------------------------------------------------------
  289. ; Pack/unpack CHOOSEFONT struct for ChooseFont().
  290. ;
  291. ; Assumption: If the hInst field is a global handle, the Win32 wrapper
  292. ; guaratees it's a (zero-extended) Win16 handle.
  293. ;-----------------------------------------------------------------------------
  294. RAWPACK__THKCHOOSEFONT_lpcf macro iOffset,iTempOffset
  295. local skip_it
  296. local nohook,hook_done
  297. local notemplate,template_done
  298. local no_log_font
  299. sub sp,CHOOSEFONT16_SIZE+LOGFONT16_SIZE ; alloc space on stack
  300. mov eax,[bp+iOffset] ; base address
  301. or eax,eax ; check structure pointer
  302. jz skip_it ; skip if null
  303. mov [bp-iTempOffset],sp ; save offset to buffer
  304. mov [bp-iTempOffset+2],ss ; save selector to buffer
  305. mov di,ss
  306. mov es,di
  307. movzx edi,sp ; es:edi == destination address
  308. mov esi,eax
  309. mov ds,cs:CodeData ; need access to FlatData
  310. mov ds,FlatData ; ds:esi == source address
  311. mov eax,ds:[esi + CF32_Flags_OFFSET]
  312. mov LOCAL__THKCHOOSEFONT_Flags,eax
  313. cld
  314. ; comments refer to action going 16->32
  315. lodsd ds:[esi] ;BUGBUG lStructSize should be checked here
  316. mov eax,CHOOSEFONT16_SIZE ;sizeof(CHOOSEFONT16)
  317. stosd es:[di] ;lStructSize same size
  318. ;hwndOwner, hDC
  319. ncopyt 2
  320. lodsd ds:[esi]
  321. or eax,eax
  322. jz no_log_font
  323. mov ax,ss
  324. ror eax,16
  325. mov ax,di
  326. add ax,CHOOSEFONT16_SIZE-8 ;already moved DI by 8
  327. no_log_font:
  328. stosd es:[di] ;lpLogFont widened (need to pack it)
  329. ;iPointSize
  330. copyt
  331. ;Flags, rgbColors, lCustData
  332. ncopyd 3
  333. test dword ptr LOCAL__THKCHOOSEFONT_Flags,CF_ENABLEHOOK
  334. jz nohook
  335. MAP_CALLBACK CBID_CHOOSEFONT ;PLUGGED lpfnHook
  336. jmp short hook_done
  337. nohook:
  338. copyd
  339. hook_done:
  340. test dword ptr LOCAL__THKCHOOSEFONT_Flags,CF_ENABLETEMPLATE
  341. jz notemplate
  342. MAP_POINTER LOCAL__THKCHOOSEFONT_lpTemplateNameTemp ;PLUGGED
  343. jmp short template_done
  344. notemplate:
  345. copyd
  346. template_done:
  347. mov ecx,LOCAL__THKCHOOSEFONT_Flags
  348. and ecx,CF_ENABLETEMPLATE
  349. lodsd ds:[esi] ;hInst
  350. MAP_CD_NULL_HINST eax,ecx
  351. stosw es:[di]
  352. ;lpszStyle must be mapped
  353. MAP_POINTER LOCAL__THKCHOOSEFONT_lpszStyleTemp ;PLUGGED
  354. ;nFontType, nSizeMin, nSizeMax
  355. ncopyt 3
  356. mov esi,[bp+iOffset] ; base address
  357. mov esi,[esi].CF32_lpLogFont_OFFSET ; ds:esi == source address
  358. or esi,esi ; check structure pointer
  359. jz skip_it ; skip if null
  360. cld
  361. ; comments refer to action going 16->32
  362. ;lfHeight, lfWidth, lfEscapement, lfOrientation, lfWeight
  363. ncopyt 5
  364. ;lfItalic, ..., lfFaceName
  365. ncopyd (40/4)
  366. skip_it:
  367. endm
  368. RAWUNPACK__THKCHOOSEFONT_lpcf macro iOffset,iTempOffset
  369. local skip_it
  370. local nohook
  371. ;!!! We're only unpacking the log font structure! Does the rest of
  372. ; the CHOOSEFONT structure need to be unpacked as well?
  373. mov eax,[bp+iOffset] ; base address
  374. or eax,eax ; check structure pointer
  375. jz skip_it ; skip if null
  376. mov es,cs:CodeData
  377. mov es,es:FlatData
  378. mov edi,eax ; dest in es:edi
  379. test dword ptr LOCAL__THKCHOOSEFONT_Flags,CF_ENABLEHOOK
  380. jz nohook
  381. mov eax,es:[edi+CF32_lpfnHook_OFFSET]
  382. FREE_CALLBACK CBID_CHOOSEFONT
  383. nohook:
  384. ;; The iPointSize, rgbColors, Flags & nFontType fields need to be copied back
  385. ;; to the caller's buffer.
  386. lds si,dword ptr [bp-iTempOffset]
  387. movzx esi,si
  388. mov eax,[si+CF16_rgbColors_OFFSET] ; rgbColors
  389. mov es:[edi+CF32_rgbColors_OFFSET],eax
  390. mov ax,[si+CF16_iPointSize_OFFSET] ; iPointSize
  391. movsx eax,ax
  392. mov es:[edi+CF32_iPointSize_OFFSET],eax
  393. mov eax,[si+CF16_Flags_OFFSET] ; Flags
  394. mov es:[edi+CF32_Flags_OFFSET],eax
  395. mov ax,[si+CF16_nFontType_OFFSET] ; nFontType
  396. movzx eax,ax
  397. mov es:[edi+CF32_nFontType_OFFSET],eax
  398. mov edi,es:[edi+CF32_lpLogFont_OFFSET]
  399. or edi,edi
  400. jz skip_it
  401. add si,CHOOSEFONT16_SIZE
  402. ; comments refer to action going 16->32
  403. cld
  404. ncopysx 5
  405. ncopyd (40/4)
  406. skip_it:
  407. pushd LOCAL__THKCHOOSEFONT_lpszStyleTemp
  408. call UnmapLS
  409. pushd LOCAL__THKCHOOSEFONT_lpTemplateNameTemp
  410. call UnmapLS
  411. endm