Jump to content
Tuts 4 You

aplib decompression

abhijit mohanta

Recommended Posts

abhijit mohanta

Does anyone have a idea on how aplib algo works? This is a derivation of lz78 decompression.

I want to know the meanings of the routines like getbit getgamma and how it is used to read the dictionary.


Below is the code



    ; aP_depack_asm(const void *source, void *destination)    _ret$  equ 7*4
    _src$  equ 8*4 + 4
    _dst$  equ 8*4 + 8    pushad    mov    esi, [esp + _src$] ; C calling convention
    mov    edi, [esp + _dst$]    cld
    mov    dl, 80h
    xor    ebx,ebxliteral:
    mov    bl, 2
    call   getbit
    jnc    literal    xor    ecx, ecx
    call   getbit
    jnc    codepair
    xor    eax, eax
    call   getbit
    jnc    shortmatch
    mov    bl, 2
    inc    ecx
    mov    al, 10h
    call   getbit
    adc    al, al
    jnc    .getmorebits
    jnz    domatch
    jmp    nexttag
    call   getgamma_no_ecx
    sub    ecx, ebx
    jnz    normalcodepair
    call   getgamma
    jmp    domatch_lastpos
    shr    eax, 1
    jz     donedepacking
    adc    ecx, ecx
    jmp    domatch_with_2incnormalcodepair:
    xchg   eax, ecx
    dec    eax
    shl    eax, 8
    call   getgamma    cmp    eax, 32000
    jae    domatch_with_2inc
    cmp    ah, 5
    jae    domatch_with_inc
    cmp    eax, 7fh
    ja     domatch_new_lastposdomatch_with_2inc:
    inc    ecxdomatch_with_inc:
    inc    ecxdomatch_new_lastpos:
    xchg   eax, ebp
    mov    eax, ebp    mov    bl, 1domatch:
    push   esi
    mov    esi, edi
    sub    esi, eax
    rep    movsb
    pop    esi
    jmp    nexttaggetbit:
    add    dl, dl
    jnz    .stillbitsleft
    mov    dl, [esi]
    inc    esi
    adc    dl, dl
    xor    ecx, ecx
    inc    ecx
    call   getbit
    adc    ecx, ecx
    call   getbit
    jc     .getgammaloop
    sub    edi, [esp + _dst$]
    mov    [esp + _ret$], edi ; return unpacked length in eax    popad    ret

Link to comment
abhijit mohanta

1) It's not a derivation of LZ78, but LZ77. ;)

2) Once you understand the theory behind data compression, meanings of getbit() and getgamma() will be obvious to you. Check some tutorials or read "The Data Compression Book" (http://forum.eviloctal.com/attachment.php?aid=322 ).

Hi Kao,

Can you give me some idea on this. I would help me learn a little faster. I went through lz77 and and some reading. Getbit seems to get a flag value from stream 0 or one according to which it is going to decide whether next bytes are literal or codeword(index,length) pair. What does the getgamma ,nexttag used for?

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...