Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Redefined Hijack each time we connect, not just when debugging

  • Loading branch information...
commit 8962079593bdfdd7716cba8355463ee447e570cd 1 parent 00cc56e
Ian Leitch authored
Showing with 62 additions and 64 deletions.
  1. +62 −64 lib/hijack/payload.rb
126 lib/hijack/payload.rb
View
@@ -18,89 +18,87 @@ def self.payload(pid)
require 'drb'
debug = #{Hijack.options[:debug] || false}
- if debug || !defined?(Hijack)
- puts 'Hijack: Debugging enabled' if debug
- module Hijack
- class OutputCopier
- def self.remote
- @remote
- end
+ puts 'Hijack: Debugging enabled' if debug
+ module Hijack
+ class OutputCopier
+ def self.remote
+ @remote
+ end
- def self.stop
- @remote = nil
- [$stdout, $stderr].each do |io|
- if io.respond_to?(:write_with_copying)
- class << io
- alias_method :write, :write_without_copying
- remove_method :write_with_copying
- end
+ def self.stop
+ @remote = nil
+ [$stdout, $stderr].each do |io|
+ if io.respond_to?(:write_with_copying)
+ class << io
+ alias_method :write, :write_without_copying
+ remove_method :write_with_copying
end
end
end
+ end
- def self.start(pid)
- @remote = DRbObject.new(nil, 'drbunix://tmp/hijack.' + pid.to_s + '.sock')
- puts @remote.inspect if Hijack.debug?
+ def self.start(pid)
+ @remote = DRbObject.new(nil, 'drbunix://tmp/hijack.' + pid.to_s + '.sock')
+ puts @remote.inspect if Hijack.debug?
- class << $stdout
- def write_with_copying(str)
- write_without_copying(str)
- begin
- Hijack::OutputCopier.remote.write('stdout', str)
- rescue Exception => e
- write_without_copying(e.message) if Hijack.debug?
- Hijack.stop
- end
+ class << $stdout
+ def write_with_copying(str)
+ write_without_copying(str)
+ begin
+ Hijack::OutputCopier.remote.write('stdout', str)
+ rescue Exception => e
+ write_without_copying(e.message) if Hijack.debug?
+ Hijack.stop
end
- alias_method :write_without_copying, :write
- alias_method :write, :write_with_copying
end
+ alias_method :write_without_copying, :write
+ alias_method :write, :write_with_copying
+ end
- class << $stderr
- def write_with_copying(str)
- write_without_copying(str)
- begin
- Hijack::OutputCopier.remote.write('stderr', str)
- rescue Exception => e
- write_without_copying(e.message) if Hijack.debug?
- Hijack.stop
- end
+ class << $stderr
+ def write_with_copying(str)
+ write_without_copying(str)
+ begin
+ Hijack::OutputCopier.remote.write('stderr', str)
+ rescue Exception => e
+ write_without_copying(e.message) if Hijack.debug?
+ Hijack.stop
end
- alias_method :write_without_copying, :write
- alias_method :write, :write_with_copying
end
+ alias_method :write_without_copying, :write
+ alias_method :write, :write_with_copying
end
end
+ end
- class Evaluator
- def initialize(context)
- @context = context
- end
-
- def evaluate(rb)
- @context.instance_eval(rb)
- end
+ class Evaluator
+ def initialize(context)
+ @context = context
end
- def self.debug?
- @debug
+ def evaluate(rb)
+ @context.instance_eval(rb)
end
+ end
- def self.start(context, debug)
- return if @service && @service.alive?
- @debug = debug
- evaluator = Hijack::Evaluator.new(context)
- @service = DRb.start_service('#{Hijack.socket_for(pid)}', evaluator)
- File.chmod(0600, '#{Hijack.socket_path_for(pid)}')
- end
+ def self.debug?
+ @debug
+ end
- def self.stop
- begin
- OutputCopier.stop
- @service.stop_service
- @service = nil
- rescue Exception
- end
+ def self.start(context, debug)
+ return if @service && @service.alive?
+ @debug = debug
+ evaluator = Hijack::Evaluator.new(context)
+ @service = DRb.start_service('#{Hijack.socket_for(pid)}', evaluator)
+ File.chmod(0600, '#{Hijack.socket_path_for(pid)}')
+ end
+
+ def self.stop
+ begin
+ OutputCopier.stop
+ @service.stop_service
+ @service = nil
+ rescue Exception
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.