Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to protect MATLAB compiled application from distribution?

How I can protect MATLAB compiled .exe from:

  • reverse-engineering
  • unauthorised distibution?

Which packers, protection tools etc should I use?

like image 520
simon Avatar asked Oct 24 '12 06:10

simon


People also ask

How do I protect my Matlab code?

One method for protecting source code is to store that source code on a remote protected server using MATLAB Web App Server or MATLAB Production Server. The stored source code resides on a server with restricted access, and users access the application through secure interfaces.

What is a .P file in Matlab?

P-code files are an obfuscated, execute-only form of MATLAB code. You cannot open a P-code file in the MATLAB Editor or Live Editor.

How do I convert a .P file to a .m file in Matlab?

This is a pre-parsed pseudocode file (P-file), which is a “pre-compiled” form of the Matlab function signal1. m. To evaluate this function, simply type y = signal1(t) where t is a vector containing values of time.

What is Matlab Coder?

MATLAB Coder™ generates C and C++ code from MATLAB® code for a variety of hardware platforms, from desktop systems to embedded hardware. It supports most of the MATLAB language and a wide range of toolboxes. You can integrate the generated code into your projects as source code, static libraries, or dynamic libraries.


1 Answers

I have been previously faced with exactly this problem. Here are some thoughts:

  • MATLAB compiled binaries are in fact ZIP archives, which are decompressed (possibly to a temp or home folder accessible to the user) at runtime.
  • The files themselves are encrypted using AES, which is not ideal, since the key can be theoretically recovered.
  • The above makes it senseless to additionally encrypt the final exe with user-based keys to limit the redistribution, since the decompressed files will be available during runtime. In that sense it is equivalent to just using mcc for protection.
  • As an additional catch: MEX files in the distribution are not encrypted. You can take the mex file from the MCR_CACHE and directly use it. The same goes for Java classes.
  • Hence, you need a solution which will encrypt/decrypt the disk writes/reads performed by MATLAB executable in addition to encrypting the executable itself
  • Obviously you need to be able to specify, which disk accesses to encrypt - you want the user to be able to provide input data, and to read his output
  • Ideally, this solution would also keep an encrypted copy of the binaries in the memory, and only decrypt them when needed, i.e., when a piece of code/data is being executed/accessed
  • In addition, the solution should detect that the code is executed from a debugger and shut down the program in such cases
  • It should be difficult to reverse-engineer the encryption process to extract the keys. With a software-only solution it is always possible (and easier than with a hardware solution) to obtain the keys.

We ended up using a solution, which involves a USB dongle. It performs the encryption/decryption on the fly and more-or-less addresses the above complexities. It works in a client/server setting, i.e., you can have a USB dongle on the server, and the clients contact the server to checkout the license and run the code. At that time however, the full encryption was only supported on Windows. I am not sure whether I should mention the company name here on SO (I am not in any way affiliated to it, but anyways). I can tell you privately what we used, or you could google around a bit - there are alternatives on this market.

Edit I made a mistake in my original statement. The archive is indeed extracted to MCR_CACHE directory, but the files are encrypted. However, this still does not prevent redistribution of the compiled program. Although the scripts are not available in clear text, so in this sense your intellectual property is secured. A more detailed description of what MATLAB deployment tool does and does not protect, and a short statement regarding the security of the scheme can be found here.

like image 92
angainor Avatar answered Oct 10 '22 10:10

angainor