Class: PWN::Plugins::Log::DebugStderrTee

Inherits:
Object
  • Object
show all
Defined in:
lib/pwn/plugins/log.rb

Overview

Ruby Thread.report_on_exception dumps IOError to $stderr. Clone that (and any other stderr from pwn-ai) into the open RN request log.

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ DebugStderrTee

Returns a new instance of DebugStderrTee.



236
237
238
# File 'lib/pwn/plugins/log.rb', line 236

def initialize(opts = {})
  @orig = opts[:orig] || $stderr
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(mid) ⇒ Object



308
309
310
# File 'lib/pwn/plugins/log.rb', line 308

def method_missing(mid, ...)
  @orig.public_send(mid, ...)
end

Instance Method Details

#<<(obj) ⇒ Object



251
252
253
254
# File 'lib/pwn/plugins/log.rb', line 251

def <<(obj)
  write(obj.to_s)
  self
end

#closeObject



283
284
285
# File 'lib/pwn/plugins/log.rb', line 283

def close
  nil
end

#closed?Boolean

Returns:

  • (Boolean)


287
288
289
# File 'lib/pwn/plugins/log.rb', line 287

def closed?
  false
end

#filenoObject



279
280
281
# File 'lib/pwn/plugins/log.rb', line 279

def fileno
  @orig.fileno if @orig.respond_to?(:fileno)
end

#flushObject



270
271
272
273
# File 'lib/pwn/plugins/log.rb', line 270

def flush
  @orig.flush if @orig.respond_to?(:flush)
  self
end


265
266
267
268
# File 'lib/pwn/plugins/log.rb', line 265

def print(*args)
  write(args.join)
  nil
end

#puts(*args) ⇒ Object



256
257
258
259
260
261
262
263
# File 'lib/pwn/plugins/log.rb', line 256

def puts(*args)
  if args.empty?
    write("\n")
  else
    args.each { |a| write("#{a}\n") }
  end
  nil
end

#respond_to_missing?(mid, include_all = false) ⇒ Boolean

Returns:

  • (Boolean)


304
305
306
# File 'lib/pwn/plugins/log.rb', line 304

def respond_to_missing?(mid, include_all = false)
  @orig.respond_to?(mid, include_all)
end

#syncObject



291
292
293
# File 'lib/pwn/plugins/log.rb', line 291

def sync
  @orig.respond_to?(:sync) ? @orig.sync : true
end

#sync=(val) ⇒ Object



295
296
297
298
# File 'lib/pwn/plugins/log.rb', line 295

def sync=(val)
  @orig.sync = val if @orig.respond_to?(:sync=)
  val
end

#to_ioObject



300
301
302
# File 'lib/pwn/plugins/log.rb', line 300

def to_io
  @orig.respond_to?(:to_io) ? @orig.to_io : @orig
end

#tty?Boolean

Returns:

  • (Boolean)


275
276
277
# File 'lib/pwn/plugins/log.rb', line 275

def tty?
  @orig.respond_to?(:tty?) && @orig.tty?
end

#write(*args) ⇒ Object



240
241
242
243
244
245
246
247
248
249
# File 'lib/pwn/plugins/log.rb', line 240

def write(*args)
  data = args.join
  begin
    @orig.write(data) if @orig.respond_to?(:write)
  rescue StandardError
    nil
  end
  PWN::Plugins::Log.capture_stderr!(text: data)
  data.bytesize
end