.386
.model	flat,stdcall
option	casemap:none

include	\masm32\include\windows.inc
include	\masm32\include\user32.inc
include	\masm32\include\kernel32.inc
include	\masm32\include\shell32.inc

includelib	\masm32\lib\user32.lib
includelib	\masm32\lib\kernel32.lib
includelib	\masm32\lib\shell32.lib

.data?
	hDll		dd	?
	TextFromCaptcha	dd	?
	_param1		db	512 dup(?)
	_param2		db	512 dup(?)
	_result		db	100 dup(?)

.code
_errfn	db	'Error loading library '
_dll	db	'Captcha.dll',0
_fn	db	'TextFromCaptcha',0
_n1	dw	0a0dh
start:
	invoke	GetCommandLineA
	lea	edi,_param1
	mov	esi,eax
	.if byte ptr[esi]==34
		lodsb
		.while byte ptr[esi]!=34
			lodsb
		.endw
		lodsb
	.else
		.while byte ptr[esi]>32
			lodsb
		.endw
	.endif
	.while byte ptr[esi]==32
		lodsb
	.endw
	.if byte ptr[esi]==34
		lodsb
		.while byte ptr[esi]!=34
			movsb
		.endw
		lodsb
	.else
		.while byte ptr[esi]>32
			movsb
		.endw
	.endif
	mov	al,0
	stosb
	.if byte ptr[esi]==32
		inc	esi
	.endif
	lea	edi,_param2
	.if byte ptr[esi]==34
		lodsb
		.while byte ptr[esi]!=34
			movsb
		.endw
		lodsb
	.else
		.while byte ptr[esi]>32
			movsb
		.endw
	.endif
	mov	al,0
	stosb
	invoke	LoadLibrary,addr _dll
	invoke	GetProcAddress,eax,addr _fn
	.if eax==0
		invoke	MessageBox,0,addr _errfn,0,0
	.endif
	push	100
	push	offset _result
	push	offset _param1
	push	0
	call	eax
	invoke	CreateFile,addr _param2,GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ,0,OPEN_ALWAYS,0,0
	.if eax!=INVALID_HANDLE_VALUE
		push	eax
		invoke	SetFilePointer,eax,0,0,FILE_END
		mov	eax,[esp]
		xor	ecx,ecx
		.while _result[ecx]
			inc	ecx
		.endw
		invoke	WriteFile,eax,addr _result,ecx,addr _param1,0
		mov	eax,[esp]
		invoke	WriteFile,eax,addr _n1,2,addr _param1,0
		call	CloseHandle
	.else
		invoke	MessageBox,0,addr _result,addr _param1,0
	.endif
	invoke	ExitProcess,0

end	start