flat assembler
Message board for the users of flat assembler.

Index > Windows > Is there a better way to wait for fasm to finish?

Author
Thread Post new topic Reply to topic
tthsqe



Joined: 20 May 2009
Posts: 767
tthsqe 04 May 2013, 09:16
I'm doing this in a 64 bit app.
Code:
invoke  ShellExecuteA,NULL,'open','E:\fasm\fdbg0024\fasm.exe','"E:\fasm\fdbg0024\test.asm"',NULL,NULL
invoke  Sleep,300    ; wait for FASM
invoke  CreateFileA,'E:\fasm\fdbg0024\test.bin',GENERIC_READ,0,0,OPEN_EXISTING,0,0    


edit by revolution: Title is more descriptive
Post 04 May 2013, 09:16
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19872
Location: In your JS exploiting you and your system
revolution 04 May 2013, 09:34
Doing what?
Post 04 May 2013, 09:34
View user's profile Send private message Visit poster's website Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 767
tthsqe 04 May 2013, 09:37
oh, I though it was clear from the code.
I am calling fasm from a 64 bit program and waiting for it to finish before opening the output file. Obviously, problems arise if fasm takes more than 0.3 seconds to compile...
Post 04 May 2013, 09:37
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19872
Location: In your JS exploiting you and your system
revolution 04 May 2013, 09:42
Sure there are much better ways. Probably not using the ShellExecute and instead use CreateProcess would be a start. That way you can wait on the handle and also get the exit code.
Post 04 May 2013, 09:42
View user's profile Send private message Visit poster's website Reply with quote
nmaps



Joined: 26 Oct 2012
Posts: 8
nmaps 05 May 2013, 20:26
Create a job or semaphore and have your process loop to check if it's finished (or WaitForObject).
Post 05 May 2013, 20:26
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
typedef 07 May 2013, 04:24
Use CreateProcess and watch it. Since you have control over it. Wink
Post 07 May 2013, 04:24
View user's profile Send private message Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 767
tthsqe 07 May 2013, 08:15
Thanks - I'm going to try CreateProcess. Smile
Post 07 May 2013, 08:15
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4324
Location: Now
edfed 07 May 2013, 08:17
or maybe read the binary file attributes to see if it's date is not older than N seconds. lol

if CreateProcess can return fasm state, it should be the solution.
Post 07 May 2013, 08:17
View user's profile Send private message Visit poster's website Reply with quote
Feryno



Joined: 23 Mar 2005
Posts: 503
Location: Czech republic, Slovak republic
Feryno 07 May 2013, 09:20
do it as revolution suggested
use the handle returned by CreateProcess and then you can call GetExitCodeProcess http://msdn.microsoft.com/library/windows/desktop/ms683189%28v=vs.85%29.aspx
if the return value is STILL_ACTIVE you must call it later again - e.g. some timeout (as the posted Sleep) or NtYieldExecution (exported from ntdll.dll)
Post 07 May 2013, 09:20
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1561
Location: Toronto, Canada
AsmGuru62 07 May 2013, 14:59
It is better to use CreateProcess() on separate thread and just WaitForSingleObject() on the handle.
Otherwise it is a loop on main thread which polls for STILL_ACTIVE and loads the CPU.
Post 07 May 2013, 14:59
View user's profile Send private message Send e-mail Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
typedef 07 May 2013, 23:28
AsmGuru62 wrote:
It is better to use CreateProcess() on separate thread and just WaitForSingleObject() on the handle.
Otherwise it is a loop on main thread which polls for STILL_ACTIVE and loads the CPU.

CreateEvent() / ResetEvent/ RaiseEvent on a separate thread would accomplish this.

Besides, WaitForSingleObject is a blocking API Wink
Post 07 May 2013, 23:28
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.