BASE_ADDR = $400000

format PE GUI 4.0 at BASE_ADDR
hInstance = BASE_ADDR

section '.bitRAKE' code import readable executable writeable

dd 0,0,0, RVA kernel_name,   RVA kernel_table
dd 0,0,0, RVA user_name,     RVA user_table
dd 0,0,0, 0,		     0

kernel_table:
	ExitProcess	     dd RVA _ExitProcess
	GetCurrentDirectoryA dd RVA _GetCurrentDirectoryA
	GetProcAddress	     dd RVA _GetProcAddress
	LoadLibraryA	     dd RVA _LoadLibraryA
	lstrcat 	     dd RVA _lstrcat
			     dd 0
user_table:
	CreateWindowExA      dd RVA _CreateWindowExA
	DefWindowProcA	     dd RVA _DefWindowProcA
	DispatchMessageA     dd RVA _DispatchMessageA
	GetClientRect	     dd RVA _GetClientRect
	GetMessageA	     dd RVA _GetMessageA
	GetSystemMetrics     dd RVA _GetSystemMetrics
	MessageBoxA	     dd RVA _MessageBoxA
	MoveWindow	     dd RVA _MoveWindow
	PostQuitMessage      dd RVA _PostQuitMessage
	RegisterClassExA     dd RVA _RegisterClassExA
	SendMessageA	     dd RVA _SendMessageA
	TranslateMessage     dd RVA _TranslateMessage
			     dd 0
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
include "%fasminc%/WIN32AX.INC"

WndProc:
	label .hWnd   dword at esp+4*1
	label .uMsg   dword at esp+4*2
	label .wParam dword at esp+4*3
	label .lParam dword at esp+4*4

	cmp [.uMsg],WM_SIZE
	je .WM_SIZE
	cmp [.uMsg],WM_DESTROY
	je .WM_DESTROY
	cmp [.uMsg],WM_CREATE
	je .WM_CREATE
	jmp [DefWindowProcA]

.WM_SIZE:
	push TRUE
	sub esp,sizeof.RECT
	invoke GetClientRect,[.hWnd+4+sizeof.RECT+4],esp
	push [g_hContainerWindow]
	call [MoveWindow]
	xor eax,eax
	retn 16

.WM_DESTROY:
	invoke PostQuitMessage,0
	xor eax,eax
	retn 16

.WM_CREATE:
	invoke LoadLibraryA,"ATL"
	invoke GetProcAddress,eax,"AtlAxWinInit"
	call eax
	invoke GetCurrentDirectoryA,MAX_PATH-7-12,_path
	invoke lstrcat,_name,"\frogleap.swf"

	invoke CreateWindowExA,0,"AtlAxWin",_name,\  ;"http://www.google.com",\
	  WS_VISIBLE or WS_CHILD,0,0,0,0,[.hWnd+12],0,hInstance,0
	xchg eax,[g_hContainerWindow]
	retn 16


WM_FORWARDMSG =$37F

CLASSNAME db "bitrake",0
class WNDCLASSEX sizeof.WNDCLASSEX,0,WndProc,0,0,hInstance,0,0,0,0,CLASSNAME,0

g_hContainerWindow dd 0

entry $
	xor ebp,ebp
	invoke GetSystemMetrics,SM_CXSCREEN
	mov esi,eax
	invoke GetSystemMetrics,SM_CYSCREEN
	mov edi,eax

	invoke RegisterClassExA,class

	invoke CreateWindowExA,WS_EX_CONTROLPARENT,\
	  CLASSNAME,CLASSNAME,\
	  WS_VISIBLE or WS_CLIPCHILDREN or WS_POPUP,\
	  ebp,ebp,esi,edi,ebp,ebp,hInstance,ebp
	mov ebx,msg
	jmp .get
.msg:	invoke TranslateMessage,ebx
	invoke SendMessageA,[g_hContainerWindow],WM_FORWARDMSG,ebp,ebx
	test eax,eax
	jne .get
	invoke DispatchMessageA,ebx
.get:	invoke GetMessageA,ebx,ebp,ebp,ebp
	test eax,eax
	je .x
	inc eax
	jne .msg

.x:	invoke ExitProcess,eax
	retn

;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

kernel_name db 'KERNEL32',0
_ExitProcess	      db 0,0,'ExitProcess',0
_GetCurrentDirectoryA db 0,0,'GetCurrentDirectoryA',0
_GetProcAddress       db 0,0,'GetProcAddress',0
_LoadLibraryA	      db 0,0,'LoadLibraryA',0
_lstrcat	      db 0,0,'lstrcat',0

user_name db 'USER32',0
_CreateWindowExA  db 0,0,'CreateWindowExA',0
_DefWindowProcA   db 0,0,'DefWindowProcA',0
_DispatchMessageA db 0,0,'DispatchMessageA',0
_GetClientRect	  db 0,0,'GetClientRect',0
_GetMessageA	  db 0,0,'GetMessageA',0
_GetSystemMetrics db 0,0,'GetSystemMetrics',0
_MessageBoxA	  db 0,0,'MessageBoxA',0
_MoveWindow	  db 0,0,'MoveWindow',0
_PostQuitMessage  db 0,0,'PostQuitMessage',0
_RegisterClassExA db 0,0,'RegisterClassExA',0
_SendMessageA	  db 0,0,'SendMessageA',0
_TranslateMessage db 0,0,'TranslateMessage',0

;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

_name:	db "file://"
_path:	rb MAX_PATH - 7

msg MSG

