Jump to content
tbexon

Encrypting Python Plug ins

Recommended Posts

So I am attempting to encrypt some plug ins objects (a mix of .vso and vsm objects) to distribute to others. 

 

I've done some searching of this wonderful forum, aswell as reading the Vectorscript Guide section on encrytion.

 

Following the instructions in this thread.

 

I created a XML File named the same as my PIO, My code is directly inside the object so I don't need to include any extra files so my XML file just looks like this:

 

<?xml version="1.0" encoding="UTF-8" standalone="no"?><!-- This file defines how the corresponding script plug-in should be packaged--><Plugin>
    <Package>
    </Package>
</Plugin>

 

I've selected my plug in in the plug in manager, used the Ctrl+Shift+Alt and Double Click method, confirmed twice that I want to encrypt it.

 

All seems to be successful, it won't let me edit the script anymore.

 

However if I go look at the .vso file in a text editor I can still see all the code.

 

Also if I copy the file out of my plug in folder, and then copy it back in, replacing the original, (To try and test installation process for another a new user) I can then edit the scripts again.

 

Am I missing something super obvious? I've seen other people running into similar problems in other threads, but I haven't found any solutions anywhere.

Share this post


Link to post

I generally encrypt via the batch encryption plug-in, as it works on files in any folder, so I can copy the original .vso, .vsm, and .vst files, encrypt the copies, and not worry about accidentally locking myself out of the code forever.

 

You shouldn't need the xml file if you're not using any external includes or dependancies.

 

I suspect a cache may be at play. Try quitting Vectorworks and seeing if that preserves the lock. I believe this may particularly be necessary on PC.

Share this post


Link to post

Is this the batch encryption plug-in from the SDK?

 

I must admit I haven't really delved into SDK yet. I've downloaded it, located the batch encryption plug in, a .vlb file??  From looking at this wiki page the way I read it is a .vlb is a SDK plug in, and I should be able just put it in my plug in folder?

 

I attempted this, and couldn't see the plugin from the plug in manager.

 

I'm guessing i'm missing (several) steps?

 

 

Share this post


Link to post

The batch encryption library is included in the SDK download, but isn’t really otherwise part of the SDK. I believe it’s actually included with 2019+, so you won’t need to do any extra installation. All it does is add two extra vs commands, so you won’t see anything in the plug-in manager. 
 

https://developer.vectorworks.net/index.php/VS:EncryptPlugin


Note that the path here can be anywhere on your drive. If you have multiple files to encrypt, you can use python’s regular directory parsing routines to iterate through a folder of plug-ins. 

Share this post


Link to post
Posted (edited)

Ah Thanks

 

I had originally looked at using vs.EncryptPlugin, but I don't believe it's included in 2020 Library as standard as I kept getting errors saying the command wasn't valid. 

 

Since placing the Batch Encryption Library in my plug in folders, those commands do now work. 

 

I'm using this code to iterate through everything in the required folder:

import vs
from os import listdir

folderpath = "D:\\Users\\tbexo\\Batch Encrypt Plug ins\\"
filelist = listdir(folderpath)

for eachitem in filelist:
	full_path = folderpath+eachitem
	vs.EncryptPlugin(full_path)

vs.AlrtDialog("All Plug ins Encrypted")

 

Even though i am only encrypting one .vsm with no dependencies (i've also tried .vso's just to be safe) I get an error saying that no "Plug Name".xml file can be found. So I create a XML file, same as I detailed above, and the operation does seem to be successful (Or atleast go through with no errors).  

 

HOWEVER my plug ins still aren't being encrypted properly.

 

When I copy the encrypted plug-in back into my VW Plug-in folder, VW Plug in Manager does recognize that it's an encrypted plug in, however I can still see the all the code when I edit it them with a text editor.

 

I'm not sure what i'm doing wrong at this point?  

Edited by tbexon

Share this post


Link to post

I just tried the exact same encryption script with a Vectorscript plug in, worked absolutely fine, the file is completely encrypted, so this seems to be a python specific issue?

Share this post


Link to post
27 minutes ago, tbexon said:

I just tried the exact same encryption script with a Vectorscript plug in, worked absolutely fine, the file is completely encrypted, so this seems to be a python specific issue?

 

