Sign in to follow this  
Followers 0
Klaatu

Macro for compiled console?

7 posts in this topic

In my script I would like to test to see if it was compiled using the console switch. Looking through help I see I can test whether or not the script is compiled, but I don't see a way to test for console compilation. Hopefully I'm just overlooking something obvious.

So it there such a macro like @compiledConsole?


My Projects:DebugIt - Debug your AutoIt scripts with DebugIt!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

#include <WinAPI.au3>

If CompiledConsole(@ScriptFullPath) Then
    MsgBox(0, "", "console!")
EndIf
Func CompiledConsole($sfile)
    Local $hFile, $nBytes, $tBuffer
    $tBuffer = DllStructCreate("byte[1]")
    $hFile = _WinAPI_CreateFile($sFile, 2, 2)
    _WinAPI_SetFilePointer($hFile, 1000)
    _WinAPI_ReadFile($hFile, DllStructGetPtr($tBuffer), 1, $nBytes)
    _WinAPI_CloseHandle($hFile)
    If(DllStructGetData($tBuffer, 1)) = 0xD4 Then
        Return True
    Else
        Return False
    EndIf
EndFunc

- May check itself or other exe's, BUT only if script was compiled with UPX(compression level doesn't matter)

Edited by GodlessSinner

_____________________________________________________________________________

Share this post


Link to post
Share on other sites

Thanks GS. I never would have figured that out on my own.

I'm a bit surprised there's not a built-in macro for this, however, as there's macros for almost everything else it seems. :(

Did you already have that bit of code laying around in your toolbox, just waiting for someone to ask? :)


My Projects:DebugIt - Debug your AutoIt scripts with DebugIt!

Share this post


Link to post
Share on other sites

Did you already have that bit of code laying around in your toolbox, just waiting for someone to ask?

- No. I spent for this ~ 6 minutes:)

_____________________________________________________________________________

Share this post


Link to post
Share on other sites

Knowing very little about APIs and DLLs and such, I have a few questions about the method you use to determine whether an app is compiled as console.

How "resilient", so to speak, is this code to changes in AutoIt itself? Will this have to be modified with new releases of AutoIt? Or is it more dependent on upx, and as long as it doesn't change you'll always be looking for a D4 at offset 1000?

Just curious to know when this method may "break". Thanks.


My Projects:DebugIt - Debug your AutoIt scripts with DebugIt!

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Knowing very little about APIs and DLLs and such, I have a few questions about the method you use to determine whether an app is compiled as console.

How "resilient", so to speak, is this code to changes in AutoIt itself? Will this have to be modified with new releases of AutoIt? Or is it more dependent on upx, and as long as it doesn't change you'll always be looking for a D4 at offset 1000?

Just curious to know when this method may "break". Thanks.

- Ha:), I don't know, what it means, just found first difference between "Console" and "Not Console" type of Script.exe

- To avoid error( that theoretically possible) you need also check if file is AutoitScript.exe(last bytes) and Compilled with UPX (few bytes before D4, see in HEX Editor for more understanding )

Best regards.

Edited by GodlessSinner

_____________________________________________________________________________

Share this post


Link to post
Share on other sites

OK. Thanks GS. Appreciate the reply. Have a good day.


My Projects:DebugIt - Debug your AutoIt scripts with DebugIt!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0