; **************************************************************************************************      
                .586p
                .model           flat,stdcall
	         option          casemap:none
                include          \masm32\include\windows.inc
        	include          \masm32\include\user32.inc
                include          \masm32\include\kernel32.inc                
                includelib       \masm32\lib\kernel32.lib	 
                includelib       \masm32\lib\user32.lib                  	    	 
; **************************************************************************************************
                .data
key             db               00h  
P               db               0,0,0,0,0,0,0,1,0,0            
box_title       db               "Congratulations!",0
box_mes         db               "You've crack this easy one... But what you say if there was 1000 threads?",0
box_title2      db               "Shit...",0    
box_mes2        db               "Invalid key",0
; **************************************************************************************************
	        .data?
ThreadId        dd               ?
; **************************************************************************************************
                .code     
                CT               MACRO StartAddress
                push             ThreadId
                push             EBX 
                push             EBX 
                push             StartAddress 
                push             EBX 
                push             EBX
                call             CreateThread
                ENDM                           
_start:                
                xor              EBX,EBX 
                call             byte2bit   
                CT               _T6     
                ;invoke           SetThreadPriority, EAX, THREAD_PRIORITY_ABOVE_NORMAL   
                CT               _T2
                CT               _T3
                CT               _T1
                CT               _T4                
                CT               _T5
                ;invoke           SetThreadPriority, EAX, THREAD_PRIORITY_LOWEST                                	
                CT               _T7
                jmp              $    
_T3:
                mov              AL,P[4]
                add              AL,P[5]
                dec              AL
                dec              AL
                jnz              _T3
                mov              P[6],1 
                mov              P[4],AL
                mov              P[5],AL               
                jmp              _T3                              
_T1:                
                mov              AL,P[3]
                dec              AL                
                jnz              _T1
                mov              P[3],AL    ; 0
                mov              P[4],1
                jmp              _T1
_T4:                              
                mov              AL,P[0]
                dec              AL
                jnz              _T4
                mov              P[8],1
                mov              P[9],1
                mov              P[0],AL                
                jmp              _T4                
_T5:
                mov              ECX,0FFFFFFh
                loop             $		; delay
                mov              AL,P[8]
                add              AL,P[9]
                add              AL,P[7]
                add              AL,P[6]
                sub              AL,4
                jnz              _T5                 
                     
                invoke           MessageBox, 40h, addr box_mes, addr box_title, EBX
                jmp              _fin
_T2:
                mov              AL,P[2]
                dec              AL                
                jnz              _T2
                mov              P[5],1
                mov              P[2],AL
                jmp              _T2
                
_T6:
                mov              AL,P[6]
                add              AL,P[1]
                add              AL,P[7]
                sub              AL,3
                jnz              _T6
                mov              P[3],1
                mov              P[2],1
                mov              P[1],1
                mov              P[7],AL
                jmp              _T6  
_T7:
                mov              ECX,0FFFFFFFh
                loop             $
_patch:               
                invoke           MessageBox, 40h, addr box_mes2, addr box_title2, EBX                 
_fin:            
                invoke	         ExitProcess, EBX    
byte2bit:
                mov              AL, byte ptr [key]                 
		push             EAX
                shr              AL, 3
                mov              P[3],AL
                pop              EAX
                push             EAX
                shr              AL, 2
                and              AL,1
                mov              P[2],AL
                pop              EAX
                push             EAX
                shr              AL, 1
                and              AL,1
                mov              P[1],AL
                pop              EAX                
                and              AL,1
                mov              P[0],AL  
                ret            
                end              _start