Jump to content

_GetSavedSource() - Retrieve the saved source file from an AutoIt exe.


guinness
 Share

Recommended Posts

Updated the UDF with using UDFs included in AutoIt v3.3.10.0+.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • 1 month later...

Updated the function. This was a total re-write including the first example.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • 1 year later...

Very Helpfull, but when testing i had a problem with the encoding of the extracted file (german language specific chars like äöüß). So i had look in your included file, and changed:

Local $hFilePath = FileOpen($sSaveFilePath, BitOR($FO_OVERWRITE, $FO_UTF8 ))

 $FO_BINARY =>  $FO_UTF8 solved my encoding problem. 

Edited by AutoBert
Link to comment
Share on other sites

5 hours ago, AutoBert said:

Very Helpfull, but when testing i had a problem with the encoding of the extracted file (german language specific chars like äöüß). So i had look in your included file, and changed:

Local $hFilePath = FileOpen($sSaveFilePath, BitOR($FO_OVERWRITE, $FO_UTF8 ))

 $FO_BINARY =>  $FO_UTF8 solved my encoding problem. 

I have update the function in the first post. Thanks

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • 5 years later...

A one liner ...
-----------------------
If StringInStr($CmdLineRaw, '/SaveSource') Then FileInstall(@ScriptFullPath, _
@ScriptDir & '\' & StringLeft(@ScriptName, StringLen(@ScriptName) - 4) & '.au3', 1)

                                                                                                                                           ----^ 0 here, if you don't want an auto overwrite.

Edited by Comatose
Link to comment
Share on other sites

  • Developers

@Comatose, what exactly do these lines have to do with the topic? It is about retrieving the savesource, not saving it. ;)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

I understand,  but has nothing to do with this topic other than it is another alternatieve to save the source of the main script, posted already several times in a past. ;)

This udf is to retrieve the source saved by: 

#AutoIt3Wrapper_Res_SaveSource=Y
Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

It's cool cuz it's generic and a one liner ... 
Good job with your code! 

Edit: Not cutting your work it's really deep. Just the whole concept of how this would be used. It's just a temp thing that will be removed or used for archiving. Either way the one liner is all you should ever need. The SaveSource=Y literally adds the text version of the script and that can easily be copied out a number of ways ...

But again, it's a sweet rabbit hole good work.
Also: I was kind of shocked. I thought you needed actual file names for FileInstall to work at all.
It seems you can use @!

Edited by Comatose
Link to comment
Share on other sites

BTW there are 2 bugs in the UDF . One can be considered major. If you specify an executable file without a source in it, it will erase the save au3 file.

Here a revised version without those 2 bugs :

Func _GetSavedSource($sExecutable = '', $sSaveFilePath = '')
    Local Enum $GETSAVEDSOURCE_ERROR_NONE, $GETSAVEDSOURCE_ERROR_FILEWRITE, $GETSAVEDSOURCE_ERROR_FINDRESOURCE, $GETSAVEDSOURCE_ERROR_LOADMODULE
    Local $iError = $GETSAVEDSOURCE_ERROR_LOADMODULE
    Local $hInstance = ($sExecutable = Default Or StringStripWS($sExecutable, $STR_STRIPALL) = '') ? _WinAPI_GetModuleHandle(Null) : _WinAPI_LoadLibraryEx($sExecutable, $LOAD_LIBRARY_AS_DATAFILE)
    If $hInstance Then
        $iError = $GETSAVEDSOURCE_ERROR_FINDRESOURCE

        ; Get the source file from the executable. This is located at resname 999
        Local $hResource = _WinAPI_FindResource($hInstance, $RT_RCDATA, 999)
        If $hResource Then
            Local $hData = _WinAPI_LoadResource($hInstance, $hResource)
            Local $iSize = _WinAPI_SizeOfResource($hInstance, $hResource)
            Local $pResource = _WinAPI_LockResource($hData)

            If $sSaveFilePath = Default Or StringStripWS($sSaveFilePath, $STR_STRIPALL) = '' Then
                $sSaveFilePath = @ScriptDir & '\' & StringLeft(@ScriptName, StringInStr(@ScriptName, '.', $STR_NOCASESENSEBASIC, -1) - 1)
            EndIf

            $iError = $GETSAVEDSOURCE_ERROR_FILEWRITE

            Local $hFilePath = FileOpen($sSaveFilePath, BitOR($FO_OVERWRITE, $FO_BINARY, $FO_UTF8))
            If $hFilePath > -1 Then
                $iError = $GETSAVEDSOURCE_ERROR_NONE

                Local $tBuffer = DllStructCreate('byte array[' & $iSize & ']', $pResource)
                FileWrite($hFilePath, DllStructGetData($tBuffer, 'array'))
                FileClose($hFilePath)
            EndIf
        EndIf
        _WinAPI_FreeLibrary($hInstance)
    EndIf

    Return SetError($iError, 0, $iError = $GETSAVEDSOURCE_ERROR_NONE)
EndFunc

Here how I use it :

#include <WinAPIRes.au3>
#include <Constants.au3>
#include <File.au3>

Local $sFileExe = FileOpenDialog("Select EXE", @ScriptDir, "Exe (*.exe)")
If @error Then Exit
Local $sDrive, $sDir, $sFileName, $sExtension
_PathSplit($sFileExe, $sDrive, $sDir, $sFileName, $sExtension)
If Not _GetSavedSource($sFileExe, $sDrive & $sDir & $sFileName & ".au3") Then MsgBox($MB_SYSTEMMODAL, "Error", @error)

 

Edited by Nine
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...