

                                             ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
                                             ³ Xine - issue #5 - Phile 305 ³
                                             ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ





ÚÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ VxD Packer2 ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ

  This utility is basically the same as "VxD Packer". The only difference is
that instead of "cutting", whenever possible, the space between the end of
the "Fixup Record Table" and the beginning of the "Enumerated Data Pages",
it "cuts" the unused space between the end of the MZ header and the start of
the LE header. This space usually contains real-mode code to display a mes-
sage like "This program cannot be run in DOS mode." and never gets executed
unless the file is renamed to an EXE extension and then run. It is only pre-
sent for compatibility.

ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ 1. Assembling and compiling ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

Compile it to a COM file, using:
tasm vxdpack2 /ml /m5
tlink vxdpack2 /t

ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ Start of file: VXDPACK2.ASM ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
                .Model  Tiny
                .Code
                .386

                include DOS.INC
                include MZ.INC
                include LE.INC

                .Radix  16d
                org     (size PSP)

Max_Size        =       0f000h

Start:
                mov     ah,9
                mov     dx,offset Intro_Text
                int     21 ;Display introductory text
                mov     bx,PSP_CommandLine
                cmp     byte ptr ds:[bx.CT_Length],0
                jne     Valid_File
                mov     dx,offset Usage_Text
                jmp     Exit_Disp ;Display syntax
Valid_File:
                inc     bx ;Same as: add bx,CT_Arguments
                cmp     byte ptr ds:[bx],' '
                je      Valid_File
                mov     dx,bx
Seek_End:
                inc     bx
                cmp     byte ptr ds:[bx],0dh
                jne     Seek_End
                mov     byte ptr ds:[bx],0
                mov     ax,3d02h
                int     21 ;Open the file (read/write mode)
                jnc     Proceed1
IO_Error:
                mov     dx,offset Fail_IO
                jmp     Exit_Disp ;Report error
Proceed1:
                mov     word ptr ds:[File_Handle],ax
                mov     al,2
                call    Seek_AL
                or      dx,dx
                jz      Proceed2
Too_Big:
                mov     ah,3eh
                call    File_Int ;Close the file
                jmp     IO_Error
Proceed2:
                cmp     ax,Max_Size
                ja      Too_Big
                mov     word ptr ds:[File_Size],ax
                push    ax
                call    Seek_Begin
                pop     cx
                mov     ah,3fh
                mov     dx,offset Buffer
                int     21 ;Read file to buffer
                mov     bx,dx
                cmp     word ptr ds:[bx.MZ_magic],IMAGE_DOS_SIGNATURE
                jne     Too_Big
                cmp     word ptr ds:[bx.MZ_lfarlc],IMAGE_SIZEOF_DOS_HEADER
                jb      Too_Big
                mov     bp,bx
                add     bx,word ptr ds:[bx.MZ_lfanew]
                cmp     word ptr ds:[bx.LE_magic],IMAGE_VXD_SIGNATURE
                jne     Too_Big
                cmp     word ptr ds:[bx.LE_dircnt],0
                jne     Too_Big
                mov     si,bx
                mov     di,(offset Buffer)+IMAGE_SIZEOF_DOS_HEADER
                mov     ax,si
                sub     ax,di
                jz      Too_Big
                mov     cx,word ptr ds:[File_Size]
                sub     cx,word ptr ds:[bp.MZ_lfanew]
                mov     word ptr ds:[bp.MZ_lfanew],IMAGE_SIZEOF_DOS_HEADER
                sub     word ptr ds:[File_Size],ax ;Fix file size
                sub     word ptr ds:[bx.LE_datapage],ax ;Fix "Offset of Enumerated Data Pages"
                mov     bp,LE_nrestab ;Fix "Offset of Non-resident Names Table"
                call    Fix_If_Not_Null
                mov     bp,LE_debuginfo ;Fix "Offset of the debugging information"
                call    Fix_If_Not_Null
                mov     bp,LE_winresoff ;Fix "Offset of Windows Resources"
                call    Fix_If_Not_Null
                cld
                rep     movsb ;Shift data to pack the file
                call    Seek_Begin
                mov     ah,40
                mov     cx,word ptr ds:[File_Size]
                mov     dx,offset Buffer
                int     21 ;Write packed file
                mov     ah,40
                xor     cx,cx
                int     21 ;Mark end of file
                mov     ah,3eh
                int     21 ;Close it
                mov     dx,offset Success ;Report success
Exit_Disp:
                mov     ah,9
                int     21
                mov     ah,4ch
                int     21 ;Terminate program

;Routines
Seek_Begin: ;Reset file position
                mov     al,0
Seek_AL:
                mov     ah,42
                xor     cx,cx
                cwd
File_Int:
                mov     bx,word ptr ds:[File_Handle]
                int     21
                retn

Fix_If_Not_Null:
                push    bx
                add     bx,bp
                cmp     word ptr ds:[bx],0
                je      Null
                sub     word ptr ds:[bx],ax
Null:
                pop     bx
                retn

;Messages and data
Intro_Text      db      "VxD Packer2 by Horned Beast/VADER",0dh,0ah
                db      "E-mail: hbeast@darkmail.com",0dh,0ah,0dh,0ah,'$'
Usage_Text      db      "Usage: VXDPACK2.COM (VxDFile)",0dh,0ah,'$'
Fail_IO         db      "Failure in file I/O!",0dh,0ah,'$'
Success         db      "File packed!",0dh,0ah,'$'
File_Handle     dw      ?
File_Size       dw      ?

Buffer:

                end     Start
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ End of file: VXDPACK2.ASM ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
