Denis, that looks exactly like what I am looking for. How did you produce this?
Anything you can share?
Thanks
– MartinB
i can… why not… partly
here is a function to encrypt a text or a string using .net
fn encryptText plainText tKey: tIV: =
(
dnConvert = dotnetClass "System.Convert"
dnUTF8 = dotNetObject "System.Text.UTF8Encoding"
algorithm = (dotnetClass "System.Security.Cryptography.SymmetricAlgorithm").Create()
encText = dnUTF8.GetBytes plainText
memStream = dotnetObject "System.IO.MemoryStream"
cStreamMode = (dotnetClass "System.Security.Cryptography.CryptoStreamMode")
cStreamTransform = algorithm.CreateEncryptor tKey tIV
cStream = dotnetObject "System.Security.Cryptography.CryptoStream" memStream cStreamTransform cStreamMode.Write
cStream.Write encText 0 encText.Count
cStream.FlushFinalBlock()
cipherBytes = memStream.ToArray()
memStream.Close()
cStream.Close()
dnConvert.ToBase64String cipherBytes
)
here is how to use it:
/*
bKey=#(1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2)
bIV=#(1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6)
encryptText "test" tKey:bKey tIV:bIV
*/
Thanks very much for sharing!
From what I see this is a function to encrypt a string; but how do you parse an existing piece of maxscript code to find the strings to replace?
I personally don’t even need to encrypt any names, I could just replace them with random letters. What is giving me trouble is the correct parsing of MAXScript code to identify the parts that can be renamed and those that need to stay – any solution to that?
– MartinB
after that you have to find all function names, variables, and arguments and rename them…
i always use ‘fn functionname <args> = (<body>)’ definition, so it’s easy for me to find all functions and arguments.
if i start all variables with ‘local ’ or ‘global’ i can also easily find them.
next is redefinition… you can make a list of built-in function for redefinition like
thePreRotateY = prerotateY
myCOS = cos
‘uglify’ them too
and last remove spaces, tabulations, replace ’
’ to ‘;’ or ‘’ and… that’s pretty it. ready to ship
not many know that mxs syntax allows to write code like:
fn'1234''12''13'=print('12'*'13')
'1234'2(6)
use it
for structures, plugins, ui definitions it might be more complicated. that’s why i said above that code has to be ‘specially prepared’
Denis, that looks indeed very very unreadable ! Worse than i ever would believe that it would still run …
@Martin:
what i meant is simply replacing function, struct and other variable names etc with GUIDs.
http://msdn.microsoft.com/en-us/library/system.guid.newguid(v=vs.110).aspx
This would ensure that you don’t get any name clashes, as by simply randomizing there are chances that you get the same randomized names string two times for different functions
But using Denis’ encryption scheme is far more advanced of course …
i’m glad you like it but i worry that all new scripts on ScriptSpot will be written this way soon.
((dotnetclass "System.Guid").NewGuid()).ToString()
looks ugly too but it’s one way ticket
Almost all of my commersial scripts are written using obfuscation. I have only to prepare a list with all words that the obfuscator have to skip. Then everything is a one clisk solution.
The final result is not so complicated as Denis showed and looks like this:
function miauuada16aec09034c8fbc3f34eee3 miauuc3f672d9789a43cda765c40937 =;(;local miauu72031bb8550f4e3c90c4a45bef = #();local miauu6f6dace50f5141d68088a37764 = #{1..(miauuc3f672d9789a43cda765c40937.numverts)};miauu72031bb8550f4e3c90c4a45bef = for miauuf15b86c3b89145169d6c452ec7 in miauu6f6dace50f5141d68088a37764 collect (miauuf8090e3093054f329bd567687e miauuc3f672d9789a43cda765c40937 miauuf15b86c3b89145169d6c452ec7);miauu72031bb8550f4e3c90c4a45bef;);
All of my free scripts is written in “standard way”.
Looks like you indeed use GUID’s for the function and variables names, with your prefix added
and you put functions in a oneliner…
so essentially it looks like the options settle on those basic possibilities and people have had similar ideas