Ah, now this is much better. After I've merged my previous script with ASM function - 120 MB file processed in 9 seconds!
About my second question - here is an example.
set memory_file binary "\xEB\x06\x90\x90\x00\x00\x00\x00\xE8\x00\x00\x00\x00\x58\x83\xC0\xF7\xC7\x00\x78\x56\x34\x12\xC3"
calldll memory_file 0 stdcall ""
Asm code source:
my_static_variable dd 0
; this block calculates virtual address of variable
add eax, (my_static_variable - @b)
mov dword [eax], 0x12345678
Function causes "access violation" exception.
It is happens because the memory page which contains my code doesn't have a permission to be written.