[Closed] dotNet: unzip base64 encoded data
Here’s a question for the dotNet-enabled MAXScripters out there:
I have a file that I want to compress and then encode as base64. Then I want to include that base64 string data within a MAXScript (instead of loading the file from disk). Next, I want to use dotNet to a.) decode the base64 data (possibly using System.Convert.FromBase64String) and finally b.) decompress the data (maybe using System.IO.Compression.DeflateStream) to use it in MAXScript. I included some dotNet methods in brackets as s starting point, but they might not even be the right methods for the task?
I did some test and always get a “NET runtime exception: Unknown block type. Stream might be corrupted” error when trying to deflate the data – maybe I am using an incorrect compression scheme, maybe something is wrong with my decoding…?
Anyone in here knowledgeable with dotNet that could help?
Thanks!
Is your question related to this script: http://www.scriptspot.com/3ds-max/scripts/maxscript-encrypt-and-protect
Since the script is encoded we can’t see the code and I think that thе author can “decrypt” any script encoded with his tool. So, I am also curious for the readable code of the tool and the possibility the user to choose the encoding(so to be able to decoda later)
Not really. That is an interesting obfuscation script, though (that you have to trust, eventually). I know too little dotNet to tell how effective the obfuscation really is.
Code Obfuscation and Encryption are different things.
The tool you mention does not obfuscate a MaxScript script, it simply encrypts and decrypts a script. As far as I can see it uses Rijndael encryption, which requires a key and a vector parameters.
The key and vector parameters used to decrypt the script are hardcoded, and so while most people won’t be able to decrypt a script, the developer of that tool can do it in a click.
Because the source MaxScript script is not obfuscated at all, once it is decrypted everything will be readable, just as how it was before you encrypted it, including comments, variable names, functions, everything.
While the approach of encrypting a script is not bad (it is in fact what an .MSE file is), you would have to create your own encryption/decryption tool to be on the “safe” side. That would be just until someone figure out the encryption key/s and the used algorithm.
but the encrypting dotnet dll which comes embedded in the mentioned mxs encryption tool ( and which does the maxscript encryption in the end i presume ) is heavily obfuscated – am i correct with my conclusion ?
For zipping and unzipping I’ve used Zipstorer as an assembly ( https://github.com/jaime-olivares/zipstorer ). It’s no fuss and solid. I’ve only had to encode stuff to base64 strings like so
Byte[] bytes = File.ReadAllBytes(filepath);
String file = Convert.ToBase64String(bytes);
Hope this helps
This is what you have to do to encrypt/decrypt a text.
- Create the Encrypt/Decrypt functions in C# (C++ would be ways better).
- Obfuscate and compile your library
If it is in C#, then you can create an assembly and load it from MXS, just like the mentioned tool does. You can add more weird things like encoding, but that doesn’t make any difference.
If it is a SDK function then you just call the function and pass the encrypted script.
With either methods, once you get the resulting script text, you just execute it in memory. That’s why the author of the scripts advises that you can’t use functions like getSourceFilename() because they need a file in the hard drive to work.
I have moved my post to new thread, because It is not related with the Martin’s question.