📄 packer.asm
字号:
.586
.model flat, stdcall
option casemap :none ; case sensitive
include c:\hd\hd.h
include c:\hd\mac.h
assume fs:nothing
;~~~~~~~~~~~~~~~~~~~protos
;~~~~~~~~~~~~~~~~~~~~~~~~~
SEH_ = 0
DECOMPRESS=0
COMPRESS=1
;;--------------
;##########################################################################
CurDate TEXTEQU <">, @Date, <">
CurTime TEXTEQU <">, @Time, <">
CurFileName TEXTEQU <">, @FileCur, <">
;##########################################################################
.DATA
ms0 db "Hume's First Huffman Based bits 2 Packer Version 1.0...",13,10
db "Built on ", CurDate, " ", CurTime, 13, 10
db "sorry for the bad performance...I'll try to improve another engine",13,10,0
exc_ms db 13,10,"Unexpected GP error or something else",13,10
db "Program will terminate...",0
Another db "another "
usage db "Usage: pack in.* out.*",13,10,0
.DATA?
hInstance dd ?
rd error_mode ;是否发生错误
rd buf,64 ;256 bytes
rb cFname,256 ;File name--------------
rb _comp,128 ;compressed file name
;-----------------------------------------
rd hinf
rd hmap
rd pview
rd src_size
rd hcomp_file
rd comp_map
rd pcomp_view
;;----------------[BCE32 ]-------------------------
rd c_c1,4
rd c_c2,4
dd ?
dd ?
rd pt_Mem
rd pt_msize
rd cb_out
;-----------------------------------------
.CODE
include ..\common\cmd.inc
__Start:
IF SEH_
push offset EXC_XIT
push fs:[0]
mov fs:[0],esp
ENDIF
call process_cmd
lea esi,ms0
call write_con_string
;display basic message
mov ecx,argc
dec ecx
jecxz wait_for_input
.if (ecx==1) || (ecx>2)
mov esi,CTEXT(13,10,"Syntax error",13,10)
call write_con_string
lea esi,usage
call write_con_string
.endif
INVOKE lstrcpy,addr cFname,dword ptr [argv+4]
INVOKE lstrcpy,addr _comp,dword ptr [argv+8]
jmp passed_cmd_line
wait_for_input:
lea esi,Another
call write_con_string
mov esi,CTEXT(13,10,"Please INPUT the file to be packed:")
call write_con_string
lea edi,cFname
mov ecx,256
call read_con_string
dec $zreg(ecx)
mov al,0dh
lea edi,buf
repnz scasb
jnz err_no_input_names
neg ecx
dec ecx
dec ecx
je err_no_input_names
mov byte ptr [edi-1],0
INVOKE wsprintf,addr _comp,CTEXT("%s%s"),addr cFname,CTEXT(".cpd")
;;INVOKE MessageBox,0,addr _comp,0,0
passed_cmd_line:
INVOKE CreateFile,addr cFname,GENERIC_READ+GENERIC_WRITE,FILE_SHARE_READ+FILE_SHARE_WRITE,eax,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,$zreg()
JEAXS error_openfile_fail
mov hinf,eax
INVOKE GetFileSize,hinf,0
JEAXZ error_zero_file
mov src_size,eax
INVOKE CreateFileMapping,hinf,EAX,PAGE_READWRITE,EAX,EAX,$zreg()
JEAXZ error_map_fail
mov hmap,eax
INVOKE MapViewOfFile,hmap,FILE_MAP_ALL_ACCESS,EAX,EAX,$zreg()
JEAXZ error_view_fail
mov pview,eax
;------------ [create output files] ---------------------
INVOKE CreateFile,addr _comp,GENERIC_READ+GENERIC_WRITE,FILE_SHARE_READ+FILE_SHARE_WRITE,eax,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,$zreg()
JEAXS error_out_openfile_fail
mov hcomp_file,eax
mov edx,src_size
imul edx,edx,2
INVOKE CreateFileMapping,hcomp_file,EAX,PAGE_READWRITE,EAX,EDX,$zreg()
JEAXZ error_out_map_fail
mov comp_map,eax
INVOKE MapViewOfFile,comp_map,FILE_MAP_ALL_ACCESS,EAX,EAX,$zreg()
JEAXZ error_out_view_fail
mov pcomp_view,eax
;-----------------------------------------
include ph32.asm
;------[ uninstall seh frame ]-------
IF SEH_
pop fs:[0]
pop eax
ENDIF
err_xit_prg:
xit_prg:
call Clear_handles
INVOKE Sleep,8000
invoke ExitProcess,0
;------------ [压缩主程序部分] -----------------------------
include ..\common\hc32.inc
include ..\common\console.inc
;-----------------------------------------
;-----------------------[error processing]------------------
include err.inc
;-----------------------------------------
IF SEH_
EXC_XIT: ;If error just exit
mov eax,fs:[0]
mov esp,[eax]
pop fs:[0]
mov [esp],offset err_xit_prg
lea esi,exc_ms
call write_con_string
ret
ENDIF
;----------[Close all handles while Exit ]-------------------
Clear_handles:
.IF hinf
INVOKE UnmapViewOfFile,pview
INVOKE CloseHandle,hmap
INVOKE CloseHandle,hinf
.ENDIF
.IF hcomp_file
INVOKE UnmapViewOfFile,pcomp_view
INVOKE CloseHandle,comp_map
mov eax,cb_out
INVOKE SetFilePointer,hcomp_file,eax,0,FILE_BEGIN
INVOKE SetEndOfFile,hcomp_file
INVOKE CloseHandle,hcomp_file
.ENDIF
.IF error_mode==1
INVOKE DeleteFile,addr _comp
.ENDIF
ret
END __Start
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -