Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there a way to obtain the same result than set compiler flags at runtime for PEFlags?

years ago i stumbled in the C0000006 external exception when running a large (100+MB) exe from a shared folder on some particular LANs. So I started using the compiler flags described in this question.

After years of succesful "execution of exe" on hundreds of customers in hundreds of networks i started having problems with the PE flags (somehow the exe was crashing at startup on same pcs and excluding one cause at a time i empirically found that commenting those flags was working).

Somehow the workaround i found is to build my exe twice (and let the customer choose which one to deploy), the first with these:

{$SetPEFlags IMAGE_FILE_NET_RUN_FROM_SWAP}
{$SetPEFlags IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP} 

and the second commenting those.

This building overhead is annoying and I would like to avoid it. I do not think there is a way, but i ask for expert advice: is there a way to "activate those flags at runtime?" for example passing a command line parameter?

Another workaround i thought of is to copy locally the exe as the exe starts, so that it is always executed from the local machine, but I fear the scenarios i need to face, even if technically it is simple.

Thanks.

like image 880
LaBracca Avatar asked Oct 03 '18 07:10

LaBracca


1 Answers

Is there a way to activate these flags at runtime, for example by passing a command line parameter?

No there is not. These PE flags are processed by the system loader, and the outcome is determined before any code in the executable is executed.

Another workaround I thought of is to copy locally the exe as the exe starts, so that it is always executed from the local machine.

That is precisely the effect that these PE flags have. If the executable file resides on a network volume, or a removable volume, then it is first copied to the swap file (a local file), and then executed.

like image 82
David Heffernan Avatar answered Sep 20 '22 02:09

David Heffernan