Tamper-Proofing with Self-Modifying Code
Gregory Morse [email protected], Tamás Kozsik [email protected] · 2026
Read Tamper-Proofing with Self-Modifying Code by Gregory Morse [email protected], Tamás Kozsik [email protected] (2026) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2604-12407.txt.
Introduction
Gregory Morse and Tamás Kozsik argue that self-modifying code can serve as tamper protection. Such programs rewrite their own instructions while running. Theory says non-modifying code can simulate them on an idealized machine. Real processors add timing, ordering, and hardware state as observables. A faithful fake then grows detectably costly, the authors argue. Their model joins introspective and shape-shifting code with reliable clocks and timing checks. Careful engineering keeps overhead low while preserving detection.
Catalog record
| CREATOR | Gregory Morse [email protected], Tamás Kozsik [email protected] |
|---|---|
| YEAR | 2026 |
| COLLECTION | PAPERS |
| FORMAT | TXT |
| FILE SIZE | 32127 |
| LICENSE | http://creativecommons.org/licenses/by/4.0/ |
| RIGHTS | CC BY |
| SOURCE | arXiv |
Source: https://arxiv.org/abs/2604.12407
Browse the full library · About the Tower of Babel
Full text
The opening of the work, from the library's hosted text:
Tamper-Proofing with Self-Modifying Code Gregory Morse [email protected], Tamás Kozsik [email protected] Abstract Classical computability theory tells us that self-modifying code (SMC) on a deterministic universal Turing machine can be simulated by non-SMC code on the same model. That abstraction, however, omits the external timing inputs, concurrency, and microarchitectural state that dominate practical execution on modern processors. We argue that once timing, ordering, and self-introspective effects are treated as observables, a practically faithful non-SMC reproduction of timed SMC becomes detectably expensive on commodity systems. We present a tamper-proofing model that combines introspective and polymorphic SMC, reliable clocks, and runtime timing predicates to bind integrity checks to execution behavior. We distinguish static and dynamic SMC generation, characterize the timing semantics needed to avoid catastrophic pipeline clears, and give x86-64 design primitives for checksum-driven self-patching. We also report timer measurements, performance comparisons, and performance-monitoring counter evidence showing that careful engineering—especially loop unrolling and cross-page modification—substantially reduces the overhead of SMC while preserving its tamper-detection value. The paper concludes with an efficiency analysis, a threat model, and deployment guidance for trusted code executing in untrusted environments. Keywords: x86, x86-64, assembly language, self-modifying code, software protection, tamper-proofing, integrity checking, runtime verification 1 Introduction It is classical in computability theory that self-modifying code (SMC) on a deterministic universal Turing machine (UTM) can be simulated by non-SMC code on the same model; SMC does not increase computational power beyond Turing completeness, but rather changes representation and potentially efficiency [ 10 , 8 , 2 ] . That baseline, however, abstracts away external inputs . In practice, time sources such as Coordinated Universal Time (UTC) and processor time-stamp counters (TSCs), together with concurrent scheduling, introduce nondeterminism: even if a TSC were made deterministic, UTC would not be; in parallel settings, TSC readings are further complicated by cache and memory synchronization. Once such inputs are admitted as observables, the equivalence of SMC to non-SMC becomes fragile in a tamper-proofing context. Functional behavior can still be simulated in principle, but preserving timing , ordering , and self-introspective effects in the presence of an adversary generally cannot be achieved without either reintroducing self-modification or incurring detectable distortions. External inputs: what helps, what does not. Many machine and system identifiers—CPU ID strings, NIC MAC addresses, disk/RAM configurations, or operating-system fingerprints—are useful for binding a license to a host [ 13 ] , but they solve fingerprinting more directly than tamper-proofing and are operationally brittle. System-activity signals such as mouse movement or event logs either feed entropy pools [ 9 ] or exhibit regularity that attackers can mimic. Cloud- or server-provided data can be incorporated as an external input, but replay and protocol attacks complicate correctness unless additional machinery is deployed; moreover, such channels do not protect code at the machine-architecture level against manual debugging, thread injection, or remote process-memory writes. A well-engineered network time source can, however, be a reliable UTC input. Practical stance. For integrity checks that bind behavior to time, there is effectively no practically faithful non-SMC equivalent that preserves both semantics and timing in the face of an adversary on contemporary systems. An attacker could attempt to simulate execution under a synthetic time source and adapt the predicate accordingly, but this requires a deterministic, fully characterizable timing model. Modern commodity processors do not satisfy this assumption. Execution timing is influenced by partially undocumented microarchitectural state—branch predictors, caches, coherence protocols, speculative execution, microcode—together with concurrent activity and operating-system scheduling. Reproducing these effects within tight timing tolerances would require a faithful simulation of both the processor and the operating system, including their dynamic state, and doing so at practical speed is infeasible. Model. We propose a tamper-proofing model in which SMC is (i) introspective , in that it checksums its own code, and (ii) polymorphic , in that it rewrites itself while executing. The model uses constant-time algorithmic kernels to reduce unrelated timing leakage and may treat sensitive data as code (SMC-backed storage) to harden against data-only faults. A virtualized SMC wrapper can dynamically generate an inner SMC layer. Formally, we assume a timer T(t) chosen per query t for reliability and a checksum function C(c) over code or data c ; the predicate P(T,C) returns true if and only if the protected code remains unmodified. Relation to prior work. Tamper-proofing via watermarking is well studied [ 5 ] . Self-check- summing with SMC has also been explored [ 7 ] , but typically with static checksum routines rather than checksum kernels that rewrite themselves while executing. Remote runtime-integrity schemes can rely on a verifier in the cloud [ 11 ] ; our goal is to avoid such infrastructure and keep the assurance mechanism local to the untrusted host. This inverts the conventional “trustworthy computing” perspective, which usually assumes a trusted host running untrusted software. Our setting instead asks how trusted software can retain integrity on an untrusted host, which is the operationally harder direction. Contributions. The paper makes four concrete contributions. • It frames timed, introspective SMC as a practical tamper-proofing primitive whose non-SMC reproduction is detectably costly on modern systems. • It develops a structured engineering model covering reliable clocks, timing semantics, static versus dynamic generation, and concrete x86-64 design primitives. • It reports empirical timing and performance-counter results that explain when SMC is impractical and when it becomes efficient enough to deploy. • It states explicit efficiency and security assumptions so that the scope and limitations of the approach are clear. Figure 1 gives a high-level overview of the resulting design. Figure 1: Design overview of checksum units and state verification. The remainder of the paper proceeds as follows. Section 2 evaluates practical time sources. Section 3 contrasts static and dynamic SMC generation. Section 4 formalizes the timing semantics relevant to detection. Sections 5 and 6 present static and dynamic design primitives. Section 7 reports measured performance. Section 8 interprets the cost model. Section 9 shows how the primitives compose into a deployment scheme. Section 10 states the threat model and assumptions, and Section 11 concludes. 2 Reliable clocks The read TSC instructions RDTSC and RDTSCP are not perfectly reliable in isolation because modern processors expose hyper-threading, out-of-order execution, speculative execution, and cache effects that can perturb measurements [ 14 ] . Nevertheless, they can be made reliable enough statistically by repeated execution and by surrounding them with serialization instructions such as CPUID and RDTSCP . In many tamper-proofing contexts, a high-probability integrity decision is sufficient to continue execution. Most contemporary systems also expose several other clocks. High Precision Event Timer (HPET), real-time clock (RTC) facilities, and operating-system monotonic counters provide alternative timing sources with different resolution and noise profiles. The specific x86 instructions discussed here are not unique in spirit: AVR32, SPARC V9, PowerPC, ARMv7, and ARMv8 all provide related counter-style instructions, underscoring the near universality of hardware time measurement. For x86 time-stamp counters, the instructions RDTSC and RDTSCP have the corresponding intrinsics __rdtsc and __rdtscp , which are readily usable from user mode. On many systems they offer the most fine-grained timing information available to ordinary software. On Windows, several Application Programming Interface (API) calls expose timer state. UTC can be queried with GetSystemTimePreciseAsFileTime . The high-resolution performance counter is obtained with QueryPerformanceCounter and calibrated with QueryPerformanceFrequency