6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/immunio/plugins/io.rb', line 6
def self.inject(mod, name, methods)
mod.class_eval <<-EOF
def self.extended(base) # def self.extended(base)
#{methods.inspect}.each do |method| # ["read", "binread"].each do |method|
base.singleton_class.alias_method_chain method, :immunio # base.singleton_class.alias_method_chain method, :immunio
end # end
end # end
def self.included(base) # def self.included(base)
#{methods.inspect}.each do |method| # ["read", "binread"].each do |method|
base.alias_method_chain method, :immunio # base.alias_method_chain method, :immunio
end # end
end # end
EOF
Immunio.logger.debug "IO: successfully chained #{name} #{methods}"
methods.each do |method|
mod.class_eval <<-EOF
def #{method}_with_immunio(*args, &block) # def read_with_immunio(*args, &block)
Request.time "plugin", "IO::#{method}" do #
strict_context, loose_context, stack, loose_stack = Immunio::Context.context()
Immunio.run_hook! "io", "file_io", # Immunio.run_hook! "io", "open",
method: "#{name}#{method}", # open_method: "IO.read",
parameters: args, # parameters: args
stack: loose_stack, #
context_key: loose_context, #
cwd: Dir.pwd
Request.pause "plugin", "IO::#{method}" do #
#{method}_without_immunio(*args, &block) # read_without_immunio(*args, &block)
end
end
end # end
EOF
Immunio.logger.debug "IO: successfully created hook for #{name} #{method}"
end
end
|