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.

222 lines
6.0 KiB

  1. PAGE 58,132
  2. ;******************************************************************************
  3. TITLE bwinexec.asm - WinExec with binary command line
  4. ;******************************************************************************
  5. ;
  6. ; Copyright (C) Microsoft Corporation 1985-1990. All rights reserved.
  7. ;
  8. ; Title: bwinexec.asm - Exec. an app. with a block of binary data.
  9. ;
  10. ; Version: 1.00
  11. ;
  12. ; Date: 14-Mar-1990 (from winexec)
  13. ;
  14. ; Author: ROBWI
  15. ;
  16. ;------------------------------------------------------------------------------
  17. ;
  18. ; Change log:
  19. ;
  20. ; DATE REV DESCRIPTION
  21. ; ----------- --- -----------------------------------------------------------
  22. ; 14-Mar-1990 RJW Modified Toddla's WinExec code to take a binary command
  23. ; block instead of an ascii command line
  24. ;
  25. ;==============================================================================
  26. ?PLM=1
  27. ?WIN=0
  28. PMODE=1
  29. .xlist
  30. include cmacros.inc
  31. include windows.inc
  32. .list
  33. externFP LoadModule
  34. EXECBLOCK struc
  35. envseg dw ? ; seg addr of environment
  36. lpcmdline dd ? ; pointer to command block (normally ascii str)
  37. lpfcb1 dd ? ; default fcb at 5C
  38. lpfcb2 dd ? ; default fcb at 6C
  39. EXECBLOCK ends
  40. ; The following structure should be used to access high and low
  41. ; words of a DWORD. This means that "word ptr foo[2]" -> "foo.hi".
  42. LONG struc
  43. lo dw ?
  44. hi dw ?
  45. LONG ends
  46. ifndef SEGNAME
  47. SEGNAME equ <_TEXT>
  48. endif
  49. createSeg %SEGNAME, CodeSeg, word, public, CODE
  50. sBegin CodeSeg
  51. assumes cs,CodeSeg
  52. assumes es,nothing
  53. assumes ds,nothing
  54. ;****************************************************************************
  55. ;
  56. ; @doc INTERNAL MMSYSTEMS
  57. ;
  58. ; @api HANDLE | BWinExec | This function executes the Windows
  59. ; or non-Windows application identified by the <p lpCmdLine>
  60. ; parameter. The <p nCmdShow> parameter specifies the initial
  61. ; state of the applications main window when it is created.
  62. ;
  63. ; @parm LPSTR | lpModuleName | Far pointer to a null-terminated
  64. ; character string that contains the filename of the
  65. ; application to run. See <f LoadModule> for more info.
  66. ;
  67. ; @parm WORD | nCmdShow | Specifies how the application is shown.
  68. ; See <f ShowWindow> for valid values.
  69. ;
  70. ; @parm LPVOID | lpParameters | Specifies a far pointer to a block
  71. ; of data which will be passed to the application as a cmd
  72. ; tail. The first byte of the block must be the length of the
  73. ; data and must be less than or equal to 120.
  74. ;
  75. ; @rdesc The return value identifies the instance of the loaded module if
  76. ; the function was successful. Otherwise, it is a value less than
  77. ; 32 that specifies the error. See <f LoadModule> for valid
  78. ; error values.
  79. ;
  80. ; @xref LoadModule WinExec
  81. ;
  82. ;============================================================================
  83. cProc BWinExec, <FAR,PUBLIC,NODATA>,<si,di>
  84. parmD lpszFile ; Pathname ptr
  85. parmW wShow ; Mode flag
  86. parmD lpParameters ; Cmd Line Data
  87. LocalV szCommand, 128 ; ASCIIZ Name of program to exec
  88. LocalV szParm, 128 ; DOS version of parameters
  89. LocalB szParmLen ; DOS parm length
  90. LocalB bDotFound ; Non-zero if a period is in the string
  91. LocalV loadparams, %(SIZE EXECBLOCK)
  92. LocalV rOF, %(SIZE OPENSTRUC)
  93. LocalD FCB1
  94. cBegin
  95. mov byte ptr szParm,0Dh
  96. mov szParmLen,0 ; Init to zero length, Line feed
  97. ; Copy first part of line into szCommand.
  98. lds si,lpszFile
  99. mov ax,ss
  100. mov es,ax
  101. lea di,szCommand
  102. xor al,al
  103. mov bDotFound,al
  104. ; Loop until a blank or NULL is found.
  105. WELoop1:
  106. lodsb
  107. cmp al,' ' ; Exit loop if blank or NULL
  108. je WECont1
  109. or al,al
  110. je WECont1
  111. cmp al,'.'
  112. jne WELoopCont
  113. mov bDotFound,al
  114. WELoopCont:
  115. stosb
  116. jmp short WELoop1
  117. WECont1:
  118. ; Does the command have an extension?
  119. cmp bDotFound,0
  120. jne WEHasExt
  121. mov ax,0452Eh ;'.E'
  122. stosw
  123. mov ax,04558h ;'XE'
  124. stosw
  125. WEHasExt:
  126. xor ax,ax ; NULL terminate string
  127. stosb
  128. lds si,lpParameters
  129. mov ax, ds
  130. or ax, si ; NULL Parameter block?
  131. jz WEExec ; Y: exec
  132. ; Copy Parameter Block into szParm.
  133. lea di, szParmLen
  134. lodsb
  135. xor cx,cx
  136. mov cl, al
  137. push dx ; truncate to legal length!
  138. mov ax, 78h
  139. sub ax, cx
  140. cwd
  141. and ax, dx
  142. add cx, ax ; length + 1 in cx
  143. pop dx
  144. mov al, cl
  145. stosb
  146. dec cx
  147. cld
  148. rep movsb
  149. ; Terminate it with a linefeed.
  150. mov al,0Dh
  151. stosb
  152. ; Set up the FCBs.
  153. WEExec:
  154. mov word ptr FCB1[0],2 ; FCB1[0] = 2;
  155. mov ax,wShow ; FCB1[1] = wShow;
  156. mov word ptr FCB1[2],ax
  157. xor ax,ax
  158. mov loadparams.envseg,ax ; loadparms.segEnv = 0;
  159. mov loadparams.lpfcb2.lo,ax ; loadparms.lpFCB2 = (LPSTR)NULL;
  160. mov loadparams.lpfcb2.hi,ax
  161. lea ax,szParmLen ; loadparms.lpCmdLine = (LPSTR)ach;
  162. mov loadparams.lpCmdLine.lo,ax
  163. mov loadparams.lpCmdLine.hi,ss
  164. lea ax,FCB1 ; loadparms.lpFCB1 = (LPSTR)fcb1buf;
  165. mov loadparams.lpfcb1.lo,ax
  166. mov loadparams.lpfcb1.hi,ss
  167. ; Exec the progam.
  168. lea dx,szCommand ; ds:ax == ptr to file to exec
  169. lea bx,loadparams ; es:bx == ptr to param block
  170. if 1
  171. cCall LoadModule, <ss,dx, ss,bx> ; return ax=hInstance, dx=hTask
  172. cmp ax,32
  173. jb @f
  174. mov ax,dx ; return hTask
  175. @@:
  176. else
  177. mov ax,ss
  178. mov ds,ax
  179. mov ax,4B00h ; dos exec
  180. int 21h
  181. endif
  182. cEnd
  183. sEnd CodeSeg
  184. end