📄 3plib.asm
字号:
mov edi,offset LibName
rep movsb
pop esi
;
;Lose export memory.
;
sys RelMemLinear32
;
;Compare the module names.
;
mov esi,offset ModName
mov edi,offset LibName
xor ecx,ecx
mov cl,[esi]
cmp cl,[edi]
jnz @@7
inc esi
inc edi
repe cmpsb
jz @@8
;
@@7: ;Move past this module.
;
mov edx,d[NewHeader+NewSize]
add edx,LibOffset
mov LibOffset,edx
mov cx,dx
shr edx,16
xchg cx,dx
mov ax,4200h
int 21h
jmp @@4
;
@@8: ;Set things up ready for this module to be extracted.
;
mov eax,d[NewHeader+NewSize]
mov LibIgnore,eax
;
;Find out how much trailing data there is.
;
xor cx,cx
xor dx,dx
mov ax,4202h
int 21h
shl edx,16
mov dx,ax
sub edx,LibOffset
sub edx,d[NewHeader+NewSize]
mov LibTrail,edx
;
;Time to generate the extracted file.
;
;
@@11: ;Create the output file.
;
mov edx,OptionPointers+4+4
or edx,edx
jnz @@12
mov edx,offset ModName
mov esi,offset ModName
mov edi,esi
inc esi
movzx ecx,b[edi]
cmp ecx,8
jc @@10
mov ecx,8
@@10: rep movsb
mov b[edi],"."
mov b[edi+1],"d"
mov b[edi+2],"l"
mov b[edi+3],"l"
mov b[edi+4],0
@@12: ;
xor cx,cx
mov ax,3c00h
int 21h
mov ErrorNumber,9
jc @@9
mov TMPHandle,eax
;
;Copy desired module.
;
mov ebx,LibHandle
mov edx,LibOffset
mov cx,dx
shr edx,16
xchg cx,dx
mov ax,4200h
int 21h
mov ebp,LibIgnore
@@18: or ebp,ebp
jz @@20
mov ecx,4096
cmp ecx,ebp
jc @@19
mov ecx,ebp
@@19: mov edx,offset IOBuffer
mov ebx,LibHandle
mov ah,3fh
int 21h
mov ErrorNumber,4
jc @@9
cmp eax,ecx
jnz @@9
mov ebx,TMPHandle
mov ah,40h
int 21h
jc @@9
mov ErrorNumber,10
cmp eax,ecx
jnz @@9
sub ebp,eax
jmp @@18
;
;Close all the files.
;
@@20: mov ebx,LibHandle
mov ah,3eh
int 21h
mov ebx,TMPHandle
mov ah,3eh
int 21h
;
;Return success to caller.
;
mov ErrorNumber,0
@@9: ret
ExtractModule endp
;*******************************************************************************
;
;Create an OBJ file for all modules in specified DLL.
;
;*******************************************************************************
ImportObjModule proc near
;
;Create the output file.
;
mov edx,OptionPointers+4
xor cx,cx
mov ax,3c00h
int 21h
mov ErrorNumber,12
jc @@9
mov TMPHandle,eax
mov ebx,eax
;
;Open the library.
;
mov edx,OptionPointers
mov ax,3d00h
int 21h
mov ErrorNumber,11
jc @@9
mov LibHandle,eax
mov ebx,eax
;
;Scan modules for names.
;
@@4: mov ebx,LibHandle
mov edx,offset NewHeader
mov ecx,size NewHeaderStruc
mov ah,3fh
int 21h
mov ErrorNumber,4
jc @@9
or eax,eax ;EOF?
jz @@20
mov ErrorNumber,4
cmp eax,ecx
jnz @@9
cmp w[NewID+edx],"P3"
jz @@6
cmp w[NewID+edx],"ZM"
jnz @@20 ;assume 3P EOF
;
;Have an MZ stub so find out how long it is and skip it.
;
xor eax,eax
mov ax,[edx+2+2]
dec eax
shl eax,8
xor ecx,ecx
mov cx,[edx+2]
or ecx,ecx
jnz @@5
add eax,512
@@5: add ecx,eax
sub ecx,size NewHeaderStruc
mov dx,cx
shr ecx,16
mov ax,4201h
int 21h
shl edx,16
mov dx,ax
mov LibOffset,edx
jmp @@4
@@6: mov edi,edx
;
;Store this modules file offset.
;
xor cx,cx
xor dx,dx
mov ax,4201h
int 21h
shl edx,16
mov dx,ax
sub edx,size NewHeaderStruc
mov LibOffset,edx
;
;Skip segment definitions.
;
movzx edx,NewSegments[edi]
shl edx,3
sys cwcInfo
jc @@03p0
mov edx,eax
@@03p0: mov cx,dx
shr edx,16
xchg cx,dx
mov ax,4201h
int 21h
;
;Skip relocations.
;
mov edx,NewRelocs[edi]
shl edx,2
or edx,edx
jz @@03p1
sys cwcInfo
jc @@03p1
mov edx,eax
@@03p1: mov cx,dx
shr edx,16
xchg cx,dx
mov ax,4201h
int 21h
;
;Load export details.
;
mov ecx,NewExports[edi]
sys GetMemLinear32
mov ErrorNumber,7
jc @@9
mov edx,ecx
sys cwcInfo
jc @@03p2
push edi
mov edi,esi
sys cwcLoad
pop edi
mov ErrorNumber,4
jc @@9
jmp @@03p4
@@03p2: mov ecx,edx
mov edx,esi
mov ah,3fh
int 21h
mov ErrorNumber,4
jc @@9
cmp eax,ecx
jnz @@9
;
@@03p4: ;Generate the THEADR.
;
push esi
add esi,[esi+4] ;get offset of module name.
movzx ecx,b[esi] ;get name length.
inc ecx
mov ModOffset,esi
mov ModLength,ecx
mov edi,offset IOBuffer
xor ah,ah
mov b[edi],80h
add ah,[edi]
inc edi
mov [edi],cx
add w[edi],1
add ah,[edi]
add ah,[edi+1]
add edi,2
@@30: mov al,[esi]
add ah,al
mov [edi],al
inc esi
inc edi
dec ecx
jnz @@30
not ah
mov [edi],ah
inc edi
pop esi
mov edx,offset IOBuffer
mov ecx,edi
sub ecx,edx
mov ebx,TMPHandle
mov ah,40h
int 21h
;
;Now generate all the exported symbols.
;
mov ModCount,1
push esi
mov edx,esi
mov ebp,[esi] ;get number of entries.
add esi,4+4
@@10: push esi
push edx
mov esi,[esi]
add esi,edx
add esi,4+2 ;skip value.
movzx ecx,b[esi]
inc ecx
mov edi,offset IOBuffer
;
;Do the EXTDEF
;
push ecx
push esi
xor ah,ah
mov b[edi],8ch
add ah,[edi]
inc edi
mov [edi],cx
add w[edi],1+1
add ah,[edi]
add ah,[edi+1]
add edi,2
@@31: mov al,[esi]
add ah,al
mov [edi],al
inc esi
inc edi
dec ecx
jnz @@31
mov b[edi],0
add ah,[edi]
inc edi
not ah
mov [edi],ah
inc edi
pop esi
pop ecx
;
;Do the IMPDEF
;
xor ah,ah
mov b[edi],88h
add ah,[edi]
inc edi
mov [edi],cx
add w[edi],1+1+1+1+2+1
mov edx,ModLength
add w[edi],dx
add ah,[edi]
add ah,[edi+1]
add edi,2
mov b[edi],0
add ah,[edi]
inc edi
mov b[edi],0a0h
add ah,[edi]
inc edi
mov b[edi],1
add ah,[edi]
inc edi
mov b[edi],1
add ah,[edi]
inc edi
@@32: mov al,[esi]
add ah,al
mov [edi],al
inc esi
inc edi
dec ecx
jnz @@32
mov esi,ModOffset
mov ecx,ModLength
@@33: mov al,[esi]
add ah,al
mov [edi],al
inc esi
inc edi
dec ecx
jnz @@33
mov edx,ModCount
mov [edi],dx
add ah,[edi]
add ah,[edi+1]
add edi,2
not ah
mov [edi],ah
inc edi
;
;Write the results.
;
mov edx,offset IOBuffer
mov ecx,edi
sub ecx,edx
mov ah,40h
mov ebx,TMPHandle
int 21h
;
pop edx
pop esi
inc ModCount
add esi,4
dec ebp
jnz @@10
pop esi
;
;Do the MODEND.
;
mov edi,offset IOBuffer
xor ah,ah
mov b[edi],8ah
add ah,[edi]
inc edi
mov w[edi],2
add ah,[edi]
add ah,[edi+1]
add edi,2
mov b[edi],0
add ah,[edi]
inc edi
not ah
mov [edi],ah
inc edi
mov edx,offset IOBuffer
mov ecx,edi
sub ecx,edx
mov ebx,TMPHandle
mov ah,40h
int 21h
;
;Lose export memory.
;
sys RelMemLinear32
;
;Move past this module.
;
mov edx,d[NewHeader+NewSize]
add edx,LibOffset
mov LibOffset,edx
mov ebx,LibHandle
mov cx,dx
shr edx,16
xchg cx,dx
mov ax,4200h
int 21h
jmp @@4
;
;Close all the files.
;
@@20: mov ebx,LibHandle
mov ah,3eh
int 21h
mov ebx,TMPHandle
mov ah,3eh
int 21h
;
;Return success to caller.
;
mov ErrorNumber,0
@@9: ret
ImportObjModule endp
;*******************************************************************************
;Read the command line tail for parameters.
;
;supports / or - or + as switch/option settings. Options and names may be in
;any order, text can be tagged onto options, names must be in correct sequence
;for current program.
;
;Each character ( 33 to 127) has an entry in OptionTable & OptionTable+128.
;
;The first entry is a byte, and is 0 for OFF & none-zero for ON.
;The second entry is a pointer to any additional text specified, 0 means none.
;Entries 0-32 are reserved for text not preceded by - or + or /. These are
;intended to be file names, but neadn't be.
;All text entries are 0 terminated.
;
;OptionCounter - Total command line parameters (files & switches).
;OptionTable - Switch table, ASCII code is index to check.
;OptionPointers - Pointer table, ASCII code*4 is index to use.
;
;On Entry:
;
;nothing.
;
;On Exit:
;
;nothing.
;
;*******************************************************************************
ReadCommand proc near
pushad
;
;Get PSP's linear address so we can point at the command tail.
;
mov bx,PSPSegment
sys GetSelDet32
mov esi,edx
add esi,80h
;
;Parse command tail.
;
mov edi,offset OptionText
mov OptionPointer,edi
movzx ecx,b[esi]
inc esi
cmp ecx,2
jc l9 ;not long enough!
mov b[esi+ecx],0 ;terminate the tail.
;
l0: mov al,[esi] ;need to skip leading spaces.
inc esi ;/
or al,al ;/
jz l9 ;/
cmp al,' ' ;/
jz l0 ;/
dec esi ;/
;
l1: cmp b[esi],'/' ;option switch?
jz lOption ;/
cmp b[esi],'-' ;/
jz lOption ;/
cmp b[esi],'+' ;/
jz lOption ;/
;
l2: xor ebx,ebx ;/
mov bl,OptionCounter ;Get file entry number.
inc OptionCounter ;/
shl ebx,2 ;/
add ebx,offset OptionTable+128 ;/
mov edi,OptionPointer ;Current free space pointer.
mov [ebx],edi ;update table entry.
;
xor cl,cl
l3: cmp b[esi],0 ;end of name?
jz l4 ;/
cmp b[esi],' ' ;/
jz l4 ;/
mov al,[esi] ;Copy this character.
mov [edi],al ;/
inc esi ;/
inc edi ;/
mov cl,1 ;flag SOMETHING found.
jmp l3 ;keep fetching them.
;
l4: mov b[edi],0 ;Terminate the name.
inc edi ;/
mov OptionPointer,edi ;Update table pointer.
;
or cl,cl ;Make sure we found something.
jnz l0 ;Go look for more info.
dec OptionPointer
dec OptionCounter ;move pointer/counter back.
xor ebx,ebx
mov bl,OptionCounter ;Get file entry number.
shl ebx,2 ;/
add ebx,offset OptionTable+128 ;/
mov w[ebx],0 ;reset table entry.
jmp l0
;
lOption: mov ah,[esi] ;Get switch character.
inc esi
l5: cmp b[esi],0 ;check for end of line.
jz l9 ;/
cmp b[esi],' ' ;skip spaces.
jnz l6 ;/
inc esi ;/
jmp l5 ;/
;
l6: mov al,[esi] ;get the switched character.
and al,127
inc esi
cmp al,61h ; 'a'
jb l12
cmp al,7Ah ; 'z'
ja l12
and al,5Fh ;convert to upper case.
l12: xor ebx,ebx
mov bl,al
add ebx,offset OptionTable ;Index into the table.
cmp ah,'-'
jnz l7
xor ah,ah ;Convert '-' to zero.
l7: mov [ebx],ah ;Set flag accordingly.
;
cmp b[esi],' ' ;check for assosiated text.
jz l0
cmp b[esi],0
jz l9
cmp b[esi],'='
jz l900
cmp b[esi],':' ;allow colon as seperator.
jnz l8
l900: inc esi ;skip colon.
;
l8: xor ebx,ebx
mov bl,al ;Get the option number again.
shl ebx,2 ; &
add ebx,offset OptionTable+128 ;index into the table.
mov edi,OptionPointer ;current position in the table.
mov [ebx],edi ;store pointer in the table.
;
mov ah," "
cmp b[esi],'"'
jnz l10
mov ah,'"'
inc esi
l10: cmp b[esi],0 ;end of line?
jz l9
cmp b[esi],ah ;end of text?
jz l11
mov al,[esi]
mov [edi],al
inc esi
inc edi
jmp l10
;
l11: mov b[edi],0 ;terminate string.
inc edi
inc esi
mov OptionPointer,edi ;store new text pointer.
jmp l0 ;scan some more text.
l9: popad
movzx eax,OptionCounter
ret
ReadCommand endp
.data
Copyright db 13,10
db 79 dup ("
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -