_GetSavedSource() allows you to extract the source file from the compiled executable and save to a file of your choice.
Note: You must use #AutoIt3Wrapper_Res_SaveSource=Y at the top of the script for this to work & it must be compiled.
Function:
#include-once #include <APIConstants.au3> ; Included with WinAPIEx.au3 #include <FileConstants.au3> #include <WinAPIEx.au3> ; Download From http://www.autoitscript.com/forum/topic/98712-winapiex-udf/ by Yashied. ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GetSavedSource ; Description ...: Retrieve the source file from a compiled executable, #AutoIt3Wrapper_Res_SaveSource=Y must be used beforehand to embed the file to the executable. ; Syntax ........: _GetSavedSource([$sExecutable = ''[, $sSaveFilePath = '']]) ; Parameters ....: $sExecutable - [optional] Executable to retrieve the source file from. ; Use a blank string or the Default keyword to use the current executable. Default is ''. ; $sSaveFilePath - [optional] FilePath to save the source file to. Nore: The file doesn't have to exist. Default is ''. ; Use a blank string or the Default keyword to save to the current directory and using the script's name with the au3 prefix. Default is ''. ; Return values .: Success - True ; Failure - False and sets @error to non-zero. ; Author ........: guinness ; Remarks .......: ; Example .......: Yes ; Note ..........: Thanks to Jos, Yashied & Zedna. ; =============================================================================================================================== Func _GetSavedSource($sExecutable = '', $sSaveFilePath = '') Local Const $STR_NOCASESENSEBASIC = 2 ; Not case sensitive, using a basic comparison If StringStripWS($sExecutable, $STR_STRIPALL) = '' Or $sExecutable = Default Then $sExecutable = @ScriptFullPath EndIf If StringStripWS($sSaveFilePath, $STR_STRIPALL) = '' Or $sSaveFilePath = Default Then $sSaveFilePath = @ScriptDir & '\' & StringLeft(@ScriptName, StringInStr(@ScriptName, '.', $STR_NOCASESENSEBASIC, -1) - 1) EndIf Local $hInstance = _WinAPI_LoadLibraryEx($sExecutable, $LOAD_LIBRARY_AS_DATAFILE) If $hInstance = 0 Then Return SetError(1, 0, False) EndIf Local $hResource = _WinAPI_FindResource($hInstance, $RT_RCDATA, 999) ; Get the source file from the executable. If @error Then Return SetError(2, 0, False) ; The source file isn't present. EndIf Local $iSize = _WinAPI_SizeOfResource($hInstance, $hResource) Local $hData = _WinAPI_LoadResource($hInstance, $hResource) Local $pData = _WinAPI_LockResource($hData) Local $tData = DllStructCreate('byte[' & $iSize & ']', $pData) Local $hFilePath = FileOpen($sSaveFilePath, $FO_OVERWRITE + $FO_BINARY) If $hFilePath = -1 Then _WinAPI_FreeLibrary($hInstance) Return SetError(3, 0, False) ; An error occurred writing the source file. EndIf FileWrite($hFilePath, DllStructGetData($tData, 1)) FileClose($hFilePath) Return _WinAPI_FreeLibrary($hInstance) EndFunc ;==>_GetSavedSource
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_Res_SaveSource=Y ; Use the full version of SciTE4AutoIt3 by Jos. #AutoIt3Wrapper_UseX64=N #include '_GetSavedSource.au3' If @Compiled = 0 Then Exit MsgBox($MB_SYSTEMMODAL, 'Compile first', 'Please compile this script first and then run the compiled file, you''ll see a new file called "' & _ScriptName() & '.au3' & '" is created in the same directory.') EndIf _GetSavedSource(@ScriptFullPath, @ScriptDir & '\' & _ScriptName() & '.au3') ; Return the @ScriptName minus the .exe or .au3 extension. Func _ScriptName() Local Const $STR_NOCASESENSEBASIC = 2 ; Not case sensitive, using a basic comparison Return StringLeft(@ScriptName, StringInStr(@ScriptName, '.', $STR_NOCASESENSEBASIC, -1) - 1) EndFunc ;==>_ScriptName
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_Res_SaveSource=Y ; Use the full version of SciTE4AutoIt3 by Jos. #AutoIt3Wrapper_UseX64=N #include <GUIConstantsEx.au3> #include '_GetSavedSource.au3' If @Compiled = 0 Then Exit MsgBox($MB_SYSTEMMODAL, 'Compile first', 'Please compile this script first and then run the compiled file, you''ll see a new file called "' & _ScriptName() & '.au3' & '" is created in the same directory.') EndIf _IsSaveSource() ; Check if the commandline parameter 'SaveSource' has been passed to the executable. Example() Func Example() ; The example of using AutoItWinGetTitle() can be found at: http://www.autoitscript.com/forum/topic/133648-autoitwingettitleautoitwinsettitle-an-example-of-usage/ Local $hAutoIt = AutoItWinShow() ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window. Local $sData = FileRead(@ScriptDir & '\' & _ScriptName() & '.au3') ; Read the source file that was extracted from the executable. If @error Then ; If the file wasn't extracted then show an error string. $sData = '## @error - can''t open the file ##' EndIf AutoItWinSetText($hAutoIt, $sData) ; Set the text of the edit box using the data returned from _GetFile. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ; Just hit the close button to Exit the application. ExitLoop EndSwitch WEnd EndFunc ;==>Example ; Add text to AutoIt's Hidden Window. Func AutoItWinSetText($sString, $hWnd = Default) If IsHWnd($hWnd) = 0 Or $hWnd = Default Then $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window. EndIf Return ControlSetText($hWnd, '', ControlGetHandle($hWnd, '', 'Edit1'), $sString) EndFunc ;==>AutoItWinSetText ; Display AutoIt's Hidden Window. Returns the handle of the window. Func AutoItWinShow() Local $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window. WinMove($hWnd, '', (@DesktopWidth / 2) - 250, (@DesktopHeight / 2) - 250, 500, 500) ; Move the AutoIt Hidden Window and re-size for a better view of the data that will be set. WinSetState($hWnd, '', @SW_SHOW) ; Show the AutoIt Hidden Window, normally this is hidden, but in the interest of this example I'm displaying it. Return $hWnd EndFunc ;==>AutoItWinShow ; Check if the commandline parameter 'SaveSource' has been passed to the executable. Func _IsSaveSource() If StringInStr($CmdLineRaw, 'SaveSource') Then Return _GetSavedSource(@ScriptFullPath, @ScriptDir & '\' & _ScriptName() & '.au3') EndIf EndFunc ;==>_IsSaveSource ; Return the @ScriptName minus the .exe or .au3 extension. Func _ScriptName() Local Const $STR_NOCASESENSEBASIC = 2 ; Not case sensitive, using a basic comparison Return StringLeft(@ScriptName, StringInStr(@ScriptName, '.', $STR_NOCASESENSEBASIC, -1) - 1) EndFunc ;==>_ScriptName
All of the above has been included in a ZIP file.
GetSavedSource.zip 3.46K
15 downloadsPreviously downloaded 100+
Edited by guinness, 20 May 2013 - 11:10 PM.








