forked from rapid7/metasploit-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: Fix Reline ASCII-8BIT <-> UTF-8 issues
- Loading branch information
1 parent
953f6c1
commit 32cfbee
Showing
11 changed files
with
259 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# -*- coding: binary -*- | ||
|
||
require 'rex/ui/text/input/utf8_common' | ||
|
||
module Rex | ||
module Ui | ||
module Text | ||
|
||
require 'rex/io/stream_abstraction' | ||
|
||
### | ||
# | ||
# This class implements input against a socket and forces UTF-8 encoding. | ||
# | ||
### | ||
class Input::Utf8Buffer < Rex::Ui::Text::Input::Buffer | ||
|
||
# Array of methods that will be used to override methods from the base class to wrap them with forced UTF-8 encoding. | ||
METHODS_TO_WRAP_WITH_UTF8_ENCODING = %i[sysread gets put].freeze | ||
|
||
METHODS_TO_WRAP_WITH_UTF8_ENCODING.each do |method| | ||
class_eval %{ | ||
def #{method} (*args, &block) | ||
Rex::Ui::Text::Input::Utf8Common.with_utf8_encoding do | ||
super | ||
end | ||
end | ||
} | ||
end | ||
|
||
def utf8? | ||
true | ||
end | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# -*- coding: binary -*- | ||
|
||
module Rex | ||
module Ui | ||
module Text | ||
class Input::Utf8Common | ||
def self.with_utf8_encoding(&block) | ||
external_encoding_on_entry = ::Encoding.default_external | ||
::Encoding.default_external = ::Encoding::UTF_8 | ||
|
||
internal_encoding_on_entry = ::Encoding.default_internal | ||
::Encoding.default_internal = ::Encoding::UTF_8 | ||
|
||
begin | ||
return block.call | ||
rescue StandardError => e | ||
elog("Failed to call block with UTF8 encoding. Backtrace: #{e.backtrace}", error: e) | ||
ensure | ||
::Encoding.default_external = external_encoding_on_entry | ||
::Encoding.default_internal = internal_encoding_on_entry | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -*- coding: binary -*- | ||
|
||
require 'rex/ui/text/input/utf8_common' | ||
|
||
module Rex | ||
module Ui | ||
module Text | ||
|
||
### | ||
# | ||
# This class implements standard input using Reline against | ||
# standard input, and forces UTF-8 encoding. It supports tab completion. | ||
# | ||
### | ||
class Input::Utf8Readline < Input::Readline | ||
|
||
# Array of methods that will be used to override methods from the base class to wrap them with forced UTF-8 encoding. | ||
METHODS_TO_WRAP_WITH_UTF8_ENCODING = %i[pgets gets sysread readline_with_output update_prompt].freeze | ||
|
||
METHODS_TO_WRAP_WITH_UTF8_ENCODING.each do |method| | ||
class_eval %{ | ||
def #{method} (*args, &block) | ||
Rex::Ui::Text::Input::Utf8Common.with_utf8_encoding do | ||
super | ||
end | ||
end | ||
} | ||
end | ||
|
||
def utf8? | ||
true | ||
end | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# -*- coding: binary -*- | ||
|
||
require 'rex/ui/text/input/utf8_common' | ||
|
||
module Rex | ||
module Ui | ||
module Text | ||
|
||
### | ||
# | ||
# This class implements input against a socket and forces UTF-8 encoding. | ||
# | ||
### | ||
class Input::Utf8Socket < Rex::Ui::Text::Input::Socket | ||
|
||
# Array of methods that will be used to override methods from the base class to wrap them with forced UTF-8 encoding. | ||
METHODS_TO_WRAP_WITH_UTF8_ENCODING = %i[sysread gets].freeze | ||
|
||
METHODS_TO_WRAP_WITH_UTF8_ENCODING.each do |method| | ||
class_eval %{ | ||
def #{method} (*args, &block) | ||
Rex::Ui::Text::Input::Utf8Common.with_utf8_encoding do | ||
super | ||
end | ||
end | ||
} | ||
end | ||
|
||
def utf8? | ||
true | ||
end | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# -*- coding: binary -*- | ||
|
||
require 'rex/ui/text/input/utf8_common' | ||
|
||
module Rex | ||
module Ui | ||
module Text | ||
|
||
### | ||
# | ||
# This class implements input against standard in and forces UTF-8 encoding. | ||
# | ||
### | ||
class Input::Utf8Stdio < Rex::Ui::Text::Input::Stdio | ||
|
||
# Array of methods that will be used to override methods from the base class to wrap them with forced UTF-8 encoding. | ||
METHODS_TO_WRAP_WITH_UTF8_ENCODING = %i[sysread gets].freeze | ||
|
||
METHODS_TO_WRAP_WITH_UTF8_ENCODING.each do |method| | ||
class_eval %{ | ||
def #{method} (*args, &block) | ||
Rex::Ui::Text::Input::Utf8Common.with_utf8_encoding do | ||
super | ||
end | ||
end | ||
} | ||
end | ||
|
||
def utf8? | ||
true | ||
end | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# -*- coding: binary -*- | ||
|
||
module Rex | ||
module Ui | ||
module Text | ||
class Output::Utf8Common | ||
def self.with_utf8_encoding(&block) | ||
external_encoding_on_entry = ::Encoding.default_external | ||
::Encoding.default_external = ::Encoding::UTF_8 | ||
|
||
internal_encoding_on_entry = ::Encoding.default_internal | ||
::Encoding.default_internal = ::Encoding::UTF_8 | ||
|
||
begin | ||
return block.call | ||
rescue ::StandardError => e | ||
puts 'Output' | ||
puts caller | ||
elog('Failed to call block with UTF8 encoding', error: e) | ||
ensure | ||
::Encoding.default_external = external_encoding_on_entry | ||
::Encoding.default_internal = internal_encoding_on_entry | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -*- coding: binary -*- | ||
|
||
require 'rex/ui/text/output/utf8_common' | ||
|
||
module Rex | ||
module Ui | ||
module Text | ||
|
||
### | ||
# | ||
# This class implements output against standard out and forces UTF-8 encoding. | ||
# | ||
### | ||
class Output::Utf8Stdio < Rex::Ui::Text::Output::Stdio | ||
|
||
# Array of methods that will be used to override methods from the base class to wrap them with forced UTF-8 encoding. | ||
METHODS_TO_WRAP_WITH_UTF8_ENCODING = %i[print_line print_raw].freeze | ||
|
||
METHODS_TO_WRAP_WITH_UTF8_ENCODING.each do |method| | ||
class_eval %{ | ||
def #{method} (*args, &block) | ||
Rex::Ui::Text::Input::Utf8Common.with_utf8_encoding do | ||
super | ||
end | ||
end | ||
} | ||
end | ||
|
||
def utf8? | ||
true | ||
end | ||
end | ||
|
||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters