Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Crack a Run-only Applescript

I need your help ~

I accidently saved an AppleScript I wrote as Run-only, and still want to make revisions to it. Is there a way to still open it in an editor?

Thanks much in advance,

Chuck

PB Ti 1GHz - The last of it's kind, Mac OS X (10.4.7)

Posted on Aug 29, 2006 6:50 PM

Reply
Question marked as Best reply

Posted on Aug 29, 2006 7:28 PM

No. There's no way to recover the original source. When saved as run-only, much of the original file (including a text-only version of the script) is omitted. There's no way to revert the compiled version back to readable text.
7 replies

Aug 30, 2006 6:05 AM in response to ChazH

When an applet (AppleScript application) is saved, as 'Run Only', the code is saved into a resource fork (of the file) 'scpt' type. The resource has - a multiple byte header, the embedded (compiled) code, and ends with 'FADEDEAD'.

When a script is saved, as 'Run Only', the code is saved into the data fork (of the file). The data has - a multiple byte header, the embedded (compiled) code, and ends with 'FADEDEAD'.

----

When code is saved as an applet or script, as 'Run Only' - all comments are removed to reduce the finished file size.

Aug 30, 2006 8:47 AM in response to Camelot

No. There's no way to recover the original source.
When saved as run-only, much of the original file
(including a text-only version of the script) is
omitted. There's no way to revert the compiled
version back to readable text.


Camelot, pardon my ignorance, but why is that? Does it convert the english-like syntax into some other machine language? If so, what language?

Aug 30, 2006 9:13 AM in response to Ang Moh

Thanks Camelot and dev_sleldy ~

Based upon your two responses I figured out there are a couple of things that can be done to retrieve at least part of the text of a run-only script. The first tip was that AppleScript Editor still saves files (both scripts and applications) with resource and / or data forks. I assume this is the case so that AppleScript scripts / apps are backwards compatible with OS 9 and earlier (but is not important here).

With a utility such as ResKnife (obtainable at http://www.versiontracker.com/dyn/moreinfo/macosx/29105), one could open the fork and get some of the text in the the "scpt" fork. Unfortunately I could not get the copy / paste function to work, but manually copied the text from ResKnife, and still had to add much of what was not obvious in the text. And from what I understand, according to dev_sleldy, one can use either a *.app or a *.scpt file (I used a *.scpt file myself).

In addition one can run a script from another script with the following, just paste it into a new Editor window and run, and view the event log. One can copy and past the event log text, but it will not have everything, and will require some additional editing.

tell application "Finder"

set theScript to choose file with prompt "Select a locked script:"
set theScript to load script theScript
run theScript

end tell

With these two methods I was able to rebuild about 75% (including the finely honed shell script calls) of my script, and from memory and other resources was able to rebuild the rest.

Thanks all, and hope this helps!

Chaz

Aug 30, 2006 11:54 AM in response to Ang Moh

>Camelot, pardon my ignorance, but why is that? Does it convert the english-like syntax into some other machine language? If so, what language?

(Note: this is an overly-simplistic outline of the process and not meant as a technical discussion of compiler/decompiler theory - it's way more involved that I'm going to get into now).

AppleScript is technically a tokenized language - when you 'compile' a script it converts it to a format that uses tokens for commands, variables, handlers, etc. This process optimizes the script in several ways since it eliminates the lexical parser (e.g. working out that "... is greater than..." is equivalent to >, although it goes much deeper than that).

Part of the tokenization process replaces all variable names with pointers to variables - for example, when your script is running AppleScript doesn't need to know 'myVeryLongVariableName' when all it needs is 'variable #32'.

Part of the compiled script keeps a reverse table of variable names, so that when you reopen the script AppleScript displays 'myVeryLongVariableName' rather than its internal representation of that variable name. When you save as Run Only, much of this information is not saved since you'll never need to go back.

That's why, at the very least, when you decompile a script (or any compiled code for that matter), you'll usually end up with mush. Some of the built-in commands may be converted, any strings should be intact (which is why things like 'do shell script' commands may be visible, but any handler names and variable names are likely to be lost.

Crack a Run-only Applescript

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.