Module: Rex::Post::Meterpreter::Extensions::Stdapi::Railgun::Type::PointerUtil

Defined in:
lib/rex/post/meterpreter/extensions/stdapi/railgun/type/pointer_util.rb

Constant Summary collapse

ARCH_POINTER_SIZE =
{
  PlatformUtil::X86_64 => 8,
  PlatformUtil::X86_32 => 4
}.freeze

Class Method Summary collapse

Class Method Details

.is_null_pointer?(pointer, platform) ⇒ Boolean

Summary: Returns true if pointer will be considered a 'null' pointer

If given nil, returns true If given 0, returns true If given a string, if 0 after unpacking, returns true false otherwise


64
65
66
67
68
69
70
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/type/pointer_util.rb', line 64

def self.is_null_pointer?(pointer, platform)
  if pointer.kind_of?(String)
    pointer = unpack_pointer(pointer, platform)
  end

  return pointer.nil? || pointer == 0
end

.is_pointer_type?(type) ⇒ Boolean

Returns true if the data type is a pointer, false otherwise


87
88
89
90
91
92
93
94
95
96
97
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/type/pointer_util.rb', line 87

def self.is_pointer_type?(type)
  if type == :pointer
    return true
  end

  if type.kind_of?(String) && type =~ /^L?P/
    return true
  end

  return false
end

.null_pointer(pointer, platform) ⇒ Object


52
53
54
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/type/pointer_util.rb', line 52

def self.null_pointer(pointer, platform)
  pack_pointer(0, platform)
end

.pack_pointer(pointer, platform) ⇒ Object


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/type/pointer_util.rb', line 23

def self.pack_pointer(pointer, platform)
  if pointer.nil?
    return pack_pointer(0, platform)
  end

  case platform
  when PlatformUtil::X86_64
    # XXX: Only works if attacker and victim are like-endianed
    [pointer].pack('Q')
  when PlatformUtil::X86_32
    [pointer].pack('V')
  else
    raise "platform symbol #{platform.to_s} not supported"
  end
end

.pointer_size(platform) ⇒ Object

Returns the pointer size for this architecture. Should accept client or platform or arch


19
20
21
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/type/pointer_util.rb', line 19

def self.pointer_size(platform)
  ARCH_POINTER_SIZE[platform]
end

.unpack_pointer(packed_pointer, platform) ⇒ Object

Given a packed pointer, unpack it according to architecture


40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/type/pointer_util.rb', line 40

def self.unpack_pointer(packed_pointer, platform)
  case platform
  when PlatformUtil::X86_64
    # XXX: Only works if attacker and victim are like-endianed
    packed_pointer.unpack('Q').first
  when PlatformUtil::X86_32
    packed_pointer.unpack('V').first
  else
    raise "platform symbol #{platform.to_s} not supported"
  end
end