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

Constants

ARCH_POINTER_SIZE

Public Class Methods

is_null_pointer?(pointer, platform) click to toggle source

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

# File lib/rex/post/meterpreter/extensions/stdapi/railgun/type/pointer_util.rb, line 63
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) click to toggle source
def self.is_unpacked_pointer?(pointer, platform)
        # TODO also check that the integer size is appropriate for the platform
        unless pointer.kind_of?(Fixnum) and pointer > 0 # and pointer <
                return false
        end

        packed_pointer = pack_pointer(pointer, platform)
        if !packed_pointer.nil? and packed_pointer.length == pointer_size(platform)
                return true
        end

        return false
end

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

# File lib/rex/post/meterpreter/extensions/stdapi/railgun/type/pointer_util.rb, line 86
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) click to toggle source
# File lib/rex/post/meterpreter/extensions/stdapi/railgun/type/pointer_util.rb, line 51
def self.null_pointer(pointer, platform)
  pack_pointer(0, platform)
end
pack_pointer(pointer, platform) click to toggle source
# File lib/rex/post/meterpreter/extensions/stdapi/railgun/type/pointer_util.rb, line 22
def self.pack_pointer(pointer, platform)
  if pointer.nil?
    return pack_pointer(0, platform)
  end

  case platform
  when PlatformUtil::X86_64
    # Assume little endian
    [pointer].pack('Q<')
  when PlatformUtil::X86_32
    [pointer].pack('V')
  else
    raise "platform symbol #{platform.to_s} not supported"
  end
end
pointer_size(platform) click to toggle source

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

# File lib/rex/post/meterpreter/extensions/stdapi/railgun/type/pointer_util.rb, line 18
def self.pointer_size(platform)
  ARCH_POINTER_SIZE[platform]
end
unpack_pointer(packed_pointer, platform) click to toggle source

Given a packed pointer, unpack it according to architecture

# File lib/rex/post/meterpreter/extensions/stdapi/railgun/type/pointer_util.rb, line 39
def self.unpack_pointer(packed_pointer, platform)
  case platform
  when PlatformUtil::X86_64
    # Assume little endian
    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