Cross-platform code anomaly vulnerability detection method, system, equipment, medium and product

By converting software code into an LLVM intermediate representation and using the structural information of abstract syntax trees, control flow graphs and data flow graphs to perform multi-layer feature encoding, the problems of inaccurate code vulnerability identification and poor cross-platform adaptability in the existing technology are solved. Achieved higher accuracy and generalization ability.

CN118246033BActive Publication Date: 2024-08-23SHANDONG UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410666177.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-05-28
Publication Date
2024-08-23
Estimated Expiration
2044-05-28

AI Technical Summary

Technical Problem

Existing code vulnerability detection methods rely on manual expertise and a large amount of labeled data, and deep learning methods only use single structural information of the code, resulting in inaccurate identification, poor generalization ability, and difficulty in adapting to cross-platform software code identification.

Method used

Convert binary, assembly language and other software codes into LLVM intermediate representation, use the structural information of abstract syntax trees, control flow graphs and data flow graphs to perform multi-layer feature encoding, and combine the intermediate representation for vulnerability detection to improve accuracy.

Benefits of technology

It realizes the unified format conversion of cross-platform software codes and the utilization of rich structural information, and improves the accuracy and generalization ability of code vulnerability identification.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118246033B
    Figure CN118246033B
Patent Text Reader

Abstract

The cross-platform code anomaly vulnerability detection method, system, device, medium and product disclosed in the present invention belong to the technical field of code vulnerability identification, and generate an intermediate representation, an abstract syntax tree, a control flow graph and a data flow graph of the code; perform multi-layer feature encoding on the adjacency matrix of the abstract syntax tree, the control flow graph and the data flow graph through a multi-layer coding layer to obtain the structural features of the abstract syntax tree, the control flow graph and the data flow graph, wherein each coding layer takes the intermediate representation and the output of the previous layer as input, calculates the self-attention of the structural information of the input abstract syntax tree, the control flow graph and the data flow graph, and the shared attention between the structural information of the input abstract syntax tree, the control flow graph and the data flow graph and the intermediate representation, adds each self-attention to the shared attention, and obtains the output of the current coding layer; obtains the vulnerability detection result of the software code according to each structural feature and the intermediate representation, and improves the accuracy of code vulnerability identification.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of code vulnerability detection, and in particular to a cross-platform code abnormality vulnerability detection method, system, device, medium and product. Background Art

[0002] The statements in this section merely provide background information related to the present invention and do not necessarily constitute prior art.

[0003] Code vulnerabilities are a major threat to software-related industries. Current methods for identifying code vulnerabilities mainly include: static analysis, dynamic analysis, machine learning methods based on hand-crafted features, deep learning methods such as LSTM and GGNN (Gated Graph Neural Network), and methods for identifying source code vulnerabilities using pre-trained models for source code such as Codebert and CodeT5.

[0004] The inventors believe that when code vulnerability identification is performed through static analysis, dynamic analysis, and machine learning methods based on hand-crafted features, professional knowledge related to the vulnerabilities and a large amount of manual labor are required, which is difficult to deploy and has poor scalability. The method of identifying code vulnerabilities using deep learning technologies such as LSTM and GGRN requires a large amount of labeled data for supervised training, and the method of identifying code vulnerabilities using deep learning technologies such as LSTM and GGRN and the method of identifying source code vulnerabilities using a pre-trained model for source code only use the single structural information of the code when identifying code vulnerabilities, but ignore the rich structural information of the code, which makes the code vulnerability identification inaccurate.

[0005] In addition, software codes for different platforms exist in multiple forms such as binary, assembly language, C language, etc., and the current vulnerability detection model using deep learning methods relies on the input format, has poor generalization ability, and is not suitable for cross-platform software code recognition. Summary of the invention

[0006] In order to solve the above problems, the present invention proposes a cross-platform code anomaly vulnerability detection method, system, device, medium and product, which improves the accuracy of code vulnerability identification by converting software codes in various forms such as binary, assembly language, C language, etc. into a unified LLVM intermediate representation, and using the intermediate representation, abstract syntax, control flow and data flow structure information of the code to identify code vulnerabilities.

[0007] To achieve the above object, the present invention adopts the following technical solution:

[0008] First, a cross-platform code anomaly vulnerability detection method is proposed, including:

[0009] Get the platform software code;

[0010] converting platform software code into an intermediate representation of that code;

[0011] Generate the code's abstract syntax tree, control flow graph, and data flow graph using the code's intermediate representation;

[0012] Get adjacency matrices of abstract syntax trees, control flow graphs, and data flow graphs;

[0013] Multi-layer feature encoding is performed on the adjacency matrix and intermediate representation of the abstract syntax tree, control flow graph and data flow graph through multi-layer coding layers to obtain the structural features of the abstract syntax tree, control flow graph and data flow graph; wherein each coding layer takes the intermediate representation and the structural information of the abstract syntax tree, control flow graph and data flow graph output by the previous coding layer as input, calculates the self-attention of the structural information of the abstract syntax tree, control flow graph and data flow graph input to this layer, and the shared attention between the structural information of the abstract syntax tree, control flow graph and data flow graph input to this layer and the intermediate representation, adds the self-attention of the structural information of the abstract syntax tree, control flow graph and data flow graph to the shared attention, and obtains the structural information of the abstract syntax tree, control flow graph and data flow graph output by the coding layer of this layer;

[0014] According to the structural characteristics of the abstract syntax tree, control flow graph and data flow graph and the intermediate representation of the code, the vulnerability detection results of the software code are obtained.

[0015] Furthermore, the structural information of the abstract syntax tree, control flow graph, and data flow graph and the shared attention between the intermediate representations are calculated through a global attention mechanism.

[0016] Furthermore, the input of the first encoding layer is the adjacency matrix and intermediate representation of the abstract syntax tree, control flow graph and data flow graph; the structural information of the abstract syntax tree, control flow graph and data flow graph output by the last encoding layer is the structural features of the abstract syntax tree, control flow graph and data flow graph.

[0017] Furthermore, the trained code vulnerability detection model is used to identify the structural features of the abstract syntax tree, control flow graph, data flow graph and the intermediate representation of the code to obtain the vulnerability detection results of the software code. The code vulnerability detection model takes the fusion features of the code as input and the vulnerability detection results of the software code as output, and is obtained by constructing a comparative learning model.

[0018] Furthermore, the loss functions of the code vulnerability detection model include cross entropy loss, structural feature matching loss of abstract syntax tree, structural feature matching loss of control flow graph, and structural feature matching loss of data flow graph.

[0019] Secondly, a cross-platform code anomaly vulnerability detection system is proposed, including:

[0020] An acquisition unit, used for acquiring platform software code;

[0021] A processing unit is used to convert the platform software code into an intermediate representation of the code; generate an abstract syntax tree, a control flow graph, and a data flow graph of the code using the intermediate representation of the code; obtain the adjacency matrix of the abstract syntax tree, the control flow graph, and the data flow graph; perform multi-layer feature encoding on the adjacency matrix of the abstract syntax tree, the control flow graph, and the data flow graph through a multi-layer encoding layer to obtain the structural features of the abstract syntax tree, the control flow graph, and the data flow graph, wherein each encoding layer takes the intermediate representation and the structural information of the abstract syntax tree, the control flow graph, and the data flow graph output by the previous layer as input, and calculates the structure of the input abstract syntax tree, control flow graph, and data flow graph. The self-attention of each structural information, and the shared attention between the structural information and intermediate representations of the input abstract syntax tree, control flow graph and data flow graph, the self-attention of the structural information of the abstract syntax tree, control flow graph and data flow graph are added to the shared attention to obtain the structural information of the abstract syntax tree, control flow graph and data flow graph output by the encoding layer of this layer; according to the structural characteristics of the abstract syntax tree, control flow graph and data flow graph and the intermediate representation of the code, the vulnerability detection result of the software code is obtained. According to the structural characteristics of the abstract syntax tree, control flow graph and data flow graph and the intermediate representation of the code, the vulnerability detection result of the software code is obtained.

[0022] Furthermore, the processing unit is used for the first coding layer whose input is the adjacency matrix and intermediate representation of the abstract syntax tree, control flow graph and data flow graph; the structural information of the abstract syntax tree, control flow graph and data flow graph output by the last coding layer is the structural features of the abstract syntax tree, control flow graph and data flow graph.

[0023] In a third aspect, an electronic device is proposed, comprising a memory and a processor, and computer instructions stored in the memory and executed on the processor, wherein when the computer instructions are executed by the processor, the steps described in the cross-platform code anomaly vulnerability detection method are completed.

[0024] In a fourth aspect, a computer-readable storage medium is proposed for storing computer instructions. When the computer instructions are executed by a processor, the steps described in the cross-platform code anomaly vulnerability detection method are completed.

[0025] In a fifth aspect, a computer program product is proposed, which includes a computer program. When the computer program is executed by a processor, the cross-platform code anomaly vulnerability detection method proposed in the first aspect is implemented.

[0026] Compared with the prior art, the present invention has the following beneficial effects:

[0027] 1. The present invention converts software code into an intermediate representation, realizes the conversion of software code in different states, modes, and platforms into a unified format, and then performs vulnerability detection on the software code based on the intermediate representation, thereby being able to perform vulnerability detection on software code in different states, modes, and platforms, thereby improving the generalization capability of cross-platform software code vulnerability detection.

[0028] 2. The present invention performs multi-layer feature encoding on the adjacency matrix of the abstract syntax tree, control flow graph and data flow graph through multiple coding layers to obtain the structural features of the abstract syntax tree, control flow graph and data flow graph, wherein each coding layer takes the intermediate representation and the structural information of the abstract syntax tree, control flow graph and data flow graph output by the previous layer as input, calculates the self-attention of the structural information of the input abstract syntax tree, control flow graph and data flow graph, and the shared attention between the structural information of the input abstract syntax tree, control flow graph and data flow graph and the intermediate representation, adds the self-attention of the structural information of the abstract syntax tree, control flow graph and data flow graph to the shared attention, and obtains the structural information of the abstract syntax tree, control flow graph and data flow graph output by the current coding layer; that is, when extracting the structural features of the abstract syntax tree, control flow graph and data flow graph, the association between the intermediate representation, abstract syntax tree, control flow graph and data flow graph of the software is fully considered, so that the extracted structural features can contain more features, and when the structural features are used to identify software vulnerabilities, the accuracy of software vulnerability identification is improved.

[0029] 3. When identifying software code vulnerabilities, the present invention not only applies the structural features of the abstract syntax tree, control flow graph and data flow graph of the application code, but also fully considers the intermediate representation of the code, that is, it also utilizes the rich structural information contained in the code itself, further improving the accuracy of code vulnerability identification.

[0030] Advantages of additional aspects of the present invention will be given in part in the following description, and in part will become obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] The drawings in the specification, which constitute a part of the present application, are used to provide further understanding of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute improper limitations on the present application.

[0032] Figure 1 is a flow chart of the method disclosed in Example 1;

[0033] Figure 2 The CFG disclosed in Example 1;

[0034] Figure 3 The AST disclosed in Example 1;

[0035] Figure 4 DFG disclosed in Example 1;

[0036] Figure 5 This is a schematic diagram of comparative learning disclosed in Example 1. DETAILED DESCRIPTION

[0037] The present invention will be further described below in conjunction with the accompanying drawings and embodiments.

[0038] It should be noted that the following detailed descriptions are illustrative and are intended to provide further explanation of the present application. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present application belongs.

[0039] Example 1

[0040] In this embodiment, a cross-platform code abnormality vulnerability detection method is disclosed, such as Figure 1-Figure 5 As shown, including:

[0041] S1: Get the platform software code.

[0042] S2: Convert the platform software code into an intermediate representation of the code; use the intermediate representation of the code to generate the abstract syntax tree (AST), control flow graph (CFG) and data flow graph (DFG) of the code.

[0043] The software code can be in various forms such as binary, assembly language, and C language. In order to adapt to the recognition of software codes in different states, modes, or platforms, this embodiment first converts the acquired software code into an intermediate representation of LLVM, and then generates an abstract syntax tree, a control flow graph, and a data flow graph of the code based on the intermediate representation of the code.

[0044] Software code contains multiple program statements. The control flow graph (CFG) is a graphical representation of the path traversed during the execution of the software code. The abstract syntax tree (AST) represents the syntax structure of the software code in a tree structure. Each subtree in the AST represents each statement in the software code. The data flow graph (DFG) is a graphical representation that tracks the use of variables during the execution of the software code, including access or modification of variables.

[0045] This embodiment uses a code structure graph generation model to parse the intermediate representation of the code and generate an abstract syntax tree (AST), a control flow graph (CFG), and a data flow graph (DFG) of the code.

[0046] Among them, the code structure diagram generation model can use Tree-sitter.

[0047] Int func(int a){

[0048] int b=5;

[0049] if(a>3){

[0050] b=ab;

[0051] }

[0052] return b;

[0053] } code as an example, when the code executes the "if(a>3)" statement, it decides whether to execute "b=ab" based on the variable "a", and the variable "a" in "b=ab" comes from "a>3", the generated control flow graph (CFG), abstract syntax tree (AST) and data flow graph (DFG) are as follows: Figure 2 , Figure 3 , Figure 4 shown.

[0054] S3: Get the adjacency matrix of the abstract syntax tree, control flow graph, and data flow graph;

[0055] Multi-layer feature encoding is performed on the adjacency matrix and intermediate representation of the abstract syntax tree, control flow graph and data flow graph through multiple coding layers to obtain the structural features of the abstract syntax tree, control flow graph and data flow graph; wherein each coding layer takes the intermediate representation and the structural information of the abstract syntax tree, control flow graph and data flow graph output by the previous coding layer as input, calculates the self-attention of the structural information of the abstract syntax tree, control flow graph and data flow graph input to this layer, and the shared attention between the structural information of the abstract syntax tree, control flow graph and data flow graph input to this layer and the intermediate representation, adds the self-attention of the structural information of the abstract syntax tree, control flow graph and data flow graph to the shared attention, and obtains the structural information of the abstract syntax tree, control flow graph and data flow graph output by the current coding layer.

[0056] Among them, the structural information of the abstract syntax tree, control flow graph and data flow graph and the shared attention between the intermediate representations are calculated through the global attention mechanism.

[0057] The input of the first encoding layer is the adjacency matrix and intermediate representation of the abstract syntax tree, control flow graph and data flow graph; the structural information of the abstract syntax tree, control flow graph and data flow graph output by the last encoding layer is the structural features of the abstract syntax tree, control flow graph and data flow graph.

[0058] Specifically, in the abstract syntax tree, control flow graph, and data flow graph, each node represents a program statement of a code, and each edge represents the association relationship between two nodes, using the element M in the adjacency matrix M nxnTo represent a certain type of edge in an abstract syntax tree, control flow graph, or data flow graph, where n is the number of nodes. Specifically, in the adjacency matrix, 1 is used to indicate that there is an edge between two nodes, and 0 is used to indicate that there is no edge between two nodes.

[0059] For example, when the i-th node and the j-th node are connected in an abstract syntax tree, control flow graph, or data flow graph, set M ixj =1, otherwise, M ixj =0.

[0060] In this embodiment, multi-layer feature encoding is performed on the adjacency matrix of the abstract syntax tree, the control flow graph, and the data flow graph through multiple layers of coding layers to obtain the structural features of the abstract syntax tree, the control flow graph, and the data flow graph. Specifically, the input of the first coding layer is the intermediate representation and the structural features of the abstract syntax tree, the control flow graph, and the data flow graph; each coding layer outputs the structural information of the abstract syntax tree, the control flow graph, and the data flow graph, and inputs the structural information of the abstract syntax tree, the control flow graph, and the data flow graph output by the current coding layer to the next coding layer; the structural information of the abstract syntax tree, the control flow graph, and the data flow graph output by the last coding layer is the structural features of the abstract syntax tree, the control flow graph, and the data flow graph; each coding layer outputs the structural information of the abstract syntax tree, the control flow graph, and the data flow graph. The process of outputting the structural information of the abstract syntax tree, control flow graph and data flow graph of the coding layer is as follows: the self-attention is calculated for the structural information of the abstract syntax tree, control flow graph and data flow graph input to the coding layer of this layer respectively, and the self-attention of the abstract syntax tree structural information, control flow graph structural information and data flow graph structural information input to the coding layer of this layer is obtained; the structural information of the abstract syntax tree, control flow graph and data flow graph input to the coding layer of this layer and the shared attention between the intermediate representations are calculated through the global attention mechanism; the self-attention and shared attention of the abstract syntax tree structural information, control flow graph structural information and data flow graph structural information input to the coding layer of this layer are added to obtain the output of the coding layer of this layer.

[0061] In a specific embodiment, each coding layer calculates the self-attention of the abstract syntax tree structure information, control flow graph structure information and data flow graph structure information of the input coding layer of this layer through a structure-aware self-attention encoder (SASA), as well as the structural information of the abstract syntax tree, control flow graph and data flow graph of the input coding layer of this layer and the shared attention between the intermediate representations, and adds the self-attention to the shared attention to obtain the output of the coding layer of this layer.

[0062] The process of calculating self-attention by the Structure-Aware Self-Attention Encoder (SASA) is: , where Attn(Q, K, V, M) represents the self-attention of the abstract syntax tree structure information, control flow graph structure information or data flow graph structure information, Q, K and V represent the query, key and value matrices respectively, d kis the dimension of k, softmax is the normalized exponential function, M is the structural information of the input abstract syntax tree, the structural information of the control flow graph, or the structural information of the data flow graph. Since there are some similar dependencies between the intermediate representation and different structural information, SASA also calculates the structural information of the abstract syntax tree, control flow graph, and data flow graph and the shared attention between the intermediate representations through the global attention mechanism. After that, the shared attention and each self-attention are projected into the same space through the linear mapping method. As a whole, the overall attention is obtained as the output of the structure-aware self-attention encoder (SASA). , where SASA (Q, K, V, M) represents the attention of SASA output, that is, the structural information of the output abstract syntax tree, control flow graph, and data flow graph, H1 is the shared attention between the intermediate representation, abstract syntax tree, control flow graph, and data flow graph of the input SASA, H2 is the self-attention of the structural information of the input SASA abstract syntax tree, control flow graph, and data flow graph, Cat refers to the concatenation operation, W O It is a linear transformation matrix used to project and integrate the concatenated attention.

[0063] When extracting the corresponding structural features, the shared attention between the intermediate representation, abstract syntax tree, control flow graph and data flow graph of the code is added, so as to utilize the dependency relationship between the intermediate representation, abstract syntax tree, control flow graph and data flow graph, so that the obtained structural features contain more structural information. When the structural features are used for code vulnerability identification, the accuracy of code vulnerability identification is improved.

[0064] S4: Obtain the vulnerability detection results of the software code based on the structural characteristics of the abstract syntax tree, control flow graph and data flow graph and the intermediate representation of the code.

[0065] This embodiment uses a trained code vulnerability detection model to identify the structural features of the abstract syntax tree, control flow graph, and data flow graph, as well as the intermediate representation of the code, to obtain the vulnerability detection results of the software code. The code vulnerability detection model takes the fusion features of the code as input and the vulnerability detection results of the software code as output, and is obtained by constructing a comparative learning model.

[0066] like Figure 5As shown, in order to enhance the structural features extracted from the abstract syntax tree, the control flow graph and the data flow graph, this embodiment regards each structural feature as a view and performs comparative learning. By placing the structural features of the intermediate representation of the code, the abstract syntax tree, the control flow graph and the data flow graph in the same semantic space, comparative learning is performed with the labeled samples to determine the vulnerability detection results of the software code. Since different structures of the same code have a certain correlation, when different structural information is used simultaneously to identify code vulnerabilities, the accuracy of code vulnerability identification is improved.

[0067] The loss function of the code vulnerability detection model includes cross entropy loss L CLS And structural feature matching loss L CONTRA . L= L CLS +λL CONTRA ,in, L Represents the total loss of the code vulnerability detection model. λ is a hyperparameter and can be 1 or other values, which can be set according to requirements.

[0068] Structural feature matching loss L CONTRA It includes the structural feature matching loss of the abstract syntax tree, the structural feature matching loss of the control flow graph, and the structural feature matching loss of the data flow graph. L CONTRA = Ψ ast + Ψ dfg + Ψ cfg ,in, Ψ ast is the structural feature matching loss of the abstract syntax tree, Ψ dfg for Structural feature matching loss for data flow graphs ,Ψ cfg Structural feature matching loss for control flow graphs.

[0069] The code structure diagram generation model, multi-layer encoding layer and code vulnerability detection model of this embodiment together constitute a code vulnerability identification model (MV-PTM).

[0070] In this embodiment, the MV-PTM is trained by obtaining known codes and code vulnerabilities as training sets. When the training is completed, a trained MV-PTM is obtained. At this time, the code vulnerability detection model is also a trained code vulnerability detection model.

[0071] The structural features of the abstract syntax tree, control flow graph, and data flow graph obtained by S3, as well as the intermediate representation of the code, are input into the trained code vulnerability detection model to output the code vulnerability identification results.

[0072] The code anomaly vulnerability detection method disclosed in this embodiment fully utilizes the structural information contained in the code itself, the abstract syntax of the code, and the structural information of the control flow and data flow when identifying code vulnerabilities, thereby improving the accuracy of code vulnerability identification.

[0073] SASA is added in each encoding layer, which utilizes both the self-attention of a specific view and the shared attention, so that the extracted structural features contain more code structure information. When the structural features are used for code vulnerability identification, the accuracy of code vulnerability identification is further improved.

[0074] Example 2

[0075] In this embodiment, a cross-platform code anomaly vulnerability detection system is disclosed, including:

[0076] An acquisition unit, used for acquiring platform software code;

[0077] A processing unit is used to convert the platform software code into an intermediate representation of the code; generate an abstract syntax tree, a control flow graph, and a data flow graph of the code using the intermediate representation of the code; obtain the adjacency matrix of the abstract syntax tree, the control flow graph, and the data flow graph; perform multi-layer feature encoding on the adjacency matrix of the abstract syntax tree, the control flow graph, and the data flow graph through a multi-layer encoding layer to obtain the structural features of the abstract syntax tree, the control flow graph, and the data flow graph, wherein each encoding layer takes the intermediate representation and the structural information of the abstract syntax tree, the control flow graph, and the data flow graph output by the previous layer as input, and calculates the structure of the input abstract syntax tree, control flow graph, and data flow graph. The self-attention of each structural information, and the shared attention between the structural information and intermediate representations of the input abstract syntax tree, control flow graph and data flow graph, the self-attention of the structural information of the abstract syntax tree, control flow graph and data flow graph are added to the shared attention to obtain the structural information of the abstract syntax tree, control flow graph and data flow graph output by the encoding layer of this layer; according to the structural characteristics of the abstract syntax tree, control flow graph and data flow graph and the intermediate representation of the code, the vulnerability detection result of the software code is obtained. According to the structural characteristics of the abstract syntax tree, control flow graph and data flow graph and the intermediate representation of the code, the vulnerability detection result of the software code is obtained.

[0078] Furthermore, the processing unit is used for the first coding layer whose input is the adjacency matrix and intermediate representation of the abstract syntax tree, control flow graph and data flow graph; the structural information of the abstract syntax tree, control flow graph and data flow graph output by the last coding layer is the structural features of the abstract syntax tree, control flow graph and data flow graph.

[0079] The present invention also discloses an electronic device, including a memory and a processor, and computer instructions stored in the memory and running on the processor. When the computer instructions are executed by the processor, the steps described in the cross-platform code anomaly vulnerability detection method disclosed in Example 1 are completed.

[0080] The present invention also discloses a computer-readable storage medium for storing computer instructions. When the computer instructions are executed by a processor, the steps of the cross-platform code anomaly vulnerability detection method disclosed in Example 1 are completed.

[0081] The present invention also discloses a computer program product, which includes a computer program. When the computer program is executed by a processor, the cross-platform code anomaly vulnerability detection method disclosed in Example 1 is implemented.

[0082] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the above embodiments, ordinary technicians in the relevant field should understand that the specific implementation methods of the present invention can still be modified or replaced by equivalents. Any modification or equivalent replacement that does not depart from the spirit and scope of the present invention should be covered within the scope of protection of the claims of the present invention.

Claims

1. Cross-platform code anomaly vulnerability detection method, It is characterized in that include: Get the platform software code; converting platform software code into an intermediate representation of that code; Generate the code's abstract syntax tree, control flow graph, and data flow graph using the code's intermediate representation; Get adjacency matrices of abstract syntax trees, control flow graphs, and data flow graphs; Multi-layer feature encoding is performed on the adjacency matrix of the abstract syntax tree, control flow graph and data flow graph through multi-layer encoding layers to obtain the structural features of the abstract syntax tree, control flow graph and data flow graph, wherein each encoding layer takes the intermediate representation and the structural information of the abstract syntax tree, control flow graph and data flow graph output by the previous layer as input, calculates the self-attention of the structural information of the input abstract syntax tree, control flow graph and data flow graph, and the shared attention between the structural information of the input abstract syntax tree, control flow graph and data flow graph and the intermediate representation, adds the self-attention of the structural information of the abstract syntax tree, control flow graph and data flow graph and the shared attention, and obtains the structural information of the abstract syntax tree, control flow graph and data flow graph output by the encoding layer of this layer; Using the trained code vulnerability detection model, the structural features of the abstract syntax tree, control flow graph and data flow graph and the intermediate representation of the code are identified to obtain the vulnerability detection results of the software code. The code vulnerability detection model takes the fusion features of the code as input and the vulnerability detection results of the software code as output, which is obtained by constructing a comparative learning model.

2. The cross-platform code abnormality vulnerability detection method according to claim 1, It is characterized in that The structural information of the abstract syntax tree, control flow graph, and data flow graph and the shared attention between intermediate representations are calculated through a global attention mechanism.

3. The cross-platform code abnormality vulnerability detection method according to claim 1, It is characterized in that The input of the first encoding layer is the adjacency matrix and intermediate representation of the abstract syntax tree, control flow graph and data flow graph; the structural information of the abstract syntax tree, control flow graph and data flow graph output by the last encoding layer is the structural features of the abstract syntax tree, control flow graph and data flow graph.

4. The cross-platform code abnormality vulnerability detection method according to claim 1, It is characterized in that The loss functions of the code vulnerability detection model include cross entropy loss, structural feature matching loss of abstract syntax tree, structural feature matching loss of control flow graph, and structural feature matching loss of data flow graph.

5. Cross-platform code anomaly vulnerability detection system, It is characterized in that include: An acquisition unit, used for acquiring platform software code; a processing unit for converting platform software code into an intermediate representation of the code; Generate the code's abstract syntax tree, control flow graph, and data flow graph using the code's intermediate representation; Get adjacency matrices of abstract syntax trees, control flow graphs, and data flow graphs; The adjacency matrix of the abstract syntax tree, control flow graph and data flow graph is multi-layered feature encoded through multi-layer encoding layers to obtain the structural features of the abstract syntax tree, control flow graph and data flow graph, wherein each encoding layer takes the intermediate representation and the structural information of the abstract syntax tree, control flow graph and data flow graph output by the previous layer as input, calculates the self-attention of the structural information of the input abstract syntax tree, control flow graph and data flow graph, and the shared attention between the structural information of the input abstract syntax tree, control flow graph and data flow graph and the intermediate representation, adds the self-attention of the structural information of the abstract syntax tree, control flow graph and data flow graph to the shared attention, and obtains the structural information of the abstract syntax tree, control flow graph and data flow graph output by the encoding layer of this layer; uses the trained code vulnerability detection model to identify the structural features of the abstract syntax tree, control flow graph and data flow graph and the intermediate representation of the code, and obtains the vulnerability detection result of the software code, wherein the code vulnerability detection model takes the fusion feature of the code as input and the vulnerability detection result of the software code as output, and is obtained by constructing a comparative learning model.

6. The cross-platform code anomaly vulnerability detection system as claimed in claim 5, It is characterized in that The processing unit is used for the first coding layer, whose input is the adjacency matrix and intermediate representation of the abstract syntax tree, control flow graph and data flow graph; the structural information of the abstract syntax tree, control flow graph and data flow graph output by the last coding layer is the structural features of the abstract syntax tree, control flow graph and data flow graph.

7. An electronic device, It is characterized in that The method comprises a memory and a processor, and computer instructions stored in the memory and executed on the processor. When the computer instructions are executed by the processor, the steps of the cross-platform code abnormality vulnerability detection method according to any one of claims 1 to 4 are completed.

8. A computer-readable storage medium, It is characterized in that Used to store computer instructions, which, when executed by a processor, complete the steps of the cross-platform code anomaly vulnerability detection method described in any one of claims 1 to 4.

9. A computer program product, It is characterized in that The computer program product includes a computer program, and when the computer program is executed by a processor, the cross-platform code anomaly vulnerability detection method according to any one of claims 1 to 4 is implemented.