Skip to main content

crashlink.recovery.hxsl

hxsl shader recovery.

Heaps shaders (hxsl.Shader subclasses) are compiled at macro time into a ShaderData AST and stored on the class as a serialized static var SRC : String (plus _MODULE). The bytecode's normal opcodes only hold the generated uniform- plumbing wrapper — the shader logic itself is that serialized string, sitting in the string pool.

Heaps 1.x serializes ShaderData with the standard haxe.Serializer text format (oy4:name...y4:funs...), so recovering a shader is: find these strings, run a haxe.Unserializer port over them, and interpret the result as a shader. This module does the first useful slice — find shaders and dump their interface (name + declared vars: inputs, params, textures, outputs). The function bodies (funs) decode too via the same unserializer; rendering them as readable shader source is a follow-up (a port of hxsl.Printer).

class HaxeUnserializer​

Minimal port of haxe.Unserializer — enough for serialized ShaderData.

Supports null/bool/int/float, strings (y, with the R string cache), anonymous objects (o..g), arrays (a..h, u null-runs), enums (j), and the value cache (r).

s​

s = s

pos​

pos = 0

scache: List[str]​

scache = []

cache: List[Any]​

cache = []

init​

def __init__(s: str)

unserialize​

def unserialize() -> Any

class HxEnum​

A deserialized Haxe enum value: type name + constructor index + args.

name​

name = name

index​

index = index

args​

args = args

init​

def __init__(name: str, index: int, args: List[Any])

class Shader​

name: str​

vars: List[ShaderVar]​

raw: Dict[str, Any]​

init​

def __init__(name: str, vars: List[ShaderVar], raw: Dict[str, Any]) -> None

class ShaderVar​

name: str​

kind: str​

type: str​

qualifiers: List[str]​

qualifiers = field(default_factory=list)

init​

def __init__(name: str, kind: str, type: str, qualifiers: List[str] = list()) -> None

class UnserializeError(RuntimeError)​

find_shader_sources​

def find_shader_sources(code: Bytecode) -> List[str]

Serialized shader-data strings in the image's string pool.

find_shaders​

def find_shaders(code: Bytecode) -> List[Shader]

Recover every hxsl shader in the image (interface only for now).

parse_shader​

def parse_shader(serialized: str) -> Shader

Deserialize one shader-data string into a Shader (name + vars).

render_shader​

def render_shader(shader: Shader) -> str

Render a recovered shader back to hxsl Haxe source.

shader_for_class​

def shader_for_class(code: Bytecode, class_name: str) -> Optional['Shader']

The recovered shader for a class name (destaticified), if it is one.

shader_header​

def shader_header(shader: Shader) -> str

A readable dump of a shader's interface (name + declared vars by kind).

shaders_by_name​

def shaders_by_name(code: Bytecode) -> Dict[str, 'Shader']

All shaders keyed by their embedded name (e.g. shader.Base2d), cached on the code object so repeated decompiler lookups don't re-scan the string pool.