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.
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.
0 件のコメント
採用された回答
Franck Tancret
2017 年 11 月 22 日
5 件のコメント
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
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
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
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
2017 年 11 月 21 日
If you mean to hide the source code, please ref to pcode()
doc pcode
4 件のコメント
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
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 Center および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!