Papers
Topics
Authors
Recent
Search
2000 character limit reached

Self-Modifying Pushdown Systems

Updated 10 November 2025
  • Self-Modifying Pushdown Systems (SM-PDS) are formal models that extend traditional pushdown systems by allowing dynamic modification of transition rules to capture self-modifying behaviors in code.
  • SM-PDS enable automated analysis techniques such as backward/forward reachability and LTL model checking, which are crucial for analyzing obfuscated and malicious software.
  • Experimental evaluations show that SM-PDS achieve 100% detection of self-modifying malware with improved performance and resource efficiency compared to traditional static analysis methods.

Self-Modifying Pushdown Systems (SM-PDS) are a formal extension of classical pushdown systems (PDS) designed to model and enable automated analysis of self-modifying code, particularly as encountered in obfuscated or malicious software. In SM-PDS, the set of transition rules can change dynamically during execution, reflecting the key ability of self-modifying programs to alter their instruction set at runtime. This modeling paradigm enables the application of reachability analysis, Linear Temporal Logic (LTL) model checking, and malware detection in the presence of code that evades traditional static verification techniques.

1. Formal Definition and Semantics

An SM-PDS is defined as a tuple P=(P,Γ,Δ,Δc)\mathcal{P} = (P, \Gamma, \Delta, \Delta_c), where PP is a finite set of control points (states), Γ\Gamma is a finite stack alphabet, Δ(P×Γ)×(P×Γ)\Delta \subseteq (P \times \Gamma) \times (P \times \Gamma^*) is the set of standard PDS transition rules, and ΔcP×(ΔΔc)×(ΔΔc)×P\Delta_c \subseteq P \times (\Delta\cup\Delta_c)\times(\Delta\cup\Delta_c)\times P encodes self-modifying rules. A configuration is of the form (p,w,θ)(\langle p, w\rangle, \theta) where pPp \in P, wΓw \in \Gamma^* (stack content), and θΔΔc\theta \subseteq \Delta \cup \Delta_c is the current set of enabled rules (referred to as the “phase”).

There are two key operational semantics:

  • Ordinary rule application (Std): If p,γp,wθΔ\langle p, \gamma\rangle \hookrightarrow \langle p', w'\rangle \in \theta \cap \Delta, then

PP0

  • Self-modification (Mod): If PP1 and PP2, then

PP3

where PP4.

If PP5, PP6 reduces to an ordinary PDS. The system thus permits arbitrary switching of its currently enabled transition rules, allowing a precise encoding of program phases for code that changes its control-flow or stack behavior at runtime (Touili et al., 2019, Touili et al., 2019).

2. Reachability Analysis

The central analysis tasks for SM-PDS are backward reachability (PP7) and forward reachability (PP8), computed with automata-theoretic saturation algorithms.

Backward Reachability (PP9)

Given a regular target set Γ\Gamma0 of configurations, the aim is to compute all configurations from which Γ\Gamma1 is reachable. Γ\Gamma2 is represented by a Γ\Gamma3-automaton Γ\Gamma4 over configurations, accepting Γ\Gamma5 iff Γ\Gamma6 for Γ\Gamma7. Saturation uses two rules:

  • Γ\Gamma8 (ordinary rules): If Γ\Gamma9 and Δ(P×Γ)×(P×Γ)\Delta \subseteq (P \times \Gamma) \times (P \times \Gamma^*)0, then Δ(P×Γ)×(P×Γ)\Delta \subseteq (P \times \Gamma) \times (P \times \Gamma^*)1 is added.
  • Δ(P×Γ)×(P×Γ)\Delta \subseteq (P \times \Gamma) \times (P \times \Gamma^*)2 (self-modifying rules): If Δ(P×Γ)×(P×Γ)\Delta \subseteq (P \times \Gamma) \times (P \times \Gamma^*)3 and Δ(P×Γ)×(P×Γ)\Delta \subseteq (P \times \Gamma) \times (P \times \Gamma^*)4, with Δ(P×Γ)×(P×Γ)\Delta \subseteq (P \times \Gamma) \times (P \times \Gamma^*)5, then Δ(P×Γ)×(P×Γ)\Delta \subseteq (P \times \Gamma) \times (P \times \Gamma^*)6 is added.

The fixpoint Δ(P×Γ)×(P×Γ)\Delta \subseteq (P \times \Gamma) \times (P \times \Gamma^*)7 thus accepts exactly Δ(P×Γ)×(P×Γ)\Delta \subseteq (P \times \Gamma) \times (P \times \Gamma^*)8 (Touili et al., 2019).

Forward Reachability (Δ(P×Γ)×(P×Γ)\Delta \subseteq (P \times \Gamma) \times (P \times \Gamma^*)9)

Forward reachability is constructed similarly, with four rules ΔcP×(ΔΔc)×(ΔΔc)×P\Delta_c \subseteq P \times (\Delta\cup\Delta_c)\times(\Delta\cup\Delta_c)\times P0 manipulating transitions depending on the operation (pop, single push, double push, and self-modification). This procedure ensures that ΔcP×(ΔΔc)×(ΔΔc)×P\Delta_c \subseteq P \times (\Delta\cup\Delta_c)\times(\Delta\cup\Delta_c)\times P1 accepts ΔcP×(ΔΔc)×(ΔΔc)×P\Delta_c \subseteq P \times (\Delta\cup\Delta_c)\times(\Delta\cup\Delta_c)\times P2.

Both analyses scale in the number of changing rules ΔcP×(ΔΔc)×(ΔΔc)×P\Delta_c \subseteq P \times (\Delta\cup\Delta_c)\times(\Delta\cup\Delta_c)\times P3, with time and space ΔcP×(ΔΔc)×(ΔΔc)×P\Delta_c \subseteq P \times (\Delta\cup\Delta_c)\times(\Delta\cup\Delta_c)\times P4, but only generate reachable phases in practice, allowing effective analysis even for real-world code.

3. LTL Model Checking and SM-BPDS

LTL model checking for self-modifying code is achieved by extending SM-PDS with a Büchi acceptance condition, forming a Self-Modifying Büchi Pushdown System (SM-BPDS) ΔcP×(ΔΔc)×(ΔΔc)×P\Delta_c \subseteq P \times (\Delta\cup\Delta_c)\times(\Delta\cup\Delta_c)\times P5, where ΔcP×(ΔΔc)×(ΔΔc)×P\Delta_c \subseteq P \times (\Delta\cup\Delta_c)\times(\Delta\cup\Delta_c)\times P6 is the set of accepting control points. A run ΔcP×(ΔΔc)×(ΔΔc)×P\Delta_c \subseteq P \times (\Delta\cup\Delta_c)\times(\Delta\cup\Delta_c)\times P7 is accepting if infinitely many ΔcP×(ΔΔc)×(ΔΔc)×P\Delta_c \subseteq P \times (\Delta\cup\Delta_c)\times(\Delta\cup\Delta_c)\times P8 have a control point in ΔcP×(ΔΔc)×(ΔΔc)×P\Delta_c \subseteq P \times (\Delta\cup\Delta_c)\times(\Delta\cup\Delta_c)\times P9.

Given an SM-PDS (p,w,θ)(\langle p, w\rangle, \theta)0 with labeling (p,w,θ)(\langle p, w\rangle, \theta)1 and an LTL formula (p,w,θ)(\langle p, w\rangle, \theta)2 over (p,w,θ)(\langle p, w\rangle, \theta)3, the algorithm computes the synchronous product (p,w,θ)(\langle p, w\rangle, \theta)4, where (p,w,θ)(\langle p, w\rangle, \theta)5 is a Büchi automaton for (p,w,θ)(\langle p, w\rangle, \theta)6. Correctness is established: (p,w,θ)(\langle p, w\rangle, \theta)7 iff (p,w,θ)(\langle p, w\rangle, \theta)8 has an accepting run from (p,w,θ)(\langle p, w\rangle, \theta)9 (Touili et al., 2019).

LTL model checking thus reduces to the emptiness problem for SM-BPDS: Does there exist an accepting run? Deciding emptiness is performed by constructing the head-reachability graph pPp \in P0 over all possible heads pPp \in P1. A head is repeating if pPp \in P2 contains a cycle through it labeled with a pPp \in P3 (visiting pPp \in P4). SAT-based saturation computes labeled pre* automata to add all relevant edges efficiently, with total complexity singly-exponential in pPp \in P5 and polynomial in pPp \in P6. This is in contrast to PDS-translation approaches yielding full state-space blowup and doubly-exponential cost.

4. Implementation Approaches and Toolchain

A direct LTL model checker for SM-PDS has been implemented in OCaml (Touili et al., 2019). The analysis pipeline comprises:

  1. Disassembly of binaries with Jakstab, recovering the control-flow graph and coarse memory/register over-approximation.
  2. Translation of non-self-modifying instructions to pPp \in P7 and self-modifying mov instructions to pPp \in P8, yielding the SM-PDS pPp \in P9.
  3. Formula Compilation: Given an LTL property wΓw \in \Gamma^*0 or a library of malware behavior formulas, the product SM-BPDS wΓw \in \Gamma^*1 is constructed.
  4. Graph Construction: The head-reachability graph wΓw \in \Gamma^*2 is built using repeated labeled wΓw \in \Gamma^*3 computations.
  5. Emptiness/Model Checking: Search for a wΓw \in \Gamma^*4-labeled cycle in wΓw \in \Gamma^*5; if found, wΓw \in \Gamma^*6 holds.

Reachability algorithms for wΓw \in \Gamma^*7 and wΓw \in \Gamma^*8 are also implemented directly, manipulating configurations and phases via P-automata and sparse exploration, thus avoiding construction of the exponentially larger “phase-encoded” classical PDS.

5. Experimental Evaluation and Applications

Benchmarks are reported for both LTL model checking and reachability analysis:

  • Malware Detection: The SM-PDS LTL checker was applied to 892 self-modifying malware samples from VirusShare, MalShare, VX-Heavens, and NGVCK, as well as 19 benign programs with injected self-modifying unpackers and 205 generated NGVCK malwares. Detection properties were encoded as LTL formulas, e.g., for registry injection, data-stealing, or keylogging behaviors.
  • Performance: Direct SM-PDS LTL model checking took seconds to minutes per sample, compared to PDS-translation plus Moped, which timed out (20-minute cutoff) or required hours to days.
  • Detection Rates: The SM-PDS approach achieved 100% detection of 892 self-modifying malware, outperforming commercial static antivirus tools (max. ~68%). For 205 NGVCK samples, completeness was 100% versus 31.2% (BitDefender), 53.1% (Kaspersky), and 82.4% (Symantec).
Tool / Antivirus Detection Rate (%)
SM-PDS LTL Checker 100
BitDefender 31.2
Kaspersky 53.1
Symantec 82.4

Synthetic benchmarks on randomly generated SM-PDSs with up to several thousand rules confirm that direct saturation is 10–1000 times faster and uses far less memory than phase-encoded PDS translation.

6. Illustrative Example

A representative SM-PDS instance is provided (Touili et al., 2019):

  • wΓw \in \Gamma^*9
  • θΔΔc\theta \subseteq \Delta \cup \Delta_c0
  • θΔΔc\theta \subseteq \Delta \cup \Delta_c1
  • θΔΔc\theta \subseteq \Delta \cup \Delta_c2
  • Initial phase θΔΔc\theta \subseteq \Delta \cup \Delta_c3

A forward trace applies θΔΔc\theta \subseteq \Delta \cup \Delta_c4, then θΔΔc\theta \subseteq \Delta \cup \Delta_c5, then θΔΔc\theta \subseteq \Delta \cup \Delta_c6, modifying the phase, thus modeling a changing transition set. This captures dynamic unpacking behavior as found in malicious binaries, which is not representable within standard PDS frameworks.

7. Limitations, Complexity, and Future Directions

The head-reachability graphs and automata manipulations introduce an exponential cost only in the number of distinct rules (θΔΔc\theta \subseteq \Delta \cup \Delta_c7), not the overall program size. Direct saturation avoids the doubly-exponential complexity suffered by PDS translations with phase encoding. In practice, the number of self-modifying rules is small, making these analyses tractable for real-world malware and synthetic cases.

Possible future directions and open problems include:

  • Incorporation of richer modification patterns, such as multi-rule swap operations.
  • Branching-time logics (e.g., CTL) and higher-order stack extensions.
  • Symbolic on-the-fly representations of phases to further reduce the θΔΔc\theta \subseteq \Delta \cup \Delta_c8 state explosion.
  • Theoretical lower bounds for LTL model checking on SM-PDS.
  • Hybridization with dynamic analysis for improved static-dynamic verification capabilities (Touili et al., 2019, Touili et al., 2019).

Self-Modifying Pushdown Systems thus provide a mathematically rigorous, scalable, and practically effective foundation for the static analysis and model checking of self-modifying code, with demonstrated utility for advanced malware detection in automated toolchains.

Definition Search Book Streamline Icon: https://streamlinehq.com
References (2)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Self-Modifying PushDown Systems (SM-PDS).