367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
93 lines
4.0 KiB
Python
93 lines
4.0 KiB
Python
"""Read-only code observation at the native race/class-vector copy block.
|
|
|
|
This is the naturally reached block in the character-selection consumer. It
|
|
captures only its exact executable page and never reads registers, packet
|
|
objects, or vector contents.
|
|
"""
|
|
import importlib
|
|
import os
|
|
import struct
|
|
from pathlib import Path
|
|
import engine_race_validator_observation
|
|
|
|
capture_code_page = importlib.reload(engine_race_validator_observation).capture_code_page
|
|
|
|
ENTRY = 0x142415208
|
|
PAGE = ENTRY & ~4095
|
|
PREFIX = bytes.fromhex('48 8b 15 04 1f 85 05')
|
|
OBSERVE_NATURAL_FIRST_USE = True
|
|
|
|
|
|
def parse_source_header(raw):
|
|
if len(raw) != 16:
|
|
return {'source_header_available': False,
|
|
'source_header_reason': 'fixed-source-header-short-read',
|
|
'source_packet_payloads_read': False}
|
|
source_pointer, source_count = struct.unpack('<QQ', raw)
|
|
if source_count > 32:
|
|
return {'source_header_available': False,
|
|
'source_header_reason': 'source-count-out-of-bound',
|
|
'source_rows_pointer_present': bool(source_pointer),
|
|
'source_packet_payloads_read': False}
|
|
return {'source_header_available': True, 'source_header_reason': None,
|
|
'source_rows_pointer_present': bool(source_pointer),
|
|
'source_row_count': source_count,
|
|
'source_pointer_count_consistent': bool(source_pointer) == bool(source_count),
|
|
'source_header_read_bytes': 16, 'source_packet_payloads_read': False,
|
|
'authentication_buffers_read': False}
|
|
|
|
|
|
def parse_race_class_pairs(raw):
|
|
if len(raw) != 16:
|
|
return {'race_class_pairs_available': False,
|
|
'race_class_pairs_reason': 'fixed-pairs-header-short-read'}
|
|
pointer, count = struct.unpack('<QQ', raw)
|
|
if count > 256:
|
|
return {'race_class_pairs_available': False,
|
|
'race_class_pairs_reason': 'race-class-count-out-of-bound',
|
|
'race_class_pairs_pointer_present': bool(pointer)}
|
|
return {'race_class_pairs_available': True,
|
|
'race_class_pairs_pointer_present': bool(pointer),
|
|
'race_class_pair_count': count,
|
|
'race_class_pairs_pointer_count_consistent': bool(pointer) == bool(count)}
|
|
|
|
|
|
def capture(pid, registers):
|
|
if registers.rip != ENTRY:
|
|
return {'available': False, 'reason': 'different-entry',
|
|
'engine_calls_made': False, 'arguments_read': False}
|
|
code = capture_code_page(pid, registers, ENTRY, PAGE)
|
|
if not registers.rsi:
|
|
return {**code, 'source_header_available': False,
|
|
'source_header_reason': 'null-consumer-object',
|
|
'source_packet_payloads_read': False}
|
|
addresses = (registers.rsi + 0x70, registers.rsi + 0xa0)
|
|
maps = Path(f'/proc/{pid}/maps').read_text().splitlines()
|
|
fd = os.open(f'/proc/{pid}/mem', os.O_RDONLY)
|
|
try:
|
|
headers = []
|
|
for address in addresses:
|
|
readable = any(
|
|
int(row.split()[0].split('-')[0], 16) <= address and
|
|
address + 16 <= int(row.split()[0].split('-')[1], 16) and
|
|
'r' in row.split()[1]
|
|
for row in maps)
|
|
if not readable:
|
|
headers.append(None)
|
|
continue
|
|
raw = os.pread(fd, 16, address)
|
|
headers.append(raw if len(raw) == 16 else None)
|
|
finally:
|
|
os.close(fd)
|
|
primary = (parse_source_header(headers[0]) if headers[0] is not None else
|
|
{'source_header_available': False,
|
|
'source_header_reason': 'fixed-source-header-unmapped',
|
|
'source_packet_payloads_read': False})
|
|
pairs = (parse_race_class_pairs(headers[1]) if headers[1] is not None else
|
|
{'race_class_pairs_available': False,
|
|
'race_class_pairs_reason': 'fixed-pairs-header-unmapped'})
|
|
return {**code, **primary, **pairs,
|
|
'source_pair_header_offset': '0xa0',
|
|
'source_packet_payloads_read': False,
|
|
'authentication_buffers_read': False}
|