module Pentest::AstUtils
Public Class Methods
get_params_key(exp)
click to toggle source
Match “params” and return :hoge
# File lib/pentest/ast_utils.rb, line 21 def get_params_key(exp) return nil unless Sexp === exp if exp[0] == :call type, callee, method, arg = exp if is_params?(callee) && method == :[] if Sexp === arg && arg[0] == :lit return arg[1] end if Sexp === arg && arg[0] == :str return arg[1].to_sym end end end nil end
is_params?(exp)
click to toggle source
Match “params”
# File lib/pentest/ast_utils.rb, line 7 def is_params?(exp) return false unless Sexp === exp if exp[0] == :call type, callee, method = exp if callee.nil? && method == :params true else false end end end
search_for_params(exp)
click to toggle source
# File lib/pentest/ast_utils.rb, line 39 def search_for_params(exp) return Set.new unless Sexp === exp ret = Set.new params_key = get_params_key(exp) unless params_key.nil? ret << [params_key, nil, nil] end if exp[0] == :call type, callee, method, arg = exp callee_params = get_params_key(callee) if callee_params.nil? ret.merge search_for_params callee else ret << [callee_params, :callee, method, arg] end arg_params = get_params_key(arg) if arg_params.nil? ret.merge search_for_params arg else ret << [arg_params, :call_arg, callee, method] end else exp.each do |child| ret.merge search_for_params child end end ret end