Clear Filters
Clear Filters

hiding 1) content of .mat file and 2) .m file names as well as the content

10 views (last 30 days)
Hi there, I need to send a software, containing about 50 files including .m, compiled mex, and .mat, to be used by someone who will test it in matlab. I need to hide: 1) content of .m files, 2) content of .mat files (I load during the run of my .m files), 3) the file names
What is the proper way to do it?
I believe pcode is not quite appropriate, and mcc is not quite right for?
Thank you in advance, Paul Ki

Accepted Answer

Jan
Jan on 27 Nov 2011
You cannot hide the contents securely, if you want the user to run your program. Even if you encrypt the MAT files, you need a function to decrypt them and then the values are found in clear text in the memory, from where they can be copied by a debugger.
P-coding the M-files is sufficiently secure, if the costs of the software are less than 10$ per line.
You can read the MAT files and convert it to M-code, e.g. by FEX: generate-m-file-code-for-any-matlab-variable . Then you can P-code the results.
Compiled MEX files are a kind of encrypted already. It is not trivial to use a reverse-engineering to get the contents of the files.
I suggest to look how others solve the problem of shipping a program for testing: E.g. MathWorks delivers new releases of Matlab for beta-testing. All testers must confirm a non-disclosure agreement. This is more efficient than encrypting the files.
  1 Comment
paul ki
paul ki on 28 Nov 2011
Thank you both for the answers.
I have about 50 files from different tools I wrote and some others like LIBSVM which need to be in this package.
As i wrote, in addition to content, I need to hide also the matlab file names (otherwise I need to rename them all such as fun1...fun50 which is a big headache).
So, is there a way to compile it all in a format but use it from matlab as a regular matlab function, without need to run it from a command line?

Sign in to comment.

More Answers (2)

Walter Roberson
Walter Roberson on 27 Nov 2011
I don't know if you will be able to hide the file names with any provided mechanism.
pcode can obscure .m file contents. There are ways that a sufficiently dedicated person can dig information (but not complete source) out of pcode'd files.
If you use the MATLAB Compiler, then deploytool will create AES encrypted files that are decrypted on-the-fly . However, auxilary files such as .mat files are, as best I recall, unpacked to plain-binary files.
MATLAB does not provide any mechanisms for load() to work in binary streams (such as a pipe that reads and decrypts a file.)
If you are concerned about protecting .mat files, you should consider using fwrite() to save the variables as binary files. You could apply encryption when you do that; your program would then have to read and decrypt the values from the binary files.

David Leffingwell
David Leffingwell on 12 Jun 2023
If you have access to the MATLAB Compiler, you can it to create a standalone application. Use the -s option to obfuscate the file and folder structure inside the standalone application (which is a self-extracting Zip file). The -s option also encrypts your data (e.g. MAT files) and mex files in addition to your M files. Also you can use the -j option to automatically P-Code all your M files. See here for more details.

Categories

Find more on Programming in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!