📄 depackf.nas
字号:
;;
;; aPLib compression library - the smaller the better :)
;;
;; NASM fast assembler depacker
;;
;; Copyright (c) 1998-2002 by Joergen Ibsen / Jibz
;; All Rights Reserved
;;
;; -> NASM by Archee/CoNTRACT (soltesz@hotmail.com)
;;
; define _ELF_ for ELF32 object files
; define _OBJ_ for OMF object files
bits 32
%include "apnasm.mac"
section aptext
cglobal aP_depack_asm_fast,8
%macro getbitM 0
add dl, dl
jnz short %%stillbitsleft
mov dl, [esi]
inc esi
adc dl, dl
%%stillbitsleft:
%endmacro
%macro domatchM 1
push esi
mov esi, edi
sub esi, %1
rep movsb
pop esi
%endmacro
%macro getgammaM 1
mov %1, 1
%%getmore:
getbitM
adc %1, %1
getbitM
jc short %%getmore
%endmacro
aplabel aP_depack_asm_fast,8
pushad
mov esi, [esp + 36] ; C calling convention
mov edi, [esp + 40]
cld
mov dl, 80h
literal:
mov al, [esi]
inc esi
mov [edi], al
inc edi
mov ebx, 2
nexttag:
getbitM
jnc short literal
getbitM
jnc short codepair
xor eax, eax
getbitM
jnc near shortmatch
getbitM
adc eax, eax
getbitM
adc eax, eax
getbitM
adc eax, eax
getbitM
adc eax, eax
jz short .thewrite
push edi
sub edi, eax
mov al, [edi]
pop edi
.thewrite:
mov [edi], al
inc edi
mov ebx, 2
jmp short short nexttag
codepair:
getgammaM eax
sub eax, ebx
mov ebx, 1
jnz short normalcodepair
getgammaM ecx
domatchM ebp
jmp near nexttag
normalcodepair:
dec eax
shl eax, 8
mov al, [esi]
inc esi
mov ebp, eax
getgammaM ecx
cmp eax, 32000
jae short .do_add_2
cmp eax, 1280
jb short .not_gt_1280
inc ecx
domatchM eax
jmp near nexttag
.not_gt_1280:
cmp eax, BYTE 7fh
ja short .dont_add_2
.do_add_2:
add ecx, 2
.dont_add_2:
domatchM eax
jmp near nexttag
shortmatch:
mov al, [esi]
inc esi
xor ecx, ecx
db 0c0h, 0e8h, 001h
jz short donedepacking
adc ecx, BYTE 2
mov ebp, eax
domatchM eax
mov ebx, 1
jmp near nexttag
donedepacking:
sub edi, [esp + 40]
mov [esp + 28], edi ; return unpacked length in eax
popad
apret 8
%ifdef _OBJ_
section apdata
%endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -