As the administrator of a Windows PC, can I create a Matlab code that a user can execute, but that this user cannot neither read nor copy?

1 次查看(过去 30 天)
Example: I write a code AAA.m, which calls another one, BBB.m. I want the user the be able to edit/modify AAA.m and to run it, which needs Matlab to be able to call BBB.m, but I want to prevent the user from reading and copying BBB.m.

采纳的回答

Franck Tancret
Franck Tancret 2017-11-22
Let's call the "open" code AAA.m, and the code to be protected BBB.m, which is called by AAA.m. At the beginning of BBB.m, test the Matlab license number with 'license()', e.g.: number=license(); if number=='012345' (supposing that the true license number is 012345) "do what the code has to do" else "do nothing or calculate an output variable with a wrong format" end. Then, pcode('BBB.m'). That's all! When launching AAA.m, BBB.p will be called and will return something that will cause AAA.m to crash. Even the reason of crashing will remain unknown by the user.
  5 个评论
Franck Tancret
Franck Tancret 2017-11-22
Sorry if I was not clear, but my question "As the administrator of a Windows PC, can I create a Matlab code that a user can execute...", implicitly meant "execute ONLY on the PC I am the administrator of". This is why the sole pcode was not enough.
John D'Errico
John D'Errico 2017-11-22
编辑:John D'Errico 2017-11-22
Actually, this is NOT a valid solution. You may think it is, but it is trivial to crack.
is a function. It returns the license number (as a string' on the current system. But I can also create my own function called license. Put it on the search path above the MATLAB directories.
So, if I want my license to appear as if it is '12345678', I did exactly that.
function Lstr = license
Lstr = '12345678';
end
Now, run my overloaded license:
license
ans =
'12345678'
That instead of the real license number that my MATLAB has.
Hey, feel free to think that your solution is a valid one. But instead, it is so trivially hacked that it took me less than 30 seconds to break it. (Roughly how long it took me to write an m-file, then save it on my computer.)
Note that when you don't really know what you are doing, writing and immediately accepting your own answer almost always leads to the wrong answer being accepted.

请先登录,再进行评论。

更多回答(2 个)

John D'Errico
John D'Errico 2017-11-21
编辑:John D'Errico 2017-11-21
In order to prevent the code from being read, you have the choices of p-code or compiled code.
A problem is that of moving the code. I think that you cannot do. If it can be used by MATLAB, then it can be copied too.
However, I think you do have an option there. You need to essentially lock it to that machine. So put code inside, code that knows which machine it is being run on, and will not execute if run on another machine. For example, if you can query the IP address of the current machine, then by testing the IP address against the known IP for your machine, any other IP will cause the code to return immediately with an error. Ok, I'll admit that I did not know how to get my IP address from within MATLAB. A quick search gave me this page:
https://www.mathworks.com/help/matlabmobile/ug/determining-a-computers-dns-name-or-ip-address.html#btpwvh3-2
  3 个评论
Guillaume
Guillaume 2017-11-22
编辑:Guillaume 2017-11-22
Locking code to an IP address (commonly MAC addresses are preferred as they're less likely to change) is not complicated. It's also very easily defeated.
I would suspect that the proper solution which is very simple is even easier to defeat.
There is a whole industry dedicated on providing expensive tools to lock even more expensive software to a specific computer (e.g. flexnet as used by matlab). None of these tools will stop a sufficiently dedicated attacker from using the code on another machine as witnessed by the fact that all these very expensive programs are all pirated. When chosing your method of protection you need to decide what level of dedication you want to stop.
John D'Errico
John D'Errico 2017-11-22
Yes, I was sure it can be defeated. But I am also sure that it is somewhat less easily defeated then the solution posed by Franck.

请先登录,再进行评论。


Fangjun Jiang
Fangjun Jiang 2017-11-21
If you mean to hide the source code, please ref to pcode()
doc pcode
  4 个评论
Image Analyst
Image Analyst 2017-11-21
Why would it prevent users from running pcode or compiled code on a different computer?
I don't think you can prevent a user from copying a file from the operating system. Maybe you can set the hidden attribute so users don't see it, but then they wouldn't know how to run it either, unless just part of it was hidden and the part they need isn't hidden. But if some part is hidden, I don't know if even the non-hidden file could find the hidden file.
Walter Roberson
Walter Roberson 2017-11-21
Sorry, no. Your file would need to be readable in order for MATLAB to be able to read it to execute it, and if MATLAB can read it then the user can copy it. .m and .p and .mex* files are data for the purpose of Windows Security settings, not controlled by "Execute" settings, so you cannot do tricks like setting it to be executable but not readable.
However, you could potentially lock the code to the node, checking some hardware information and refusing to proceed if the hardware does not match. There are no Mathworks provided tools for this, though.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by