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.

331 lines
8.3 KiB

  1. ;-----------------------------------------------------------------------;
  2. ;
  3. ; WINEXEC.ASM -
  4. ;
  5. ; Windows Exec Function
  6. ;
  7. ;-----------------------------------------------------------------------;
  8. include kernel.inc
  9. ifdef WOW
  10. include wowcmpat.inc
  11. ;The following defines come from winerror.inc, which is new in the
  12. ;win95 source tree, but hasn't been merged into wow
  13. ERROR_FILE_NOT_FOUND equ 2
  14. ERROR_BAD_LENGTH equ 24
  15. endif
  16. ifdef FE_SB
  17. externFP FarMyIsDBCSLeadByte
  18. endif
  19. ifdef WOW
  20. externFP MyGetAppWOWCompatFlagsEx
  21. endif
  22. externW WinFlags ; (kdata.asm)
  23. externD WinAppHooks ; (kdata.asm)
  24. sBegin NRESCODE
  25. assumes cs,NRESCODE
  26. ;-----------------------------------------------------------------------;
  27. ;
  28. ; WinExec() -
  29. ;
  30. ;-----------------------------------------------------------------------;
  31. ; HANDLE PASCAL WinExec(lpszFile,wShow)
  32. cProc IWinExec, <FAR,PUBLIC>,<si,di>
  33. parmD lpszFile ; Pathname ptr
  34. parmW wShow ; Mode flag
  35. ;
  36. ; szCmdLine buffer must be big enough for passed in path & parms, plus
  37. ; .EXE, null terminator, and newline terminator.
  38. ; So we add a little room for good measure here.
  39. ;
  40. LocalV szCmdLine,260+256+8 ; Path and command line (to account for .exe)
  41. LocalW pszParm ; Ptr to start of parameters
  42. LocalB bDotFound ; Non-zero if a period is in the string
  43. LocalB bDblQFound ; Non-zero if the string starts with "
  44. LocalV loadparams, %(SIZE EXECBLOCK)
  45. LocalD FCB1
  46. cBegin
  47. ; Copy first part of line into szCmdLine.
  48. lds si,lpszFile
  49. smov es,ss
  50. lea di,szCmdLine
  51. mov cx,260 ; MAX_PATH
  52. xor al,al
  53. mov bDotFound,al
  54. mov bDblQFound,al
  55. ; The Dbl-quote is used as a delimiter for cmdname as in
  56. ; winexec("\"c:\fldr with spaces\" cmd line", ..);
  57. mov al, ds:[si] ; get Ist char
  58. cmp al,'"' ; is it a "
  59. jne WELoop1 ; N:
  60. mov bDblQFound,al ; Y: remember that
  61. lodsb ; skip the dblQ
  62. ; Loop until a blank or NULL is found.
  63. WELoop1:
  64. lodsb
  65. cmp bDblQFound, 0 ; If str didn't start with dblQ
  66. je WESpaceCheck ; then SPACE is a delimiter
  67. ; otherwise " is the delimiter
  68. cmp al,'"' ; look for second DblQ
  69. jne WESkipSpaceCheck
  70. and bDblQFound,0 ; reset this, so space is the delimiter
  71. lodsb ; skip past the dbl Q
  72. WESpaceCheck:
  73. cmp al,' ' ; Exit loop if blank or NULL
  74. je WECont1
  75. WESkipSpaceCheck:
  76. cmp al,9
  77. je WECont1
  78. or al,al
  79. je WECont1
  80. cmp al,'.'
  81. jne WELoopCont
  82. mov bDotFound,al
  83. WELoopCont:
  84. ;** We have to check to see if the dot we found was actually in
  85. ;** a directory name, not in the filename itself.
  86. cmp al, '\' ; Separator?
  87. je WE_Separator
  88. cmp al, '/'
  89. jne WE_Not_Separator
  90. WE_Separator:
  91. mov bDotFound,0 ; No dots count yet
  92. WE_Not_Separator:
  93. stosb
  94. dec cx
  95. jz WE_filename_too_long
  96. ifdef FE_SB ;Apr.26,1990 by AkiraK
  97. push cx
  98. call FarMyIsDBCSLeadByte
  99. pop cx
  100. jc WELoop1
  101. movsb
  102. dec cx
  103. jz WE_filename_too_long
  104. endif
  105. jmp short WELoop1
  106. WE_filename_too_long:
  107. krDebugOut DEB_TRACE, "WinExecEnv: filename too long, > 259"
  108. mov ax,ERROR_FILE_NOT_FOUND
  109. jmp WinExecEnvExit
  110. WECont1:
  111. mov dx,ax ; Store final char in DX
  112. ; Does the command have an extention?
  113. cmp bDotFound,0
  114. jne WEHasExt
  115. mov ax,0452Eh ;'.E'
  116. stosw
  117. mov ax,04558h ;'XE'
  118. stosw
  119. WEHasExt:
  120. xor ax,ax ; NULL terminate string
  121. stosb
  122. mov pszParm,di ; Store pointer to parm string
  123. stosb ; length = 0
  124. mov al,0dh ; line feed terminator
  125. stosb
  126. dec di ; back up
  127. or dl,dl ; Exec if lpszFile was null terminated
  128. jz WEExec
  129. ; Copy everything else into szParm.
  130. mov cx,255 ; Max length of cmd tail +1
  131. WELoop2:
  132. lodsb
  133. or al,al
  134. ifdef WOW
  135. jz WEDoneParm
  136. else
  137. jz WECont2
  138. endif
  139. stosb
  140. dec cx
  141. jnz WELoop2
  142. ifdef WOW
  143. jmps @F
  144. ;
  145. ; On NT we have a compatibility flag, WOWCFEX_LONGWINEXECTAIL which is
  146. ; set for applications such as TSSETUP, the setup program for Intergraph's
  147. ; NT-only Transcend app. This app uses a command tail on the order of
  148. ; 143 bytes for a Win32 worker app, and it worked on 3.5 and 3.51,
  149. ; so we need to continue to let at least this app cheat.
  150. ;
  151. WEDoneParm:
  152. sub cx, 128
  153. ja WECont2
  154. ; tail was longer than 126 characters
  155. call MyGetAppWOWCompatFlagsEx
  156. test dx, word ptr cs:[WE_GACFEX_LONGWINEXECTAIL+2]
  157. jz @F
  158. jmps WECont2
  159. WE_GACFEX_LONGWINEXECTAIL:
  160. DD WOWCFEX_LONGWINEXECTAIL
  161. @@:
  162. endif
  163. ; Cmd tail too long to fit in PSP !!!
  164. ; Fail the call.
  165. ; We _could_ alloc some memory to hold the cmd tail and make its
  166. ; owner be the new hTask. However InitTask is documented to return
  167. ; es=PSP, es:bx=cmd_tail. So we're in trouble. Could truncate the cmd line.
  168. ; Cleaner to fail the exec.
  169. ; Could grow the PSP and tack the big cmd tail on at the end. Scary!
  170. ; Unfortunately, kernel32.ExecWin16Program maps ERROR_BAD_LENGTH to
  171. ; ERROR_GEN_FAILURE.
  172. krDebugOut DEB_TRACE, "WinExecEnv: command tail too long, > 126"
  173. mov ax,ERROR_BAD_LENGTH
  174. jmps WinExecEnvExit
  175. WECont2:
  176. ; Terminate it with a carriage return.
  177. mov al,0Dh
  178. stosb
  179. ; Prefix the parameter string with its length.
  180. mov bx,pszParm ; ax = length + 2
  181. mov ax,di
  182. sub ax,bx
  183. dec ax ; don't include line feed char or length
  184. dec ax
  185. mov ss:[bx],al
  186. ; Set up the FCBs.
  187. WEExec:
  188. mov word ptr FCB1[0],2 ; FCB1[0] = 2;
  189. mov ax,wShow ; FCB1[1] = wShow;
  190. mov word ptr FCB1[2],ax
  191. xor ax,ax
  192. mov loadparams.envseg,ax ; loadparms.segEnv = 0;
  193. mov loadparams.lpfcb2.lo,ax ; loadparms.lpFCB2 = (LPSTR)NULL;
  194. mov loadparams.lpfcb2.hi,ax
  195. mov ax,pszParm ; loadparms.lpCmdLine = (LPSTR)pszParm;
  196. mov loadparams.lpCmdLine.lo,ax
  197. mov loadparams.lpCmdLine.hi,ss
  198. lea ax,FCB1 ; loadparms.lpFCB1 = (LPSTR)fcb1buf;
  199. mov loadparams.lpfcb1.lo,ax
  200. mov loadparams.lpfcb1.hi,ss
  201. ; Exec the progam.
  202. smov ds,ss
  203. lea dx,szCmdLine ; ds:ax == ptr to file to exec
  204. lea bx,loadparams ; es:bx == ptr to param block
  205. mov ax,4B00h ; dos exec
  206. int 21h
  207. WinExecEnvExit:
  208. cEnd
  209. ;**************************************************************************
  210. ; RegisterWinoldapHook(Addr,Opcode):
  211. ;
  212. ; Description: (Opcode == 1) => hook, (Opcode == 0) => unhook.
  213. ; Addr is a ptr to struct of the form WinoldapHookList
  214. ; struct WinoldapHookList { struct WinoldapHookList *ptr; DWORD Hook;};
  215. ;**************************************************************************
  216. cProc RegisterWinoldapHook,<FAR,PUBLIC,PASCAL>,<ds,es,di,si,dx>
  217. parmD Address
  218. parmB Opcode
  219. cBegin
  220. SetKernelDSNRes ; set kernel's DS
  221. mov ax, WinFlags
  222. test ax, WF_STANDARD
  223. mov ax,0
  224. jz RWH_Call
  225. lea si,WinAppHooks
  226. les di,Address
  227. cmp Opcode,0 ; unhook ?
  228. jz RWH_Unhook
  229. RWH_Exchange:
  230. mov ax,ds:[si] ; old
  231. mov es:[di],ax ; next of new
  232. mov ax,ds:[si+2]
  233. mov es:[di+2],ax ; next set
  234. mov ds:[si],di
  235. mov di,es
  236. mov ds:[si+2],di ; new one becomes first
  237. mov ax,1
  238. jmp SHORT RWH_Call
  239. RWH_Unhook:
  240. mov dx,es
  241. RWH_Compare:
  242. cmp di,ds:[si]
  243. jnz RWH_Nexthook
  244. cmp dx,ds:[si+2]
  245. jnz RWH_NextHook
  246. mov ax,es:[di]
  247. mov ds:[si],ax
  248. mov ax,es:[di+2]
  249. mov ds:[si+2],ax
  250. mov ax,1
  251. jmp SHORT RWH_Call
  252. RWH_NextHook:
  253. lds si,ds:[si]
  254. mov ax,ds
  255. or ax,si
  256. jnz short RWH_Compare
  257. RWH_Call:
  258. UnSetKernelDS ; unset it
  259. cEnd
  260. ;**********************************************************************
  261. ;
  262. ; GetWinoldapHooks:
  263. ; Description: Called exclusively by winoldap to get a pointer to a list
  264. ; of WinoldapHookList.
  265. ; Entry: None
  266. ; EXIT: DX:AX -> WinoldapHookList...
  267. ; USES: Flags.
  268. ;**********************************************************************
  269. cProc GetWinoldapHooks,<FAR,PUBLIC,PASCAL>,<ds,si>
  270. cBegin
  271. SetKernelDSNRes ; set kernel DS
  272. lea si,WinAppHooks
  273. mov ax, word ptr ds:[si]
  274. mov dx, word ptr ds:[si+2]
  275. UnSetKernelDS ; unset it
  276. cEnd
  277. sEnd NRESCODE
  278. end