.386
.model	flat,stdcall
option	casemap:none

include	c:\masm32\include\windows.inc
include	c:\masm32\include\user32.inc
include	c:\masm32\include\kernel32.inc

includelib	c:\masm32\lib\user32.lib
includelib	c:\masm32\lib\kernel32.lib

.code
errmsg	db	'Error opening file '
fname	db	'Dooble.exe',0
fname1	db	'Dooble.bak',0
okmsg	db	'The file was patched successfully',0
start:
	invoke	CreateFile,addr fname,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,0,0
	.if eax==INVALID_HANDLE_VALUE
		invoke	MessageBox,0,addr errmsg,0,0
	.else
		mov	esi,eax
		invoke	GetFileSize,esi,0
		lea	edi,[eax+1024]
		invoke	GlobalAlloc,GPTR,edi
		xchg	ecx,edi
		xchg	edi,eax
		push	0
		mov	edx,esp
		invoke	ReadFile,esi,edi,ecx,edx,0
		invoke	CloseHandle,esi
		pop	esi
		.if esi>1024 && word ptr[edi+80h]=='EP' && word ptr[edi+94h]==0e0h
			mov	dword ptr[edi+0d8h],0
		.endif
		xor	ecx,ecx
		.while ecx<esi
			mov	eax,[edi+ecx]
			or	eax,20202000h
			.if eax=='crs '
				mov	ebx,ecx
				lea	ecx,[ecx+4]
				.while byte ptr[edi+ecx]==32
					inc	ecx
				.endw
				.if byte ptr[edi+ecx]=='='
					inc	ecx
					.while byte ptr[edi+ecx]==32
						inc	ecx
					.endw
					.if byte ptr[edi+ecx]==34 || byte ptr[edi+ecx]==39
						inc	ecx
						mov	eax,[edi+ecx]
						or	eax,20202020h
						.if eax=='ptth'
							.if byte ptr[edi+ecx-1]==34
								.while byte ptr[edi+ecx]!=34 && byte ptr[edi+ecx]!=0 && byte ptr[edi+ecx]!='>'
									inc	ecx
								.endw
							.else
								.while byte ptr[edi+ecx]!=39 && byte ptr[edi+ecx]!=0 && byte ptr[edi+ecx]!='>'
									inc	ecx
								.endw
							.endif
							.if byte ptr[edi+ecx]==34 || byte ptr[edi+ecx]==39
								inc	ecx
							.endif
							.while ebx<ecx
								mov	byte ptr[edi+ebx],32
								inc	ebx
							.endw
						.endif
					.endif
				.endif
			.else
				inc	ecx
			.endif
		.endw
		invoke	DeleteFile,addr fname1
		invoke	MoveFile,addr fname,addr fname1
		invoke	CreateFile,addr fname,GENERIC_WRITE,FILE_SHARE_READ,0,CREATE_ALWAYS,0,0
		push	eax
		push	0
		mov	edx,esp
		invoke	WriteFile,eax,edi,esi,edx,0
		pop	edx
		call	CloseHandle
		invoke	MessageBox,0,addr okmsg,addr fname,0
	.endif
	invoke	ExitProcess,0

end	start