⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 le23p.asm

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 ASM
📖 第 1 页 / 共 3 页
字号:
        mov     ecx,size NewHeaderStruc
        calls   WriteFile,ebx,edx,ecx
        cmp     eax,-1
        mov     ErrorNumber,8
        jz      @@9
        cmp     eax,ecx
        jnz     @@9
        ;
        ;Write the segment definitions.
        ;
        mov     esi,ObjectList  ;Point to the segment list.
        mov     ebp,[esi]               ;Get number of entries.
        add     esi,4
@@0:    mov     edx,esi         ;Point to segment defintion.
        mov     ecx,4+4
        calls   WriteFile,ebx,edx,ecx           ;Write this entry.
        cmp     eax,-1
        mov     ErrorNumber,8
        jz      @@9
        cmp     eax,ecx
        jnz     @@9
        add     esi,size _Seg_  ;Next entry.
        dec     ebp
        jnz     @@0             ;Do all segments.
        ;
        ;Write the relocation entries.
        ;
        mov     esi,RelocationList
        or      esi,esi
        jz      @@1
        mov     ecx,[esi]               ;Get number of entries.
        shl     ecx,2           ;Dword per entry.
        add     esi,4
        mov     edx,esi         ;Point to data.
        calls   WriteFile,ebx,edx,ecx
        cmp     eax,-1
        mov     ErrorNumber,8
        jz      @@9
        cmp     eax,ecx
        jnz     @@9
        ;
@@1:    ;Write the EXE image.
        ;
        mov     esi,ObjectList  ;Point to object definitions.
        mov     ebp,[esi]               ;Get number of entries.
        add     esi,4           ;Point to real data.
@@2:    mov     ecx,Seg_Length[esi]     ;Get segments length.
        mov     edx,Seg_Memory[esi]     ;point to segments image.
        calls   WriteFile,ebx,edx,ecx
        cmp     eax,-1
        mov     ErrorNumber,8
        jz      @@9
        cmp     eax,ecx
        jnz     @@9
        add     esi,size _Seg_  ;point to next entry.
        dec     ebp
        jnz     @@2             ;Do all entries.
        ;
        ;Close the output file.
        ;
        calls   CloseFile,ebx
        clc
        ret
        ;
@@9:    stc
        ret
Write3PFile     endp


;------------------------------------------------------------------------------
;
;Create 3P header data.
;
Create3PHeader  proc    near
        mov     esi,offset BuildHeaderText
        calls   PrintString,esi
        ;
        mov     edi,offset RealHeader
        ;
        ;Set auto DS object number if there is one.
        ;
        mov     esi,LEAddress
        mov     eax,[esi+94h]
        mov     NewAutoDS[edi],ax
        ;
        ;Set number of segments and increase file length field.
        ;
        mov     esi,ObjectList
        mov     eax,[esi]               ;Get number of segments.
        mov     NewSegments[edi],ax
        shl     eax,3           ;8 bytes per seg.
        mov     NewSize[edi],eax
        ;
        ;Set number of relocations and increase file length field.
        ;
        mov     esi,RelocationList
        xor     eax,eax
        or      esi,esi
        jz      @@0
        mov     eax,[esi]
@@0:    mov     NewRelocs[edi],eax
        shl     eax,2           ;4 bytes per entry.
        add     NewSize[edi],eax
        ;
        ;Set EXE image length and increase file length field.
        ;
        mov     eax,SegmentBase ;This is now total length.
        mov     NewLength[edi],eax
        mov     NewAlloc[edi],eax
        add     NewSize[edi],eax
        ;
        ;Include header in length field.
        ;
        add     NewSize[edi],size NewHeaderStruc
        ;
        ;Set entry CS:EIP
        ;
        mov     esi,LEAddress
        mov     eax,[esi+18h]   ;CS object number.
        dec     eax
        mov     NewEntryCS[edi],ax
        mov     eax,[esi+1Ch]   ;EIP value.
        mov     NewEntryEIP[edi],eax
        ;
        ;Set entry SS:ESP
        ;
        mov     esi,LEAddress
        mov     eax,[esi+20h]   ;SS object number.
        dec     eax
        mov     NewEntrySS[edi],ax
        mov     eax,[esi+24h]   ;ESP value.
        mov     NewEntryESP[edi],eax
        ;
        clc
        ret
