Reverse control flow planarization method and device based on firmware security, and storage medium
By inputting the control flow flattened target code into an external knowledge base and utilizing a large language model, the problem of being unable to accurately restore the control flow flattened code in the existing technology is solved, and more accurate source code generation is achieved.
Patent Information
- Application Number
- CN202410664351.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-27
- Publication Date
- 2024-10-29
AI Technical Summary
The existing technology cannot accurately restore the control flow flattening code, resulting in the inability to accurately obtain the source code.
By inputting the target code of control flow flattening into the external knowledge base, and using the large language model to generate the target source code of anti-control flow flattening, combining the external knowledge base and the trained large language model, the large language model can improve the program document knowledge. understanding and accuracy.
It effectively improves the use of program document knowledge by large language models, generates more accurate source code, and solves the problem of large language models being unable to obtain information other than the model training data set.
Smart Images

Figure CN118862025A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of software security technology, for example, to a firmware security-based anti-control flow flattening method, device and computer-readable storage medium. Background Art
[0002] Generally speaking, publicly released software (including software built into hardware) uses certain encryption and obfuscation methods to prevent users from decompiling and analyzing the program, thereby achieving the purpose of preventing the program logic from being leaked. Control flow flattening is a code obfuscation technology that acts on the control flow graph. Its basic idea is to reorganize the basic block relationship in the control flow graph of the function and control the execution flow of the basic block by inserting a "main distributor". Figure 1 This is the normal execution flow chart of the software. After the control flow is flattened, the attached Figure 2 By flattening the control flow, the context between basic blocks will be obfuscated, making reverse analysis of the program more difficult.
[0003] A binary deobfuscation method is disclosed in the related art, including constructing a pseudocode model in an obfuscation mode; obtaining a binary file, and decompiling the binary file using a compilation tool to construct a binary pseudocode model in the obfuscation mode; using the data structure of the decompilation tool to construct an instruction graph and control block information of the binary file; using the binary pseudocode model in the obfuscation mode to search for obfuscated code in the instruction graph and control block information, and removing the obfuscated code.
[0004] In the process of implementing the embodiments of the present disclosure, it is found that there are at least the following problems in the related art:
[0005] The related technology removes the obfuscated code, but cannot accurately obtain the control flow of the source code, and thus cannot accurately restore the control flow flat code.
[0006] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present application, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention
[0007] In order to provide a basic understanding of some aspects of the disclosed embodiments, a brief summary is given below. The summary is not an extensive review, nor is it intended to identify key / critical components or delineate the scope of protection of these embodiments, but rather serves as a prelude to the detailed description that follows.
[0008] The embodiments of the present disclosure provide a firmware-safe anti-control flow flattening method, device, and computer-readable storage medium to improve the accuracy of restoring control flow flattening code.
[0009] In some embodiments, the method includes: inputting the control flow flattened target code into an external knowledge base to obtain an interpretation of the program document corresponding to the target code; the external knowledge base is constructed based on the same type of program document corresponding to the target code; the control flow flattened target code and the interpretation of the program document corresponding to the target code are input into a trained large language model to generate a target source code for reverse control flow flattening.
[0010] In some embodiments, the apparatus includes: a processor and a memory storing program instructions, wherein the processor is configured to execute the aforementioned method for firmware anti-control flow flattening when running the program instructions.
[0011] In some embodiments, the computer-readable storage medium stores program instructions, and when the program instructions are executed, the computer executes the aforementioned method for firmware anti-control flow flattening.
[0012] The firmware security-based anti-control flow flattening method, device, and computer-readable storage medium provided by the embodiments of the present disclosure can achieve the following technical effects:
[0013] In the disclosed embodiment, an external knowledge base is used to assist the large language model in understanding the control flow flattened target code and interpret the target code. Then, based on the large language model, the target source code of the control flow flattened target code is obtained. On the one hand, the large language model is offline and cannot obtain information outside the model training data set; the use of an external knowledge base effectively solves this problem and improves the use of program document knowledge by the large language model. On the other hand, the external knowledge base can also assist the large language model in understanding the target code, so that the large language model can generate more accurate source code.
[0014] The above general description and the following description are exemplary and explanatory only and are not intended to limit the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] One or more embodiments are exemplarily described by corresponding drawings, which do not limit the embodiments. Elements with the same reference numerals in the drawings are shown as similar elements, and the drawings do not constitute a scale limitation, and wherein:
[0016] Figure 1 It is a schematic diagram of a normal execution flow chart of software in the prior art provided by an embodiment of the present disclosure;
[0017] Figure 2 It is a control flow graph after code control flow flattening processing in the prior art provided by an embodiment of the present disclosure;
[0018] Figure 3 is a schematic diagram of an anti-control flow flattening method based on firmware security provided by an embodiment of the present disclosure;
[0019] Figure 4 is a schematic diagram of a method for constructing an external knowledge base in the method of an embodiment of the present disclosure;
[0020] Figure 5 is a schematic diagram of a method for obtaining a trained large language model in a method of an embodiment of the present disclosure;
[0021] Figure 6 is a schematic diagram of an anti-control flow flattening method based on firmware security provided by an embodiment of the present disclosure;
[0022] Figure 7 It is a schematic diagram of an anti-control flow flattening device based on firmware security provided by an embodiment of the present disclosure. DETAILED DESCRIPTION
[0023] In order to be able to understand the features and technical contents of the embodiments of the present disclosure in more detail, the implementation of the embodiments of the present disclosure is described in detail below in conjunction with the accompanying drawings. The attached drawings are for reference only and are not used to limit the embodiments of the present disclosure. In the following technical description, for the convenience of explanation, a full understanding of the disclosed embodiments is provided through multiple details. However, one or more embodiments can still be implemented without these details. In other cases, to simplify the drawings, well-known structures and devices can be simplified for display.
[0024] The terms "first", "second", etc. in the specification and claims of the embodiments of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchanged where appropriate, so that the embodiments of the embodiments of the present disclosure described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions.
[0025] Unless otherwise stated, the term "plurality" means two or more.
[0026] In the embodiment of the present disclosure, the character " / " indicates that the preceding and following objects are in an "or" relationship. For example, A / B indicates: A or B.
[0027] The term "and / or" is a description of the association relationship between objects, indicating that three relationships can exist. For example, A and / or B means: A or B, or, A and B.
[0028] The term "correspondence" may refer to an association relationship or a binding relationship. The correspondence between A and B means that there is an association relationship or a binding relationship between A and B.
[0029] Firmware is a specific computer software embedded in hardware devices / various electronic devices, which is used to control the hardware / electronic devices and is responsible for realizing the basic functions of the hardware / electronic devices.
[0030] Combination Figure 3 As shown, the embodiment of the present disclosure provides an anti-control flow flattening method based on firmware security, including:
[0031] S101, the processor inputs the target code with control flow flattening into an external knowledge base to obtain an interpretation of the program document corresponding to the target code; the external knowledge base is constructed based on the program document of the same language type corresponding to the target code.
[0032] S102, the processor inputs the control flow flattened target code and the interpretation of the target code into the trained large language model to generate a reverse control flow flattened target source code.
[0033] Here, the target code of control flow flattening refers to the API (Application Programming Interface) document of the firmware code, and the code obtained by control flow flattening. The API document of the firmware code includes assembly language, C language, high-level language and other languages. The external knowledge base is constructed based on the program document of the same language type corresponding to the target code to be detected, and the language type is such as assembly language, C++ language, etc. In this way, after the target code of control flow flattening is input into the external knowledge base, the explanation of the program document corresponding to the target code can be queried. Among them, the explanation of the program document refers to the explanation of the original logic and function of the target code. In addition, the external knowledge base also provides a lot of background knowledge and contextual knowledge, and the explanation of the degree document can also include this part of the content. It can be understood that the front and back relationships of each basic block of the target code of control flow flattening are confused, but the logic and function behind the code remain unchanged. The explanation of the program document helps the large language model understand the code, so that the source code can be accurately predicted.
[0034] Therefore, after obtaining the interpretation of the program document corresponding to the target code, the target code with flattened control flow and the interpretation of the target code are input into the trained large language model; the large language model outputs the result, that is, the generated target source code. Among them, the large language model is a type of deep learning model with a large number of parameters. The model is pre-trained on a large amount of text data to learn the complex structure and patterns of the language. Large language models include GPT (Generative Pre-trained Transformer), BERT (Bidirectional Encoder Representations from Transformers), etc. The corresponding large language model can be reasonably selected based on needs. With the assistance of the program document interpretation, the large language model can more accurately obtain the relevant API information in the source code, thereby improving the understanding of the large language model to produce more accurate source code.
[0035] The anti-control flow flattening method based on firmware security provided by the embodiment of the present disclosure is adopted, and the large language model is assisted in understanding the control flow platform target code based on the external knowledge base, and the target code is interpreted. Then, based on the large language model, the target source code of the control flow flattened target code is obtained. On the one hand, due to its offline nature, the large language model cannot obtain information outside the model training data set; and the use of the external knowledge base effectively solves this problem and improves the use of the large language model for program document knowledge. On the other hand, the external knowledge base can also assist the large language model in understanding the target code, so that the large language model can generate more accurate source code.
[0036] Combination Figure 4 Optionally, in step S101, the processor constructs an external knowledge base in the following manner:
[0037] S111, the processor obtains the original text of the same type of program document corresponding to the target code.
[0038] S112, the processor divides the original text of the program document into blocks to obtain text blocks.
[0039] S113, the processor encodes the text block into a vector embedding, and stores the vector embedding in a vector database to construct an external knowledge base.
[0040] Here, if the target code is a C language API document, the original text (such as English text) of the C language API document is collected. The original text of the C language API document may include multiple versions, and optimally, the original text of the C language API document includes at least the text of the latest version. Because the latest version of the program document will introduce new features, if the control flow flattening code to be restored uses new features, then the constructed external library can recognize and correctly interpret these new features when interpreting the code.
[0041] Furthermore, the original text of the program document is divided into blocks. On the one hand, for large language models, the input window size is limited; the text block can accurately reflect the specific content in the block, which can improve the accuracy of embedding. On the other hand, the information source of the code is in this text block rather than the full text, and text block analysis can prevent important information from being diluted by the entire extensive document content. In addition, the text block segmentation can be based on specific rules (such as special characters), or can be divided based on pre-trained models, etc.
[0042] Finally, each text block is encoded as a vector embedding. Vector embedding serves as a "numerical representation" of the meaning of each text block. Although a long paragraph or a complex concept in a text block is compressed into a simple series of numbers, the series still retains the key information of the original text. Vector embedding converts complex text data into a numerical form that is easy for computers to process, thereby ensuring that the large language model can read it. Among them, models such as BERT or GPT can be used for embedding. In the embodiment of the present disclosure, OpenAI's text-embedding-ada-002 model is preferably used for embedding. This model is a pre-trained model that can output a 1536-dimensional vector to represent the input text block, and the embedding effect of this model is better. Vector storage is a database that can perform vector embedding storage. As an example, ChromaDB can be used as a vector database that efficiently stores and retrieves text embeddings. Storing text embeddings in a vector database allows for quick similarity searches. Thereby querying the text block that is most relevant to the input embedding semantics.
[0043] Optionally, in step S113, the external knowledge base also includes a retriever.
[0044] Here, the retriever is used to perform a retrieval operation, that is, to create an index on the vector database. The retriever compares the question vector to be retrieved with the vectors in the vector database, and feeds back the vector with the highest similarity, thereby obtaining the API information corresponding to the vector. Among them, the retriever can be a vector storage retriever, a semantic retriever, a database retriever, and so on. As an example, the retriever is Langchain's VectorStoreRetriever retriever.
[0045] Optionally, in step S112, the processor divides the original text of the program document into blocks to obtain text blocks, including:
[0046] The processor uses the determined tokenizer to segment the original text and obtains tokens and the token numbers corresponding to the tokens.
[0047] The processor determines the size of the target block based on the number of tokens.
[0048] The processor divides the original text into blocks according to the size of the target block and the specific characters to obtain the text blocks.
[0049] Here, the text can be segmented with the help of a tagger (such as a tagger using a GPT model) to form tokens. The size of the token can be the size of a word or the size of a subword. In the embodiment of the present disclosure, the token size is a subword unit, and the subword can be a part of a word, a whole word, or a combination of multiple words. Among them, the subword unit is constructed by repeatedly merging the most frequently occurring character pairs in the text, so as to gradually expand the vocabulary; and then the original text is segmented based on the vocabulary. After obtaining the token, the number of tokens, that is, the number of tokens, can be counted. For a large language model, the input window size is limited (such as the maximum input token length of a certain model is 4096 tokens). And the size of the number of input tokens will affect the context information of the program document, and will also affect the performance and response speed of the model. For this reason, the size of the target block is determined according to the number of tokens. The target block refers to dividing the original text of the program document into blocks that do not exceed the size of the target block. Further, the original text is divided into blocks according to the size of the target block and the specific characters. Among them, the specific characters can be determined by the original text. As an example, in order to avoid segmenting the context information, the escape character can be used as a specific character. This ensures the integrity of contextual information and improves understanding of the text block.
[0050] Optionally, the processor divides the original text into blocks according to the size of the target block and the specific characters to obtain the text blocks, including:
[0051] The processor preliminarily divides the original text into blocks according to specific characters to obtain initial text blocks;
[0052] When the size of the initial text block is larger than the size of the target block, the processor divides the initial text block again according to the size of the target block to obtain a final text block.
[0053] Here, in order to ensure that the original text context information is not segmented as much as possible, the original text is first segmented using specific characters to obtain the initial text block. Then, it is further determined whether the initial text block exceeds the size of the target block. If it exceeds the size of the target block, even if the initial text cutting will affect the understanding of the text, the initial text block will be forced to be cut so that its size is less than or equal to the size of the target block. In addition, if the size of the initial text block does not exceed the size of the target block, the initial text block is not the final text block. In this way, the damage to the semantic integrity of the original text is minimized and text segmentation is achieved.
[0054] Optionally, in step S113, after the processor builds the external knowledge base, the process further includes:
[0055] In case the programming language standard of the program documentation is updated, the processor updates the external knowledge base.
[0056] Understandably, the large language model can only access information in the training data set during training, and cannot obtain new information outside the training data set. And the large language model is an offline model after training, but once the language standard of the program document is updated, it will affect the accuracy of the large language model prediction. Therefore, the external knowledge base is updated in real time to follow the latest version of the C language standard. Thereby ensuring that the source code interpretation process after deflattening is always synchronized with the latest language standard. Among them, the programming language standard update of the corresponding program document can be detected periodically or non-periodically so as to update the external knowledge base in time.
[0057] Combination Figure 5 Optionally, in step S102, the processor obtains the trained large language model by:
[0058] S121, the processor constructs a training data set using the source code of the program document and the corresponding control flow flattening code.
[0059] S122, the processor optimizes the CodeGen base model based on the training data set and low-rank adaptive technology.
[0060] S123, when the cross entropy loss function characterization of the optimized CodeGen base model meets the requirements, the processor uses the optimized CodeGen base model as the trained large language model.
[0061] Here, the large language model includes the CodeGen base model, which is a large language model for code generation, so that the accuracy of restoring the control flow flattened code is further improved. The CodeGen base model is fine-tuned to obtain a trained model. Specifically, a training data set is established. The source code of the program document is a program document of the same type as the target code. For example, the source code of the C language API document can be obtained from the C language open source software library, and then the OLLVM (Obfuscator-Low-Level Virtual Machine, obfuscation compiler) tool is used to flatten the control flow of the selected source code to generate the obfuscated code, that is, the control flow flattened code. In this way, the control flow flattened code is used as the input of the model, and the source code is used as the target output to construct a training data set. It can be understood that the number of samples in the training data set needs to be sufficient.
[0062] Furthermore, the CodeGen base model is optimized based on the training data set and low-rank adaptive technology. Here, the control flow flattening code is restored based on the CodeGen base model, in which the obfuscation of the control flow structure is the key. The optimization model is also mainly to make the model focus on the control flow pattern rather than other changes in the code. In detail, the data samples in the data set are analyzed, and the structural features of the control flow in the samples are converted into low-rank features. The model is then trained based on the supervised learning method, so that the model uses low-rank features to reconstruct the control flow structure of the source code. In the process of optimizing the model, the loss function is used to measure the similarity of the model prediction; when the loss function characterizes the model prediction similarity to meet the requirements, the model optimization is completed. Otherwise, continue to optimize and supervise the fine-tuning of the model parameters and training strategies.
[0063] Optionally, in step S122, the processor optimizes the CodeGen base model based on the training data set and the low-rank adaptive technology, including:
[0064] Processor analysis identifies key features of control flattening code in a training set database, and the key features characterize the control flow structure of the control flow flattening code.
[0065] The processor uses low-rank adaptation technology to construct key features into a low-rank feature space.
[0066] The processor optimizes the CodeGen basis model based on the low-rank feature space.
[0067] Here, the code samples of control flow flattening are analyzed to identify the key features in the control flow structure. As an example, the key features include the pattern of analysis logic, the sequence of virtual instructions, etc. Then, these key features are compressed to generate a low-rank feature space using low-rank adaptive technology. The low-rank feature space is used to capture the confusion and recovery mode of the control flow. For large models, the low-rank feature space can increase the calculation rate and also retain the semantic information of high-dimensional features. Then, based on the low-rank feature space, the CodeGen base model is optimized. Among them, the model uses the fine structure in the low-rank feature space to reconstruct the control flow graph to obtain the source code predicted by the model. According to the predicted source code and the actual source code, the model is supervised and fine-tuned (the adjustment content includes the adjustment of hyperparameters, the improvement of training strategies, and the fine-tuning of loss functions, etc.) to make the similarity between the predicted source code and the actual source code meet the requirements. Among them, during the fine-tuning process, it is sufficient to ensure that the features of the low-rank feature space can accurately correspond to the control flow structure in the source code.
[0068] Optionally, the processor optimizes the CodeGen basis model according to the low-rank feature space, including:
[0069] The processor uses the low-rank feature space and the CodeGen basis model to output the predicted source code.
[0070] The processor optimizes the parameters and loss function of the CodeGen base model based on the difference between the predicted source code and the actual source code.
[0071] Here, the CodeGen base model reconstructs the control flow structure based on the low-rank feature space to output the predicted source code. The model is optimized based on the difference between the predicted source code and the actual source code. The cross entropy loss function can be used to measure the difference between the predicted source code and the actual source code. When the value of the cross entropy loss function is close to the minimum value and tends to be stable, it indicates that the difference is small. At this point, the model optimization ends. Otherwise, continue to optimize the model parameters and loss function until the value of the cross entropy loss function meets the above requirements.
[0072] Combination Figure 6 As shown, the embodiment of the present disclosure provides another anti-control flow flattening method based on firmware security, including:
[0073] S201, the processor processes the control flow flattened target code to obtain a corresponding target vector embedding.
[0074] S202, the processor embeds the target vector into an external knowledge base to obtain an interpretation of a program document corresponding to the target vector embedding; the external knowledge base is constructed based on a program document of the same language type corresponding to the target code.
[0075] S203, the processor embeds the target vector and the corresponding interpretation into the trained large language model to generate the target source code for anti-control flow flattening.
[0076] Here, before the target code with control flow flattening is input into the external knowledge base and the trained large language model, the target code needs to be preprocessed. As mentioned above, the external knowledge base is retrieved through a vector retriever, so the input content should be a vector. Therefore, before retrieval, the target code is preprocessed to obtain a vector embedding. The steps for obtaining the vector embedding can be found in the previous article, that is, the target code is text segmented, encoded into a vector embedding, etc. At the same time, as mentioned above, the input window size of the large model is also limited, and the complete document may not be input. Therefore, it is also necessary to perform text segmentation on the target code and encode the text block into a vector embedding. The target vector embedding corresponding to the target code is input into the external knowledge base and the trained large language model to obtain the source code and explain the source code for the anti-control flow flattening.
[0077] Combination Figure 7As shown, an embodiment of the present disclosure provides an anti-control flow flattening device 100 based on firmware security, including a processor 101 and a memory 102. Optionally, the device 100 may also include a communication interface 103 and a bus 104. Among them, the processor 101, the communication interface 103, and the memory 102 can communicate with each other through the bus 104. The communication interface 103 can be used for information transmission. The processor 101 can call the logic instructions in the memory 102 to execute the method for firmware anti-control flow flattening of the above embodiment.
[0078] In addition, the logic instructions in the memory 102 described above may be implemented in the form of software functional units and when sold or used as independent products, may be stored in a computer-readable storage medium.
[0079] The memory 102 is a computer-readable storage medium that can be used to store software programs and computer executable programs, such as program instructions / modules corresponding to the method in the embodiment of the present disclosure. The processor 101 executes functional applications and data processing by running the program instructions / modules stored in the memory 102, that is, the anti-control flow flattening method for firmware security in the above embodiment is implemented.
[0080] The memory 102 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application required for at least one function; the data storage area may store data created according to the use of the terminal device, etc. In addition, the memory 102 may include a high-speed random access memory and may also include a non-volatile memory.
[0081] The embodiments of the present disclosure provide an electronic device, including: a device body, and the above-mentioned anti-control flow flattening device 100 based on firmware security. The anti-control flow flattening device 100 based on firmware security is installed on the electronic device body. The installation relationship described here is not limited to placement inside the product body, but also includes installation connections with other components of the electronic device, including but not limited to physical connections, electrical connections, or signal transmission connections. It can be understood by those skilled in the art that the device 100 for firmware anti-control flow flattening can be adapted to a feasible electronic device body, thereby realizing other feasible embodiments.
[0082] An embodiment of the present disclosure provides a computer-readable storage medium storing computer-executable instructions, wherein the computer-executable instructions are configured to execute the above-mentioned firmware security-based anti-control flow flattening method.
[0083] The technical solution of the embodiment of the present disclosure can be embodied in the form of a software product, which is stored in a storage medium and includes one or more instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in the embodiment of the present disclosure. The aforementioned storage medium may be a non-transient storage medium, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, and other media that can store program codes.
[0084] The above description and the accompanying drawings fully illustrate the embodiments of the present disclosure so that those skilled in the art can practice them. Other embodiments may include structural, logical, electrical, process and other changes. The embodiments represent only possible changes. Unless explicitly required, separate components and functions are optional, and the order of operation may vary. The parts and features of some embodiments may be included in or replace the parts and features of other embodiments. Moreover, the words used in this application are only used to describe the embodiments and are not used to limit the claims. As used in the description of the embodiments and the claims, unless the context clearly indicates, the singular forms of "a", "an" and "the" are intended to include plural forms as well. Similarly, the term "and / or" as used in this application refers to any and all possible combinations of listings containing one or more associated ones. In addition, when used in the present application, the term "comprise" and its variants "comprises" and / or comprising refer to the presence of stated features, wholes, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or groups thereof. In the absence of further restrictions, the elements defined by the sentence "comprising a ..." do not exclude the presence of other identical elements in the process, method or device comprising the elements. In this article, each embodiment may focus on the differences from other embodiments, and the same and similar parts between the various embodiments may refer to each other. For the methods, products, etc. disclosed in the embodiments, if they correspond to the method part disclosed in the embodiments, then the relevant parts can refer to the description of the method part.
[0085] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software may depend on the specific application and design constraints of the technical solution. The technicians may use different methods for each specific application to implement the described functions, but such implementations should not be considered to exceed the scope of the embodiments of the present disclosure. The technicians may clearly understand that, for the convenience and simplicity of description, the specific working processes of the systems, devices and units described above may refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here.
[0086] In the embodiments disclosed herein, the disclosed methods and products (including but not limited to devices, equipment, etc.) can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units can be only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between each other shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms. The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the units may be selected according to actual needs to implement this embodiment. In addition, each functional unit in the embodiment of the present disclosure may be integrated in a processing unit, or each unit may exist physically alone, or two or more units may be integrated in one unit.
[0087] The flowchart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to the embodiment of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of the code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. In some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, which can depend on the functions involved. In the description corresponding to the flowchart and the block diagram in the accompanying drawings, the operations or steps corresponding to different boxes can also occur in a different order from the order disclosed in the description, and sometimes there is no specific order between different operations or steps. For example, two consecutive operations or steps can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, which can depend on the functions involved. Each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented by a dedicated hardware-based system that performs the specified functions or actions, or may be implemented by a combination of dedicated hardware and computer instructions.
Claims
1. A firmware security-based anti-control flow flattening method, characterized in that: include: Input the target code with control flow flattening into the external knowledge base to obtain the explanation of the program document corresponding to the target code; The external knowledge base is built based on the same type of program documentation corresponding to the target code; The control flow flattened target code and the interpretation of the target code corresponding to the program document are input into the trained large language model to generate the anti-control flow flattened target source code.
2. The method according to claim 1, characterized in that Build an external knowledge base by: Obtain the original text of the same type of program document corresponding to the target code; Divide the original text of the program document into blocks to obtain the text blocks; The text blocks are encoded into vector embeddings and stored in a vector database to build an external knowledge base.
3. The method according to claim 2, characterized in that Divide the original text of the program document into blocks to obtain the text blocks, including: Use the determined tokenizer to segment the original text and obtain tokens and the number of tokens corresponding to the tokens; According to the number of tokens, the size of the target block is determined; According to the size of the target block and the specific characters, the original text is divided into blocks to obtain the text blocks.
4. The method according to claim 3, characterized in that According to the size of the target block and specific characters, the original text is divided into blocks to obtain the text blocks, including: According to specific characters, the original text is preliminarily divided into blocks to obtain initial text blocks; When the size of the initial text block is larger than the size of the target block, the initial text block is segmented again according to the size of the target block to obtain a final text block.
5. The method according to claim 2, characterized in that: After storing the vector embedding in the vector database to build an external knowledge base, it also includes: Update external knowledge bases in case of updates to programming language standards for program documentation.
6. The method according to any one of claims 1 to 5, characterized in that: Get the trained large language model by: Construct a training data set using the source code of the program documentation and the corresponding control flow flattening code; Optimize the CodeGen base model based on the training dataset and low-rank adaptive technology; When the cross entropy loss function characterizes the optimized CodeGen base model and meets the requirements, the optimized CodeGen base model is used as the trained large language model.
7. The method according to claim 6, characterized in that Based on the training dataset and low-rank adaptive technology, the CodeGen base model is optimized, including: Analyze and identify key features of control flattening codes in the training set database, where the key features represent the control flow structure of the control flow flattening codes; Use low-rank adaptive technology to construct key features into a low-rank feature space; Optimize the CodeGen basis model based on the low-rank feature space.
8. The method according to claim 7, characterized in that According to the low-rank feature space, the CodeGen base model is optimized, including: Using low-rank feature space and CodeGen basis model, output the predicted source code; According to the difference between the predicted source code and the actual source code, the parameters and loss function of the CodeGen base model are optimized.
9. A firmware-safe anti-control flow flattening device, comprising a processor and a memory storing program instructions, characterized in that: The processor is configured to execute the firmware security-based anti-control flow flattening method as described in any one of claims 1 to 8 when running the program instructions.
10. A computer-readable storage medium storing program instructions, characterized in that: When the program instructions are executed, the computer is used to execute the firmware security-based anti-control flow flattening method as described in any one of claims 1 to 8.
