我正在用Python开发一款软件,它将分发给我雇主的客户。我的雇主想用一个有时间限制的许可证文件来限制软件的使用。
如果我们分发.py文件甚至.pyc文件,将很容易(反编译和)删除检查许可证文件的代码。
另一个方面是,我的雇主不希望我们的客户读到代码,担心代码可能被窃取,或者至少是“新颖的想法”。
有什么好办法来解决这个问题吗?
我正在用Python开发一款软件,它将分发给我雇主的客户。我的雇主想用一个有时间限制的许可证文件来限制软件的使用。
如果我们分发.py文件甚至.pyc文件,将很容易(反编译和)删除检查许可证文件的代码。
另一个方面是,我的雇主不希望我们的客户读到代码,担心代码可能被窃取,或者至少是“新颖的想法”。
有什么好办法来解决这个问题吗?
当前回答
发布.pyc文件有它的问题-它们与创建它们时使用的python版本以外的任何其他python版本都不兼容,这意味着您必须知道产品将运行的系统上运行的python版本。这是一个非常有限的因素。
其他回答
在某些情况下,可以将软件(全部或至少关键部分)移动到组织托管的web服务中。
这样,许可证检查就可以在您自己的服务器机房的安全环境中执行。
你的雇主是否意识到他可以“偷”回其他人从你的代码中得到的任何想法?如果他们能读懂你的作品,你也能读懂他们的。也许看看你如何能从这种情况中受益,会比担心你可能会失去多少,获得更好的投资回报。
[编辑]回答尼克的评论:
没有得到也没有失去。客户得到了他想要的东西(因为他自己进行了更改,所以已经为此付费了)。因为他没有发布变更,就好像它没有发生在其他人身上一样。
现在如果客户出售软件,他们必须更改版权声明(这是非法的,所以你可以起诉并且会赢->简单的案件)。
如果他们不更改版权声明,第二级客户就会注意到软件来自您的原创,并想知道发生了什么。很有可能他们会联系你,这样你就会了解到你的作品被转售的情况。
同样,我们有两种情况:原来的客户只卖了几份。这意味着他们并没有赚到多少钱,所以为什么要麻烦呢。或者是销量。这意味着你有更好的机会了解他们的工作,并为此做些什么。
But in the end, most companies try to comply to the law (once their reputation is ruined, it's much harder to do business). So they will not steal your work but work with you to improve it. So if you include the source (with a license that protects you from simple reselling), chances are that they will simply push back changes they made since that will make sure the change is in the next version and they don't have to maintain it. That's win-win: You get changes and they can make the change themselves if they really, desperately need it even if you're unwilling to include it in the official release.
Python不是你需要的工具
您必须使用正确的工具来做正确的事情,而Python不是为混淆而设计的。事实恰恰相反;在Python中,任何东西都是开放的、易于显示或修改的,因为这是该语言的哲学。
如果你想要一些你看不透的东西,找另一个工具。这并不是一件坏事,重要的是为不同的用途存在不同的工具。
混淆真的很难
即使编译过的程序也可以被逆向工程,所以不要认为你可以完全保护任何代码。你可以分析模糊的PHP,破解flash加密密钥等等。新版本的Windows系统每次都被破解。
有一个法律要求是一个很好的方法
你不能阻止别人滥用你的代码,但是如果有人这样做了,你可以很容易地发现。因此,这只是一个偶然的法律问题。
代码保护被高估了
如今,商业模式倾向于销售服务,而不是产品。你不能复制服务,盗版或窃取它。也许是时候考虑顺其自然了……
“有没有解决这个问题的好办法?”不。没有什么可以防止逆向工程。甚至DVD机器上的固件也被逆向工程,AACS加密密钥被暴露。这还是不顾DMCA规定的刑事犯罪。
由于没有任何技术方法可以阻止客户阅读您的代码,所以您必须应用普通的商业方法。
Licenses. Contracts. Terms and Conditions. This still works even when people can read the code. Note that some of your Python-based components may require that you pay fees before you sell software using those components. Also, some open-source licenses prohibit you from concealing the source or origins of that component. Offer significant value. If your stuff is so good -- at a price that is hard to refuse -- there's no incentive to waste time and money reverse engineering anything. Reverse engineering is expensive. Make your product slightly less expensive. Offer upgrades and enhancements that make any reverse engineering a bad idea. When the next release breaks their reverse engineering, there's no point. This can be carried to absurd extremes, but you should offer new features that make the next release more valuable than reverse engineering. Offer customization at rates so attractive that they'd rather pay you to build and support the enhancements. Use a license key which expires. This is cruel, and will give you a bad reputation, but it certainly makes your software stop working. Offer it as a web service. SaaS involves no downloads to customers.
用同样的方法保护c/c++的二进制文件,即对可执行文件或库二进制文件中的每个函数体进行混淆,在每个函数项的开头插入指令“跳转”,跳转到特定的函数来恢复混淆的代码。字节码是Python脚本的二进制代码,所以
首先编译python脚本代码对象 然后迭代每个代码对象,将每个代码对象的co_code混淆如下所示
0 JUMP_ABSOLUTE n = 3 + len(bytecode) 3 ... ... Here it's obfuscated bytecode ... n LOAD_GLOBAL ? (__pyarmor__) n+3 CALL_FUNCTION 0 n+6 POP_TOP n+7 JUMP_ABSOLUTE 0
将混淆的代码对象保存为.pyc或.pyo文件
那些模糊的文件(。Pyc或.pyo)可以被普通的python解释器使用,当这些代码对象第一次被调用时
First op is JUMP_ABSOLUTE, it will jump to offset n At offset n, the instruction is to call a PyCFunction. This function will restore those obfuscated bytecode between offset 3 and n, and put the original byte-code at offset 0. The obfuscated code can be got by the following code char *obfucated_bytecode; Py_ssize_t len; PyFrameObject* frame = PyEval_GetFrame(); PyCodeObject *f_code = frame->f_code; PyObject *co_code = f_code->co_code; PyBytes_AsStringAndSize(co_code, &obfucated_bytecode, &len) After this function returns, the last instruction is to jump to offset 0. The really byte-code now is executed.
有一个工具Pyarmor可以通过这种方式混淆python脚本。