Make functions unreadable to end-user

8 views (last 30 days)
I have a complete program to perform phase equilibrium calculations at fixed temperature and pressure using an equation of state (EOS). The structure of the code is as follows.
TPflash_Main.m is the main file that calls the following:
1. "INPUTS.m" is a script that gathers all possible parameters from an EXCEL file and creates DATA.mat
2. "EOSparameters.m" is a function that gathers only relevant variables from DATA.mat (based on inputs to the function)
  • [normalizedComposition, EOSprops] = EOSparameters(Components, Composition, EOS)
3. "TPflash.m" is a function that computes equilibrium properties and calls the equation of state that corresponds to the input "EoS".
  • [eqProps] = TPflash(T,P,normalizedComposition,EOSprops,EOS)
I want the code to be packaged in such a way that the end-user cannot see the internals of the code. I have made INPUTS.m into an executable, but this isn't really what I want because I want the user to be able to pass inputs to the function to be able to change the source EXCEL file.
Additionally, there is a function file that is called by TPflash.m that I want the end-user to be able to replace with their own. If you have familiarity with flash calculations, then this is the file that outputs compressibility (Z) and fugacity (PHI) depending on the equation of state. I have coded the cubic equations of state and it is called by TPflash.m by:
  • [Z, PHI] = cubicEOS(T,P,Compositions,EOSprops)
I want the user to be able to replace my "cubicEOS.m" function with one of their own where I require that they output the same properties [Z,PHI] as "cubicEOS.m"
I'm a long-time user of MATLAB, so I have checked all the usual places to get help on this issue. I know the answer will be obvious, but I'm tired of looking. Thank you for any help!

Accepted Answer

Walter Roberson
Walter Roberson on 26 Sep 2016
You could pcode your routines, but a user who bothers to user a debugger can find out names of functions and variables.
You could create a shared library (executable) that could be called. This would have to be done for each platform to be supported. Because a MATLAB instance would still be there, it would be possible to call a user-provided function. Uaer-provided routines may be able to probe the call stack to some degree.
Any data that you hang off a graphics object (or other queryable MATLAB object) is fair game for the user to try to probe. Any shared variable or persistent variable is fair game for a user to probe with functions() if they can get hold of the function handle.
On MS Windows, you could create an executable that was communicated with using COM objects. You could hide the important parts and provide an interface routine.
On all platforms, you could create an executable that was communicated with using TCP.
Note: code that has been obscured in this ways is not permitted in the MATLAB File Exchange.
  2 Comments
Caleb
Caleb on 26 Sep 2016
What I'm trying to do I've seen done with MEX files. Can I make a MEX file from MATLAB source code?
Walter Roberson
Walter Roberson on 26 Sep 2016
MATLAB Coder can generate C/C++ source, provided that your code fits within the language subset.
MATLAB Compiler compiling to a shared library has more leeway because the full MATLAB MCR engine is still around for that case.

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!