从 Perl 中的字符串执行整个 Perl 程序
我有一个在文件中用 Blowfish 加密的程序和第二个 perl 程序,提示输入用于将其解密为字符串的密码,我希望不必将解密的源写入硬盘驱动器,尽管将其保存在内存中并不是真正的问题,因为运行该程序的人已经知道其来源。我想我可能会使用 eval 但我需要运行的程序有很多使用 Curses 和东西的输入/输出,所以 eval 不会工作,因为它只返回最后一个值......有谁知道如何实现这一点?
I have a program that is encrypted with Blowfish in a file and a second perl program that prompts for a passphrase that is used to decrypt it into a string, I would like to not have to write the decrypted source to the hard drive ever, although having it in memory isn't really a problem as those running the program already know the source. I thought I might use eval but the program I need to run has a lot of input/output using Curses and stuff so eval wont work as it only returns the last value... Does anyone have any idea how this could be accomplished?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
@INC
挂钩来执行解密。然后您可以简单地require
或use
加密的程序。例如,You can use an
@INC
hook to perform the decryption. Then you can simplyrequire
oruse
the encrypted program. For example,没有理由
eval
不适用于您所描述的内容。虽然它只返回一个值,但这并不能阻止评估代码与终端交互。通常不会以这种方式使用,但您的用例是使用字符串eval
的合理原因。 (请注意,您最终仍可能将源代码写入交换文件。)There's no reason
eval
won't work for what you describe. While it only returns a single value, that doesn't prevent the eval'd code from interacting with the terminal. It's not usually used that way, but your use-case is a legitimate reason for using stringeval
. (Note that you could still end up with the source code written to your swap file.)只需启动一个单独的 perl 实例并使用标准输入将程序传递给它,如下所示:
使用 perl 代码:
Just start a separate perl instance and pass the program to it using standard input, like this:
With perl code: