xhookLua
Game

memorynative tier

Read, write and scan game memory; exists only with "Raw memory access" on in the Scripting tab.

Functions

memory.module_base

memory.module_base([name]) -> integer
NameTypeDescription
nameoptionalstringLike "hw.dll"; omitted means game exe. Default nil.

Base address of a loaded module.

Returns base address, 0 if not loaded

memory.module_size

memory.module_size([name]) -> integer
NameTypeDescription
nameoptionalstringOmitted means the game exe. Default nil.

Size of a module's mapped image.

Returns image bytes, 0 if not loaded

memory.find_pattern

memory.find_pattern(module, pattern) -> integer | nil
NameTypeDescription
modulestringLoaded module to scan.
patternstringSpaced hex bytes, ? or ?? wildcards.

Scans a module for a byte signature, like "55 8B EC ?? 83".

Returns first match address, or nil

  • Bytes need spaces: "8BEC" is read as one byte, EC.
  • Slow on big modules; cache the result.

memory.read_int

memory.read_int(addr) -> integer | nil
NameType
addrinteger

Reads a signed 32-bit integer.

Returns nil if unreadable

Every read checks the page: bad addresses return nil, never crash.

memory.read_uint

memory.read_uint(addr) -> integer | nil
NameType
addrinteger

Reads an unsigned 32-bit integer.

Returns nil if unreadable

memory.read_short

memory.read_short(addr) -> integer | nil
NameType
addrinteger

Reads a signed 16-bit integer.

Returns nil if unreadable

memory.read_byte

memory.read_byte(addr) -> integer | nil
NameType
addrinteger

Reads an unsigned byte.

Returns 0 to 255, nil if unreadable

memory.read_float

memory.read_float(addr) -> number | nil
NameType
addrinteger

Reads a 32-bit float.

Returns nil if unreadable

memory.read_double

memory.read_double(addr) -> number | nil
NameType
addrinteger

Reads a 64-bit double.

Returns nil if unreadable

memory.read_ptr

memory.read_ptr(addr) -> integer | nil
NameType
addrinteger

Reads a 32-bit pointer, for pointer chains.

Returns nil if unreadable

memory.read_bytes

memory.read_bytes(addr, count) -> string | nil
NameTypeDescription
addrinteger
countinteger1 to 1048576 (1 MiB).

Copies a memory block into a Lua string.

Returns raw bytes, or nil

nil if count is out of range or any byte is unreadable.

memory.read_string

memory.read_string(addr [, maxlen]) -> string
NameTypeDescription
addrintegerNUL-terminated string address.
maxlenoptionalinteger1 to 65536, else 256. Default 256.

Reads a C string up to the NUL or maxlen.

Returns never nil

An unreadable address returns "", same as an empty string.

memory.write_int

memory.write_int(addr, value) -> boolean
NameTypeDescription
addrinteger
valueintegerTruncated to 32 bits.

Writes a 32-bit integer.

Returns false if not writable

Writes never change protection; use memory.protect for code and read-only data.

memory.write_short

memory.write_short(addr, value) -> boolean
NameTypeDescription
addrinteger
valueintegerTruncated to 16 bits.

Writes a 16-bit integer.

Returns true if written

memory.write_byte

memory.write_byte(addr, value) -> boolean
NameTypeDescription
addrinteger
valueintegerTruncated to 8 bits.

Writes one byte.

Returns true if written

memory.write_float

memory.write_float(addr, value) -> boolean
NameType
addrinteger
valuenumber

Writes a 32-bit float.

Returns true if written

memory.write_double

memory.write_double(addr, value) -> boolean
NameType
addrinteger
valuenumber

Writes a 64-bit double.

Returns true if written

memory.write_bytes

memory.write_bytes(addr, data) -> boolean
NameTypeDescription
addrinteger
datastringRaw bytes, like "\x90\x90".

Copies a byte string into memory, for patches.

Returns true if written

All or nothing: false if any byte is not writable.

memory.alloc

memory.alloc(size) -> integer | nil
NameTypeDescription
sizeintegerBytes, rounded up to pages.

Allocates executable read/write memory.

Returns zeroed RWX address, or nil

Never freed, even on unload; allocate once and reuse.

memory.protect

memory.protect(addr, size, prot) -> integer | nil
NameTypeDescription
addrintegerStart address.
sizeintegerBytes.
protintegerA memory.PAGE_* constant.

Changes page protection, usually to patch code then restore.

Returns previous protection, or nil

Whole pages, unguarded: no-access on a game page crashes.

Constants

NameValueDescription
memory.PAGE_NOACCESS1Any access faults.
memory.PAGE_READONLY2
memory.PAGE_READWRITE4
memory.PAGE_EXECUTE16Execute only.
memory.PAGE_EXECUTE_READ32Normal code.
memory.PAGE_EXECUTE_READWRITE64For patching code.
memory ยท Lua API ยท xhook