AHK Code Obfsucation Protection

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
caeee
Posts: 7
Joined: 29 Jan 2024, 08:55

AHK Code Obfsucation Protection

23 Mar 2024, 06:49

Hey there, pretty weird title but bear with me. Is it possible to create a function inside a script, that basically ruins/breaks the script source code itself and makes it impossible to get it back? (i.e: not deleting it, because you could retrieve it from Recycle Bin for example)

So let's take this example:

Code: Select all

; index.ahk
msgbox % "my ahk version: " A_AhkVersion
return
The function would write to index.ahk and turn it into unreadable, non-functional code.
Like this (or something similar):

Code: Select all

; Unreadable jibberish
Tmzasgqbweorxt y%@y ~!"mz!232y Yy1hfsda235h^k esxvesaeefrtywe2Y2si41hoynuasd:yt231 !~"yasd qwe23A53_235A6SDh23kVdasfe6das0rdsasdioqwen
adsrasdeaqw12!t23$uasd$%r%n!
; Basically what I did was inserted random amount of characters & random characters between every new character.
User avatar
mikeyww
Posts: 27178
Joined: 09 Sep 2014, 18:38

Re: AHK Code Obfsucation Protection

23 Mar 2024, 07:26

:arrow: Delete one or more files permanently

Various disk and data recovery programs are available, as well as programs to wipe an area of the disk. I imagine that unless the disk area itself is wiped, a file might be recoverable by accessing the disk directly. Today's data recovery programs are quite good and can scan the disk for all data, regardless of whether the data are indexed in a file table. A wiping program would need to locate the entire file on disk-- realizing that some files are not represented contiguously-- and then replace those blocks with other data.
The only way to ensure that deleted files, as well as files that you encrypt with EFS, are safe from recovery is to use a secure delete application. Secure delete applications overwrite a deleted file's on-disk data using techniques that are shown to make disk data unrecoverable, even using recovery technology that can read patterns in magnetic media that reveal weakly deleted files. SDelete (Secure Delete) is such an application. You can use SDelete both to securely delete existing files, as well as to securely erase any file data that exists in the unallocated portions of a disk (including files that you have already deleted or encrypted). SDelete implements the Department of Defense clearing and sanitizing standard DOD 5220.22-M, to give you confidence that once deleted with SDelete, your file data is gone forever. Note that SDelete securely deletes file data, but not file names located in free disk space.
Source: SDelete - Sysinternals | Microsoft Learn
A script can usually act upon its own file while the script is handled in memory by AutoHotkey.
User avatar
andymbody
Posts: 937
Joined: 02 Jul 2017, 23:47

Re: AHK Code Obfsucation Protection

23 Mar 2024, 10:02

caeee wrote:
23 Mar 2024, 06:49
ruins/breaks the script source code itself and makes it impossible to get it back
I would say yes, but I'm curious... what would be the use case?

Why not just overwrite the file with.

Code: Select all

### overwritten ###
Or remove all content within file, period?
Last edited by andymbody on 23 Mar 2024, 10:06, edited 1 time in total.
User avatar
mikeyww
Posts: 27178
Joined: 09 Sep 2014, 18:38

Re: AHK Code Obfsucation Protection

23 Mar 2024, 10:06

This might work with a file object, could be worth testing.
Last edited by mikeyww on 23 Mar 2024, 10:13, edited 2 times in total.
User avatar
andymbody
Posts: 937
Joined: 02 Jul 2017, 23:47

Re: AHK Code Obfsucation Protection

23 Mar 2024, 10:10

mikeyww wrote:
23 Mar 2024, 10:06
This might work with a file object, could be worth testing.
Hmm... I will have to look into binary writes in AHK. As far as I recall, I have not had to delete files (when using other languages), to overwrite their contents
User avatar
mikeyww
Posts: 27178
Joined: 09 Sep 2014, 18:38

Re: AHK Code Obfsucation Protection

23 Mar 2024, 10:12

Code: Select all

#Requires AutoHotkey v1.1.33.11
FileGetSize bytes, % A_ScriptFullPath
fileObj := FileOpen(A_ScriptFullPath, "w")
Loop % bytes
 fileObj.Write(0)
fileObj.Close()
Run % "notepad.exe """ A_ScriptFullPath """"
Last edited by mikeyww on 23 Mar 2024, 10:18, edited 1 time in total.
User avatar
andymbody
Posts: 937
Joined: 02 Jul 2017, 23:47

Re: AHK Code Obfsucation Protection

23 Mar 2024, 10:17

lol... don't you just hate when more than one person is posting a reply at same time?
User avatar
mikeyww
Posts: 27178
Joined: 09 Sep 2014, 18:38

Re: AHK Code Obfsucation Protection

23 Mar 2024, 10:19

Absolutely, but I'm often all three of them! :crazy:
caeee
Posts: 7
Joined: 29 Jan 2024, 08:55

Re: AHK Code Obfsucation Protection

23 Mar 2024, 10:20

andymbody wrote:
23 Mar 2024, 10:02
caeee wrote:
23 Mar 2024, 06:49
ruins/breaks the script source code itself and makes it impossible to get it back
I would say yes, but I'm curious... what would be the use case?

Why not just overwrite the file with.

Code: Select all

### overwritten ###
Or remove all content within file, period?
Well..sometimes I do AHK snippets for people for a quick buck. I recently got scammed, though, so I am thinking of a protection that destroys the script's functionality if a specific condition is not met. I'm not sure if this goes against the rules of the board in any way so I am sorry if it does, in advance. I'm not looking to obfuscate the code, because it'd still work.
User avatar
andymbody
Posts: 937
Joined: 02 Jul 2017, 23:47

Re: AHK Code Obfsucation Protection

23 Mar 2024, 10:37

caeee wrote:
23 Mar 2024, 10:20
so I am thinking of a protection that destroys the script's functionality if a specific condition is not met. I'm not sure if this goes against the rules of the board in any way so I am sorry if it does, in advance. I'm not looking to obfuscate the code, because it'd still work.
Gotcha... I'm sure we have all wanted this capability at some point. It comes in many different forms, of course. There are legitimate reasons to do this... for non-payment of a sw subscription as an example, and it's been done for years (in many forms). It might be a good idea to do it in a way that does not "appear" to be shady or unethical. Just something to consider. I have no concrete suggestions using AHK at this time, but registration values have been use for years. I've used my own device/user-license/registration/encryption/file manipulation techniques as long as 30+ years ago, prior to it being popular for commercial sw. Back when I wrote shareware.
caeee
Posts: 7
Joined: 29 Jan 2024, 08:55

Re: AHK Code Obfsucation Protection

23 Mar 2024, 10:40

andymbody wrote:
23 Mar 2024, 10:37
caeee wrote:
23 Mar 2024, 10:20
so I am thinking of a protection that destroys the script's functionality if a specific condition is not met. I'm not sure if this goes against the rules of the board in any way so I am sorry if it does, in advance. I'm not looking to obfuscate the code, because it'd still work.
Gotcha... I'm sure we have all wanted this capability at some point. It comes in many different forms, of course. There are legitimate reasons to do this... for non-payment of a sw subscription as an example, and it's been done for years (in many forms). It might be a good idea to do it in a way that does not "appear" to be shady or unethical. Just something to consider. I have no concrete suggestions as this time, but registration values have been use for years. I've used my own registration/encryption/file manipulation techniques as long as 35 years ago, prior to it being used regularly in commercial sw. Back when I wrote shareware.
I'm trying to tread carefully when it comes to it being shady or unethical. The thing is, I always finish the product --> Deliver the product --> Receive payment. So the current way it's set up, I have no insurance or guarantee of payment. Is it possible to develop a registration/encryption methods in AHK in a simple way? I'm not that advanced with programming in general, let alone AHK.
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: AHK Code Obfsucation Protection

23 Mar 2024, 10:50

caeee wrote:
23 Mar 2024, 10:20
Well..sometimes I do AHK snippets for people for a quick buck. I recently got scammed, though, so I am thinking of a protection that destroys the script's functionality if a specific condition is not met. I'm not sure if this goes against the rules of the board in any way so I am sorry if it does, in advance. I'm not looking to obfuscate the code, because it'd still work.
you could go through the trouble of having an ahk gui front end which does nothing but query your website with authentication of a license code. if the code is valid, then the ahk front end downloads the script from your website

or you could just get paid in advance

User avatar
andymbody
Posts: 937
Joined: 02 Jul 2017, 23:47

Re: AHK Code Obfsucation Protection

23 Mar 2024, 10:57

But to answer the question originally posted. Give mikeyww solution a try.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: akosipaul1, busymind, Chunjee, just me, mikeyww and 85 guests