Copy Link
Add to Bookmark
Report

Xine - issue #5 - Phile 304

eZine's profile picture
Published in 
Xine
 · 7 months ago

 

Ú-----------------------------¿
| Xine - issue #5 - Phile 304 |
À-----------------------------Ù





Ú------------¿
| VxD Packer |
À------------Á--------------------------------------------------------------

"VxD Packer" isn't exactly a packer since it doesn't use any compression
algorithm but I named it this way to avoid discrepancies about its purpose.
It simply "cuts", whenever possible, the space between the end of the "Fixup
Record Table" and the beginning of the "Enumerated Data Pages", thereby re-
ducing the size of the VxD. In order to retain a valid VxD, it then fixes
all pointers to nonresident data, starting from the "Enumerated Data Pages".
It is also limited to a maximum size of 0xF000.

Ú-----------------------------¿
| 1. Assembling and compiling |
À-----------------------------Ù

Compile it to a COM file, using:
tasm vxdpack /ml /m5
tlink vxdpack /t

-----------------------´ Start of file: VXDPACK.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
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_impmodcnt],0
jne Too_Big
cmp word ptr ds:[bx.LE_pagesum],0
jne Too_Big
cmp word ptr ds:[bx.LE_dircnt],0
jne Too_Big
mov di,bx
add di,word ptr ds:[bx.LE_fpagetab]
add di,word ptr ds:[bx.LE_fixupsize]
mov si,word ptr ds:[bx.LE_datapage]
mov cx,word ptr ds:[File_Size]
sub cx,si
add si,offset Buffer
cmp di,si
jae Too_Big
mov ax,si
sub ax,di
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 Packer by Horned Beast/VADER",0dh,0ah
db "E-mail: hbeast@darkmail.com",0dh,0ah,0dh,0ah,'$'
Usage_Text db "Usage: VXDPACK.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: VXDPACK.ASM Ã------------------------

← previous
next →
loading
sending ...
New to Neperos ? Sign Up for free
download Neperos App from Google Play
install Neperos as PWA

Let's discover also

Recent Articles

Recent Comments

Neperos cookies
This website uses cookies to store your preferences and improve the service. Cookies authorization will allow me and / or my partners to process personal data such as browsing behaviour.

By pressing OK you agree to the Terms of Service and acknowledge the Privacy Policy

By pressing REJECT you will be able to continue to use Neperos (like read articles or write comments) but some important cookies will not be set. This may affect certain features and functions of the platform.
OK
REJECT