Listen to this Post

Introduction:
The convergence of Information Technology (IT) and Operational Technology (OT) has reached a critical tipping point. For decades, industrial automation has been locked into proprietary, vendor-specific ecosystems with development environments that lag far behind modern software engineering practices. Autonomy Logic’s open-source STruC++ compiler and its accompanying VSCode extension shatter these constraints by transforming IEC 61131-3 Structured Text (ST) into clean, portable C++17 code. This innovation not only modernizes the PLC programming experience with features like intelligent autocomplete and source-level debugging but also introduces new cybersecurity considerations that demand immediate attention from ICS security professionals.
Learning Objectives:
- Understand the architecture and security implications of compiling ST to C++17 for OPENPLC environments.
- Learn how to simulate, test, and debug STruC++ programs using the VSCode extension’s integrated toolchain.
- Master host firewall and network segmentation configurations to secure industrial PCs running STruC++-compiled logic.
- Identify and mitigate memory corruption vulnerabilities introduced by the C++ translation layer.
- Implement unit testing and continuous integration pipelines for industrial automation code.
You Should Know:
1. Understanding the STruC++ Compiler and OPENPLC Architecture
OPENPLC is an open-source PLC software suite that has gained popularity as a flexible alternative to proprietary offerings from Siemens or Rockwell. Traditional OPENPLC development relies on ladder logic or Structured Text (ST) instructions. Autonomy Logic’s STruC++ acts as a transpiler, allowing developers to write logic in ST while leveraging the power of the C++ ecosystem. The compiler translates ST programs into clean C++17 code that targets the OPENPLC runtime, building for Linux, macOS, Windows, and even microcontrollers.
From a security engineering perspective, this introduces the risk of classic memory corruption vulnerabilities—buffer overflows, use-after-free, and null pointer dereferences—that were exceedingly rare in the constrained, deterministic IEC 61131-3 language environment. When deployed on hardware such as Advantech industrial PCs (IPCs), the code runs on a full operating system (typically Linux or Windows), inheriting all the vulnerabilities of general-purpose OSes.
To inspect the compiler’s output and audit for security issues, you can clone example repositories and analyze the generated intermediate files:
Clone the example repository (hypothetical structure)
git clone https://github.com/Autonomy-Logic/STruCpp-Examples.git
cd STruCpp-Examples/SimpleLogic
Assuming a CMake-based build environment
mkdir build && cd build
cmake .. && make
Locate generated intermediate ST files in the output directory
find . -1ame ".st" -exec cat {} \; > compiled_plc_logic.txt
Audit for unsafe C functions that may have been introduced
grep -1E "strcpy|sprintf|gets|memcpy|strcat" ../source/.cpp
- Setting Up the STruC++ VSCode Extension for Modern PLC Development
The STruC++ VSCode extension brings a modern integrated development environment (IDE) experience to industrial automation. To get started, install the extension from the Visual Studio Marketplace. The extension requires VSCode 1.82 or later, g++ with C++17 support, and either the Microsoft C/C++ extension or CodeLLDB for debugging.
Step‑by‑step installation and configuration:
- Install the extension: Open VSCode, navigate to the Extensions view (Ctrl+Shift+X), search for “STruC++ Structured Text Compiler,” and install it.
-
Configure compiler settings: Open your VSCode settings (Ctrl+,) and search for
strucpp. Key settings include:
– strucpp.outputDirectory: Output directory for generated C++ files (default: ./generated).
– strucpp.gppPath: Path to the g++ compiler (default: g++).
– strucpp.libraryPaths: Additional `.stlib` library search paths.
– strucpp.autoDiscoverLibraries: Auto-discover `.stlib` files in workspace (default: true).
– strucpp.globalConstants: Global constants passed to the compiler.
- Create a new ST file: Create a `.st` file in your workspace. The extension provides full TextMate grammar and semantic token support for Structured Text, including all IEC 61131-3 keywords, types, literals, and operators.
-
Write your first program: Use the bundled IEC standard function block library (TON, TOF, TP, CTU, CTD, R_TRIG, F_TRIG, SR, RS) and the OSCAT Basic library.
Example ST program (simple counter):
PROGRAM Main VAR Counter : CTU; Reset : BOOL := FALSE; Output : INT := 0; END_VAR Counter(CU := TRUE, R := Reset, PV := 10); Output := Counter.CV;
- Compile and build: Use the Command Palette (Ctrl+Shift+1) to access STruC++ commands:
– `STruC++: Compile Current File to C++`
– `STruC++: Compile Workspace to C++`
– `STruC++: Build Executable (REPL)`
– `STruC++: Build and Run REPL`
3. Source-Level Debugging and Variable Inspection
One of the most powerful features of the STruC++ extension is source-level debugging, which brings software engineering debugging practices to PLC programming.
Step‑by‑step debugging guide:
- Set breakpoints: Click in the gutter next to line numbers in your `.st` files to set breakpoints directly in Structured Text source.
-
Launch the debugger: Press F5 to build with debug symbols and launch the debugger. The extension works with GDB (Linux) and LLDB (macOS) via CodeLLDB or the C/C++ extensions.
3. Debugging controls: Use the standard debugging controls:
- Step Over (F10): Execute the current line and move to the next
- Step Into (F11): Step into function or function block calls
- Step Out (Shift+F11): Step out of the current function
-
Variable inspection: Hover over any variable to see its type, scope, and current value. The Variables pane displays IEC-type formatted values.
-
Force and unforce variables: During debug sessions, you can force or unforce variables using the Command Palette commands:
– `STruC++: Force Variable`
– `STruC++: Unforce Variable`
– `STruC++: Unforce All`
4. Unit Testing and Test Explorer Integration
The STruC++ extension integrates unit testing directly into VSCode’s Test Explorer, enabling test-driven development for industrial automation code.
Step‑by‑step testing guide:
- Write test blocks: Use
TEST,ASSERT_, and `MOCK_` blocks in your ST files.
Example test:
TEST CounterTest VAR Counter : CTU; Result : INT; END_VAR Counter(CU := TRUE, R := FALSE, PV := 5); ASSERT_EQ(Counter.CV, 1); Counter(CU := TRUE, R := FALSE, PV := 5); ASSERT_EQ(Counter.CV, 2); END_TEST
- Discover tests: The extension automatically discovers test blocks and displays them in the Test Explorer panel.
-
Run tests: Click the play button in the Test Explorer or use the `STruC++: Run Tests` command. Results appear inline with pass/fail gutter icons and failure annotations at the exact `ASSERT_` line that failed.
-
Watch mode: Enable watch mode for automatic re-running of tests on file changes.
-
View diffs: For `ASSERT_EQ` failures, the extension provides a diff view showing expected vs. actual values.
5. Library Management and Cross-Platform Portability
STruC++ is designed for portability, compiling ST to standard C++17 that builds for Linux, macOS, Windows, and microcontrollers. The extension includes robust library management features.
Step‑by‑step library management:
- Compile libraries: Use the `STruC++: Compile Library (.stlib)` command to compile your projects as `.stlib` library archives.
-
Import existing libraries: The extension can import Codesys v2 or v3 libraries and convert them to STruC++ native `.stlib` format.
-
Library discovery: The extension automatically discovers `.stlib` files in your workspace. The Library Explorer panel in the sidebar provides a visual overview.
-
Configure library paths: Add additional library search paths using the `strucpp.libraryPaths` setting.
-
Use standard libraries: The extension bundles the IEC standard function block library (TON, TOF, TP, CTU, CTD, R_TRIG, F_TRIG, SR, RS) and the OSCAT Basic library.
-
Security Hardening for STruC++ Deployments on Industrial PCs
When deploying STruC++-compiled logic on industrial hardware such as Advantech IPCs running Linux or Windows, additional security measures are essential.
Step‑by‑step security hardening guide:
- Isolate the development environment: Before deploying any STruC++ logic to production, set up a secure development sandbox.
2. Harden the host OS:
- Disable unnecessary services and ports
- Apply the principle of least privilege for user accounts
- Enable comprehensive logging and monitoring
3. Configure host firewall (Linux example using iptables):
Allow only essential ports (e.g., Modbus TCP on 502, OPC UA on 4840) iptables -A INPUT -p tcp --dport 502 -j ACCEPT iptables -A INPUT -p tcp --dport 4840 -j ACCEPT Drop all other incoming traffic iptables -A INPUT -j DROP Save rules iptables-save > /etc/iptables/rules.v4
- Network segmentation: Place industrial control networks behind firewalls with strict access control lists (ACLs). Segment OT networks from IT networks using VLANs or physical separation.
-
Memory protection: Enable ASLR (Address Space Layout Randomization) and DEP (Data Execution Prevention) on the host system:
Linux: Check ASLR status cat /proc/sys/kernel/randomize_va_space 0 = disabled, 1 = partial, 2 = full ASLR echo 2 > /proc/sys/kernel/randomize_va_space
-
Static code analysis: Integrate static analysis tools into your CI pipeline to detect memory corruption vulnerabilities in the generated C++ code:
Using cppcheck for static analysis cppcheck --enable=all --inconclusive --suppress=missingIncludeSystem ./generated/ Using Clang Static Analyzer scan-build make
What Undercode Say:
-
Modernizing industrial automation through open-source innovation: Autonomy Logic’s decision to release STruC++ as open-source (GPL-3.0-or-later) democratizes access to modern PLC development tools that were previously only available internally at major PLC manufacturers. This has the potential to accelerate innovation in the industrial automation sector by lowering the barrier to entry for new developers and enabling community-driven improvements.
-
The security double-edged sword: While STruC++ brings the power of the C++ ecosystem to PLC programming, it also introduces the security risks associated with memory-unsafe languages. Industrial cybersecurity professionals must now contend with buffer overflows, use-after-free vulnerabilities, and other memory corruption issues in control systems that were previously immune to such threats. This shift demands new skills, tools, and processes for securing industrial control systems.
Analysis: The STruC++ compiler represents a fundamental shift in how industrial automation software is developed, tested, and deployed. By bridging the gap between IEC 61131-3 and modern C++ development practices, it enables unit testing, continuous integration, and source-level debugging for PLC programs. However, this modernization comes with significant security implications. The introduction of memory-unsafe code into the OT environment expands the attack surface and requires security teams to adapt their strategies accordingly. Organizations adopting STruC++ must invest in secure coding practices, static analysis tools, and rigorous testing to mitigate the risks of memory corruption vulnerabilities. The open-source nature of the project also means that security researchers can audit the codebase, potentially leading to faster vulnerability discovery and remediation compared to proprietary alternatives. For the industrial automation industry, STruC++ is both an opportunity and a challenge—an opportunity to modernize development practices and a challenge to maintain the safety and reliability that are the hallmarks of industrial control systems.
Prediction:
- +1 The STruC++ project will accelerate the adoption of DevOps practices in industrial automation, leading to faster innovation cycles and more reliable control systems. The ability to write unit tests and implement CI/CD pipelines for PLC code will reduce downtime and improve system quality.
-
+1 The open-source nature of STruC++ will foster a vibrant community of developers and security researchers, leading to rapid identification and remediation of vulnerabilities. This community-driven approach could set a new standard for security in industrial automation.
-
-1 The introduction of memory-unsafe C++ code into OT environments will lead to an increase in security incidents targeting industrial control systems. Organizations that fail to adapt their security practices to address these new risks will be vulnerable to attacks that exploit memory corruption vulnerabilities.
-
-1 The complexity of the STruC++ toolchain may create a skills gap, as traditional PLC programmers lack experience with C++ development and security practices. This could lead to the deployment of insecure code by well-intentioned but undertrained engineers.
-
+1 The portability of STruC++ across Linux, macOS, Windows, and microcontrollers will enable new use cases for industrial automation, including edge computing and IoT applications. This expanded deployment surface will drive innovation in areas such as predictive maintenance and industrial analytics.
-
-1 The reliance on general-purpose operating systems for STruC++ deployments introduces OS-level vulnerabilities that were not previously relevant to PLC environments. Security teams must now patch and secure the underlying OS in addition to the PLC application itself, increasing the operational burden.
▶️ Related Video (76% Match):
https://www.youtube.com/watch?v=3l7xPwUWv5Y
🎯Let’s Practice For Free:
🎓 Live Courses & Certifications:
Join Undercode Academy for Verified Certifications
🚀 Request a Custom Project:
Secure, high-velocity infrastructure and disruptive technological engineering. Contact our engineering team for high-tier development and proprietary systems:
[email protected]
💎 Smart Architecture | 🛡️ Secure by Design | ⭐ Trusted by Thousands
IT/Security Reporter URL:
Reported By: Thiago Alves – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅


