WO2022206062A1 - 一种函数调用关系检测方法及装置 - Google Patents

一种函数调用关系检测方法及装置 Download PDF

Info

Publication number
WO2022206062A1
WO2022206062A1 PCT/CN2021/141990 CN2021141990W WO2022206062A1 WO 2022206062 A1 WO2022206062 A1 WO 2022206062A1 CN 2021141990 W CN2021141990 W CN 2021141990W WO 2022206062 A1 WO2022206062 A1 WO 2022206062A1
Authority
WO
WIPO (PCT)
Prior art keywords
node
function
detected
fractal
tree
Prior art date
Application number
PCT/CN2021/141990
Other languages
English (en)
French (fr)
Inventor
白明乾
Original Assignee
深圳前海微众银行股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳前海微众银行股份有限公司 filed Critical 深圳前海微众银行股份有限公司
Publication of WO2022206062A1 publication Critical patent/WO2022206062A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites

Definitions

  • the present application relates to the network technology field of financial technology (Fintech), and in particular, to a method and device for detecting a function call relationship.
  • one method is call hierarchy (function call hierarchy tree), and the function call hierarchy tree generated by this method can include all functions in the code to be tested; but this method cannot identify the if in the code to be tested.
  • Statement block, switch statement block and overriding rewrite function, and the branch of the execution relationship of 'or' of these three methods is directly represented as serial execution, which reduces the accuracy of the generated function call hierarchy tree and further reduces code detection.
  • One method is the function call sequence 3D fractal tree. Although this method can identify the if statement block, switch statement block and overriding function in the code to be detected, it can only 'or' the three methods according to a fixed algorithm.
  • the execution branch of the relationship is calculated to obtain the calculation result, and the calculation result is used as the called function, and the original function calling sequence of the three methods in the code to be detected is lost, and the code detection accuracy is reduced.
  • Another method is to obtain the function call sequence at runtime by running the code to be tested. In this method, when the code to be tested contains an execution branch with an 'or' relationship, only the execution sequence of one branch is obtained, resulting in a different function call sequence. Complete, reducing code detection accuracy.
  • the embodiments of the present application provide a method and device for detecting a function call relationship, which can obtain a complete function call relationship of a code to be detected, and increase the accuracy of the detected code.
  • an embodiment of the present application provides a method for detecting a function call relationship, the method comprising:
  • the node information includes a node label used to represent whether the function to be detected is a fractal node; build a first fractal tree according to the node information of each first function to be detected, and A second fractal tree is constructed according to the node information of each second function to be detected; wherein, the first function to be detected is a function to be detected whose node label indicates a non-fractal node; the second function to be detected is a function to be detected whose node label indicates a fractal node Detecting a function; constructing a 3D fractal tree according to the first fractal tree and the second fractal tree; determining whether the functions to be detected conform to a function calling relationship through the 3D fractal tree.
  • the information of the function to be detected in the 3D fractal tree is determined, and whether the function to be detected is included as a fractal label of a fractal node;
  • the function to be detected is analyzed in a fractal node mode or in a non-fractal node mode.
  • the node information of the fractal node and the non-fractal node can be obtained, so that the 3D fractal tree contains the first fractal tree, that is, the calling relationship between the first function to be detected of the non-fractal node, and the relationship between the non-fractal node and the fractal node.
  • a calling relationship a calling relationship
  • a second fractal tree that is, the calling relationship of each second function to be detected in the fractal node.
  • the node information further includes child nodes; the child nodes are functions called by the functions to be detected; the constructing the first fractal tree according to the node information of each first function to be detected includes: for any first The function to be detected, taking the first function to be detected as the root node of the first fractal tree, taking the root node as the first construction node, and determining whether the child nodes of the first construction node are non-fractal nodes; if it is The non-fractal node constructs the child node as the next layer node of the first construction node, and uses the next layer node as the first construction node, and returns to determine whether the child node of the first construction node is a The step of non-fractal node; if the child node of the first construction node is a fractal node, construct the child node as a virtual node of the first construction node without child nodes; until the first fractal tree Neither node has child nodes.
  • the child node of the non-fractal node of the first function to be detected is taken as the first layer node under the root node of the first fractal tree, and the The fractal node is used as a virtual node without child nodes; the second layer node of the first fractal tree is constructed according to the child node set of the child node in the node information of the child node; the first fractal tree is constructed in this circular manner, until None of the nodes in the first fractal tree have child nodes.
  • the function calling relationship level of the first function to be detected in the first fractal tree is clear, the calling relationship of the function to be detected corresponding to each node in the first fractal tree is accurately determined, and the accuracy of function calling relationship detection is improved. If the child node is a fractal node, the child node is constructed as a virtual node without child nodes in the first fractal tree.
  • all functions contained in the fractal node, or other virtual function information can be set in the virtual node, so that when the second fractal tree corresponding to each second function to be detected in the fractal node is subsequently determined, the first The binary fractal tree is supplemented at the corresponding fractal node position of the first fractal tree, increasing the accuracy and integrity of the 3D fractal tree.
  • the constructing the second fractal tree according to the node information of each second function to be detected includes: for any second function to be detected, generating a virtual node of the second function to be detected as a part of the second fractal tree. a root node; generate a virtual node corresponding to any function branch of the second function to be detected as the first layer node under the root node of the second fractal tree;
  • the child node of the second construction node is a non-fractal node; if the child node of the second construction node is a non-fractal node, then the child node is constructed as The next layer node of the second construction node, and the next layer node is used as the second construction node, and returns to the step of judging whether the child node of the second construction node is a non-fractal node; if the second construction node
  • the sub-nodes of the construction node are fractal nodes, and the sub-nodes are constructed as virtual nodes of the second construction node that do not have sub-nodes; until any node in the second fractal tree has no sub-nodes.
  • the virtual node of the second function to be detected is used as the root node of the second fractal tree, and the virtual node corresponding to any function branch of the second function to be detected is used as the first node under the root node of the second fractal tree. layer node.
  • the virtual node of the second function to be detected that is, the root node, can represent the source of at least one function branch, and the virtual node corresponding to the function branch can represent the number of function branches; and then the function called in the function branch corresponds to the function branch.
  • the child node of the virtual node is used as the root node of the second fractal tree, and the virtual node corresponding to any function branch of the second function to be detected is used as the first node under the root node of the second fractal tree. layer node.
  • the function called by each branch in the fractal node can be accurately and clearly characterized, so that the function calling relationship in the second fractal tree corresponding to the fractal node is accurate, the accuracy and integrity of the 3D fractal tree are improved, and the function calling relationship is further improved. detection accuracy.
  • any function branch of the second function to be detected also includes a fractal node
  • a second fractal tree corresponding to the fractal node is constructed, and the second fractal tree can be added to the In the second fractal tree where the fractal node is located, the function calling relationship in the second fractal tree is accurate and complete, and the accuracy and integrity of the 3D fractal tree are further improved.
  • constructing a 3D fractal tree according to the first fractal tree and the second fractal tree includes: determining a second fractal tree corresponding to a virtual node in the first fractal tree; A virtual node in the tree that fuses the first fractal tree and the second fractal into a 3D fractal tree.
  • the second fractal tree corresponding to the fractal node is supplemented into the first fractal tree through the virtual node corresponding to the fractal node in the first fractal tree to obtain a fused 3D fractal tree.
  • the 3D fractal tree contains the function call relationship of all functions to be detected in the code to be detected.
  • the fusion of the first fractal tree and the second fractal into a 3D fractal tree includes:
  • the second fractal tree corresponding to the virtual node is added to the virtual node corresponding to the first fractal tree to obtain a 3D fractal tree in which the first fractal tree and the second fractal tree are fused.
  • a 3D branch with different branches is obtained, which is a fusion of the branches of the first fractal tree and the second fractal tree. Fractal tree.
  • each obtained 3D fractal tree is a function call path for the code to be detected to run once, and it can also be ensured that the obtained 3D fractal tree contains accurate and complete function call relationships.
  • determining the node information of each function to be detected in the code to be detected includes: traversing each element in the code to be detected; for any element, if the element is a function, determining the function to be detected; determining Whether the function to be detected is a set function, if it is a set function, then determine that the node label of the function to be detected indicates that the function to be detected is a fractal node; traverse each function body code of the function to be detected. element, thereby determining the child nodes of the function to be detected.
  • the generation 3D fractal tree represents the function call relationship, so as to prevent the 3D fractal tree from containing non-function elements, resulting in an inaccurate function call relationship. It is determined whether the function to be detected is a set function, and if it is a set function, such as an overwrite function, the node label of the function to be detected is obtained as a fractal node.
  • the setting function may also be a setting block.
  • the set function can be an if block and/or a switch block.
  • the method before determining the node information of each function to be detected in the code to be detected, the method further includes: determining that the cache does not include the node information of the function to be detected.
  • the node information in the cache is directly used as Node information of the function to be detected, and set the pointer direction of the function to be detected. In this way, only one analysis is needed for the same multiple functions to be detected, which speeds up the acquisition of the 3D fractal tree and further speeds up the detection speed.
  • determining that the element is a function to be detected includes: determining that the element is a function and a business function of a set class, determining that the element is a function to be detected.
  • the function is a business class function
  • the business class function can be used to realize the business function of the code to be detected.
  • determining whether the functions to be detected conform to the function calling relationship through the 3D fractal tree includes: traversing the 3D fractal tree after each node is added in the process of constructing the 3D fractal tree, and determining Whether each function to be detected in the 3D fractal tree conforms to the function calling relationship; if not, the construction of the 3D fractal tree is stopped.
  • the function call relationship detection of the code to be detected can be performed during the construction process of the 3D fractal tree, so as to speed up the detection speed.
  • determining whether the functions to be detected conform to the function calling relationship through the 3D fractal tree includes: traversing each first function to be detected in the 3D fractal tree starting from the root node in the 3D fractal tree. For the corresponding node, the first function calling path is obtained; for any second function to be detected, start traversing each second function to be detected in the 3D fractal tree from the virtual node corresponding to the function branch in the second function to be detected The corresponding node obtains a second function invocation path; according to the first function invocation path and the second function invocation path, it is determined whether the functions to be detected conform to the function invocation relationship.
  • the 3D fractal tree includes nodes corresponding to each of the first functions to be detected and nodes corresponding to each of the second functions to be detected, and the first function call path and the second function call path can be obtained. That is, each node line in the 3D fractal tree completely includes the calling relationship of all functions to be detected, and further, the function calling relationship can be determined according to the node line.
  • an embodiment of the present application provides an apparatus for detecting a function call relationship, and the apparatus includes:
  • an analysis module configured to determine the node information of each function to be detected in the code to be detected, wherein the node information includes a node label used to characterize whether the function to be detected is a fractal node;
  • the processing module is used to construct a first fractal tree according to the node information of each first function to be detected, and to construct a second fractal tree according to the node information of each second function to be detected; wherein, the first function to be detected is a node label indicated as The function to be detected of the non-fractal node; the second function to be detected is the function to be detected that the node label indicates as a fractal node;
  • the processing module is further configured to construct a 3D fractal tree according to the first fractal tree and the second fractal tree;
  • the judgment module is used for determining whether the functions to be detected conform to the function calling relationship through the 3D fractal tree.
  • an embodiment of the present application further provides a computing device, including: a memory for storing a program; a processor for calling a program stored in the memory, and executing various aspects of the first aspect according to the obtained program methods described in possible designs.
  • FIG. 1(a) is a schematic structural diagram of a function call relationship detection provided by an embodiment of the present application
  • FIG. 1(b) is a schematic structural diagram of a function call relationship detection provided by an embodiment of the present application.
  • FIG. 2 is a schematic flowchart of a method for detecting a function call relationship provided by an embodiment of the present application
  • FIG. 3 is a schematic diagram of a first fractal tree provided by an embodiment of the present application.
  • FIG. 4 is a schematic diagram of a second fractal tree provided by an embodiment of the present application.
  • FIG. 5 is a schematic diagram of a 3D fractal tree provided by an embodiment of the present application.
  • FIG. 6(a) is a schematic diagram of a 3D fractal tree provided by an embodiment of the present application.
  • FIG. 6(b) is a schematic diagram of a 3D fractal tree provided by an embodiment of the present application.
  • FIG. 7(a) is a schematic diagram of a 3D fractal tree provided by an embodiment of the present application.
  • FIG. 7(b) is a schematic diagram of a 3D fractal tree provided by an embodiment of the present application.
  • FIG. 8(a) is a schematic diagram of generating a 3D fractal tree according to an embodiment of the present application.
  • FIG. 8(b) is a schematic diagram of generating a 3D fractal tree according to an embodiment of the present application.
  • FIG. 9 is a schematic flowchart of a method for detecting a function call relationship provided by an embodiment of the present application.
  • FIG. 10 is a schematic diagram of an apparatus for detecting a function call relationship provided by an embodiment of the present application.
  • FIG. 1(a) and FIG. 1(b) respectively provide a system architecture for detecting a function call relationship according to an embodiment of the present application; wherein, as shown in FIG. 1(a), when the detection module does not include the function call relationship principle When: input the code to be detected into the detection module, and input the corresponding function call relationship principle into the detection module.
  • the detection module can analyze and obtain the node information of each code to be detected in the code to be detected, and build a first fractal tree according to the node information of the first function to be detected corresponding to each non-fractal node obtained by analysis. According to the node information of the second function to be detected corresponding to each fractal node obtained by analysis, a second fractal tree is constructed.
  • a complete 3D fractal tree is constructed and obtained according to the first fractal tree and the second fractal tree.
  • Each node included in the 3D fractal tree can represent the complete function calling relationship between the business functions in the code to be detected. Further, compare the function calling relationship of the code to be detected in the 3D fractal tree with the input function calling relationship principle, determine whether the function calling relationship of the code to be detected is wrong, and output the detection result to indicate the function calling relationship in the code to be detected. Error function information occurs, or the detection result is output to indicate that the function call relationship in the code to be detected is correct.
  • the detection module contains at least one function call relationship principle: input the code to be detected into the detection module, and use it to indicate the selected principle for detection using a function call relationship principle Command input detection module.
  • the detection module determines the function call relationship principle for detection according to the selected principle instruction; the further detection module can obtain the function call relationship between the business functions in the code to be detected according to the constructed complete 3D fractal tree. Further, the function calling relationship of the code to be detected is compared with the selected function calling relationship principle to determine whether the function calling relationship of the code to be detected is wrong, and the detection result is output.
  • the function call relationship detection of the code to be detected can be performed according to the currently obtained partial function call relationship, that is, the function call relationship is obtained while generating the 3D fractal tree, and the function call relationship is performed. detection, in order to speed up the detection speed, the detection mode can be specifically set here as required, and the implementation details of the specific detection are not limited.
  • a plurality of function call relationship principles may respectively correspond to the function call relationship detection of the code to be detected of different business functions. For example, the function call relationship of the code to be tested with the deposit function is detected by the function call relationship principle 1, and the function call relationship of the code to be tested with the withdrawal function is detected by the function call relationship principle 2.
  • Multiple function call relationship principles may also respectively correspond to the function call relationship detection of the code to be tested of different functional modules in the same business function.
  • the function call relationship of the code to be detected in the payment update module is detected through the function call relationship principle 3.
  • the function call relationship principle here can be set as needed, and the specific setting is not limited.
  • an embodiment of the present application provides a process of a method for detecting a function call relationship, as shown in FIG. 2 , including:
  • Step 201 Determine the node information of each function to be detected in the code to be detected, wherein the node information includes a node label used to characterize whether the function to be detected is a fractal node;
  • the fractal node includes: if statement block, switch statement block and overriding function.
  • Step 202 construct a first fractal tree according to the node information of each first function to be detected, and construct a second fractal tree according to the node information of each second function to be detected; wherein, the first function to be detected is a node label indicating that it is non-fractal The function to be detected of the node; the second function to be detected is the function to be detected that the node label indicates as a fractal node;
  • Step 203 constructing a 3D fractal tree according to the first fractal tree and the second fractal tree;
  • Step 204 Determine whether the functions to be detected conform to the function calling relationship through the 3D fractal tree.
  • whether the function calling relationship is met may be the function calling sequence, the function calling interval, and the like.
  • the table lock function is generally required to lock the table to be updated, and then the data of the corresponding row or column of the table is updated through the update function, which is the function of the lock table function and the update function of the code. Invoke the relationship principle. If the code needs to detect the function call relationship, the code can be used as the code to be detected, and a 3D fractal tree can be generated according to the above method to represent the function call relationship of the code to be detected.
  • the lock The table function is executed or not executed later, that is, after the corresponding data of the table is updated, the table is locked or the table is not locked, then the detection result can obtain the error code of the code to be detected, and the error code is marked and displayed on the interface. Display, so that developers can quickly and intuitively get the error code and modify it.
  • the information of the function to be detected in the 3D fractal tree is determined, and whether the function to be detected is included as a fractal label of a fractal node;
  • the function to be detected is analyzed in a fractal node mode or in a non-fractal node mode.
  • the node information of the fractal node and the non-fractal node can be obtained, so that the 3D fractal tree contains the first fractal tree, that is, the calling relationship between the first function to be detected of the non-fractal node, and the relationship between the non-fractal node and the fractal node.
  • a calling relationship a calling relationship
  • a second fractal tree that is, the calling relationship of each second function to be detected in the fractal node.
  • An embodiment of the present application provides a method for constructing a first fractal tree, the node information further includes child nodes; the child nodes are functions called by functions to be detected; the construction is based on the node information of each first function to be detected.
  • the first fractal tree includes: for any first function to be detected, taking the first function to be detected as the root node of the first fractal tree, using the root node as the first construction node, and judging the first construction Whether the child node of the node is a non-fractal node; if it is a non-fractal node, construct the child node as the next layer node of the first construction node, and use the next layer node as the first construction node, and return The step of judging whether the child node of the first construction node is a non-fractal node; if the child node of the first construction node is a fractal node, constructing the child node as the first construction node without child nodes The virtual node of
  • FIG. 3 which is a schematic diagram of a first fractal tree provided in the embodiment of the application
  • the schematic diagram of the first fractal tree is only used to help understand the content of this solution, and does not limit this solution
  • the first fractal tree may or may not be displayed in the form of an interface tree.
  • the code to be detected contains functions to be detected: function 1, function 2, function 3, function 4, function 5, function 6, function 7; wherein, the first function to be detected of the non-fractal node is: function 1, function 2, function 3. Function 4.
  • One of the two branches of the second function to be detected of the fractal node includes function 5 , and the other branch includes function 6 and function 7 .
  • the node information may include the function name, the function of the next level called (the child node of the function 1) ) set and fractal label; the called function set includes: function 2 and fractal node; fractal label is non-fractal node.
  • the function 1 is used as the root node of the first fractal tree, and the root node function 1 is the first construction node, and the child node function 2 and the fractal node of the function 1 are used as the next layer nodes of the root node of the first fractal tree.
  • the node can contain all the content of the fractal node, or only the identification of the fractal node, etc.
  • the content of the node can be set as required, so that the fractal node is in the first fractal tree. It does not have child nodes and has an identifiable identifier, and the specific content is not limited.
  • the function 2 in the currently obtained code to be detected is analyzed, and the node information of the function 2 is obtained.
  • the called function set in the node information includes: function 3 and function 4; the fractal label is a non-fractal node. Store the node information of function 2 in the cache.
  • a first fractal tree with a clear hierarchy is generated, and it is possible to accurately determine the first fractal tree in the first fractal tree.
  • the calling relationship of the function to be detected corresponding to each node improves the accuracy of the function calling relationship detection.
  • An embodiment of the present application provides a method for constructing a second fractal tree.
  • the constructing a second fractal tree according to node information of each second function to be detected includes: for any second function to be detected, generating the second fractal tree.
  • the virtual node of the function to be detected is used as the root node of the second fractal tree; the virtual node corresponding to any function branch of the second function to be detected is generated as the first layer node under the root node of the second fractal tree;
  • the child node of the second construction node is a non-fractal node; if the child node of the second construction node is a non-fractal node, then the child node is constructed as The next layer node of the second construction node, and the next layer node is used as the second construction node, and returns to the step of judging whether the child node of the second construction node is a non-fractal node; if the second construction node
  • the sub-nodes of the construction node are fractal nodes, and the sub-nodes are constructed as virtual nodes of the second construction node that do not have sub-nodes; until any node in the second fractal tree has no sub-nodes.
  • FIG. 4 is a schematic diagram of a second fractal tree provided in the embodiment of the present application
  • the schematic diagram of the second fractal tree is only used to help understand the content of this solution, and does not make any changes to this solution.
  • the second fractal tree can be displayed in the form of an interface tree, or not.
  • the fractal node can be divided into two types, one is an if statement block or switch statement block, and the other is an overriding rewrite function.
  • the obtained fractal node is an if statement block or a switch statement block; analyze the fractal node, define a virtual function X for the fractal node, wrap the virtual function X as a virtual node X; and use the virtual node X as the root node of the second fractal tree.
  • a virtual function Y and a virtual function Z are respectively defined for each function branch of the fractal node, and the virtual function Y and the virtual function Z are respectively packaged into the virtual node Y and virtual node Z corresponding to the function branch;
  • the virtual node Z serves as the first layer node under the root node of the second fractal tree.
  • the virtual node Y is used as the second construction node, and the set of child nodes of the second construction node-virtual node Y is: function 5; the fractal label is a non-fractal node; the function 5 is constructed as the second construction node-virtual node Y next level node. Then take function 5 as the second construction node, the second construction node-the set of child nodes of function 5 is: function 8; the fractal label is a non-fractal node, and function 8 is constructed as the next layer node of the second construction node-function 5 .
  • the second construction node-the child node set of the virtual node Z is: function 6, function 7; the fractal label is a non-fractal node, and the function 6 and function 7 are constructed as the second construction node- The next level node of virtual node Z. Then use function 6 and function 7 as the second construction node; the child node set of the second construction node-function 6 is: function 9; the fractal label is a non-fractal node, and function 9 is constructed as the second construction node-function 6.
  • the set of child nodes of the second construction node-function 7 is: V; the fractal label is a fractal node, and V is constructed as the next virtual node of the second construction node-function 7 without child nodes. In this way, any node up to the bottommost layer in the second fractal tree has no child node. In this way, by setting the hierarchical relationship and branch relationship of the virtual nodes, the function call relationship in the second fractal tree corresponding to the fractal node is accurate, the accuracy and integrity of the 3D fractal tree are improved, and the accuracy of function call relationship detection is further improved.
  • the obtained fractal node is an overriding rewrite function; to analyze the fractal node, call com.intellij.psi.search.searches.OverridingMethodsSearch.search(PsiMethod method, SearchScope scope, boolean checkDeep) to obtain all implementations, that is, The parent function and the child function that overrides and overrides the parent function.
  • the parent function X of the overriding function is packaged as a virtual node X; and the virtual node X is used as the root node of the second fractal tree.
  • the sub-function Y and sub-function Z that cover and rewrite the parent function X in the overriding rewrite function are taken as the virtual node Y and the virtual node Z respectively; the virtual node Y and the virtual node Z are taken as the root node of the second fractal tree. the first level node.
  • the virtual node Y is used as the second construction node, and the function 5 that will cover and rewrite the sub-function Y (the second construction node and the virtual node Y) is used as a child node, and the child node set of the virtual node Y is: function 5; Fractal labels are non-fractal nodes; function 5 is constructed as the next layer node of virtual node Y.
  • the function 8 that will cover and rewrite function 5 (the second construction node) is taken as a child node, and the child node set of function 5 is: function 8; the fractal label is a non-fractal node; the Function 8 is constructed as the next level node of Function 5 (the second construction node).
  • function 9 The fractal label is a non-fractal node, and function 9 is constructed as the next layer node of function 6 (the second construction node).
  • the V that will cover and rewrite the function 7 (the second construction node) is taken as a child node, and the set of child nodes of the function 7 (the second construction node) is: V; the fractal label is the fractal node, and V is constructed as the function 7 (No. The next-level virtual node that does not have child nodes of the second build node).
  • any node up to the bottommost layer in the second fractal tree has no child node.
  • the coverage and rewriting levels of the parent function and each sub-function in the overriding function can be clarified, so that the function calling relationship in the second fractal tree corresponding to the fractal node is accurate, and the 3D function is improved.
  • the accuracy and integrity of the fractal tree further improve the accuracy of function call relationship detection.
  • An embodiment of the present application provides a method for constructing a 3D fractal tree.
  • constructing a 3D fractal tree includes: determining the corresponding virtual nodes in the first fractal tree.
  • the second fractal tree; the first fractal tree and the second fractal are fused into a 3D fractal tree through virtual nodes in the first fractal tree.
  • the 3D fractal tree shown in FIG. 5 is a 3D fractal tree obtained by supplementing the second fractal tree in the above example to the first fractal tree.
  • An embodiment of the present application provides a method for constructing a 3D fractal tree, wherein the fusion of the first fractal tree and the second fractal into a 3D fractal tree includes: combining the second fractal tree corresponding to the virtual node, adding to the virtual node of the first fractal tree to obtain a 3D fractal tree fused with the first fractal tree and the second fractal tree; or, for each of the second fractal tree corresponding to the virtual node add the branches to the virtual nodes of the first fractal tree, respectively, to obtain at least one 3D fractal with different branches in which the branches of the first fractal tree and the second fractal tree are fused Tree.
  • the second fractal tree can be added to the corresponding virtual node corresponding to the first fractal tree, as shown in FIG. 5; each branch in the second fractal tree can also be fused with the first fractal tree, as shown in FIG. 5 .
  • a complete 3D fractal tree with multiple function call paths can be obtained; or a 3D fractal tree with a different function call path can be obtained separately, and the 3D fractal tree with a different function call path can be obtained separately.
  • the 3D fractal tree includes the function calling relationship of all functions to be detected in the code to be detected, which can improve the accuracy of the detection result of the code to be detected.
  • An embodiment of the present application provides a method for building a 3D fractal tree, and determining the node information of each function to be detected in the code to be detected includes: traversing each element in the code to be detected; for any element, if the element is a function, then it is determined to be a function to be detected; determine whether the function to be detected is a set function, if it is a set function, then determine that the node label of the function to be detected indicates that the function to be detected is a fractal node; traverse all Each element in the function body code of the function to be detected is determined, thereby determining the child nodes of the function to be detected.
  • the analysis element in the code to be detected is a function
  • the fractal function is a setting function. For example, if block, switch block, override function.
  • the element is a non-fractal node and a non-function
  • the element can contain at least one function
  • the element has at least one function branch.
  • the element that is a non-fractal node and a non-function can be a statement block, and the element can be analyzed by using the above-mentioned method of generating the first fractal tree.
  • FIG. 7(a) when it is determined that the next-level nodes of function 1 are statement block W and function 2, respectively, continue to obtain function 3 and function 4 in statement block W, and the function of the next level node of function 2 5 and function 6; the final obtained 3D fractal tree is shown in Fig. 7(b), which integrates the node statement block W of the next layer of function 1 into function 3 and function 4 of the next layer of function 1.
  • the embodiment of the present application provides a method for constructing a 3D fractal tree. Before determining the node information of each function to be detected in the code to be detected, the method further includes: determining that the cache does not include the node information of the function to be detected.
  • the node information in the cache is directly used as the node information of the function to be detected.
  • the node information of the function to be detected can be set to the pointer direction of the function to be detected; if there is no function to be detected that has been analyzed that is the same as the function to be detected in the cache, then the function to be detected is analyzed to obtain the node information and cache. In this way, only one analysis is needed for the same multiple functions to be detected, which speeds up the acquisition of the 3D fractal tree and further speeds up the detection speed.
  • An embodiment of the present application provides a method for constructing a 3D fractal tree. If the element is a function, then determining that the element is a function to be detected includes: if determining that the element is a function and is a business function of a set class, determining as function to be tested. That is, the function to be detected can be set; for example, if only the business function of the code to be detected needs to be detected, that is, the business function in the code to be detected is detected, the business function can be set as the function to be detected. In this way, only the function calling relationship of the business function can be detected, without analyzing the constructor, hash function, toString function, and the like.
  • ! Scenarios such as method.isWritable() are skipped.
  • the method can determine the function to be detected pertinently, reduce the number of function analysis, reduce the function analysis work, and speed up the detection speed.
  • An embodiment of the present application provides a method for constructing a 3D fractal tree.
  • the 3D fractal tree is used to determine whether the functions to be detected conform to the function calling relationship, including: after each node is added in the process of constructing the 3D fractal tree , traverse the 3D fractal tree to determine whether each function to be detected in the 3D fractal tree conforms to the function calling relationship; if not, stop the construction of the 3D fractal tree. That is to say, while constructing the 3D fractal tree, the function call relationship is acquired and detected according to the currently constructed partial fractal tree, that is, the function call relationship is detected while being constructed, so as to speed up the detection of the function call relationship.
  • the function calling relationship between the first functions to be detected and the calling relationship between the first function to be detected and the second function to be detected can be obtained respectively according to the first fractal tree, so as to obtain the calling path of the first function.
  • the calling relationship between the second functions to be detected can be obtained according to the second fractal tree, so as to obtain the calling path of the second function.
  • the code to be detected can be divided into three categories.
  • the first type is that the code to be detected contains both the second function to be detected corresponding to the fractal node and the first function to be detected corresponding to the non-fractal node.
  • the above method The process has already explained how to obtain the 3D fractal tree of the code to be detected.
  • the second type is that the code to be detected does not contain the second function to be detected corresponding to the fractal node, but only contains the first function to be detected corresponding to the non-fractal node; this kind of code to be detected can be constructed using a 3D fractal tree such as the first fractal tree.
  • the method obtains the 3D fractal tree corresponding to the code to be detected, obtains the function call relationship, and performs detection according to the principle of the function call relationship corresponding to the code to be detected.
  • the third type is that the code to be detected only contains the second function to be detected corresponding to the fractal node; this kind of code to be detected can be obtained by applying a 3D fractal tree construction method such as the second fractal tree to obtain the 3D fractal tree corresponding to the code to be detected, The function call relationship is obtained, and the detection is performed according to the function call relationship principle corresponding to the code to be detected.
  • the pointer that has a cyclic pointing and does not affect the detection of the function calling relationship can be erased.
  • the next layer nodes of function 1 are function 2 and function 3
  • the next layer nodes of function 3 are this function 1
  • the next layer nodes of this function 1 are this function 3
  • the next layer nodes of this function 3 are The function 1.
  • the circular pointer of the function call path is formed between function 1 and function 3, but in the function call relationship principle, only the function call relationship between function 1 and function 2 is detected, then the pointer of function 3 to function 1 can be erased and destroyed. Remove the loop pointing; prevent the endless loop analysis of function 1 and function 3 when generating a 3D tree, reducing the detection speed.
  • code 1 to be detected and code 2 to be detected are shown below;
  • Fig. 8(a) is used to represent the schematic diagram of the generation of a 3D fractal tree of code 1 to be detected, and
  • Fig. 8(b) is used to represent the 3D fractal of code 2 to be detected Tree generation diagram:
  • an embodiment of the present application provides a flow of a method for detecting a function call relationship, as shown in FIG. 9 , including:
  • Step 901 Obtain the code to be detected.
  • Step 902 analyze any element in the code to be detected, and determine that the element whose element is a function is the function to be detected.
  • the element is a function
  • the element that is a business function is the function to be detected
  • it can also be determined that the element is a non-fractal node and a non-function, which can contain at least one function, and the element with at least one function branch is the first The function to be detected; here it can also be determined that the element is a fractal node, and the element is the second function to be detected.
  • Step 903 Obtain node information of each function to be detected.
  • Step 904 Acquire the first fractal tree and the second fractal tree according to the node information of each function to be detected.
  • Step 905 Integrate the first fractal tree and the second fractal tree to obtain a 3D fractal tree.
  • Step 906 Obtain the function calling relationship of the code to be detected through the 3D fractal tree.
  • Step 907 Compare and detect the function calling relationship with the function calling relationship principle.
  • Step 908 Obtain the detection result.
  • step 903 and step 904 may be performed simultaneously.
  • FIG. 10 is a schematic diagram of a device for detecting a function call relationship provided by an embodiment of the present application, as shown in FIG. 10 , including:
  • the analysis module 1001 is used to determine the node information of each function to be detected in the code to be detected, wherein the node information includes a node label used to characterize whether the function to be detected is a fractal node;
  • the processing module 1002 is used for constructing a first fractal tree according to the node information of each first function to be detected, and constructing a second fractal tree according to the node information of each second function to be detected; wherein, the first function to be detected is a node label indication is the function to be detected of the non-fractal node; the second function to be detected is the function to be detected that the node label indicates as a fractal node;
  • the processing module 1002 is further configured to construct a 3D fractal tree according to the first fractal tree and the second fractal tree;
  • the judgment module 1003 is configured to determine whether the functions to be detected conform to the function calling relationship through the 3D fractal tree.
  • the node information further includes a child node; the child node is a function called by the function to be detected; the processing module 1002 is specifically configured to: for any first function to be detected, the first function to be detected The function is used as the root node of the first fractal tree, and the root node is used as the first construction node to determine whether the child node of the first construction node is a non-fractal node; if it is a non-fractal node, the child node is constructed as The next layer node of the first construction node, and the next layer node is used as the first construction node, and returns to the step of judging whether the child nodes of the first construction node are non-fractal nodes; if the first construction node The sub-nodes of the construction node are fractal nodes, and the sub-nodes are constructed as virtual nodes of the first construction node that do not have sub-nodes; until any node in the first fractal tree has no sub-nodes.
  • the processing module 1002 is specifically configured to: for any second function to be detected, generate a virtual node of the second function to be detected as the root node of the second fractal tree; generate the second function to be detected
  • the virtual node corresponding to any function branch is used as the first layer node under the root node of the second fractal tree; the lower layer node of the virtual node of any function branch is generated in the following way: the virtual node is used as the second construction node, judge whether the child node of the second construction node is a non-fractal node; if the child node of the second construction node is a non-fractal node, then construct the child node as the next node of the second construction node layer node, and take the next layer node as the second construction node, and return to the step of judging whether the child node of the second construction node is a non-fractal node; if the child node of the second construction node is a fractal node, The child node is constructed as
  • the processing module 1002 is specifically configured to: determine a second fractal tree corresponding to a virtual node in the first fractal tree; and the second fractal are fused into a 3D fractal tree.
  • the processing module 1002 is specifically configured to: supplement the second fractal tree corresponding to the virtual node to the virtual node of the first fractal tree to obtain the first fractal tree and the The 3D fractal tree fused by the second fractal tree; or, for each branch of the second fractal tree corresponding to the virtual node, the branch is respectively added to the virtual node of the first fractal tree to obtain the At least one 3D fractal tree with different branches in which the branches of the first fractal tree and the second fractal tree are fused.
  • the processing module 1002 is specifically configured to: traverse each element in the code to be detected; for any element, if the element is a function, determine the function to be detected; determine whether the function to be detected is In order to set a function, if it is a set function, then determine that the node label of the function to be detected indicates that the function to be detected is a fractal node; traverse each element in the function body code of the function to be detected, so as to determine the Child nodes of the function to be detected.
  • the analysis module 1001 is further configured to: determine that the cache does not include the node information of the function to be detected.
  • the processing module 1002 is specifically configured to: if the element is a function, determine that the element is a function to be detected, including: if it is determined that the element is a function and a business function of a set class, determine that it is a function to be detected function.
  • the judging module 1003 is specifically configured to: determine whether the functions to be detected conform to the function calling relationship through the 3D fractal tree, including: after each additional node is added in the process of constructing the 3D fractal tree, to The 3D fractal tree is traversed to determine whether each function to be detected in the 3D fractal tree conforms to the function calling relationship; if not, the construction of the 3D fractal tree is stopped.
  • the processing module 1002 is specifically configured to: traverse the nodes corresponding to each first function to be detected in the 3D fractal tree from the root node in the 3D fractal tree, and obtain the first function calling path; Any second function to be detected starts traversing the node corresponding to each second function to be detected in the 3D fractal tree from the virtual node corresponding to the function branch in the second function to be detected, to obtain the second function calling path; according to The first function invocation path and the second function invocation path determine whether the functions to be detected conform to the function invocation relationship.
  • the embodiments of the present application may be provided as a method, a system, or a computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein.
  • computer-usable storage media including, but not limited to, disk storage, CD-ROM, optical storage, etc.
  • These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory result in an article of manufacture comprising instruction means, the instructions
  • the apparatus implements the functions specified in the flow or flow of the flowcharts and/or the block or blocks of the block diagrams.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本申请实施例提供一种函数调用关系检测方法及装置,确定待检测代码中各待检测函数的节点信息,节点信息中包括用于表征待检测函数是否为分形节点的节点标签;根据各第一待检测函数的节点信息构建第一分形树,并根据各第二待检测函数的节点信息构建第二分形树;其中,第一待检测函数为节点标签指示为非分形节点的待检测函数;第二待检测函数为节点标签指示为分形节点的待检测函数;根据第一分形树和第二分形树,构建3D分形树;通过3D分形树确定各待检测函数是否符合函数调用关系。上述方法相比于现有技术中3D分形树中无法完整获取分形节点中的函数调用关系来说,本申请获取的3D分形树中的函数调用关系完整,提高了检测代码的准确度。

Description

一种函数调用关系检测方法及装置
相关申请的交叉引用
本申请要求在2021年03月30日提交中国专利局、申请号为202110338210.1、申请名称为“一种函数调用关系检测方法及装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及金融科技(Fintech)的网络技术领域,尤其涉及一种函数调用关系检测方法及装置。
背景技术
近年来,随着计算机技术的发展,越来越多的技术应用在金融领域,传统金融业正在逐步向金融科技(Fintech)转变,但由于金融行业的安全性、实时性要求,也对技术提出更高的要求。如,现在社会中,人们可以通过终端中的应用软件完成人们大部分的生活需求,且随着人们安全和便捷性等需求的增加,这些应用软件的设计也愈加复杂;其中,终端中软件以及支持软件运行的相关系统等都是通过开发人员编写的具有对应功能的代码实现的。例如,可以在终端中下载购物软件、办公软件、视频软件、聊天软件、理财软件等等,这些应用软件给人们的生活带来了非常大的便利。相应的,随着人们需求的增加,软件的代码编写愈加复杂,相应的人工检测代码会耗费大量时间成本,甚至更复杂的代码无法通过人工进行检测。
当前有三种代码检测方法:一种方法为call hierarchy(函数调用层次树),该方法生成的函数调用层次树中可以包含待检测代码中的所有函数;但该方法无法识别待检测代码中的if语句块、switch语句块和覆盖重写函数,而且将这三种方法的‘或’的执行关系的分支直接表征为串行执行,使得生成的函数调用层次树的准确度降低,进一步降低代码检测准确度。一种方法为函数调 用顺序3D分形树,该方法虽然能够识别待检测代码中的if语句块、switch语句块和覆盖重写函数,但只能按照固定的算法将这三种方法的‘或’的关系的执行分支进行计算得到计算结果,将计算结果作为被调用函数,而失去待检测代码中这三种方法原有的函数调用顺序,降低代码检测准确度。又一种方法为通过运行待检测代码获取运行时的函数调用顺序,该方式在待检测代码包含具有‘或’的关系的执行分支时,只会获取一个分支的执行顺序,导致函数调用顺序不完整,降低代码检测准确度。
因此,现在亟需一种函数调用关系检测方法及装置,能够获取待检测代码的完整的函数调用关系,增加检测代码的准确度。
发明内容
本申请实施例提供一种函数调用关系检测方法及装置,能够获取待检测代码的完整的函数调用关系,增加检测代码的准确度。
第一方面,本申请实施例提供一种函数调用关系检测方法,该方法包括:
确定待检测代码中各待检测函数的节点信息,其中,节点信息中包括用于表征待检测函数是否为分形节点的节点标签;根据各第一待检测函数的节点信息构建第一分形树,并根据各第二待检测函数的节点信息构建第二分形树;其中,第一待检测函数为节点标签指示为非分形节点的待检测函数;第二待检测函数为节点标签指示为分形节点的待检测函数;根据所述第一分形树和所述第二分形树,构建3D分形树;通过所述3D分形树确定所述各待检测函数是否符合函数调用关系。
上述方法中,通过获取待检测代码中各待检测函数的节点信息,以确定该待检测函数在3D分形树中的信息,以及通过待检测函数是否包含为分形节点的分形标签;进而可知,对该待检测函数以分形节点方式进行分析,或者以非分形节点方式进行分析。如此,可以获取分形节点和非分形节点的节点信息,使得3D分形树中包含第一分形树,即,非分形节点的第一待检测函数之间的调用关系,以及非分形节点对分形节点的调用关系;和第二分形树, 即,分形节点中的各第二待检测函数的调用关系。相比于现有技术中3D分形树中无法完整获取分形节点中的函数调用关系来说,本申请中获取的3D分形树中的函数调用关系完整,提高了检测代码的准确度。
可选的,所述节点信息还包括子节点;所述子节点为待检测函数调用的函数;所述根据各第一待检测函数的节点信息构建第一分形树,包括:针对任一第一待检测函数,将所述第一待检测函数作为第一分形树的根节点,将所述根节点作为第一构建节点,判断所述第一构建节点的子节点是否为非分形节点;若为非分形节点则将所述子节点构建为所述第一构建节点的下一层节点,并将所述下一层节点作为第一构建节点,返回判断所述第一构建节点的子节点是否为非分形节点的步骤;若所述第一构建节点的子节点为分形节点,将所述子节点构建为所述第一构建节点的不具有子节点的虚拟节点;直至所述第一分形树中任一节点均不具有子节点。
上述方法中,通过以第一待检测函数作为第一分形树的根节点,将第一待检测函数的非分形节点的子节点作为第一分形树的根节点下的第一层节点,并将分形节点作为不具有子节点的虚拟节点;根据子节点的节点信息中子节点的子节点集合,构建所述第一分形树的第二层节点;以这种循环方式构建第一分形树,直至第一分形树中任一节点均不具有子节点。如此,使得第一分形树中第一待检测函数的函数调用关系层级明确,准确确定第一分形树中各节点对应的待检测函数的调用关系,提高函数调用关系检测的准确性。若子节点为分形节点,则将该子节点构建为第一分形树中不具有子节点的虚拟节点。如此,可以在该虚拟节点中设置分形节点所包含的所有函数,或者其他等虚拟函数信息,以便于在后续确定该分形节点中各第二待检测函数对应的第二分形树时,将该第二分形树在第一分形树的对应的分形节点位置补充,增加3D分形树的准确性和完整性。
可选的,所述根据各第二待检测函数的节点信息构建第二分形树,包括:针对任一第二待检测函数,生成所述第二待检测函数的虚拟节点作为第二分形树的根节点;生成所述第二待检测函数的任一函数分支对应的虚拟节点作 为所述第二分形树的根节点下的第一层节点;
通过如下方式生成任一函数分支的虚拟节点的下层节点:
将所述虚拟节点作为第二构建节点,判断所述第二构建节点的子节点是否为非分形节点;若所述第二构建节点的子节点为非分形节点,则将所述子节点构建为所述第二构建节点的下一层节点,并将所述下一层节点作为第二构建节点,返回判断所述第二构建节点的子节点是否为非分形节点的步骤;若所述第二构建节点的子节点为分形节点,将所述子节点构建为所述第二构建节点的不具有子节点的虚拟节点;直至所述第二分形树中任一节点均不具有子节点。
上述方法中,以第二待检测函数的虚拟节点作为第二分形树的根节点,并以第二待检测函数的任一函数分支对应的虚拟节点作为第二分形树的根节点下的第一层节点。如此,可以以第二待检测函数的虚拟节点,即,该根节点表征至少一个函数分支的来源,并以函数分支对应的虚拟节点表征函数分支数量;继而函数分支中调用的函数为函数分支对应的虚拟节点的子节点。这样可以准确并清楚地表征分形节点中每个分支所调用的函数,使得分形节点对应的第二分形树中的函数调用关系准确,提高3D分形树的准确性和完整性,进一步提高函数调用关系检测的准确性。且若第二待检测函数的任一函数分支中还包含分形节点,则依照第二分形树的构造方法,构造该分形节点对应的第二分形树,并可以将该第二分形树补充道该分形节点所在的第二分形树中,使得第二分形树中的函数调用关系准确且完整,进一步提高3D分形树的准确性和完整性。
可选的,根据所述第一分形树和所述第二分形树,构建3D分形树,包括:确定所述第一分形树中的虚拟节点对应的第二分形树;通过所述第一分形树中的虚拟节点,将所述第一分形树和所述第二分形融合为3D分形树。
上述方法中,将分形节点对应的第二分形树,通过第一分形树中该分形节点对应的虚拟节点,补充到第一分形树中得到融合的3D分形树。使得3D分形树中包含待检测代码中所有待检测函数的函数调用关系,当使用函数调 用关系原则对该3D分形树中的函数调用关系检测时,可以准确确定待检测代码中的各待检测函数调用关系是否有误。
可选的,所述将所述第一分形树和所述第二分形融合为3D分形树,包括:
将所述虚拟节点对应的第二分形树,补充至所述第一分形树的所述虚拟节点中,得到所述第一分形树和所述第二分形树融合的3D分形树;或者,针对所述虚拟节点对应的第二分形树的每个分支,将所述分支分别补充至所述第一分形树的所述虚拟节点中,得到所述第一分形树和所述第二分形树的分支融合的,具有不同分支的至少一个3D分形树。
上述方法中,将虚拟节点对应的第二分形树,补充至对应第一分形树的该虚拟节点中,得到该第一分形树和该第二分形树融合的3D分形树。如此,保证获取的3D分形树中包含准确且完整的函数调用关系。若将虚拟节点对应的第二分形树的每个分支分别补充至对应第一分形树的该虚拟节点中,得到该第一分形树和该第二分形树的分支融合的,具有不同分支的3D分形树。如此,得到的每个3D分形树都是该待检测代码运行一次的函数调用路径,同样可以保证获取的3D分形树中包含准确且完整的函数调用关系。
可选的,确定待检测代码中各待检测函数的节点信息,包括:遍历所述待检测代码中的各元素;针对任一元素,若所述元素为函数,则确定为待检测函数;确定所述待检测函数是否为设定函数,若为设定函数,则确定所述待检测函数的节点标签指示所述待检测函数为分形节点;遍历所述待检测函数的函数体代码中的各元素,从而确定所述待检测函数的子节点。
上述方法中,通过判断任一元素是否为函数,以保证生成的3D分形树表征函数调用关系,防止3D分形树中包含非函数元素,导致函数调用关系不准确。确定待检测函数是否为设定函数,若为设定函数,如,覆盖重写函数,则获取该待检测函数的节点标签为分形节点。此处,设定函数也可以为设定语句块。如,设定函数可以为if语句块和/或switch语句块。
可选的,确定待检测代码中各待检测函数的节点信息之前,还包括:确定缓存中不包括所述待检测函数的节点信息。
上述方法中,若缓存中存在与该待检测函数相同的已经分析过的待检测函数,且缓存中已经存在该已经分析过的待检测函数的节点信息,则直接以缓存中的该节点信息作为该待检测函数的节点信息,并设置该待检测函数的指针方向。如此,针对相同的多个待检测函数只需要分析一遍,加快获取3D分形树速度,进一步加快检测速度。
可选的,若所述元素为函数,则确定为待检测函数,包括:若确定所述元素为函数且为设定类的业务函数,则确定为待检测函数。
上述方法中,函数为业务类函数,所述业务类函数可以用于实现所述待检测代码的业务功能。获取针对实现待检测代码的业务功能的业务函数的函数调用关系检测,无需对日志函数等辅助函数进行分析,加快获取3D分形树速度,进一步加快检测速度。
可选的,通过所述3D分形树确定所述各待检测函数是否符合函数调用关系,包括:在构建所述3D分形树过程中每增加一个节点之后,对所述3D分形树进行遍历,确定所述3D分形树中的各待检测函数是否符合函数调用关系;若不符合,则停止对所述3D分形树的构建。
上述方法中,可以在3D分形树的构建过程中进行待检测代码的函数调用关系检测,加快检测速度。
可选的,通过所述3D分形树确定所述各待检测函数是否符合函数调用关系,包括:自所述3D分形树中的根节点开始遍历所述3D分形树中的各第一待检测函数对应的节点,得到第一函数调用路径;针对任一第二待检测函数,自所述第二待检测函数中函数分支对应的虚拟节点开始遍历所述3D分形树中的各第二待检测函数对应的节点,得到第二函数调用路径;根据所述第一函数调用路径和所述第二函数调用路径,确定所述各待检测函数是否符合函数调用关系。
上述方法中,3D分形树中包含各第一待检测函数对应的节点和各第二待检测函数对应的节点,可以得到第一函数调用路径和第二函数调用路径。即,3D分形树中各节点线路,完全包含了所有待检测函数的调用关系,进一步可 以根据节点线路确定函数调用关系。
第二方面,本申请实施例提供一种函数调用关系检测装置,该装置包括:
分析模块,用于确定待检测代码中各待检测函数的节点信息,其中,节点信息中包括用于表征待检测函数是否为分形节点的节点标签;
处理模块,用于根据各第一待检测函数的节点信息构建第一分形树,并根据各第二待检测函数的节点信息构建第二分形树;其中,第一待检测函数为节点标签指示为非分形节点的待检测函数;第二待检测函数为节点标签指示为分形节点的待检测函数;
所述处理模块还用于,根据所述第一分形树和所述第二分形树,构建3D分形树;
判断模块,用于通过所述3D分形树确定所述各待检测函数是否符合函数调用关系。
第三方面,本申请实施例还提供一种计算设备,包括:存储器,用于存储程序;处理器,用于调用所述存储器中存储的程序,按照获得的程序执行如第一方面的各种可能的设计中所述的方法。
本申请的这些实现方式或其他实现方式在以下实施例的描述中会更加简明易懂。
附图说明
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简要介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域的普通技术人员来讲,在不付出创造性劳动性的前提下,还可以根据这些附图获得其他的附图。
图1(a)为本申请实施例提供的一种函数调用关系检测的架构示意图;
图1(b)为本申请实施例提供的一种函数调用关系检测的架构示意图;
图2为本申请实施例提供的一种函数调用关系检测方法的流程示意图;
图3为本申请实施例提供的一种第一分形树的示意图;
图4为本申请实施例提供的一种第二分形树的示意图;
图5为本申请实施例提供的一种3D分形树的示意图;
图6(a)为本申请实施例提供的一种3D分形树的示意图;
图6(b)为本申请实施例提供的一种3D分形树的示意图;
图7(a)为本申请实施例提供的一种3D分形树的示意图;
图7(b)为本申请实施例提供的一种3D分形树的示意图;
图8(a)为本申请实施例提供的一种生成3D分形树的示意图;
图8(b)为本申请实施例提供的一种生成3D分形树的示意图;
图9为本申请实施例提供的一种函数调用关系检测方法的流程示意图;
图10为本申请实施例提供的一种函数调用关系检测装置示意图。
具体实施方式
为了使本申请的目的、技术方案和优点更加清楚,下面将结合附图对本申请作进一步地详细描述,显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其它实施例,都属于本申请保护的范围。
图1(a)和图1(b)分别为本申请实施例提供的一种函数调用关系检测的系统架构;其中,如图1(a)所示,当检测模块中不包含函数调用关系原则时:将待检测代码输入检测模块,并将对应的函数调用关系原则输入检测模块。使得检测模块可以分析获取待检测代码中各待检测代码的节点信息,并根据分析获得的各非分形节点对应的第一待检测函数的节点信息,构建第一分形树。根据分析获得的各分形节点对应的第二待检测函数的节点信息,构建第二分形树。根据该第一分形树和该第二分形树,构建得到完整的3D分形树。使得3D分形树中包含的各节点可以表征待检测代码中业务函数之间完整的函数调用关系。进一步,将3D分形树中的待检测代码的函数调用关系和输入的函数调用关系原则进行比较,确定待检测代码的函数调用关系是否有 误,并输出检测结果以指示待检测代码中函数调用关系出现错误的函数信息,或者,输出检测结果以指示待检测代码中函数调用关系正确。
其中,如图1(b)所示,当检测模块中包含至少一个函数调用关系原则时:将待检测代码输入检测模块,并将用于指示使用某一函数调用关系原则进行检测的选定原则指令输入检测模块。使得检测模块根据选定原则指令确定用于检测的函数调用关系原则;进一步检测模块可以根据构建得到的完整的3D分形树,获取待检测代码中业务函数之间的函数调用关系。再进一步,将待检测代码的函数调用关系和选定的函数调用关系原则进行比较,确定待检测代码的函数调用关系是否有误,并输出检测结果。上述说法中,也可以在3D分形树构建进行时,根据当前获取的部分函数调用关系进行待检测代码的函数调用关系检测,即,边生成3D分形树边获取函数调用关系,并进行函数调用关系检测,以加快检测速度,这里可以根据需要具体设置检测方式,对具体检测的实现细节不做限定。另外,多个函数调用关系原则可以分别对应不同的业务功能的待检测代码的函数调用关系检测。例如,具有存款功能的待检测代码的函数调用关系通过函数调用关系原则1进行检测,具有取款功能的待检测代码的函数调用关系通过函数调用关系原则2进行检测。多个函数调用关系原则也可以分别对应相同的业务功能中不同功能模块的待检测代码的函数调用关系检测。例如,存款功能中款项更新模块的待检测代码的函数调用关系通过函数调用关系原则3进行检测。这里的函数调用关系原则可以根据需要设置,具体设定不做限定。
基于此,本申请实施例提供了一种函数调用关系检测方法的流程,如图2所示,包括:
步骤201、确定待检测代码中各待检测函数的节点信息,其中,节点信息中包括用于表征待检测函数是否为分形节点的节点标签;
此处,分形节点包括:if语句块、switch语句块和覆盖重写函数。
步骤202、根据各第一待检测函数的节点信息构建第一分形树,并根据各第二待检测函数的节点信息构建第二分形树;其中,第一待检测函数为节点 标签指示为非分形节点的待检测函数;第二待检测函数为节点标签指示为分形节点的待检测函数;
步骤203、根据所述第一分形树和所述第二分形树,构建3D分形树;
步骤204、通过所述3D分形树确定所述各待检测函数是否符合函数调用关系。
此处,是否符合函数调用关系可以为函数调用顺序、函数调用间隔等。例如,在代码中流转状态时,一般需要锁表函数将待更新的表格锁住,之后通过更新函数更新该表格的对应行或列的数据,这是该代码的锁表函数和更新函数的函数调用关系原则。若该代码需要检测函数调用关系,则可以以该代码为待检测代码,按照上述方法生成3D分形树以表征该待检测代码的函数调用关系,当该函数调用关系为更新函数在前执行,锁表函数在后执行或未执行,即,对表格的对应数据更新后,才进行锁表或者没有锁表,则检测结果可以得到该待检测代码的错误代码,并将该错误代码标记且在界面显示,以使得开发人员可以快速直观获取错误代码并修改。
上述方法中,通过获取待检测代码中各待检测函数的节点信息,以确定该待检测函数在3D分形树中的信息,以及通过待检测函数是否包含为分形节点的分形标签;进而可知,对该待检测函数以分形节点方式进行分析,或者以非分形节点方式进行分析。如此,可以获取分形节点和非分形节点的节点信息,使得3D分形树中包含第一分形树,即,非分形节点的第一待检测函数之间的调用关系,以及非分形节点对分形节点的调用关系;和第二分形树,即,分形节点中的各第二待检测函数的调用关系。相比于现有技术中3D分形树中无法完整获取分形节点中的函数调用关系来说,本申请中获取的3D分形树中的函数调用关系完整,提高了检测代码的准确度。
本申请实施例提供了一种构建第一分形树的方法,所述节点信息还包括子节点;所述子节点为待检测函数调用的函数;所述根据各第一待检测函数的节点信息构建第一分形树,包括:针对任一第一待检测函数,将所述第一待检测函数作为第一分形树的根节点,将所述根节点作为第一构建节点,判 断所述第一构建节点的子节点是否为非分形节点;若为非分形节点则将所述子节点构建为所述第一构建节点的下一层节点,并将所述下一层节点作为第一构建节点,返回判断所述第一构建节点的子节点是否为非分形节点的步骤;若所述第一构建节点的子节点为分形节点,将所述子节点构建为所述第一构建节点的不具有子节点的虚拟节点;直至所述第一分形树中任一节点均不具有子节点。
举例说明:如图3所示,为本申请实施例中提供的一种第一分形树的示意图,该第一分形树的示意图仅用于帮助理解本方案的内容,并不对本方案做限制,第一分形树可以以界面树图形式显示,也可以不显示。待检测代码中包含待检测函数:函数1、函数2、函数3、函数4、函数5、函数6、函数7;其中,非分形节点的第一待检测函数为:函数1、函数2、函数3、函数4。分形节点的第二待检测函数的两个分支的一个分支中包含函数5,另一个分支中包含函数6和函数7。则获取该待检测代码;对当前获取到的待检测代码中的函数1进行分析,获取函数1的节点信息,节点信息中可以包括函数名称、所调用下一层次的函数(函数1的子节点)集合以及分形标签;所调用的函数集合中包括:函数2和分形节点;分形标签为非分形节点。将函数1的节点信息存储在缓存中。以函数1作为第一分形树的根节点,且根节点函数1为第一构建节点,以函数1的子节点函数2和分形节点作为第一分形树的根节点的下一层节点。将分形节点作为一个虚拟节点,该节点中可以包含分形节点中的所有内容,也可以只包含分形节点的标识等等,该节点中的内容可以根据需要设置,使得该分形节点在第一分形树中不具有子节点,且具有可识别标识,具体内容不做限定。对当前获取到的待检测代码中的函数2进行分析,获取函数2的节点信息,节点信息中的所调用的函数集合中包括:函数3和函数4;分形标签为非分形节点。将函数2的节点信息存储在缓存中。以函数2作为函数3和函数4的根节点,且以根节点函数2为第一构建节点,以函数2的子节点函数3和函数4作为第一分形树的根节点的下一层节点。若函数3和/或函数4还有调用的函数,则按照上述方法继续生成下一层节点, 直至第一分形树中最底层的任一节点均不具有子节点。如此,根据各第一待检测函数在第一分形树的节点层级,以及第一待检测函数对应的下一层级的分形节点,生成层级明确的第一分形树,可以准确确定第一分形树中各节点对应的待检测函数的调用关系,提高函数调用关系检测的准确性。
本申请实施例提供了一种构建第二分形树的方法,所述根据各第二待检测函数的节点信息构建第二分形树,包括:针对任一第二待检测函数,生成所述第二待检测函数的虚拟节点作为第二分形树的根节点;生成所述第二待检测函数的任一函数分支对应的虚拟节点作为所述第二分形树的根节点下的第一层节点;
通过如下方式生成任一函数分支的虚拟节点的下层节点:
将所述虚拟节点作为第二构建节点,判断所述第二构建节点的子节点是否为非分形节点;若所述第二构建节点的子节点为非分形节点,则将所述子节点构建为所述第二构建节点的下一层节点,并将所述下一层节点作为第二构建节点,返回判断所述第二构建节点的子节点是否为非分形节点的步骤;若所述第二构建节点的子节点为分形节点,将所述子节点构建为所述第二构建节点的不具有子节点的虚拟节点;直至所述第二分形树中任一节点均不具有子节点。
在上述示例中:如图4所示,为本申请实施例中提供的一种第二分形树的示意图,该第二分形树的示意图仅用于帮助理解本方案的内容,并不对本方案做限制,第二分形树可以以界面树图形式显示,也可以不显示。这里分形节点可以分为两种,一种为if语句块或switch语句块,一种为覆盖重写函数。
其中,若获取的分形节点为if语句块或switch语句块;对该分形节点进行分析,为该分形节点定义一个虚拟函数X,将该虚拟函数X包装为虚拟节点X;并以该虚拟节点X作为第二分形树的根节点。为该分形节点的各函数分支分别定义一个虚拟函数Y和虚拟函数Z,并分别将该虚拟函数Y和该虚拟函数Z包装为函数分支对应的虚拟节点Y和虚拟节点Z;将虚拟节点Y和 虚拟节点Z作为第二分形树的根节点下的第一层节点。进一步,将虚拟节点Y作为第二构建节点,第二构建节点-虚拟节点Y的子节点集合为:函数5;分形标签为非分形节点;将函数5构建为第二构建节点-虚拟节点Y的下一层节点。再以函数5为第二构建节点,第二构建节点-函数5的子节点集合为:函数8;分形标签为非分形节点,将函数8构建为第二构建节点-函数5的下一层节点。
将虚拟节点Z作为第二构建节点,第二构建节点-虚拟节点Z的子节点集合为:函数6、函数7;分形标签为非分形节点,将函数6、函数7构建为第二构建节点-虚拟节点Z的下一层节点。再以函数6、函数7为第二构建节点;第二构建节点-函数6的子节点集合为:函数9;分形标签为非分形节点,将函数9构建为第二构建节点-函数6的下一层节点。第二构建节点-函数7的子节点集合为:V;分形标签为分形节点,将V构建为第二构建节点-函数7的不具有子节点的下一层虚拟节点。如此,直至第二分形树中最底层的任一节点均不具有子节点。如此,通过设置虚拟节点的层级关系和分支关系,使得分形节点对应的第二分形树中的函数调用关系准确,提高3D分形树的准确性和完整性,进一步提高函数调用关系检测的准确性。
若获取的分形节点为覆盖重写函数;对该分形节点进行分析,调用com.intellij.psi.search.searches.OverridingMethodsSearch.search(PsiMethod method,SearchScope scope,boolean checkDeep)获取到所有的实现,即,父函数以及将父函数重写并覆盖的子函数。将该覆盖重写函数的父函数X包装为虚拟节点X;并以该虚拟节点X作为第二分形树的根节点。将覆盖重写函数中对父函数X进行覆盖和重写的子函数Y和子函数Z,分别作为虚拟节点Y和虚拟节点Z;将虚拟节点Y和虚拟节点Z作为第二分形树的根节点下的第一层节点。进一步,将虚拟节点Y作为第二构建节点,将对子函数Y(第二构建节点和虚拟节点Y)进行覆盖重写的函数5作为子节点,虚拟节点Y的子节点集合为:函数5;分形标签为非分形节点;将函数5构建为虚拟节点Y的下一层节点。再以函数5为第二构建节点,将对函数5(第二构建节点)进 行覆盖重写的函数8作为子节点,函数5的子节点集合为:函数8;分形标签为非分形节点;将函数8构建为函数5(第二构建节点)的下一层节点。
将虚拟节点Z作为第二构建节点,将对子函数Z(第二构建节点和虚拟节点Z)进行覆盖重写的函数6、函数7作为子节点,虚拟节点Z的子节点集合为:函数6、函数7;分形标签为非分形节点;将函数6、函数7构建为虚拟节点Z(第二构建节点)的下一层节点。再以函数6、函数7为第二构建节点,将对函数6(第二构建节点)进行覆盖重写的函数9作为子节点,函数6(第二构建节点)的子节点集合为:函数9;分形标签为非分形节点,将函数9构建为函数6(第二构建节点)的下一层节点。将对函数7(第二构建节点)进行覆盖重写的V作为子节点,函数7(第二构建节点)的子节点集合为:V;分形标签为分形节点,将V构建为函数7(第二构建节点)的不具有子节点的下一层虚拟节点。如此,直至第二分形树中最底层的任一节点均不具有子节点。如此,通过设置虚拟节点的层级关系,可以将覆盖重写函数中父函数与各子函数的覆盖和重写的层级明确,使得分形节点对应的第二分形树中的函数调用关系准确,提高3D分形树的准确性和完整性,进一步提高函数调用关系检测的准确性。
本申请实施例提供了一种构建3D分形树的方法,根据所述第一分形树和所述第二分形树,构建3D分形树,包括:确定所述第一分形树中的虚拟节点对应的第二分形树;通过所述第一分形树中的虚拟节点,将所述第一分形树和所述第二分形融合为3D分形树。在上述示例中,如图5所示的3D分形树,为将上述示例中的第二分形树补充至第一分形树中得到的3D分形树。
本申请实施例提供了一种构建3D分形树的方法,所述将所述第一分形树和所述第二分形融合为3D分形树,包括:将所述虚拟节点对应的第二分形树,补充至所述第一分形树的所述虚拟节点中,得到所述第一分形树和所述第二分形树融合的3D分形树;或者,针对所述虚拟节点对应的第二分形树的每个分支,将所述分支分别补充至所述第一分形树的所述虚拟节点中,得到所述第一分形树和所述第二分形树的分支融合的,具有不同分支的至少一个3D分 形树。也就是说,可以将第二分形树补充至对应第一分形树的对应虚拟节点中,如图5所示;还可以将第二分形树中的每个分支分别与第一分形树融合,如图6(a)和图6(b)所示。如此,可以获取一个具有多函数调用路径的且完整的3D分形树;或者可以分别获取具有各不相同的一条函数调用路径的3D分形树,该具有各不相同的一条函数调用路径的3D分形树包含所有函数调用路径。使得3D分形树中包含待检测代码中所有待检测函数的函数调用关系,可以提高待检测代码检测结果的准确性。
本申请实施例提供了一种构建3D分形树的方法,确定待检测代码中各待检测函数的节点信息,包括:遍历所述待检测代码中的各元素;针对任一元素,若所述元素为函数,则确定为待检测函数;确定所述待检测函数是否为设定函数,若为设定函数,则确定所述待检测函数的节点标签指示所述待检测函数为分形节点;遍历所述待检测函数的函数体代码中的各元素,从而确定所述待检测函数的子节点。也就是说,对待检测代码中的分析元素为函数,且分形函数为设定函数。例如,if语句块、switch语句块、覆盖重写函数。另外,这里还可以提供一种待检测代码中的同样需要分析并生成对应节点信息的元素,该元素为非分形节点也为非函数,该元素中可以包含至少一个函数,且该元素至少有一个函数分支。例如,该为非分形节点也为非函数的元素可以为语句块,可以通过上述第一分形树的生成方式对该元素进行分析。如图7(a)所示,当确定函数1的下一层节点分别为语句块W和函数2,则继续获取语句块W中的函数3和函数4,以及函数2下一层节点的函数5和函数6;最后得到的3D分形树如图7(b)所示,将函数1下一层节点语句块W整合为函数1下一层节点函数3和函数4。
本申请实施例提供了一种构建3D分形树的方法,确定待检测代码中各待检测函数的节点信息之前,还包括:确定缓存中不包括所述待检测函数的节点信息。也就是说,若缓存中存在与该待检测函数相同的已经分析过的待检测函数,且缓存中已经存在该已经分析过的待检测函数的节点信息,则直接以缓存中的该节点信息作为该待检测函数的节点信息,可以对该待检测函数 的指针方向进行设置;若缓存中没有与该待检测函数相同的已经分析过的待检测函数,则对该待检测函数进行分析,获取节点信息并缓存。如此,针对相同的多个待检测函数只需要分析一遍,加快获取3D分形树速度,进一步加快检测速度。
本申请实施例提供了一种构建3D分形树的方法,若所述元素为函数,则确定为待检测函数,包括:若确定所述元素为函数且为设定类的业务函数,则确定为待检测函数。也就是说,可以对待检测函数进行设定;如,若只需要对待检测代码的业务功能进行检测,即,对待检测代码中的业务函数进行检测,则可以设定业务函数为待检测函数。如此,可以只对业务函数的函数调用关系进行检测,而无需对构造函数、hash函数、toString函数等分析。即:method.getResolveScope()instanceof LibraryScopeBase||!method.isWritable()等场景跳过。该方法具有针对性的确定待检测函数,减少函数分析数量,降低函数分析工作,加快检测速度。
本申请实施例提供了一种构建3D分形树的方法,通过所述3D分形树确定所述各待检测函数是否符合函数调用关系,包括:在构建所述3D分形树过程中每增加一个节点之后,对所述3D分形树进行遍历,确定所述3D分形树中的各待检测函数是否符合函数调用关系;若不符合,则停止对所述3D分形树的构建。也就是说,边构建3D分形树边根据当前的构建完成的部分分形树获取函数调用关系并检测,即,边构建边检测,加快函数调用关系检测的速度。
本申请实施例提供了一种构建3D分形树的方法,通过所述3D分形树确定所述各待检测函数是否符合函数调用关系,包括:自所述3D分形树中的根节点开始遍历所述3D分形树中的各第一待检测函数对应的节点,得到第一函数调用路径;针对任一第二待检测函数,自所述第二待检测函数中函数分支对应的虚拟节点开始遍历所述3D分形树中的各第二待检测函数对应的节点,得到第二函数调用路径;根据所述第一函数调用路径和所述第二函数调用路径,确定所述各待检测函数是否符合函数调用关系。也就是说,可以分别根 据第一分形树获取第一待检测函数之间的函数调用关系以及第一待检测函数对第二待检测函数的调用关系,以获取第一函数调用路径。可以根据第二分形树获取第二待检测函数之间的调用关系,以获取第二函数调用路径。如此,根据第一函数调用路径和第二函数调用路径获取待检测代码的各待检测函数的函数调用路径并进行检测。
基于上述方法流程可知,待检测代码可以分为三类,第一种为待检测代码中即包含分形节点对应的第二待检测函数,又包含非分形节点对应的第一待检测函数,上述方法流程已经说明如何获取该种待检测代码的3D分形树。第二种为待检测代码中不包含分形节点对应的第二待检测函数,只包含非分形节点对应的第一待检测函数;该种待检测代码可以应用如第一分形树的3D分形树构建方法获取该种待检测代码对应的3D分形树,并获取函数调用关系,根据该待检测代码对应的函数调用关系原则进行检测。第三种为待检测代码中只包含分形节点对应的第二待检测函数;该种待检测代码可以应用如第二分形树的3D分形树构建方法获取该种待检测代码对应的3D分形树,并获取函数调用关系,根据该待检测代码对应的函数调用关系原则进行检测。另外,当上述三种待检测代码中存在循环调用函数时,可以将具有循环指向、且不影响函数调用关系检测的指针擦除。例如,函数1的下一层节点为函数2和函数3,函数3的下一层节点为该函数1,该函数1的下一层节点为该函数3,该函数3的下一层节点为该函数1。如此,函数1和函数3之间形成函数调用路径的循环指向,但函数调用关系原则中只针对函数1和函数2的函数调用关系检测,则可以将函数3指向函数1的指针擦除,破坏掉该循环指向;防止生成3D树时,对该函数1和函数3进行无尽循环分析,降低检测速度。
当上述三种待检测代码中存在重复调用同一节点的情况时,对最终获取的3D分形树并不影响。例如,如下所示的待检测代码1和待检测代码2;图8(a)用于表示待检测代码1的3D分形树生成示意图,图8(b)用于表示待检测代码2的3D分形树生成示意图:
Figure PCTCN2021141990-appb-000001
Figure PCTCN2021141990-appb-000002
基于上述的方法流程,本申请实施例提供了一种函数调用关系检测方法的流程,如图9所示,包括:
步骤901、获取待检测代码。
步骤902、针对待检测代码中的任一元素进行分析,确定元素为函数的元素为待检测函数。这里还可以确定元素为函数,且为业务函数的元素为待检测函数;这里还可以确定元素为非分形节点也为非函数,可以包含至少一个函数,以及至少有一个函数分支的元素为第一待检测函数;这里还可以确定元素为分形节点,该元素为第二待检测函数。
步骤903、获取各待检测函数的节点信息。
步骤904、根据各待检测函数的节点信息获取第一分形树和第二分形树。
步骤905、将所述第一分形树和第二分形树融合获取3D分形树。
步骤906、通过3D分形树获取待检测代码的函数调用关系。
步骤907、将该函数调用关系与函数调用关系原则进行对比检测。
步骤908、获取检测结果。
这里需要说明的是,上述流程步骤并不唯一,例如,步骤903和步骤904可以同时进行。
基于同样的构思,本申请实施例提供一种函数调用关系检测装置,图10 为本申请实施例提供的一种函数调用关系检测装置示意图,如图10示,包括:
分析模块1001,用于确定待检测代码中各待检测函数的节点信息,其中,节点信息中包括用于表征待检测函数是否为分形节点的节点标签;
处理模块1002,用于根据各第一待检测函数的节点信息构建第一分形树,并根据各第二待检测函数的节点信息构建第二分形树;其中,第一待检测函数为节点标签指示为非分形节点的待检测函数;第二待检测函数为节点标签指示为分形节点的待检测函数;
所述处理模块1002还用于,根据所述第一分形树和所述第二分形树,构建3D分形树;
判断模块1003,用于通过所述3D分形树确定所述各待检测函数是否符合函数调用关系。
可选的,所述节点信息还包括子节点;所述子节点为待检测函数调用的函数;所述处理模块1002具体用于:针对任一第一待检测函数,将所述第一待检测函数作为第一分形树的根节点,将所述根节点作为第一构建节点,判断所述第一构建节点的子节点是否为非分形节点;若为非分形节点则将所述子节点构建为所述第一构建节点的下一层节点,并将所述下一层节点作为第一构建节点,返回判断所述第一构建节点的子节点是否为非分形节点的步骤;若所述第一构建节点的子节点为分形节点,将所述子节点构建为所述第一构建节点的不具有子节点的虚拟节点;直至所述第一分形树中任一节点均不具有子节点。
可选的,所述处理模块1002具体用于:针对任一第二待检测函数,生成所述第二待检测函数的虚拟节点作为第二分形树的根节点;生成所述第二待检测函数的任一函数分支对应的虚拟节点作为所述第二分形树的根节点下的第一层节点;通过如下方式生成任一函数分支的虚拟节点的下层节点:将所述虚拟节点作为第二构建节点,判断所述第二构建节点的子节点是否为非分形节点;若所述第二构建节点的子节点为非分形节点,则将所述子节点构建为所述第二构建节点的下一层节点,并将所述下一层节点作为第二构建节点, 返回判断所述第二构建节点的子节点是否为非分形节点的步骤;若所述第二构建节点的子节点为分形节点,将所述子节点构建为所述第二构建节点的不具有子节点的虚拟节点;直至所述第二分形树中任一节点均不具有子节点。
可选的,所述处理模块1002具体用于:确定所述第一分形树中的虚拟节点对应的第二分形树;通过所述第一分形树中的虚拟节点,将所述第一分形树和所述第二分形融合为3D分形树。
可选的,所述处理模块1002具体用于:将所述虚拟节点对应的第二分形树,补充至所述第一分形树的所述虚拟节点中,得到所述第一分形树和所述第二分形树融合的3D分形树;或者,针对所述虚拟节点对应的第二分形树的每个分支,将所述分支分别补充至所述第一分形树的所述虚拟节点中,得到所述第一分形树和所述第二分形树的分支融合的,具有不同分支的至少一个3D分形树。
可选的,所述处理模块1002具体用于:遍历所述待检测代码中的各元素;针对任一元素,若所述元素为函数,则确定为待检测函数;确定所述待检测函数是否为设定函数,若为设定函数,则确定所述待检测函数的节点标签指示所述待检测函数为分形节点;遍历所述待检测函数的函数体代码中的各元素,从而确定所述待检测函数的子节点。
可选的,所述分析模块1001还用于:确定缓存中不包括所述待检测函数的节点信息。
可选的,所述处理模块1002具体用于:若所述元素为函数,则确定为待检测函数,包括:若确定所述元素为函数且为设定类的业务函数,则确定为待检测函数。
可选的,所述判断模块1003具体用于:通过所述3D分形树确定所述各待检测函数是否符合函数调用关系,包括:在构建所述3D分形树过程中每增加一个节点之后,对所述3D分形树进行遍历,确定所述3D分形树中的各待检测函数是否符合函数调用关系;若不符合,则停止对所述3D分形树的构建。
可选的,所述处理模块1002具体用于:自所述3D分形树中的根节点开 始遍历所述3D分形树中的各第一待检测函数对应的节点,得到第一函数调用路径;针对任一第二待检测函数,自所述第二待检测函数中函数分支对应的虚拟节点开始遍历所述3D分形树中的各第二待检测函数对应的节点,得到第二函数调用路径;根据所述第一函数调用路径和所述第二函数调用路径,确定所述各待检测函数是否符合函数调用关系。
本领域内的技术人员应明白,本申请的实施例可提供为方法、系统、或计算机程序产品。因此,本申请可采用完全硬件实施例、完全软件实施例、或结合软件和硬件方面的实施例的形式。而且,本申请可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。
本申请是参照根据本申请的方法、设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。
这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。
这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。
显然,本领域的技术人员可以对本申请进行各种改动和变型而不脱离本申请的精神和范围。这样,倘若本申请的这些修改和变型属于本申请权利要 求及其等同技术的范围之内,则本申请也意图包含这些改动和变型在内。

Claims (10)

  1. 一种函数调用关系检测方法,其特征在于,所述方法包括:
    确定待检测代码中各待检测函数的节点信息,其中,节点信息中包括用于表征待检测函数是否为分形节点的节点标签;
    根据各第一待检测函数的节点信息构建第一分形树,并根据各第二待检测函数的节点信息构建第二分形树;其中,第一待检测函数为节点标签指示为非分形节点的待检测函数;第二待检测函数为节点标签指示为分形节点的待检测函数;
    根据所述第一分形树和所述第二分形树,构建3D分形树;
    通过所述3D分形树确定所述各待检测函数是否符合函数调用关系。
  2. 如权利要求1中所述的方法,其特征在于,所述节点信息还包括子节点;所述子节点为待检测函数调用的函数;所述根据各第一待检测函数的节点信息构建第一分形树,包括:
    针对任一第一待检测函数,将所述第一待检测函数作为第一分形树的根节点,将所述根节点作为第一构建节点,判断所述第一构建节点的子节点是否为非分形节点;
    若为非分形节点则将所述子节点构建为所述第一构建节点的下一层节点,并将所述下一层节点作为第一构建节点,返回判断所述第一构建节点的子节点是否为非分形节点的步骤;
    若所述第一构建节点的子节点为分形节点,将所述子节点构建为所述第一构建节点的不具有子节点的虚拟节点;
    直至所述第一分形树中任一节点均不具有子节点。
  3. 如权利要求2中所述的方法,其特征在于,所述根据各第二待检测函数的节点信息构建第二分形树,包括:
    针对任一第二待检测函数,生成所述第二待检测函数的虚拟节点作为第二分形树的根节点;生成所述第二待检测函数的任一函数分支对应的虚拟节 点作为所述第二分形树的根节点下的第一层节点;
    通过如下方式生成任一函数分支的虚拟节点的下层节点:
    将所述虚拟节点作为第二构建节点,判断所述第二构建节点的子节点是否为非分形节点;
    若所述第二构建节点的子节点为非分形节点,则将所述子节点构建为所述第二构建节点的下一层节点,并将所述下一层节点作为第二构建节点,返回判断所述第二构建节点的子节点是否为非分形节点的步骤;
    若所述第二构建节点的子节点为分形节点,将所述子节点构建为所述第二构建节点的不具有子节点的虚拟节点;
    直至所述第二分形树中任一节点均不具有子节点。
  4. 如权利要求3中所述的方法,其特征在于,根据所述第一分形树和所述第二分形树,构建3D分形树,包括:
    确定所述第一分形树中的虚拟节点对应的第二分形树;
    通过所述第一分形树中的虚拟节点,将所述第一分形树和所述第二分形树融合为3D分形树。
  5. 如权利要求4中所述的方法,其特征在于,所述将所述第一分形树和所述第二分形融合为3D分形树,包括:
    将所述虚拟节点对应的第二分形树,补充至所述第一分形树的所述虚拟节点中,得到所述第一分形树和所述第二分形树融合的3D分形树;或者,
    针对所述虚拟节点对应的第二分形树的每个分支,将所述分支分别补充至所述第一分形树的所述虚拟节点中,得到所述第一分形树和所述第二分形树的分支融合的,具有不同分支的至少一个3D分形树。
  6. 如权利要求1至5任一项中所述的方法,其特征在于,确定待检测代码中各待检测函数的节点信息,包括:
    遍历所述待检测代码中的各元素;
    针对任一元素,若所述元素为函数,则确定为待检测函数;确定所述待检测函数是否为设定函数,若为设定函数,则确定所述待检测函数的节点标 签指示所述待检测函数为分形节点;遍历所述待检测函数的函数体代码中的各元素,从而确定所述待检测函数的子节点。
  7. 如权利要求1至5任一项中所述的方法,其特征在于,
    通过所述3D分形树确定所述各待检测函数是否符合函数调用关系,包括:
    在构建所述3D分形树过程中每增加一个节点之后,对所述3D分形树进行遍历,确定所述3D分形树中的各待检测函数是否符合函数调用关系;若不符合,则停止对所述3D分形树的构建。
  8. 如权利要求1至5任一项中所述的方法,其特征在于,通过所述3D分形树确定所述各待检测函数是否符合函数调用关系,包括:
    自所述3D分形树中的根节点开始遍历所述3D分形树中的各第一待检测函数对应的节点,得到第一函数调用路径;
    针对任一第二待检测函数,自所述第二待检测函数中函数分支对应的虚拟节点开始遍历所述3D分形树中的各第二待检测函数对应的节点,得到第二函数调用路径;
    根据所述第一函数调用路径和所述第二函数调用路径,确定所述各待检测函数是否符合函数调用关系。
  9. 一种函数调用关系检测装置,其特征在于,所述装置包括:
    分析模块,用于确定待检测代码中各待检测函数的节点信息,其中,节点信息中包括用于表征待检测函数是否为分形节点的节点标签;
    处理模块,用于根据各第一待检测函数的节点信息构建第一分形树,并根据各第二待检测函数的节点信息构建第二分形树;其中,第一待检测函数为节点标签指示为非分形节点的待检测函数;第二待检测函数为节点标签指示为分形节点的待检测函数;
    所述处理模块还用于,根据所述第一分形树和所述第二分形树,构建3D分形树;
    判断模块,用于通过所述3D分形树确定所述各待检测函数是否符合函数调用关系。
  10. 一种计算机设备,其特征在于,包括:
    存储器,用于存储计算机程序;
    处理器,用于调用所述存储器中存储的计算机程序,按照获得的程序执行如权利要求1至8任一权利要求所述的方法。
