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

📄 3plib.asm

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 ASM
📖 第 1 页 / 共 3 页
字号:
	mov	ax,3d02h
	int	21h
	mov	ErrorNumber,11
	jc	@@9
	mov	LibHandle,eax
	mov	ebx,eax
;
;Scan modules for name that matches the one we're deleteing.
;
@@4:	mov	edx,offset NewHeader
	mov	ecx,size NewHeaderStruc
	mov	ah,3fh
	int	21h
	mov	ErrorNumber,4
	jc	@@9
	mov	ErrorNumber,11
	or	eax,eax		;EOF?
	jz	@@9
	mov	ErrorNumber,4
	cmp	eax,ecx
	jnz	@@9
	cmp	w[NewID+edx],"P3"
	jz	@@6
	mov	ErrorNumber,11
	cmp	w[NewID+edx],"ZM"
	jnz	@@9		;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 in case it has the right name.
	;
	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:	;Copy the module name.
	;
	push	esi
	add	esi,[esi+4]		;get offset of module name.
	movzx	ecx,b[esi]		;get name length.
	inc	ecx
	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 deleted.
	;
	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 updated library.
;
	;
@@11:	;Create a dummy output file.
	;
	mov	edx,offset TMPName
	xor	cx,cx
	mov	ax,3c00h
	int	21h
	mov	ErrorNumber,9
	jc	@@9
	mov	TMPHandle,eax
	mov	ebx,eax
	;
	;Copy leading data.
	;
	xor	dx,dx
	xor	cx,cx
	mov	ebx,LibHandle
	mov	ax,4200h
	int	21h
	mov	ebp,LibOffset
@@12:	or	ebp,ebp
	jz	@@14
	mov	ecx,4096
	cmp	ecx,ebp
	jc	@@13
	mov	ecx,ebp
@@13:	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	@@12
	;
@@14:	;Copy any trailing library data.
	;
	mov	ebx,LibHandle
	mov	edx,LibIgnore
	mov	cx,dx
	shr	edx,16
	xchg	cx,dx
	mov	ax,4201h
	int	21h
	mov	ebp,LibTrail
@@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
;
;Delete the origional library file.
;
	mov	edx,OptionPointers
	mov	ah,41h
	int	21h
;
;Rename temp file as library file.
;
	mov	edx,offset TMPName
	mov	edi,OptionPointers
	mov	ah,56h
	int	21h
;
;Return success to caller.
;
	mov	ErrorNumber,0
@@9:	ret
DeleteModule	endp


;*******************************************************************************
;
;List modules and exports/imports within a module.
;
;*******************************************************************************
ListModules	proc	near
;
;Open the library.
;
	mov	edx,OptionPointers
	mov	ax,3d02h
	int	21h
	mov	ErrorNumber,11
	jc	@@9
	mov	LibHandle,eax
	mov	ebx,eax
;
;Scan modules for names.
;
@@4:	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:	;Copy the module name.
	;
	push	esi
	add	esi,[esi+4]		;get offset of module name.
	movzx	ecx,b[esi]		;get name length.
	inc	esi
	mov	edi,offset LibName
	rep	movsb
	mov	b[edi],13
	mov	b[edi+1],10
	mov	b[edi+2],"$"
	pop	esi
	;
	;Print the module name.
	;
	mov	edx,offset LibName
	mov	ah,9
	int	21h
	;
	;Now print all the exported symbols.
	;
	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	esi
	mov	edi,offset IOBuffer
	mov	d[edi],"    "
	add	edi,4
	rep	movsb
	mov	b[edi],13
	mov	b[edi+1],10
	mov	b[edi+2],"$"
	mov	edx,offset IOBuffer
	mov	ah,9
	int	21h
	pop	edx
	pop	esi
	add	esi,4
	dec	ebp
	jnz	@@10
	pop	esi
	;
	mov	edx,offset CarriageReturn
	mov	ah,9
	int	21h
	;
	;Lose export memory.
	;
	sys	RelMemLinear32
	;
	;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
;
;Close all the files.
;
@@20:	mov	ebx,LibHandle
	mov	ah,3eh
	int	21h
;
;Return success to caller.
;
	mov	ErrorNumber,0
@@9:	ret
ListModules	endp


;*******************************************************************************
;
;Extract a module.
;
;*******************************************************************************
ExtractModule	proc	near
;
;Get module name to extract in right format.
;
	mov	esi,OptionPointers+4
	xor	ecx,ecx
@@0:	mov	al,[esi]
	or	al,al
	jz	@@1
	inc	esi
	inc	ecx
	jmp	@@0
@@1:	mov	esi,OptionPointers+4
	mov	edi,offset ModName
	mov	b[edi],cl
	inc	edi
@@2:	mov	al,[esi]
	cmp	al,61h		; 'a'
	jb	@@3
	cmp	al,7Ah		; 'z'
	ja	@@3
	and	al,5Fh		;convert to upper case.
@@3:	mov	[edi],al
	inc	esi
	inc	edi
	dec	ecx
	jnz	@@2
;
;Open the library.
;
	mov	edx,OptionPointers
	mov	ax,3d02h
	int	21h
	mov	ErrorNumber,11
	jc	@@9
	mov	LibHandle,eax
	mov	ebx,eax
;
;Scan modules for name that matches the one we're extracting.
;
@@4:	mov	edx,offset NewHeader
	mov	ecx,size NewHeaderStruc
	mov	ah,3fh
	int	21h
	mov	ErrorNumber,4
	jc	@@9
	mov	ErrorNumber,11
	or	eax,eax		;EOF?
	jz	@@9
	mov	ErrorNumber,4
	cmp	eax,ecx
	jnz	@@9
	cmp	w[NewID+edx],"P3"
	jz	@@6
	mov	ErrorNumber,11
	cmp	w[NewID+edx],"ZM"
	jnz	@@9		;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 in case it has the right name.
	;
	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:	;Copy the module name.
	;
	push	esi
	add	esi,[esi+4]		;get offset of module name.
	movzx	ecx,b[esi]		;get name length.
	inc	ecx

⌨️ 快捷键说明

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