Module refinery.lib.scripts.xlm.deobfuscation

The static deobfuscation of an XLM program: the passes that clean the macrosheet model a listing starts from. The constant folding replaces what the workbook stores with what it computes, the removal of the cells no formula leads to then drops the padding that folding emptied, and nothing else rewrites the model — the emulator evaluates everything else, and a trace that folded or swept its input would hide the program it exists to show.

Expand source code Browse git
"""
The static deobfuscation of an XLM program: the passes that clean the macrosheet model a
listing starts from. The constant folding replaces what the workbook stores with what it
computes, the removal of the cells no formula leads to then drops the padding that folding
emptied, and nothing else rewrites the model — the emulator evaluates everything else, and a
trace that folded or swept its input would hide the program it exists to show.
"""
from __future__ import annotations

from typing import TYPE_CHECKING

from refinery.lib.scripts.xlm.deobfuscation.deadcode import sweep
from refinery.lib.scripts.xlm.deobfuscation.fold import fold

if TYPE_CHECKING:
    from refinery.lib.scripts.xlm.view import XlmView


def deobfuscate(view: XlmView, start_point: str = '') -> None:
    """
    Clean the macrosheets of the view in place for a listing: fold every statically computable
    subtree into the value it computes, then remove the cells no formula leads to, keeping the
    entry points the run starts from.
    """
    fold(view)
    sweep(view, start_point)

Sub-modules

refinery.lib.scripts.xlm.deobfuscation.deadcode

The removal of the cells no formula leads to: the padding obfuscation scatters over its macrosheets. Execution enters a column only at a cell a …

refinery.lib.scripts.xlm.deobfuscation.fold

The constant folding of the macrosheet model: every subtree of a formula that computes from stored state alone — literals, the operators over them, …

refinery.lib.scripts.xlm.deobfuscation.program

The text of an XLM program as the static passes read it: the formula of every macrosheet cell and of every defined name, and the formulas their string …

Functions

def deobfuscate(view, start_point='')

Clean the macrosheets of the view in place for a listing: fold every statically computable subtree into the value it computes, then remove the cells no formula leads to, keeping the entry points the run starts from.

Expand source code Browse git
def deobfuscate(view: XlmView, start_point: str = '') -> None:
    """
    Clean the macrosheets of the view in place for a listing: fold every statically computable
    subtree into the value it computes, then remove the cells no formula leads to, keeping the
    entry points the run starts from.
    """
    fold(view)
    sweep(view, start_point)