代码:
; ---------------------------------------------------------------------------
;
; The Headless Horsemen Engine v1.03
;
; (x) forgot 2k7 - 2k8
;
; Size = 94 bytes
;
; input:                esi = input buffer
;                       edi = output buffer
;                       edx = virtual address delta
;
; output:               eax = output size
;
; ---------------------------------------------------------------------------
hhe                     proc
 
                        push    esi
                        push    edi
 
                        lodsb
 
                        cmp     al, 0E8h
                        jz      __e8e9
 
                        cmp     al, 0E9h
                        jnz     __x0
 
__e8e9:                 stosb
 
__fixup_dword:          lodsd
 
__store_dword:          sub     eax, edx
                        stosd
 
__exit:                 pop     eax
                        sub     edi, eax
                        pop     esi
                        xchg    eax, edi
                        retn
 
; ---------------------------------------------------------------------------
 
__x0:                   cmp     al, 0Fh
                        jnz     __x1
 
                        lodsb
                        and     al, 0F0h
                        cmp     al, 80h
                        jnz     __exit
 
                        dec     esi
                        dec     esi
                        movsw
                        jmp     __fixup_dword
 
; ---------------------------------------------------------------------------
 
__x1:                   add     edx, 3
 
                        cmp     al, 0EBh
                        jnz     __x2
 
__eb:                   mov     al, 0E9h
                        stosb
 
__fixup_byte:           lodsb
                        movsx   eax, al
                        jmp     __store_dword
 
; ---------------------------------------------------------------------------
__x2:                   inc     edx
 
                        mov     ah, al
                        and     al, 0FCh
                        cmp     al, 0E0h
                        jz      __x3
 
                        and     al, 0F3h
                        cmp     al, 70h
                        jnz     __exit
 
                        xor     ah, 0F0h
                        mov     al, 0Fh
                        stosw
                        jmp     __fixup_byte
 
; ---------------------------------------------------------------------------
 
__x3:                   add     edx, 4
                        movzx   eax, ah
                        or      eax, 5EB0200h
                        stosd
                        jmp     __eb
 
hhe                     endp
; ---------------------------------------------------------------------------

  • 标 题:答复
  • 作 者:forgot
  • 时 间:2008-03-15 21:37

经典应用 pseudocode:

代码:
while (copied_size < 5)
{
  n = lde(src);
  nx = hhe(src, dst, dst - src);
  if ( nx == 0 )
  {
    memcpy(dst, src, n);
    dst += n;
  }
  else
  {
    dst += nx;
  }
  src += n;  
  copied_size += n;
}