📄 lzrw1dec.asm
字号:
;
; LZRW1_Decompression, by Virogen/PC
; revision 2 - 05/08/99 2:25pm EST
; -------------------------------------------------------------------
;
; This is my rewrite and optimization of the LZRW1 decompression
; algorithm. Originally, I acquired an asm output of the LZRW1
; decompressor from a C compiler. Using that source as a guideline,
; I rewrote this algorithm from scratch and improved its size and
; performance significantly.
;
; Enjoy!
; Virogen/PC
;
; rev 2: optimized it a little more
;
;
; prototype:
; void LZRW1_Decompress(pSource,Size,pDestination)
;
;
FLAG_COMPRESS equ 0 ; compression
FLAG_COPY equ 1 ; no compression
FLAG_BYTES equ 4 ; number of bytes for flag
LZRW1_Decompress proc
pop eax ; pop return address
pop esi ; esi=pSource
pop ebx ; ebx=size
pop edi ; edi=pDestination
push eax ; push return address
mov ebp,ebx
add ebp,esi ; ebp->pEndOfSource (pSource+size)
xor ecx,ecx ; null control bits reg
add esi,4 ; esi->pSource[FLAG_BYTES]
cmp byte ptr [esi-4],FLAG_COPY; did compression occur?
jnz did_compression
; direct copy from source[FLAG_BYTES] to destination
; length-=FLAG_BYTE
xchg ecx,ebx ; ecx=length
sub ecx,FLAG_BYTES ; ecx-=FLAG_BYTES
cld
rep movsb
jmp _exit_lzwr1
; decompression code
did_compression:
or ebx,ebx ; was length 0?
jz _exit_lzwr1
xor ebx,ebx
main_loop:
or ecx,ecx
jnz literal
xor eax,eax
lodsw ; get num of blocks
xchg eax,edx ; in edx
mov ecx,16 ; set counter
literal:
bt edx,0 ; is low bit 0?
jnc move_literal ; if not then move literal
lodsb ; get next byte (low nibble=length)
mov bl,al
and eax,0fh ; AND off high nibble of low byte
inc eax ; increment byte
and ebx,0f0h ; AND off low nibble of low byte
push ecx ; save ecx
xchg ecx,eax
xor eax,eax
lodsb
shl ebx,4 ; shift high nibble of low byte to low word
add ebx,eax ; combine byte with high nibble of previous
; ecx=offset
mov eax,edi ; ebx=pDest
sub eax,ebx ; ebx->pDest-offset
mov ebx,eax ; ecx=sequence offset
push esi
xchg esi,ebx
rep movsb ; copy sequence
pop esi ecx ; restore esi,ecx
jmp shift_control_bits
move_literal:
lodsb
stosb
shift_control_bits:
shr edx,1 ;
dec ecx ; decrement count
cmp esi,ebp ; are we at end of crypted code?
jne short main_loop ; if not then do the main deal
_exit_lzwr1:
ret
LZRW1_Decompress endp
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -