A program feature representation method and device, electronic equipment and storage medium
By generating logical feature representation maps through program representation models, the problem of inconsistent representation forms of program logic vulnerabilities written in different programming languages is solved, and theoretical support is provided for logical vulnerability cause analysis and migration mining.
Patent Information
- Application Number
- CN202310188066.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-24
- Publication Date
- 2026-11-20
- Estimated Expiration
- 2043-02-24
AI Technical Summary
In existing technologies, the representation of logical vulnerabilities in programs written in different programming languages is not uniform, making it difficult to perform direct transfer comparison and analysis.
By extracting features from the program to be represented using a program representation model, a logical feature representation graph is generated, revealing the similar logical essence of different programming languages, and then using a unified representation model for analysis and representation.
It provides theoretical support for the analysis of the causes of program logic vulnerabilities in different programming languages and for migration mining, and provides the possibility of direct migration comparison.
Smart Images

Figure CN116149626B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and more specifically, to a method, apparatus, electronic device, and storage medium for representing program features. Background Technology
[0002] Currently, as logical vulnerabilities are increasingly becoming a focus of security analysis, their formal representation and analysis have also become key issues. Given the large volume of target code for vulnerability discovery, making it difficult to simply rely on manually searching and analyzing triggering logic to find vulnerabilities, the industry is generally attempting to use automated analysis methods to find potential logical vulnerability trigger points and exploit paths.
[0003] However, the current forms of representing logical vulnerabilities are often highly coupled with the programming language architecture used by the system where the logical vulnerability is located. Therefore, there are problems such as inconsistent deep logical feature representations of programs written in different programming languages and the inability to directly transfer and compare intermediate representations. Summary of the Invention
[0004] The purpose of this application is to provide a method, apparatus, electronic device, and storage medium for representing program features, so as to represent the deep logical features of programs written in different programming languages by analyzing the logical features of the program to be represented and using a unified representation model.
[0005] In a first aspect, embodiments of this application provide a method for representing program features. The method includes: extracting features from a program to be represented using a program representation model to obtain a logical feature representation graph; wherein the nodes of the logical feature representation graph represent the data logic structure of the program to be represented, and the edges of the logical feature representation graph represent the execution logic structure of the program to be represented; analyzing the logical feature representation graph using the program representation model to output the program feature representation result of the program to be represented; wherein the program representation model is generated by pre-extracting features from sample representation features to generate a sample logical feature graph, and generating the graph based on the sample logical feature graph.
[0006] In the technical solution of this application embodiment, by using a program representation model to analyze and represent the logical feature representation diagram of the program to be represented, logical feature representation diagrams can be generated for programs written in different programming languages by extracting their data logic structure and execution logic structure. These logical feature representation diagrams reveal the similar logical essence implicit in different programming languages, enabling direct transfer comparison between different programming languages, thereby providing theoretical support for downstream tasks such as logical vulnerability cause analysis and transfer mining.
[0007] In some embodiments, feature extraction of the program to be represented by a program representation model is performed to obtain a logical feature representation map, including: extracting the data logic structure and execution logic structure of the program to be represented by the program representation model; and generating a logical feature representation map based on the data logic structure and execution logic structure.
[0008] This application embodiment generates a logical feature representation map based on the extracted data logic structure and execution logic structure of the program to be represented, so that the logical feature representation map can reflect the logical structure features of the program to be represented in multiple ways.
[0009] In some embodiments, the data logical structure includes a file level, a class level, a function level, and a statement level; generating a logical feature representation diagram based on the data logical structure and the execution logical structure includes: generating a first logical feature diagram of the file level of the program to be represented based on the file level and the execution logical structure of the file level; generating a second logical feature diagram of the class level of the program to be represented based on the class level and the execution logical structure of the class level; generating a third logical feature diagram of the function level of the program to be represented based on the function level and the execution logical structure of the function level; generating a fourth logical feature diagram of the statement level of the program to be represented based on the statement level and the execution logical structure of the statement level; and generating a logical feature representation diagram based on the first logical feature diagram, the second logical feature diagram, the third logical feature diagram, and the fourth logical feature diagram.
[0010] This application's embodiments subdivide the data logic structure into multiple levels and generate a logic feature map for each level. Based on the logic feature maps of each level, a logic feature representation map is generated, enabling the map to reflect the logical structure characteristics of each level of the program to be represented and the relationships between these levels. This provides a more intuitive representation of the internal logical features of the program. Furthermore, it allows different programming languages to achieve a unified language-independent abstract logical expression at the file level, class level, function level, and statement level.
[0011] In some embodiments, generating a logical feature representation map based on a first logical feature map, a second logical feature map, a third logical feature map, and a fourth logical feature map includes: removing contradictory logical features among the first logical feature map, the second logical feature map, the third logical feature map, and the fourth logical feature map to obtain a logical feature representation map of the program to be represented; wherein, contradictory logical features refer to logical features in the first logical feature map, the second logical feature map, the third logical feature map, and the fourth logical feature map that express different logical features for the same logical feature.
[0012] This application embodiment removes contradictory logical features from each level, enabling the smooth assembly process of logical feature diagrams at each level. The final assembled logical feature representation diagram represents the correct internal logic of the program to be represented.
[0013] In some embodiments, generating a first logical feature map of the file hierarchy of the program to be represented based on the file hierarchy and the execution logic structure of the file hierarchy includes: obtaining the file location and file type of the program to be represented using a file feature analysis method; and generating the first logical feature map of the file hierarchy of the program to be represented using a file tree analysis method based on the file location and file type.
[0014] This application embodiment analyzes the logical features of file levels using relevant file analysis methods and obtains a logical feature map of the file levels. This characterizes the logical features of file levels and lays the foundation for constructing logical feature maps of other levels.
[0015] In some embodiments, the second logical feature map, the third logical feature map, and the fourth logical feature map are generated through the following steps: obtaining the running mode of the program to be represented according to the file type; wherein, the running mode includes a compiled running mode and an interpreted running mode; and generating the second logical feature map, the third logical feature map, and the fourth logical feature map according to the running mode of the program to be represented.
[0016] This application embodiment obtains the running mode of the program to be represented based on the file type, enabling the construction of logical feature maps for programming languages with different running modes, thereby accurately expressing the logical features of different levels of the program to be represented.
[0017] In some embodiments, the method further includes: obtaining a sample representation program; wherein the sample representation program includes a sample data logical structure and a sample execution logical structure; the sample data logical structure includes a sample file level, a sample class level, a sample function level, and a sample statement level; generating a first sample logic feature map of the sample file level of the sample representation program based on the sample file level and the sample execution logical structure of the sample file level; generating a second sample logic feature map of the sample class level of the sample representation program based on the sample class level and the sample execution logical structure of the sample class level; generating a third sample logic feature map of the sample function level of the sample representation program based on the sample function level and the sample execution logical structure of the sample function level; generating a fourth sample logic feature map of the sample statement level of the sample representation program based on the sample statement level and the sample execution logical structure of the sample statement level; combining the first sample logic feature map, the second sample logic feature map, the third sample logic feature map, and the fourth sample logic feature map into a sample logic feature representation map; and generating the program representation model based on the sample logic feature representation map.
[0018] The embodiments of this application improve the accuracy and versatility of the program representation model by constructing a program representation model using a sample representation program.
[0019] Secondly, embodiments of this application provide a device for representing program features. The device includes: a feature extraction module, used to extract features from a program to be represented through a program representation model to obtain a logical feature representation graph; wherein, the nodes of the logical feature representation graph represent the data logic structure of the program to be represented, and the edges of the logical feature representation graph represent the execution logic structure of the program to be represented; and a representation module, used to analyze the logical feature representation graph through the program representation model and output the program feature representation result of the program to be represented; wherein, the program representation model is generated by pre-extracting features from sample representation features to generate a sample logical feature graph, and is generated based on the sample logical feature graph.
[0020] This application embodiment utilizes different modules to execute corresponding method steps, enabling the generated logical feature representation graph to reveal the similar logical essence implied by different programming languages. This allows for direct migration comparison between different programming languages, thereby providing theoretical support for downstream tasks such as logical vulnerability cause analysis and migration mining.
[0021] Thirdly, embodiments of this application provide an electronic device, including: a processor, a memory, a storage medium, and a bus, wherein the processor and the memory communicate with each other through the bus; the memory stores program instructions that can be executed by the processor, and the processor can execute the method steps of the first aspect by calling the program instructions.
[0022] Fourthly, embodiments of this application provide a non-transitory computer-readable storage medium, comprising: the computer-readable storage medium storing computer instructions, the computer instructions causing the computer to perform the method steps of the first aspect.
[0023] Other features and advantages of this application will be set forth in the following description and will be apparent in part from the description or may be learned by practicing embodiments of this application. Attached Figure Description
[0024] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0025] Figure 1 A flowchart illustrating a method for representing program features as provided in an embodiment of this application;
[0026] Figure 2 A schematic diagram of the analysis and characterization of a program to be characterized, provided for an embodiment of this application;
[0027] Figure 3 A schematic diagram of a data logic structure provided in an embodiment of this application;
[0028] Figure 4 A schematic diagram of an execution logic structure provided in an embodiment of this application;
[0029] Figure 5 A schematic diagram of a four-level hierarchical structure provided in this application embodiment;
[0030] Figure 6 A schematic diagram illustrating an exception handling method for the assembly process of logic feature maps at various levels, provided in an embodiment of this application;
[0031] Figure 7 A schematic diagram illustrating the generation process of logic feature maps at various levels, provided for embodiments of this application;
[0032] Figure 8 A schematic diagram illustrating a method for generating a logical feature map of a compiled programming language, as provided in an embodiment of this application;
[0033] Figure 9 A schematic diagram illustrating a method for generating a logical feature map of an interpreted programming language, provided in an embodiment of this application;
[0034] Figure 10 A schematic diagram illustrating a method for identifying and extracting abnormal execution paths in a programming language with an exception handling mechanism, provided in an embodiment of this application.
[0035] Figure 11 A schematic diagram of a device for representing program features provided in an embodiment of this application;
[0036] Figure 12 This is a schematic diagram of the electronic device structure provided in an embodiment of this application. Detailed Implementation
[0037] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. It should be understood that the accompanying drawings in this application are for illustrative and descriptive purposes only and are not intended to limit the scope of protection of this application. Furthermore, it should be understood that the schematic drawings are not drawn to scale. The flowcharts used in this application illustrate operations implemented according to some embodiments of this application. It should be understood that the operations in the flowcharts may not be implemented in sequence, and steps without logical contextual relationships may be reversed or implemented simultaneously. In addition, those skilled in the art, guided by the content of this application, may add one or more other operations to the flowcharts, or remove one or more operations from the flowcharts.
[0038] Furthermore, the described embodiments are merely some, not all, of the embodiments of this application. The components of the embodiments of this application described and illustrated herein can typically be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely to illustrate selected embodiments of the application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.
[0039] It should be noted that all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains; the terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit this application; the terms “comprising” and “having”, and any variations thereof, in the specification, claims, and foregoing description of the drawings are intended to cover non-exclusive inclusion.
[0040] In the description of the embodiments of this application, technical terms such as "first" and "second" are used only to distinguish different objects and should not be construed as indicating or implying relative importance or implicitly specifying the number, specific order, or primary and secondary relationship of the indicated technical features. In the description of the embodiments of this application, "multiple" means two or more, unless otherwise explicitly defined.
[0041] In the description of the embodiments in this application, the term "and / or" is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Additionally, the character " / " in this document generally indicates that the preceding and following related objects have an "or" relationship.
[0042] It is understood that the method for representing program features provided in this application embodiment can be applied to terminal devices (also known as electronic devices) and servers; wherein the terminal device can specifically be a smartphone, tablet computer, computer, personal digital assistant (PDA), etc.; the server can specifically be an application server or a web server.
[0043] To facilitate understanding of the technical solutions provided in the embodiments of this application, the following uses a server as the execution subject as an example to introduce the application scenario of a method for representing program features provided in the embodiments of this application.
[0044] Figure 1 A flowchart illustrating a method for representing program features provided in an embodiment of this application is shown below. Figure 1 As shown, the method includes:
[0045] Step 101: The server extracts features from the program to be represented using the program representation model to obtain a logical feature representation map.
[0046] In this context, the nodes of the logical feature representation graph represent the data logic structure of the program to be represented, and the edges of the logical feature representation graph represent the execution logic structure of the program to be represented.
[0047] In the specific implementation process, the server first obtains the program to be represented before performing feature extraction. The program to be represented refers to the program whose logical characteristics need to be analyzed and represented using a program representation model. The program to be represented can be written in common programming languages such as Java, Python, Go, C, and C++. It should be noted that the program to be represented can be a single executable file or a program group composed of multiple executable files that work together. The program to be represented can be input by the user or extracted from storage media. The storage media can be a hard drive, USB flash drive, virtual storage media, etc. In practical applications, the form, acquisition method, and language type of the program to be represented can be selected according to the actual situation; this application does not impose specific limitations in these aspects.
[0048] When the server extracts features from the program to be represented, it extracts the data logic structure and execution logic structure of the program. The data logic structure is treated as nodes, and the execution logic structure as edges. The relationships between nodes and edges are determined based on the execution relationships between the various data logic structures, thus generating a logical feature representation graph of the program. Here, the data logic structure refers to the data types contained in the program and the corresponding actual storage methods. The actual storage method refers to the actual storage allocation scheme corresponding to a specific data type name. The execution logic structure refers to the execution methods at each level of the program and between each level.
[0049] Step 102: The server analyzes the logical feature representation graph through the program representation model and outputs the program feature representation result of the program to be represented.
[0050] The program representation model involves pre-extracting features from the sample representation features to generate a sample logical feature map, and then generating a model based on the sample logical feature map.
[0051] In the specific implementation process, after obtaining the logical feature representation diagram of the program to be represented, the server analyzes it through the program representation model to represent the program features of the program to be represented.
[0052] In the technical solution of this application embodiment, by using a program representation model to analyze and represent the logical feature representation diagram of the program to be represented, logical feature representation diagrams can be generated for programs written in different programming languages by extracting their data logic structure and execution logic structure. These logical feature representation diagrams reveal the similar logical essence implicit in different programming languages, enabling direct transfer comparison between different programming languages, thereby providing theoretical support for downstream tasks such as logical vulnerability cause analysis and transfer mining.
[0053] In some embodiments, the server extracts features from the program to be represented using a program representation model to obtain a logical feature representation map, including: the server extracts the data logic structure and execution logic structure of the program to be represented using the program representation model, and generates a logical feature representation map based on the data logic structure and execution logic structure.
[0054] In the specific implementation process, when extracting the data logical structure of the program to be represented, the server extracts the smallest data logical unit of the program. For example, the extracted data logical structure can be the file to which the program belongs, or the classes, functions, and statements contained within the program. Similarly, when extracting the execution logical structure, the server extracts the execution relationships between the various data logical structures. For example, execution relationships can be calls, inclusions, inheritances, etc. Finally, a logical feature representation graph is generated based on the extracted data logical units and execution relationships. It should be noted that the extracted data logical structure or execution logical structure can be limited according to the actual situation during feature extraction; this application does not impose specific limitations in this regard.
[0055] This application embodiment generates a logical feature representation map based on the extracted data logic structure and execution logic structure of the program to be represented, so that the logical feature representation map can reflect the logical structure features of the program to be represented in multiple ways.
[0056] In some embodiments, the data logical structure includes a file level, a class level, a function level, and a statement level. The server generates a logical feature representation diagram based on the data logical structure and the execution logical structure, including: the server generating a first logical feature diagram of the file level of the program to be represented based on the file level and the execution logical structure of the file level; the server generating a second logical feature diagram of the class level of the program to be represented based on the class level and the execution logical structure of the class level; the server generating a third logical feature diagram of the function level of the program to be represented based on the function level and the execution logical structure of the function level; the server generating a fourth logical feature diagram of the statement level of the program to be represented based on the statement level and the execution logical structure of the statement level; and the server generating a logical feature representation diagram based on the first, second, third, and fourth logical feature diagrams.
[0057] Figure 2A schematic diagram of the analysis and characterization of a program to be characterized, provided for an embodiment of this application, is shown below. Figure 2 As shown, the horizontal axis represents the analysis level of the program to be characterized, and the vertical axis represents the representation level. When analyzing the program to be characterized, it is divided into file level, class level, function level, and statement level. When representing the program, it is represented from the perspectives of its data logic structure, execution logic structure, and orchestration and composition patterns.
[0058] In the specific implementation process, when representing the data logic structure of the program to be represented, the server extracts the data organization at each level and uses the extracted data organization to represent the data logic structure. Specifically, file-level data organization includes code packages, code files, etc.; class-level data organization includes code classes, code blocks without attributes, etc.; function-level data organization includes functions, functions without attributes, code blocks without attributes, etc.; and statement-level data organization includes statement types, variable declaration methods, variable declaration types, etc. Any data organization at any level can be represented by a node in the logical feature representation graph. Furthermore, the data organization type at each level can be selected according to the actual situation; this application does not impose specific limitations on this.
[0059] It should be noted that a "classless code block" refers to a detached code block that does not belong to any class, used to process code sets that are not categorized under a particular class structure. A "classless function" refers to a function that does not belong to any class but possesses complete function characteristics. A "block of countless functions" refers to a collection of code instructions that neither belong to any class nor possess complete function characteristics, but can be considered a function from an operational logic perspective, and is densely arranged in physical code organization. Functions can also be referred to as methods.
[0060] For ease of understanding, Figure 3 This is a schematic diagram of a data logic structure provided in an embodiment of this application, such as... Figure 3 As shown, a class (e.g., Class_A) is used as an example of a data logical structure. In this class, its logical structure includes three parts:
[0061] (1) Entity name, usually given by code, is globally unique.
[0062] (2) Category label, which is determined by the nature of the entity. For example, here it represents a class implementation and is displayed with the "Class" label; there is only one category label.
[0063] (3) Attributes. All attributes that may be related to an entity, except for type attributes, are marked as attributes. For example, here are two attributes of Class_A: external visibility, which is marked as Public in the code and is therefore True, and internal text content Body, which is simplified to #classF.
[0064] When representing the execution logic structure of the program to be represented, the server extracts the execution logic features at each level. The execution logic features at each level are as follows: file level features include inclusion and application; class level features include inheritance, implementation, and usage; function level features include calling, inheritance, and overriding; and statement level features include execution and jump. Any execution logic feature at any level can be represented by an edge in the logic feature representation graph, that is, a directed or undirected edge from a graph node representing a related data logic structure to another graph node representing a related data logic structure is used to represent the relationship of that execution logic structure. The name of the relationship of that execution data structure is represented by the name of the edge of that execution data structure.
[0065] For ease of understanding, Figure 4 This is a schematic diagram of an execution logic structure provided in an embodiment of this application, such as... Figure 4 As shown, this is a way to represent the execution logic of temporarily declaring another class within a certain class and calling the logical operations of that class.
[0066] In this approach, the operating subject Class_A and the operating recipient Class_B have been identified as two graph nodes named Class_A and Class_B respectively, according to the aforementioned data logic structure representation method. The temporary declaration command is marked as a relationship from the Class_A node to the Class_B node, with the relationship label "". <include>(meaning "contains") directed edges.
[0067] It should be noted that directed or undirected edges can be created from a graph node representing a data logical structure to itself. However, more than two directed or undirected edges with the same name, pointing from the same graph node representing a data logical structure to another graph node representing a data logical structure, cannot be created; this is the "edge duplication rule." If an operation would violate this constraint, the more recently created directed or undirected edge will be retained, and the remaining directed or undirected edges will be deleted from the graph. Except for the "type" characteristic, other characteristics to be represented can be selectively labeled on edge instances according to representation needs. That is, except for the edge name, which is limited in its purpose, the definition method of other edge attributes can be freely determined according to actual data collection and analysis needs, and is not constrained by the representation method.
[0068] Based on the data logic structure and execution logic structure obtained above for each level, a corresponding logical feature map can be generated for each level, such as... Figure 2 The arrangement and combination patterns shown include file-level logical feature diagrams, class-level logical feature diagrams, function-level logical feature diagrams, and statement-level logical feature diagrams.
[0069] Using the above method, any program can be divided into a four-level hierarchical structure of "file-class-function-statement". Figure 5 This application provides a schematic diagram of a four-level hierarchical structure, as shown in the embodiments. Figure 5 As shown, at each hierarchical level, the data logic structure and execution logic structure elements contained within that level are used to independently construct the logical feature graph for that level of structure according to the actual organizational structure relationships existing in the code. Furthermore, between adjacent hierarchical levels, multi-level logical feature representation graphs are formed through merging: "File-Class" level, file nodes; "Class-Function" level, class nodes; "Function-Statement" level, function nodes. The specific merging process is as follows: for logical feature graphs with adjacent hierarchical relationships, graph search methods are used to find node pairs with the same name. Nodes in node pairs with the same name are merged, and all relational edges related to the nodes in the node pairs are retained. Finally, the logical feature representation graph of the program to be represented is obtained. It should be noted that the newly generated merged nodes still need to maintain the aforementioned "edge non-repetition rule".
[0070] The specific execution process of the graph search method is as follows:
[0071] Step 1: Create a list array containing the names of all nodes in the graph for each logical feature graph of the adjacent level, and divide these arrays into two piles according to the logical feature level they belong to.
[0072] Step 2: For each group of array pairs belonging to different heaps, use the array matching algorithm to find node name pairs that contain the same name (referring to the same logical element).
[0073] Step 3: For each node name pair found in Step 2, return the original logical feature graph represented by these arrays. Use graph search to find the nodes that these names refer to and combine them into node pairs. These node pairs are the required "node pairs with the same name".
[0074] This application's embodiments subdivide the data logic structure into multiple levels and generate a logic feature map for each level. Based on the logic feature maps of each level, a logic feature representation map is generated, enabling the map to reflect the logical structure characteristics of each level of the program to be represented and the relationships between these levels. This provides a more intuitive representation of the internal logical features of the program. Furthermore, it allows different programming languages to achieve a unified language-independent abstract logical expression at the file level, class level, function level, and statement level.
[0075] In some embodiments, the server generates a logical feature representation map based on the first logical feature map, the second logical feature map, the third logical feature map, and the fourth logical feature map, including: the server removes contradictory logical features among the first logical feature map, the second logical feature map, the third logical feature map, and the fourth logical feature map to obtain a logical feature representation map of the program to be represented; wherein, contradictory logical features refer to logical features in the first logical feature map, the second logical feature map, the third logical feature map, and the fourth logical feature map that express different logical features for the same logical feature.
[0076] In the specific implementation process, after obtaining the first, second, third, and fourth logical feature maps, the server needs to combine these four levels of logical feature maps into a logical feature representation map. During the combination process, some contradictory logical features may exist between different levels, causing errors in the combination process. That is, the combination operation may cause the "edge non-repetition rule" to be violated. Therefore, it is necessary to execute an exception handling method to attempt to repair the rule and remove these contradictory logical features. Figure 6 This is a schematic diagram illustrating an exception handling method for the assembly process of logical feature maps at various levels, as provided in an embodiment of this application. Figure 6 As shown, the method includes:
[0077] Step 601: Using the lower-level logical feature diagram as the base diagram, discard the parts in other diagrams that contradict the representation of this diagram, and try to merge them again; it should be noted that when performing exception handling, the four levels of the data logical structure are subdivided from high to low into file level, class level, function level and statement level.
[0078] Step 602: Using the logical feature map whose final generation time is later as the base map, discard the parts in other maps that contradict the representation of the base map, and try to merge them again;
[0079] Step 603: Randomly select a graph from the set of logical feature graphs as the base graph, discard the parts of other graphs that contradict the representation of the base graph, and try to combine them again.
[0080] Finally, the logic feature maps after exception handling are combined into a logic feature representation map.
[0081] This application embodiment removes contradictory logical features from each level, enabling the smooth assembly process of logical feature diagrams at each level. The final assembled logical feature representation diagram represents the correct internal logic of the program to be represented.
[0082] In some embodiments, the server generates a first logical feature map of the file hierarchy of the program to be represented based on the file hierarchy and the execution logic structure of the file hierarchy, including: the server obtains the file location and file type of the program to be represented by a file feature analysis method, and generates a first logical feature map of the file hierarchy of the program to be represented by a file tree analysis method based on the file location and file type.
[0083] In practical implementation, "file feature analysis method" refers to the process of using publicly available tools provided by the operating system program to obtain certain features similar to programming language files in the program file package to be analyzed, such as external naming format and internal text format, thereby inferring the location of inferable program files and the type of language code used. File feature analysis methods can be feature analysis methods based on file statistical information, specifically including analysis and location methods based on file extensions and suspicious code file screening methods based on file size. They can also be feature analysis methods based on file content information, specifically including regular expression text matching methods based on specific code formats and NLP natural language processing recognition methods based on randomly sampled fragments of code text. The choice of file feature analysis method can be made according to the actual situation, and this application does not impose specific limitations on it.
[0084] "File tree analysis method" refers to the operation of using publicly available tools provided by the operating system to analyze a program file package to obtain the organizational structure information of each folder and file within the program file package, and finally generating an information structure based on this organizational structure information. The file organization structure generated by the file tree analysis method is a tree structure with the root directory file as the root node and the containment relationships between directories and files as directed edges. Therefore, it can serve as the basic skeleton structure of the first logical feature graph of the file hierarchy of the program to be represented. The file tree analysis method can be a file hash analysis method, a chained file analysis method, etc. The file tree analysis method can be selected according to the actual situation, and this application does not make specific limitations on it.
[0085] The file location refers to the storage location of the program to be characterized, and the file type refers to the programming language used by the program. Before generating the first logical feature map of the file hierarchy of the program to be characterized, the server needs to determine the file portion of the program to be characterized that needs to be analyzed, i.e., the analysis depth, based on the preset analysis scope. The preset analysis scope is a pre-defined range, such as one or more subroutine function packages in a program file package, one or more subroutine files in a program file package, or one or more specific functions under a program file. The analysis scope can be determined according to the actual situation, and this application does not make specific limitations on it.
[0086] Figure 7 This application provides a schematic diagram illustrating the generation process of logic feature maps at various levels, as shown in the embodiments. Figure 7 As shown, the generation process includes the following steps:
[0087] Step 701: After obtaining the file analysis depth, the file location and file type of the program to be characterized are analyzed using the file feature analysis method.
[0088] Step 702: Based on the file location and file type, generate the first logical feature map of the file hierarchy using the file tree analysis method.
[0089] Step 703: Classify the program to be characterized according to its file type to obtain the program's execution mode. The execution mode includes compiled execution mode and interpreted execution mode.
[0090] Step 704: Based on different operating modes, execute different logical feature map generation methods to generate logical feature maps of the class level, function level, and statement level of the program to be represented.
[0091] If the program to be characterized runs in a compiled mode, then step 7041 is executed, and the generation method for compiled programming languages is used to generate logical feature maps at the class level, function level, and statement level. If the program to be characterized runs in an interpreted mode, then step 7042 is executed, and the generation method for interpreted programming languages is used to generate logical feature maps at the class level, function level, and statement level.
[0092] It should be noted that the logical feature graphs constructed at each level should conform to the specifications of the logical feature graphs at each level in the program representation model described in the above embodiments.
[0093] This application embodiment analyzes the logical features of file levels using relevant file analysis methods and obtains a logical feature map of the file levels. This characterizes the logical features of file levels and lays the foundation for constructing logical feature maps of other levels.
[0094] In some embodiments, the second logical feature map, the third logical feature map, and the fourth logical feature map are generated through the following steps: the server obtains the running mode of the program to be represented based on the file type; wherein, the running mode includes a compiled running mode and an interpreted running mode; the server generates the second logical feature map, the third logical feature map, and the fourth logical feature map based on the running mode of the program to be represented.
[0095] In the specific implementation process, according to Figure 7 Steps 703 and 704 shown generate the second, third, and fourth logical feature maps of the program to be characterized.
[0096] Figure 8 A schematic diagram illustrating a method for generating logical feature maps of a compiled programming language, as provided in this application embodiment, is shown below. Figure 8 As shown, the specific implementation process of step 7041 includes the following steps:
[0097] Step 801: Compile the source code or use an intermediate representation language compiler to obtain the intermediate representation (IR) of the target program file. The intermediate representation can be LLVM IR or a similar form. It should be noted that the intermediate representation compiler can be the Soot tool for Java, or the LLVM compiler for C / C++, etc. It is important to understand that for different languages, the compiler corresponding to that language should be used.
[0098] Step 802: Based on the preset analysis requirements, construct the logical feature map using relevant data in the intermediate language representation according to the top-down hierarchical order; it should be noted that the top-down hierarchical order is class level, function level and statement level.
[0099] Step 803: Repeat the process of step 802 until the preset analysis granularity range is reached or the analysis can no longer continue based on the intermediate language representation obtained in step 801.
[0100] Figure 9 A schematic diagram illustrating a method for generating a logical feature map of an interpreted programming language, as provided in this application embodiment, is shown below. Figure 9 As shown, the specific implementation process of step 7041 includes the following steps:
[0101] Step 901: Obtain the Abstract Syntax Tree (AST) representation of the target program file based on the interpreter or lexical analyzer of the programming language program. It should be noted that the interpreter can be the Jython interpreter for Python, or the official interpreter for Lua. The lexical analyzer can be the AST lexical compiler module for Python, the Opcodes interpreter module for PHP, etc. It is important to understand that for different languages, the interpreter or lexical analyzer corresponding to that language should be used.
[0102] Step 902: Based on the preset analysis requirements, and following a top-down hierarchical order, construct the logical feature map using relevant data in the AST (Abstract Syntax Tree) representation. It should be noted that the top-down explanation refers to the above embodiment and will not be repeated here.
[0103] Step 903: Repeat step 902 until the preset analysis granularity range is reached or the analysis can no longer continue based on the AST abstract syntax tree obtained in step 901.
[0104] It should be noted that, in the process of constructing the edges and nodes in the logical feature graph described in steps 802 and 902, the program execution process described should include both the execution logic representation for the code in the normal running state and the execution logic representation for the code in the exception handling running state. Figure 10 A schematic diagram illustrating a method for identifying and extracting abnormal execution paths in a programming language with an exception handling mechanism, as provided in an embodiment of this application, is shown below. Figure 10 As shown, the method includes the following steps:
[0105] Step 1001: Based on the IR intermediate language representation or AST abstract syntax tree representation of the code's execution logic during normal operation, construct a representation diagram of the execution logic during normal operation.
[0106] Step 1002: Start traversing from the execution start point node of each function definition, and find the set of nodes that contain the command representing the exception being thrown;
[0107] Step 1003: For each exception throwing command node in the exception node set, add an exception execution path edge from the exception throwing command node to the exception execution exit of the function execution block;
[0108] Step 1004: If the exception execution exit is the definition exit of the function, then add another exception execution path edge from the definition exit node to all function nodes that have called this function.
[0109] This application embodiment obtains the running mode of the program to be represented based on the file type, enabling the construction of logical feature maps for programming languages with different running modes, thereby accurately expressing the logical features of different levels of the program to be represented.
[0110] In some embodiments, the method further includes: obtaining a sample representation program; wherein the sample representation program includes a sample data logical structure and a sample execution logical structure; the sample data logical structure includes a sample file level, a sample class level, a sample function level, and a sample statement level; generating a first sample logic feature map of the sample file level of the sample representation program based on the sample file level and the sample execution logical structure of the sample file level; generating a second sample logic feature map of the sample class level of the sample representation program based on the sample class level and the sample execution logical structure of the sample class level; generating a third sample logic feature map of the sample function level of the sample representation program based on the sample function level and the sample execution logical structure of the sample function level; generating a fourth sample logic feature map of the sample statement level of the sample representation program based on the sample statement level and the sample execution logical structure of the sample statement level; combining the first sample logic feature map, the second sample logic feature map, the third sample logic feature map, and the fourth sample logic feature map into a sample logic feature representation map; and generating the program representation model based on the sample logic feature representation map.
[0111] In the specific implementation process, please refer to the above embodiments for the specific execution process of obtaining the sample representation program and generating sample logical feature maps at each level, which will not be repeated here.
[0112] The embodiments of this application improve the accuracy and versatility of the program representation model by constructing a program representation model using a sample representation program.
[0113] In summary, the program feature representation method provided by this application addresses the inherent drawback of traditional program feature representations based on specific machine code instruction sets, which are closely related to specific code language features. Furthermore, compared to traditional graph-structured code representation models, the program representation model provided by this application has stronger static representation capabilities for exception handling. Compared to traditional static full-code analysis methods, the feature graph generation method provided by this application, under the same computing power conditions, can represent code structures that are more targeted and facilitate security personnel in conducting in-depth logical vulnerability research and discovery through static code logic analysis methods.
[0114] Figure 11 A schematic diagram of a device for representing program features provided in an embodiment of this application is shown below. Figure 11 As shown, the device includes a feature extraction module 1101 and a representation module 1102, wherein,
[0115] The feature extraction module 1101 is used to extract features from the program to be represented through the program representation model to obtain a logical feature representation graph; wherein, the nodes of the logical feature representation graph represent the data logic structure of the program to be represented, and the edges of the logical feature representation graph represent the execution logic structure of the program to be represented; the representation module 1102 is used to analyze the logical feature representation graph through the program representation model and output the program feature representation result of the program to be represented; wherein, the program representation model is generated by pre-extracting features from the sample representation features to generate a sample logical feature graph, and is generated based on the sample logical feature graph.
[0116] Based on the above embodiments, the feature extraction module 1101 is specifically used to: extract the data logic structure and execution logic structure of the program to be represented through the program representation model; and generate a logical feature representation map based on the data logic structure and execution logic structure.
[0117] Based on the above embodiments, the feature extraction module 1101 is specifically used for: the data logical structure including file level, class level, function level and statement level; generating a logical feature representation map based on the data logical structure and execution logical structure, including: generating a first logical feature map of the file level of the program to be represented based on the file level and the execution logical structure of the file level; generating a second logical feature map of the class level of the program to be represented based on the class level and the execution logical structure of the class level; generating a third logical feature map of the function level of the program to be represented based on the function level and the execution logical structure of the function level; generating a fourth logical feature map of the statement level of the program to be represented based on the statement level and the execution logical structure of the statement level; and generating a logical feature representation map based on the first logical feature map, the second logical feature map, the third logical feature map and the fourth logical feature map.
[0118] Based on the above embodiments, the feature extraction module 1101 is specifically used to: remove contradictory logical features among the first logical feature map, the second logical feature map, the third logical feature map, and the fourth logical feature map to obtain a logical feature representation map of the program to be represented; wherein, contradictory logical features refer to logical features in the first logical feature map, the second logical feature map, the third logical feature map, and the fourth logical feature map that express different logical features for the same logical feature.
[0119] Based on the above embodiments, the feature extraction module 1101 is specifically used to: obtain the file location and file type of the program to be represented by the file feature analysis method; and generate a first logical feature map of the file hierarchy of the program to be represented by the file location and file type through the file tree analysis method.
[0120] Based on the above embodiments, the feature extraction module 1101 is specifically used to: obtain the running mode of the program to be represented according to the file type; wherein, the running mode includes a compiled running mode and an interpreted running mode; and generate a second logical feature map, a third logical feature map and a fourth logical feature map according to the running mode of the program to be represented.
[0121] Based on the above embodiments, the device further includes a model generation module, specifically used for: acquiring a sample representation program; wherein the sample representation program includes a sample data logical structure and a sample execution logical structure; the sample data logical structure includes a sample file level, a sample class level, a sample function level, and a sample statement level; generating a first sample logic feature map of the sample file level of the sample representation program based on the sample file level and the sample execution logical structure of the sample file level; generating a second sample logic feature map of the sample class level of the sample representation program based on the sample class level and the sample execution logical structure of the sample class level; generating a third sample logic feature map of the sample function level of the sample representation program based on the sample function level and the sample execution logical structure of the sample function level; generating a fourth sample logic feature map of the sample statement level of the sample representation program based on the sample statement level and the sample execution logical structure of the sample statement level; combining the first sample logic feature map, the second sample logic feature map, the third sample logic feature map, and the fourth sample logic feature map into a sample logic feature representation map; and generating the program representation model based on the sample logic feature representation map.
[0122] This application embodiment utilizes different modules to execute corresponding method steps, enabling the generated logical feature representation graph to reveal the similar logical essence implied by different programming languages. This allows for direct migration comparison between different programming languages, thereby providing theoretical support for downstream tasks such as logical vulnerability cause analysis and migration mining.
[0123] Figure 12 This is a schematic diagram of the electronic device structure provided in the embodiments of this application, such as... Figure 12 As shown, the electronic device includes a processor 1201, a memory 1202, and a bus 1203; wherein the processor 1201 and the memory 1202 communicate with each other through the bus 1203. The processor 1201 is used to call program instructions in the memory 1202 to execute the methods provided in the above-described method embodiments.
[0124] Processor 1201 can be an integrated circuit chip with signal processing capabilities. The processor 1201 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), an off-the-shelf programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor can be a microprocessor or any conventional processor.
[0125] The memory 1202 may include, but is not limited to, random access memory (RAM), read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), etc.
[0126] This embodiment discloses a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium. The computer program includes program instructions, and when the program instructions are executed by a computer, the computer can execute the methods provided in the above-described method embodiments, such as: extracting features from the program to be represented through a program representation model to obtain a logical feature representation graph; wherein, the nodes of the logical feature representation graph represent the data logic structure of the program to be represented, and the edges of the logical feature representation graph represent the execution logic structure of the program to be represented; analyzing the logical feature representation graph through the program representation model to output the program feature representation result of the program to be represented; wherein, the program representation model is generated by pre-extracting features from sample representation features to generate a sample logical feature graph, and generating the model based on the sample logical feature graph.
[0127] This embodiment provides a non-transitory computer-readable storage medium storing computer instructions that cause the computer to execute the methods provided in the above-described method embodiments. These instructions include, for example,: extracting features from a program to be represented using a program representation model to obtain a logical feature representation graph; wherein the nodes of the logical feature representation graph represent the data logic structure of the program to be represented, and the edges of the logical feature representation graph represent the execution logic structure of the program to be represented; analyzing the logical feature representation graph using the program representation model to output the program feature representation result of the program to be represented; wherein the program representation model is generated by pre-extracting features from sample representation features to generate a sample logical feature graph, and then generating the graph based on the sample logical feature graph.
[0128] In the embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. Furthermore, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Additionally, the displayed or discussed mutual couplings, direct couplings, or communication connections may be through some communication interfaces; indirect couplings or communication connections between devices or units may be electrical, mechanical, or other forms.
[0129] Furthermore, the units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0130] Furthermore, the functional modules in the various embodiments of this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0131] The above description is merely an embodiment shown in this application and is not intended to limit the scope of protection of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application.< / include>
Claims
1. A method for representing program features, characterized in that, The method includes: The program representation model is used to extract features from the program to be represented, thereby obtaining a logical feature representation graph; wherein, the nodes of the logical feature representation graph represent the data logic structure of the program to be represented, and the edges of the logical feature representation graph represent the execution logic structure of the program to be represented. The logical feature representation map is analyzed by the program representation model to output the program feature representation result of the program to be represented; wherein, the program representation model is generated by pre-extracting features from the sample representation features to generate a sample logical feature map, and then generating the program based on the sample logical feature map. The step of extracting features from the program to be represented using a program representation model to obtain a logical feature representation map includes: The data logic structure and execution logic structure of the program to be represented are extracted through the program representation model; wherein, the data logic structure includes file level, class level, function level and statement level; A first logical feature map of the file level of the program to be represented is generated based on the file level and the execution logic structure of the file level. The second logical feature map of the class hierarchy of the program to be represented is generated based on the class hierarchy and the execution logic structure of the class hierarchy. The third logical feature map of the function level of the program to be represented is generated based on the function level and the execution logic structure of the function level. The fourth logical feature map of the statement level of the program to be represented is generated based on the statement level and the execution logic structure of the statement level. The logical feature representation map is generated based on the first logical feature map, the second logical feature map, the third logical feature map, and the fourth logical feature map.
2. The method according to claim 1, characterized in that, The step of generating the logical feature representation map based on the first logical feature map, the second logical feature map, the third logical feature map, and the fourth logical feature map includes: By removing contradictory logical features among the first logical feature map, the second logical feature map, the third logical feature map, and the fourth logical feature map, a logical feature representation map of the program to be represented is obtained; wherein, the contradictory logical features refer to logical features in the first logical feature map, the second logical feature map, the third logical feature map, and the fourth logical feature map that express the same logical feature differently.
3. The method according to claim 2, characterized in that, The step of generating a first logical feature map of the file level of the program to be represented based on the file level and the execution logic structure of the file level includes: The file location and file type of the program to be characterized are obtained using file feature analysis methods; Based on the file location and the file type, a first logical feature map of the file hierarchy of the program to be represented is generated using a file tree analysis method.
4. The method according to claim 3, characterized in that, The second logical feature map, the third logical feature map, and the fourth logical feature map are generated through the following steps: The execution mode of the program to be characterized is obtained based on the file type; wherein, the execution mode includes compiled execution mode and interpreted execution mode; The second logical feature map, the third logical feature map, and the fourth logical feature map are generated according to the running mode of the program to be represented.
5. The method according to any one of claims 1-4, characterized in that, The method further includes: Obtain a sample representation program; wherein the sample representation program includes a sample data logical structure and a sample execution logical structure; the sample data logical structure includes a sample file level, a sample class level, a sample function level, and a sample statement level; The first sample logic feature map of the sample file level of the sample representation program is generated based on the sample file level and the sample execution logic structure of the sample file level. The second sample logic feature map of the sample class level of the sample representation program is generated based on the sample class level and the sample execution logic structure of the sample class level. The third sample logic feature map of the sample function level of the sample representation program is generated based on the sample function level and the sample execution logic structure of the sample function level. The fourth sample logic feature map of the sample statement level of the sample representation program is generated based on the sample statement level and the sample execution logic structure of the sample statement level. The first sample logic feature map, the second sample logic feature map, the third sample logic feature map, and the fourth sample logic feature map are combined to form a sample logic feature representation map; The program representation model is generated based on the sample logical feature representation diagram.
6. A device for representing program features, characterized in that, The device includes: The feature extraction module is used to extract features from the program to be represented through the program representation model to obtain a logical feature representation graph; wherein, the nodes of the logical feature representation graph represent the data logic structure of the program to be represented, and the edges of the logical feature representation graph represent the execution logic structure of the program to be represented. The representation module is used to analyze the logical feature representation map through the program representation model and output the program feature representation result of the program to be represented; wherein, the program representation model is generated by pre-extracting features from the sample representation features to generate a sample logical feature map, and then generating the representation based on the sample logical feature map. Specifically, the feature extraction module is used for: The data logic structure and execution logic structure of the program to be represented are extracted using the program representation model; the data logic structure includes file level, class level, function level and statement level. A first logical feature map of the file level of the program to be represented is generated based on the file level and the execution logic structure of the file level. The second logical feature map of the class hierarchy of the program to be represented is generated based on the class hierarchy and the execution logic structure of the class hierarchy. The third logical feature map of the function level of the program to be represented is generated based on the function level and the execution logic structure of the function level. The fourth logical feature map of the statement level of the program to be represented is generated based on the statement level and the execution logic structure of the statement level. The logical feature representation map is generated based on the first logical feature map, the second logical feature map, the third logical feature map, and the fourth logical feature map.
7. An electronic device, characterized in that, include: The device includes a processor, a storage medium, and a bus, wherein the storage medium stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor communicates with the storage medium via the bus, and the processor executes the machine-readable instructions to perform the steps of a method for representing program features as described in any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that is executed by a processor to perform the steps of a method for representing a program feature as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Bug detection method and system based on program characteristic tree
CN107038380A
Android system vulnerability detection method, electronic equipment and storage medium
CN112733158A
