home *** CD-ROM | disk | FTP | other *** search
/ CICA 1992 November / CICA_MS_Windows_CD-ROM_Walnut_Creek_November_1992.iso / win3 / util / autostub / autostub.asm next >
Assembly Source File  |  1992-07-08  |  5KB  |  150 lines

  1.     title    AUTOSTUB Version 1.2
  2.  
  3. ;Copyright (C) 1992 Steve Flynn, C-Scape Computing
  4.  
  5. ;This program is hereby donated to the Public Domain providing the line
  6. ;above copyright notice is left in tact.
  7.  
  8. ;You may use this hack for any purpose that you wish, but I do not warrant
  9. ;it to be suitable for ANY purpose at all. Use at your own risk. If it
  10. ;blows up in your face, I am not responsible and I dont want to know.
  11.  
  12. ;This is a replacement for WINSTUB.EXE which will auto load WINDOWS if the
  13. ;program using this stub is executed from the DOS command line.
  14.  
  15. ;The string searching is crude, but its fast and effective (like TYLENOL).
  16. ;Anyway, most of the code if thrown away when WIN.COM is loaded. Only
  17. ;enough is kept to throw away the rest of the program, load WIN.COM
  18. ;and return to DOS after WIN.COM.
  19.  
  20. ;I use the Borland C++ compiler and therefore TASM and TLINK.
  21. ;To assemble the program -
  22. ;    TASM AUTOSTUB
  23. ;    TLINK AUTOSTUB
  24. ;Thats all!
  25.  
  26. ;For Microsoft assembler it should be -
  27. ;    MASM AUTOSTUB;
  28. ;    LINK AUTOSTUB;
  29. ;But I have not tried it!
  30.  
  31. ;To use AUTOSTUB in your windows executables modify your .DEF files as follows
  32. ;Change the line
  33. ;    STUB    'WINSTUB.EXE'
  34. ;To
  35. ;    STUB    'AUTOSTUB.EXE'
  36. ;Or add this line if there is no STUB definition (which is often the case with
  37. ;the Borland products since the TLINK.EXE program knows how to add a WINSTUB
  38. ;all by itself).
  39.  
  40. ;Fixes:
  41. ;    V1.2    Fixed problem when WINDIR= was last entry in environment
  42. ;    V1.1    Fixed problem of incorrect path when WINDIR= was not found
  43. ;        in the environment
  44.  
  45.  
  46. msdos    equ    21h            ;MS-DOS function request interrupt
  47. envseg    equ    2ch            ;PSP offset of environent segment
  48. b    equ    byte ptr        ;I HATE byte ptr
  49. w    equ    word ptr        ;and word ptr
  50.  
  51. code    segment
  52.     assume    cs:code, ds:code, es:code, ss:code
  53.  
  54. path    db    '\WINDOWS', 120 dup (0)    ;path to WIN.COM
  55. cmdline    db    128 dup (0)        ;command line to pass
  56. param    dw    0            ;pass same environment to WIN.COM
  57.     dw    offset    cmdline
  58. seg1    dw    0
  59.     dw    5ch
  60. seg2    dw    0
  61.     dw    6ch
  62. seg3    dw    0
  63.  
  64. loadwin:mov    bx, offset start    ;last byte to keep
  65.     mov    cl,4
  66.     shr    bx,cl            ;convert to paragraphs
  67.     add    bx,17            ;allow for PSP, and round to next para
  68.     mov    es,bp            ;get PSP segment
  69.     mov    ah,4Ah            ;dealloc
  70.     int    msdos
  71.     push    ds
  72.     pop    es            ;find data again
  73.     lea    bx,param        ;es:bx = parameter block
  74.     lea    dx,path            ;ds:dx = path to WIN.COM
  75.     mov    ax,4B00h        ;spawn WIN.COM
  76.     int    msdos
  77.     mov    ah,4ch            ;terminate process
  78.     int    msdos            ;return code in AL
  79.  
  80. start:    push    cs
  81.     pop    ds            ;find the data
  82.     mov    bp,es            ;save PSP segment
  83.     mov    seg1,cs            ;save segment in parameter block
  84.     mov    seg2,cs
  85.     mov    seg3,cs
  86.  
  87. ;Search environment for "WINDIR="
  88.     mov    ax,es:[envseg]        ;get segment of environment
  89.     mov    ds,ax            ;find environment
  90.     push    cs
  91.     pop    es            ;find data
  92.     mov    si,-1h            ;set di just before environment
  93. dir1:    inc    si            ;point to next environment variable
  94.     cmp    b [si],'W'        ;test for start of WINDIR
  95.     je    dir3            ;found what looks like start
  96. dir2:    cmp    w [si],0        ;at end of environment yet
  97.     jz    envend            ;yes
  98.     cmp    b [si],0        ;end of variable statement
  99.     jz    dir1            ;found next variable
  100.     inc    si            ;try next character
  101.     jmp    dir2            ;keep looking
  102. dir3:    cmp    [si+1],4E49h        ;test for "IN"
  103.     jne    dir2            ;no match
  104.     cmp    [si+3],4944h        ;test for "DI"
  105.     jne    dir2            ;no match
  106.     cmp    [si+5],3D52h        ;test for "R="
  107.     jne    dir2            ;no match
  108.     add    si,7            ;found it, point to dir name
  109.     lea    di,path            ;where to copy it
  110. dir4:    lodsb                ;get character
  111.     or    al,al            ;is it end of directory name
  112.     jz    dir5            ;keep looking for end of environment
  113.     stosb                ;save character
  114.     jmp    dir4            ;copy whole name
  115. dir5:    dec    si            ;in case WINDIR= is at end of environment
  116.     jmp    dir2
  117.  
  118. ;By the time we are here -
  119. ;    si points to the end of the environment
  120. ;    di points to the end of the directory name for WIN.COM
  121. ;Now add "\WIN.COM" to directory name and get program name for
  122. ;WIN.COM to load, plus any command line arguments.
  123. envend:    cmp    di,offset path        ;was a path found
  124.     jnz    env1            ;yes
  125.     add    di,8            ;no, so point to end of default path
  126. env1:    mov    w es:[di],575Ch        ;add "\W"
  127.     mov    w es:[di+2],4E49h    ;add "IN"
  128.     mov    w es:[di+4],432Eh    ;add ".C"
  129.     mov    w es:[di+6],4D4Fh    ;add "OM"
  130.     add    si,4            ;point si to program name
  131.     lea    di,cmdline        ;command line to pass
  132.     inc    di            ;allow for command line size byte
  133. env2:    lodsb                ;get character
  134.     or    al,al            ;is it end of program name
  135.     jz    prgend            ;yes
  136.     stosb                ;save character
  137.     inc    b es:[cmdline]        ;count this character
  138.     jmp    env2            ;copy whole name
  139. ;Path to WIN.COM is now setup all that needs to be done is to
  140. ;delimit the command line, then throw away this crud and run WINDOWS.
  141. prgend:    push    es
  142.     pop    ds            ;find data
  143.     mov    w [di],0A0Dh        ;add carriage return linefeed
  144.     inc    b [cmdline]        ;count delimiter
  145.     inc    b [cmdline]
  146.     jmp    loadwin            ;now load WINDOWS
  147.  
  148. code    ends
  149.     end    start
  150.