;
; Program demonstrates how to run code from resource table in memory
; ---typedef
;

format pe gui 4.0

include 'win32a.inc'

entry main

section '.txt' code readable writeable executable

msg db 'hello world MessageBox from html resource file!',0

main:
	;The file must be saved in ANSI or else it will crash
 push RT_RCDATA ;can be any type
 push 12
 push 0
 call [FindResource]
 push eax
 call [GetCommandLine]
 xchg eax,edx
 pop  eax
 push MB_OK
 push edx
 push msg
 push 0
 ;replace 'o' with null char(The first byte of the MessageBoxA address)
 mov byte[eax+5],00
 jmp  eax ;call [MessagBoxA]

;return op code is in the html file

;MessageBox dummy, do not remove it. Yes it takes up space
;Make fasm import  it
invoke MessageBox,0,0,0,0

section '.idata' import data readable

library user32,'user32.dll',\
	kernel32,'kernel32.dll'

import user32,\
       MessageBox,'MessageBoxA'


import kernel32,\
       FindResource,'FindResourceA',\
       GetCommandLine,'GetCommandLineA'

section '.rsrc' resource data readable

directory RT_RCDATA,raw

resource raw,\
	 12,SUBLANG_DEFAULT,raw_data
resdata
 ;raw_data db 'ÿ','','`',' ','@',0,'Ã'
 raw_data file 'MessageBoxA.txt' ;db 'ÿ','','`',' ','@','o','Ã'
endres