Create3PHeader  endp


;------------------------------------------------------------------------------
;
;Create 3P version of LE file in memory.
;
Create3PFile    proc    near
        mov     esi,offset BuildImageText
        calls   PrintString,esi
IFDEF DEBUG2
;       int     3
ENDIF
        ;
        mov     esi,LEAddress
        mov     ecx,[esi+44h]   ;Get number of Objects.
        add     esi,[esi+40h]   ;Point to object table.
        mov     ObjectCount,ecx
        mov     ObjectBase,esi
        ;
@@0:    cmp     ObjectList,0            ;Started object list yet?
        jnz     @@0_0
        mov     ecx,4
        callc   Malloc,ecx
        mov     esi,eax
        or      eax,eax
        mov     ErrorNumber,6
        jz      @@9
        mov     ObjectList,esi
        mov     d[esi],0
@@0_0:  mov     esi,ObjectList
        mov     eax,[esi]               ;Get number of entries.
        inc     eax
        mov     edx,size _Seg_
        mul     edx
        add     eax,4
        mov     ecx,eax
        callc   ReAlloc,esi,ecx         ;Enlarge it.
        mov     esi,eax
        or      eax,eax
        mov     ErrorNumber,6
        jz      @@9
        mov     ObjectList,esi
        inc     d[esi]
        add     esi,ecx
        sub     esi,size _Seg_  ;Point to new entry.
        mov     edi,esi
        mov     ecx,size _Seg_
        xor     al,al
        rep     stosb           ;Clear it out.
        mov     edi,esi
        ;
        mov     eax,SegmentBase
        mov     Seg_BaseAddress[edi],eax
        mov     esi,ObjectBase
        mov     ecx,[esi]               ;Get segments size.
        add     ecx,4095
        and     ecx,not 4095            ;page align it
        add     SegmentBase,ecx
        mov     Seg_Length[edi],ecx     ;Set segments size.
        ;
        callc   Malloc,ecx
        mov     esi,eax
        or      eax,eax
        mov     ErrorNumber,6
        jz      @@9
        mov     Seg_Memory[edi],esi     ;Store segments address.
        pushs   eax,ecx,edi
        mov     edi,esi
        xor     al,al
        rep     stosb
        pops    eax,ecx,edi
        ;
        mov     esi,ObjectBase
        mov     eax,[esi+08h]   ;Get objects flags.
        xor     ebx,ebx
        test    eax,4           ;Executable?
        jnz     @@1
        inc     ebx             ;Make it Data.
        test    eax,2           ;Writeable?
        jz      @@1
;       add     ebx,2           ;Read only data.
@@1:
;       shl     ebx,24
        shl     ebx,21          ; MED, 01/22/96

        test    eax,2000h               ;Big bit set?
        jz      @@2
        or      ebx,1 shl 26            ;Force 32-bit.
        jmp     @@3
@@2:    or      ebx,1 shl 25            ;Force 16-bit.
@@3:    mov     eax,Seg_Length[edi]
        cmp     eax,100000h             ;>1M?
        jc      @@4
        shr     eax,12
        or      eax,1 shl 20
@@4:
        or      ebx,eax         ;Include length.

; MED 01/23/96
        test    WORD PTR [esi+08h],2000h        ; check if D/B bit set
        je      med2            ; not set, don't mark segment as flat

        or      ebx,1 shl 27            ;mark target type

med2:
        mov     Seg_Type[edi],ebx       ;Store the 3P type.
        ;
        mov     esi,ObjectBase
        mov     ecx,[esi+10h]   ;Get number of pages.

; MED 09/06/97
        test    ecx,ecx
        je      mednextobj              ; no pages to process

        mov     edx,[esi+0Ch]   ;Get page table index.
        mov     ebp,Seg_Length[edi]     ;Get maximum length again.
        mov     edi,Seg_Memory[edi]     ;Point to segments memory.
        mov     ebx,LEAddress
        add     ebx,[ebx+80h]
        sub     ebx,LEOffset
        ;
