Module: MemoryIO

Defined in:
lib/memory_io.rb,
lib/memory_io/io.rb,
lib/memory_io/util.rb,
lib/memory_io/error.rb,
lib/memory_io/logger.rb,
lib/memory_io/stream.rb,
lib/memory_io/context.rb,
lib/memory_io/process.rb,
lib/memory_io/version.rb,
lib/memory_io/types/type.rb,
lib/memory_io/types/types.rb,
lib/memory_io/types/record.rb,
lib/memory_io/types/cpp/string.rb,
lib/memory_io/types/clang/c_str.rb,
lib/memory_io/types/basic/number.rb

Overview

MemoryIO - Read/Write structures in memory.

Defined Under Namespace

Modules: Types, Util Classes: Context, Error, IO, InvalidAddressError, Process, ProcessNotFoundError, Stream, ValueOutOfRangeError

Constant Summary collapse

FORMATTER =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Keeps a message readable when it is shown to a human.

Examples:

# [memory_io] WARN: something happened
proc { |severity, _datetime, progname, msg| "[#{progname}] #{severity}: #{msg}\n" }
VERSION =

Current gem version.

'1.0.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loggerLogger

Diagnostics that are worth surfacing but don't stop the operation are written here, so they can be silenced or redirected.

Examples:

MemoryIO.logger.level = Logger::ERROR

MemoryIO.logger = Logger.new('memory_io.log')

Returns:

  • (Logger)

    Defaults to a logger writing to $stderr.



18
19
20
# File 'lib/memory_io/logger.rb', line 18

def logger
  @logger ||= ::Logger.new($stderr, progname: 'memory_io', formatter: FORMATTER)
end

Class Method Details

.attach(pid, endian: nil, pointer_size: nil) ⇒ MemoryIO::Process

Note:

The context is read from /proc/[pid]/exe, which names the interpreter when the process was started through one. Pass endian and pointer_size for such a process, whose context may differ from the interpreter running it.

Get a process by process id.

Examples:

process = MemoryIO.attach(`pidof victim`.to_i)
process.read('heap', 8)
# a program started through an interpreter is described by the
# interpreter, so state the context of the program instead
MemoryIO.attach(`pidof victim32`.to_i, pointer_size: 4)

Parameters:

  • pid (Integer)

    Process id in Linux.

  • endian (:little, :big, :native, nil) (defaults to: nil)

    Byte order of the process's memory.

  • pointer_size (Integer?) (defaults to: nil)

    Size of a pointer in the process, in bytes.

    Both are taken from the process's executable when not given.

Returns:

Raises:

See Also:



40
41
42
# File 'lib/memory_io.rb', line 40

def attach(pid, endian: nil, pointer_size: nil)
  MemoryIO::Process.new(pid, endian: endian, pointer_size: pointer_size)
end