AI
AI Recovers Lost PLC Code from Sensor Logs, Outperforming Classical Approaches
A new technique uses LLMs to reconstruct executable industrial control programs from input/output traces alone, with built-in verification to catch gaps.
When industrial control systems age, their source code often vanishes—but their sensor logs remain. A new study shows that large language models can reverse-engineer missing PLC (programmable logic controller) programs from these records, something classical software reconstruction methods struggle to do reliably.
The Problem: Code Loss in Critical Infrastructure#
Programmable logic controllers run power plants, water treatment facilities, and manufacturing lines worldwide. Many of these systems have operated for decades, and their original source code in Structured Text (ST), the IEC 61131-3 standard, is frequently lost or inaccessible. Yet every input signal and actuator command is logged continuously, creating a detailed record of what the program did—if not why it did it.
A Generate-Verify Approach#
Researchers built a generate-replay-feedback pipeline that sidesteps traditional code recovery challenges. An LLM first examines a compressed summary of the recorded trace and writes a candidate program without ever seeing the original. The key innovation lies in verification: the candidate runs one control cycle at a time against the actual log, and whenever output diverges from the recording, that mismatch is fed back to the LLM for revision (up to three attempts). This tight coupling between generation and evidence ensures the recovered code reflects what actually happened.
Real-World Results#
Testing on 47 third-party programs from public benchmarks:
- 43 cases reproduced the recorded trace perfectly
- 94% agreement with the original program on unseen test inputs
- Remaining errors clustered in untested program branches
When researchers added traces that exercised those gaps, agreement on adversarial inputs jumped from 80% to 98%. In contrast, a classical automata-learning baseline—which learns state machines without language models—fit the recorded data but collapsed to 40% accuracy on new inputs, underscoring that recovering program structure, not just replay, is the hard part.
On real data from a public water-treatment facility, the reconstructed control logic matched unseen sensor measurements with an $R^2 > 0.99$ and flagged an actuator attack in the dataset.

