How to use mcode to encrypt source code? Are there any ready-made tools?

Get help with using AutoHotkey and its commands and hotkeys
afe
Posts: 616
Joined: 06 Dec 2018, 04:36

How to use mcode to encrypt source code? Are there any ready-made tools?

22 Oct 2020, 06:35

How to use mcode to encrypt source code? Are there any ready-made tools?
I don't understand mcode. Is it possible to encrypt the source code into an EXE and no longer need AutoHotKey.exe when running it?
User avatar
boiler
Posts: 6602
Joined: 21 Dec 2014, 02:44

Re: How to use mcode to encrypt source code? Are there any ready-made tools?

22 Oct 2020, 07:57

Mcode won’t help you do this.

When you compile a script, it includes the AHK interpreter in the resulting .exe file so you don’t need a separate AHK executable. You cannot encrypt the script’s source code, though. You can help hide it from casual would-be hackers by employing one of the compression techniques like MPress. That usually increases the chances that the .exe will get flagged by anti-virus software as malicious, in case that’s important to you.

AutoHotkey_H allows you the option to password protect your source code, although it requires re-compiling the AutoHotkey_H C++ source code with your password. There is a thread in that sub-forum that guides you through that process.
SOTE
Posts: 1139
Joined: 15 Jun 2015, 06:21

Re: How to use mcode to encrypt source code? Are there any ready-made tools?

22 Oct 2020, 11:47

afe wrote:
22 Oct 2020, 06:35
How to use mcode to encrypt source code? Are there any ready-made tools?
I don't understand mcode.
You can see an example of such by referring to Encryptor by FeiYue.
https://www.autohotkey.com/boards/viewtopic.php?f=28&t=42494

To better understand MCode in particular, you can refer to the below links for starters:

https://www.autohotkey.com/boards/viewtopic.php?t=32
(MCode Tutorial (Compiled Code in AHK))

https://www.autohotkey.com/boards/viewtopic.php?t=4642
(MCode4GCC -- C/C++ to MCode Generator)

https://www.autohotkey.com/boards/viewtopic.php?t=73099
(Online MCode Generator(Beta, Tool))

But, there are some things to keep in mind:

1. AutoHotkey is an interpreted language, like C#, Python, Java, JavaScript...

As such, there are various way to circumvent the encryption or obfuscation of source code. If you are trying to get protection at the same levels of an compiled language, then better to go program in such languages instead. C, C++, Pascal/Object Pascal, Go, Red, etc...

Compiled languages aren't hackerproof or "safe havens" either. Though the source code can't be recovered with compiled languages, you can generate pseudo C code from the machine/assembly code. Furthermore, hackers/crackers have ways of manipulating and reading code at the machine/assembly level and in memory.

You should not have the expectation of making any program hackerproof or that experienced professional programmers can't figure it out (if they choose to invest time into it). At best, you are making the code too difficult for casuals to want to be bothered.

2. MCode requires that you have an advanced understanding of AutoHotkey, and some understanding of C or C++.

This requires the person invests time into study, and not have the expectation that answers will always be easy to come by.
SOTE
Posts: 1139
Joined: 15 Jun 2015, 06:21

Re: How to use mcode to encrypt source code? Are there any ready-made tools?

23 Oct 2020, 06:13

afe wrote:
22 Oct 2020, 06:35
Is it possible to encrypt the source code into an EXE and no longer need AutoHotKey.exe when running it?
I think this part of your question needs an answer which expands upon it a bit more. As AutoHotkey is an interpreted language (like Python, C#, Java, JavaScript), it will always need its interpreter to execute. Which would be AutoHotkey.exe, in our language. Be that externally or through binding with it to create an .exe (which we call "compile" for convenience of understanding). The AutoHotkey script that people write, is a series of instructions to the AutoHotkey interpreter.

To have your source code no longer need the AutoHotkey interpreter, means you have manually rewritten it into a compiled programming language or used a transpiler (which is more like automatic translation into another compiled programming language). As no transpiler for AutoHotkey to another compiled language is known to exists (and it would be very hard to create such), then that means the person needs to manually translate their source code to the other language.

Other, somewhat intermediate options do exists, among those would be MCode or creating your own DLL. In those cases, the person is taking functions from a compiled language that they have written or got from elsewhere, and turns it into machine code to be executed by the MCode function in the script or compiles them into a .dll file that is executed by DllCall(). The machine code used by the MCode function or .dll is not in human readable form. For casuals looking upon machine code in a script or .dll file, they will likely not know what it is or simply don't want to take the time or get headaches from bothering with it.

However, all machine code can be directly and automatically translated into Assembly language code. There is an almost 1 to 1 correspondence. This is why compiled programming languages like C, C++, Pascal/Object Pascal, Go, Swift, etc... are not safe havens from hackers/crackers. Some people are very good at understanding, manipulating, and writing in the more difficult and tedious Assembly language. Furthermore, as mentioned, Assembly code can also be automatically turned into pseudo C code. While the pseudo C code or Assembly code is not the source code of the original program, upon careful analysis by skilled or professional programmers, it allows for clear understanding of what the program is doing.
afe
Posts: 616
Joined: 06 Dec 2018, 04:36

Re: How to use mcode to encrypt source code? Are there any ready-made tools?

16 Nov 2020, 10:39

You can see an example of such by referring to Encryptor by FeiYue.
https://www.autohotkey.com/boards/viewtopic.php?f=28&t=42494
Oh, no. Don't mention this. I tested it today. The script has only two lines of code.

Code: Select all

Msgbox OK
return
After compiling and running, it looked like a virus. Not only did it not execute as expected, but there were multiple script processes in the task management. I wanted to end it. As a result, there were more and more processes. Something unreliable.
SOTE
Posts: 1139
Joined: 15 Jun 2015, 06:21

Re: How to use mcode to encrypt source code? Are there any ready-made tools?

16 Nov 2020, 13:51

afe wrote:
16 Nov 2020, 10:39
You can see an example of such by referring to Encryptor by FeiYue.
https://www.autohotkey.com/boards/viewtopic.php?f=28&t=42494
Oh, no. Don't mention this. I tested it today. The script has only two lines of code.

Code: Select all

Msgbox OK
return
After compiling and running, it looked like a virus. Not only did it not execute as expected, but there were multiple script processes in the task management. I wanted to end it. As a result, there were more and more processes. Something unreliable.
My mentioning of MCode in regards to Encryptor, is referring to the user being able to replace FeiYue's machine code function with their own machine code function for encrypting a script. FeiYue has even given an example of the C code he used on that thread (go to the bottom of the Encryptor script to see it). It's up to the person to learn MCode and understand how FeiYue's Encryptor works. FeiYue has even provided additional help on using MCode, with his own guide and conversion program. It's in Chinese, but you can use Google Translate to get the English version. https://www.autohotkey.com/boards/viewtopic.php?t=18405

And as for a specific problem on how to use Encryptor or if a recent version of the script is having an issue, the person should post that question on the Encryptor thread. FeiYue would be the best person to fix a problem with the script he created.

Saying that Encryptor is a virus, is inappropriate and showing a lack of understanding. FeiYue provides the source code of his script, except for the exact C language encryption algorithm code in which he used to do the encryption (that is hidden in machine code). He has to hide that part, otherwise anybody could decrypt it, but does give the source for the rest of the C code (and an example algorithm). Any user is free to replace his machine code function with their machine code function, as I mentioned previously. If the latest version of FeiYue's script is having a problem, it's more likely a bug.

There is always the choice of using AutoHotkey_H (https://www.autohotkey.com/boards/viewforum.php?f=65). It can provide protection right out of the box, either by using it's compression option and/or default password. There is a very well written guide in that sub-forum on how to recompile AutoHotkey_H, if the person seeks to change the password used for the encryption, and is willing to install Visual Studio and deal with a bit of C/C++.

Return to “Ask For Help”

Who is online

Users browsing this forum: anv, effel, JAutohotkey, mikeyww, teadrinker and 48 guests