Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

AHK Decompile script 1.0


  • Please log in to reply
20 replies to this topic
sleepyy35
  • Members
  • 193 posts
  • Last active: Apr 23 2008 08:18 PM
  • Joined: 22 Jul 2004
sometime ago i lost some scripts to a harddrive crash so iwas looking for a way to decompile them easy, being the lazy dog that i am haha
i came up with this script !!!
tested on win98


menu,utility, Add,Download the  Exe2Ahk Decomplie cmd utility,MenuHandler1
menu, myMenuBar, Add,utility,:utility
menu,help, Add,Help,MenuHandler2
menu,help, Add,About,MenuHandler3
menu, myMenuBar, Add,Help,:Help
gui, menu,MyMenuBar
Gui, Add, Edit, x156 y63 w250 h20, 
Gui, Add, Button, x416 y63 w30 h20,[]
Gui, Add, Edit, x156 y93 w250 h20,
Gui, Add, Edit, x156 y123 w250 h20,
Gui, Add, Button, x416 y93 w30 h20, Exe2Ahk
Gui, Add, Button, x76 y163 w390 h20, Decompile
Gui, Add, Text, x76 y53 w80 h30,AHK exe file to Decompile
Gui, Add, Button, x76 y193 w390 h20,Decompile Without Password
Gui, Add, Text, x86 y93 w70 h20,Exe2Ahk
Gui, Add, Text, x86 y123 w70 h20,Password
Gui, Show, x170 y110 h246 w557, AHK Decomplie script 1.0
Return

MenuHandler3:
msgbox, AHK Decomplie script 1.0  a script to Decompile Ahk compile scripts  script by   (^sleepy^) 1-22-05
return
MenuHandler2:
run,http://www.autohotkey.com/forum/index.php
return
MenuHandler1:
URLDownloadToFile,http://www.autohotkey.com/download/Exe2Ahk.exe ,Exe2Ahk.exe
return
button[]:
FileSelectFile, SelectedFile, 3, , Open a, ahk compiled script (*.exe)
if SelectedFile =
	MsgBox, You didn't select anything.
else
GuiControl,,Edit1,%SelectedFile%
return
;-----------------------------------------------------------------------------------------------
buttonExe2Ahk:
msgbox,4,,Decompiler will now look for your copy of the Exe2Ahk Decomplie cmd utility!
IfMsgBox, No
return
Loop,C:\Exe2Ahk.exe, , 1  ; Recurse into subfolders.

{
	GuiControl,,Edit2, %A_LoopFileFullPath%
}

return
;-----------------------------------------------------------------------------------------------
buttondecompile:
ControlGetText, OutputVar1, Edit2
ControlGetText, OutputVar, Edit3
Run,command
Send,{CapsLock}%OutputVar1% {SPACE}%SelectedFile%  %OutputVar%{return} 
return
;---withoutpassword----------------------
buttonDecompileWithoutPassword:
ControlGetText, OutputVar1, Edit2
Run,command
Send,{CapsLock}%OutputVar1% {SPACE}%SelectedFile%{return} 
return
GuiClose:
ExitApp

^sleepy^

DRSAMRAZA
  • Guests
  • Last active:
  • Joined: --
Dear Sleepy

I was searching for a way to Decompile AHK Exes to AHK scripts when I came accross this little script of your`s. It is no doubt a good script but I would like to make some suggestions if it does not bother you.

First of all the script performs too much of a work which seems un neccessary. What you want to accomplish here, can be done with a lot fewer lines of code.

I came up with a simple way to do what is required. Here it goes.

PS: All you have to do is to Download Exe2Ahk rename it to 1.exe or anything of your liking and you are all set to go.

Instead of having the user to download the file first if it is not found by the script.

Another Suggesstiion is that it is a good idea to use Environment Variables istead of a Fixed Path because like me, not every body has the OS installed on drive C:\

Loop,C:\Exe2Ahk.exe, , 1 ; Recurse into subfolders


Here is the modified script, It may still be improved further, but this is what I could come up with for now. I hope you do not mind any of this


FileSelectFile, MyFile, 3, , Select a compiled [ AHK Script ], Compiled AHK (*.exe)
if MyFile = 
	{
		MsgBox 16, OoopS!, No File selected
		ExitApp
	}
InputBox, MyInput, Write the Password [ If Any ], , , , 100
FileAppend, "%A_ScriptDir%\Exe2Ahk.exe" "%MyFile%" "%MyInput%"`n, Compiler.cmd
FileAppend, Del /s /q "%A_ScriptDir%\Exe2Ahk.exe"`n, Compiler.cmd
FileAppend, Del /s /q Compiler.cmd, Compiler.cmd
FileInstall, 1.exe, Exe2Ahk.exe, 1
Run, Compiler.cmd
ExitApp


Just compile the script and you are ready to go. And it is only 13 Lines.

I have done it and it works

corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004
Thanks sleepyy35 :D

Here's a modified version that I have been using (138 lines!! :lol: ):
menu,utility, Add,Download the  Exe2Ahk Decompile cmd utility,MenuHandler1 
menu, myMenuBar, Add,utility,:utility 
menu,help, Add,Help,MenuHandler2 
menu,help, Add,About,MenuHandler3 
menu, myMenuBar, Add,Help,:Help 
gui, menu,MyMenuBar 
Gui, Add, Edit, x156 y63 w250 h20,
Gui, Add, Button, x416 y63 w30 h20 gBrowse1, ... 
Gui, Add, Edit, x156 y93 w250 h20, 
Gui, Add, Edit, x156 y123 w250 h20, 
Gui, Add, Button, x416 y93 w30 h20 gBrowse2, ... 
Gui, Add, Button, x76 y163 w390 h20, Decompile 
Gui, Add, Text, x76 y53 w80 h30,AHK exe file to Decompile 
Gui, Add, Text, x86 y93 w70 h20,Exe2Ahk 
Gui, Add, Text, x86 y123 w70 h20,Password 
Gui, Show, x170 y110 h246 w557, AHK Decompile script 1.0
Spath = %A_ScriptDir%\Exe2Ahk.exe
Gosub, GetSpath
IfExist, %Spath%
  GuiControl,,Edit2, %Spath% 
Return 
;----------------------------------------------------------------------------------------------- 
MenuHandler3: 
msgbox, AHK Decompile script 1.0  a script to Decompile Ahk compile scripts  script by   (^sleepy^) 1-22-05 `r`n`r`nModified...
return
;-----------------------------------------------------------------------------------------------  
MenuHandler2: 
run,http://www.autohotkey.com/docs/ 
return
;-----------------------------------------------------------------------------------------------  
MenuHandler1:
URLDownloadToFile,http://www.autohotkey.com/download/Exe2Ahk.exe ,%A_ScriptDir%\Exe2Ahk.exe
IfExist, %A_ScriptDir%\Exe2Ahk.exe
{
   Spath = %A_ScriptDir%\Exe2Ahk.exe
   Gosub, GetSpath
   foundit = %Spath%
   GuiControl,,Edit2, %Spath%
} 
return
;-----------------------------------------------------------------------------------------------  
Browse1:
FileSelectFile, SelectedFile, 3, , Open a, ahk compiled script (*.exe) 
if SelectedFile = 
{
   MsgBox, You didn't select anything.
   Return
} 
else
{
  Spath = %SelectedFile%
  Gosub, GetSpath
  GuiControl,,Edit1,%Spath% 
}
return 
;----------------------------------------------------------------------------------------------- 
Browse2:
msgbox,1,,Decompiler will now search for the Exe2Ahk Decompile cmd utility! 
IfMsgBox, Cancel 
return
SplashTextOn,,,Searching...,
Loop,C:\Exe2Ahk.exe, , 1  ; Recurse into subfolders. 
{ 
   foundit = %A_LoopFileShortPath%
} 
IfExist, foundit
{
  FileCopy, %foundit%, %A_ScriptDir%\Exe2Ahk.exe
  Spath = %A_ScriptDir%\Exe2Ahk.exe
  Gosub, GetSpath
  foundit = %Spath%
  GuiControl,,Edit2, %Spath%
}
else
{
  Gosub, MenuHandler1
}
SplashTextOff
return 
;----------------------------------------------------------------------------------------------- 
GetSpath:
Loop, %Spath%
{
Spath = %A_LoopFileShortPath%
}
Return
;----------------------------------------------------------------------------------------------- 
buttondecompile:
ControlGetText, AHKfile, Edit1 
ControlGetText, E2AHK, Edit2 
ControlGetText, EXEpass, Edit3
IfNotExist, %E2AHK%
{
  MsgBox, Error. EXE2AHK not specified. File not Decompiled.
  Return
}
else
{
  RunWait, %E2AHK%%A_Space%%AHKfile%%A_Space%%EXEpass%,, Hide
  StringTrimRight, dcomp, AHKfile, 3
  dcomp2 = %dcomp%new
  dcomp = %dcomp%ahk

  IfExist, %dcomp2%
  {
    msgbox,4,,Decompiled file already exists. Overwrite? 
    IfMsgBox, No
    {
      FileDelete, %dcomp2%
      MsgBox, File was not decompiled 
      return
    }
    else
    {
      FileMove, %dcomp2%, %dcomp%, 1
    }
  }
  
  IfExist, %dcomp%
  {
    MsgBox, Decompiled Ok. `r`n`r`n%AHKfile%
    msgbox,4,,Open file for editing with Notepad? 
    IfMsgBox, Yes
    { 
      Run, Notepad%A_Space%%dcomp%
    }
  }
 else
  {
    MsgBox, File was not decompiled
  }
}
dcomp=
dcompnew=
return
;-----------------------------------------------------------------------------------------------  
GuiClose: 
ExitApp


garry
  • Guests
  • Last active:
  • Joined: --
script from DRSAMRAZA works very good
one line (exe2ahk.bat) :D (just a joke)
exe2ahk.exe test11.exe


DRSAMRAZA
  • Guests
  • Last active:
  • Joined: --
If you liked my script

Check out these other scripts too

http://www.geocities.com/drsamraza

corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004
@DRSAMRAZA
It's a different method and it works :) but the temporary batch file is doing 50% of the work when it could all be done by the AHK script or all done using a batch file.

Del /s /q

This may not be a good idea as it deletes the specified file(s) from ALL subdirectories without confirmation...

DRSAMRAZA
  • Guests
  • Last active:
  • Joined: --

This may not be a good idea as it deletes the specified file(s) from ALL subdirectories without confirmation.

If you read the code carefully, the batch file is working in the directory %TEMP% as it's working dir, therefore it will not delete any of other Compiler.exe files anywhere on the system.

I have 2 or three files named compiler.exe just to see if your argument is valid.

Guess what ? IT IS NOT

But thankx anyway to remind me of this Unforseen possibility
javascript:emoticon(':lol:')

corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004

If you read the code carefully, the batch file is working in the directory %TEMP% as it's working dir, therefore it will not delete any of other Compiler.exe files anywhere on the system.

The script you posted works in the script's directory. Did you post a previous version?

I have 2 or three files named compiler.exe just to see if your argument is valid.

Guess what ? IT IS NOT

That's because the temp batch file created is called Compiler.cmd and not Compiler.exe. AFAIK the /s and /q switches will not work on Win9.x systems. The switches are not necessary in this case as far as I can tell though...

But thankx anyway to remind me of this Unforseen possibility
javascript:emoticon('')

np. I like your script btw ;). I'm curious though, why use a batch file? Why not use RunWait and FileDelete in AHK instead?

DRSAMRAZA
  • Guests
  • Last active:
  • Joined: --
It is now official. You spend waaaaay too much time in this forum.

Now to your arguments.
No 1:

That's because the temp batch file created is called Compiler.cmd

Well, a .CMD file is not a .BAT file don't you think

No 2:

The script you posted works in the script's directory. Did you post a previous version?


You are right here [ for once ]. Here is the script I intended to post

#NOTRAYICON
WINMINIMIZEALL

IF A_OSVERSION in WIN_NT4,WIN_95,WIN_98,WIN_ME
	{
		MSGBOX 16, OoopS!, ERROR! Occured`n`nReason`:`tThis Program requires Windows  [ 2000 / XP ] or later
		EXITAPP
	}
FileSelectFile, MyFile, 3, , Select a compiled [ AHK Script ], Compiled AHK (*.exe)
if MyFile = 
	{
		MsgBox 16, OoopS!, No File selected
		ExitApp
	}
InputBox, MyInput, Write the Password [ If Any ], , , , 100
FileAppend, "%Temp%\Exe2Ahk.exe" "%MyFile%" "%MyInput%"`n, %Temp%\Compiler.cmd
FileAppend, Del /s /q "%Temp%\Exe2Ahk.exe"`n, %Temp%\Compiler.cmd
FileAppend, Del /s /q "%Temp%\Compiler.cmd", %Temp%\Compiler.cmd
FileInstall, 1.exe, %Temp%\Exe2Ahk.exe, 0
Run, %Temp%\Compiler.cmd, , HIDE

WINMINIMIZEALLUNDO
ExitApp

No 3:

/s and /q switches will not work on Win9.x systems


I think the above script will take care of that.

But thakx again for this In-Depth input for a 13 Line code. Thank GOD, I did not post any of my other Looooooooooooong scripts or your scrutiny would be miles and miles long.

corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004

It is now official. You spend waaaaay too much time in this forum.

:lol: :D

Well, a .CMD file is not a .BAT file don't you think

*.NT and *.CMD
.NT and .CMD may be used as .BAT files were used in earlier versions of Windows. You may notice on NT systems that there are fewer and fewer .BAT files. Try seaching for .NT or .CMD and you will find many of the same types of batch files that were available as .BATs. For example: CONFIG.NT has a similar function to the old CONFIG.SYS of Windows.


I think the above script will take care of that.

FileAppend, Del /s /q

:?:

FileSelectFile, MyFile, 3, , Select a compiled [ AHK Script ], Compiled AHK (*.exe) 
if MyFile = 
   { 
      MsgBox 16, OoopS!, No File selected 
      ExitApp 
   } 
InputBox, MyInput, Write the Password [ If Any ], , , , 100
FileInstall, Exe2Ahk.exe, %A_ScriptDir%\Exe2Ahk.exe, 1
Loop, %MyFile%
{
if A_LoopFileShortPath <>
  MyFile = %A_LoopFileShortPath%
} 
RunWait, %A_ScriptDir%\Exe2Ahk.exe %MyFile% %MyInput%,,Hide 
FileDelete, %A_ScriptDir%\Exe2Ahk.exe
ExitApp


HandSOME
  • Guests
  • Last active:
  • Joined: --
Mr Sam Raza
Xcellent Job

Your Ma Ustaad

  • Guests
  • Last active:
  • Joined: --
I like corrupt's script.
It's very user friendly, especially for AHK begginers.
Many users haven't reached this level yet, & can find it immediately useful.

ZeikJT
  • Guests
  • Last active:
  • Joined: --

I think the above script will take care of that.

FileAppend, Del /s /q

:?:


This Program requires Windows [ 2000 / XP ] or later

there is your answer, he added an exitapp command if it detects older systems, so it is not really a fix, but it does solve the problem xD

MalanoiD
  • Members
  • 7 posts
  • Last active: Jul 30 2010 05:53 PM
  • Joined: 12 May 2010

Dear Sleepy

I was searching for a way to Decompile AHK Exes to AHK scripts when I came accross this little script of your`s. It is no doubt a good script but I would like to make some suggestions if it does not bother you.

First of all the script performs too much of a work which seems un neccessary. What you want to accomplish here, can be done with a lot fewer lines of code.

I came up with a simple way to do what is required. Here it goes.

PS: All you have to do is to Download Exe2Ahk rename it to 1.exe or anything of your liking and you are all set to go.

Instead of having the user to download the file first if it is not found by the script.

Another Suggesstiion is that it is a good idea to use Environment Variables istead of a Fixed Path because like me, not every body has the OS installed on drive C:\

Loop,C:\Exe2Ahk.exe, , 1 ; Recurse into subfolders


Here is the modified script, It may still be improved further, but this is what I could come up with for now. I hope you do not mind any of this


FileSelectFile, MyFile, 3, , Select a compiled [ AHK Script ], Compiled AHK (*.exe)
if MyFile = 
	{
		MsgBox 16, OoopS!, No File selected
		ExitApp
	}
InputBox, MyInput, Write the Password [ If Any ], , , , 100
FileAppend, "%A_ScriptDir%\Exe2Ahk.exe" "%MyFile%" "%MyInput%"`n, Compiler.cmd
FileAppend, Del /s /q "%A_ScriptDir%\Exe2Ahk.exe"`n, Compiler.cmd
FileAppend, Del /s /q Compiler.cmd, Compiler.cmd
FileInstall, 1.exe, Exe2Ahk.exe, 1
Run, Compiler.cmd
ExitApp


