[214] | 1 | ; $Id: ldstub-nasm.asm 3665 2010-09-17 00:56:18Z bird $
|
---|
| 2 | ;
|
---|
[3664] | 3 | ; Micro stub for <app> -> <app>.exe forwarding, nasm version.
|
---|
[214] | 4 | ;
|
---|
| 5 | ; Build Instructions:
|
---|
| 6 | ; Stantard version:
|
---|
[3664] | 7 | ; nasm -f obj -o ldstub-nasm.o ldstub-nasm.asm
|
---|
| 8 | ; ilink /pmtype:vio /ALIGN:1 /OUT:ldstub.bin ldstub-nasm.obj ldstub.def os2386.lib
|
---|
[214] | 9 | ;
|
---|
| 10 | ; OVERLAY may be defined for execv()/spawnv(OVERLAY,..) is to be emulated.
|
---|
| 11 | ;
|
---|
| 12 | ; InnoTek Systemberatung GmbH Confidential
|
---|
| 13 | ;
|
---|
| 14 | ; Copyright (c) 2003 InnoTek Systemberatung GmbH
|
---|
| 15 | ; Author: knut st. osmundsen <bird@anduin.net>
|
---|
| 16 | ;
|
---|
| 17 | ; All Rights Reserved
|
---|
| 18 | ;
|
---|
| 19 | ;
|
---|
| 20 |
|
---|
| 21 |
|
---|
| 22 | ;*******************************************************************************
|
---|
[3664] | 23 | ;* Global Variables *
|
---|
[214] | 24 | ;*******************************************************************************
|
---|
[3664] | 25 | extern DosExecPgm
|
---|
| 26 | extern DosQueryModuleName
|
---|
[214] | 27 |
|
---|
| 28 |
|
---|
[3664] | 29 | ;*******************************************************************************
|
---|
| 30 | ;* Segment definitions *
|
---|
| 31 | ;*******************************************************************************
|
---|
| 32 | segment TEXT32 public align=1 use32 FLAT class=CODE FLAT
|
---|
| 33 | segment STACK32 stack align=16 use32 class=STACK FLAT
|
---|
[214] | 34 |
|
---|
| 35 |
|
---|
[3664] | 36 | ;*******************************************************************************
|
---|
| 37 | ;* Structures and Typedefs *
|
---|
| 38 | ;*******************************************************************************
|
---|
| 39 | segment TEXT32 ; works around warning and dummy 'text' segment.
|
---|
| 40 | struc RESC
|
---|
| 41 | .codeTerminate resd 1
|
---|
| 42 | .codeResult resd 1
|
---|
| 43 | endstruc
|
---|
[214] | 44 |
|
---|
| 45 |
|
---|
| 46 | ; Program startup registers are defined as follows.
|
---|
| 47 | ; EIP = Starting program entry address.
|
---|
| 48 | ; ESP = Top of stack address.
|
---|
| 49 | ; CS = Code selector for base of linear address space.
|
---|
| 50 | ; DS = ES = SS = Data selector for base of linear address space.
|
---|
| 51 | ; FS = Data selector of base of Thread Information Block (TIB).
|
---|
| 52 | ; GS = 0.
|
---|
| 53 | ; EAX = EBX = 0.
|
---|
| 54 | ; ECX = EDX = 0.
|
---|
| 55 | ; ESI = EDI = 0.
|
---|
| 56 | ; EBP = 0.
|
---|
| 57 | ; [ESP+0] = Return address to routine which calls DosExit(1,EAX).
|
---|
| 58 | ; [ESP+4] = Module handle for program module.
|
---|
| 59 | ; [ESP+8] = Reserved.
|
---|
| 60 | ; [ESP+12] = Environment data object address.
|
---|
| 61 | ; [ESP+16] = Command line linear address in environment data object.
|
---|
| 62 | ;
|
---|
| 63 | ; @remark I don't care about cleaning up arguments as the leave does so.
|
---|
| 64 | ;
|
---|
[3664] | 65 | segment TEXT32
|
---|
[214] | 66 | start:
|
---|
[3664] | 67 | ..start:
|
---|
| 68 | BITS 32
|
---|
| 69 | enter 260 + 4 + RESC_size, 0
|
---|
[3665] | 70 | %define achNewExeName ebp - 260 - RESC_size - 4 ; == esp right now
|
---|
[3664] | 71 | %define res ebp - RESC_size
|
---|
[214] | 72 |
|
---|
| 73 | ;
|
---|
| 74 | ; Get the executable name.
|
---|
| 75 | ;
|
---|
| 76 | ; ULONG DosQueryModuleName(HMODULE hmod, ULONG ulNameLength, PCHAR pNameBuf);
|
---|
| 77 | ;
|
---|
[3665] | 78 | mov ebx, esp ; esp=achNewExeName
|
---|
[3664] | 79 | push ebx ; pNameBuf
|
---|
| 80 | push 260 ; ulNameLength
|
---|
| 81 | push dword [ebp+8] ; hmod
|
---|
[214] | 82 | call DosQueryModuleName
|
---|
| 83 | or eax, eax
|
---|
[3664] | 84 | jnz .exec_failed ; this ain't supposed to happen
|
---|
[214] | 85 |
|
---|
| 86 | ;
|
---|
| 87 | ; Append .EXE to the module name.
|
---|
| 88 | ;
|
---|
| 89 | xor ecx, ecx
|
---|
| 90 | dec ecx
|
---|
[3664] | 91 | mov edi, ebx ; achNewExeName
|
---|
[214] | 92 | repne scasb
|
---|
[3664] | 93 | mov dword [edi-1], 'EXE.'
|
---|
| 94 | mov dword [edi+3], esi ; esi = 0 at this point.
|
---|
[214] | 95 |
|
---|
| 96 | ;
|
---|
| 97 | ; Try execute the .EXE appended module name.
|
---|
| 98 | ;
|
---|
| 99 | ; APIRET APIENTRY DosExecPgm(PCHAR pObjname,
|
---|
| 100 | ; LONG cbObjname,
|
---|
| 101 | ; ULONG execFlag,
|
---|
| 102 | ; PCSZ pArg,
|
---|
| 103 | ; PCSZ pEnv,
|
---|
| 104 | ; PRESULTCODES pRes,
|
---|
| 105 | ; PCSZ pName);
|
---|
| 106 | ;
|
---|
[3664] | 107 | push ebx ; pName (achNewExeName)
|
---|
| 108 | lea edi, [res]
|
---|
| 109 | push edi ; pRes
|
---|
| 110 | push dword [ebp + 10h] ; pEnv
|
---|
| 111 | push dword [ebp + 14h] ; pArg
|
---|
| 112 | %ifdef OVERLAY
|
---|
[214] | 113 | push 1 ; execFlag = EXEC_ASYNC
|
---|
[3664] | 114 | %else
|
---|
| 115 | push esi ; execFlag = EXEC_SYNC = 0
|
---|
| 116 | %endif
|
---|
| 117 | push esi ; cbObjname
|
---|
| 118 | push esi ; pObjname
|
---|
[214] | 119 | call DosExecPgm
|
---|
| 120 | or eax, eax
|
---|
[3664] | 121 | jz .exec_success
|
---|
[214] | 122 |
|
---|
[3664] | 123 | .exec_failed:
|
---|
[3665] | 124 | mov eax, 07fh
|
---|
[3664] | 125 | jmp .done
|
---|
[214] | 126 |
|
---|
[3664] | 127 | .exec_success:
|
---|
| 128 | %ifndef OVERLAY
|
---|
[214] | 129 | ;
|
---|
| 130 | ; Retrieve the result code.
|
---|
| 131 | ;
|
---|
[3664] | 132 | mov eax, [res + RESC.codeResult]
|
---|
| 133 | cmp [res + RESC.codeTerminate], esi
|
---|
| 134 | jz .done
|
---|
[214] | 135 |
|
---|
| 136 | ;
|
---|
| 137 | ; Something bad happend and the result code is 0.
|
---|
| 138 | ; We shouldn't return 0 when we trap, crash or is killed.
|
---|
| 139 | ;
|
---|
[3665] | 140 | mov eax, 0ffh
|
---|
[3664] | 141 | %endif
|
---|
[214] | 142 |
|
---|
| 143 |
|
---|
[3664] | 144 | .done:
|
---|
[214] | 145 | leave
|
---|
[3664] | 146 | ret
|
---|
[214] | 147 |
|
---|
| 148 |
|
---|
[3664] | 149 | ; for emxomfld
|
---|
| 150 | ABSOLUTE 0
|
---|
| 151 | global WEAK$ZERO
|
---|
| 152 | WEAK$ZERO:
|
---|
| 153 |
|
---|