emendelson Posted April 26, 2023 Share Posted April 26, 2023 (edited) I compile some of my executables with the option to include the source code in the program resources. Is there an easy way for an end user to extract the source code? The answer is probably obvious, but I can't find it, and will be grateful for any pointers. EDIT: To be clear: I'm talking about my own code that I want to make available to other users. I am NOT, repeat NOT, asking about decompiling someone else's code. I am asking about how to give the user access to the script that I wrote and that I want to share, using the option built into the AutoIt compiler. Edited April 26, 2023 by emendelson Link to comment Share on other sites More sharing options...
Developers Jos Posted April 26, 2023 Developers Share Posted April 26, 2023 (edited) You mean using the #autoIt3Wrapper directive? Edited April 26, 2023 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 More sharing options...
emendelson Posted April 26, 2023 Author Share Posted April 26, 2023 (edited) 9 minutes ago, Jos said: You mean using the #autoIt3Wrapper directive? Yes, this directive: #AutoIt3Wrapper_Res_SaveSource=y It's the same option that SciTe puts on the Compile->Resource Update tab, where you can check a box that says "Save a copy of the Scriptsource in the output program resources." Again, just to be one-hundred-percent clear: I am talking about making my own code - the code that I wrote - available to an end user, NOT trying to extract someone else's code. Edited April 26, 2023 by emendelson Link to comment Share on other sites More sharing options...
emendelson Posted April 26, 2023 Author Share Posted April 26, 2023 One thought: is it possible to write the script so that a user could use a command-line parameter to the program that would extract the source? Link to comment Share on other sites More sharing options...
Developers Solution Jos Posted April 26, 2023 Developers Solution Share Posted April 26, 2023 (edited) Just try this code which you can save as RetrieveSource.au3, compile and then F5/Run in SciTE #AutoIt3Wrapper_Res_SaveSource=y ; https://www.autoitscript.com/forum/topic/162499-resourcesex-udf #include <ResourcesEx.au3> Const $RCData = 999 Global $Source $ExeFile = "RetrieveSource.exe" If FileExists($ExeFile) Then $SavedSource = _Resource_GetAsString(999, 10, 2057, $ExeFile) ConsoleWrite('$SavedSource = ' & $SavedSource & @CRLF) EndIf Edited April 26, 2023 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 More sharing options...
emendelson Posted April 26, 2023 Author Share Posted April 26, 2023 Thank you, @Jos! That definitely works, thought I had to add an include line to ResourcesEx.au3 (I added five at once, and clearly one of them worked - I'll sort out which one it was and post something in the thread about it.) Now my next job is to figure out how to make this available for the user from my actual script - maybe as a command-line option. I'll have to experiment to see if the script can extract its own source code. Again, thank you! Link to comment Share on other sites More sharing options...
emendelson Posted April 26, 2023 Author Share Posted April 26, 2023 (edited) @Jos- To continue: ResourcesEx.au3 gave an error until I added this to the code. #include <WinAPI.au3> I'll post a message about that on its thread. Edited April 26, 2023 by emendelson Link to comment Share on other sites More sharing options...
emendelson Posted April 27, 2023 Author Share Posted April 27, 2023 Further details: This routine at the top of a script makes it possible for the end-user to extract the source, by changing the name of the executable so that it includes "extract": ; make sure to include this in the directives at the top of the script: #AutoIt3Wrapper_Res_SaveSource=y ; then add this near the top of the source so the user can extract the source #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> ; https://www.autoitscript.com/forum/topic/162499-resourcesex-udf #include <ResourcesEx.au3> If StringInStr(@ScriptName, "extract") Then $Manifest = _Resource_GetAsString(999, 10, 2057, @ScriptFullPath) $hSource = FileOpen(@ScriptDir & "\" & @ScriptName & "-source.au3", 1) FileWrite($hSource, $Manifest) FileClose($hSource) Exit EndIf Is there a size limit for the Manifest? I can make this work in some of my scripts, but not in at least one that's much longer than the others. Link to comment Share on other sites More sharing options...
emendelson Posted April 27, 2023 Author Share Posted April 27, 2023 ... and I see that this was thoroughly discussed earlier: Apologies for not finding this earlier. Link to comment Share on other sites More sharing options...
Developers Jos Posted April 27, 2023 Developers Share Posted April 27, 2023 8 hours ago, emendelson said: @Jos- To continue: ResourcesEx.au3 gave an error until I added this to the code. #include <WinAPI.au3> I'll post a message about that on its thread. There was indeed an include extra in my version. I've added it in the download on the first page I've made available. 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...
Developers Jos Posted April 27, 2023 Developers Share Posted April 27, 2023 5 hours ago, emendelson said: Apologies for not finding this earlier. No worries, I knew about that one too, but just wanted so show a simple version I already had and also works. 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...
Lion66 Posted June 14, 2023 Share Posted June 14, 2023 In the past for these purposes I used FileInstall Link to comment Share on other sites More sharing options...
Nandhulal Posted March 5 Share Posted March 5 Hi , I tried the above code,but it doesn't work for me. it showing an error as "#include <ResourcesEx.au3> Error: Error opening the file" Anyone please explain how it can be fixed? or share the working code Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 5 Moderators Share Posted March 5 57 minutes ago, Nandhulal said: Hi , I tried the above code,but it doesn't work for me. it showing an error as "#include <ResourcesEx.au3> Error: Error opening the file" Anyone please explain how it can be fixed? or share the working code It took about 2 seconds to do a search : robertocm and argumentum 2 Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. 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