Ahk2Exe - Replacement of certain variables incorrect

Report problems with documented functionality
TAC109
Posts: 1111
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Ahk2Exe - Replacement of certain variables incorrect

30 May 2019, 21:44

When Ahk2Exe processes #Include's, the replacement of the variables A_AhkVersion, A_IsUnicode, and A_PtrSize are not handled correctly. These variables are incorrectly replaced by an empty string.

This can be demonstrated by trying to compile the following program. This, of course will fail as the file to be included is nonsensical and does not exist, but the error msgbox shows the attempted replacements. (A_WinDir is included to show that the replacements are shown in the msgbox.)

Code: Select all

#include Version=+%A_AhkVersion%+ PtrSize=+%A_PtrSize%+ IsUnicode=+%A_IsUnicode%+ A_WinDir=+%A_WinDir%+
I believe that the problem lies in the file lib\AhkType.ahk, which was updated recently. This file/function is called by ScriptParser.ahk (145) and Compiler.ahk (35), and it is the latter call that is returning false.

Please note that I have forked Ahk2Exe to TAC109 on GitHub, where I am working on the Compiler Directives enhancements in the Edge branch. I would have fixed this problem myself, but it looks rather complicated.

Thanks.
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Ahk2Exe - Replacement of certain variables incorrect

01 Jun 2019, 01:32

I believe that the problem lies in the file lib\AhkType.ahk, which was updated recently.
That is accurate. It was updated when the compiler was updated to support more variables in #include. Prior to that, only %A_ScriptDir%, %A_AppData%, %A_AppDataCommon% and %A_LineFile% were supported. AhkType is used to determine the values of A_AhkVersion, A_PtrSize and A_IsUnicode.

I'm not sure how it passed my testing, since AhkType does not work with AutoHotkeySC.bin files, and never did:

Code: Select all

if !InStr(FileDescription, "AutoHotkey")
    return
The "file description" string is omitted from AutoHotkeySC.bin, possibly for the same reason "AutoHotkey" is omitted from the window title:
// One reason for this is to reduce backlash if evil-doers create viruses and such
// with the program.
Without it, we need to find some other way to determine whether the executable is Unicode or ANSI. In theory, it could be done by looking at which functions are imported, but it doesn't seem worthwhile. A_PtrSize can be determined by the machine type (exeMachine).

I think I'll just remove them from the list of supported variables for now, and fix A_AhkVersion and A_PtrSize for future versions.
TAC109
Posts: 1111
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Ahk2Exe - Replacement of certain variables incorrect

01 Jun 2019, 05:13

Thanks.

In the mean time I’ve coded a temporary workaround for now. You can see it in the edge branch. It’s rather simplistic, but supplies all the missing data for now:-

Code: Select all

	if !(BinType.Version)   ; Temporary workaround for AhkType() bug
		{
			FileGetVersion ver, %ExeFileTmp%
			DerefIncludeVars.A_AhkVersion := ver
	
			FileGetSize size, %ExeFileTmp%
			Loop Files, %A_ScriptDir%\*bit.bin
			{ if (A_LoopFileSize = size)
				{
					DerefIncludeVars.A_PtrSize   := InStr(A_LoopFileName,64) ? 8 : 4
					DerefIncludeVars.A_IsUnicode := InStr(A_LoopFileName,"Unicode") ? 1 : ""
		}	}	}
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 54 guests