Hello, as title says this is a tutorial/guide on how to compile ahk_h's source code with Visual Studio.
English is not my main language so any corrections will be appreciated. I'm not an expert, so all these steps will be exactly what I did to compile ahk_h. (some steps might not be needed).
2.4.1.1 Understanding how it works (read it before trying to change the pw)
First part: "A\0\0\0\0u\0\0\0\0t\0\0\0\0o\0\0\0\0H\0\0\0\0o\0\0\0\0t\0\0\0\0k\0\0\0\0e\0\0\0\0y\0\0\0\0"
Second part: [i*5]
The first part contains the password "AutoHotkey" separated with 4 "\0".
The second part "will pick" a character every 5 characters.
Examples
Example 1:
Spoiler
First part: "A\0\0\0\0u\0\0\0\0t\0\0\0\0o\0\0\0\0H\0\0\0\0o\0\0\0\0t\0\0\0\0k\0\0\0\0e\0\0\0\0y\0\0\0\0"
Second part: [i*5]
When i=0 i*5=0 = A
When i=1 i*5=5 = u
When i=2 i*5=10 = t
When i=3 i*5=15 = o
When i=4 i*5=20 = H
When i=5 i*5=25 = o
When i=6 i*5=30 = t
When i=7 i*5=35 = k
When i=8 i*5=40 = e
When i=9 i*5=45 = y
When i=10 i*5=50 = \0
Password = AutoHotkey <-- Length: 10
Example 2:
Spoiler
First part: "PsAjS#SJWFOnR9Da1p2E\0"
Second part: [i*2]
When i=0 i*2=0 = P
When i=1 i*2=2 = A
When i=2 i*2=4 = S
When i=3 i*2=6 = S
When i=4 i*2=8 = W
When i=5 i*2=10 = O
When i=6 i*2=12 = R
When i=7 i*2=14 = D
When i=8 i*2=16 = 1
When i=9 i*2=18 = 2
When i=10 i*2=20 = \0
Password = PASSWORD12 <-- Length: 10
Example 2:
Spoiler
First part: "AutoH87key\0"
Second part: [i*1]
When i=0 i*1=0 = A
When i=1 i*1=1 = u
When i=2 i*1=2 = t
When i=3 i*1=3 = o
When i=4 i*1=4 = H
When i=5 i*1=5 = 8
When i=6 i*1=6 = 7
When i=7 i*1=7 = k
When i=8 i*1=8 = e
When i=9 i*1=9 = y
When i=10 i*1=10 = \0
Password = AutoH87key <-- Length: 10
Remember you have to use the same length that you used on steps 2.1, 2.2, 2.3 and 2.4 (for the FINAL password, not for the string with \0)
To-do
Add how to make a dynamic password.
Troubleshooting: 1. "Missing dlls" and "couldn't link..." errors
Check if you followed the steps correctly. If you did then it might be because you updated Visual Studio and "$(LibraryPath)" changed to Spectre dlls but you didn't download Spectre libs.
There are 2 ways to fix it: Download Spectre library using Visual Studio Installer or inside Visual Studio do right click on "Autohotkey"->"Properties"->"C/C++"->"Code Generation" and search for "Spectre Mitigation" on the panel in the right side and change its value to "Disabled".
IMPORTANT
As said at the start EVERYTHING here was made thanks to Joe Glines's webinars, please if this guide was helpful for you go to this video like and subscribe because this guide is made by watching that video, if you liked the guide you liked the video: https://www.youtube.com/watch?v=ao5FdsqWTVQ and also part 2: https://www.youtube.com/watch?v=tiL_bIebTx4 and of course thanks to HotKeyIt for all you do for ahk's community.
Updates:
I forgot to thank HotKeyIt for making everything possible.
Added a Troubleshoot section
Updated step 2
Deleted Troubleshoot section as it was not needed anymore, added how to change password.
Fixed a typo in step 2.5
Added Troubleshoot section again .
Updated to new version of ahk_h
Old guide
Hello, as title says this is a tutorial/guide on how to compile ahk_h's source code with Visual Studio.
English is not my main language so any corrections will be appreciated. I'm not an expert, so all these steps will be exactly what I did to compile ahk_h. (some steps might not be needed).
IMPORTANT
As said at the start EVERYTHING here was made thanks to Joe Glines's webinars, please if this guide was helpful for you go to this video like and subscribe because this guide is made by watching that video, if you liked the guide you liked the video: https://www.youtube.com/watch?v=ao5FdsqWTVQ and also part 2: https://www.youtube.com/watch?v=tiL_bIebTx4 and of course thanks to HotKeyIt for all you do for ahk's community.
1. Installing Visual Studio 2017 Community Edition
After downloading it, open it.
When you open it you will see a menu that has a lot of checkboxes like this one: (I can't see the menu you will see because I have VS already installed, please if anyone can send me an image of the menu you see after opening the exe it will be really helpful)
Spoiler
Make sure you check the following:
Spoiler
1. Compiling ahk_h's source code 1.1. Opening source code in Visual Studio
Double click AutoHotkey.sln (file downloaded from github), wait until it finishes loading. You will receive a message like this one:
Spoiler
Select latest Windows SDK Version (prob first option) and remember the version (write it somewhere, we will use 10.0.17763.0 for this tutorial) and Upgrade to v141 on Platform Toolset (like on the image).
Click OK, wait until it finishes, might take minutes to finish.
1.2. Setting Autohotkey as StartUp project
Right click Autohotkey and click on "Set as StartUp project":
Spoiler
1.3. Adding SDK include directory
Right click Autohotkey and go to properties:
Spoiler
Select Platform and Configuration:
Spoiler
Click on VC++ Directories:
Spoiler
Remember I said that you have to write SDK version somewhere? We need it now, on Include Directories (on the right side) add the following: 'C:\Program Files (x86)\Windows Kits\10\Include\HERE GOES THE VERSION\shared';
Spoiler
And click OK.
You will have to repeats this step with each of the following:
Configuration: Release, ReleaseDll, ReleaseDllMini and Self-Contained.
And for each configuration you have to do the same steps for x32 and x64 Platform (I think you can choose "All Platforms" for this step, but not sure).
1.4. Adding $(LibraryPath); to Library Directories
Right click Autohotkey and go to properties:
Spoiler
On Library Directories (on the right side) add the following BEFORE DOING CHECK IF IT'S NOT ALREADY THERE: $(LibraryPath);
Spoiler
Click OK
You will have to repeats this step with each of the following:
Configuration: Release, ReleaseDll, ReleaseDllMini and Self-Contained.
And for each configuration you have to do the same steps for x32 and x64 Platform (I think you can choose "All Platforms" for this step, but not sure).
1.5. Compiling the source
Click on Build -> Batch Build...
Spoiler
Check the following (for both x32 and x64):
Release:
Spoiler
ReleaseDll:
Spoiler
ReleaseDllMini:
Spoiler
Self-Contained:
Spoiler
Click on Build.
Wait until it finishes.
You have compiled ahk_h's source now.
1.6. Cleaning up and packing
Execute CleanUpAndPack.exe (file downloaded from github inside ahk_h's source)
Then go to bin and you will see 2 folders:
Spoiler
You will see both contain 2 dlls (mini and normal one) an exe and a bin file. These are the files needed to compile your scripts.
2. Changing default password 2.1. Getting all g_default_pwd's references
On the left side click on the arrow next to "Autohotkey" then on the arrow next to "Source Files" and double click "util.cpp"
Spoiler
Press ctrl+f, set the search to current document and write "g_default_pwd" and press the arrow.
Spoiler
Select g_default_pwd, right click and select "Find All References"
Spoiler
Important: If you don't want to change ahk_h's default password length you can skip steps 2.2, 2.3 and 2.4 2.2. First reference (globaldata.cpp)
Click the 1st reference:
Spoiler
Here you have to add/remove TCHAR g_default_pwd NUMBER = 0; depending on your password's length:
Example 1 (default password, length = 10)
Spoiler
Example 2 (custom password, length = 3)
Spoiler
Example 3 (custom password, length = 15)
Spoiler
You have to add/remove &g_default_pwd NUMBER, depending on your password's length:
Example 1 (default password, length = 10)
2.3. Second reference (globaldata.h)
Click the 2nd reference:
Spoiler
Here you have to add/remove extern TCHAR g_default_pwd NUMBER; depending on your password's length:
Example 1 (default password, length = 10)
Spoiler
Example 2 (custom password, length = 3)
Spoiler
Example 3 (custom password, length = 15)
Spoiler
2.4. Third reference (script.cpp)
Click the 3nd reference:
Spoiler
Here you have to update the for with the new length for (int i = 0; i < NUMBER; i++) depending on your password's length:
Example 1 (default password, length = 10)
to your new password.
This line contains 2 important parts (read both of them and then you will understand how it works):
1_ "A\0\0\0\0u\0\0\0\0t\0\0\0\0o\0\0\0\0H\0\0\0\0o\0\0\0\0t\0\0\0\0k\0\0\0\0e\0\0\0\0y\0\0\0\0"
Spoiler
This contains our password (default is: AutoHotkey), as you can see there is 4 "\0" between each character, those are not part of our password, they are there only to make it a little harder to find / understand the password.
2_ [i*5]
Spoiler
This part is the one that "selects"/"picks" the characters from the definition (TCHAR) _T("A\0\0\0\0u\0\0\0\0t\0\0\0\0o\0\0\0\0H\0\0\0\0o\0\0\0\0t\0\0\0\0k\0\0\0\0e\0\0\0\0y\0\0\0\0"), it is i*5 because we have our password's characters every 5 characters: "A\0\0\0\0u\0\0\0\0t\0\0\0\0o\0\0\0\0H\0\0\0\0o\0\0\0\0t\0\0\0\0k\0\0\0\0e\0\0\0\0y\0\0\0\0"
When i=0 i*5=0 = A
When i=1 i*5=5 = u
When i=2 i*5=10 = t
When i=3 i*5=15 = o
When i=4 i*5=20 = H
When i=5 i*5=25 = o
When i=6 i*5=30 = t
When i=7 i*5=35 = k
When i=8 i*5=40 = e
When i=9 i*5=45 = y
The values between your password's characters, in this case "\0", can be any character you want.
Example 1: (password = "AutoHotkey", [i*2])
Spoiler
"A\0u\0t\0o\0H\0o\0t\0k\0e\0y\0"
Example 2: (password = "abc", [i*1])
Spoiler
"abc"
Example 3: (password = "abc", [i*2])
Spoiler
"a1b2c3"
Example 4: (password = "Hotkey", [i*5])
Spoiler
"H1234o5678t9876k5432e1234y"
Remember that you have to respect the length you specified before.
To-do: Add how to make a dynamic password.
Troubleshooting: 1. "Missing dlls" and "couldn't link..." errors
Check if you followed the steps correctly (specially 1.4). If you did then it might be because you updated Visual Studio and "$(LibraryPath)" changed to Spectre dlls but you didn't download Spectre libs.
There are 2 ways to fix it: Download Spectre library using Visual Studio Installer or inside Visual Studio do right click on "Autohotkey"->"Properties"->"C/C++"->"Code Generation" and search for "Spectre Mitigation" on the panel in the right side, change its value to "Disabled".
IMPORTANT
As said at the start EVERYTHING here was made thanks to Joe Glines's webinars, please if this guide was helpful for you go to this video like and subscribe because this guide is made by watching that video, if you liked the guide you liked the video: https://www.youtube.com/watch?v=ao5FdsqWTVQ and also part 2: https://www.youtube.com/watch?v=tiL_bIebTx4 and of course thanks to HotKeyIt for all you do for ahk's community.
Updates:
1. I forgot to thank HotKeyIt for making everything possible.
2. Added a Troubleshoot section
3. Updated step 2
4. Deleted Troubleshoot section as it was not needed anymore, added how to change password.
5. Fixed a typo in step 2.5
6. Added Troubleshoot section again .
Last edited by kyuuuri on 03 Mar 2020, 02:36, edited 8 times in total.
For some reason my 2017 VC never ask to upgrade the solution when I open it. When I compile the scripts with my newly minted ahk2exe either nothing happens upon opening them or i get the can not extract AHK error.
Huge thanks to @kyuuuri and everyone else who made this guide possible… starting with HotkeyIt.
It's wonderful to have these step-by-step details.
Visual Studio 2019 just came out, so I have to ask: has anyone had success following these steps in VS2019?
Just upgraded from VS2015 and would prefer not to install VS2017 as well if that can be avoided.
Regarding WinSDK, substituted this string (the path exists):
Error C1047 The object or library file 'source\lib\libMinHook.x86.lib' was created with an older compiler than other objects; rebuild old objects and libraries
Thank you @HotKeyIt
Since there's no sln file provided with MinHook and I want to minimize suffering, I think I'll wait until someone releases a pre-compiled versions (as you suggested) done in VS2019. It's probably only a matter of months.
Set password from source code (ahkdll-master) ; compile script
1) got 990kb only compare to 2MB from ahkdll-v1-release-master
2) CleanUpAndPack.ahk
\ahkdll-master\bin\Win32a\AutoHotkey.exe
The system cannot find the path specified. do i need to build all?
Set password from source code (ahkdll-master) ; compile script
1) got 990kb only compare to 2MB from ahkdll-v1-release-master
2) CleanUpAndPack.ahk
\ahkdll-master\bin\Win32a\AutoHotkey.exe
The system cannot find the path specified. do i need to build all?
As HotKeyIt said, you need to build all if you don't want to adapt CleanUpAndPack.ahk
don't forget to make your own encryption techniques and to add more anti-debugging ones, otherwise it won't protect your scripts from being easily decrypted
and it's not compiling, it's packing and encrypting
don't forget to make your own encryption techniques and to add more anti-debugging ones, otherwise it won't protect your scripts from being easily decrypted
and it's not compiling, it's packing and encrypting
Might be good if you could provide some examples of added anti-debugging measures. A lot of people would probably not know what you mean by this or what additional steps they could take.
I did the whole process correctly, but it presents this error, can anyone help me?
It presents this error but compiles. Weird
Screenshot_4.png
Those are simple warnings, you can ignore them. Basically you have 7 warnings about deprecated / non-supported features, 4 truncation, and 2 that give you information about conflicts between libs.
I did the whole process correctly, but it presents this error, can anyone help me?
It presents this error but compiles. Weird
Screenshot_4.png
Those are simple warnings, you can ignore them. Basically you have 7 warnings about deprecated / non-supported features, 4 truncation, and 2 that give you information about conflicts between libs.
Thank you bro!
I'm trying to compile only the .exe that I need, in this case: \bin\x64w
But it has an error, it only works when I set ALL compilation options. This really makes it a very slow process, and I don't even use the other compiled files.
Would there be any way to compile just the .exe that I need without error?
----------------------------------------------------------- Stop to think, shut up to resist, and act to win!