Sha256: 615559ba2e90c8e90fad4961df212992cd53c560d9271c73b5bfe5a08cdb4714

Contents?: true

Size: 1.66 KB

Versions: 43

Compression:

Stored size: 1.66 KB

Contents

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

43 entries across 43 versions & 1 rubygems

Version Path
librex-0.0.65 lib/rex/proto/dcerpc/ndr.rb
librex-0.0.63 lib/rex/proto/dcerpc/ndr.rb
librex-0.0.54 lib/rex/proto/dcerpc/ndr.rb
librex-0.0.53 lib/rex/proto/dcerpc/ndr.rb
librex-0.0.52 lib/rex/proto/dcerpc/ndr.rb
librex-0.0.51 lib/rex/proto/dcerpc/ndr.rb
librex-0.0.50 lib/rex/proto/dcerpc/ndr.rb
librex-0.0.49 lib/rex/proto/dcerpc/ndr.rb
librex-0.0.48 lib/rex/proto/dcerpc/ndr.rb
librex-0.0.47 lib/rex/proto/dcerpc/ndr.rb
librex-0.0.46 lib/rex/proto/dcerpc/ndr.rb
librex-0.0.44 lib/rex/proto/dcerpc/ndr.rb
librex-0.0.43 lib/rex/proto/dcerpc/ndr.rb
librex-0.0.42 lib/rex/proto/dcerpc/ndr.rb
librex-0.0.41 lib/rex/proto/dcerpc/ndr.rb
librex-0.0.40 lib/rex/proto/dcerpc/ndr.rb
librex-0.0.39 lib/rex/proto/dcerpc/ndr.rb
librex-0.0.38 lib/rex/proto/dcerpc/ndr.rb
librex-0.0.37 lib/rex/proto/dcerpc/ndr.rb
librex-0.0.36 lib/rex/proto/dcerpc/ndr.rb