Just compile the script and you are ready to go. And it is only 13 Lines.

I have done it and it works


could u tell me how to use it?

codybear
  • Members
  • 600 posts
  • Last active: Feb 09 2015 12:41 PM
  • Joined: 15 Sep 2009

could u tell me how to use it?


Upon further investigation of the code, you could actually use just the following three lines of code as long as the exe2ahk.exe file is in the same folder as this following script:
FileSelectFile, MyFile, 3, , Select a compiled [ AHK Script ], Compiled AHK (*.exe)
InputBox, MyInput, Write the Password [ If Any ], , , , 100
Run, %A_ScriptDir%\Exe2Ahk.exe "%MyFile%" "%MyInput%"

Save the script like normal...for example I've saved it as "Decompiler.ahk"
(Without quotes - could be compiled if you'd like also).
Then go here (link) and scroll down to the bottom to where it says "Script Decompiler."
Download that file and make sure it is in the same location(folder) as the saved decompiler script.
Then run the decompiler script.

It will open a fileselectfile dialog to search for the compiled ahk file(it'll actually list all exe files, but the decompiler will only work for ahk files obviously), then it will prompt you for a password(if none, just hit okay). Then a command window will popup and run the decompile for you.
The command window should take about a quarter of a second (if that) then disappear. About half a second after that, the decompiled version of the script will be located in the folder of the compiled script you had chosen in the beginning.


I'm going to work on a semi updated version with a couple quick options that will include everything for people in one exe...but dunno when that will be finished as I have atleast about ten other projects going on right now.