A method for recovering identifier names in decompilation scenarios

By adopting the encoder-decoder architecture and attention mechanism in the decompilation scenario, combining GGNN and Transformer handler dependency graphs, the problem of the inability to effectively restore identifier names in the existing technology is solved, and more accurate name recovery and code are achieved Understand that improves the efficiency of reverse engineering.

CN118605885BActive Publication Date: 2024-11-15NANJING UNIV OF AERONAUTICS & ASTRONAUTICS
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202410652114.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-05-24
Publication Date
2024-11-15
Estimated Expiration
2044-05-24

AI Technical Summary

Technical Problem

The existing technology cannot effectively restore the identifier name in the decompilation scenario, especially because the information lost during the compilation and binary stripping cannot be accurately restored, resulting in the identifier name losing its meaning. The existing methods have limitations when utilizing structured information. and lack of interaction between external information and code representation.

Method used

Using the encoder-decoder architecture, combined with the attention mechanism, the graph structure is processed by constructing a enhanced program dependency graph and gated graph neural network (GGNN), and combining the Transformer encoder and decoder, the control dependency and data dependency are used to perform dual processing. Linear interaction, predict identifier name.

Benefits of technology

It realizes more accurate recovery of identifier names in decompiled code, improves the efficiency of reverse engineering, enhances understanding of code functions and structure, and promotes malware analysis and vulnerability repair.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118605885B_ABST
    Figure CN118605885B_ABST
Patent Text Reader

Abstract

The present invention discloses a method for recovering identifier names in a decompilation scenario, including: step 1, constructing an enhanced program dependency graph for an input decompiled code sequence; step 2, using GGNN to process the program dependency graph to obtain the embedding of each node in the graph; step 3, using a Transformer encoder to encode the input decompiled code sequence to obtain the encoding of the code; step 4, passing the node embedding and the encoding of the code to a Transformer decoder to obtain a prediction result. The present invention adopts an encoder-decoder architecture, based on an attention mechanism, and infers the original possible name of the identifier by using the control dependency and data dependency in the program through bilinear interaction, which can more accurately recover the original name of the identifier, improve the efficiency of reverse engineering, and further promote malware analysis, vulnerability repair and other aspects.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of software engineering and network security, and relates to an identifier name recovery method in a decompilation scenario. Background Art

[0002] Software reverse engineering aims to understand program behavior without access to program source code. Decompilation, as an important technology of reverse engineering, refers to the process of restoring compiled machine code to high-level language code, which plays an important role in malware analysis, vulnerability repair, etc. However, during the compilation process, due to operations such as optimization and obfuscation, information such as identifiers, comments, and user-defined types in the source code will be discarded. Even the debugging information that represents the relationship between the executable program and the source code is usually stripped in wild software and released software. Therefore, the names of identifiers in the decompiled code usually become meaningless. Even though today's decompilers use advanced program analysis techniques and complex heuristic algorithms to identify much of the information lost during compilation and binary stripping, such as function boundaries, function prototypes, variable locations, variable types, etc., they still cannot assign a meaningful name to the identifier.

[0003] When recovering the names of decompiled identifiers, the prior art focuses on predicting the variable name or function name separately, and usually processes it in a similar way to NLP. For example, a sequence-to-sequence model (Seq2Seq) is used, which is regarded as a machine translation task, combined with the identifier context, and attempts to use software engineering knowledge, such as abstract syntax tree AST, control flow graph CFG, etc., to recover the possible names of identifiers. Whether it is AST or CFG, both are attempts to allow the model to learn the structured information in the code to make up for the deficiency that the NLP method can only learn the sequential information in the code. Although AST reflects the hierarchical structure and grammatical structure in the program, it is relatively complex and prone to produce deeper levels. Although CFG is conducive to the model learning control processes such as conditional branches and loops, understanding the execution path and logical structure of the code, and learning function semantics, it is not comprehensive enough. In short, both have certain limitations.

[0004] In addition, when utilizing external information, existing technologies usually use simple concatenated input or merge external information into the code representation before / after model processing, lacking the interaction between external information and input code. Summary of the invention

[0005] The technical problem to be solved by the present invention is to provide an identifier name recovery method in a decompilation scenario in response to the deficiencies of the above-mentioned prior art. The method adopts an encoder-decoder architecture and is based on an attention mechanism. Through bilinear interaction, the control dependencies and data dependencies in the program are used to infer the original possible names of the identifiers. The original names of the identifiers can be restored more accurately, and meaningful identifier names can be obtained, which helps reverse engineers understand the functions and structures of the decompiled codes, improves the efficiency of reverse engineering, and further promotes malware analysis, vulnerability repair and other aspects.

[0006] In order to achieve the above technical objectives, the technical solution adopted by the present invention is:

[0007] A method for recovering identifier names in a decompilation scenario, comprising:

[0008] Step 1: construct an enhanced program dependency graph for the input decompiled code sequence;

[0009] Step 2: Use GGNN to process the program dependency graph to get the embedding of each node in the graph;

[0010] Step 3: Use the Transformer encoder to encode the input decompiled code sequence to obtain the code encoding;

[0011] Step 4: Pass the node embedding and code encoding to the Transformer decoder to get the prediction result.

[0012] To optimize the above technical solutions, the specific measures taken also include:

[0013] The above step 1 builds an enhanced program dependency graph for the input decompiled code sequence, including:

[0014] Construct a control flow graph for each function in the input decompiled code sequence, analyze control dependencies and data dependencies based on the control flow graph, and analyze the execution order between nodes that control the same statement. Construct and visualize an enhanced program dependency graph based on the execution order analysis results, where the nodes in the program dependency graph represent non-jump, sequentially executed statements.

[0015] The above step 2 uses the GGNN process dependency graph to get the embedding of each node in the graph, including:

[0016] 2.1) Obtain GGNN input based on the program dependency graph G(V,E), including features at the full graph level, features of each edge, and features of each node;

[0017] 2.2) Initialize the state vector of the node using the node’s features;

[0018] 2.3) Through the features of the entire graph and the features of each edge, the connection relationship between nodes is obtained, based on which information is propagated, the node representation is updated over time, and the final node embedding is obtained.

[0019] The above-mentioned full-graph level features are the connection relationships between nodes;

[0020] The characteristics of the edge are determined by the type of edge and the direction of the edge. The direction of the edge is divided into input edge and output edge. The types of edges are divided into control dependency edge, data dependency edge and execution order edge. Control dependency edge is divided into control dependency caused by correct condition and control dependency caused by incorrect condition. Data dependency edge is further divided according to variables, and data dependency edges of different variables belong to different types. Execution order edge is an enhancement based on the original program dependency graph. The characteristics of the node include the statement type contained in the node, the name of the called library function and the type of variable.

[0021] The above 2.3) updates the node representation over time through information propagation to obtain the final node embedding, including:

[0022] Use the update gate to control the forgotten information, and use the reset gate to control the newly generated information, and then merge the information from adjacent nodes and from the previous time step to update the hidden state of each node. When the final moment is reached, the representation of the node at this time is mapped to the output to obtain the final node embedding.

[0023] The above step 3 uses the Transformer encoder to encode the input decompiled code sequence to obtain the code encoding, including:

[0024] 3.1) Segment the decompiled code sequence using byte pair encoding;

[0025] 3.2) Obtain the input of the Transformer encoder based on the code sequence after word segmentation, including word embedding and position embedding;

[0026] 3.3) Take a single function in the decompiled code sequence as the input unit, merge its word embedding and position embedding, and pass it to the Transformer encoder for processing to obtain the encoding of each token in the code sequence.

[0027] The above 3.1) includes:

[0028] Perform preliminary word segmentation on the input decompiled code sequence by spaces and count the frequency of each word;

[0029] Add stop characters at the end of words, then split each word into its smallest unit, i.e., characters, to build a basic vocabulary;

[0030] The most frequently occurring adjacent character pairs are selected from the base vocabulary according to the frequency and merged until the preset vocabulary size or the number limit is reached.

[0031] The above 3.2) includes:

[0032] The position embedding is directly calculated by the following formula:

[0033] PE (pos,2i) =sin(pos / 10000 2i / d )

[0034] PE (pos,2i+1) =cos(pos / 10000 2i / d )

[0035] Among them, PE (pos,2i) PE (pos,2i+1) Positional embeddings for even and odd dimensions, respectively;

[0036] pos represents the position of the word in the sentence, d represents the dimension of the position embedding, 2i represents an even dimension, and 2i+1 represents an odd dimension;

[0037] Word embedding is obtained in the following way:

[0038] The input word is encoded into a sequence vector in One-Hot form, and the sequence vector is dot-multiplied with the weight matrix. Through the Transformer training process, the value of the weight matrix W is determined to obtain the final word embedding.

[0039] The above step 4 passes the node embedding and code encoding to the Transformer decoder to obtain the prediction result:

[0040] During the Transformer decoding process, the Transformer decoder uses bilinear interaction to inject the program dependency information contained in the node embedding into the attention graph and the code encoding, outputs the probability distribution, and obtains the prediction result. The bilinear interaction is specifically:

[0041] Q m =T·W q,m ⊙E m

[0042] K m =T·W k,m ⊙E m

[0043] V m =T·W v,m ⊙E m

[0044] Among them, ⊙ represents the inner product and Hadamard product, Qm , K m and V m is applied to the code representation T and the node embedding E m Bilinear transformation of W q,m , W k,m and W v,m is a learnable weight matrix.

[0045] The present invention has the following beneficial effects:

[0046] The enhanced program dependency graph used in the present invention not only reflects the dependency relationship caused by control flow in the program, but also embodies the data flow between variables. It is a combination of the two. When restoring identifier names, it can more comprehensively learn the implicit features in the program and make correct predictions as much as possible.

[0047] In addition to using Transformer to process the sequential information in the code, the present invention also uses GGNN to learn the structural information in the code. By comprehensively utilizing the control flow information and data flow information in the program, the function name and variable name are restored. GGNN processing program dependency graph can better utilize the favorable information in the code and obtain a node embedding representation that is more suitable for the task, thereby improving the accuracy of name prediction.

[0048] The present invention performs BPE word segmentation on the input decompiled code sequence, which can better capture the semantic similarity between identifiers and help learn implicit features in the code that can be used for name recovery tasks.

[0049] The information used by the present invention is more comprehensive: since programming languages ​​are highly structured and logical, and are very sensitive to data flow and logic, the present invention can better understand the semantics of functions to increase the probability of correct prediction.

[0050] Compared with simple concatenated input or merging external information into the code representation before / after model processing, the present invention uses bilinear interaction based on the attention mechanism to inject the learned structural information into the code representation during the model processing, so that the structural information and sequential information of the code can be better integrated, thereby improving the accuracy of model prediction. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] Figure 1 A flowchart of an identifier name recovery method in a decompilation scenario provided by the present invention;

[0052] Figure 2 An example of an enhanced program dependency graph constructed for the present invention;

[0053] Figure 3 Schematic diagram of three common feature interaction modes. DETAILED DESCRIPTION

[0054] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.

[0055] Although the steps in the present invention are arranged with numbers, they are not used to limit the order of the steps. Unless the order of the steps is clearly stated or the execution of a certain step requires other steps as a basis, the relative order of the steps can be adjusted. It is understood that the term "and / or" used in this article involves and covers any and all possible combinations of one or more of the associated listed items.

[0056] like Figure 1 As shown, a method for recovering identifier names in a decompilation scenario of the present invention is characterized by being divided into two modules: a graph representation module and a code representation module, and comprising the following steps:

[0057] Step 1: construct an enhanced program dependency graph for the input decompiled code sequence;

[0058] Step 2: Use the gated graph neural network GGNN to process the program dependency graph to obtain the embedding of each node in the graph;

[0059] Step 3: Use the Transformer encoder to encode the input decompiled code sequence to obtain the code encoding;

[0060] Step 4: Pass the node embedding and code encoding to the Transformer decoder to get the prediction result. It is divided into two modules: graph representation module and code representation module

[0061] In the embodiment, the original input is a decompiled code sequence, in which a function is an input unit, and the final output is a predicted identifier name.

[0062] Steps 1-2 belong to the graph representation module, which receives the input code sequence, performs dependency analysis on it, builds an enhanced program dependency graph, processes it using GGNN, and outputs the embedding representation of each node;

[0063] Gated graph neural network GGNN is a kind of GNN, which introduces the gating mechanism of GRU in the propagation process, allowing nodes to selectively receive and ignore information from neighboring nodes, and obtain embedded representations of nodes and the entire graph through iterative message passing and updating, which can better capture the global information of the graph and node context information. In addition, in GNN, it is meaningless to initialize the node state vector, while GGNN allows the node state vector to be initialized using the node's feature vector. The node feature vector constructed by the present invention contains several parts that are helpful for the name recovery task, so using GGNN to process the program dependency graph can better utilize the favorable information in the code, obtain a node embedding representation that is more suitable for this task, and thus improve the accuracy of name prediction.

[0064] Step 3) belongs to the code representation module, receives the input code sequence, uses BPE to segment it, and constructs a vocabulary; then uses the Transformer encoder to process it and outputs the coded representation of the code. Among them, BPE constructs a vocabulary by merging the most frequent adjacent characters. For the input decompiled code sequence, after BPE segmentation, similar identifiers usually share some of the same subtokens, so that the model can better capture the semantic similarity between identifiers, which helps the model learn implicit features in the code that can be used for name recovery tasks. Transformer is one of the commonly used models in the field of NLP. The task of the present invention is to predict the original possible name of the identifier based on the program context. Since in a longer code sequence, the name of the identifier may be far away from its reference or definition location, the traditional LSTM may not be able to effectively handle this long-distance dependency. Transformer uses the attention mechanism to capture the characteristics of global dependencies, making it more effective in processing identifier name recovery tasks.

[0065] There is no dependency between modules and they can be executed in parallel.

[0066] After obtaining the node embedding and code representation, they are concatenated and input into the Transformer decoder. Based on the attention mechanism, bilinear interaction is used to inject the node embedding into the code representation. After Transformer decoding, the probability distribution, i.e. the possible identifier names, is obtained.

[0067] Among them, combined Figure 3Bilinear interaction is a method for calculating feature interaction used in the field of click-through rate (CTR) prediction. The introduction of feature interaction allows the model to make predictions not only based on individual features, but also based on the combination of features, thereby improving the accuracy of predictions. If there are features i and j, the inner product or Hadamard product of the two is a common feature interaction method, while bilinear interaction is to first make an inner product between feature i and a matrix or a part of the matrix, and then make a Hadamard product between the result of the previous step and feature j. In the name recovery task, the node embedding of the program dependency graph can be regarded as a feature. Under the self-attention mechanism of Transformer, the calculation of Q, K, and V in the formula coincides with the first step of bilinear interaction. Therefore, it is considered to add a second step on this basis, introduce bilinear interaction, and inject the information learned from the program dependency graph into the code representation during the model processing process, so that the model can make predictions based on the combination of the sequential information and structural information of the code, thereby improving the accuracy of the model prediction.

[0068] The present invention tends to start with semantics, and helps to recover function names and variable names by understanding function semantics and variable semantics. The functional semantics of functions can be learned to a certain extent by modeling the control flow, and the semantics of variables can be learned by modeling the source of variables, that is, the data flow. Except for a small number of identifiers in the program that are used to identify functions, the vast majority of the remaining identifiers are variable names, so the learning of variable semantics plays an important role in the task of recovering identifier names. The enhanced program dependency graph used in the present invention is constructed based on the control flow graph, which not only reflects the dependency relationship caused by the control flow in the program, but also reflects the data flow between variables, and is a combination of the two. Therefore, introducing the program dependency graph when recovering identifier names can enable the model to learn the implicit features in the program more comprehensively and make correct predictions as much as possible.

[0069] The steps are further described below:

[0070] Step 1 builds an enhanced program dependency graph for the decompiled code, including:

[0071] Construct a control flow graph for each function in the decompiled code, perform dependency analysis based on the control flow graph, including control dependency and data dependency, and analyze the execution order between nodes that control the same statement. Construct an enhanced program dependency graph based on the analysis results, and then visualize it, such as Figure 2 shown.

[0072] Step 2 uses GGNN to process the program dependency graph to get the embedding of each node in the graph, including:

[0073] Represent the program dependency graph G(V,E) in a form acceptable to GGNN and initialize the node state vector. Update the node representation over time through information propagation to obtain the final node embedding. Specifically:

[0074] The program dependency graph G(V,E) is represented as a form acceptable to GGNN. The input of GGNN includes three parts: the features at the full graph level, the features of each edge, and the features of each node:

[0075] The connection relationship between nodes is used to represent the features at the whole graph level. The edge type and direction are used to represent the edge features. The directions of the edges in the enhanced program dependency graph are divided into in-edges and out-edges. The edge types are divided into: control dependency edges caused by correct conditions, control dependency edges caused by incorrect conditions, data dependency edges of different variables, and execution order edges. The features of the node are represented by three parts: the statement type contained in the node, the name of the library function called, and the type of the variable.

[0076] Furthermore, step 2 specifically includes:

[0077] 2.1) First, the program dependency graph G(V,E) is represented in a form acceptable to GGNN. The input of GGNN includes three parts: features at the full graph level, features of each edge, and features of each node.

[0078] The feature at the whole graph level is the connection relationship between nodes, which is represented by the adjacency matrix in the specific implementation.

[0079] In the specific implementation, the characteristics of the edge are determined by the type of edge and the direction of the edge. For the enhanced program dependency graph, the direction of the edge is divided into input edge and output edge, and the type of edge is divided into: control dependency edge, data dependency edge and execution order edge. Control dependency edges can be divided into control dependencies caused by correct conditions and control dependencies caused by incorrect conditions; data dependency edges can be further divided according to variables, and data dependency edges of different variables belong to different types. The execution order edge is an enhancement based on the original program dependency graph. Since the control dependency edge does not directly reflect the running order like the control flow, it may cause the lack of connection between the nodes that control the same statement. Therefore, execution order edges are added between such nodes to provide more information for GGNN to construct node representation.

[0080] The characteristics of a node are determined by the content it contains.

[0081] The program dependency graph is constructed on the basis of the control flow graph. Each node in the graph represents a non-jump, sequentially executed statement. Statement types can be divided into six types: function call, operation, variable declaration, input, output, and assignment. A statement may belong to multiple types at the same time. For example, int a=function(5,9) includes both declaration, call, and assignment.

[0082] If a basic block contains a function call statement, the name of the called function will appear, which reflects the function and semantic information of the caller to a certain extent and can help the caller to restore the name. However, due to the stripping of debugging information, ordinary function names will lose their meaning, and only the library function under dynamic linking will retain the complete function name.

[0083] If a basic block contains a variable declaration statement, the type of the variable will appear. Since there is a certain connection between the name and type of the variable, such as s and str are usually used to represent strings, the type of the variable also helps to recover the name.

[0084] Therefore, the feature vector of a node is composed of three parts that reflect the characteristics of the node itself and help to recover the name. These three parts are the statement type contained in the node, the name of the called library function, and the type of the variable. The latter two will only have values ​​when the statement type is a call statement or a variable declaration statement. For nodes that do not contain these two types of statements, the positions of these parts are filled with zeros. In the specific implementation, the types of statements and variables are represented by one-hot encoding, and the library function name encoding is generated using Word2Vec, etc.

[0085] 2.2) Use the input node feature vector to initialize the node's state vector, that is, assign the input node feature vector to the node's state vector for initialization.

[0086] In a specific implementation, when the dimension of the node feature vector is smaller than the dimension of the state vector, 0 is added at the end.

[0087] 2.3) Through the features of the entire graph and the features of each edge, the connection relationship between nodes is obtained, based on which information is propagated, the node representation is updated over time, and the final node embedding is obtained.

[0088] In the specific implementation, the calculation process during update is similar to GRU (Gate Recurrent Unit), using the update gate to control the forgotten information and the reset gate to control the newly generated information, and then merge the information from the adjacent nodes and from the previous time step to update the hidden state of each node. When the final moment is reached, the node's representation at this time is mapped to the output to obtain the final node embedding.

[0089] Step 3 encodes the code sequence using the Transformer encoder, including:

[0090] 3.1) Use Byte Pair Encoding (BPE) to segment the code sequence and build a vocabulary.

[0091] First, the input decompiled code sequence is preliminarily segmented by spaces, and the frequency of each word is counted. Then, a stop symbol "" is added at the end of the word to split each word into the smallest unit (character) and build a basic vocabulary. The most frequently occurring adjacent character pairs are selected and merged according to the frequency, and this step is repeated until the preset vocabulary size or number limit is reached. This can theoretically minimize the size of the constructed vocabulary.

[0092] 3.2) Represent the segmented code sequence as an input form acceptable to Transformer, including word embedding and position embedding.

[0093] In the specific implementation, Transformer uses absolute position encoding, which is directly calculated by the following formula.

[0094] PE (pos,2i) =sin(pos / 10000 2i / d )

[0095] PE (pos,2i+1) =cos(pos / 10000 2i / d )

[0096] Among them, PE (pos,2i) PE (pos,2i+1) Positional embeddings for even and odd dimensions, respectively;

[0097] pos represents the position of the word in the sentence, d represents the dimension of the position embedding, 2i represents even dimensions, and 2i+1 represents odd dimensions.

[0098] In the specific implementation, word embedding is obtained in the following way: encode the input word into a sequence vector in One-Hot form, design a learnable weight matrix W, perform dot multiplication on the word vector and this matrix, determine the value of the weight matrix W through the Transformer training process, and obtain the final word embedding.

[0099] 3.3) Take a single function in the decompiled code sequence as the input unit, merge its word embedding and position embedding, and pass it to the Transformer encoder for processing to obtain the encoding representation of each token in the code sequence. During the processing, average pooling is used to summarize all occurrences of a variable in the function to obtain a more accurate representation of the variable.

[0100] A variable usually appears multiple times in a function, and each occurrence is called an instance of the variable. In practice, in order to obtain a more accurate representation of the variable, combine a more comprehensive variable context, and make different instances of the same variable have the same predicted name, it is necessary to summarize the occurrences of all variables through average pooling, that is, the representation of the i-th variable is calculated based on all its instances in the code sequence:

[0101]

[0102] Where W is the input code sequence, A i are all instances of the ith variable in the code, t j It is the encoding representation of the jth token in the code, i=1~n, n is the number of variables in the function.

[0103] Step 4 passes the node embedding and the encoded representation of the code to the Transformer decoder to obtain the prediction result. The implementation process is as follows:

[0104] 4.1) During the Transformer decoding process, bilinear interactions are used to inject program dependency information implied in node embeddings into the attention graph and code representation.

[0105] In the specific implementation, suppose that after BPE, the input code can be represented as a token sequence: W = {w 1 ,w 2 ,…,w L}, where L is the length of a code sequence, and the code obtained by the Transformer encoder is represented as T = [t 1 ,t 2 ,…,t L ]=f([w 1 ,w 2 ,…,w L ];θ). The embedding of each node obtained by GGNN can be expressed as E=[E 1 ,E 2 ,…,E M ], M is the number of nodes in the program dependency graph. The present invention uses node embedding in the program dependency graph as a feature and injects these features into the attention graph and code representation using bilinear interaction.

[0106] The process is as follows:

[0107] Bilinear interaction is introduced when calculating Q, K, and V in the self-attention mechanism:

[0108] Q m =T·W q,m ⊙E m

[0109] K m =T·W k,m ⊙E m

[0110] V m =T·W v,m ⊙E m

[0111] Among them, ⊙ represents the inner product and Hadamard product, Q m , K m and V m is applied to the code representation T and the node embedding E m Bilinear transformation of W q,m , W k,m and W v,m is a learnable weight matrix.

[0112] Attention weight U m for:

[0113]

[0114] Finally, we have:

[0115] Y=MFA(T,E)=[U 1 ,U 2 ,…,U M ]

[0116] Among them, MFA stands for multi-feature attention mechanism.

[0117] 4.2) Output probability distribution and get prediction results

[0118] In the specific implementation, the output Y of the multi-feature attention mechanism is passed through a linear layer and a softmax function to obtain the probability distribution of all possible types.

[0119] In the specific implementation, since Transformer is an autoregressive (AR) model, subsequent predictions will be made based on previous prediction results, that is, Therefore, the first prediction result in each input, that is, the function name, will naturally be used as information to predict the identifier name in the function body. The function name reflects the semantics and functionality of the function and is closely related to the variable name in the function body. The implicit use of function names allows the model to learn typical variable names used in functions with specific names, further improving the prediction accuracy.

[0120] It will be apparent to those skilled in the art that the invention is not limited to the details of the exemplary embodiments described above and that the invention can be implemented in other specific forms without departing from the spirit or essential features of the invention. Therefore, the embodiments should be considered exemplary and non-limiting in all respects, and the scope of the invention is defined by the appended claims rather than the foregoing description, and it is intended that all variations falling within the meaning and scope of the equivalent elements of the claims be included in the invention. Any reference numeral in a claim should not be considered as limiting the claim to which it relates.

[0121] In addition, it should be understood that although the present specification is described according to implementation modes, not every implementation mode contains only one independent technical solution. This description of the specification is only for the sake of clarity. Those skilled in the art should regard the specification as a whole. The technical solutions in each embodiment may also be appropriately combined to form other implementation modes that can be understood by those skilled in the art.

Claims

1. A method for recovering identifier names in a decompilation scenario, characterized in that: include: Step 1: construct an enhanced program dependency graph for the input decompiled code sequence; Step 2: Use GGNN to process the program dependency graph to get the embedding of each node in the graph; Step 3: Use the Transformer encoder to encode the input decompiled code sequence to obtain the code encoding; Step 4: Pass the node embedding and code encoding to the Transformer decoder to obtain the prediction result; The step 3 uses a Transformer encoder to encode the input decompiled code sequence to obtain the code encoding, including: 3.1) Use byte pair encoding to tokenize the decompiled code sequence; 3.2) Obtain the input of the Transformer encoder based on the code sequence after word segmentation, including word embedding and position embedding; 3.3) Take a single function in the decompiled code sequence as the input unit, merge its word embedding and position embedding, and pass it to the Transformer encoder for processing to obtain the encoding of each token in the code sequence; The 3.2) includes: The position embedding is directly calculated by the following formula: ; ; in, , Positional embeddings for even and odd dimensions, respectively; pos represents the position of the word in the sentence, d represents the dimension of the position embedding, 2i represents the even dimension, and 2i+1 represents the odd dimension; Word embedding is obtained in the following way: Encode the input word into a sequence vector in One-Hot form, perform dot multiplication on the sequence vector and the weight matrix W, and determine the value of the weight matrix W through the Transformer training process to obtain the final word embedding; The step 4 passes the node embedding and the code encoding to the Transformer decoder to obtain the prediction result, specifically: During the Transformer decoding process, the Transformer decoder uses bilinear interaction to inject the program dependency information contained in the node embedding into the attention graph and the code encoding, outputs the probability distribution, and obtains the prediction result. The bilinear interaction is specifically: ; in, represents the inner product and Hadamard product, Q m , K m and V m is applied to the code representation T and the node embedding E m Bilinear transformation, W q,m , W k,m and W v,m is a learnable weight matrix.

2. The identifier name recovery method in a decompilation scenario according to claim 1, characterized in that: The step 1 constructs an enhanced program dependency graph for the input decompiled code sequence, including: Construct a control flow graph for each function in the input decompiled code sequence, analyze control dependencies and data dependencies based on the control flow graph, and analyze the execution order between nodes that control the same statement. Construct and visualize an enhanced program dependency graph based on the execution order analysis results, where the nodes in the program dependency graph represent non-jump, sequentially executed statements.

3. The identifier name recovery method in a decompilation scenario according to claim 1, characterized in that: The step 2 uses the GGNN processing program dependency graph to obtain the embedding of each node in the graph, including: 2.1) Obtain GGNN input based on the program dependency graph G(V,E), including features at the full graph level, features of each edge, and features of each node; 2.2) Initialize the node's state vector using the node's features; 2.3) Through the features of the entire graph and the features of each edge, the connection relationship between nodes is obtained, based on which information is propagated, the node representation is updated over time, and the final node embedding is obtained.

4. The identifier name recovery method in a decompilation scenario according to claim 3, characterized in that: The feature of the full graph level is the connection relationship between nodes; The characteristics of the edge are determined by the type of edge and the direction of the edge. The direction of the edge is divided into input edge and output edge. The types of edges are divided into control dependency edge, data dependency edge and execution order edge. Control dependency edge is divided into control dependency caused by correct condition and control dependency caused by incorrect condition. Data dependency edge is further divided according to variables, and data dependency edges of different variables belong to different types. Execution order edge is an enhancement based on the original program dependency graph. The characteristics of the node include the statement type contained in the node, the name of the called library function and the type of variable.

5. The identifier name recovery method in a decompilation scenario according to claim 3, characterized in that: Said 2.3) updates the node representation over time through information propagation to obtain the final node embedding, including: Use the update gate to control the forgotten information, and use the reset gate to control the newly generated information, and then merge the information from adjacent nodes and from the previous time step to update the hidden state of each node. When the final moment is reached, the representation of the node at this time is mapped to the output to obtain the final node embedding.

6. The identifier name recovery method in a decompilation scenario according to claim 1, characterized in that: The 3.1) includes: Perform preliminary word segmentation on the input decompiled code sequence by spaces and count the frequency of each word; Add stop characters at the end of words, then split each word into its smallest unit, i.e., characters, to build a basic vocabulary; The most frequently occurring adjacent character pairs are selected from the base vocabulary according to the frequency and merged until the preset vocabulary size or the number limit is reached.

Citation Information

Patent Citations

  • Sub-graph semantic isomorphism based instruction idiom identification method

    CN105589728A

  • A code annotation generation method based on program analysis and a recurrent neural network

    CN109783079A

  • Multi-class vulnerability detection method based on program slices and graph neural network

    CN115357904A

  • Vulnerability identification method based on semantic learning of slice code dependency graph

    CN116305158A

  • Bill of material SBOM + analysis method and device for open source software supply chain

    CN117195233A