.386 
.model flat,stdcall 
option casemap:none 

include		windows.inc 
include		kernel32.inc 
include		user32.inc 
includelib	kernel32.lib
includelib	user32.lib 

DlgProc		proto		:DWORD,:DWORD,:DWORD,:DWORD 

.data? 
hInstance	HINSTANCE	?  
NameBuffer	db		32 dup(?) 
SerialBuffer	db		32 dup(?)

.const
IDD_KEYGEN	equ		1001
IDC_NAME	equ		1002
IDC_SERIAL	equ		1003
IDC_GENERATE	equ		1004
IDC_COPY	equ		1005 
IDC_EXIT	equ		1006
ARIcon		equ		2001

.code 
start: 
    invoke GetModuleHandle, NULL 
    mov    hInstance,eax 
    invoke DialogBoxParam, hInstance, IDD_KEYGEN, NULL, addr DlgProc, NULL 
    invoke ExitProcess,eax 
    
DlgProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM 
.if uMsg == WM_INITDIALOG
	invoke	LoadIcon,hInstance,ARIcon
	invoke	SendMessage,hWnd,WM_SETICON,1,eax
	invoke GetDlgItem,hWnd,IDC_NAME
	invoke SetFocus,eax 
.elseif uMsg == WM_COMMAND
	mov	eax,wParam
	.if eax==IDC_GENERATE
		invoke GetDlgItemText,hWnd,IDC_NAME,addr NameBuffer,32
		call Generate
		invoke SetDlgItemText,hWnd,IDC_SERIAL,addr SerialBuffer
	.elseif eax==IDC_COPY
		invoke SendDlgItemMessage,hWnd,IDC_SERIAL,EM_SETSEL,0,-1
		invoke SendDlgItemMessage,hWnd,IDC_SERIAL,WM_COPY,0,0
	.elseif eax==IDC_EXIT 
		invoke	SendMessage,hWnd,WM_CLOSE,0,0
	.endif
.elseif	uMsg == WM_CLOSE
	invoke	EndDialog,hWnd,0
.endif        
    xor	eax,eax
    ret 
DlgProc endp 

Generate proc
invoke lstrlen, addr NameBuffer
test eax, eax
jle NOINPUT
mov ecx, eax
mov esi, offset NameBuffer	 
mov edi, offset SerialBuffer	
@@:
	dec ecx
	mov dl, BYTE ptr [esi+ecx]
	mov BYTE ptr[edi], dl
	inc edi
	or ecx, ecx
	ja @b
NOINPUT:
	ret
Generate endp

end start