Jump to content

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

exe2ahk ahk2exe ahk_L ahk_Basic decompile compile compress


  • Please log in to reply
2 replies to this topic
garry
  • Spam Officer
  • 3219 posts
  • Last active: Sep 20 2018 02:47 PM
  • Joined: 19 Apr 2005

I use ahk_basic and ahk_L   , extensions for ahk_Basic is=AHK  for ahk_L is = AHL

combined here scripts

for exe2ahk (ahk_L)  see  script from IsNull

http://www.autohotke...payload-method/

drag&drop ahk-files (AHK,AHL,EXE)  and start

example:

  xy.AHK / AHL  >> xy_a_now.exe  ( usually with rightclick )

  xy.EXE  >> xy_a_now.AHK / AHL

  xy.exe >> compress

 

select:  password  ,  Icon , ansi / unicode32 / unicode64

see original files ... \Compiler\ahk2exe.exe

 

 

;- compile   &  decompile  (drag&drop)
;- ahk_Basic &  ahk_L
;- exe2ahk   &  ahk2exe
;- compress exe-file

 

I used these programs , autohotkey paths are renamed

 

;  ########## check your path :  ########################
;  pr1=%a_programfiles%\AutoHotkey_B\Compiler\ahk2exe.exe           ;- ahk2exe ahk_Basic  usually with rightclick
;  pr2=%a_programfiles%\AutoHotkey_L\Compiler\ahk2exe.exe           ;- ahk2exe ahk_L      usually with rightclick
;  pr3=%a_scriptdir%\exe2ahk.exe                                    ;- exe2ahk ahk_Basic script downloads this
;  this script=      exe2ahk                                        ;- exe2ahk ahk_L  included in this script IsNull

; mpress.exe
 

MODIFIED=20130121   ; added /bin parameter
;- decompile (exe2ahk) & compile (ahk2exe )   ahk_Basic & ahk_L
;- from IsNull http://www.autohotke...payload-method/
;
;==============================================================================================================
;- this script is AHK_L  tested with XP netbook  unicode32 , used extension for ahk_L=xy.AHL for ahk_B=xy.AHK
;
;  ahk_L    = 1.1.09.02     extension xy.AHL  autohotkeyU32
;  ahk_Basic =1.0.48.05     extension xy.AHK
;
;- compile   &  decompile  (drag&drop)
;- ahk_Basic &  ahk_L
;- exe2ahk   &  ahk2exe
;- compress exe-file
;
;
;  ########## check your path :  ########################
;  pr1=%a_programfiles%\AutoHotkey_B\Compiler\ahk2exe.exe           ;- ahk2exe ahk_Basic  usually with rightclick
;  pr2=%a_programfiles%\AutoHotkey_L\Compiler\ahk2exe.exe           ;- ahk2exe ahk_L      usually with rightclick
;  pr3=%a_scriptdir%\exe2ahk.exe                                    ;- exe2ahk ahk_Basic script downloads this
;  this script=      exe2ahk                                        ;- exe2ahk ahk_L  included in this script IsNull
;
;- http://l.autohotkey....exe             ;- ahk_L
;- http://www.autohotke...Install.exe     ;- ahk_B
;- http://www.autohotke...e               ;- exe2ahk_B
;
;- if msvcr100.dll missing :  ( download Visual basic C microsoft vcredist_x86.exe )
;- http://www.microsoft...ls.aspx?id=5555
;
;- this script IsNull :
;- http://www.autohotke...payload-method/
;- http://www.autohotke...basic-versions/
;
;  mpress:
;  http://www.matcode.com/mpress.htm
;
;  if you have installed ansi32 , start script with autohotkeyU32 (unicode) :
;  or use original-program ... \Compiler\ahk2exe.exe and use unicode
;  --------------------------------------------------------------------
;   pr1=%a_programfiles%\Autohotkey_L\AutoHotkeyU32.exe
;   pr2=%a_scriptdir%\ahk_compile_20130121.ahl         ;-<<  this scripts name
;   run,%comspec% /c %pr1% %pr2%,,hide
;   return
;
;
;================================================================================================


#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
transform,S,chr,32           ;-- SPACE

;- i have 32-bit computer
   if (A_IsUnicode)
      codex := " Unicode32-bit"
   else
      codex := " ANSI32-bit"
   aaw:=( InStr( (v:=A_AhkVersion), "1.1" ) ? "ahk_L " : "ahk_Basic " ) v codex
   aac:=codex
Filename1=Ahk_Compile_Decompile_exe2ahk_ahk2exe_%aaw%


;-- downloads exe2ahk.exe ---
fx=%a_scriptdir%\exe2ahk.exe
ifnotexist,%fx%
{
;-- internet exists :
For objStatus in ComObjGet("winmgmts:").ExecQuery("Select * From Win32_PingStatus where Address = 'www.google.com'")
{
   If (objStatus.StatusCode="" || objStatus.StatusCode != 0)
      {
      msgbox, 262192,Internet-Check ,No internet-connection
      exitapp
      }
}
urldownloadtofile,http://www.autohotkey.com/download/Exe2Ahk.exe,%fx%
}


;-- files here , create 2-testfiles -----
folder1=%a_scriptdir%\Encoded_Decoded
ifnotexist,%folder1%
    filecreatedir,%folder1%

   e4x=
   (Ltrim Join`r`n
   if (A_IsUnicode)
      unicode := "Encoding is Unicode"
   else
      unicode := "Encoding is ANSI"
   aav:="Version: " ( InStr( (v:=A_AhkVersion)`n, "1.1" ) ? "ahk_L " : "ahk_Basic " ) v "``n" unicode
   msgbox, 262208,AHK-Version-Info ,`%aav`%
   return
   )
   file1_L=%folder1%\ahk_L_Version.ahl
   file1_B=%folder1%\ahk_B_Version.ahk

   ifnotexist,%file1_L%
     fileappend,%e4x%`r`n,%file1_L%
   ifnotexist,%file1_B%
     fileappend,%e4x%`r`n,%file1_B%
;------------------------------------------



  pr1=%a_programfiles%\AutoHotkey_B\Compiler\ahk2exe.exe           ;- ahk2exe ahk_Basic
  pr2=%a_programfiles%\AutoHotkey_L\Compiler\ahk2exe.exe           ;- ahk2exe ahk_L
  pr3=%a_scriptdir%\exe2ahk.exe                                    ;- exe2ahk ahk_Basic script downloads this
; this script=      exe2ahk                                        ;- exe2ahk ahk_L  included in this script IsNull


ifnotexist,%pr1%
   {
   msgbox, 262208,File ,File=`n%pr1%`nNot exist`nSee correct path from your autohotkey-program
   exitapp
   }

ifnotexist,%pr2%
   {
   msgbox, 262208,File ,File=`n%pr2%`nNot exist`nSee correct path from your autohotkey-program
   exitapp
   }




global DEBUG := false
global POSSIBLE_RESOURCE_NAMES := [">AHK WITH ICON<", ">AUTOHOTKEY SCRIPT<"]
global PATCHED_RESOURCE_NAMES  := [">UHK WITH ICON<", ">UUTOHOTKEY SCRIPT<"]
global ExtractionDir           := A_ScriptDir "\ExtractionTemp"
global DecompilerPayload_URL   := "http://dl.securityvision.ch/tools/decompiler_payload.dll"
global DecompilerPayload64_URL := "http://dl.securityvision.ch/tools/decompiler_payload_64.dll"
global DecompilerPayload_BIN   := A_ScriptDir "\payload.dll"
global DecompilerPayload64_BIN := A_ScriptDir "\payload64.dll"
global CurrentPayload_BIN      := ExtractionDir "\winmm.dll"




;GUI,2:+AlwaysOnTop
;Gui,2: new, +Resize
Gui,2: add, Edit, x5 y5 w800 h20  gGoAnalyze   vAHKExe, drag Autohotkey-files here (  AHK or AHL or EXE  )
Gui,2: Font,,FixedSys

   ;----------------------------
   Menu,S1,add,OpenFolder   ,MH1
   Menu,S1,add,FolderIcons  ,MH1

   Menu,S2,add,ahk2exe_B             ,MH2
   Menu,S2,add,ahk2exe_L             ,MH2
   Menu,S2,add,exe2ahk_B             ,MH2
   Menu,S2,add,Forum_ahk_Basic       ,MH2
   Menu,S2,add,Download exe2ahk_B    ,MH2
   Menu,S2,add,Download AutoHotkey_L ,MH2
   Menu,S2,add,Download AutoHotkey_B ,MH2
   Menu,S2,add,IsNull_exe2ahk_L      ,MH2
   Menu,S2,add,ahk_B_Version         ,MH2
   Menu,S2,add,ahk_L_Version         ,MH2
   Menu,S2,add,Download_msvcr100.dll ,MH2
   Menu,S2,add,Download_Mpress.exe   ,MH2

   Menu,S3,add,Volume      ,MH3
   Menu,S3,add,Charmap     ,MH3

   Menu,S4,add,Search_ahk  ,MH4



   ;----------------------------
   menu,myMenuBar,Add,Folder             ,:S1
   menu,myMenuBar,Add,Help               ,:S2
   menu,myMenuBar,Add,Tools              ,:S3
   menu,myMenuBar,Add,Search             ,:S4

   ;----------------------------
   gui,2:menu,MyMenuBar
   ;----------------------------


Gui,2: add, Edit, +ReadOnly vMyLog        x0 y35   w800 h200
Gui,2: add, Edit, +ReadOnly vScriptSource x0 y250  w800 h300 c4A708B


Gui,2: add, Text, x5  y570 ,Source
Gui,2: add, Text, x5  y600 ,Destination
Gui,2: add, Text, x5  y630 ,Programm
Gui,2: add, Text, x5  y660 ,Comment
Gui,2: add, Text, x5  y720 ,Password

Gui,2: add, Edit, +ReadOnly vSource1      x110  y570 w680 h25
Gui,2: add, Edit, +ReadOnly vDestination1 x110  y600 w680 h25
Gui,2: add, Edit, +ReadOnly vProgram1     x110  y630 w680 h25
Gui,2: add, Edit, +ReadOnly vComment1     x110  y660 w680 h25

Gui,2: add, Edit, +Readonly vIcon2        x110  y690 w680 h25
Gui,2: add, Edit,           vPassword1    x110  y720 w100 h25,1234

Gui,2: add, Button, gSelectIco  vSelectIco1     x5    y690 w95 h25,Icon...
Gui,2: Add, Checkbox, x230 y720     gGoAnalyze vCheck1         ,Password
Gui,2: Add, Checkbox, x330 y720     gMpress1   vMpress1        ,MPRESS`nCompress xy_L.exe

;Gui,2: Add,Button   , x500 y720 w100  vAnalyze1     gGoAnalyze,Analyze
Gui,2: Add,Button   , x720 y720 w100  vConvert1     gGoConvert,Convert



TXX1=
(Ltrim Join|

ansi 32-bit
unicode 32-bit
unicode 64-bit
)
Gui,2:Add,DropDownList,  x500  y720  w200 h20 r5 vA462,%TXX1%
Gui,2:add, Text,         x500  y745 ,ahk_L >> exe



Gui,2: show, x10 y10 w850 h780, %filename1%
GuiControl,2:disable,password1
GuiControl,2:disable,check1
GuiControl,2:disable,selectico1
GuiControl,2:disable,mpress1
;GuiControl,2: Choose, a462,unicode 32-bit
GuiControl,2:disable,a462


LogLn("<Running on: AHK Version "A_AhkVersion " - " (A_IsUnicode ? "Unicode" : "Ansi") " " (A_PtrSize == 4 ? "32" : "64") "bit>")
return
;------------
2GuiClose:
ExitApp
;------------
2GuiDropFiles:
   GuiControl,2:,AHKExe, % A_GuiEvent
return
;------------
SelectIco:
bbb=C:\M_CSVTXT\CSV_MENULISTBOX2\ICO
FileSelectFile, filenameIco,1,%bbb%,Select your file,*.ico
if filenameIco =
   return
GuiControl,2:,Icon2,%filenameIco%
gosub,goanalyze
return


MH1:
if A_thisMenuItem=OpenFolder
  run,%folder1%
if A_thisMenuItem=FolderIcons
  run,C:\M_CSVTXT\CSV_MENULISTBOX2\ICO
return



MH2:
if A_thisMenuItem=ahk2exe_B
{
ifexist,%pr1%
    run,%pr1%
}

if A_thisMenuItem=ahk2exe_L
{
ifexist,%pr2%
    run,%pr2%
}


if A_thisMenuItem=exe2ahk_B
{
ifexist,%a_scriptdir%\exe2ahk.exe
    run,%comspec% /k %a_scriptdir%\exe2ahk.exe
}

if A_thisMenuItem=Forum_ahk_Basic
   run,http://www.autohotkey.com/board/topic/86134-autohotkey-10-classic-and-basic-versions/
if A_thisMenuItem=Download exe2ahk_B
   run,http://www.autohotkey.com/download/Exe2Ahk.exe
if A_thisMenuItem=Download AutoHotkey_L
   run,http://l.autohotkey.net/AutoHotkey_L_Install.exe
if A_thisMenuItem=Download AutoHotkey_B
   run,http://www.autohotkey.com/download/AutoHotkeyInstall.exe
if A_thisMenuItem=IsNull_exe2ahk_L
   run,http://www.autohotkey.com/board/topic/82986-ahk-l-decompiler-payload-method/
if A_thisMenuItem=Download_msvcr100.dll
   run,http://www.microsoft.com/de-de/download/details.aspx?id=5555
if A_thisMenuItem=ahk_L_Version
   run,%file1_L%
if A_thisMenuItem=ahk_B_Version
   run,%file1_B%
if A_thisMenuItem=Download_Mpress.exe
   run,http://www.matcode.com/mpress.htm
return


MH3:
if A_thisMenuItem=Volume
    {
    run,sndvol32
    run,sndvol32 /rec
    ;CN=RunDLL32.EXE shell32.dll,Control_RunDLL mmsys.cpl,,1
    ;run,%CN%
    }
if A_thisMenuItem=Charmap
    run,charmap
return


MH4:
InputBox,src,Search in Autohotkey,Search:, , 300, 100
run, http://www.google.co...otkey.com %src%
return
;------------------------------------------------------------------





mpress1:
Gui,2:submit,nohide
GuiControl,2:disable,password1
GuiControl,2:,ScriptSource ,
GuiControl,2:,Mylog ,
gosub,clears

SplitPath, AHKexe, name, dir, ext, name_no_ext, drive
f1 =%ahkexe%           ;--- original

;-- this reduces size from xy_L.exe ---
if ext=exe
  {
  if Mpress1=1
     {
     ifexist,%a_scriptdir%\mpress.exe
        {
        runwait,%comspec% /k mpress.exe "%f1%"
        GuiControl,2:,Comment1 ,Finished %name_no_ext%.exe compressed
        GuiControl,2:,mpress1,0
        ;GuiControl,2:disable,mpress1
        return
        }
     }
  }
return







;-------------------------------------------
GoAnalyze:
Gui,2:submit,nohide
GuiControl,2:disable,password1
GuiControl,2:,ScriptSource ,
GuiControl,2:,Mylog ,
GuiControl,2:disable,mpress1
GuiControl,2:,mpress1,0

if check1=1
   textpassword=Password=YES
else
   {
   textpassword=Password=NO
   password1=
   }

if Icon2=
   texticon=Icon=NO
else
   texticon=ICON=YES



if AHKexe<>            ;--- file to convert  AHK  AHL  EXE
{
SplitPath, AHKexe, name, dir, ext, name_no_ext, drive
f1 =%ahkexe%           ;--- original


;------------- begin ahk2exe AHK AHL --------------------------------------
  ;- ahk2exe_Basic  convert ahk_B to ahk.exe ------------------------------
  if ext=ahk           ;--- ICON  / PASSWORD possible for ahk_B -----------
     {
     f2 =%folder1%\%name_no_ext%_%a_now%_B.exe
     ;run,%pr1% /in "%f1%" /out "%f2%" /icon xy.ico /pass %password1%

     GuiControl,2:,Source1      ,%f1%
     GuiControl,2:,Destination1 ,%f2%
     GuiControl,2:,Program1     ,%pr1%
     GuiControl,2:,Icon2        ,%icon2%

     GuiControl,2:,ScriptSource,Compile`n%name%  >>>  `n%name_no_ext%_B.exe

     GuiControl,2: enable,check1
     GuiControl,2:enable,password1
     GuiControl,2:enable,selectico1
     GuiControl,2:,Comment1     ,You selected >> %textpassword%    %texticon%
     GuiControl,2:disable,mpress1
     GuiControl,2:disable,a462
     return
     }


  ;- ahk2exe_L  convert ahk_L to ahk.exe ------------------------------
  if ext=ahl           ;--- ICON possible for ahk_L -----------
     {
     f2 =%folder1%\%name_no_ext%_%a_now%_L.exe
     ; run,%pr2% /in "%f1%" /out "%f2%" /icon xy.ico /bin xx
     ; /bin autohotkeySC.bin
     ; /bin ansi 32-bit.bin
     ; /bin unicode 32-bit.bin
     ; /bin unicode 64-bit.bin

     GuiControl,2:,Source1      ,%f1%
     GuiControl,2:,Destination1 ,%f2%
     GuiControl,2:,Program1     ,%pr2%
     GuiControl,2:,Icon2        ,%icon2%

     GuiControl,2:,ScriptSource,Compile`n%name%  >>>  `n%name_no_ext%_L.exe

     GuiControl,2:disable,check1
     GuiControl,2:disable,password1
     GuiControl,2:enable,selectico1
     GuiControl,2:,Comment1     , You Selected >> %texticon%
     GuiControl,2:disable,mpress1
     GuiControl,2:enable,a462
     return
     }
;------------- end ahk2exe ---------------------------------------



  ;---- exe2ahk / exe2ahL decompile EXE >>>  AHK or AHL  ---------
  if ext=exe
     {
     ;--- for ahk_B  maybe PASSWORD possible ------------
     GuiControl,2:,Source1      ,%f1%
     GuiControl,2:enable,check1
     GuiControl,2:enable,password1
     GuiControl,2:disable,selectico1

     GuiControl,2:,Destination1 ,depending if exe is ahk_B  or ahk_L
     GuiControl,2:,Program1     ,maybe %pr3%  or This-Script
     GuiControl,2:,Comment1     ,%textpassword%   / exe >> AHK  or AHL ahk_B extract to working_DIR
     ifexist,%a_scriptdir%\mpress.exe
         GuiControl,2:enable,mpress1
    GuiControl,2:disable,a462
    return
    }
;------------------------  end exe2ahk  -------------------------------
}
return
;-------------------------------------------








;-------------------------------------------
GoConvert:
Gui,2:submit,nohide
GuiControl,2:disable,password1


if check1=1
   textpassword=Password=YES
else
   {
   textpassword=Password=NO
   password1=
   }

if Icon2=
   texticon=Icon=NO
else
   texticon=ICON=YES



if AHKexe<>            ;--- file to convert  AHK  AHL  EXE
{
SplitPath, AHKexe, name, dir, ext, name_no_ext, drive
f1 =%ahkexe%           ;--- original


;------------- begin ahk2exe AHK AHL --------------------------------------
  ;- ahk2exe_Basic  convert ahk_B to ahk.exe ------------------------------
  if ext=ahk           ;--- ICON  / PASSWORD possible for ahk_B -----------
     {
     f2 =%folder1%\%name_no_ext%_%a_now%_B.exe
     ;run,%pr1% /in "%f1%" /out "%f2%" /icon xy.ico /pass %password1%

     GuiControl,2:,Source1      ,%f1%
     GuiControl,2:,Destination1 ,%f2%
     GuiControl,2:,Program1     ,%pr1%
     GuiControl,2:,Icon2        ,%icon2%

     GuiControl,2:,ScriptSource,Compile`n%name%  >>>  `n%name_no_ext%_B.exe
     GuiControl,2: enable,check1
     GuiControl,2:enable,password1
     GuiControl,2:enable,selectico1
     GuiControl,2:disable,a462

     GuiControl,2:,Comment1     ,You selected >> %textpassword%    %texticon%

     if ((check1="1") and (Icon2=""))
        runwait,%pr1% /in "%f1%" /out "%f2%" /pass %password1%

     if ((check1="1") and (Icon2<>""))
        runwait,%pr1% /in "%f1%" /out "%f2%" /icon %Icon2% /pass %password1%

     if ((check1="0") and (Icon2=""))
        runwait,%pr1% /in "%f1%" /out "%f2%"

     if ((check1="0") and (Icon2<>""))
        runwait,%pr1% /in "%f1%" /out "%f2%" /icon %Icon2%

     run,%folder1%
     gosub,clears
     GuiControl,2:,Comment1 ,Finished %name_no_ext%_B.ahl >> %name_no_ext%_%a_now%_B.exe
     return
     }


  ;- ahk2exe_L  convert ahk_L to ahk.exe ------------------------------
  if ext=ahl           ;--- ICON possible for ahk_L -----------
     {
     GuiControl,2:enable,a462
     fbin=%a_programfiles%\Autohotkey_L\Compiler\%a462%.bin
     stringsplit,g,a462,%s%
     binn=%g1%%g2%
     if a462=
        binn=%aac%            ;- default ansi32 or unicode32
     f2 =%folder1%\%name_no_ext%_%a_now%_%binn%_L.exe
     ;run,%pr2% /in "%f1%" /out "%f2%" /icon xy.ico /bin xx

     GuiControl,2:,Source1      ,%f1%
     GuiControl,2:,Destination1 ,%f2%
     GuiControl,2:,Program1     ,%pr2%
     GuiControl,2:,Comment1     , You Selected >> %texticon%
     GuiControl,2:,Icon2        ,%icon2%

     GuiControl,2:,ScriptSource,Compile`n%name%  >>>  `n%name_no_ext%_L.exe

     GuiControl,2:disable,check1
     GuiControl,2:disable,password1
     GuiControl,2:enable,selectico1

     if (Icon2="" and a462="")
        run,%pr2% /in "%f1%" /out "%f2%"
     if (Icon2<>"" and a462="")
        run,%pr2% /in "%f1%" /out "%f2%" /icon %Icon2%
     if (Icon2="" and a462<>"")
        run,%pr2% /in "%f1%" /out "%f2%" /bin "%fbin%"
     if (Icon2<>"" and a462<>"")
        run,%pr2% /in "%f1%" /out "%f2%" /icon %Icon2% /bin "%fbin%"
     run,%folder1%
     gosub,clears
     GuiControl,2:,Comment1 ,Finished %name_no_ext%_L.ahl >> %name_no_ext%_%a_now%_%binn%_L.exe
     return
     }
;------------- end ahk2exe ---------------------------------------



  ;---- exe2ahk / exe2ahL decompile EXE >>>  AHK or AHL  ---------
  if ext=exe
     {
     ;--- for ahk_B   PASSWORD possible ------------
     GuiControl,2:,Source1      ,%f1%
     GuiControl,2:enable,check1
     GuiControl,2:enable,password1
     GuiControl,2:disable,selectico1
     GuiControl,2:disable,a462

     if (check1="0")
        runwait,%comspec% /c %pr3% "%f1%",,hide useerrorlevel
     if (check1="1")
        runwait,%comspec% /c %pr3% "%f1%" "%password1%",,hide useerrorlevel

     if (errorlevel=0)     ;-- ahk_B
        {
        f4=%dir%\%name_no_ext%.ahk           ;- exe2ahk created-file  ahk_B creates automatically in working directory ext=new ifexist
        GuiControl,2:,Destination1 ,%f4%
        GuiControl,2:,Program1     ,%pr3%
        GuiControl,2:,Comment1     ,%textpassword%   / Script will be extracted to the current working directory
        if (check1="1")
           GuiControl,2:,ScriptSource,EXE was ahk-BASIC password protected`nexe2ahk.exe  >>  %name_no_ext%.AHK
        else
           GuiControl,2:,ScriptSource,EXE was ahk-BASIC`nexe2ahk.exe  >>  %name_no_ext%.AHK
        ifexist,%f4%
          {
          GuiControl,2:,Comment1 ,Finished %name_no_ext%.exe to %name_no_ext%.ahk
          run,notepad %f4%
          }
        return
        }

     if (errorlevel=1)      ;-- ahk_L  , try but maybe ahk_B password was wrong
        {
        f5 =%folder1%\%name_no_ext%_encoded_%a_now%.AHL       ;-- exe2ahk encoded ahk_L script IsNull
        GuiControl,2:,Destination1 ,%f5%
        gosub,extractnow
        gosub,clears
        ifexist,%f5%
            {
            GuiControl,2:,Comment1 ,Finished %name_no_ext%.exe >> %name_no_ext%_encoded_%a_now%.AHL
            run,notepad %f5%
            }
        return
        }

    }
;------------------------  end exe2ahk  -------------------------------
}
GuiControl,2:enable,selectico1
return
;-------------------------------------------


clears:
GuiControl,2:,Source1      ,
GuiControl,2:,Destination1 ,
GuiControl,2:,Program1     ,
GuiControl,2:,Comment1     ,
GuiControl,2:,Icon2        ,
;GuiControl,2:,ScriptSource ,
;GuiControl,2:,Mylog ,
return






;################################################################################
;=== function from IsNull / fincs and others  exe2ahk ahk_L ---------------------
;- http://www.autohotke...payload-method/

/*
* AHK_L Decompiler / Source Extractor
* Written by IsNull 2012
* the payload method bases on fincs injection example
* This Script suports generic resource extraction
* This version is based upon a dll injection which can extract the resources.
* This method was discovered by fincs, so credits go to him!
*/

;#################################
ExtractNow:
    Gui,2:submit, nohide
    LogClear()
    GuiCodeSet("")
    if(PrepareFile(AHKExe, preparedFile))
    {
        ; file was prepared successfull
        if(EnsurePayloadIsPresent())
        {
            LogLn("<Injecting payload...>")
            PlacePayload(preparedFile)
            RunWait, % preparedFile, % ExtractionDir, UseErrorLevel
            if(ErrorLevel == "ERROR")
            {
                LogLn("<The Target could not be started. Is this a valid PE Executable?>")
            }else{
                SplitPath, preparedFile, OutFileName, OutDir, OutExtension, OutNameNoExt
                tmpCodePath := OutDir "\" OutNameNoExt "-uncompiled.ahk"
                try {
                    WaitForFile(tmpCodePath, 10000) ; wait maximum 10secs for the file, this should be enough for even very slow harddisks.
                }catch e{
                    LogLn("<" e.Message ">")
                    LogLn("<Missing: " tmpCodePath ">")
                }

                if(FileExist(tmpCodePath))
                {
                    LogLn("<Payload succeeded. Recovering Script.>")
                    FileRead, script, % tmpCodePath
                    if(!DEBUG)
                        FileDelete, % tmpCodePath
                    GuiCodeSet(script)
                }else{
                    LogLn("<Script could not be extracted.>")
                }
                if(!DEBUG)
                    FileDelete, % CurrentPayload_BIN ; remove the winmm.dll as it causes trouble if it get accedintially injected.^^
            }
        }else{
            LogLn("<Missing payload. Aborting now.>")
            return
        }
    }else{
        LogLn("<File seems not to be a valid compiled AHK Script or it uses an unknown protection.>")
    }
    if(!DEBUG)
        FileDelete, % preparedFile
return








;=======================================================================================
/*
* Waits until the file is present
* can be aborted by the timeout
*
* file      File-Path to check
* timeout   Timeout in Milliseconds (Max waittime)
*/
WaitForFile(file, timeout=5000){
   start := A_TickCount

   while(!FileExist(file))
   {
      if((A_TickCount - start) > timeout)
         throw Exception("TimeoutException: File was not present whithin the expected time.")
   }
}

PlacePayload(preparedFile){
   success := false
   SplitPath, preparedFile, OutFileName, OutDir

   if(Is64BitAssembly(preparedFile))
   {
      LogLn("<Target Application is 64bit.>")
      payloadSrc := DecompilerPayload64_BIN
   }else{
      LogLn("<Target Application is 32bit.>")
      payloadSrc := DecompilerPayload_BIN
   }

   if(FileExist(payloadSrc))
   {
      FileCopy, % payloadSrc, % CurrentPayload_BIN, 1
      success := true
   }
   return success
}

Is64BitAssembly(appName){
   static GetBinaryType := "GetBinaryType" (A_IsUnicode ? "W" : "A")
   static SCS_32BIT_BINARY := 0
   static SCS_64BIT_BINARY := 6

   ret := DllCall(GetBinaryType
      ,"Str", appName
      ,"int*", binaryType)

   return binaryType == SCS_64BIT_BINARY
}

EnsurePayloadIsPresent(){
   if(!FileExist(DecompilerPayload_BIN))
   {
      URLDownloadToFile, % DecompilerPayload_URL, % DecompilerPayload_BIN
      LogLn("<" DecompilerPayload_BIN " downloaded.>")
   }
   if(!FileExist(DecompilerPayload64_BIN))
   {
      URLDownloadToFile, % DecompilerPayload64_URL, % DecompilerPayload64_BIN
      LogLn("<" DecompilerPayload64_BIN " downloaded.>")
   }
   return FileExist(DecompilerPayload_BIN)
}

PrepareFile(fileToPrepare, byref preparedFile){
   success := false

   if(!FileExist(ExtractionDir))
      FileCreateDir, % ExtractionDir

   if(FileExist(fileToPrepare))
   {
      LogLn("<Recover Source for " fileToPrepare ">")
      binaryTarget := ExtractionDir "\patched.exe"
      preparedFile := binaryTarget
      FileCopy, % fileToPrepare, % binaryTarget, 1
      LogLn("<Starting file analysis...>")
      ;##########

      ofile := FileOpen(binaryTarget, "rw")
      VarSetCapacity(buffer, ofile.Length)
      bytesRead := ofile.RawRead(buffer, ofile.Length)
      LogLn("<Readed " bytesRead " bytes from file.>")

      if(HasPEHeaderMagic(buffer))
      {
         LogLn("<Seems to be a valid PE File.>")
         for i, resName in POSSIBLE_RESOURCE_NAMES
         {
            ahkResourceName := StringToUTFByteArray(POSSIBLE_RESOURCE_NAMES[i])
            patch := StringToUTFByteArray(PATCHED_RESOURCE_NAMES[i])
            LogLn("<Searching for " ByteArrayToHex(ahkResourceName) " in " bytesRead "bytes.>")
            if(pos := FindMagic(buffer, bytesRead, ahkResourceName))
            {
                if(PatchBinary(ofile, pos, patch)){
                   LogLn("<Patched successfull>")
                   success := true
                   break
                }
            }
         }
         ofile.Close() ; Flush
      }else{
         LogLn("<Whatever you dragged here, this is NOT a valid PE file.>")
      }
      ;##########

   }else{
      LogLn("<File Not Found!>")
   }

   return success
}

HasPEHeaderMagic(ByRef buffer){
   return (NumGet(buffer,0,"UChar") == 77 && (NumGet(buffer,1,"UChar") == (A_IsUnicode ? 90 : 82)))
}

PatchBinary(targetfile, pos, byteArrayReplacement){
   written := false
   if(!IsObject(targetfile)){
      throw "targetfile: must be a valid file instance"
   }

   if(pos != -1)
   {
      LogLn("<Found Resource-Name @" pos ">")
      LogLn("<Patching Resource-Name...>")
      targetfile.Seek(pos)
      size := ByteArrayToBuffer(byteArrayReplacement, patched)
      written := targetfile.RawWrite(patched, size)
      LogLn("<PatchBinary: Written " written " bytes.>")
   }else{
      LogLn("<Could not find pattern: " ByteArrayToHex(arr) ">")
   }
   return written
}


global mylogData := ""
LogLn(line){
   global
   mylogData .= line "`n"
   GuiControl,2:,MyLog, % mylogData
}
LogClear(){
   global
   mylogData := ""
   GuiControl,2:,MyLog, % mylogData
}

;#######################################
GuiCodeSet(scriptcode){
   global
   GuiControl,2:,ScriptSource, % scriptcode
   fileappend,%scriptcode%,%f5%
}



StringToUTFByteArray(str){
   bufSize := StringToUTFBUffer(str, buf)
   return BufferToByteArray(buf, bufSize)
}

StringToUTFBUffer(str, byref buf){
   ;size := StrPut(str, "UTF-16") ; seems the size is not calculated correctly for UTF-16 Strings...
   size := (StrPut(str, "UTF-16") - 1) * 2
   VarSetCapacity( buf, size, 0x00)
   StrPut(str, &buf, size, "UTF-16")
   return size
}

BufferToHex( ptr, size )
{
   myhexdmp := ""
   SetFormat, integer, hex
   Loop, % size
   {
      byte := NumGet(ptr+0, A_index-1,"UChar") + 0
      myhexdmp .= byte
   }
   return myhexdmp
}

ByteArrayToHex(arr){
   s := ""
   SetFormat, integer, hex
   for each, byte in arr
   {
      byte += 0
      s .= (StrLen(x := SubStr(byte, 3)) < 2 ? "0" x : x ) " "
   }
   SetFormat, integer, dez
   StringUpper, s, s
   return s
}

PrintArr(obj) {
    str := ""
   for i, val in obj
      str .= "[" i "] -> " val  "`n"
   return str
}
PrintArrAsStr(obj) {
    str := ""
   for each, val in obj
      str .= val "(" (val != 0 ? chr(val) : "null") ")"  "`n"
   return str
}

ToByteArray(str){
   bytes := []
   Loop, parse, str
      bytes[A_index] := asc(A_LoopField)
   return bytes
}

ByteArrayToBuffer(byteArray, byref buf){
   bufferSize := byteArray.MaxIndex()
   VarSetCapacity(buf, bufferSize, 0x00)
   for each, byte in byteArray
      NumPut(byte, buf, A_Index-1, "uchar")
   return bufferSize
}

BufferToByteArray(byref buffer, size){
   arr := []
   loop, % size
      arr[A_index] := NumGet(buffer, A_Index-1, "UChar")
   return arr
}



/************************************************
* FindMagic
*
* Search in binary data for a given byte-Pattern
*
* buffer   binary data
* size      size of the buffer
* magic      Byte-Array of the pattern to search
* offset   start offset to skip
*
* returns the position where the found magic starts
*         -1 indicates that no match was found
*************************************************
*/

FindMagic(byref buffer, size, magic, offset=0){
   magicLen := ByteArrayToBuffer(magic, magicBuffer)
   magicByte := magic[1]
   searchPtr := &buffer + offset
   searchEnd := &buffer + size - magicLen + 1  ; First byte must precede searchEnd.
   if(searchPtr >= searchEnd)
      return -1
   while searchPtr := DllCall("msvcrt\memchr", "ptr", searchPtr, "int", magicByte
                              , "ptr", searchEnd - searchPtr, "ptr"){
      if !DllCall("msvcrt\memcmp", "ptr", searchPtr, "ptr", &magicBuffer, "ptr", magicLen)
         return searchPtr - &buffer  ; I think this is what the script expects...
      ++searchPtr  ; Resume search at the next byte.
   }
   return -1
}

;====================================== END script decode / encode ====================================================







garry
  • Spam Officer
  • 3219 posts
  • Last active: Sep 20 2018 02:47 PM
  • Joined: 19 Apr 2005

( keep empty at moment , reserved for comments )

 



dgkim1991
  • New members
  • 2 posts
  • Last active: Jul 20 2015 08:50 PM
  • Joined: 13 Jul 2015

i got missing payload. aborting now message... any solution? running on win 7 64 bit