matlab compiler vs mcc functionality

Hi, I am testing out the matlab compiler and the mcc function. I cannot get a full overlap of functionality between them. For example:
When using the mcc function, is there a way to include matlab runtime in the package, and specify the name of the installer executable? That is, the equivalent of the check box and edit field at the top of the compiler.
When using matlab compiler, is there a way to specify conversion of m files to p code (the '-p' option)?
Also, how do I validate that my compiled executable is using p code rather than m files?
I noticed some behaviour with matlab compiler regarding precedence that I think is contrary to the documentation. If the m files are in the same folder as the main file, then the m files take precedence over p code files, otherwise p code files take precedence. I suspect it is not matlab's intention that you create the p code files separately prior to compiling the executable, as I could not get this to work using mcc or compiler. I can only get it to work using mcc on m files with the '-p' option on. Some better examples or guidance would help here, as I am testing out lots of different ways to do things in the hope of finding what works.
Apologies if this is too many questions in one post.

Réponses (1)

Dirk Engel
Dirk Engel le 27 Avr 2024

1 vote

I assume that by "MATLAB Compiler" you are referring to the MATLAB Compiler user interface (deplytool) which you can use to build and package your app. mcc only covers the build step, not the packaging. That's why there is no full overlap between the two.
Use the -o option of mcc to specify the name of the final executable.
Note that the compiled application contains encrypted files with the .m extension, but these are no normal m-files. They are neither human-readable, nor can they be be decrypted (to the best of my knowledge), nor can they be taken from the compiled app and used in a different context such as in MATLAB or in another compiled app. The files are encrypted with a key that changes with each compilation, so they only work in the context of that one specific compiled app. There is no need to create p-code before compilation. Your intellectual property is well protected in a compiled app.

5 commentaires

CM
CM le 27 Avr 2024
Déplacé(e) : Walter Roberson le 28 Avr 2024
Thanks Dirk. I did not realise those files were encrypted but I just checked and you are correct. I can see where matlab unpacks them using ctfroot or mpath - this probably answers my own question about validating whether p code was used.
From this site:
At run time, the encrypted files remain encrypted on the disk but are decrypted in memory to their original form before compiling. Depending on the use case, you can combine other methods with this one to gain an additional layer of protection. For example, you can create a P-coded file from MATLAB code files before they are compiled.
I am not really sure what "decypted in memory" means or how easy it is to get access to them, so I plan on using p code as well. If someone is clever enough to get the decrypted files from "memory," would it then be a trivial task for them to unpack the p code into m code?
My current understanding is that I should use the MATLAB Compiler user interface to create the package, from which I only need the mcr installation executable. I will probably use the "runtime included in package" option to keep it as simple as possible for the end user. Then I use the mcc function to (re)create the executable of the code I have written, with whatever options I want (-s to obscure file names and -p to use p code). Then I only need those two executables to install everything on an ofline computer?
I understand that there is no way to avoid using the MATLAB Compiler user interface as I need that to get the mcr installation executable, but if I could get the -s and -p options into the MATLAB Compiler user interface that would be one less step.
Does the mcr installation executable by default include every in-built function in my matlab package, or just the functions my code uses? If it is the former, then I only need to make that executable once and can re-use it, presumably until I upgrade matlab. Otherwise I will need to produce both executables each time, in case I have used an additional in-built function.
Dirk Engel
Dirk Engel le 30 Avr 2024
Modifié(e) : Dirk Engel le 30 Avr 2024
p-files will also be decoded in memory, so any additional layer of protection against a serious hacker is hypothetical. For the "average hacker", the task is probably already too difficult.
The installer for MATLAB Runtime (aka MATLAB Compiler Runtime, aka MCR) includes every built-in MATLAB function. It is not created specifically for your app but can be re-used by multiple apps. Installers are readily available from https://mathworks.com/products/compiler/matlab-runtime.html Just make sure to use the same release version you created your app with, or your app won't start. Given the size of the MATLAB installer (several GBs) I recommend that you do not package it with your app. Just use mcc to compile the executable of your app, and let the end user download MATLAB Runtime from the web resource and install it manually. The installation procedure is straight forward.
Walter Roberson
Walter Roberson le 30 Avr 2024
"If someone is clever enough to get the decrypted files from "memory," would it then be a trivial task for them to unpack the p code into m code?"
Not trivial.
A small number of releases ago, Mathworks changed the pcode algorithm. It is not known how secure the current one is. It is known that a few people had reverse-engineered the previous algorithm; if anyone has reverse-engineered the current algorithm, then that is not public knowledge.
CM
CM le 30 Avr 2024
Modifié(e) : CM le 30 Avr 2024
Thanks Walter. I intend to use the p code option in creating my executables. I understand that in addition to being another layer of protection, if they do crack it, they end up with code that has no comments (and obscured variable names?), so it would be difficult to do any further improvements to it, so it would be no better than a hacked executable with the licencing provisions bypassed. Or at least, it would probably be just as easy to re-write it from scratch.
CM
CM le 30 Avr 2024
"It is not created specifically for your app but can be re-used by multiple apps."
Thanks Dirk. Regarding downloading MCR from the matlab website, I would like to have the package appear to be completely self contained and branded. I don't think the GB's of download will be an issue.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Troubleshooting in MATLAB Compiler SDK dans Centre d'aide et File Exchange

Produits

Version

R2023a

Question posée :

CM
le 20 Mar 2024

Modifié(e) :

CM
le 30 Avr 2024

Community Treasure Hunt

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

Start Hunting!

Translated by