@@5:    mov     eax,edx         ;Get page number.
        dec     eax             ;make it base 0.
        shl     eax,12          ;*4096.
        add     eax,ebx         ;Make offset from data pages.
        mov     esi,eax
        ;
        mov     eax,4096                ;Default page size.
@@6:    cmp     ebp,eax         ;Want whole page?
        jnc     @@7
        mov     eax,ebp         ;Force smaller value.
@@7:    push    ecx
        mov     ecx,eax         ;Get length to copy.

;       rep     movsb           ;Copy this page.
        push    ecx
        shr     ecx,2
        rep     movsd
        pop     ecx
        and     ecx,3
        rep     movsb

        pop     ecx
        sub     ebp,eax         ;Update length remaining.
        inc     edx             ;Next page index.

;; MED 09/06/97
;       test    ecx,ecx
;       je      mednextobj              ; no pages to process

        dec     ecx
        jnz     @@6             ;Get all pages.
        ;

mednextobj:
        add     ObjectBase,18h  ;Next object
        dec     ObjectCount
        jnz     @@0             ;Do all objects.
        ;
        clc
        ret
        ;
@@9:    stc
        ret
Create3PFile    endp


;------------------------------------------------------------------------------
;
;Fetch the specified LE file, just the LE bit not its stub.
;
FetchLEFile     proc    near

IFDEF DEBUG
        push    eax
        push    ebx
        push    ecx
        push    edx
        push    ds
        mov     edx,OFFSET debug9
        mov     ecx,SIZEOF debug9
        mov     ebx,1
        mov     ah,40h
        int     21h
        jmp     med9
debug9  DB      'In Fetch...',13,10
med9:
        pop     ds
        pop     edx
        pop     ecx
        pop     ebx
        pop     eax
ENDIF

        mov     esi,offset ReadingLEText
        calls   PrintString,esi
        ;
        mov     edx,OptionPointers
        calls   OpenFile,edx,0
        mov     ebx,eax
        or      eax,eax
        mov     ErrorNumber,2
        jz      @@9
        mov     ecx,3ch
        xor     al,al
        calls   SeekFile,ebx,ecx,0      ;Move to the LE bit.
        push    edx
        mov     edx,esp
        mov     ecx,4
        calls   ReadFile,ebx,edx,ecx            ;Read offset to LE.
        pop     edx
        mov     LEOffset,edx
        mov     ErrorNumber,3
        cmp     eax,-1
        jz      @@9
        cmp     eax,ecx
        jnz     @@9
        xor     ecx,ecx
        mov     al,2
        calls   SeekFile,ebx,ecx,2      ;Get file length.
        mov     ecx,eax
        sub     ecx,edx         ;Lose stub section from length.
        xchg    ecx,edx
        xor     al,al
        calls   SeekFile,ebx,ecx,0      ;Point to LE section.
        mov     ecx,eax
        xchg    ecx,edx
        push    ecx

;       add     ecx,4095
        add     ecx,4095+4096

        and     ecx,not 4095

        calls   Malloc,ecx              ;Get memory for the file.

        mov     esi,eax
        or      eax,eax
        pop     ecx
        mov     ErrorNumber,4
        jz      @@9
        pushs   eax,ecx,edi

;       add     ecx,4095
        add     ecx,4095+4096

        and     ecx,not 4095
        mov     edi,esi

;       xor     al,al
;       rep     stosb
        xor     eax,eax
        push    ecx
        shr     ecx,2
        rep     stosd
        pop     ecx
        and     ecx,3
        rep     stosb

        pops    eax,ecx,edi
        mov     edx,esi
        calls   ReadFile,ebx,edx,ecx            ;Read the file.
        cmp     eax,-1
        mov     ErrorNumber,5
        jz      @@9
        cmp     eax,ecx
        jnz     @@9
        calls   CloseFile,ebx   ;Close the file again.
        ;
        mov     LEAddress,esi   ;Store LE files address.
        mov     LELength,ecx            ;Store its length as well.
        clc
        ret
        ;
@@9:    stc
        ret
FetchLEFile     endp


        .data

Copyright       db 13
        db 79 dup ("

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -