Method for detecting program integrity

By setting identifiers at the beginning and end of the program, dynamic integrity detection during program execution is achieved, solving the problem of real-time monitoring in existing technologies and improving the concealment and reliability of program integrity protection.

CN122432048APending Publication Date: 2026-07-21TIANJIN HUARUIYUAN TECH
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
TIANJIN HUARUIYUAN TECH
Filing Date
2026-05-21
Publication Date
2026-07-21

AI Technical Summary

Technical Problem

Existing program integrity detection methods cannot perform dynamic self-checks during program execution, and existing verification logic is easily bypassed or destroyed, making it impossible to monitor program integrity in real time.

Method used

By setting identifiers at the beginning and end of the program, the program can perform two-way verification by retrieving the first identifier at the end when executing the program from front to back, and then retrieving the second identifier at the beginning after retrieving the tail identifier. This ensures that the program can determine the integrity in real time during execution.

Benefits of technology

It enables dynamic integrity monitoring during program execution, improves the concealment and reliability of program integrity protection, prevents the verification logic from being bypassed or destroyed, and avoids malfunctions and security incidents.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122432048A_ABST
    Figure CN122432048A_ABST
Patent Text Reader

Abstract

The present application relates to the detection of program integrity, and specifically provides a kind of detection method of program integrity, to solve the problem that existing program integrity detection method cannot carry out dynamic self-checking in the process of program execution.To this end, a kind of detection method of program integrity of the present application, program includes head and tail, head is set in front of tail, tail includes first mark, detection method includes: in the process of executing program from front to back, first mark is retrieved from head, and the integrity of program is determined according to whether first mark can be retrieved.The present application judges program integrity in real time according to retrieval result, so that integrity check and program execution are integrated into one;Once the tail of program is missing due to accidental deletion, tampering or jumping, the mark cannot be retrieved when the head is executed, so that the incomplete state can be found in time during program running, and the defect that existing technology can only carry out static check before execution and cannot dynamically monitor program integrity is overcome.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the detection of program integrity, and specifically provides a method for detecting program integrity. Background Technology

[0002] In CNC machining, industrial automation, and various embedded control systems, the integrity of machining or control programs directly affects machining quality and equipment operational safety. During storage, transmission, editing, or long-term use, these programs may become incomplete due to factors such as misoperation, aging storage media, electromagnetic interference, or malicious tampering, leading to the deletion, replacement, insertion, or disordered sequence of program instructions. Taking CNC machining programs as an example, incomplete programs can cause problems such as incorrect toolpaths and coordinate offsets, resulting in workpiece scrap or, in severe cases, machine collisions and other safety accidents.

[0003] Currently, the common approach to detecting program integrity is to perform a comprehensive check before program execution. For example, a Cyclic Redundancy Check (CRC) or message digest (such as MD5, SHA, etc.) for the entire program file is pre-calculated, and then recalculated and compared with the expected value when the program is loaded to determine if the program has been modified. The drawbacks of this method are: it relies on an external check before program execution and cannot dynamically monitor integrity during program execution; once the program has started executing, if external interference causes a program pointer jump or a section of code is unexpectedly skipped, the integrity check mechanism cannot respond in real time and prevent it from being blocked. Furthermore, the checksum requires additional storage and management, and calculating the checksum itself consumes processing time.

[0004] Another approach is to embed self-checking code within the program, such as setting up a check logic in the program header to verify specific identifiers or critical code segments. However, this type of self-checking code is usually concentrated in a fixed location within the program (such as the program entry point), making it easy for analysts to locate, skip, or remove. Once the self-checking code is successfully bypassed, any missing or tampered parts of the program will remain completely undetectable. Furthermore, if the program segment containing the self-checking code is corrupted, the integrity protection mechanism will be completely ineffective.

[0005] Therefore, there is an urgent need in this field for a method to detect program integrity in order to solve the above problems. Summary of the Invention

[0006] The present invention aims to solve the above-mentioned technical problems, namely, to solve the problem that existing program integrity detection methods cannot perform dynamic self-checks during program execution.

[0007] In a first aspect, the present invention provides a method for detecting program integrity, the program including a header and a tail, the header being disposed in front of the tail, the tail including a first identifier, the detection method comprising the following steps: During the execution of the program from front to back, the first identifier is retrieved from the header, and the integrity of the program is determined based on whether the first identifier can be retrieved.

[0008] In a specific implementation of the above detection method, the header includes a first search statement, which is used to retrieve the first identifier.

[0009] In a specific implementation of the above detection method, "determining the integrity of the program based on whether the first identifier can be retrieved" includes the following steps: If the first identifier is not found, the program is stopped and an alarm is triggered.

[0010] In a specific embodiment of the above detection method, the program further includes a main body disposed between the head and the tail, the head including a second identifier, and the detection method further includes the following steps: When the first identifier is retrieved, the second identifier is retrieved, and the integrity of the program is determined based on whether the second identifier can be retrieved.

[0011] In a specific implementation of the above detection method, the tail includes a second search statement, which is used to search for the second identifier, and the second search statement is set after the first identifier.

[0012] In a specific implementation of the above detection method, the second identifier is positioned in front of the main body. "Determining the integrity of the program based on whether the second identifier can be retrieved" includes the following steps: If the second identifier is not found, the program is stopped and an alarm is triggered.

[0013] In a specific implementation of the above detection method, the second identifier is positioned in front of the main body, and the process of "determining the integrity of the program based on whether the second identifier can be retrieved" further includes the following steps: When the second identifier is retrieved, the main body continues to be executed.

[0014] By adopting the above technical solution, the present invention actively retrieves the first identifier set at the end of the program from the program header during normal program execution, and judges the program integrity in real time based on the retrieval results, thus integrating integrity verification with program execution. Once the program tail is missing due to accidental deletion, tampering, or jump, the identifier will not be retrieved during the execution of the header, thereby enabling timely detection of incomplete states during program operation. This overcomes the shortcomings of existing technologies that can only perform static verification before execution and cannot dynamically monitor program integrity. At the same time, because the verification logic and the identifier are placed at the beginning and end of the program respectively, they are not easily located or skipped at once, significantly improving the concealment and reliability of program integrity protection.

[0015] Furthermore, by setting a second identifier at the beginning of the program and adding a step to retrieve the second identifier after successfully retrieving the first identifier at the end, the present invention achieves bidirectional mutual verification between the beginning and end of the program: the program is determined to be complete only when both the tail identifier and the head identifier are intact, which effectively avoids the possibility of missed detections that may occur in unidirectional verification and improves the comprehensiveness and anti-bypass capability of program integrity detection.

[0016] Furthermore, the present invention places the second identifier in front of the main program body and sets the execution of the main body only after the second identifier is retrieved, thereby forcing the above verification to be completed before entering the core function, forming a "verify first, execute later" security barrier, effectively preventing malfunctions or security accidents caused by the execution of the main body despite the verification failing, and improving the reliability and security of program operation. Attached Figure Description

[0017] The preferred embodiments of the present invention are described below with reference to the accompanying drawings, in which: Figure 1 This is a code example diagram of the program header in the embodiments provided by the present invention; Figure 2 This is a code example diagram of the program tail in the embodiments provided by the present invention. Detailed Implementation

[0018] Preferred embodiments of the present invention will now be described with reference to the accompanying drawings. Those skilled in the art should understand that these embodiments are merely illustrative of the technical principles of the present invention and are not intended to limit the scope of protection of the present invention.

[0019] It should be noted that in the description of this invention, terms such as "upper," "lower," "left," "right," "inner," and "outer," indicating directional or positional relationships, are based on the directional or positional relationships shown in the accompanying drawings. These are merely for ease of description and do not indicate or imply that the device or element must have a specific orientation, or be constructed and operated in a specific orientation; therefore, they should not be construed as limitations on this invention. Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.

