matlab.lang.obfuscateNames
Obfuscate names of local variables, local functions, and nested functions
Since R2024b
Syntax
Description
matlab.lang.obfuscateNames(
reads MATLAB® source code from inputFile
,outputFile
)inputFile
and writes nearly-identical
source code to outputFile
with the names of local variables, local
functions, and nested functions replaced with generic names (id242487092
,
id581240213
, ...). This is intended to provide additional obfuscation
for advanced users who are already using
. The names pcode
-R2022aans
,
varargin
, varargout
, and names that are used as
literal arguments for the load
function are never obfuscated.
Both inputFile
and outputFile
must be local
file system paths and must have a .m
filename extension.
inputFile
must be a function or class definition file. If
inputFile
and outputFile
are the same file, the
file will be overwritten without warning. A warning will be issued if the output filename
does not match the name of the function or class being defined.
Source code written to outputFile
is encoded using UTF-8.
Note
Code with obfuscated names may behave differently from the original, unobfuscated
source code. matlab.lang.obfuscateNames
only obfuscates direct
occurrences of names in code, such as x
in x = 1
,
if x < 5
, and f(x+y)
. Occurrences in strings,
character vectors, and command-syntax arguments are not obfuscated, such as
eval("f(x+y)")
or clear x
.
matlab.lang.obfuscateNames(
writes the new file in the specified folder with the same name as
inputFile
,outputFolder
)inputFile
. Use "."
to write to the current
directory.
matlab.lang.obfuscateNames(___,
writes the new file with the specified options. Name=Value
)
Examples
Input Arguments
Tips
Thoroughly test obfuscated code to ensure it is functioning as intended. Consider making use of MATLAB Testing Frameworks to write automated tests to verify the behavior of obfuscated code. If the code does not behave as desired, use
PreserveNames
and other name-value arguments to control the obfuscation process.Use name obfuscation together with
pcode -R2022a
andmcc -s
. Name obfuscation preserves comments to make debugging easier. Obfuscated source code should not be distributed directly; it should be distributed as a P-code file, ideally in a deployable form produced by the MATLAB Compiler or MATLAB Compiler SDK.Do not write code that relies on specific obfuscated names. Instead, use the
PreserveNames
option exclude names from obfuscation. Names assigned after obfuscation may change in the future.
Version History
Introduced in R2024b