Bytecode program analysis method, device, equipment and medium

By identifying and deleting unconnectable nodes in the initial control flow graph, an optimized control flow graph is generated, which solves the problem of resource waste caused by full path traversal in bytecode program analysis and improves the accuracy and efficiency of analysis.

CN118502732BActive Publication Date: 2024-10-25HANGZHOU NEWGRAND TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410962157.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-18
Publication Date
2024-10-25
Estimated Expiration
2044-07-18

AI Technical Summary

Technical Problem

When analyzing bytecode programs in the prior art, the entire path of the program flow graph needs to be traversed, which results in meaningless consumption of computing resources and time and affects the accuracy and efficiency of the analysis.

Method used

By determining the connectivity between the starting node and other nodes in the initial control flow graph, identifying unconnectable nodes as abnormal nodes, and deleting paths in the initial control flow graph, an optimized control flow graph is generated, and only reachable nodes are Path is analyzed.

Benefits of technology

It simplifies the analysis process, avoids meaningless consumption of computing resources and time, improves the accuracy and efficiency of bytecode program analysis, and reduces errors caused by overly complex path analysis.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118502732B_ABST
    Figure CN118502732B_ABST
Patent Text Reader

Abstract

The present invention discloses a bytecode program analysis method, device, equipment and medium, which relates to the field of computer technology, including: obtaining a target bytecode program to be analyzed, and generating an initial control flow graph corresponding to the target bytecode program; determining the connectivity between a starting node and other nodes in the initial control flow graph, and treating other nodes whose connectivity with the starting node is not connected as first-class abnormal nodes; wherein other nodes are nodes other than the starting node in the initial control flow graph; performing path deletion on the initial control flow graph according to the first-class abnormal nodes, generating a first optimized control flow graph, and analyzing the target bytecode program according to the first optimized control flow graph. The present invention eliminates meaningless analysis paths in the control flow graph, simplifies the analysis process, avoids meaningless consumption of computing resources and time, and improves the accuracy and efficiency of the target bytecode program analysis.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a bytecode program analysis method, device, equipment and medium. Background Art

[0002] In the process of software development, maintenance and testing, bytecode program analysis is an important technical means to understand the behavior and characteristics of bytecode programs without executing them.

[0003] Currently, the analysis of bytecode programs usually requires traversing all paths in the program flow graph corresponding to the bytecode program. However, this full-path traversal analysis method is often prone to introduce irrelevant or meaningless analysis paths, which in practical applications will lead to a large amount of meaningless consumption of computing resources and time, thus affecting the accuracy and efficiency of bytecode program analysis. Summary of the invention

[0004] The present invention provides a bytecode program analysis method, device, equipment and medium to solve the problem of low accuracy and efficiency of bytecode program analysis caused by full-path analysis of program flow graph.

[0005] According to one aspect of the present invention, there is provided a method for analyzing a bytecode program, comprising:

[0006] Obtaining a target bytecode program to be analyzed, and generating an initial control flow graph corresponding to the target bytecode program;

[0007] Determine the connectivity between the starting node and other nodes in the initial control flow graph, and use the other nodes whose connectivity with the starting node is not connected as the first type of abnormal nodes; wherein the other nodes are nodes in the initial control flow graph other than the starting node;

[0008] The initial control flow graph is path-pruned according to the first type of abnormal nodes to generate a first optimized control flow graph, and the target bytecode program is analyzed according to the first optimized control flow graph.

[0009] According to another aspect of the present invention, there is provided a bytecode program analysis device, comprising:

[0010] An initial control flow graph generation module, used to obtain a target bytecode program to be analyzed and generate an initial control flow graph corresponding to the target bytecode program;

[0011] A first-type abnormal node determination module is used to determine the connectivity between the starting node and other nodes in the initial control flow graph, and to use the other nodes whose connectivity with the starting node is not connected as the first-type abnormal nodes; wherein the other nodes are nodes other than the starting node in the initial control flow graph;

[0012] The first optimized control flow graph generation module is used to perform path deletion on the initial control flow graph according to the first type of abnormal nodes to generate a first optimized control flow graph, and analyze the target bytecode program according to the first optimized control flow graph.

[0013] According to another aspect of the present invention, there is provided an electronic device, the electronic device comprising:

[0014] at least one processor; and

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

[0016] The memory stores a computer program that can be executed by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the bytecode program analysis method described in any one of the present inventions.

[0017] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to implement the bytecode program analysis method described in any one of the present invention when executed by a processor.

[0018] Since the connectivity between the first type of abnormal nodes and the starting node is not connected, the code segment corresponding to the first type of abnormal nodes in the target bytecode program will not be accessed during the normal execution of the program, that is, the first type of abnormal nodes can be ignored during analysis. Therefore, the present invention generates a first optimized control flow graph by performing path deletion on the initial control flow graph according to the first type of abnormal nodes, and analyzes the target bytecode program according to the first optimized control flow graph, thereby eliminating meaningless analysis paths in the control flow graph, simplifying the analysis process, avoiding meaningless consumption of computing resources and time, and improving the accuracy and efficiency of the analysis of the target bytecode program.

[0019] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0021] Figure 1 A flowchart of a bytecode program analysis method provided in Embodiment 1 of the present invention;

[0022] Figure 2 A flowchart of a bytecode program analysis method provided in Embodiment 2 of the present invention;

[0023] Figure 3 A flowchart of a bytecode program analysis method provided in Embodiment 3 of the present invention;

[0024] Figure 4 A flowchart of a bytecode program analysis method provided in Embodiment 4 of the present invention;

[0025] Figure 5 A flowchart of a bytecode program analysis method provided in Embodiment 5 of the present invention;

[0026] Figure 6 A flowchart of a bytecode program analysis method provided in Embodiment 6 of the present invention;

[0027] Figure 7 A flowchart of a bytecode program analysis method provided in Embodiment 7 of the present invention;

[0028] Figure 8 A schematic diagram of the structure of a bytecode program analysis device provided in Embodiment 8 of the present invention;

[0029] Fig. 9 It is a schematic diagram of the structure of an electronic device for implementing the bytecode program analysis method of an embodiment of the present invention. DETAILED DESCRIPTION

[0030] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0031] It should be noted that the terms "target", "initial", "optimization", "first category", "second category", "third category", "fourth category", "fifth category", "sixth category", "first", "second", etc. in the specification and claims of the present invention 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 data used in this way can be interchangeable where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0032] Embodiment 1

[0033] Figure 1 This is a flowchart of a bytecode program analysis method provided in the first embodiment of the present invention. This embodiment is applicable to the case where a target bytecode program is analyzed using a control flow graph. The method can be executed by a bytecode program analysis device, which can be implemented in the form of hardware and / or software, such as by a processor in a computer. Figure 1 As shown, the method includes:

[0034] S101. Obtain a target bytecode program to be analyzed, and generate an initial control flow graph corresponding to the target bytecode program.

[0035] The target bytecode program represents the bytecode program that needs to be analyzed to understand the program behavior and program characteristics. The bytecode program is an intermediate representation of the source code converted by a compiler or interpreter before the source code is compiled or interpreted for execution. The bytecode program is a low-level program representation that is abstract enough to be executed on different platforms or virtual machines. For example, Java source code is first compiled into a bytecode program, which is then interpreted or just-in-time compiled into machine code for execution by the Java Virtual Machine (JVM).

[0036] The initial control flow graph refers to the most initial control flow graph generated directly from the target bytecode program. The control flow graph, also known as CFG (Control Flow Graph), is a graphical representation used to describe all possible paths during program execution. The paths represent the possible order of program execution, that is, the transfer relationship between basic blocks. In simple terms, the control flow graph shows all the paths and conditional branches that the program may go through during execution. The nodes in the control flow graph represent the basic blocks in the program, and each basic block is a continuous sequence of code. The edges in the control flow graph are used to connect the nodes in the control flow graph and represent the possible order of node execution. For example, if the target bytecode contains an if-else statement, the initial control flow graph will show two edges contained in the node corresponding to the if-else statement: one represents the execution path when the if condition is true, and the other represents the execution path when the if condition is false. Through the control flow graph, you can see all the possible execution paths of the program, which is very helpful for understanding the behavior of the program, discovering potential logical errors, and optimizing the code.

[0037] The initial control flow graph is further explained in combination with the actual scenario: Assume that the target bytecode program is a calculator program that accepts two numbers input by the user and performs calculations based on the operator (addition, subtraction, multiplication, and division) selected by the user. The generated initial control flow graph includes the main execution path of the target bytecode program: input number->select operator->execute calculation->output result. At the same time, the initial control flow graph also displays various possible error handling paths, such as the processing path when the input is illegal, etc.

[0038] In one embodiment, the processor obtains an original bytecode program, wherein the original bytecode program refers to the most original unoptimized bytecode program. In order to improve the clarity and neatness of the bytecode program, the original bytecode program needs to be optimized at the code level, such as deleting unused local variables or parameters in the original bytecode program, and obtaining a target bytecode program based on the optimization result of the original bytecode program.

[0039] Compiler front-end technology, including but not limited to lexical analysis, syntax analysis and semantic analysis, or specialized static analysis tools, are used to parse the target bytecode program, identify the basic blocks contained in the target bytecode program, and establish nodes in the control flow graph based on the identified basic blocks. Furthermore, the control flow involved in the target bytecode program is determined, and then the established nodes are connected in the control flow graph based on the determined control flow to establish edges in the control flow graph, and finally the initial control flow graph corresponding to the target bytecode program is output.

[0040] S102: Determine the connectivity between the starting node and other nodes in the initial control flow graph, and regard other nodes whose connectivity with the starting node is not connectable as first-type abnormal nodes.

[0041] The start node represents the entry node of the initial control flow graph, that is, node 1 in the initial control flow graph. Other nodes are nodes in the initial control flow graph other than the start node. The connectivity between the start node and other nodes reflects whether the start node can reach other nodes in the initial control flow graph.

[0042] If in the initial control flow graph, starting from the starting node, any other node can be reached through any path, then the connectivity between the other node and the starting node is connected; if in the initial control flow graph, starting from the starting node, any other node cannot be reached through all paths, then the connectivity between the other node and the starting node is disconnected, and the other node is regarded as a first-class abnormal node. For example, if any other node does not have an entry edge, that is, starting from the starting node in the initial control flow graph, the other node must not be reached, then the connectivity between the other node and the starting node is disconnected, and the other node is regarded as a first-class abnormal node.

[0043] Exemplarily, assuming that the structure of the initial control flow graph can be briefly described as: node 1->node 2->node 3->node 4->node 5, where node 1 is the starting node, and node 2, node 3, node 4 and node 5 are other nodes, it can be determined that the connectivity of node 2, node 3, node 4 and node 5 with the starting node (node ​​1) are all connectable.

[0044] Exemplarily, assuming that the structure of the initial control flow graph can be briefly described as: node 1->node 2->node 3->node 4; node 5->node 6->node 7, where node 1 is the starting node, and node 2, node 3, node 4, node 5, node 6 and node 7 are other nodes, it can be determined that the connectivity between node 2, node 3 and node 4 and the starting node (node ​​1) is all connectable; the connectivity between node 5, node 6 and node 7 and the starting node (node ​​1) is all disconnected, then node 5, node 6 and node 7 are regarded as first-class abnormal nodes.

[0045] S103: prune the initial control flow graph according to the first type of abnormal nodes to generate a first optimized control flow graph, and analyze the target bytecode program according to the first optimized control flow graph.

[0046] Among them, since the connectivity between the first type of abnormal nodes and the starting node is not connected, the basic blocks corresponding to the first type of abnormal nodes in the target bytecode program will not be accessed during the normal execution of the program, that is, the basic blocks corresponding to the first type of abnormal nodes can be understood as "dead code" or "unreachable code". Since these basic blocks will not be accessed during the normal execution of the program, these basic blocks can be ignored during the analysis of the target bytecode program. Correspondingly, ignoring these basic blocks means deleting the paths corresponding to these basic blocks in the initial control flow graph, so that these basic blocks are skipped during the analysis of the target bytecode program and are not included in the analysis scope.

[0047] In one embodiment, in the initial control flow graph, the path of the initial control flow graph is pruned according to each first-class abnormal node and the first-class abnormal edge connected to each first-class abnormal node, and the first optimized control flow graph is generated according to the path pruned result. A graph algorithm, such as a depth-first traversal algorithm (DFS) or a breadth-first traversal algorithm (BFS), is used for the first optimized control flow graph to traverse and analyze all paths starting from the starting node. By continuously exploring these paths, the behavior of the target bytecode program can be more deeply understood, potential problems can be discovered, and possible optimization opportunities can be identified, thereby ensuring the completeness and accuracy of the analysis results. In other words, the analysis of the target bytecode program can essentially be completed by traversing and analyzing each node and edge in the first optimized control flow graph corresponding to the target bytecode program.

[0048] Since the connectivity between the first type of abnormal nodes and the starting node is not connected, the code segment corresponding to the first type of abnormal nodes in the target bytecode program will not be accessed during the normal execution of the program, that is, the first type of abnormal nodes can be ignored during analysis. Therefore, the present invention generates a first optimized control flow graph by performing path deletion on the initial control flow graph according to the first type of abnormal nodes, and analyzes the target bytecode program according to the first optimized control flow graph, thereby eliminating meaningless analysis paths in the control flow graph, simplifying the analysis process, avoiding meaningless consumption of computing resources and time, and improving the efficiency of analyzing the target bytecode program; and, it also helps to reduce errors that may be introduced due to overly complex path analysis, and improves the accuracy of analyzing the target bytecode program.

[0049] Optionally, analyzing the target bytecode program according to the first optimized control flow graph includes:

[0050] Determine the target path to be analyzed currently in the first optimized control flow graph, and determine the number of analyses of the target path; if the number of analyses is greater than a threshold, skip the analysis operation on the target path.

[0051] Among them, the target bytecode program includes loop structures, such as for loops, while loops, etc. Accordingly, when analyzing the paths associated with the loop structures in the first optimized control flow graph, multiple iterations of analysis will be involved. However, when the number of loops of the loop structure is too many, or even an infinite loop occurs, the number of iterations of the analysis of the paths associated with the loop structure will be too many, resulting in excessive computational overhead and time. Therefore, it is necessary to limit the number of analyses of each path. The number threshold is used to determine whether the analysis of the target path will generate excessive computational overhead and time.

[0052] In one embodiment, the target path to be analyzed in the first optimized control flow graph is determined, and the number of analyses of the target path is determined, and the number of analyses is compared with a number threshold. If the number of analyses is less than or equal to the number threshold, that is, the analysis of the target path will not temporarily generate excessive computational overhead and time, then the analysis operation on the target path continues to be performed; if the number of analyses is greater than the number threshold, that is, the analysis of the target path has generated excessive computational overhead and time, then the analysis operation on the target path is skipped.

[0053] By determining the target path to be analyzed in the first optimized control flow graph, and determining the number of times the target path is analyzed; when the number of analyses is greater than the threshold, the analysis operation on the target path is skipped, thereby reducing the exploration of overly repeated paths in the first optimized control flow graph, so that in some complex loop structures, resources will not be exhausted due to in-depth exploration of too many iterations, which helps prevent potential infinite loops or excessive computational overhead and time during the analysis process, while still retaining enough information to identify possible problems or performance bottlenecks within the loop structure. This approach ensures the feasibility and efficiency of the analysis while avoiding negative impacts on program performance.

[0054] Optionally, analyzing the target bytecode program according to the first optimized control flow graph includes:

[0055] Determine the target path to be analyzed currently in the first optimized control flow graph, and determine the number of analyses of the target path; when the number of analyses is one, skip the analysis operation on the target path.

[0056] In the first optimized control flow graph, each time a path is analyzed, a record is made to avoid repeated analysis of the same path, thereby improving the analysis efficiency.

[0057] In one embodiment, the target path to be analyzed in the first optimized control flow graph is determined, and the number of analyses of the target path is determined. If the number of analyses is zero, that is, the target path has not been analyzed, the analysis operation on the target path is performed; if the number of analyses is one, that is, the target path has been analyzed, in order to avoid repeated analysis of the same path, the analysis operation on the target path is skipped.

[0058] By determining the target path to be analyzed in the first optimized control flow graph and determining the number of times the target path is analyzed; when the number of analyses is one, the analysis operation on the target path is skipped. This method can ensure that each path is analyzed only once, thereby saving time and computing resources.

[0059] Embodiment 2

[0060] Figure 2 This is a flowchart of a bytecode program analysis method provided in Embodiment 2 of the present invention. This embodiment further optimizes and expands the above embodiment and can be combined with the above optional implementations. Figure 2 As shown, the method includes:

[0061] S201, obtaining an original bytecode program, and determining unused local variables in the original bytecode program as abnormal local variables, and unused parameters as abnormal parameters.

[0062] The original bytecode program refers to the most original unoptimized bytecode program.

[0063] In one embodiment, the original bytecode program is processed by at least one of data flow analysis, symbol table checking, and scope analysis to identify unused local variables and unused parameters in the original bytecode program. Data flow analysis, symbol table checking, and scope analysis can all be supported by an integrated development environment (IDE) or a dedicated code analysis tool. Specifically:

[0064] Data flow analysis: performed during compilation, tracking the use of each local variable and identifying local variables and parameters that have been assigned but not used. Symbol table check: the compiler generates a symbol table when parsing the code, recording the information of all local variables and parameters, and finds unused local variables and parameters by comparing the references in the symbol table and the code. Scope analysis: checks whether local variables and parameters are referenced within the scope in which they are defined. Local variables and parameters that are not referenced are considered unused.

[0065] After identifying unused local variables in the original bytecode program, the unused local variables are used as abnormal local variables; and after identifying unused parameters in the original bytecode program, the unused parameters are used as abnormal parameters.

[0066] S202: When the number of abnormal local variables is less than a first threshold, and the number of abnormal parameters is less than a second threshold, the abnormal local variables and the abnormal parameters are deleted from the original bytecode program to obtain a target bytecode program.

[0067] The first threshold and the second threshold are used to determine whether there are potential design problems in the original bytecode program.

[0068] In one embodiment, the number of variables of the identified abnormal local variables and the number of parameters of the abnormal parameters are counted. The variable parameters of the abnormal local variables are compared with a first threshold, and the number of parameters of the abnormal parameters is compared with a second threshold. If the number of variables of the abnormal local variables is less than the first threshold, and the number of parameters of the abnormal parameters is less than the second threshold, it means that there is no potential design problem in the original bytecode program, and there is no need to reconstruct the code. Only code optimization is required, and then the abnormal local variables and abnormal parameters are deleted in the original bytecode program to obtain the target bytecode program.

[0069] By obtaining an original bytecode program and determining unused local variables in the original bytecode program as abnormal local variables and unused parameters as abnormal parameters; when the number of variables of the abnormal local variables is less than a first threshold and the number of parameters of the abnormal parameters is less than a second threshold, the abnormal local variables and abnormal parameters are deleted in the original bytecode program to obtain a target bytecode program, which helps to eliminate confusion and unnecessary complexity in the original bytecode program and makes the obtained target bytecode program neater.

[0070] Optionally, after determining that unused local variables in the original bytecode program are abnormal local variables and unused parameters are abnormal parameters, the method further includes:

[0071] When the number of variables of abnormal local variables is greater than or equal to a first threshold, or the number of parameters of abnormal parameters is greater than or equal to a second threshold, code refactoring prompt information is generated; wherein the code refactoring prompt information is used to prompt the user to refactor the original bytecode program.

[0072] In one embodiment, if the number of variables of abnormal local variables is greater than or equal to a first threshold, or the number of parameters of abnormal parameters is greater than or equal to a second threshold, that is, unused local variables or parameters frequently appear in the original bytecode program, then it indicates that there are potential design problems in the original bytecode program. In this case, the original bytecode program should be refactored, and code refactoring prompt information is generated to prompt the user to refactor the original bytecode program.

[0073] By generating code refactoring prompt information when the number of variables of abnormal local variables is greater than or equal to a first threshold, or the number of parameters of abnormal parameters is greater than or equal to a second threshold; wherein the code refactoring prompt information is used to prompt the user to refactor the original bytecode program, which can improve the structure and efficiency of the code on the one hand, and avoid meaningless analysis of the original bytecode program with potential design problems on the other hand, resulting in a waste of computing resources and time.

[0074] S203, generating an initial control flow graph corresponding to the target bytecode program, determining the connectivity between the starting node and other nodes in the initial control flow graph, and treating other nodes whose connectivity with the starting node is not connectable as first-category abnormal nodes.

[0075] Among them, other nodes are nodes in the initial control flow graph except the start node.

[0076] S204. Determine at least one edge connected to the first type of abnormal node in the initial control flow graph as the first type of abnormal edge.

[0077] Exemplarily, assuming that the structure of the initial control flow graph can be briefly described as: node 1-edge 1-node 2-edge 2-node 3-edge 3-node 4-edge 4-node 5, if node 4 is a first-type abnormal node, then "edge 3" and "edge 4" connected to node 4 are first-type abnormal edges.

[0078] S205 . Determine a first type of abnormal path according to the first type of abnormal nodes and the first type of abnormal edges, and perform path deletion on the initial control flow graph according to the first type of abnormal paths to generate a first optimized control flow graph.

[0079] Exemplarily, continuing with the above example for explanation, node 4 is a first-class abnormal node, and "edge 3" and "edge 4" connected to node 4 are first-class abnormal edges, then "edge 3-node 4-edge 4" is used as the first-class abnormal path, and "edge 3-node 4-edge 4" is deleted in the initial control flow graph to generate the first optimized control flow graph.

[0080] By determining at least one edge connected to a first type of abnormal node in the initial control flow graph as a first type of abnormal edge; determining a first type of abnormal path according to the first type of abnormal node and the first type of abnormal edge, and performing path deletion on the initial control flow graph according to the first type of abnormal path, a first optimized control flow graph is generated, thereby achieving the effect of eliminating meaningless analysis paths in the initial control flow graph, thereby avoiding wasting computing resources and time on these meaningless analysis paths, thereby concentrating resources on analyzing those paths that are more likely to affect program behavior.

[0081] S206: Analyze the target bytecode program according to the first optimized control flow graph.

[0082] Embodiment 3

[0083] Figure 3 This is a flowchart of a bytecode program analysis method provided in Embodiment 3 of the present invention. This embodiment further optimizes and expands the above embodiment and can be combined with the above optional implementations. Figure 3 As shown, the method includes:

[0084] S301. Obtain a target bytecode program to be analyzed, and generate an initial control flow graph corresponding to the target bytecode program.

[0085] S302: Obtain the historical bytecode program corresponding to the target bytecode program in the historical version.

[0086] The target bytecode program is the bytecode program of the current version, and the historical bytecode program refers to the bytecode program corresponding to the historical version of the target bytecode program. The current version and the historical version are generated according to the iterative update of the program. The historical bytecode program is the bytecode program that has been analyzed, that is, the analysis of each path in the control flow graph corresponding to the historical bytecode program has been completed.

[0087] S303. Determine function code blocks in the target bytecode program that have not changed compared to the historical bytecode program, and determine nodes and edges associated with the function code blocks in the initial control flow graph as second-type abnormal nodes and second-type abnormal edges, respectively.

[0088] Among them, the function code block refers to the code block corresponding to the function called by the bytecode program in the bytecode program. A function code block can be composed of one or more basic blocks.

[0089] The function code block corresponding to the same function in the target bytecode program may or may not change from the function code block corresponding to the historical bytecode program. Changes in function code blocks include, but are not limited to, at least one of the following forms: 1) Addition: A new function is added to the target bytecode program. 2) Deletion: A function that existed in the historical bytecode program is deleted from the target bytecode program. 3) Modification / re-editing: The internal logic, parameter list, return value type, or function name of the function in the target bytecode program may have changed. This includes reconstruction, optimization, and logic changes of the target bytecode program. 4) Changes in permissions and access modifiers: For example, a function that was originally public may become private, or other changes may occur to the visibility of the function.

[0090] Correspondingly, the unchanged function code block refers to the function code block corresponding to the same function in the target bytecode program, which is exactly the same as the function code block corresponding to the same function in the historical bytecode program.

[0091] In one embodiment, the target bytecode program is compared with the historical bytecode program by using at least one of the following methods to determine the function code blocks in the target bytecode program that have not changed relative to the historical bytecode program:

[0092] 1) Use bytecode comparison tools: Tools such as Jardiff can be used to compare the differences between the target bytecode program and the historical bytecode program. It provides a detailed difference report showing the added, deleted, and modified function code blocks. Or tools such as apkcompare can analyze the target bytecode program and the historical bytecode program and generate a difference report. By analyzing these differences, you can determine which function code blocks have not changed.

[0093] 2) Hash value comparison: A hash value can be generated for each function code block. If the function code block with the same name in the target bytecode program and the historical bytecode program has the same hash value, this usually indicates that the function code block has not changed between the target bytecode program and the historical bytecode program. This method is suitable for quickly detecting unchanged code parts.

[0094] 3) Structured bytecode analysis tools: Using structured bytecode analysis tools, you can customize the comparison logic to deeply analyze the differences between the target bytecode program and the historical bytecode program. These tools can provide precise comparison results at the function level.

[0095] 4) Professional bytecode view and comparison tools: For example, Bytecode Viewer, which can display bytecode and support intuitive graphical comparison. Such tools can help users directly observe the differences at the bytecode level and assist in identifying the function code blocks that have not changed between the target bytecode program and the historical bytecode program.

[0096] Since the historical bytecode program is a bytecode program that has been analyzed, that is, all function code blocks in the historical bytecode program have been analyzed. Therefore, in order to avoid repeated analysis of the code parts that have been analyzed and confirmed to be unchanged, the function code blocks in the target bytecode program that have not changed relative to the historical bytecode program can be ignored during the analysis process. Accordingly, ignoring these function code blocks means deleting the paths corresponding to these function code blocks in the initial control flow graph, so that these function code blocks are skipped during the analysis of the target bytecode program and are not included in the analysis scope.

[0097] Specifically, the function code blocks in the target bytecode program that have not changed relative to the historical bytecode program are determined, and in the initial control flow graph, at least one node associated with the function code blocks that have not changed is determined as a second-type abnormal node, and at least one edge associated with it is determined as a second-type abnormal edge.

[0098] S304: Determine a second type of abnormal path according to the second type of abnormal nodes and the second type of abnormal edges, and perform path deletion on the initial control flow graph according to the second type of abnormal paths to generate a second optimized control flow graph.

[0099] In one implementation, a path formed by second-type abnormal nodes and second-type abnormal edges in an initial control flow graph is determined as a second-type abnormal path, and the second-type abnormal path is deleted in the initial control flow graph to generate a second optimized control flow graph.

[0100] S305: Analyze the target bytecode program according to the second optimized control flow graph.

[0101] Since the historical bytecode program is a bytecode program that has been analyzed, that is, all function code blocks in the historical bytecode program have been analyzed, the function code blocks in the target bytecode program that have not changed compared with the historical bytecode program can be ignored in the analysis process. Therefore, the function code blocks in the target bytecode program that have not changed compared with the historical bytecode program are determined, and the nodes and edges associated with the function code blocks in the initial control flow graph are determined as the second type of abnormal nodes and the second type of abnormal edges respectively; the second type of abnormal paths are determined according to the second type of abnormal nodes and the second type of abnormal edges, and the initial control flow graph is pruned according to the second type of abnormal paths to generate a second optimized control flow graph; the target bytecode program is analyzed according to the second optimized control flow graph, thereby eliminating meaningless analysis paths in the control flow graph, simplifying the analysis process, avoiding meaningless consumption of computing resources and time, and improving the efficiency of the analysis of the target bytecode program; and it also helps to reduce errors that may be introduced due to overly complex path analysis, thereby improving the accuracy of the analysis of the target bytecode program.

[0102] Embodiment 4

[0103] Figure 4 This is a flowchart of a bytecode program analysis method provided by Embodiment 4 of the present invention. This embodiment further optimizes and expands the above embodiment and can be combined with the above optional implementations. Figure 4 As shown, the method includes:

[0104] S401. Obtain a target bytecode program to be analyzed, and generate a first initial data flow graph corresponding to the target bytecode program.

[0105] Among them, the first initial data flow graph refers to the most initial data flow graph directly generated according to the target bytecode program. The data flow graph, also known as DFG (Data Flow Graph), is a graphical representation used to show the generation, use and transmission relationship of data in the target bytecode program, which helps to understand the data flow and dependency relationship in the target bytecode program. The nodes in the data flow graph include two types: data nodes and processing nodes. The edges in the data flow graph reflect how the data flows between processing nodes. Each processing node represents a computational operation in the program (such as assignment, arithmetic operation, etc.), and the data nodes output by the processing node are the results of these computational operations. The output data nodes can be passed to other processing nodes as input to form a path in the data flow graph.

[0106] For example, a segment of assignment statement in the target bytecode program corresponds to a processing node in the first initial data flow graph, and the data generated by the segment of assignment statement corresponds to a data node in the first initial data flow graph, and there is an edge between the processing node and the data node; for another example, a function corresponds to a processing node in the first initial data flow graph, and one or more data used by the function corresponds to one or more data nodes in the first initial data flow graph, and there is an edge between the processing node and the one or more data nodes. Through the data flow graph, the source, conversion and final use of the data in the program can be tracked, which helps to discover data-related errors and optimize the use of data.

[0107] The first initial data flow graph is further explained in combination with an actual scenario: Assume that the target bytecode program is a calculator program that accepts two numbers input by the user and performs calculations based on the operator (addition, subtraction, multiplication, and division) selected by the user. In the generated first initial data flow graph, you can see how the two numbers input by the user flow from the input point to the calculation point and finally output the result. At the same time, you can also see how the choice of operator affects the calculation result.

[0108] In one embodiment, compiler front-end technology, including but not limited to lexical analysis, syntax analysis and semantic analysis, or a special static analysis tool, is used for the target bytecode program to perform variable analysis on the target bytecode program and establish data nodes and processing nodes in the data flow graph. Further, the data flow involved in the target bytecode program is determined, and then the established data nodes and processing nodes are connected in the data flow graph according to the determined data flow to establish edges in the data flow graph, and finally the first initial data flow graph corresponding to the target bytecode program is output.

[0109] S402: Determine the third type of abnormal nodes and the fourth type of abnormal nodes included in the first initial data flow graph.

[0110] The third type of abnormal node is a data node without an egress edge, and the fourth type of abnormal node is a data node that is not used by an adjacent processing node, where the adjacent processing node is a processing node connected to the egress edge of the data node.

[0111] Specifically, there may be redundant calculation results in the target bytecode program, including two situations: 1) the calculation results of any program code are not input into other program codes. 2) the calculation results of any program code are input into other program codes but are not used by other program codes.

[0112] Correspondingly, for the above situation 1), it can be determined in the first initial data flow graph based on whether each data node has an exit edge, where the exit edge refers to the edge from the data node to other processing nodes. When any data node does not have an exit edge, it means that the data node does not flow to any processing node, that is, the data (computation result) corresponding to the data node in the target bytecode program is redundant, and then the data node is regarded as the third type of abnormal node.

[0113] For the above situation 2), it is possible to determine in the first initial data flow graph whether any data node's adjacent processing node uses the data node. When any data node is not used by its adjacent processing node, it means that the data node does not affect the calculation or processing of the adjacent processing node after entering the adjacent processing node, that is, the data (calculation result) corresponding to the data node in the target bytecode program is redundant, and then the data node is regarded as the fourth type of abnormal node.

[0114] S403. Determine in the first initial data flow graph at least one edge connected to the third type of abnormal node as the third type of abnormal edge, and determine at least one edge connected to the fourth type of abnormal node as the fourth type of abnormal edge.

[0115] S404: Determine a third type of abnormal path according to the third type of abnormal nodes and the third type of abnormal edges, and determine a fourth type of abnormal path according to the fourth type of abnormal nodes and the fourth type of abnormal edges.

[0116] S405. Delete paths from the first initial data flow graph according to the third type of abnormal paths and the fourth type of abnormal paths to generate a first optimized data flow graph, and analyze the target bytecode program according to the first optimized data flow graph.

[0117] Redundant calculation results will not affect subsequent calculations or processing, so these calculation results can be ignored during the analysis of the target bytecode program. Correspondingly, ignoring these calculation results means deleting the third-category abnormal paths and the fourth-category abnormal paths corresponding to these calculation results in the first initial data flow graph, so that these calculation results are skipped during the analysis of the target bytecode program and are not included in the analysis scope.

[0118] A graph algorithm, such as a depth-first traversal algorithm (DFS) or a breadth-first traversal algorithm (BFS), is used for the first optimized data flow graph to traverse and analyze all paths starting from the starting node. By continuously exploring these paths, the behavior of the target bytecode program can be more deeply understood, potential problems can be discovered, and possible optimization opportunities can be identified, thereby ensuring the completeness and accuracy of the analysis results. In other words, the analysis of the target bytecode program can essentially be completed by traversing and analyzing each node and edge in the first optimized data flow graph corresponding to the target bytecode program.

[0119] Since the redundant calculation results will not affect the subsequent calculation or processing, the third type of abnormal nodes and the fourth type of abnormal nodes included in the first initial data flow graph are determined; wherein the third type of abnormal nodes are data nodes without an exit edge, the fourth type of abnormal nodes are data nodes that are not used by adjacent processing nodes, and the adjacent processing nodes are processing nodes connected to the exit edge of the data node, at least one edge connected to the third type of abnormal nodes is determined in the first initial data flow graph as the third type of abnormal edge, and at least one edge connected to the fourth type of abnormal nodes is determined as the fourth type of abnormal edge; according to the third type of abnormal nodes and the third type of abnormal nodes, The third type of abnormal path is determined according to the regular edge, and the fourth type of abnormal path is determined according to the fourth type of abnormal node and the fourth type of abnormal edge; the first initial data flow graph is path-pruned according to the third type of abnormal path and the fourth type of abnormal path to generate a first optimized data flow graph, and the target bytecode program is analyzed according to the first optimized data flow graph, thereby eliminating meaningless analysis paths in the data flow graph, simplifying the analysis process, avoiding meaningless consumption of computing resources and time, and improving the efficiency of the analysis of the target bytecode program; and it also helps to reduce errors that may be introduced due to overly complex path analysis, thereby improving the accuracy of the analysis of the target bytecode program.

[0120] Embodiment 5

[0121] Figure 5 This is a flowchart of a bytecode program analysis method provided in Embodiment 5 of the present invention. This embodiment further optimizes and expands the above embodiment and can be combined with the above optional implementations. Figure 5 As shown, the method includes:

[0122] S501. Obtain the target bytecode program to be analyzed.

[0123] S502: Replace the current input data of the target bytecode program with other input data, obtain the comparison bytecode program, and generate a second initial data flow graph corresponding to the target bytecode program and a comparison data flow graph corresponding to the comparison bytecode program.

[0124] Among them, there may be calculation results that are always constants, or calculation operations that always output constants in the target bytecode program. Since a certain calculation result is always a constant, or a certain calculation operation always outputs a constant, these calculation results or calculation operations are unnecessary. Therefore, in the process of analyzing the target bytecode program, the code blocks corresponding to these calculation results or calculation operations can be ignored. Correspondingly, ignoring these code blocks means deleting the paths corresponding to these code blocks in the initial data flow graph, so that these code blocks are skipped in the process of analyzing the target bytecode program and are not included in the analysis scope.

[0125] When a data node is always a constant in the initial data flow graph, it means that the data node does not change with the input data of the target bytecode program, and its value is always fixed. Therefore, if you want to determine whether a data node is a constant in the initial data flow graph, you need to change the input data of the target bytecode program to obtain different initial data flow graphs, and by comparing the values ​​of each data node in different initial data flow graphs, you can determine the data nodes that are always constants, and the corresponding processing nodes that always output constants.

[0126] The current input data represents the input of the target bytecode program, the other input data represents the input of the comparison bytecode program, and the comparison bytecode program represents the target bytecode program corresponding to the current input data after the other input data is replaced. It can be understood that the current input data and the other input data refer to two input data with different values. Correspondingly, when the input data of the target bytecode program is the current input data, the initial data flow graph corresponding to the target bytecode program is the second initial data flow graph; when the input data of the comparison bytecode program is the other input data, the initial data flow graph corresponding to the comparison bytecode program is the comparison data flow graph.

[0127] S503: Use the data nodes included in the second initial data flow graph as the first data nodes, and use the data nodes included in the comparison data flow graph as the second data nodes, and compare the first data nodes and the second data nodes at corresponding positions.

[0128] It is understandable that, since the target bytecode program and the comparison bytecode program differ only in the numerical value of the input data, and do not involve changes in other code levels, the second initial data flow graph corresponding to the target bytecode program and the comparison data flow graph corresponding to the comparison bytecode program have the same graph structure. Further, the data nodes included in the second initial data flow graph are taken as the first data nodes, and the data nodes included in the comparison data flow graph are taken as the second data nodes, and the first data nodes and the second data nodes at corresponding positions between the second initial data flow graph and the comparison data flow graph are compared.

[0129] Exemplarily, it is assumed that the first data nodes included in the second initial data flow graph include: data node 1, data node 2, and data node 3. The second data nodes included in the comparison data flow graph include: data node 4, data node 5, and data node 6. It is assumed that between the second initial data flow graph and the comparison data flow graph, the positions of data node 1 and data node 4 correspond, the positions of data node 2 and data node 5 correspond, and the positions of data node 3 and data node 6 correspond. Then, data node 1 and data node 4 are numerically compared, data node 2 and data node 5 are numerically compared, and data node 3 and data node 6 are numerically compared.

[0130] S504: The first data node having the same value as the second data node at the corresponding position is regarded as a fifth type of abnormal node, and the processing node connected to the entry edge of the fifth type of abnormal node in the second initial data flow graph is regarded as a sixth type of abnormal node.

[0131] Among them, the entry edge refers to the edge from other processing nodes to the data node.

[0132] Exemplarily, the above example is continued for explanation. Assuming that the values ​​of data node 1 and data node 4 are the same, data node 1 is regarded as the fifth type of abnormal node, and the processing node connected to the entry edge of "data node 1" is determined in the second initial data flow graph. Assuming that the processing node connected to the entry edge of "data node 1" is "processing node 1", "processing node 1" is regarded as the sixth type of abnormal node.

[0133] S505. Determine in the second initial data flow graph at least one edge connected to the fifth type of abnormal node as the fifth type of abnormal edge, and determine at least one edge connected to the sixth type of abnormal node as the sixth type of abnormal edge.

[0134] S506 : Determine a fifth type of abnormal path according to the fifth type of abnormal nodes and the fifth type of abnormal edges, and determine a sixth type of abnormal path according to the sixth type of abnormal nodes and the sixth type of abnormal edges.

[0135] S507. Delete paths from the second initial data flow graph according to the fifth type of abnormal paths and the sixth type of abnormal paths to generate a second optimized data flow graph, and analyze the target bytecode program according to the second optimized data flow graph.

[0136] Data nodes that are always constants and processing nodes that always output constants are unnecessary nodes. Therefore, the fifth type of abnormal path determined based on the five types of abnormal nodes and the sixth type of abnormal path determined based on the sixth type of abnormal nodes are deleted, so that these calculation results are skipped during the analysis of the target bytecode program and are not included in the analysis scope.

[0137] A graph algorithm, such as a depth-first traversal algorithm (DFS) or a breadth-first traversal algorithm (BFS), is used for the second optimized data flow graph to traverse and analyze all paths starting from the starting node. By continuously exploring these paths, the behavior of the target bytecode program can be more deeply understood, potential problems can be discovered, and possible optimization opportunities can be identified, thereby ensuring the completeness and accuracy of the analysis results. In other words, the analysis of the target bytecode program can essentially be completed by traversing and analyzing each node and edge in the second optimized data flow graph corresponding to the target bytecode program.

[0138] Since data nodes that are always constants and processing nodes that always output constants are unnecessary nodes, the current input data of the target bytecode program is replaced with other input data to obtain the comparison bytecode program, and a second initial data flow graph corresponding to the target bytecode program and a comparison data flow graph corresponding to the comparison bytecode program are generated; the first data node and the second data node at the corresponding position are compared; the first data node with the same value as the second data node at the corresponding position is taken as the fifth type of abnormal node, and the processing node connected to the entry edge of the fifth type of abnormal node in the second initial data flow graph is taken as the sixth type of abnormal node; at least one edge connected to the fifth type of abnormal node is determined in the second initial data flow graph as the fifth type of abnormal edge, and Determine at least one edge connected to the sixth type of abnormal node as the sixth type of abnormal edge; determine the fifth type of abnormal path according to the fifth type of abnormal node and the fifth type of abnormal edge, and determine the sixth type of abnormal path according to the sixth type of abnormal node and the sixth type of abnormal edge; perform path deletion on the second initial data flow graph according to the fifth type of abnormal path and the sixth type of abnormal path to generate a second optimized data flow graph, and analyze the target bytecode program according to the second optimized data flow graph, thereby eliminating meaningless analysis paths in the data flow graph, simplifying the analysis process, avoiding meaningless consumption of computing resources and time, and improving the efficiency of analyzing the target bytecode program; and, it also helps to reduce errors that may be introduced due to overly complex path analysis, and improves the accuracy of analyzing the target bytecode program.

[0139] Embodiment 6

[0140] Figure 6 This is a flowchart of a bytecode program analysis method provided by Embodiment 6 of the present invention. This embodiment further optimizes and expands the above embodiment and can be combined with the above optional implementations. Figure 6 As shown, the method includes:

[0141] S601, obtaining a target bytecode program to be analyzed, and generating an initial control flow graph corresponding to the target bytecode program; determining the connectivity between a starting node and other nodes in the initial control flow graph, and treating other nodes whose connectivity with the starting node is not connected as first-category abnormal nodes.

[0142] Among them, other nodes are nodes in the initial control flow graph except the starting node;

[0143] S602: Delete paths from the initial control flow graph according to the first type of abnormal nodes to generate a first optimized control flow graph.

[0144] S603: Determine at least one candidate code block included in the target bytecode program, and determine the code similarity between the candidate code blocks.

[0145] The candidate code block refers to a code block included in the target bytecode program, and the code block refers to a set of included codes.

[0146] There may be identical or highly similar candidate code blocks in the target bytecode program, and identical or highly similar candidate code blocks mean belonging to the same code pattern. In the process of analyzing the target bytecode program, identical or highly similar candidate code blocks contained in the same code pattern only need to be analyzed once to avoid repeated analysis.

[0147] Code similarity refers to the similarity of codes between different candidate code blocks. The higher the code similarity, the more similar the codes between different candidate code blocks are, that is, the greater the possibility that different candidate code blocks belong to the same code pattern; the lower the code similarity, the less similar the codes between different candidate code blocks are, that is, the smaller the possibility that different candidate code blocks belong to the same code pattern.

[0148] In one embodiment, the target bytecode program is lexically analyzed and decomposed into lexical units or tokens. These lexical units or tokens are converted into an abstract syntax tree to more clearly understand the structure and logic of the code. By traversing the abstract syntax tree, data flow and control flow analysis techniques are used to identify the code similarity between candidate code blocks.

[0149] In another embodiment, a code comparison tool is used to perform text comparison or structured comparison (such as comparison of control flow graphs and data flow graphs) on the target bytecode program, and based on the text comparison results or structured comparison results, the code similarity between each candidate code block is identified.

[0150] In another embodiment, a duplicate code detection algorithm (such as clone detection technology) is used to perform duplicate code detection on the target bytecode program to automatically identify candidate code blocks that are reused in different contexts of the target bytecode program, thereby identifying the code similarity between the candidate code blocks.

[0151] S604. Take at least two candidate code blocks whose code similarity is greater than a similarity threshold as repeated code blocks belonging to the same code pattern; determine the nodes and edges associated with the repeated code blocks of the same code pattern in the first optimized control flow graph, and use them as repeated nodes and repeated edges associated with the same code pattern, respectively.

[0152] Among them, the similarity threshold is used to determine whether at least two candidate code blocks belong to repeated code blocks of the same code pattern. If the code similarity between the two candidate code blocks is greater than the similarity threshold, that is, at least the candidate code blocks are identical or highly similar candidate code blocks, then at least the candidate code blocks belong to repeated code blocks of the same code pattern; if the code similarity between the two candidate code blocks is less than or equal to the similarity threshold, that is, at least the candidate code blocks are not identical or highly similar candidate code blocks, then at least the candidate code blocks do not belong to the same code pattern.

[0153] Exemplarily, it is assumed that the code similarity between candidate code block A and candidate code block B is greater than the similarity threshold, that is, candidate code block A and candidate code block B belong to repeated code blocks of the same code pattern. Assume that the nodes associated with candidate code block A in the first optimized control flow graph are "node 1", "node 2" and "node 3", and the associated edges are "edge 1" and "edge 2"; assume that the nodes associated with candidate code block B in the first optimized control flow graph are "node 4", "node 5" and "node 6", and the associated edges are "edge 3" and "edge 4", then "node 1", "node 2" and "node 3", "node 4", "node 5" and "node 6"; "edge 1", "edge 2", "edge 3" and "edge 4" are respectively regarded as repeated nodes and repeated edges associated with the same code pattern.

[0154] S605: Obtain the node to be analyzed currently in the first optimized control flow graph as the node to be analyzed, or obtain the edge to be analyzed currently in the first optimized control flow graph as the edge to be analyzed.

[0155] S606. If the node to be analyzed is a repeated node associated with any repeated code block, and the nodes and edges associated with other repeated code blocks in the first optimized control flow graph are in an analyzed state, then the analysis operation of the node to be analyzed is skipped; or, if the edge to be analyzed is a repeated edge associated with any repeated code block, and the nodes and edges associated with other repeated code blocks in the first optimized control flow graph are in an analyzed state, then the analysis of the edge to be analyzed is skipped.

[0156] Among them, other repeated code blocks are any repeated code blocks included in the target code pattern except the repeated code block, and the target code pattern is the code pattern to which the repeated code block belongs.

[0157] Exemplarily, assuming that the node to be analyzed is the repeated node "node 1" associated with repeated code block 1, and assuming that the code pattern to which repeated code block 1 belongs is "pattern 1", if "pattern 1" also includes repeated code blocks "repeated code block 2" and "repeated code block 3" in addition to "repeated code block 1", then "repeated code block 2" and "repeated code block 3" are regarded as other repeated code blocks.

[0158] Assuming that the nodes and edges associated with "repeated code block 2" in the first optimized control flow graph are in the analyzed state, that is, the analysis of all nodes and edges associated with "repeated code block 2" in the first optimized control flow graph has been completed, the analysis operation of "node 1" is skipped. This is because "repeated code block 2" and "repeated code block 1" belong to the same code pattern and do not need to be analyzed repeatedly.

[0159] Exemplarily, assuming that the node to be analyzed is the repeated edge "edge 1" associated with repeated code block 1, and assuming that the code pattern to which repeated code block 1 belongs is "pattern 1", if "pattern 1" also includes repeated code blocks "repeated code block 2" and "repeated code block 3" in addition to "repeated code block 1", then "repeated code block 2" and "repeated code block 3" are regarded as other repeated code blocks.

[0160] Assuming that the nodes and edges associated with "repeated code block 2" in the first optimized control flow graph are in the analyzed state, that is, the analysis of all nodes and edges associated with "repeated code block 2" in the first optimized control flow graph has been completed, the analysis operation of "edge 1" is skipped. This is because "repeated code block 2" and "repeated code block 1" belong to the same code pattern and do not need to be analyzed repeatedly.

[0161] If the node to be analyzed is a repeated node associated with any repeated code block, and the nodes and edges associated with other repeated code blocks in the first optimized control flow graph are in an analyzed state, the analysis operation of the node to be analyzed is skipped; or if the edge to be analyzed is a repeated edge associated with any repeated code block, and the nodes and edges associated with other repeated code blocks in the first optimized control flow graph are in an analyzed state, the analysis of the edge to be analyzed is skipped. This processing method is intended to improve the efficiency of the analysis, reduce unnecessary calculations, ensure that resources are effectively utilized, optimize the analysis process, and avoid repeated analysis work.

[0162] Embodiment 7

[0163] Figure 7 This is a flowchart of a bytecode program analysis method provided by Embodiment 7 of the present invention. This embodiment further optimizes and expands the above embodiment and can be combined with the above optional implementations. Figure 7 As shown, the method includes:

[0164] S701, obtaining a target bytecode program to be analyzed, and generating an initial control flow graph corresponding to the target bytecode program; determining the connectivity between a starting node and other nodes in the initial control flow graph, and treating other nodes whose connectivity with the starting node is not connected as first-category abnormal nodes.

[0165] Among them, other nodes are nodes in the initial control flow graph except the starting node;

[0166] S702: Delete paths from the initial control flow graph according to the first type of abnormal nodes to generate a first optimized control flow graph.

[0167] S703: Determine at least one candidate code block included in the target bytecode program.

[0168] S704: If the current code structure corresponding to any candidate code block matches the vulnerability code structure corresponding to any known vulnerability code block, the analysis priority of the nodes and edges associated with the candidate code block in the first optimized control flow graph is set to the first analysis priority.

[0169] Among them, the vulnerable code block refers to a collection of codes that have been identified as having security issues.

[0170] In one embodiment, a bytecode analysis tool is used to parse the target bytecode program to determine the current code structure corresponding to each candidate code block in the target bytecode program, including but not limited to function calls, loop structures, conditional statements, and other code structures. The current code structure corresponding to each candidate code block is matched with the vulnerability code structure corresponding to each pre-extracted vulnerability code block (also including but not limited to function calls, loop structures, conditional statements, and other code structures). If it is determined that the similarity between the current code structure corresponding to any candidate code block and the vulnerability code structure corresponding to any vulnerability code block is greater than a similarity threshold, then it is determined that the current code structure corresponding to the candidate code block matches the vulnerability code structure corresponding to the vulnerability code block.

[0171] It can be understood that since the vulnerable code blocks have all been identified as having security issues, and the current code structure corresponding to the candidate code block matches the vulnerable code structure corresponding to a vulnerable code block, it means that the candidate code block has a security risk and needs to be analyzed first when analyzing the target bytecode program. Therefore, the analysis priority of the nodes and edges associated with the candidate code block in the first optimized control flow graph is set to the first analysis priority.

[0172] S705: If the current code structure corresponding to any candidate code block does not match the vulnerability code structures corresponding to all known vulnerability code blocks, the analysis priority of the nodes and edges associated with the candidate code block in the first optimized control flow graph is set to the second analysis priority.

[0173] In one implementation, if it is determined that the similarity between the current code structure corresponding to any candidate code block and the vulnerability code structures corresponding to all vulnerability code blocks is less than or equal to a similarity threshold, then it is determined that the current code structure corresponding to the candidate code block does not match the vulnerability code structures corresponding to all vulnerability code blocks.

[0174] It is understandable that since the vulnerable code blocks have been identified as having security issues, and the current code structure corresponding to the candidate code block does not match the vulnerable code structure corresponding to any vulnerable code block, it means that the candidate code block does not have a security risk, or has a lower security risk, so the analysis priority of the nodes and edges associated with the candidate code block in the first optimized control flow graph is set to the second analysis priority. Among them, the first analysis priority is higher than the second analysis priority, that is, when analyzing each node and each edge in the first optimized control flow graph, the nodes and edges with the analysis priority of "the first analysis priority" are analyzed first.

[0175] S706: Obtain the analysis priority of each node and each edge in the first optimized control flow graph, and analyze the target bytecode program according to the analysis priority of each node and each edge.

[0176] In one embodiment, the analysis priority of each node and each edge in the first optimized control flow graph is obtained, and it is determined whether the analysis priority of each node and each edge is a "first analysis priority" or a "second analysis priority", and the nodes and edges corresponding to the "first analysis priority" are analyzed first, and the nodes and edges corresponding to the "second analysis priority" are analyzed with a delay.

[0177] If the current code structure corresponding to any candidate code block matches the vulnerability code structure corresponding to any known vulnerability code block, the analysis priority of the nodes and edges associated with the candidate code block in the first optimized control flow graph is set to the first analysis priority; if the current code structure corresponding to any candidate code block does not match the vulnerability code structures corresponding to all known vulnerability code blocks, the analysis priority of the nodes and edges associated with the candidate code block in the first optimized control flow graph is set to the second analysis priority; wherein the first analysis priority is higher than the second analysis priority, the analysis priority of each node and each edge in the first optimized control flow graph is obtained, and the target bytecode program is analyzed according to the analysis priority of each node and each edge, thereby ensuring that the analysis is not only fast but also accurate, so that resources are concentrated on giving priority to those code parts that may really affect the security of the application, aiming to improve the effect of the entire security review and code optimization.

[0178] This embodiment also provides a process for analyzing the impact of modifying the target bytecode program interface:

[0179] 1) Determine which lines of code, functions, or modules in the target bytecode program are affected by the interface change, including:

[0180] Interface definition analysis:

[0181] First, review the specific content of the interface change in detail. This includes looking at the old and new definitions of the interface and comparing the differences between them to identify the specific operations that were added, deleted, or modified.

[0182] Dependency Analysis:

[0183] Using your code analysis tool or the dependency graph feature of your IDE (Integrated Development Environment), identify all the lines of code, functions, or modules that directly call or depend on the interface. These are usually the immediate targets that are affected.

[0184] Control flow and data flow analysis:

[0185] Build or update control flow graphs and data flow graphs to track call sequences and data propagation paths through the code. By analyzing these graphs, you can identify potential impact paths starting from the interface change.

[0186] Deep traversal and pattern matching:

[0187] Use a depth-first search (DFS) or breadth-first search (BFS) algorithm to traverse the code graph and look for patterns or paths associated with the changed interface. This helps to find indirect effects, i.e. code that does not directly call the interface but may be affected by the interface change.

[0188] Static code review:

[0189] Perform a static code review to check all affected lines of code, functions, and modules. This includes checking parameter types, return values, exception handling, and any logic that may depend on the behavior of the interface.

[0190] Test verification:

[0191] Write or update unit, integration, and system tests to verify the correctness of the interface changes and check for any unanticipated impacts. Automated test suites are particularly helpful at this time because they can execute quickly and provide feedback on the scope of the impact.

[0192] Document Review:

[0193] Review documentation related to the interface, including API documentation, design documents, or user manuals. This helps identify changes that may affect developers, users, or system integrators.

[0194] 2) Evaluate the impact of these changes on program functionality, performance, and security, including:

[0195] 1. Functional impact analysis

[0196] a. Interface function changes:

[0197] Carefully review the changes to the interface and understand the purpose and impact of each change.

[0198] Analyze whether the new interface function is compatible with other parts of the existing system and whether it will cause certain functions to fail or behave abnormally.

[0199] b. Business process analysis:

[0200] Analyze whether the interface changes will affect existing business processes, such as order processing, user authentication, etc.

[0201] Check whether the business logic needs to be updated to adapt to the changes in the interface.

[0202] c. Integration testing:

[0203] Perform integration testing to verify whether the interactions between system components are normal after the interface changes.

[0204] Pay special attention to checking edge cases and exception handling logic related to changing interfaces.

[0205] 2. Performance impact analysis

[0206] a. Response time:

[0207] Analyze whether the interface changes will increase processing time and cause the system response time to slow down.

[0208] Use performance testing tools to simulate high-concurrency scenarios and test the performance of the modified interfaces.

[0209] b. Resource consumption:

[0210] Evaluate whether the modified interface consumes more CPU, memory, or disk resources.

[0211] Monitor the system's resource usage to ensure that changes do not cause resource bottlenecks.

[0212] c. Scalability:

[0213] Analyze the impact of interface changes on system scalability, especially in distributed systems or microservice architectures.

[0214] Ensure that the modified interface can support horizontal expansion to cope with future load growth.

[0215] 3. Security impact analysis

[0216] a. Input Validation:

[0217] Check whether the modified interface has adequately validated all inputs to prevent security issues such as SQL injection and cross-site scripting (XSS).

[0218] Ensure that the interface can handle abnormal input and malicious requests.

[0219] b. Access Control:

[0220] Verify that the interface still follows appropriate access control policies, such as authentication, authorization, etc., after the change.

[0221] Ensure that only authorized users can access the modified interfaces.

[0222] c. Data Protection:

[0223] Analyze whether the changes may lead to the disclosure or tampering of sensitive data.

[0224] Ensure that all sensitive data is properly encrypted and protected while in transit and at storage.

[0225] d. Logging and Monitoring:

[0226] Ensure that the modified interfaces have appropriate logging and monitoring mechanisms to detect and respond to potential security threats in a timely manner.

[0227] 3) Provide repair suggestions or code refactoring solutions.

[0228] 1. Problem location and analysis:

[0229] First, pinpoint the area of ​​the code where the problem occurs and analyze the root cause of the problem. This may involve diving into the specific implementation of the code to understand the problematic logic, data flow, or performance bottleneck.

[0230] 2. Develop a repair plan:

[0231] Depending on the nature of the problem, make specific suggestions for fixes. For example, if the problem is caused by a code logic error, provide specific code examples for modifying the logic.

[0232] For performance issues, recommendations may be made to optimize algorithms or improve data processing methods.

[0233] Security issues may require the addition or modification of security controls, such as strengthening input validation, revising permission checks, etc.

[0234] 3. Code refactoring suggestions:

[0235] If the problem is caused by poor code structure, you may need to propose a code refactoring plan. For example, you can suggest modular reorganization of the code to split complex functions into smaller, more manageable units. Provide a refactored code structure diagram and pseudocode to help developers better understand the proposed structure.

[0236] 4. Consider implementation impact:

[0237] When proposing any fixes or refactorings, consider the impact of these changes on the existing system. Evaluate the resources and time required for the change, as well as the new problems that may arise.

[0238] 5. Documentation suggestions:

[0239] Document all repair suggestions or reconstruction plans in detail, including specific operation steps, expected results and implementation risks.

[0240] Provide enough code examples and reference material to ensure that the development team can clearly understand and implement the recommendations.

[0241] 6. Review and Feedback:

[0242] Before implementation, code review should be conducted and other developers or architects should be invited to participate in the discussion of the repair or refactoring plan to ensure the effectiveness and security of the plan. After implementation, feedback should be collected, the effect of the repair or refactoring should be evaluated, and adjustments should be made if necessary.

[0243] 4) Organize the analysis results into an easy-to-understand report format and generate an analysis report.

[0244] All affected lines of code, functions, and modules should be documented and a detailed report should be generated. The report should include a description of the affected scope, potential risks, recommended fixes, and any relevant test results.

[0245] 5) Output analysis report to developers or testers.

[0246] Embodiment 8

[0247] Figure 8 A schematic diagram of the structure of a bytecode program analysis device provided in Embodiment 8 of the present invention. Figure 8 As shown, the device comprises:

[0248] An initial control flow graph generation module 81 is used to obtain a target bytecode program to be analyzed and generate an initial control flow graph corresponding to the target bytecode program;

[0249] The first type abnormal node determination module 82 is used to determine the connectivity between the starting node and other nodes in the initial control flow graph, and to regard other nodes whose connectivity with the starting node is not connected as the first type abnormal nodes; wherein the other nodes are nodes other than the starting node in the initial control flow graph;

[0250] The first optimized control flow graph generation module 83 is used to perform path deletion on the initial control flow graph according to the first type of abnormal nodes, generate a first optimized control flow graph, and analyze the target bytecode program according to the first optimized control flow graph.

[0251] Optionally, the first optimized control flow graph generating module 83 is specifically used for:

[0252] Determine at least one edge connected to the first type of abnormal node in the initial control flow graph as the first type of abnormal edge;

[0253] A first type of abnormal path is determined according to the first type of abnormal nodes and the first type of abnormal edges, and the initial control flow graph is pruned according to the first type of abnormal path to generate a first optimized control flow graph.

[0254] Optionally, the device further includes a second optimized control flow graph generating module, which is specifically used to:

[0255] Obtaining a historical bytecode program corresponding to the target bytecode program in a historical version; wherein the historical bytecode program is a bytecode program that has completed analysis;

[0256] Determine the function code blocks in the target bytecode program that have not changed compared to the historical bytecode program, and determine the nodes and edges associated with the function code blocks in the initial control flow graph as the second type of abnormal nodes and the second type of abnormal edges, respectively;

[0257] Determine a second type of abnormal path according to the second type of abnormal nodes and the second type of abnormal edges, and perform path deletion on the initial control flow graph according to the second type of abnormal paths to generate a second optimized control flow graph;

[0258] The target bytecode program is analyzed according to the second optimized control flow graph.

[0259] Optionally, the device further includes a first optimized data flow graph generating module, which is specifically used to:

[0260] Generate a first initial data flow graph corresponding to the target bytecode program;

[0261] Determine a third type of abnormal node and a fourth type of abnormal node included in the first initial data flow graph; wherein the third type of abnormal node is a data node without an exit edge, and the fourth type of abnormal node is a data node that is not used by an adjacent processing node, and the adjacent processing node is a processing node connected to the exit edge of the data node;

[0262] Determine in the first initial data flow graph at least one edge connected to the third type of abnormal node as the third type of abnormal edge, and determine at least one edge connected to the fourth type of abnormal node as the fourth type of abnormal edge;

[0263] Determine a third type of abnormal path according to the third type of abnormal nodes and the third type of abnormal edges, and determine a fourth type of abnormal path according to the fourth type of abnormal nodes and the fourth type of abnormal edges;

[0264] The first initial data flow graph is pruned according to the third type of abnormal path and the fourth type of abnormal path to generate a first optimized data flow graph, and the target bytecode program is analyzed according to the first optimized data flow graph.

[0265] Optionally, the device further includes a second optimized data flow graph generating module, which is specifically used to:

[0266] Replace the current input data of the target bytecode program with other input data, obtain the comparison bytecode program, and generate a second initial data flow graph corresponding to the target bytecode program and a comparison data flow graph corresponding to the comparison bytecode program;

[0267] The data nodes included in the second initial data flow graph are taken as the first data nodes, and the data nodes included in the comparison data flow graph are taken as the second data nodes, and the first data nodes and the second data nodes at corresponding positions are compared;

[0268] The first data node having the same value as the second data node at the corresponding position is regarded as a fifth type of abnormal node, and the processing node connected to the entry edge of the fifth type of abnormal node in the second initial data flow graph is regarded as a sixth type of abnormal node;

[0269] Determine in the second initial data flow graph at least one edge connected to the fifth type of abnormal node as the fifth type of abnormal edge, and determine at least one edge connected to the sixth type of abnormal node as the sixth type of abnormal edge;

[0270] Determine a fifth type of abnormal path according to the fifth type of abnormal nodes and the fifth type of abnormal edges, and determine a sixth type of abnormal path according to the sixth type of abnormal nodes and the sixth type of abnormal edges;

[0271] The second initial data flow graph is subjected to path deletion according to the fifth type of abnormal path and the sixth type of abnormal path to generate a second optimized data flow graph, and the target bytecode program is analyzed according to the second optimized data flow graph.

[0272] Optionally, the device further includes an abnormal code deletion module, which is specifically used to:

[0273] Obtaining an original bytecode program, and determining unused local variables in the original bytecode program as abnormal local variables, and unused parameters as abnormal parameters;

[0274] When the number of abnormal local variables is less than a first threshold, and the number of abnormal parameters is less than a second threshold, the abnormal local variables and the abnormal parameters are deleted in the original bytecode program to obtain a target bytecode program.

[0275] Optionally, the device further includes a code refactoring prompt module, which is specifically used to:

[0276] When the number of variables of abnormal local variables is greater than or equal to a first threshold, or the number of parameters of abnormal parameters is greater than or equal to a second threshold, code refactoring prompt information is generated; wherein the code refactoring prompt information is used to prompt the user to refactor the original bytecode program.

[0277] Optionally, the device further includes a repeated code block processing module, which is specifically used to:

[0278] Determine at least one candidate code block included in the target bytecode program, and determine the code similarity between the candidate code blocks;

[0279] Taking at least two candidate code blocks whose code similarity is greater than a similarity threshold as repeated code blocks belonging to the same code pattern;

[0280] Determine nodes and edges associated with repeated code blocks of the same code pattern in the first optimized control flow graph as repeated nodes and repeated edges associated with the same code pattern, respectively;

[0281] The first optimized control flow graph generating module 83 is further used for:

[0282] Obtaining a node to be analyzed currently in the first optimized control flow graph as a node to be analyzed, or obtaining an edge to be analyzed currently in the first optimized control flow graph as an edge to be analyzed;

[0283] If the node to be analyzed is a repeated node associated with any repeated code block, and the nodes and edges associated with other repeated code blocks in the first optimized control flow graph are in an analyzed state, then the analysis operation of the node to be analyzed is skipped; or, if the edge to be analyzed is a repeated edge associated with any repeated code block, and the nodes and edges associated with other repeated code blocks in the first optimized control flow graph are in an analyzed state, then the analysis of the edge to be analyzed is skipped;

[0284] Among them, other repeated code blocks are any repeated code blocks included in the target code pattern except the repeated code block, and the target code pattern is the code pattern to which the repeated code block belongs.

[0285] Optionally, the device further includes a vulnerability code block matching module, which is specifically used to:

[0286] If the current code structure corresponding to any candidate code block matches the vulnerability code structure corresponding to any known vulnerability code block, the analysis priority of the nodes and edges associated with the candidate code block in the first optimized control flow graph is set to the first analysis priority;

[0287] If the current code structure corresponding to any candidate code block does not match the vulnerability code structures corresponding to all known vulnerability code blocks, the analysis priority of the nodes and edges associated with the candidate code block in the first optimized control flow graph is set to the second analysis priority; wherein the first analysis priority is higher than the second analysis priority;

[0288] The first optimized control flow graph generating module 83 is further used for:

[0289] The analysis priority of each node and each edge in the first optimized control flow graph is obtained, and the target bytecode program is analyzed according to the analysis priority of each node and each edge.

[0290] The bytecode program analysis device provided in the embodiment of the present invention can execute the bytecode program analysis method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.

[0291] Embodiment 9

[0292] Fig. 9 A schematic diagram of an electronic device 90 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.

[0293] like Fig. 9 As shown, the electronic device 90 includes at least one processor 91, and a memory connected to the at least one processor 91 in communication, such as a read-only memory (ROM) 92, a random access memory (RAM) 93, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 91 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 92 or the computer program loaded from the storage unit 98 to the random access memory (RAM) 93. In the RAM 93, various programs and data required for the operation of the electronic device 90 can also be stored. The processor 91, the ROM 92, and the RAM 93 are connected to each other via a bus 94. An input / output (I / O) interface 95 is also connected to the bus 94.

[0294] A number of components in the electronic device 90 are connected to the I / O interface 95, including: an input unit 96, such as a keyboard, a mouse, etc.; an output unit 97, such as various types of displays, speakers, etc.; a storage unit 98, such as a disk, an optical disk, etc.; and a communication unit 99, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 99 allows the electronic device 90 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0295] The processor 91 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 91 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 91 executes the various methods and processes described above, such as the analysis method of the bytecode program.

[0296] In some embodiments, the analysis method of the bytecode program may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 98. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 90 via the ROM 92 and / or the communication unit 99. When the computer program is loaded into the RAM 93 and executed by the processor 91, one or more steps of the analysis method of the bytecode program described above may be performed. Alternatively, in other embodiments, the processor 91 may be configured to execute the analysis method of the bytecode program in any other appropriate manner (e.g., by means of firmware).

[0297] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0298] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.

[0299] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, device, or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0300] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).

[0301] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.

[0302] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.

[0303] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.

[0304] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims

1. A method for analyzing a bytecode program, characterized in that: include: Obtaining a target bytecode program to be analyzed, and generating an initial control flow graph corresponding to the target bytecode program; Determine the connectivity between the starting node and other nodes in the initial control flow graph, and use the other nodes whose connectivity with the starting node is not connected as the first type of abnormal nodes; wherein the other nodes are nodes in the initial control flow graph other than the starting node; Delete paths from the initial control flow graph according to the first type of abnormal nodes to generate a first optimized control flow graph, and analyze the target bytecode program according to the first optimized control flow graph; Wherein, after generating the initial control flow graph corresponding to the target bytecode program, the method further includes: Obtaining a historical bytecode program corresponding to the target bytecode program in a historical version; wherein the historical bytecode program is a bytecode program that has completed analysis; Determine a function code block in the target bytecode program that has not changed relative to the historical bytecode program, and determine nodes and edges associated with the function code block in the initial control flow graph as second-type abnormal nodes and second-type abnormal edges, respectively; Determine a second type of abnormal path according to the second type of abnormal nodes and the second type of abnormal edges, and perform path deletion on the initial control flow graph according to the second type of abnormal paths to generate a second optimized control flow graph; The target bytecode program is analyzed according to the second optimized control flow graph.

2. The method according to claim 1, characterized in that: The step of performing path deletion on the initial control flow graph according to the first type of abnormal nodes to generate a first optimized control flow graph includes: Determine at least one edge connected to the first type of abnormal node in the initial control flow graph as a first type of abnormal edge; A first type of abnormal path is determined according to the first type of abnormal nodes and the first type of abnormal edges, and the initial control flow graph is pruned according to the first type of abnormal paths to generate the first optimized control flow graph.

3. The method according to claim 1, after obtaining the target bytecode program to be analyzed, further comprising: Generating a first initial data flow graph corresponding to the target bytecode program; Determine a third type of abnormal node and a fourth type of abnormal node included in the first initial data flow graph; wherein the third type of abnormal node is a data node without an exit edge, and the fourth type of abnormal node is a data node that is not used by an adjacent processing node, and the adjacent processing node is a processing node connected to the exit edge of the data node; Determine in the first initial data flow graph at least one edge connected to the third type abnormal node as the third type abnormal edge, and determine at least one edge connected to the fourth type abnormal node as the fourth type abnormal edge; Determine a third type of abnormal path according to the third type of abnormal nodes and the third type of abnormal edges, and determine a fourth type of abnormal path according to the fourth type of abnormal nodes and the fourth type of abnormal edges; The first initial data flow graph is subjected to path deletion according to the third type of abnormal path and the fourth type of abnormal path to generate a first optimized data flow graph, and the target bytecode program is analyzed according to the first optimized data flow graph.

4. The method according to claim 1, after obtaining the target bytecode program to be analyzed, further comprising: Replacing current input data of the target bytecode program with other input data, obtaining a comparison bytecode program, and generating a second initial data flow graph corresponding to the target bytecode program and a comparison data flow graph corresponding to the comparison bytecode program; The data nodes included in the second initial data flow graph are used as first data nodes, and the data nodes included in the comparison data flow graph are used as second data nodes, and the first data nodes and the second data nodes at corresponding positions are compared; The first data node having the same value as the second data node at the corresponding position is regarded as a fifth type of abnormal node, and the processing node connected to the entry edge of the fifth type of abnormal node in the second initial data flow graph is regarded as a sixth type of abnormal node; Determine in the second initial data flow graph at least one edge connected to the fifth type of abnormal node as the fifth type of abnormal edge, and determine at least one edge connected to the sixth type of abnormal node as the sixth type of abnormal edge; Determine a fifth type of abnormal path according to the fifth type of abnormal nodes and the fifth type of abnormal edges, and determine a sixth type of abnormal path according to the sixth type of abnormal nodes and the sixth type of abnormal edges; The second initial data flow graph is subjected to path deletion according to the fifth type of abnormal path and the sixth type of abnormal path to generate a second optimized data flow graph, and the target bytecode program is analyzed according to the second optimized data flow graph.

5. The method according to claim 1, before obtaining the target bytecode program to be analyzed, further comprising: Obtaining an original bytecode program, and determining unused local variables in the original bytecode program as abnormal local variables, and unused parameters as abnormal parameters; When the number of variables of the abnormal local variables is less than a first threshold, and the number of parameters of the abnormal parameters is less than a second threshold, the abnormal local variables and the abnormal parameters are deleted in the original bytecode program to obtain the target bytecode program.

6. The method according to claim 5, after determining that unused local variables in the original bytecode program are abnormal local variables and unused parameters are abnormal parameters, further comprising: When the number of variables of the abnormal local variables is greater than or equal to a first threshold, or the number of parameters of the abnormal parameters is greater than or equal to a second threshold, code refactoring prompt information is generated; wherein the code refactoring prompt information is used to prompt the user to perform code refactoring on the original bytecode program.

7. The method according to claim 1, before analyzing the target bytecode program according to the first optimized control flow graph, further comprising: Determine at least one candidate code block included in the target bytecode program, and determine the code similarity between the candidate code blocks; Taking at least two of the candidate code blocks whose code similarity is greater than a similarity threshold as repeated code blocks belonging to the same code pattern; Determine the nodes and edges associated with the repeated code blocks of the same code pattern in the first optimized control flow graph as the repeated nodes and repeated edges associated with the same code pattern, respectively; The analyzing the target bytecode program according to the first optimized control flow graph includes: Obtaining a node to be analyzed currently in the first optimized control flow graph as a node to be analyzed, or obtaining an edge to be analyzed currently in the first optimized control flow graph as an edge to be analyzed; If the node to be analyzed is a repeated node associated with any of the repeated code blocks, and the nodes and edges associated with other repeated code blocks in the first optimized control flow graph are in an analyzed state, then the analysis operation on the node to be analyzed is skipped; or, if the edge to be analyzed is a repeated edge associated with any of the repeated code blocks, and the nodes and edges associated with other repeated code blocks in the first optimized control flow graph are in an analyzed state, then the analysis of the edge to be analyzed is skipped; The other repeated code blocks are any repeated code blocks included in the target code pattern except the repeated code block, and the target code pattern is the code pattern to which the repeated code block belongs.

8. The method according to claim 7, after determining at least one candidate code block included in the target bytecode program, further comprising: If the current code structure corresponding to any of the candidate code blocks matches the vulnerability code structure corresponding to any known vulnerability code block, the analysis priority of the nodes and edges associated with the candidate code block in the first optimized control flow graph is set to the first analysis priority; If the current code structure corresponding to any of the candidate code blocks does not match the vulnerability code structures corresponding to all known vulnerability code blocks, the analysis priority of the nodes and edges associated with the candidate code block in the first optimized control flow graph is set to a second analysis priority; wherein the first analysis priority is higher than the second analysis priority; The analyzing the target bytecode program according to the first optimized control flow graph includes: The analysis priority of each node and each edge in the first optimized control flow graph is obtained, and the target bytecode program is analyzed according to the analysis priority of each node and each edge.

9. A bytecode program analysis device, characterized in that: include: An initial control flow graph generation module, used to obtain a target bytecode program to be analyzed and generate an initial control flow graph corresponding to the target bytecode program; A first-type abnormal node determination module is used to determine the connectivity between the starting node and other nodes in the initial control flow graph, and to use the other nodes whose connectivity with the starting node is not connected as the first-type abnormal nodes; wherein the other nodes are nodes other than the starting node in the initial control flow graph; a first optimized control flow graph generating module, configured to perform path deletion on the initial control flow graph according to the first type of abnormal nodes, generate a first optimized control flow graph, and analyze the target bytecode program according to the first optimized control flow graph; The device further includes a second optimized control flow graph generating module, which is specifically used for: Obtaining a historical bytecode program corresponding to the target bytecode program in a historical version; wherein the historical bytecode program is a bytecode program that has completed analysis; Determine a function code block in the target bytecode program that has not changed relative to the historical bytecode program, and determine nodes and edges associated with the function code block in the initial control flow graph as second-type abnormal nodes and second-type abnormal edges, respectively; Determine a second type of abnormal path according to the second type of abnormal nodes and the second type of abnormal edges, and perform path deletion on the initial control flow graph according to the second type of abnormal paths to generate a second optimized control flow graph; The target bytecode program is analyzed according to the second optimized control flow graph.

10. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can perform the bytecode program analysis method according to any one of claims 1 to 8.

11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to execute the bytecode program analysis method according to any one of claims 1 to 8.