PCT/CN2021/141990 2021-03-30 2021-12-28 一种函数调用关系检测方法及装置 WO2022206062A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202110338210.1 2021-03-30
CN202110338210.1A CN113076244B (zh) 2021-03-30 2021-03-30 一种函数调用关系检测方法及装置

Publications (1)

Publication Number Publication Date
WO2022206062A1 true WO2022206062A1 (zh) 2022-10-06

Family

ID=76611369

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/141990 WO2022206062A1 (zh) 2021-03-30 2021-12-28 一种函数调用关系检测方法及装置

Country Status (2)

Country Link
CN (1) CN113076244B (zh)
WO (1) WO2022206062A1 (zh)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113076244B (zh) * 2021-03-30 2023-03-03 深圳前海微众银行股份有限公司 一种函数调用关系检测方法及装置

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130061215A1 (en) * 2011-09-02 2013-03-07 Microsoft Corporation Inter-procedural dead catch handler optimizations
CN105468508A (zh) * 2014-09-04 2016-04-06 阿里巴巴集团控股有限公司 代码检测方法及装置
CN112181808A (zh) * 2020-09-08 2021-01-05 北京邮电大学 一种程序并发缺陷检测方法、装置、设备以及存储介质
CN113076244A (zh) * 2021-03-30 2021-07-06 深圳前海微众银行股份有限公司 一种函数调用关系检测方法及装置

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5581696A (en) * 1995-05-09 1996-12-03 Parasoft Corporation Method using a computer for automatically instrumenting a computer program for dynamic debugging
US7162741B2 (en) * 2001-07-30 2007-01-09 The Trustees Of Columbia University In The City Of New York System and methods for intrusion detection with dynamic window sizes
US7120901B2 (en) * 2001-10-26 2006-10-10 International Business Machines Corporation Method and system for tracing and displaying execution of nested functions
US8296735B2 (en) * 2010-02-19 2012-10-23 National Ict Australia Limited Inter-procedural analysis of computer programs
CN106294156B (zh) * 2016-08-11 2018-12-07 北京邮电大学 一种静态代码缺陷检测分析方法及装置
CN111104335B (zh) * 2019-12-25 2021-08-24 清华大学 一种基于多层次分析的c语言缺陷检测方法及装置

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130061215A1 (en) * 2011-09-02 2013-03-07 Microsoft Corporation Inter-procedural dead catch handler optimizations
CN105468508A (zh) * 2014-09-04 2016-04-06 阿里巴巴集团控股有限公司 代码检测方法及装置
CN112181808A (zh) * 2020-09-08 2021-01-05 北京邮电大学 一种程序并发缺陷检测方法、装置、设备以及存储介质
CN113076244A (zh) * 2021-03-30 2021-07-06 深圳前海微众银行股份有限公司 一种函数调用关系检测方法及装置

Also Published As

Publication number Publication date
CN113076244B (zh) 2023-03-03
CN113076244A (zh) 2021-07-06

Similar Documents

Publication Publication Date Title
US8935673B1 (en) System and method for debugging computer program based on execution history
EP3433732B1 (en) Converting visual diagrams into code
US20060150160A1 (en) Software analyzer
US20090249250A1 (en) Method and system for log file processing and generating a graphical user interface based thereon
US9588744B2 (en) Renaming instances of an entity in a coding environment
CN103955426A (zh) 一种检测c代码空指针引用的方法及系统
CN112799937B (zh) 基于GitHub自动化检测Maven项目中依赖冲突问题的方法
US20200210158A1 (en) Automated or machine-enhanced source code debugging
WO2022206062A1 (zh) 一种函数调用关系检测方法及装置
US20120159515A1 (en) Sharing object representations
CN116302930A (zh) 应用测试方法和装置
US7603388B2 (en) Representing file data using virtual hierarchy
CN112604273B (zh) 数据驱动的游戏系统功能加载方法、设备及存储介质
CN116432185B (zh) 一种异常检测方法、装置、可读存储介质及电子设备
US10338891B2 (en) Migration between model elements of different types in a modeling environment
CN108459963A (zh) 一种基于中断控制流图的中断验证方法
KR102185294B1 (ko) 병렬 프로그램의 소스 코드 분석 장치 및 방법, 기록매체
US10635416B2 (en) Property filtering
CN115292418B (zh) 跨系统业务流程自动化处理方法及系统
Déhoulé et al. A Change Impact Analysis Model for Aspect Oriented Programs.
CN115408003A (zh) 虚拟机中的数据访问方法、装置、电子设备及介质
CN115167825A (zh) 在Java中处理C++对象的方法、装置、电子设备及存储介质
CN118193382A (zh) 应用程序的测试方法、装置、设备、存储介质及程序产品
CN113590223A (zh) 引擎编辑器的启动方法、装置、电子设备及存储介质
CN114020358A (zh) 基于iOS应用的界面渲染方法及装置

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21934698

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 180124)