[0020] Furthermore, it should be noted that, in the description of this invention, unless otherwise explicitly specified and limited, the terms "installation," "setting," and "connection" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a direct connection, an indirect connection through an intermediate medium, or a connection within two components. Those skilled in the art can understand the specific meaning of the above terms in this invention according to the specific circumstances.

[0021] To address the limitation of existing program integrity detection methods in failing to perform dynamic self-checks during program execution, this embodiment discloses a program integrity detection method. The program includes a program header, a program body, and a program tail. The program header is positioned before the program body, and the program body is positioned before the program tail. The program is executed sequentially from beginning to end during execution.

[0022] The program header includes a first search statement and a second identifier, with the first search statement preceding the second identifier. The program footer includes a first identifier and a second search statement, with the first identifier preceding the second search statement. The first search statement is used to search for the first identifier, and the second search statement is used to search for the second identifier.

[0023] The detection method includes the following steps: During program execution, when the first search statement is executed, the program searches for the first identifier. If the first identifier is found, execution proceeds from the first identifier onwards. If the first identifier is not found, an alarm is triggered.

[0024] After the first identifier is found, execution proceeds from the first identifier; after the second search statement is executed, the second identifier is searched in the program; if the second identifier is found, execution proceeds from the second identifier; if the second identifier is not found, an alarm is triggered.

[0025] The following example illustrates the specific implementation of this program: Reference Figure 1 The program header includes the following code: 5 FN 9: IF +1 EQU +1 GOTO LBL “TEST” 6 LBL “BEGIN” Line 5 contains the first search query, used to retrieve the first identifier, "TEST". Line 6 contains the second identifier, "BEGIN".

[0026] Reference Figure 2 The program ends with the following code: 102 LBL “TEST” 103 FN 9: IF +1 EQU +1 GOTO LBL “BEGIN” Line 102 is the first identifier. Line 103 is the second search statement, used to retrieve the second identifier.

[0027] The technical solution of the present invention has been described above with reference to the preferred embodiments shown in the accompanying drawings. However, it will be readily understood by those skilled in the art that the scope of protection of the present invention is obviously not limited to these specific embodiments. Without departing from the principles of the present invention, those skilled in the art can make equivalent changes or substitutions to the relevant technical features, and the technical solutions after such changes or substitutions will all fall within the scope of protection of the present invention.

Claims

1. A method for detecting program integrity, characterized in that, The program includes a head and a tail, the head being positioned in front of the tail, and the tail including a first identifier. The detection method includes the following steps: During the execution of the program from front to back, the first identifier is retrieved from the header, and the integrity of the program is determined based on whether the first identifier can be retrieved.

2. The detection method according to claim 1, characterized in that, The header includes a first search statement, which is used to retrieve the first identifier.

3. The detection method according to claim 1, characterized in that, "Determining the integrity of the program based on whether the first identifier can be retrieved" includes the following steps: If the first identifier is not found, the program is stopped and an alarm is triggered.

4. The detection method according to claim 1, characterized in that, The program further includes a main body disposed between the head and the tail, the head including a second identifier, and the detection method further includes the following steps: When the first identifier is retrieved, the second identifier is retrieved, and the integrity of the program is determined based on whether the second identifier can be retrieved.

5. The detection method according to claim 4, characterized in that, The tail section includes a second search statement, which is used to search for the second identifier. The second search statement is located after the first identifier.

6. The detection method according to claim 4, characterized in that, The second identifier is positioned in front of the main body. "Determining the integrity of the program based on whether the second identifier can be retrieved" includes the following steps: If the second identifier is not found, the program is stopped and an alarm is triggered.

7. The detection method according to claim 6, characterized in that, The second identifier is positioned in front of the main body. "Determining the integrity of the program based on whether the second identifier can be retrieved" further includes the following steps: When the second identifier is retrieved, the main body continues to be executed.