Class: Origami::HexaString

Inherits:
String
  • Object
show all
Includes:
String
Defined in:
lib/origami/string.rb,
lib/origami/obfuscation.rb

Overview

Class representing an hexadecimal-writen String Object.

Constant Summary collapse

TOKENS =

:nodoc:

%w{ < > }
@@regexp_open =
Regexp.new(WHITESPACES + TOKENS.first)
@@regexp_close =
Regexp.new(TOKENS.last)

Instance Attribute Summary

Attributes included from String

#encoding

Attributes included from Object

#file_offset, #generation, #no, #objstm_offset, #parent

Class Method Summary collapse

Instance Method Summary collapse

Methods included from String

#detect_encoding, #to_pdfdoc, #to_utf16be, #to_utf8

Methods included from Object

#<=>, #cast_to, #copy, #document, #export, included, #indirect?, #indirect_parent, #logicalize, #logicalize!, #native_type, #post_build, #pre_build, #reference, #set_document, #set_indirect, skip_until_next_obj, #solve, #to_o, #type, typeof, #version_required, #xrefs

Constructor Details

#initialize(str = "") ⇒ HexaString

Creates a new PDF hexadecimal String.

str

The string value.


173
174
175
176
177
178
179
# File 'lib/origami/string.rb', line 173

def initialize(str = "")
    unless str.is_a?(::String)
        raise TypeError, "Expected type String, received #{str.class}."
    end

    super(str)
end

Class Method Details

.parse(stream, _parser = nil) ⇒ Object

:nodoc:


181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/origami/string.rb', line 181

def self.parse(stream, _parser = nil) #:nodoc:
    offset = stream.pos

    if stream.skip(@@regexp_open).nil?
        raise InvalidHexaStringObjectError, "Hexadecimal string shall start with a '#{TOKENS.first}' token"
    end

    hexa = stream.scan_until(@@regexp_close)
    if hexa.nil?
        raise InvalidHexaStringObjectError, "Hexadecimal string shall end with a '#{TOKENS.last}' token"
    end

    decoded = Filter::ASCIIHex.decode(hexa.chomp!(TOKENS.last))

    hexastr = HexaString.new(decoded)
    hexastr.file_offset = offset

    hexastr
end

Instance Method Details

#to_literalObject

Converts self to a literal String.


208
209
210
# File 'lib/origami/string.rb', line 208

def to_literal
    LiteralString.new(self.value)
end

#to_sObject Also known as: to_obfuscated_str

:nodoc:


201
202
203
# File 'lib/origami/string.rb', line 201

def to_s #:nodoc:
    super(TOKENS.first + Filter::ASCIIHex.encode(to_str) + TOKENS.last)
end

#valueObject


212
213
214
215
216
# File 'lib/origami/string.rb', line 212

def value
    self.decrypt! if self.is_a?(Encryption::EncryptedString) and not @decrypted

    to_str
end