Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement "pause" method #176

Merged
merged 3 commits into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/pwnlib/pwn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
require 'pwnlib/tubes/process'
require 'pwnlib/tubes/serialtube'
require 'pwnlib/tubes/sock'

require 'pwnlib/ui'
require 'pwnlib/util/cyclic'
require 'pwnlib/util/fiddling'
require 'pwnlib/util/getdents'
Expand All @@ -31,6 +31,7 @@ module Pwn
include ::Pwnlib::Context
include ::Pwnlib::Logger
include ::Pwnlib::Runner
include ::Pwnlib::UI
include ::Pwnlib::Util::Cyclic
include ::Pwnlib::Util::Fiddling
include ::Pwnlib::Util::HexDump
Expand Down
21 changes: 21 additions & 0 deletions lib/pwnlib/ui.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# encoding: ASCII-8BIT
# frozen_string_literal: true

require 'pwnlib/logger'

module Pwnlib
# This module collects utilities that need user interactions.
module UI
module_function

# Waits for user input.
#
# @return [void]
def pause
log.info('Paused (press enter to continue)')
$stdin.gets
end

include ::Pwnlib::Logger
end
end
17 changes: 17 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,22 @@ def log_hook(obj)
::Pwnlib::Logger.log.instance_variable_set(:@logdev, old)
end
end

# Hooks +$stdin+.
#
# @param [IO] io
# IO object to be used as +$stdin+.
#
# @return [Object]
# Returns what the block returned.
def hook_stdin(io)
org_stdin = $stdin
$stdin = io
begin
yield
ensure
$stdin = org_stdin
end
end
end
end
18 changes: 18 additions & 0 deletions test/ui_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# encoding: ASCII-8BIT
# frozen_string_literal: true

require 'stringio'

require 'test_helper'

require 'pwnlib/ui'

class UITest < MiniTest::Test
def test_pause
hook_stdin(StringIO.new("\n")) do
assert_output(<<-EOS) { log_stdout { ::Pwnlib::UI.pause } }
[INFO] Paused (press enter to continue)
EOS
end
end
end