Class: Rex::OLE::Util
- Inherits:
-
Object
- Object
- Rex::OLE::Util
- Defined in:
- lib/rex/ole/util.rb
Class Method Summary collapse
- .get16(buf, offset) ⇒ Object
- .get32(buf, offset) ⇒ Object
- .get32array(buf) ⇒ Object
- .get64(buf, offset) ⇒ Object
- .get8(buf, offset) ⇒ Object
- .getUnicodeString(buf) ⇒ Object
- .Hexify32array(arr) ⇒ Object
- .name_is_valid(name) ⇒ Object
- .pack16(value) ⇒ Object
- .pack32(value) ⇒ Object
- .pack32array(arr) ⇒ Object
- .pack64(value) ⇒ Object
- .pack8(value) ⇒ Object
- .Printable(buf) ⇒ Object
- .putUnicodeString(buf) ⇒ Object
- .set_endian(endian) ⇒ Object
Class Method Details
.get16(buf, offset) ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'lib/rex/ole/util.rb', line 103 def self.get16(buf, offset) @endian = LITTLE_ENDIAN if not @endian if (@endian == LITTLE_ENDIAN) buf[offset,2].unpack('v')[0] else buf[offset,2].unpack('n')[0] end end |
.get32(buf, offset) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/rex/ole/util.rb', line 67 def self.get32(buf, offset) @endian = LITTLE_ENDIAN if not @endian if (@endian == LITTLE_ENDIAN) buf[offset,4].unpack('V')[0] else buf[offset,4].unpack('N')[0] end end |
.get32array(buf) ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'lib/rex/ole/util.rb', line 85 def self.get32array(buf) @endian = LITTLE_ENDIAN if not @endian if (@endian == LITTLE_ENDIAN) buf.unpack('V*') else buf.unpack('N*') end end |
.get64(buf, offset) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rex/ole/util.rb', line 44 def self.get64(buf, offset) @endian = LITTLE_ENDIAN if not @endian if (@endian == LITTLE_ENDIAN) arr = buf[offset,8].unpack('VV') return (arr[0] + (arr[1] << 32)) else arr = buf[offset,8].unpack('NN') return ((arr[0] << 32) + arr[1]) end end |
.get8(buf, offset) ⇒ Object
121 122 123 |
# File 'lib/rex/ole/util.rb', line 121 def self.get8(buf, offset) buf[offset,1].unpack('C')[0] end |
.getUnicodeString(buf) ⇒ Object
130 131 132 133 134 135 136 |
# File 'lib/rex/ole/util.rb', line 130 def self.getUnicodeString(buf) buf = buf.unpack('S*').pack('C*') if (idx = buf.index(0x00.chr)) buf.slice!(idx, buf.length) end buf end |
.Hexify32array(arr) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/rex/ole/util.rb', line 17 def self.Hexify32array(arr) ret = "" arr.each { |dw| ret << " " if ret.length > 0 ret << "0x%08x" % dw } ret end |
.name_is_valid(name) ⇒ Object
147 148 149 150 151 152 153 |
# File 'lib/rex/ole/util.rb', line 147 def self.name_is_valid(name) return nil if (name.length > 31) (0..0x1f).to_a.each { |x| return nil if (name.include?(x.chr)) } return true end |
.pack16(value) ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'lib/rex/ole/util.rb', line 112 def self.pack16(value) @endian = LITTLE_ENDIAN if not @endian if (@endian == LITTLE_ENDIAN) [value].pack('v') else [value].pack('n') end end |
.pack32(value) ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/rex/ole/util.rb', line 76 def self.pack32(value) @endian = LITTLE_ENDIAN if not @endian if (@endian == LITTLE_ENDIAN) [value].pack('V') else [value].pack('N') end end |
.pack32array(arr) ⇒ Object
94 95 96 97 98 99 100 101 |
# File 'lib/rex/ole/util.rb', line 94 def self.pack32array(arr) @endian = LITTLE_ENDIAN if not @endian if (@endian == LITTLE_ENDIAN) arr.pack('V*') else arr.pack('N*') end end |
.pack64(value) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rex/ole/util.rb', line 55 def self.pack64(value) @endian = LITTLE_ENDIAN if not @endian arr = [] arr << (value & 0xffffffff) arr << (value >> 32) if (@endian == LITTLE_ENDIAN) arr.pack('VV') else arr.reverse.pack('NN') end end |
.pack8(value) ⇒ Object
125 126 127 |
# File 'lib/rex/ole/util.rb', line 125 def self.pack8(value) [value].pack('C') end |
.Printable(buf) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rex/ole/util.rb', line 26 def self.Printable(buf) ret = "" buf.unpack('C*').each { |byte| ch = byte.chr if (byte < 0x20 || byte > 0x7e) ret << "\\x" + ch.unpack('H*')[0] else ret << ch end } ret end |
.putUnicodeString(buf) ⇒ Object
138 139 140 141 142 143 144 |
# File 'lib/rex/ole/util.rb', line 138 def self.putUnicodeString(buf) buf = buf.unpack('C*').pack('S*') if (buf.length < 0x40) buf << "\x00" * (0x40 - buf.length) end buf end |
.set_endian(endian) ⇒ Object
40 41 42 |
# File 'lib/rex/ole/util.rb', line 40 def self.set_endian(endian) @endian = endian end |