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.

429 lines
7.0 KiB

  1. FindStruc struc
  2. db 21 dup (?) ;reserved area
  3. Attr db ? ;attribute of file
  4. Time dw ? ;time of last write
  5. Date dw ? ;date of last write
  6. Fsize dd ? ;filesize
  7. Fname db 13 dup (?) ;filename
  8. FindStruc ends
  9. CMDSIZE equ 94h ;current resident size of
  10. ;command.com is 94h paras
  11. code segment byte public 'CODE'
  12. assume cs:code, ds:code, es:code
  13. org 100h
  14. public start
  15. start:
  16. mov sp,offset MyStack ;set ss:sp to our stack
  17. mov ax,offset EndProg
  18. add ax,15
  19. mov cl,4
  20. shr ax,cl ;para size of this program
  21. mov bx,ax ;bx = this program's size
  22. mov cx,es
  23. add ax,cx ;ax = top of this program
  24. sub ax,1000h - CMDSIZE ;are we below the first 64K?
  25. jae no_mem ;no, dont reserve memory
  26. neg ax ;additional memory to be reserved
  27. add bx,ax
  28. no_mem: ;bx = #paras needed
  29. mov ah,4ah
  30. int 21h ;resize to desired size
  31. ;
  32. ;Prepare to execute the desired program
  33. ;
  34. call Exec_prepare
  35. jnc do_exec
  36. mov al,1 ;return error
  37. jmp short exit
  38. do_exec:
  39. cmp helpflg,1
  40. je do_help
  41. mov ah,4bh
  42. mov dx,offset ExecPath
  43. mov bx,offset ExecBlk
  44. int 21h ;do the Exec
  45. jc exec_err ;error while executing
  46. ;
  47. ;No error on execution. Get the return code of the program we executed and
  48. ;return that as our return code.
  49. ;
  50. mov ah,4dh
  51. int 21h ;al = return code now
  52. exit:
  53. mov ah,4ch
  54. int 21h ;terminate ourselves
  55. exec_err:
  56. mov dx,offset ErrMsg ;Error executing command.com
  57. ifdef BILINGUAL
  58. call IsDBCSCodePage
  59. jz @f
  60. mov dx,offset ErrMsg2
  61. @@:
  62. endif
  63. mov al,1
  64. call dispmsg
  65. jmp short exit
  66. do_help:
  67. mov dx,offset HelpMsg ;Display help for loadfix
  68. ifdef BILINGUAL
  69. call IsDBCSCodePage
  70. jz @f
  71. mov dx,offset HelpMsg2
  72. @@:
  73. endif
  74. call dispmsg
  75. xor al,al
  76. jmp short exit
  77. ;***
  78. ;Dispmsg -- Displays messages that are terminated by '$'
  79. ;
  80. ;Input: ds:dx = pointer to message
  81. ;
  82. ;Output: None
  83. ;
  84. ;Registers: ax
  85. ;***
  86. dispmsg proc near
  87. mov ah,9
  88. int 21h
  89. ret
  90. dispmsg endp
  91. ;***
  92. ;Exec_prepare -- Searches the environment for the COMSPEC and sets up the
  93. ;command line and FCBs for the Exec call
  94. ;
  95. ;Input: None
  96. ;
  97. ;Output: Carry set => error. Error message is displayed here
  98. ; Carry clear => all parameters set successfully
  99. ;
  100. ;Registers: ax, cx, dx, si, di
  101. ;***
  102. Exec_prepare proc near
  103. push ds
  104. push es
  105. mov si,81h ;ds:si points at our command line
  106. call skip_white ;skip all leading whitespace
  107. cmp byte ptr [si],0dh ;Did we hit a CR?
  108. je no_parms ;yes, no parameters given
  109. ;
  110. ;Check if we have a /? here
  111. ;
  112. cmp byte ptr [si],'/'
  113. jne no_help
  114. cmp byte ptr [si+1],'?'
  115. jne no_help
  116. inc helpflg ;/? given -- print help
  117. jmp short exefnd
  118. no_help:
  119. mov dx,si ;ds:dx now points at the program
  120. mov si,offset CmdOpt
  121. mov di,offset CmdParms
  122. inc di
  123. mov cl,CmdOptLen
  124. xor ch,ch
  125. rep movsb
  126. mov si,dx
  127. xor cx,cx
  128. st_lp:
  129. lodsb
  130. stosb
  131. inc cx
  132. cmp al,0dh
  133. jne st_lp
  134. dec cx
  135. add cl,CmdOptLen ;command line cannot be >128
  136. mov CmdParms,cl
  137. mov si,offset CmdParms
  138. mov word ptr CmdPtr,si
  139. mov word ptr CmdPtr+2,cs ;store command line pointer
  140. mov word ptr Fcb1+2,cs
  141. mov word ptr Fcb2+2,cs
  142. call find_comspec
  143. jc no_comspec
  144. mov si,offset ExecPath
  145. xchg si,di
  146. push ds
  147. push es
  148. pop ds
  149. pop es
  150. comspec_lp:
  151. lodsb
  152. stosb
  153. or al,al
  154. jnz comspec_lp
  155. exefnd:
  156. clc
  157. execp_ret:
  158. pop es
  159. pop ds
  160. ret
  161. no_parms:
  162. mov dx,offset NoParms
  163. ifdef BILINGUAL
  164. call IsDBCSCodePage
  165. jz @f
  166. mov dx,offset NoParms2
  167. @@:
  168. endif
  169. call dispmsg
  170. stc
  171. jmp short execp_ret
  172. no_comspec:
  173. mov dx,offset NoComspec
  174. ifdef BILINGUAL
  175. call IsDBCSCodePage
  176. jz @f
  177. mov dx,offset NoComspec2
  178. @@:
  179. endif
  180. call dispmsg
  181. stc
  182. jmp short execp_ret
  183. Exec_prepare endp
  184. ;***
  185. ;skip_white -- Skips all whitespace characters until it hits a non-whitespace
  186. ;
  187. ;Input: ds:si = string to be looked at
  188. ;
  189. ;Output: ds:si points at the first non-whitespace char in the string
  190. ;
  191. ;Registers: ax, si
  192. ;***
  193. skip_white proc near
  194. lodsb
  195. cmp al,20h ;Blank?
  196. je skip_white ;yes, skip
  197. cmp al,9 ;Tab?
  198. je skip_white ;yes, skip
  199. dec si ;point at the first non-white
  200. ret
  201. skip_white endp
  202. ;***
  203. ;find_comspec -- searches in the environment for the COMSPEC variable
  204. ;
  205. ;Input: None
  206. ;
  207. ;Output: es:di points at the arguments of the COMSPEC= variable
  208. ;
  209. ;Registers: si
  210. ;***
  211. find_comspec proc near
  212. mov si,offset Comspec_Text
  213. ;
  214. ; input: ds:si points to a "=" terminated string
  215. ; output: es:di points to the arguments in the environment
  216. ; zero is set if name not found
  217. ; carry flag is set if name not valid format
  218. ;
  219. call find ; find the name
  220. jc done_findp ; carry means not found
  221. call scasb1 ; scan for = sign
  222. done_findp:
  223. ret
  224. find_comspec endp
  225. ;***
  226. ;find -- scans the environment for the variable whose name is passed in
  227. ;
  228. ;Input: ds:si points at the environment variable to be scanned for
  229. ;
  230. ;Output: es:di points at the environment variable
  231. ;
  232. ;Registers: ax, di
  233. ;***
  234. find proc near
  235. cld
  236. call count0 ; cx = length of name
  237. mov es,es:[2ch] ; get environment segment
  238. ;
  239. ;Bugbug: What if the environment segment here is 0?
  240. ;
  241. xor di,di
  242. find1:
  243. push cx
  244. push si
  245. push di
  246. find11:
  247. lodsb
  248. inc di
  249. cmp al,es:[di-1]
  250. jnz find12
  251. loop find11
  252. find12:
  253. pop di
  254. pop si
  255. pop cx
  256. jz end_find
  257. push cx
  258. call scasb2 ; scan for a nul
  259. pop cx
  260. cmp byte ptr es:[di],0
  261. jnz find1
  262. stc ; indicate not found
  263. end_find:
  264. ret
  265. find endp
  266. ;***
  267. ;count0 -- returns length of string until the first '=' char
  268. ;
  269. ;Input: ds:si points at the string
  270. ;
  271. ;Output: cx = length until '='
  272. ;
  273. ;Registers: di
  274. ;***
  275. count0 proc near
  276. mov di,si ;ds = es = cs
  277. push di ; count number of chars until "="
  278. call scasb1
  279. pop cx
  280. sub di,cx
  281. xchg di,cx
  282. ret
  283. count0 endp
  284. ;***
  285. ;scasb1 -- scans string for the first '='
  286. ;scasb2 -- scans string for the first null
  287. ;
  288. ;Input: es:di = string
  289. ;
  290. ;Output: es:di points after the desired char
  291. ;
  292. ;Registers: ax, cx
  293. ;***
  294. scasb1 proc near
  295. mov al,'=' ; scan for an =
  296. jmp short scasbx
  297. scasb2:
  298. xor al,al ; scan for a nul
  299. scasbx:
  300. mov cx,100h
  301. repnz scasb
  302. ret
  303. scasb1 endp
  304. ifdef BILINGUAL
  305. IsDBCSCodePage proc near
  306. push ax
  307. push bx
  308. mov ax,4f01h ; get code page
  309. xor bx,bx
  310. int 2fh
  311. ifdef JAPAN
  312. cmp bx,932
  313. endif
  314. ifdef KOREA
  315. cmp bx,949
  316. endif
  317. ifdef TAIWAN
  318. cmp bx,950
  319. endif
  320. ifdef PRC
  321. cmp bx,936
  322. endif
  323. pop bx
  324. pop ax
  325. ret
  326. IsDBCSCodePage endp
  327. endif
  328. ;**************************
  329. ;Data
  330. ;**************************
  331. ExecBlk label word
  332. dw 0
  333. CmdPtr dd ?
  334. Fcb1 dw offset MyFcb1
  335. dw ?
  336. Fcb2 dw offset MyFcb2
  337. dw ?
  338. dw 128 dup (1)
  339. MyStack label word
  340. CmdOpt db '/C '
  341. CmdOptLen db $ - CmdOpt
  342. CmdParms db 128 dup (?) ;buffer to hold prog to be Exec'ed
  343. ExecPath db 67 dup (?) ;holds path to COMMAND.COM
  344. ComSpec_Text db 'COMSPEC=',0
  345. MyFcb1 db 0
  346. db 11 dup (' ')
  347. MyFcb2 db 0
  348. db 11 dup (' ')
  349. Helpflg db 0 ;default is no help
  350. include loadmsg.msg
  351. EndProg label byte
  352. code ends
  353. end start
  354.