Skip to content

Memory

The memory area reads and writes the game’s memory. Reads and writes check the pages first, so a bad address gives an error instead of a crash. It all works from any thread.

There’s a read and a write for each kind of number, like memory.readU32(address) and memory.writeF32(address, value), from U8 to I64, F32, F64 and Pointer. readString and readUtf16 read text up to a 0, and readBytes and writeBytes take bytes. isReadable(address, length) checks first.

For game types, schemas are easier, since they read and write fields by name.

import { Wraith } from "wraith";
const memory = Wraith.memory();
const gold = memory.readU32(address);
memory.writeU32(address, gold + 100);

memory.main() is the game’s exe, and findModule(name) and containing(address) find others, each with its name, base and size. memory.find(module, name, pattern) finds a byte pattern like "48 8B ?? C3" that’s there once, and findAll every match.

Like Cheat Engine. memory.scan(options) looks on a worker and gives a Memory.Scan, then next(compare, value, high) narrows it, on a worker too.

  • The options’ type is u8 to u64, i8 to i64, f32, f64, string, utf16 or bytes for a pattern like "48 8B ?? C3".
  • value is text, like 100 or -1.5.
  • module, or start and length, look in less.
  • next takes exact, changed, unchanged, increased, decreased, greater, less or between, with a low and a high for between. The others leave them empty.

count() says how many are left, and results(offset, limit) gives their addresses. Results are freed when the plugin stops, or with destroy().

const scan = await memory.scan({ type: "i32", value: "100" });
// Take a hit, then
await scan.next("decreased", "", "");
await scan.next("exact", "90", "");
const [health] = scan.results(0, 1);

memory.regions(module, all) lists stretches of memory, just in module unless it’s empty. With all it lists memory you can’t read too. memory.protect(address, length, protection) changes the pages under it, and gives what the first one was. Wraith puts protection back when the plugin stops.

import { Wraith } from "wraith";
for (const r of memory.regions("game.exe", false)) Wraith.log().info(`${r.start} ${r.length} ${r.writable}`);
const old = memory.protect(address, 16, "read_write");

To see which code writes to an address, watch it with watches.add and write. Each hit says where the instruction is, and code.disassemble shows it. See Watches and breakpoints.

Made with ♥ by Asgard