Class: Unisec::Hexdump
- Inherits:
-
Object
- Object
- Unisec::Hexdump
- Defined in:
- lib/unisec/hexdump.rb
Overview
Hexadecimal dump (hexdump) of all Unicode encodings.
Instance Attribute Summary collapse
-
#utf16be ⇒ String
readonly
UTF-16BE hexdump.
-
#utf16le ⇒ String
readonly
UTF-16LE hexdump.
-
#utf32be ⇒ String
readonly
UTF-32BE hexdump.
-
#utf32le ⇒ String
readonly
UTF-32LE hexdump.
-
#utf8 ⇒ String
readonly
UTF-8 hexdump.
Class Method Summary collapse
-
.display_reverse(hexbytes, enc, exact: true) ⇒ String
Display a CLI-friendly output summurizing the reverse hexdump search results.
-
.reverse(hexbytes, enc, exact: true) ⇒ Array<String>
Search X byte(s) hexadecimal value in Y encoding, basically which characters will give this resulting encoded value.
-
.utf16be(str) ⇒ String
Encode to UTF-16BE in hexdump format (spaced at every code unit = every 2 bytes).
-
.utf16le(str) ⇒ String
Encode to UTF-16LE in hexdump format (spaced at every code unit = every 2 bytes).
-
.utf32be(str) ⇒ String
Encode to UTF-32BE in hexdump format (spaced at every code unit = every 4 bytes).
-
.utf32le(str) ⇒ String
Encode to UTF-32LE in hexdump format (spaced at every code unit = every 4 bytes).
-
.utf8(str) ⇒ String
Encode to UTF-8 in hexdump format (spaced at every code unit = every byte).
Instance Method Summary collapse
-
#display ⇒ String
Display a CLI-friendly output summurizing the hexdump in all Unicode encodings.
-
#initialize(str) ⇒ Hexdump
constructor
Init the hexdump.
Constructor Details
Instance Attribute Details
#utf16be ⇒ String (readonly)
UTF-16BE hexdump
14 15 16 |
# File 'lib/unisec/hexdump.rb', line 14 def utf16be @utf16be end |
#utf16le ⇒ String (readonly)
UTF-16LE hexdump
18 19 20 |
# File 'lib/unisec/hexdump.rb', line 18 def utf16le @utf16le end |
#utf32be ⇒ String (readonly)
UTF-32BE hexdump
22 23 24 |
# File 'lib/unisec/hexdump.rb', line 22 def utf32be @utf32be end |
#utf32le ⇒ String (readonly)
UTF-32LE hexdump
26 27 28 |
# File 'lib/unisec/hexdump.rb', line 26 def utf32le @utf32le end |
#utf8 ⇒ String (readonly)
UTF-8 hexdump
10 11 12 |
# File 'lib/unisec/hexdump.rb', line 10 def utf8 @utf8 end |
Class Method Details
.display_reverse(hexbytes, enc, exact: true) ⇒ String
Display a CLI-friendly output summurizing the reverse hexdump search results
145 146 147 148 149 150 151 152 153 154 |
# File 'lib/unisec/hexdump.rb', line 145 def self.display_reverse(hexbytes, enc, exact: true) res = Unisec::Hexdump.reverse(hexbytes, enc, exact: exact) out = '' res.each do |char| cp = Utils::String.char2codepoint(char) hxd = Unisec::Hexdump.send(enc, char) out += "#{char.encode('UTF-8')} (#{cp}) - #{hxd}\n" end out end |
.reverse(hexbytes, enc, exact: true) ⇒ Array<String>
Search X byte(s) hexadecimal value in Y encoding, basically which characters will give this resulting encoded value
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/unisec/hexdump.rb', line 98 def self.reverse(hexbytes, enc, exact: true) chars = [] (0x000000..0x10FFFF).each do |i| char = i.chr(Unisec::Utils::Arguments.argenc2enc(enc, target: 'class')) encoded_value = Unisec::Hexdump.send(enc, char).delete(' ') if exact && encoded_value == hexbytes # exact match chars << char break elsif !exact && encoded_value.include?(hexbytes) # includes value chars << char end rescue RangeError # skip invalid code points for selected encoding next end chars end |
.utf16be(str) ⇒ String
Encode to UTF-16BE in hexdump format (spaced at every code unit = every 2 bytes)
57 58 59 |
# File 'lib/unisec/hexdump.rb', line 57 def self.utf16be(str) str.encode('UTF-16BE').to_hex.scan(/.{4}/).join(' ') end |
.utf16le(str) ⇒ String
Encode to UTF-16LE in hexdump format (spaced at every code unit = every 2 bytes)
66 67 68 |
# File 'lib/unisec/hexdump.rb', line 66 def self.utf16le(str) str.encode('UTF-16LE').to_hex.scan(/.{4}/).join(' ') end |
.utf32be(str) ⇒ String
Encode to UTF-32BE in hexdump format (spaced at every code unit = every 4 bytes)
75 76 77 |
# File 'lib/unisec/hexdump.rb', line 75 def self.utf32be(str) str.encode('UTF-32BE').to_hex.scan(/.{8}/).join(' ') end |
.utf32le(str) ⇒ String
Encode to UTF-32LE in hexdump format (spaced at every code unit = every 4 bytes)
84 85 86 |
# File 'lib/unisec/hexdump.rb', line 84 def self.utf32le(str) str.encode('UTF-32LE').to_hex.scan(/.{8}/).join(' ') end |
.utf8(str) ⇒ String
Encode to UTF-8 in hexdump format (spaced at every code unit = every byte)
48 49 50 |
# File 'lib/unisec/hexdump.rb', line 48 def self.utf8(str) str.encode('UTF-8').to_hex.scan(/.{2}/).join(' ') end |
Instance Method Details
#display ⇒ String
Display a CLI-friendly output summurizing the hexdump in all Unicode encodings
124 125 126 127 128 129 130 |
# File 'lib/unisec/hexdump.rb', line 124 def display "UTF-8: #{@utf8}\n" \ "UTF-16BE: #{@utf16be}\n" \ "UTF-16LE: #{@utf16le}\n" \ "UTF-32BE: #{@utf32be}\n" \ "UTF-32LE: #{@utf32le}" end |