Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/rex/proto/dcerpc/ndr.rb
Views: 11704
# -*- coding: binary -*-1require "rex/text"23module Rex4module Proto5module DCERPC6class NDR789# Provide padding to align the string to the 32bit boundary10def self.align(string)11warn 'should be using Rex::Encoder::NDR'12return "\x00" * ((4 - (string.length & 3)) & 3)13end1415# Encode a 4 byte long16# use to encode:17# long element_1;18def self.long(string)19warn 'should be using Rex::Encoder::NDR'20return [string].pack('V')21end2223# Encode a 2 byte short24# use to encode:25# short element_1;26def self.short(string)27warn 'should be using Rex::Encoder::NDR'28return [string].pack('v')29end3031# Encode a single byte32# use to encode:33# byte element_1;34def self.byte(string)35warn 'should be using Rex::Encoder::NDR'36return [string].pack('C')37end3839# Encode a byte array40# use to encode:41# char element_142def self.UniConformantArray(string)43warn 'should be using Rex::Encoder::NDR'44return long(string.length) + string + align(string)45end4647# Encode a string48# use to encode:49# w_char *element_1;50def self.UnicodeConformantVaryingString(string)51warn 'should be using Rex::Encoder::NDR'52string += "\x00" # null pad53return long(string.length) + long(0) + long(string.length) + Rex::Text.to_unicode(string) + align(Rex::Text.to_unicode(string))54end5556# Encode a string that is already unicode encoded57# use to encode:58# w_char *element_1;59def self.UnicodeConformantVaryingStringPreBuilt(string)60warn 'should be using Rex::Encoder::NDR'61# if the string len is odd, thats bad!62if string.length % 2 > 063string += "\x00"64end65len = string.length / 2;66return long(len) + long(0) + long(len) + string + align(string)67end6869end70end71end72end737475