Jump to content

How to extract source code from exe compiled with source code?


Go to solution Solved by Jos,

Recommended Posts

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 by emendelson
Link to comment
Share on other sites

  • Jos locked and unlocked this topic
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 by emendelson
Link to comment
Share on other sites

  • Developers
  • Solution

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 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

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

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

  • Developers
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

  • Developers
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

  • 1 month later...
  • 8 months later...

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

  • Moderators
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 :whistle::

 

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

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...