Sha256: 4a61c940543c595227cb092960e432ceb0a96a4b3c527bf9b1bdae27c064b1a0

Contents?: true

Size: 1.75 KB

Versions: 14

Compression:

Stored size: 1.75 KB

Contents

# -*- coding: binary -*-
require "rex/text"

module Rex
module Proto
module DCERPC
class NDR


  # Provide padding to align the string to the 32bit boundary
  def self.align(string)
    warn 'should be using Rex::Encoder::NDR'
    return "\x00" * ((4 - (string.length & 3)) & 3)
  end

  # Encode a 4 byte long
  # use to encode:
  #       long element_1;
  def self.long(string)
    warn 'should be using Rex::Encoder::NDR'
    return [string].pack('V')
  end

  # Encode a 2 byte short
  # use to encode:
  #       short element_1;
  def self.short(string)
    warn 'should be using Rex::Encoder::NDR'
    return [string].pack('v')
  end

  # Encode a single byte
  # use to encode:
  #       byte element_1;
  def self.byte(string)
    warn 'should be using Rex::Encoder::NDR'
    return [string].pack('C')
  end

  # Encode a byte array
  # use to encode:
  #       char  element_1
  def self.UniConformantArray(string)
    warn 'should be using Rex::Encoder::NDR'
    return long(string.length) + string + align(string)
  end

  # Encode a string
  # use to encode:
  #       w_char *element_1;
  def self.UnicodeConformantVaryingString(string)
    warn 'should be using Rex::Encoder::NDR'
    string += "\x00" # null pad
    return long(string.length) + long(0) + long(string.length) + Rex::Text.to_unicode(string) + align(Rex::Text.to_unicode(string))
  end

  # Encode a string that is already unicode encoded
  # use to encode:
  #       w_char *element_1;
  def self.UnicodeConformantVaryingStringPreBuilt(string)
    warn 'should be using Rex::Encoder::NDR'
    # if the string len is odd, thats bad!
    if string.length % 2 > 0
      string += "\x00"
    end
    len = string.length / 2;
    return long(len) + long(0) + long(len) + string + align(string)
  end

end
end
end
end

Version data entries

14 entries across 14 versions & 3 rubygems

Version Path
rex-2.0.13 lib/rex/proto/dcerpc/ndr.rb
rex-2.0.12 lib/rex/proto/dcerpc/ndr.rb
rex-2.0.11 lib/rex/proto/dcerpc/ndr.rb
rex-2.0.10 lib/rex/proto/dcerpc/ndr.rb
rex-2.0.9 lib/rex/proto/dcerpc/ndr.rb
rex-2.0.8 lib/rex/proto/dcerpc/ndr.rb
rex-2.0.7 lib/rex/proto/dcerpc/ndr.rb
rex-2.0.5 lib/rex/proto/dcerpc/ndr.rb
rex-2.0.4 lib/rex/proto/dcerpc/ndr.rb
dstruct-0.0.1 lib/rex/proto/dcerpc/ndr.rb
rex-2.0.3 lib/rex/proto/dcerpc/ndr.rb
librex-0.0.999 lib/rex/proto/dcerpc/ndr.rb
rex-2.0.2 lib/rex/proto/dcerpc/ndr.rb
librex-0.0.71 lib/rex/proto/dcerpc/ndr.rb