Binary function boundary detection method, system and electronic device based on semantic features

Through the semantic feature method based on the BERT model, the problem of inaccurate positioning and low efficiency of binary function boundaries is solved, and binary function boundary detection with high accuracy and efficiency is achieved, which is suitable for vulnerability detection and malware analysis.

CN114138273BInactive Publication Date: 2024-10-15COMP APPL RES INST CHINA ACAD OF ENG PHYSICS
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111338422.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-12
Publication Date
2024-10-15
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

In the existing technology, when disassembling binary programs that remove symbol tables and have high optimization levels, function boundary positioning is inaccurate, and existing methods are inefficient or rely on manual experience, and cannot effectively identify the boundaries of binary functions.

Method used

Using the semantic feature method based on the BERT model, by constructing an assembly code data set containing function boundary markers, the BERT model is used for pre-training to obtain word vectors of contextual semantics, and the model is fine-tuned to determine whether the assembly instruction is a function boundary, combined with IDApro disassembly and Transformer Encoder structures implement binary function boundary detection.

Benefits of technology

It improves the accuracy and efficiency of binary function boundary detection, enhances function identification capabilities, and is suitable for fields such as vulnerability detection and malware analysis.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114138273B_ABST
    Figure CN114138273B_ABST
Patent Text Reader

Abstract

The present invention proposes a binary function boundary detection method, system and electronic device based on semantic features. The method constructs a data set by disassembling a binary program with a symbol table through IDApro, and trains the assembly code using a BERT model to determine whether it is a binary function boundary. The present invention can enhance the recognition ability of functions during the disassembly process, and can achieve better effects in the fields of vulnerability detection, malware analysis, software engineering reverse engineering, etc.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of binary code function boundary detection, and in particular relates to a binary function boundary detection method, system and electronic equipment based on semantic features. Background Art

[0002] In the field of binary function boundary identification, disassembly tools such as IDApro and BAP can be used. IDApro uses a pattern matching algorithm to detect function boundaries, which has high accuracy and applicability. However, when disassembling binary programs with symbol tables removed and high optimization levels, function boundaries are often inaccurately located, resulting in some functions being unrecognizable. BAP uses a pattern and signature matching algorithm, but the signature relies on manual experience and needs to be dynamically updated.

[0003] To address the above issues, neural networks have been introduced. Methods such as ByteWeight, which utilize weighted prefix trees for recognition, improve accuracy but suffer from low efficiency. Another example is using recurrent neural networks to directly input binary bytes and predict whether each byte is a function boundary. While this improves both efficiency and accuracy, LSTM neural networks are not as effective as BERT in recognizing contextual semantic information. Summary of the Invention

[0004] The purpose of the present invention is to solve the problems in the prior art and to propose a binary function boundary detection method, system and electronic device based on semantic features.

[0005] The present invention is implemented according to this solution. The present invention proposes a binary function boundary detection method based on semantic features. Binary code is disassembled to obtain assembly code, which is composed of assembly instructions. The assembly instructions are composed of a mnemonic and n operators, where n ≥ 0. The method includes:

[0006] Step 1: Construct an assembly code dataset containing function boundary markers;

[0007] Step 2: Use the dataset to pre-train the BERT model to obtain word vectors with contextual semantics;

[0008] Step 3: Retrain the pre-trained BERT model to obtain a model that can determine whether an assembly instruction is a function boundary;

[0009] Step 4: Input the assembly code into the trained function boundary judgment model to perform binary function boundary detection.

[0010] Furthermore, the step 1 is specifically as follows:

[0011] The collected binary code is disassembled using IDApro to obtain the function start and end addresses. Then, the disassembled assembly code is marked with function boundaries in units of instructions, that is, whether the assembly instruction is the start of a function, the end of a function, or a non-function boundary, which is divided into three categories. Finally, the assembly code is randomly segmented to obtain an assembly code dataset containing function boundary markers.

[0012] Furthermore, the BERT model structure is divided into three parts, namely Embeddings, Bert and output vector; the Embeddings layer is composed of word vectors Token Embeddings, function boundary vectors function embeddings, and position information vectors Position Embeddings to form a word vector representation of a single mnemonic; Bert as a whole is composed of multiple Transformer Encoders superimposed, and finally outputs a word vector containing contextual semantics; the function boundary vector includes non-function boundary E M , function starting address E S and function end address E E .

[0013] Furthermore, there are two training tasks in the pre-training process. One is the mask prediction task of Token Embeddings, which masks 15% of the tokens and predicts the masked part. The output result is compared with the Token Embeddings before masking, and the cross entropy is calculated as loss_mask; the other training task is the function boundary prediction task, that is, adding a linear layer and a softmax layer after the embedding vector of each token, comparing the output result with the function embeddings, and calculating the cross entropy as loss_func; the final cross entropy loss = loss_mask + loss_func, and the Adam optimizer is used to minimize the cross entropy loss; the pre-trained BERT model will output word vectors with contextual semantics.

[0014] Furthermore, in step three, the assembly code is input into the pre-trained BERT model to obtain an embedding vector for each token, and the embedding vector is input into a linear layer and a softmax layer, compared with the correct function label, and the cross entropy is calculated as loss_func. The Adam optimizer is used to minimize loss_func, and a model that can determine whether the assembly instruction is a function boundary is obtained.

[0015] Furthermore, constants in assembly code are divided into five categories, namely immediate values, addresses, variable names, function names and basic block labels, which are replaced by the characters 'IMM', 'ADDRESS', 'VAR', 'FUNC' and 'BB' respectively.

[0016] The present invention also proposes a binary function boundary detection system based on semantic features. Binary code is disassembled to obtain assembly code, which is composed of assembly instructions. The assembly instructions are composed of a mnemonic and n operators, where n ≥ 0. The system includes:

[0017] Dataset construction module: used to construct an assembly code dataset containing function boundary markers;

[0018] Pre-training module: used to use the BERT model to pre-train the dataset to obtain word vectors with contextual semantics;

[0019] Optimization module: used to retrain the pre-trained BERT model to obtain a model that can determine whether an assembly instruction is a function boundary;

[0020] Detection module: used to input assembly code into the trained function boundary judgment model to perform binary function boundary detection.

[0021] The present invention further provides an electronic device, comprising:

[0022] at least one processor; and,

[0023] a memory communicatively connected to the at least one processor; wherein,

[0024] The memory stores instructions that can be executed by the at least one processor. The instructions are executed by the at least one processor to enable the at least one processor to perform the binary function boundary detection method based on semantic features.

[0025] This paper introduces the BERT language model for natural language processing and adds a new function boundary training task. Finally, it fine-tunes the pre-trained model to obtain a model that can determine whether assembly instructions are function boundaries. This method can enhance the ability to identify functions during the disassembly process, which can improve vulnerability detection, malware analysis, software reverse engineering, and other fields. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] Figure 1 Schematic diagram of the BERT model structure of the present invention;

[0027] Figure 2 Schematic diagram of vector expression in the BERT model structure described in the present invention;

[0028] Figure 3 Schematic diagram of the fully connected layer of the present invention. DETAILED DESCRIPTION

[0029] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.

[0030] Combine Figure 1-3 The present invention proposes a binary function boundary detection method based on semantic features. A data set is constructed by disassembling a binary program with a symbol table using IDApro. The assembly code is trained using the BERT model to determine whether it is a binary function boundary. The binary code is disassembled to obtain the assembly code, which is composed of assembly instructions. The assembly instruction consists of a mnemonic and n operators, where n ≥ 0. The method specifically includes:

[0031] Step 1: Construct an assembly code dataset containing function boundary markers;

[0032] When training the BERT model, you need to build your own dataset first. Since the '-s' compilation option is not added during compilation, the binary program contains a symbol table, and the symbol table contains the names of all functions, the starting address of the function, and the ending address of the function. Therefore, any disassembler can correctly identify the function boundary. The present invention disassembles the collected binary code through IDA pro to obtain the function starting address and ending address, and then marks the function boundary of the disassembled assembly code in units of instructions, that is, determines whether the assembly instruction is the start of a function, the end of a function, or a non-function boundary, a total of three categories, and finally, randomly segments the assembly code to obtain an assembly code dataset containing function boundary markers.

[0033] Step 2: Use the dataset to pre-train the BERT model to obtain word vectors with contextual semantics;

[0034] Assembly code mnemonics are a finite set. Directly feeding raw assembly code into a neural network for semantic training may result in some words not in the vocabulary. Furthermore, a register in the assembly code can be replaced by another register of the same type without changing the semantics. To address this issue, the following measures are adopted:

[0035] The constants in the assembly code are divided into five categories, namely immediate values, addresses, variable names, function names and basic block labels, which are replaced by the characters 'IMM', 'ADDRESS', 'VAR', 'FUNC' and 'BB' respectively.

[0036] Registers in the x86 are divided into 14 categories, including pointer registers, floating-point registers, four general-purpose registers, four data registers, and four address registers. General-purpose registers, data registers, and address registers are divided into four types based on the length of the data they store: 8-bit, 16-bit, 32-bit, and 64-bit. ARM registers are divided into two categories: general-purpose registers and pointer registers. One-hot encoding is used to assign the same encoding to registers with the same function.

[0037] The BERT model structure is divided into three parts, namely Embeddings, Bert and output vector; the Embeddings layer is composed of word vectors Token Embeddings, function boundary vectors function embeddings, and position information vectors Position Embeddings to form a word vector representation of a single mnemonic; Bert as a whole is composed of multiple TransformerEncoders superimposed, and finally outputs a word vector containing contextual semantics; the function boundary vector includes non-function boundary E M , function starting address E S and function end address E E , the modified embedding vector contains the information of whether it is a binary boundary.

[0038] There are two training tasks in the pre-training process. One is the mask prediction task of Token Embeddings, which masks 15% of the tokens and predicts the masked part. The output result is compared with the Token Embeddings before masking, and the cross entropy is calculated as loss_mask; the other training task is the function boundary prediction task, that is, adding a linear layer and a softmax layer after the embedding vector of each token, comparing the output result with the function embeddings, and calculating the cross entropy as loss_func; the final cross entropy loss = loss_mask + loss_func, and the Adam optimizer is used to minimize the cross entropy loss; the pre-trained BERT model will output word vectors with contextual semantics.

[0039] Step 3: Retrain the pre-trained BERT model to obtain a model that can determine whether an assembly instruction is a function boundary;

[0040] In step 3, the assembly code is input into the pre-trained BERT model to obtain an embedding vector for each token. The embedding vector is input into a linear layer and a softmax layer, compared with the correct function label, and the cross entropy is calculated as loss_func. The Adam optimizer is used to minimize loss_func to obtain a model that can determine whether the assembly instruction is a function boundary.

[0041] Step 4: Input the assembly code into the trained function boundary judgment model to perform binary function boundary detection.

[0042] The present invention also proposes a binary function boundary detection system based on semantic features. Binary code is disassembled to obtain assembly code, which is composed of assembly instructions. The assembly instructions are composed of a mnemonic and n operators, where n ≥ 0. The system includes:

[0043] Dataset construction module: used to construct an assembly code dataset containing function boundary markers;

[0044] Pre-training module: used to use the BERT model to pre-train the dataset to obtain word vectors with contextual semantics;

[0045] Optimization module: used to retrain the pre-trained BERT model to obtain a model that can determine whether an assembly instruction is a function boundary;

[0046] Detection module: used to input assembly code into the trained function boundary judgment model to perform binary function boundary detection.

[0047] The present invention further provides an electronic device, comprising:

[0048] at least one processor; and,

[0049] a memory communicatively connected to the at least one processor; wherein,

[0050] The memory stores instructions that can be executed by the at least one processor. The instructions are executed by the at least one processor to enable the at least one processor to perform the binary function boundary detection method based on semantic features.

[0051] The above is a detailed introduction to the binary function boundary detection method, system and electronic device based on semantic features proposed in the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea; at the same time, for general technical personnel in this field, based on the ideas of the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.

Claims

1. Binary function boundary detection method based on semantic features. Binary code is disassembled to obtain assembly code, which is composed of assembly instructions. Assembly instructions are composed of a mnemonic and n operators, where n ≥ 0. Features: The method comprises: Step 1: Construct an assembly code dataset containing function boundary markers; Step 2: Use the dataset to pre-train the BERT model to obtain word vectors with contextual semantics; Step 3: Train the pre-trained BERT model again to obtain a model that can determine whether an assembly instruction is a function boundary; Step 4: Input the assembly code into the trained function boundary judgment model to perform binary function boundary detection; The BERT model structure is divided into three parts, namely Embeddings, Bert and output vector; the Embeddings layer is composed of word vectors Token Embeddings, function boundary vectors function embeddings, and position information vectors PositionEmbeddings to form a word vector representation of a single mnemonic; Bert as a whole is composed of multiple Transformer Encoders superimposed, and finally outputs a word vector containing contextual semantics; the function boundary vector includes non-function boundary E M , function starting address E S and function end address E E ; There are two training tasks in the pre-training process. One is the mask prediction task of Token Embeddings, which masks 15% of the tokens and predicts the masked parts. The output results are compared with the Token Embeddings before masking, and the cross entropy is calculated as loss_mask. The other training task is the function boundary prediction task, which adds a linear layer and a softmax layer after the embedding vector of each Token, compares the output results with the function embeddings, and calculates the cross entropy as loss_func. The final cross entropy loss = loss_mask + loss_func, and the Adam optimizer is used to minimize the cross entropy loss. The pre-trained BERT model will output word vectors with contextual semantics.

2. The method according to claim 1, Features: The step 1 is specifically as follows: The collected binary code is disassembled through IDApro to obtain the function start address and end address. Then, the disassembled assembly code is marked with function boundaries in units of instructions, that is, whether the assembly instruction is the start of a function, the end of a function, or a non-function boundary, which is a total of three categories. Finally, the assembly code is randomly segmented to obtain an assembly code data set containing function boundary markers.

3. The method according to claim 1, Features: In step three, the assembly code is input into the pre-trained BERT model, an embedding vector is obtained for each Token, and the embedding vector is input into a linear layer and a softmax layer, compared with the correct function label, the cross entropy is calculated as loss_func, and the Adam optimizer is used to minimize loss_func to obtain a model that can determine whether the assembly instruction is a function boundary.

4. The method according to claim 1, Features: The constants in the assembly code are divided into five categories, namely, immediate values, addresses, variable names, function names and basic block labels, which are replaced by the characters 'IMM', 'ADDRESS', 'VAR', 'FUNC' and 'BB' respectively.

5. A binary function boundary detection system based on semantic features. The binary code is disassembled to obtain the assembly code, which is composed of assembly instructions. The assembly instruction is composed of a mnemonic and n operators, where n≥0. Features: The system comprises: Dataset construction module: used to construct an assembly code dataset containing function boundary markers; Pre-training module: used to use the BERT model to pre-train the data set to obtain word vectors with contextual semantics; Optimization module: used to retrain the pre-trained BERT model to obtain a model that can determine whether an assembly instruction is a function boundary; Detection module: used to input the assembly code into the trained function boundary judgment model to perform binary function boundary detection; The BERT model structure is divided into three parts, namely Embeddings, Bert and output vector; the Embeddings layer is composed of word vectors Token Embeddings, function boundary vectors function embeddings, and position information vectors PositionEmbeddings to form a word vector representation of a single mnemonic; Bert as a whole is composed of multiple Transformer Encoders superimposed, and finally outputs a word vector containing contextual semantics; the function boundary vector includes non-function boundary E M , function starting address E S and function end address E E ; There are two training tasks in the pre-training process. One is the mask prediction task for Token Embeddings, which masks 15% of the tokens and predicts the masked parts. The output is compared with the tokens before masking. Embeddings are compared and the cross entropy is calculated as loss_mask; another training task is the function boundary prediction task, that is, a linear layer and a softmax layer are added after the embedding vector of each Token, the output result is compared with the function embeddings, and the cross entropy is calculated as loss_func; the final cross entropy loss = loss_mask + loss_func, and the Adam optimizer is used to minimize the cross entropy loss; the pre-trained BERT model will output word vectors with contextual semantics.

6. An electronic device, It is characterized in that The electronic device comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the binary function boundary detection method based on semantic features as described in any one of claims 1-4.