实现pry,ronin,msf类似的终端下交互功能,这里主要用到了ripl gem:
1.能够调用定义的方法,如help
2.能够执行系统命令
3.能够类似irb/pry进行ruby语言解析
安装:
gem install ripl gem install ripl-shell_commands
示例
ripl这个gem,它也提供很多插件,如下是一个简单的终端下交互实现:
require 'ripl'
require 'ripl/shell_commands'
require 'ripl/color_result'
require 'ripl/color_streams'
require 'ripl/commands'
require 'ripl/rocket'
#设置输出颜色
ripl.config[:color_streams_stdout] = :light_blue
ripl.config[:color_streams_stderr] = :light_red
#定义提示符号
ripl.config[:prompt] = lambda {"[#{ripl.shell.line.to_s}] cmd> " }
# define plugins, load files, etc...
class dodolook
def help
puts "xiaomi noops blog"
end
def name
"wilbur"
end
end
dodo = dodolook.new
verison = "1.0.3"
ripl.start :binding => dodo.instance_eval{ binding }
使用
在终端下运行程序后,出现[0] cmd>这样的提示,其中help、name、dodo这些变量/方法可以tab补全。
运行shell命令前加!,如:!df
还有更多内部方法,如: history, list, jump…
正宗卖男孩的小火柴