[TOOL] AHK Dynamic Obfuscator L - Protect your code by Obfuscation

Post your working scripts, libraries and tools for AHK v1.1 and older
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

[TOOL] AHK Dynamic Obfuscator L - Protect your code by Obfuscation

31 May 2018, 03:36

Image

AHK obfuscation tool entirely written in AHK, fully documented, and open-source ;)

It can help protecting your code (uncompiled, or compiled). It does that by:
  • ✔ Obfuscating your code
    AND optionally:
    ✔ Removing all your comments
    ✔ Stripping all whitespaces and empty lines
    ✔ Scrambling all your code together so that there is no logical order.
Automatic obfuscation means basically that it will rewrite your code differently so the code is very difficult to understand.
**********************************************************
:!: DISCLAIMER :!:
This is an advanced tool and therefore is not meant for beginners.

I would like this topic to be focused on the tool itself, use, documentation , bugs and ways of improving it.
If you want to discuss general subjects such as your views on obfuscation and code protection techniques that you dislike please open another topic in a discussion section and I can link it from there for those interested.
Code protection is a complex topic I would encourage users to research and understand. There exist different techniques and no protection method is infallible. Also AHK is difficult to protect.
DO NOT post encrypted scripts in the Script and Functions forum (except in this very topic)
**********************************************************

Hi all, I'm glad to finally being able to release this tool officially :P .

It took me a long time and I know some of you already found it on GitHub/Google before this official release :lol: but I wanted to have it in a good shape, along with a good documentation and all.

I've used it to obfuscate a major innovative note-taking software of more than 70.000 lines I was developing for several years that I've presented there:

EverFastAccess: Take Notes on Anything from Anywhere.

So this tool can be used for recent AHK project, with more use for bigger project.

A code like this

Code: Select all

ValueFromList(P_Index,P_List,Delim="|") {
global
local found
;This function returns the value from a list index
	if (Delim=#Bar#)
	P_List:=StrReplace(P_List, #DBar#, #Bar#)
	Loop, Parse, P_List, % Delim
		if (P_Index = A_Index)
			found:=A_LoopField
	return found
}
can look like this:

Code: Select all

kfk@#ff@kffk@f#f(#f#ffkff#ff@kk,ffk@f@fkk@@kff#k,k@kf#k@f#kkkf#f@="|") {
global
local kkk#@kfff#
if (k@k%kf#fff%%k@kfkfkk@f#f@k%#%@f@k#fk@fkf@@fkf%@f#kkkf#f@=f#f%f@kkffk@#kf#fkfk#f#k%fk%f@#f%kf)
ffk@%#ff#@f@k%f@fkk@@%@fkf@fk@k@@ff@kf%ff#k:=%k#kkf@k#%%#fk@k#@k@f#f%%@ff@kf%%k@kk%%kkf@f#kkkk#fff@k%%#ff#@f@k%(%k@f##kk#%%k@@f#kfkkfk#kkk@fffk%%k@f@%, %#k@k%%@f@k@f%%f##k@k#f#k@k%, f%kkfk%%#k#fk#k##k@fkk#kfk%f%#fk#kff@%kfkkf)
Loop, Parse, ffk%fkf#k@@ffk@kf@@kffkfff%%ffkkffk@@kfff#ff@kkf%@%#k@k#kk@%fkk@@kff#k, % k@k%kf@f%f%@k#kk#k@f@ffkk%k@%f@#f%f%#k#fk#k##k@fkk#kfk%kkkf#f@
if (#f#%kk@kk#k##fk@#fffff#f#k@k%%@kk#%fkf%kf@ff#f#kfkffk#ff@k#%#ff@kk = %kkf@f#@f%%fk#fff%%f#f#f@k@#kf#k#%%k#f#ff%%fkf##k%%@fkk@kfk@ffkf#%)
%ffk#%%kf#ff@f@%%f#kfk#@k%:=%kfffkk%%kf@f%%@kkk#kf#k@k#%%ff@fk@%%kffkf@#ff@#fkf%%fkf@f@%
return kk%@kkkkk@fk#f#ffk#fkf@%%k#f#@f#fffk#f@f@kkkkf#%@%k#@fkf%kfff#
}
**********************************************************
This project is a fork of the Obfuscator for Autohotkey scripts first release by David Malia (Dave) on the Autohotkey forums back in 2013.
I've spent 5 months full-time to be able to improve this quite complex project that required already quite massive work for the original version : correcting bugs, adding new capabilities, improving usability, and revamping the whole documentation, etc. Some of the changes can be found there: What's new

Also as this script is basically a huge parser, I thought of developping sub-projects that could do some code analysis and tell you statistics, information on possible dead codes etc.
It already gives you some stats about your code:
Image[/size]

It is functional and so much has been improved yet there are still remaining parts to improve but that would require some support/donations.
This project has required an important investment from my side and I am just not capable to spend more time on it without support right now, but let's see.


I hope this tool can help you protect your work and that this version will make it much more usable.
Please tell me if you were able to use it, how you like the documentation, which problems do you have and what could be improved.
Some answers are always pleasant ! ;)

**********************************************************
:!: GET IT ON GITHUB
:!: VIEW DOCUMENTATION
Last edited by DigiDon on 12 Nov 2019, 16:03, edited 28 times in total.
EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

Re: [TOOL] AHK Dynamic Obfuscator L - Protect your code by Obfuscation

31 May 2018, 03:37

UPDATES
v2.14 - 05/06
-No obfuscation for labels ending with Guiclose, GuiEscape etc.
Last edited by DigiDon on 05 Jun 2018, 15:57, edited 1 time in total.
EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

Re: [TOOL] AHK Dynamic Obfuscator L - Protect your code by Obfuscation

31 May 2018, 03:38

TODO (paused because lack of donations)
-gLabels or vVars : Regression : no %'s straight or dynamic vars introduced no more. --> Correct doc or make it work again
-ihidestr: ihidestr should be renamed hidestr in the "hidestring" example --> Correct the example
Last edited by DigiDon on 21 Aug 2018, 12:52, edited 2 times in total.
EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: [TOOL] AHK Dynamic Obfuscator L - Protect your code by Obfuscation

31 May 2018, 09:37

I hope to learn this, thank you for sharing.

I did my first test, this was the outcome

here was my ahk file

Code: Select all

;$OBFUSCATOR: $END_AUTOEXECUTE:
q::
WinGetTitle, yyy, A
msgbox, % yyy
ExitApp
I created the map and then had the program Obfuscate

The results was a new ahk file that has this

Code: Select all

obf_copyright := " Date: 5:31 PM Thursday, May 31, 2018           "
obf_copyright := "                                                "
obf_copyright := " THE FOLLOWING AUTOHOTKEY SCRIPT WAS OBFUSCATED "
obf_copyright := " BY DYNAMIC OBFUSCATOR L FOR AUTOHOTKEY         "
obf_copyright := " Adapted by DigiDon                             "
obf_copyright := "                                                "
obf_copyright := " Based on DYNAMIC OBFUSCATOR                    "
obf_copyright := " Copyright (C) 2011-2013  David Malia           "
obf_copyright := " DYNAMIC OBFUSCATOR is released under           "
obf_copyright := " the Open Source GPL License                    "


;HOTKEY ORIGINAL NAME: q
q::
WinGetTitle, yyy, A
msgbox, % yyy
ExitApp

What did I miss?
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

Re: [TOOL] AHK Dynamic Obfuscator L - Protect your code by Obfuscation

31 May 2018, 09:54

Hi AHKStudent,

You need to read the documentation more precisely.
Also check the examples.

In your simple case what can be obfuscated easily is the yyy variables by adding to your code

Code: Select all

;$OBFUSCATOR: $DEFGLOBVARS: yyy
You should also add at the top the command to specify the Straight Obfuscation mode

Code: Select all

;$OBFUSCATOR: $STRAIGHT_MODE:
OR put in place mandatory commands to be able to use dynamic obfuscation:
https://www.everfastaccess.com/AHK-Obfu ... ndumps.htm

For the msgbox, as is is a command you need to replace it with a function if you want it to be obfuscated, ie :

Code: Select all

msgbox("test")

msgbox(P_text) {
global
msgbox % P_text
}
EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: [TOOL] AHK Dynamic Obfuscator L - Protect your code by Obfuscation

31 May 2018, 10:01

Yeah I am reading the documentation now, very detailed, thank you

Edit: I managed to write a small program, created a few functions (it has no include files), I was able to compile it as exe and run on another machine no problems.

I admit I have no idea how in the world this works, but it works. Would love to understand how it works, general google search on obfuscation brings back all kinds of results, but the basic explanation on how its possible for something like ahk, to suddenly be able to read lines like:

Code: Select all

kkfkffk@@kff@f(@kfkfk@fkff@f@)


Without me including any information really boggles the mind.

Thank You, this is a remarkable useful tool especially as you pointed out for people selling a script etc.
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

Re: [TOOL] AHK Dynamic Obfuscator L - Protect your code by Obfuscation

31 May 2018, 18:26

Glad you got it working :)

Ahah there is no real magic :D

On the introduction about obfuscation documentation it says:
Obfuscation is the ability to disguise things under complicated names.
The first step is to rename all functions, labels, variables etc. to complicated and non logical names.
For example myfunction() will become ffk@fkfkk()
This program only uses "fk@#" characters to make up new names that resembles the others, creating extra-confusion.
So the basic step is renaming to non logical name just as if you were doing it right away yourself : instead of creating a function called msgbox() you would name it kkfkffk@@kff@f().
In this sense there is no secret that ahk could understand kkfkffk@@kff@f(@kfkfk@fkff@f@) as easily as msgbox(text)

But then come advanced things, notably by creating dynamic %'s variables that will contain also part of the new obfuscated name, and other advanced features ;)
EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: [TOOL] AHK Dynamic Obfuscator L - Protect your code by Obfuscation

31 May 2018, 18:52

DigiDon wrote:
But then come advanced things, notably by creating dynamic %'s variables that will contain also part of the new obfuscated name, and other advanced features ;)
That's what confuses me.

For example:

If I have a function now in AHK called abc(name) the only way I can call it is if I say abc(somedata)

Using the Obfuscation tool this is what I found:

Code: Select all


msgbox(yyy) was converted to kkfk%k@fk@fk#%ffk@@kff@f(k@ff%k@kkkf%#kf%f@#f%#@k)

and the first line of the function itself

msgbox(P_text) {    was converted to kkfkffk@@kff@f(@kfkfk@fkff@f@) {
My guess was that the function call and function would be a match but its not, I am happy it works this way but I cannot wrap my mind around how that is possible.
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

Re: [TOOL] AHK Dynamic Obfuscator L - Protect your code by Obfuscation

01 Jun 2018, 06:47

Yes otherwise it would be too easy to see where the different calls are.

Still in the documentation, it inserts between the name :

In the case of simple straight obfuscation :
empty %'s variables (they contain nothing but help hiding the real call)
In the case of dynamic obfuscation :
%'s variables that contains parts of the name, or single characters used to make the names, or empty variables. This results in many possibilities which makes it very difficult to understand the code.
EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

Re: [TOOL] AHK Dynamic Obfuscator L - Protect your code by Obfuscation

05 Jun 2018, 10:04

EDIT: Has been made automatic in 2.14
Last edited by DigiDon on 05 Jun 2018, 16:04, edited 1 time in total.
EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

Re: [TOOL] AHK Dynamic Obfuscator L - Protect your code by Obfuscation

05 Jun 2018, 16:03

Well it was kind of an overlooked spot. It has been corrected in the new version (I will try to put new updates on the second post)

In 2.14
-No obfuscation for labels ending with Guiclose, GuiEscape etc.

Therefore no need to force no-obfuscation for special GUI labels/functions anymore, which will be more intuitive ;)
PS: auto skipping of GUI functions is yet to be confirmed but it should work as well

There is no current support to hide Gui names, which would be quite complex actually because they could also be used in variables.
Workaround would be to always used an obfuscated variable for the name and use the GUI +LabelPrefix command and special obfuscation procedure.
I will add this in documentation when I have time.
EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates
alware
Posts: 8
Joined: 01 Jun 2018, 02:25

Re: [TOOL] AHK Dynamic Obfuscator L - Protect your code by Obfuscation

06 Jun 2018, 06:41

i am newbie.. and i have no idea how to use your code .
i guess its really hard for beginner to understand this... are there any files that i have to download beside your obfuscator.ahk?

i tried just running your program but doesn't run at all..(saying #include blahblah cannot be opened) i have read your documentation and your complete example.. but.. few things are not cleared for me
in the example you didn't include your dynamicobfuscator.ahk and how the hell did it obfuscate practice code you wrote..

if i have my own ahk script file, im pretty sure to include your code #include dynamicobfuscator.ahk and what?? does that give new encoded ahk file? so when i run the encoded ahk file it will run?

i guess its better if you put exact instruction from the scratch like downloading your file and using your file for the practice...
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

Re: [TOOL] AHK Dynamic Obfuscator L - Protect your code by Obfuscation

06 Jun 2018, 08:15

Hi alware,

Well yes as you said it will be hard for beginners to understand and actually I did not mean the tool for beginners.
Complex and useful obfuscation will be probably out of reach for someone who doesn't master AHK basics.
Actually I do not really understand why this tool would be useful to them. Indeed, why would you want to obfuscate a script that will be probably be basic?

I have added a line on the disclaimer about that.

Anyway, as for most ahk complex project you have to "download" the whole project on Github which contains multiple folders including "@@SOURCE-CODE" folder that contains all includes.
"dynamicobfuscator.ahk" is just the launcher.
EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates
guest3456
Posts: 3453
Joined: 09 Oct 2013, 10:31

Re: [TOOL] AHK Dynamic Obfuscator L - Protect your code by Obfuscation

06 Jun 2018, 08:53

DigiDon wrote: This project is a fork of the Obfuscator for Autohotkey scripts first release by David Malia (Dave) on the Autohotkey forums back in 2013.

Dave has since not continued improving this project due to personal reasons. And although the script was quite impressive, it was pretty complicated, manual for many parts, and did not encapsulate many of the innovations from the AHK language. Therefore it became very very hard to continue using it.

I therefore decided to improve it myself, and there was born the "Dynamic Obfuscator L" project.
I obviously respected the license by releasing the source code opened but decided to keep the spirit behind it to try to make it a tool others could use as well.
**********************************************************
thank you for your work sir. i remember the original project and i thought it as quite good, but it was pretty hard to get working properly. i haven't yet tried your updates, but i appreciate the work you've done!

guest3456
Posts: 3453
Joined: 09 Oct 2013, 10:31

Re: [TOOL] AHK Dynamic Obfuscator L - Protect your code by Obfuscation

06 Jun 2018, 08:59

AHKStudent wrote:For example:

If I have a function now in AHK called abc(name) the only way I can call it is if I say abc(somedata)

Using the Obfuscation tool this is what I found:

Code: Select all

msgbox(yyy) was converted to kkfk%k@fk@fk#%ffk@@kff@f(k@ff%k@kkkf%#kf%f@#f%#@k)

and the first line of the function itself

msgbox(P_text) {    was converted to kkfkffk@@kff@f(@kfkfk@fkff@f@) {
My guess was that the function call and function would be a match but its not, I am happy it works this way but I cannot wrap my mind around how that is possible.
because AHK allows dynamic function calls, where a variable can hold a function name.
look at this working AHK code:

Code: Select all

abc("hello world")

variable1 := "abc"
%variable1%("hello world 2")

variable2 := "c"
ab%variable2%("hello world 3")


abc(text)
{
   msgbox, %text%
}

DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

Re: [TOOL] AHK Dynamic Obfuscator L - Protect your code by Obfuscation

06 Jun 2018, 09:24

Hi guest3456,

It's great to hear that from you, I highly appreciate :D
I also found many people desperating that the tool was so complex and not up-to-date and was quite frustrated myself.

Through time I was able to simplify many ... many things (mostly by making a lot of automation but also by simplifying process, ...).
Some exemples:
-Possibility to obfuscate a single file without making an special include file (before that was mandatory)
-Obfuscator Include file using same AHK style so you can most often simply copy paste (before it was only full paths)
-Automatic switching to straight obfuscation when dynamic obfuscation is not possible (before it was all or nothing nearly or very manual)
-Autodetection of continuation section (before none)
-Simple new commands to switch mode, stop, ignore, etc.
...And the list goes on and on

I made a total revamp of the documentation (with syntax highlighting), providing simplier examples, improved capabilities, corrected many bugs and integrated special cases, ...

Would be gald to hear how you find the new version ;)
EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: [TOOL] AHK Dynamic Obfuscator L - Protect your code by Obfuscation

10 Jun 2018, 07:52

Been working with this now since you posted it, it is a great contribution!

Can you use mpress on an obfuscated script? I tried but it keeps all the code (obfuscated) as is.
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

Re: [TOOL] AHK Dynamic Obfuscator L - Protect your code by Obfuscation

10 Jun 2018, 08:11

Thanks AHKStudent. Glad you could put it to use without much troubles :).

Well although I do not use MPRESS, I would see no reason at all why obfuscated code could not go through it.
Are you sure Mpress worked correctly on your original script? If yes it should work on your obfuscated one as this is still AHK regular code.

Be advised that from what I've read Mpress and other packers can result in false antivirus flagging and that source code can still be pretty easily found.
EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: [TOOL] AHK Dynamic Obfuscator L - Protect your code by Obfuscation

10 Jun 2018, 09:20

DigiDon wrote:Thanks AHKStudent. Glad you could put it to use without much troubles :).

Well although I do not use MPRESS, I would see no reason at all why obfuscated code could not go through it.
Are you sure Mpress worked correctly on your original script? If yes it should work on your obfuscated one as this is still AHK regular code.

Be advised that from what I've read Mpress and other packers can result in false antivirus flagging and that source code can still be pretty easily found.
I will avoid mpress for now because of the false AV warnings plus the published script that decompiles mpress

I tried again and this time it did work with mpress, dont know what I did wrong when I tried earlier.

I love that it uses the letters fk so much, I know the documentation gives a logical reason for it, but I find it funny

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: MiM, Pareidol and 75 guests