/*************************************************************** * aPLib v0.12b - the smaller the better :) * * WATCOM assembler depacker * * * * Copyright (c) 1998 by ÄúJibzúÄ All Rights Reserved * ***************************************************************/ #ifndef __APACK_DEPACK #define __APACK_DEPACK /* NOTE: if you don't include debug, you may remove the push ebp + pop ebp */ void aP_depack_asm_fast(unsigned char *, unsigned char *); #pragma aux aP_depack_asm_fast = \ "push ebp " \ "cld " \ "mov dh, 1 " \ "nexttag: " \ "dec dh " \ "jnz stillbitsleftA " \ "mov dl, [esi] " \ "inc esi " \ "mov dh, 8 " \ "stillbitsleftA: " \ "add dl, dl " \ "jc not_literal " \ "literal: " \ "movsb " \ "jmp short nexttag " \ "not_literal: " \ "dec dh " \ "jnz stillbitsleftB " \ "mov dl, [esi] " \ "inc esi " \ "mov dh, 8 " \ "stillbitsleftB: " \ "add dl, dl " \ "jnc codepair " \ "dec dh " \ "jnz stillbitsleftC " \ "mov dl, [esi] " \ "inc esi " \ "mov dh, 8 " \ "stillbitsleftC: " \ "add dl, dl " \ "jnc shortmatch " \ "xor eax, eax " \ "dec dh " \ "jnz stillbitsleft_eaxA " \ "mov dl, [esi] " \ "inc esi " \ "mov dh, 8 " \ "stillbitsleft_eaxA: " \ "add dl, dl " \ "adc eax, eax " \ "dec dh " \ "jnz stillbitsleft_eaxB " \ "mov dl, [esi] " \ "inc esi " \ "mov dh, 8 " \ "stillbitsleft_eaxB: " \ "add dl, dl " \ "adc eax, eax " \ "dec dh " \ "jnz stillbitsleft_eaxC " \ "mov dl, [esi] " \ "inc esi " \ "mov dh, 8 " \ "stillbitsleft_eaxC: " \ "add dl, dl " \ "adc eax, eax " \ "dec dh " \ "jnz stillbitsleft_eaxD " \ "mov dl, [esi] " \ "inc esi " \ "mov dh, 8 " \ "stillbitsleft_eaxD: " \ "add dl, dl " \ "adc eax, eax " \ "neg eax " \ "jz thewrite " \ "mov al, [edi+eax] " \ "thewrite: " \ "stosb " \ "jmp short nexttag " \ "codepair: " \ "jmp short getgamma_eax " \ "getgamma_eax_ret: " \ "sub eax, 2 " \ "jnz normalcodepair " \ "call getgamma " \ "copydata2: " \ "push esi " \ "mov esi, edi " \ "sub esi, ebp " \ "rep movsb " \ "pop esi " \ "jmp short nexttag " \ "normalcodepair: " \ "dec eax " \ "shl eax, 8 " \ "lodsb " \ "mov ebx, eax " \ "call getgamma " \ "cmp ebx, 127 " \ "ja domatch3 " \ "add ecx, 2 " \ "domatch3: " \ "mov ebp, ebx " \ "push esi " \ "mov esi, edi " \ "sub esi, ebx " \ "rep movsb " \ "pop esi " \ "jmp short nexttag " \ "shortmatch: " \ "xor eax, eax " \ "lodsb " \ "xor ecx, ecx " \ "db 0xc0, 0xe8, 0x01 " \ "jz donedepacking " \ "adc ecx, 2 " \ "mov ebx, eax " \ "domatch: " \ "push esi " \ "mov esi, edi " \ "sub esi, ebx " \ "rep movsb " \ "pop esi " \ "jmp short nexttag " \ \ \ "getgamma_eax: " \ "mov eax, 1 " \ "getgammaloop_eax: " \ "dec dh " \ "jnz stillbitsleft_eax " \ "mov dl, [esi] " \ "inc esi " \ "mov dh, 8 " \ "stillbitsleft_eax: " \ "add dl, dl " \ "jnc getgammabit_eax " \ "dec dh " \ "jnz stillbitsleft_eax2 " \ "mov dl, [esi] " \ "inc esi " \ "mov dh, 8 " \ "stillbitsleft_eax2: " \ "add dl, dl " \ "adc eax, eax " \ "jmp short getgammaloop_eax " \ "getgammabit_eax: " \ "dec dh " \ "jnz stillbitsleft_eax4 " \ "mov dl, [esi] " \ "inc esi " \ "mov dh, 8 " \ "stillbitsleft_eax4: " \ "add dl, dl " \ "adc eax, eax " \ "jmp short getgamma_eax_ret " \ \ \ "getgamma: " \ "mov ecx, 1 " \ "getgammaloop: " \ "dec dh " \ "jnz stillbitsleft2 " \ "mov dl, [esi] " \ "inc esi " \ "mov dh, 8 " \ "stillbitsleft2: " \ "add dl, dl " \ "jnc getgammabit " \ "dec dh " \ "jnz stillbitsleft3 " \ "mov dl, [esi] " \ "inc esi " \ "mov dh, 8 " \ "stillbitsleft3: " \ "add dl, dl " \ "adc ecx, ecx " \ "jmp short getgammaloop " \ "getgammabit: " \ "dec dh " \ "jnz stillbitsleft4 " \ "mov dl, [esi] " \ "inc esi " \ "mov dh, 8 " \ "stillbitsleft4: " \ "add dl, dl " \ "adc ecx, ecx " \ "ret " \ "donedepacking: " \ "pop ebp " \ parm [esi] [edi] \ modify exact [eax ebx ecx edx ebp esi edi]; void aP_depack_asm(unsigned char *, unsigned char *); #pragma aux aP_depack_asm = \ "push ebp " \ "cld " \ "mov dh, 1 " \ "nexttag: " \ "call getbit " \ "jc not_literal " \ "literal: " \ "movsb " \ "jmp short nexttag " \ "not_literal: " \ "call getbit " \ "jnc codepair " \ "call getbit " \ "jnc shortmatch " \ "xor ecx, ecx " \ "call getgammabit " \ "call getgammabit " \ "call getgammabit " \ "call getgammabit " \ "mov ebx, ecx " \ "mov cl, 1 " \ "test ebx, ebx " \ "jnz domatch " \ "xchg eax, ebx " \ "jmp short domatch_continue " \ "codepair: " \ "call getgamma " \ "dec ecx " \ "dec ecx " \ "jnz normalcodepair " \ "mov ebx, ebp " \ "call getgamma " \ "jmp short domatch " \ "normalcodepair: " \ "dec ecx " \ "shl ecx, 8 " \ "lodsb " \ "mov cl, al " \ "mov eax, ecx " \ "mov ebp, eax " \ "xchg eax, ebx " \ "call getgamma " \ "cmp ebx, 127 " \ "ja domatch " \ "inc ecx " \ "inc ecx " \ "jmp short domatch " \ "shortmatch: " \ "lodsb " \ "xor ecx, ecx " \ "shr al, 1 " \ "jz donedepacking " \ "adc ecx, 2 " \ "cbw " \ "cwde " \ "xchg eax, ebx " \ "domatch: " \ "neg ebx " \ "copydata: " \ "mov al, [edi+ebx] " \ "domatch_continue: " \ "stosb " \ "loop copydata " \ "jmp short nexttag " \ "getbit: " \ "dec dh " \ "jnz stillbitsleft " \ "lodsb " \ "xchg eax, edx " \ "mov dh, 8 " \ "stillbitsleft: " \ "add dl, dl " \ "ret " \ "getgamma: " \ "mov ecx, 1 " \ "getgammaloop: " \ "call getbit " \ "jnc getgammabit " \ "call getgammabit " \ "jmp short getgammaloop " \ "getgammabit: " \ "call getbit " \ "adc ecx, ecx " \ "ret " \ "donedepacking: " \ "pop ebp " \ parm [esi] [edi] \ modify exact [eax ebx ecx edx ebp esi edi]; #endif