cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
pauldeen
Level VI

How to check if the running script is encrypted

From a running script I would like to do a check if the script is encrytped or not. This is to seperate behavior between development versions and release versions of a script without having to change variables in the code. So something like:

If( !Script is encrypted(),
  //Do bit of code for development version
,
  //Do bit of code for release version
)

 

One way is to check if the script starts with "//-e12.1" which seems to be on the top of all encrypted scripts.

Left(LoadTextFile(IncludeFileList()[1]),8)== "//-e12.1";

But this doesn't work from VSCode as it gives:

pauldeen_0-1682071059364.png

so you will always run the release code.

1 ACCEPTED SOLUTION

Accepted Solutions
Craige_Hales
Super User

Re: How to check if the running script is encrypted

//
// This reports if the isEncrypted function is
// encrypted, NOT some file it might be called from.
// It works because part of the JSL encryption tries
// to prevent the internals (like expressions) of
// your JSL from being converted to text that could
// be printed.
//

isEncrypted = Function( {},
	{x},
	x = Expr( 1 + 1 );
	Char( Name Expr( x ) ) != "1 + 1";
);

write("\!n isEncrypted()=",isEncrypted(),"\!n");
Craige

View solution in original post

6 REPLIES 6
pauldeen
Level VI

Re: How to check if the running script is encrypted

I created a wish list item for this

StarfruitBob
Level VI

Re: How to check if the running script is encrypted

@pauldeen,

 

I haven't tried this, but I see that encrypted scripts are wrapped in the Encrypted() function. This means that you might be able to include() a target script, parse the script to see if one of the function headers contains() the Encrypted() header.  This is vague response, but it may be possible.

 

StarfruitBob_0-1682531071362.png

Here's where within the JMP Documentation Library.pdf I screenshotted the information from for JMP 17.0.0.

StarfruitBob_1-1682531224043.png

 

 

Learning every day!
Craige_Hales
Super User

Re: How to check if the running script is encrypted

//
// This reports if the isEncrypted function is
// encrypted, NOT some file it might be called from.
// It works because part of the JSL encryption tries
// to prevent the internals (like expressions) of
// your JSL from being converted to text that could
// be printed.
//

isEncrypted = Function( {},
	{x},
	x = Expr( 1 + 1 );
	Char( Name Expr( x ) ) != "1 + 1";
);

write("\!n isEncrypted()=",isEncrypted(),"\!n");
Craige
vince_faller
Super User (Alumni)

Re: How to check if the running script is encrypted

Our vscode extension can't even really run encrypted stuff from the editor unless it's an include.  If it's safe to assume encryption is all or nothing, then I think @Craige_Hales is probably the best option.  

 

If you need to it to be module specific, that's harder as we don't run the expression as an include (because sometimes the file isn't saved so it wouldn't be an include).   

Depends on how you're setting up scopes.  Maybe you could just hardcode the name of the file instead of using the includefilelist()?

 

For example.  I created a script `test.jsl`

Names Default to here(1);
isEncrypted = Left(LoadTextFile("test.jsl"),9)== "//-e6.0.2"; // I had to edit this because that's what my encryption gives.  

if(isEncrypted, 
    print("This script is encrypted"),
    print("This script is not encrypted")
);

If I encrypt that script then include it from another script in vscode I can get.  

 

vince_faller_0-1682549376758.png

 

This definitely isn't perfect and assumes A LOT about your structure.  But maybe that's helpful?  

Either way I've made an issue in the GitLab Repo 

 

@ben_ph maybe you can think of a better workaround? 

Vince Faller - Predictum
pauldeen
Level VI

Re: How to check if the running script is encrypted

Thanks all for your suggestions! My goal was to do development work in VSCode, then encrypt and package the whole thing up in an add-in. So this is about checking if the main file is encrypted, when it is run in JMP directly or in development mode while still within VS Code. Craige's solution gives me the functionality I was looking for!

ErraticAttack
Level VI

Re: How to check if the running script is encrypted

Careful relying on the encryption -- it is quite simple to beat unless you're using functions -- as in, an encrypted file that is one function and nothing else is pretty secure, but if it's classes or just a generic script, it is quite easy to get the OG script out.

Jordan