SL2 Analyzer
Read a FromSoftware .sl2 save and report what is in it
Loading...
Searching...
No Matches
sl2.reader Namespace Reference

Functions

 read_uint (buf, off, size)
 Read a little-endian unsigned integer, or None if it would run past the end of the buffer.
 
 u8 (buf, off)
 One-byte read.
 
 u16 (buf, off)
 Two-byte read.
 
 u32 (buf, off)
 Four-byte read.
 
 u64 (buf, off)
 Eight-byte read.
 
 read_utf16 (buf, off, max_char)
 Decode a UTF-16LE string that ends at the first null pair.
 
 is_valid_name (name)
 Decide whether a decoded string is a plausible character name.
 

Variables

 NAME_OK = set("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 -_'")
 The only characters a real player name may contain.
 

Detailed Description

Safe, bounds-checked readers.

Nothing anywhere in the package indexes a buffer without going through these. A
read that would run off the end returns None (or "") instead of raising or
reading whatever happens to sit past it.

Function Documentation

◆ read_uint()

sl2.reader.read_uint (   buf,
  off,
  size 
)

Read a little-endian unsigned integer, or None if it would run past the end of the buffer.

Parameters
bufThe bytes to read from.
offByte offset. A negative offset is treated as out of range.
sizeWidth in bytes (1, 2, 4, or 8).
Returns
The integer value, or None if the read is out of range.

Definition at line 16 of file reader.py.

◆ u8()

sl2.reader.u8 (   buf,
  off 
)

One-byte read.

See also
read_uint

Definition at line 23 of file reader.py.

◆ u16()

sl2.reader.u16 (   buf,
  off 
)

Two-byte read.

See also
read_uint

Definition at line 28 of file reader.py.

◆ u32()

sl2.reader.u32 (   buf,
  off 
)

Four-byte read.

See also
read_uint

Definition at line 33 of file reader.py.

◆ u64()

sl2.reader.u64 (   buf,
  off 
)

Eight-byte read.

See also
read_uint

Definition at line 38 of file reader.py.

◆ read_utf16()

sl2.reader.read_utf16 (   buf,
  off,
  max_char 
)

Decode a UTF-16LE string that ends at the first null pair.

Souls names are UTF-16LE and not always fixed-length, so this reads a bounded window and stops at the first 0x0000. Returns an empty string on a bad read rather than raising.

Parameters
bufThe bytes to read from.
offWhere the string starts.
max_charMaximum characters to consider.
Returns
The decoded string, stripped of trailing nulls.

Definition at line 51 of file reader.py.

◆ is_valid_name()

sl2.reader.is_valid_name (   name)

Decide whether a decoded string is a plausible character name.

Parameters
nameThe candidate string.
Returns
True if it is non-empty and every character is allowed.

Definition at line 73 of file reader.py.

Variable Documentation

◆ NAME_OK

sl2.reader.NAME_OK = set("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 -_'")

The only characters a real player name may contain.

Anything outside this set means the bytes are not a name — usually an empty slot.

Definition at line 66 of file reader.py.