Yes, python scripts are more locked than encrypted, which is just the nature of the embedded python compiler. Try searching the forum for "obfuscate". If you use external files for the code, you should be able to use the .pyo and .pyc files from __pycache__ to make copying code a little more difficult.

  • Like 1

Share this post


Link to post

Thanks Joshua, that's really helpful!

 

Guess thats my weekend then! Doing some research into obfuscation...

Share this post


Link to post

It has been a little while since I have dealt with this, but if I recall correctly, with python based plug ins, you have to get the code out of the main vso object in order to actually encrypt it and hide its code.  i.e., make an external _main.py file, and then in the script that you can see from within the Vectorworks plugin manager, you would only have 

 

import _main
_main.execute() 

 

You can use the xml file to identify this external file to be bundled

 

 

 

 

Share this post


Link to post

Thanks David,

 

So i've been doing some more reading around this.

 

As per you're suggestions i've now structured by plug ins so that the plug in script is simply:

 

import script_name

Then I have a separate .py file with all my script in.

 

This works absolutely fine, until I come to encryption.

 

To Encrypt I take the (in this case) .vsm file, but it into my batch encryption folder, I take the .pyc file from __Pycache__ and add that into the same directory. 

I have a XML File named the same as the .vsm file. The XML looks like this:

<?xml version="1.0" encoding="UTF-8" standalone="no"?><!-- This file defines how the corresponding script plug-in should be packaged--><Plugin>
    <Package>
		<file>DMX_Parameters_Per_Position.pyc</file>
    </Package>
</Plugin>

I then run a script that runs the vs.EncryptPlugin(full_path) command on the specific file. This doesn't return any errors, all seems happy.

 

However when I copy the .vsm back into VW Plug in folder, and remove the orginal my_script.py. I get an error saying that the script can't find my_script module to import. Then if I restore the my_script.py everything works again.

 

My understanding of .pyc files was that they are a compiled version of the .py script, and most of the responses I have read online suggest that a script should be able to import a module from a .pyc just fine. I've tried variations of having the .pyc in the same directory as the plug in command, aswell as within it's original __pycache__ folder.

 

I'm unsure at this stage whether I am doing something wrong with the XML file and VW isn't looking in the right place for the file, or if i've misunderstood something fundamental about .pyc and .py files?

Share this post


Link to post

I think I may not have enough info to answer this regarding batch encryption.

 

For one plugin at a time, I think that what I have done in the past is to delete the __pycache__ folder and the .pyc files within, leaving only the vsm or vso file, the xml file, and the source .py files, then following the steps in

which describes encrypting a single plugin from the Plugin Manager (as an alternative to EncryptVSPluginFilePath call) holding Ctrl+Shirt+Alt on win or Ctrl+Option+Cmd+Shift+CapsLock on mac and double click on a plugin. 

 

I'm not sure how encrypted this actually makes things, and how easy it is or is not to decompile / unencrypt in some way, but I think the code is not listed in plain text at least

 

@Vlado may be able to clarify further on the process and its relationship to .pyc files, and how to ensure that the source code truly cannot be accessed in some way.

Share this post


Link to post

Interesting I shall give this a go! 

 

I was under the impression that the Ctrl+Shift+Alt method was basically just calling the vs.EncryptPlugin() function. I shall try encrypting via this method and report back!

Share this post


Link to post

 @David Bengali

 

> clarify further on the process and its relationship to .pyc files, and how to ensure that the source code truly cannot be accessed in some way.

 

The python would compile the .py files into .pyc files before execution. This is part of python and always happens, it always executes the pyc files, and it has some smarts to not compile if the py didn't change.

 

The pyc files are binary files that are byte-code of the python code. I guess you can read more about them in the python documentation. As far as I know, it can be uncompiled but it doesn't restore variable names, comments, etc.

 

The process of encrypting a python plugin in Vectorworks consist of bundling all .pyc files into the vsm, vso, or vst files. It essentially, copies the binary files as is, one after the other in the vso, vsm, and vst file. This adds a little protection too as it's becomes one big binary now. Even though, if you really wanted, and analysed the bytes, you can figure it out.

 

let me know if you have more questions.


Regards,

Vlado

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×
×
  • Create New...