/*************************************************************** * aPLib v0.12b - the smaller the better :) * * DJGPP assembler depacker * * * * Copyright (c) 1998 by ÄúJibzúÄ All Rights Reserved * ***************************************************************/ #ifndef __APACK_DEPACK #define __APACK_DEPACK void aP_depack_asm_fast(unsigned char *source, unsigned char *destination) { asm ( "pushl %%ebp \n\t" "cld \n\t" "movb $0x01, %%dh \n\t" "nexttag: \n\t" "decb %%dh \n\t" "jnz stillbitsleftA \n\t" "movb (%%esi), %%dl \n\t" "incl %%esi \n\t" "movb $0x08, %%dh \n\t" "stillbitsleftA: \n\t" "addb %%dl, %%dl \n\t" "jc not_literal \n\t" "literal: \n\t" "movsb \n\t" "jmp nexttag \n\t" "not_literal: \n\t" "decb %%dh \n\t" "jnz stillbitsleftB \n\t" "movb (%%esi), %%dl \n\t" "incl %%esi \n\t" "movb $0x08, %%dh \n\t" "stillbitsleftB: \n\t" "addb %%dl, %%dl \n\t" "jnc codepair \n\t" "decb %%dh \n\t" "jnz stillbitsleftC \n\t" "movb (%%esi), %%dl \n\t" "incl %%esi \n\t" "movb $0x08, %%dh \n\t" "stillbitsleftC: \n\t" "addb %%dl, %%dl \n\t" "jnc shortmatch \n\t" "xorl %%eax, %%eax \n\t" "decb %%dh \n\t" "jnz stillbitsleft_eaxA \n\t" "movb (%%esi), %%dl \n\t" "incl %%esi \n\t" "movb $0x08, %%dh \n\t" "stillbitsleft_eaxA: \n\t" "addb %%dl, %%dl \n\t" "adcl %%eax, %%eax \n\t" "decb %%dh \n\t" "jnz stillbitsleft_eaxB \n\t" "movb (%%esi), %%dl \n\t" "incl %%esi \n\t" "movb $0x08, %%dh \n\t" "stillbitsleft_eaxB: \n\t" "addb %%dl, %%dl \n\t" "adcl %%eax, %%eax \n\t" "decb %%dh \n\t" "jnz stillbitsleft_eaxC \n\t" "movb (%%esi), %%dl \n\t" "incl %%esi \n\t" "movb $0x08, %%dh \n\t" "stillbitsleft_eaxC: \n\t" "addb %%dl, %%dl \n\t" "adcl %%eax, %%eax \n\t" "decb %%dh \n\t" "jnz stillbitsleft_eaxD \n\t" "movb (%%esi), %%dl \n\t" "incl %%esi \n\t" "movb $0x08, %%dh \n\t" "stillbitsleft_eaxD: \n\t" "addb %%dl, %%dl \n\t" "adcl %%eax, %%eax \n\t" "negl %%eax \n\t" "jz thewrite \n\t" "movb (%%edi,%%eax,), %%al \n\t" "thewrite: \n\t" "stosb \n\t" "jmp nexttag \n\t" "codepair: \n\t" "jmp getgamma_eax \n\t" "getgamma_eax_ret: \n\t" "subl $0x02, %%eax \n\t" "jnz normalcodepair \n\t" "call getgamma \n\t" "copydata2: \n\t" "pushl %%esi \n\t" "movl %%edi, %%esi \n\t" "subl %%ebp, %%esi \n\t" "rep \n\t" "movsb \n\t" "popl %%esi \n\t" "jmp nexttag \n\t" "normalcodepair: \n\t" "decl %%eax \n\t" "shll $0x08, %%eax \n\t" "lodsb \n\t" "movl %%eax, %%ebx \n\t" "call getgamma \n\t" "cmpl $0x007f, %%ebx \n\t" "ja domatch3 \n\t" "addl $0x02, %%ecx \n\t" "domatch3: \n\t" "movl %%ebx, %%ebp \n\t" "pushl %%esi \n\t" "movl %%edi, %%esi \n\t" "subl %%ebx, %%esi \n\t" "rep \n\t" "movsb \n\t" "popl %%esi \n\t" "jmp nexttag \n\t" "shortmatch: \n\t" "xorl %%eax, %%eax \n\t" "lodsb \n\t" "xorl %%ecx, %%ecx \n\t" "shrb $0x01, %%al \n\t" "jz donedepacking \n\t" "adcl $0x02, %%ecx \n\t" "movl %%eax, %%ebx \n\t" "domatch: \n\t" "pushl %%esi \n\t" "movl %%edi, %%esi \n\t" "subl %%ebx, %%esi \n\t" "rep \n\t" "movsb \n\t" "popl %%esi \n\t" "jmp nexttag \n\t" "getgamma_eax: \n\t" "movl $0x01, %%eax \n\t" "getgammaloop_eax: \n\t" "decb %%dh \n\t" "jnz stillbitsleft_eax \n\t" "movb (%%esi), %%dl \n\t" "incl %%esi \n\t" "movb $0x08, %%dh \n\t" "stillbitsleft_eax: \n\t" "addb %%dl, %%dl \n\t" "jnc getgammabit_eax \n\t" "decb %%dh \n\t" "jnz stillbitsleft_eax2 \n\t" "movb (%%esi), %%dl \n\t" "incl %%esi \n\t" "movb $0x08, %%dh \n\t" "stillbitsleft_eax2: \n\t" "addb %%dl, %%dl \n\t" "adcl %%eax, %%eax \n\t" "jmp getgammaloop_eax \n\t" "getgammabit_eax: \n\t" "decb %%dh \n\t" "jnz stillbitsleft_eax4 \n\t" "movb (%%esi), %%dl \n\t" "incl %%esi \n\t" "movb $0x08, %%dh \n\t" "stillbitsleft_eax4: \n\t" "addb %%dl, %%dl \n\t" "adcl %%eax, %%eax \n\t" "jmp getgamma_eax_ret \n\t" "getgamma: \n\t" "movl $0x01, %%ecx \n\t" "getgammaloop: \n\t" "decb %%dh \n\t" "jnz stillbitsleft2 \n\t" "movb (%%esi), %%dl \n\t" "incl %%esi \n\t" "movb $0x08, %%dh \n\t" "stillbitsleft2: \n\t" "addb %%dl, %%dl \n\t" "jnc getgammabit \n\t" "decb %%dh \n\t" "jnz stillbitsleft3 \n\t" "movb (%%esi), %%dl \n\t" "incl %%esi \n\t" "movb $0x08, %%dh \n\t" "stillbitsleft3: \n\t" "addb %%dl, %%dl \n\t" "adcl %%ecx, %%ecx \n\t" "jmp getgammaloop \n\t" "getgammabit: \n\t" "decb %%dh \n\t" "jnz stillbitsleft4 \n\t" "movb (%%esi), %%dl \n\t" "incl %%esi \n\t" "movb $0x08, %%dh \n\t" "stillbitsleft4: \n\t" "addb %%dl, %%dl \n\t" "adcl %%ecx, %%ecx \n\t" "ret \n\t" "donedepacking: \n\t" "popl %%ebp \n\t" : : "S" (source), "D" (destination) : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi", "cc" ); } void aP_depack_asm(unsigned char *source, unsigned char *destination) { asm ( "pushl %%ebp \n\t" "cld \n\t" "movb $0x01, %%dh \n\t" ".nexttag: \n\t" "call .getbit \n\t" "jc .not_literal \n\t" ".literal: \n\t" "movsb \n\t" "jmp .nexttag \n\t" ".not_literal: \n\t" "call .getbit \n\t" "jnc .codepair \n\t" "call .getbit \n\t" "jnc .shortmatch \n\t" "xorl %%ecx, %%ecx \n\t" "call .getgammabit \n\t" "call .getgammabit \n\t" "call .getgammabit \n\t" "call .getgammabit \n\t" "movl %%ecx, %%ebx \n\t" "movb $0x01, %%cl \n\t" "testl %%ebx, %%ebx \n\t" "jnz .domatch \n\t" "xchgl %%ebx, %%eax \n\t" "jmp .domatch_continue \n\t" ".codepair: \n\t" "call .getgamma \n\t" "decl %%ecx \n\t" "decl %%ecx \n\t" "jnz .normalcodepair \n\t" "movl %%ebp, %%ebx \n\t" "call .getgamma \n\t" "jmp .domatch \n\t" ".normalcodepair: \n\t" "decl %%ecx \n\t" "shll $0x08, %%ecx \n\t" "lodsb \n\t" "movb %%al, %%cl \n\t" "movl %%ecx, %%eax \n\t" "movl %%eax, %%ebp \n\t" "xchgl %%ebx, %%eax \n\t" "call .getgamma \n\t" "cmpl $0x007f, %%ebx \n\t" "ja .domatch \n\t" "incl %%ecx \n\t" "incl %%ecx \n\t" "jmp .domatch \n\t" ".shortmatch: \n\t" "lodsb \n\t" "xorl %%ecx, %%ecx \n\t" "shrb $0x01, %%al \n\t" "jz .donedepacking \n\t" "adcl $0x02, %%ecx \n\t" "cbw \n\t" "cwde \n\t" "xchgl %%ebx, %%eax \n\t" ".domatch: \n\t" "negl %%ebx \n\t" ".copydata: \n\t" "movb (%%edi,%%ebx,), %%al \n\t" ".domatch_continue: \n\t" "stosb \n\t" "loop .copydata \n\t" "jmp .nexttag \n\t" ".getbit: \n\t" "decb %%dh \n\t" "jnz .stillbitsleft \n\t" "lodsb \n\t" "xchgl %%edx, %%eax \n\t" "movb $0x08, %%dh \n\t" ".stillbitsleft: \n\t" "addb %%dl, %%dl \n\t" "ret \n\t" ".getgamma: \n\t" "movl $0x01, %%ecx \n\t" ".getgammaloop: \n\t" "call .getbit \n\t" "jnc .getgammabit \n\t" "call .getgammabit \n\t" "jmp .getgammaloop \n\t" ".getgammabit: \n\t" "call .getbit \n\t" "adcl %%ecx, %%ecx \n\t" "ret \n\t" ".donedepacking: \n\t" "popl %%ebp \n\t" : : "S" (source), "D" (destination) : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi", "cc" ); } #endif