Code:
;© Ten$ion 2013
NormalizeCode PROTO :DWORD
DenormalizeCode PROTO :DWORD
RotateRight PROTO :WORD
CrazyCode PROTO :WORD, :WORD
.data
XLAT1 db 02Bh, 062h, 028h, 032h, 039h, 065h, 02Ah, 06Ah, 031h, 056h, 04Dh, 045h, 04Bh, 04Ch, 079h, 043h
db 07Dh, 029h, 038h, 026h, 06Dh, 023h, 07Eh, 057h, 03Eh, 071h, 078h, 064h, 052h, 070h, 030h, 077h
db 06Bh, 072h, 055h, 06Fh, 05Bh, 044h, 037h, 02Ch, 058h, 054h, 063h, 041h, 022h, 06Ch, 049h, 02Eh
db 076h, 025h, 07Bh, 067h, 04Ah, 068h, 034h, 047h, 05Ch, 02Dh, 03Dh, 04Fh, 040h, 035h, 060h, 05Fh
db 033h, 069h, 03Ch, 03Fh, 05Ah, 027h, 03Bh, 046h, 04Eh, 051h, 075h, 059h, 05Dh, 073h, 07Ah, 066h
db 024h, 021h, 042h, 053h, 02Fh, 07Ch, 074h, 03Ah, 050h, 06Eh, 036h, 05Eh, 048h, 061h
CrazyTable dw 4, 3, 3, 1, 0, 0, 1, 0, 0
dw 4, 3, 5, 1, 0, 2, 1, 0, 2
dw 5, 5, 4, 2, 2, 1, 2, 2, 1
dw 4, 3, 3, 1, 0, 0, 7, 6, 6
dw 4, 3, 5, 1, 0, 2, 7, 6, 8
dw 5, 5, 4, 2, 2, 1, 8, 8, 7
dw 7, 6, 6, 7, 6, 6, 4, 3, 3
dw 7, 6, 8, 7, 6, 8, 4, 3, 5
dw 8, 8, 7, 8, 8, 7, 5, 5, 4
P9 dw 1, 9, 81, 729, 6561
szOut db 59048 dup(?)
.code
NormalizeCode proc szInput:DWORD
invoke RtlZeroMemory, addr szOut, 59048
xor ebx, ebx
xor edi, edi
mov esi, szInput
.while 1
mov al, byte ptr ds:[esi]
.if al == 0
.break
.endif
.if al > 20h
.if al < 7Fh
lea eax, [eax+edi-21h]
cdq
mov ecx, 5Eh
idiv ecx
mov al, byte ptr ds:[XLAT1+1*edx]
inc edi
.endif
.endif
mov szOut[ebx], al
inc ebx
inc esi
.endw
mov eax, offset szOut
ret
NormalizeCode endp
DenormalizeCode proc szInput:DWORD
LOCAL tmp:BYTE
invoke RtlZeroMemory, addr szOut, 59048
xor ebx, ebx
xor edi, edi
mov esi, szInput
.while 1
xor eax, eax
mov al, byte ptr ds:[esi]
.if al == 0
.break
.endif
.if al > 20h
.if al < 7Fh
mov tmp, al
push ebx
xor ecx, ecx
.while ecx < 5Eh
lea eax, [edi+ecx]
cdq
mov ebx, 5Eh
idiv ebx
mov al, byte ptr ds:[XLAT1+1*edx]
.if al == tmp
mov eax, ecx
add eax, 21h
.break
.endif
inc ecx
.endw
pop ebx
.endif
.endif
inc edi
mov szOut[ebx], al
inc ebx
inc esi
.endw
mov eax, offset szOut
ret
DenormalizeCode endp
RotateRight proc data:WORD
xor ecx, ecx
xor eax, eax
movzx eax, word ptr ds:[data]
cdq
mov ecx, 3
idiv ecx
mov ecx, eax
movzx eax, word ptr ds:[data]
cdq
mov esi, 3
idiv esi
imul edx, edx, 4CE3h
add ecx, edx
mov ax, cx
ret
RotateRight endp
CrazyCode proc X:WORD, Y:WORD
LOCAL output:WORD
xor edi, edi
xor ebx, ebx
mov output, 0
.while edi < 5
push edi
movzx eax, word ptr ds:[Y]
movzx ecx, word ptr ds:[P9+2*edi]
cdq
idiv ecx
cdq
mov ecx, 9
idiv ecx
mov ecx, edx
imul ecx, ecx, 12h
movzx eax, word ptr ds:[X]
movzx esi, word ptr ds:[P9+2*edi]
cdq
idiv esi
cdq
mov esi, 9
idiv esi
xor eax, eax
mov eax , edx
imul eax, 2
add eax, ecx
movzx eax, word ptr ds:[CrazyTable+eax]
movzx edx, word ptr ds:[P9+2*edi]
imul eax, edx
movzx ecx, word ptr ds:[output]
add ecx, eax
mov output, cx
pop edi
inc edi
.endw
movzx eax, word ptr ds:[output]
ret
CrazyCode endp