Self-Modifying Code Detection and Exception Handling in Binary Execution
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Existing technologies fail to efficiently recover from states where self-modifying code (SMC) modifies parts of binary code, rendering converted code unusable, leading to performance issues during recovery processing.
Innovation Solution
A device and method that includes a detection unit to identify SMC modifications, a specifying unit to identify corresponding parts in converted binary code, and a correction unit to cause exceptions in specific threads executing those parts, allowing for controlled execution of the original code by replacing instructions with interrupt instructions and separating links to maintain page protection.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Productivity
If the converted binary code is executed, then execution efficiency is improved, but the code becomes unusable when self-modifying code modifies it
Solution Approach 1:
The binary code is divided into multiple pages with different protection attributes. The detection unit monitors modifications on a per-page basis, allowing the system to identify and handle self-modifying code at the page level rather than affecting the entire binary code, thus maintaining reliability while preserving execution efficiency of unaffected portions.
Solution Approach 2:
The system performs preliminary conversion of the original binary code to optimized binary code before execution. This preliminary action prepares the code for efficient execution while the detection unit is already in place to handle potential self-modification issues, ensuring that the optimized code can be executed efficiently without compromising reliability.
2Stability of the object's composition
If global synchronization is performed to handle self-modifying code, then code consistency is maintained, but processing performance deteriorates
Solution Approach 1:
Instead of performing global synchronization across all threads and code pages, the system applies page protection attributes and exception handling on a per-page basis. When self-modifying code is detected in a specific page, only that page is marked for exception handling, allowing other pages and threads to continue executing without interruption, thus maintaining code consistency locally while preserving overall processing performance.
Solution Approach 2:
The binary code is segmented into multiple pages with independent protection attributes. This segmentation allows the system to handle self-modifying code on a fine-grained page level rather than requiring global synchronization, thereby maintaining code consistency in affected areas while avoiding performance degradation from system-wide synchronization.
3Speed
If the converted binary code is used, then execution speed is improved, but infinite waiting states occur during recovery processing
Solution Approach 1:
The system performs preliminary conversion of the original binary code to optimized binary code and sets up page protection attributes before execution. This preliminary preparation ensures that the optimized code can execute at high speed while the detection and exception handling mechanisms are already in place to prevent infinite waiting states during recovery processing.
Solution Approach 2:
The detection unit continuously monitors for self-modifying code and provides feedback to the exception handling mechanism. When modification is detected, the system immediately marks the affected page for exception handling, providing real-time feedback that prevents infinite waiting states and ensures stable recovery processing while maintaining high execution speed for unaffected code.
Data Source
AI summary
An apparatus for controlling an execution of a binary code by multiple threads includes a detection unit configured to detect an occurrence of modification of a first part that is a part of a first binary code by a self-modifying code; a specifying unit configured to specify a second part that is a part corresponding to the first part in a second binary code acquired by converting the first binary code, in response to detection of the occurrence of modification of the first part by the self-modifying code; and a correction unit configured to correct the second part such that a specific thread that executes the second part of the second binary code among the multiple threads causes an exception.


