Xenobiologist Posted December 13, 2007 Share Posted December 13, 2007 (edited) Hi, after decompilation is no more available, you cannot get your source back from the exe. I worte a script to easily add the au3 file to your source. Concept: 1. Add au3 file to source 2. Compile script Then after a few weeks you need the source from the exe. The source is protected by ... 1. The name of the executable (so you have to rename the exe to something specified before) 2. a password The script to start from Scite: (This script copies your currently opened script to temp folder, so that you can FileInstall it and append the necessary code to your script.) expandcollapse popup#include<GUIConstants.au3> ; Get SciTE DirectorHandle Global $GUI = GUICreate('SourceCode') Global $SciTECmd, $My_Dec_Hwnd, $Scite_hwnd Global $Scite_hwnd = WinGetHandle("DirectorExtension") GUIRegisterMsg($WM_COPYDATA, "MY_WM_COPYDATA") Global $My_Dec_Hwnd = Dec(StringTrimLeft($GUI, 2)) _restoreSourceCode("Mega.exe", 'Autoit') Func _restoreSourceCode($scriptName = 'source.exe', $passphrase = '') If Not ProcessExists('SciTE.exe') Then Exit (0) Local $opt = Opt('WinTitleMatchMode', 4) SendSciTE_Command($My_Dec_Hwnd, $Scite_hwnd, "askfilename:") $SciTECmd = StringReplace($SciTECmd, '\\', '\') $FilePath = StringTrimLeft($SciTECmd, StringInStr($SciTECmd, ':', Default, 3)) Opt('WinTitleMatchMode', $opt) SendSciTE_Command($My_Dec_Hwnd, $Scite_hwnd, "menucommand:106") FileCopy($FilePath, 'c:\TEMP\SourceCode.au3', 1) $h_file = FileOpen($FilePath, 1) If $h_file = -1 Then SendSciTE_Command($My_Dec_Hwnd, $Scite_hwnd, "output:+> Error open file: " & $FilePath) Exit EndIf SendSciTE_Command($My_Dec_Hwnd, $Scite_hwnd, "menucommand:106") Sleep(1000) FileWrite($h_file, FileRead($h_file) & @CRLF) FileWrite($h_file, "; ************************************************************************************" & @CRLF) FileWrite($h_file, "; SourceCode restore function " & @CRLF) FileWrite($h_file, "_restoreSourceCode()" & @CRLF & @CRLF) FileWrite($h_file, "Func _restoreSourceCode() " & @CRLF) FileWrite($h_file, @TAB & "Local $passphrase = '" & $passphrase & "'" & @CRLF) FileWrite($h_file, @TAB & "If @Compiled And @ScriptName == " & "'" & $scriptName & "'" & " Then " & @CRLF) FileWrite($h_file, @TAB & @TAB & "If $passphrase <> '' Then " & @CRLF) FileWrite($h_file, @TAB & @TAB & @TAB & "Local $re = InputBox('SourceCode recovery', 'Please, type in the password : ', '')" & @CRLF) FileWrite($h_file, @TAB & @TAB & @TAB & "If $re == '" & $passphrase & "'Then " & @CRLF) FileWrite($h_file, @TAB & @TAB & @TAB & @TAB & "FileInstall('C:\TEMP\SourceCode.au3', @DesktopDir &'\SourceCode.au3', 1)" & @CRLF) FileWrite($h_file, @TAB & @TAB & @TAB & @TAB & "MsgBox(64, 'Information', 'SourceCode restored!', 5)" & @CRLF) FileWrite($h_file, @TAB & @TAB & @TAB & "Else" & @CRLF) FileWrite($h_file, @TAB & @TAB & @TAB & @TAB & "MsgBox(16, 'Error', 'Wrong password!', 5)" & @CRLF) FileWrite($h_file, @TAB & @TAB & @TAB & "EndIf" & @CRLF) FileWrite($h_file, @TAB & @TAB & "EndIf" & @CRLF) FileWrite($h_file, @TAB & "EndIf" & @CRLF) FileWrite($h_file, "EndFunc" & @CRLF) FileWrite($h_file, "; ************************************************************************************") FileClose($h_file) EndFunc ;==>_restoreSourceCode ; Send command to SciTE Func SendSciTE_Command($My_Hwnd, $Scite_hwnd, $sCmd) $sCmd = ":" & $My_Dec_Hwnd & ":" & $sCmd Local $CmdStruct = DllStructCreate('Char[' & StringLen($sCmd) + 1 & ']') DllStructSetData($CmdStruct, 1, $sCmd) Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr') DllStructSetData($COPYDATA, 1, 1) DllStructSetData($COPYDATA, 2, StringLen($sCmd) + 1) DllStructSetData($COPYDATA, 3, DllStructGetPtr($CmdStruct)) DllCall('User32.dll', 'None', 'SendMessage', 'HWnd', $Scite_hwnd, _ 'Int', $WM_COPYDATA, 'HWnd', $My_Hwnd, _ 'Ptr', DllStructGetPtr($COPYDATA)) EndFunc ;==>SendSciTE_Command ; Received Data from SciTE Func MY_WM_COPYDATA($hWnd, $msg, $wParam, $lParam) Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr', $lParam) $SciTECmdLen = DllStructGetData($COPYDATA, 2) Local $CmdStruct = DllStructCreate('Char[255]', DllStructGetData($COPYDATA, 3)) $SciTECmd = StringLeft(DllStructGetData($CmdStruct, 1), $SciTECmdLen) EndFunc ;==>MY_WM_COPYDATA And I added this to SciteUser.properties to get a command in Scite. # 37 SourceCode command.37.*.au3="$(autoit3dir)\beta\autoit3.exe" "$(SciteDefaultHome)\OrganizeIncludes\SourceCode.au3" "$(FilePath)" command.name.37.*.au3=SourceCode command.save.before.37.*.au3=1 command.is.filter.37.*.au3=1 command.shortcut.37.*.au3=Ctrl+Shift+Alt+O Edit: I also asked in Support forum, whether there is a better or easier way doing this. So long, Mega Edited December 13, 2007 by Xenobiologist Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Developers Jos Posted December 13, 2007 Developers Share Posted December 13, 2007 Edit: I also asked in Support forum, whether there is a better or easier way doing this. So long,MegaMaybe:#AutoIt3Wrapper_res_SaveSource 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 More sharing options...
Xenobiologist Posted December 13, 2007 Author Share Posted December 13, 2007 Maybe:#AutoIt3Wrapper_res_SaveSource HI,okay and then? How to use it? So long,Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Developers Jos Posted December 13, 2007 Developers Share Posted December 13, 2007 HI,okay and then? How to use it? So long,MegaIt will save the source in the program resources and you can always retrieve it with reshacker ... 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 More sharing options...
Xenobiologist Posted December 13, 2007 Author Share Posted December 13, 2007 Hi, okay. Please do not explain to much, other might learn something! I'll have to check whether I can get the resources with resourcehacker when using FileInstall. If yes, then this is bad. So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Developers Jos Posted December 13, 2007 Developers Share Posted December 13, 2007 okay. Please do not explain to much, other might learn something! Just add this line to the top of your script: #AutoIt3Wrapper_Res_SaveSource=y This will create a new section in the resources of the program called AutoIt3:ScriptSource. Just try it and run Reshacker and look for this section. There is really nothing more to 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 More sharing options...
livewire Posted December 13, 2007 Share Posted December 13, 2007 Works for me...as long as you don't use UPX when you compile. Link to comment Share on other sites More sharing options...
Developers Jos Posted December 13, 2007 Developers Share Posted December 13, 2007 Works for me...as long as you don't use UPX when you compile.You can always run "UPX -d" first when you want to retrieve the source. 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 More sharing options...
Zedna Posted December 14, 2007 Share Posted December 14, 2007 Here is my attempt for script to extract such resource from EXE at runtime Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Xenobiologist Posted December 14, 2007 Author Share Posted December 14, 2007 Just add this line to the top of your script: #AutoIt3Wrapper_Res_SaveSource=y This will create a new section in the resources of the program called AutoIt3:ScriptSource. Just try it and run Reshacker and look for this section. There is really nothing more to it ..... Hi, yes, I already did that right after you posted your first post. But isn't it more secure to go the way I do? FileInstall instead of adding to resources? There should be a little trick to get the source back, so that not everybody can use it. So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
JerryD Posted December 14, 2007 Share Posted December 14, 2007 (edited) Even before decompilation was discontinued, I always include the following code in my scripts If $CmdLine[0] = 2 AND $CmdLine[1] = '/source' AND $CmdLine[2] = 'password' Then FileInstall ( 'ScriptName.au3', 'ScriptName.au3', 1 ) Exit EndIf I also FileInstall any files needed to rebuild the program from scratch like icons and custom include files. It has not only saved my butt many times, but makes it a LOT easier to rework a very old script. Downside - the program is slightly larger, if you actually use a password, you have to remember it or have it documented someplace! Upside - the script and source can be protected, and you can use UPX which offsets the size issue. I've only had to actually protect one script over the last several years (and thankfully it's out of production!) - all other scripts use the code above, so it's usually easy to retrieve the original source. And I have to admit, this technique was derived from a post here years ago. Thanks to whoever that was! Edited December 14, 2007 by JerryD Link to comment Share on other sites More sharing options...
Developers Jos Posted December 14, 2007 Developers Share Posted December 14, 2007 Upside - the script and source can be protected, and you can use UPX which offsets the size issue.UPX compresses the Executable's header only. By default, the FileInstall(ed) files are compressed by a buildin compression mechanism. see the compressionlevel option in aut2exe or the directive in SciTE4AutoIt3. 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 More sharing options...
Xenobiologist Posted December 14, 2007 Author Share Posted December 14, 2007 Hi, so Jos, what would you do, to get the au3 source back? Which concept do you prefer? Thanks! So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Developers Jos Posted December 14, 2007 Developers Share Posted December 14, 2007 Hi,so Jos, what would you do, to get the au3 source back?Which concept do you prefer?Thanks!So long,MegaI never use any of this myself because I put all my scripts in SVN to have version control and update history for my scripts. 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 More sharing options...
MaudKip Posted December 14, 2007 Share Posted December 14, 2007 Ok I read the first few lines of your post, then I stopped and tried my own Idea. Here is what I got. If @ScriptName = "Pass.exe" Then $a = InputBox("Password", "Please type the password...", "", "*") If $a = "Pass" Then FileInstall("test.au3", @ScriptDir & "\" & "Source_" & @ScriptName & ".au3") EndIf EndIf ;Your code here. Exit After I got it working I read the rest of the thread and realized that this is not the same thing lol. Still, thanks for the idea. =] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now