有没有成熟的解决方案来创建带有 ELF 符号和 C 语法命令解析器的即时 shell?
我需要在每个c exe(linux环境)中创建一个调试shell,我的解决方案如下:
- 从exe文件中读取elf符号,在其中构建一个符号->地址表 记忆;
- 运行一个调用 readline 的线程来接受用户输入,一些事情 就像 ac 函数调用一样;
- 使用 Lex & yacc 解析函数名和arg列表;
- 在符号表中查找函数的地址;
- 使用参数列表调用函数;
- 每个编写的函数都可以立即作为 shell 命令输入。
我不认为这是一个新鲜的想法,我的问题是:是否已经实现了成熟的代码? 感谢您的帮助!
I need to make a debug shell inside each c exe(linux enviroment), and my solution is as follows:
- Read elf symbols from exe file, build a symbol->address table in
memory; - Run a thread calling readline to accept user input, some thing
like a c function call; - use Lex & yacc to parse the function name and arg list;
- Find address of the function in the symbol table;
- Call the function with args list;
- Every function written can be input as shell command instantly.
I don't think this is a fresh idea, and my question is: Are there any mature codes implemented already?
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然。如果您曾经使用过 VxWorks,您会发现 WindShell 正是您所需要的。我已经将类似的 shell 移植到 Linux 上。您可以从以下位置下载源代码:
https://sourceforge.net/projects/zprj/
注意:请勿将源代码用于商业用途产品,因为它们是从 WindShell 移植的。如果你确实想要一个商业领域的 shell,那么你应该使用 LEX/YACC 开发一个 shell。
Sure. If you had working with VxWorks, you'll find WindShell is what you're looking for. I had port a similar shell to Linux. You can download the source from:
https://sourceforge.net/projects/zprj/
Note: don't use the source in commercial products, since they are ported from WindShell. If you do want a shell in commercial fields, then you shall develop one with LEX/YACC.