Script frame identification method and device, and computer-readable storage medium
By generating a syntax tree of JavaScript scripts and calculating node feature attribute vectors, and cross-referencing them to determine the framework, the limitations of existing keyword matching methods are overcome, achieving more efficient script framework recognition.
Patent Information
- Application Number
- CN202110211269.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-02-25
- Publication Date
- 2024-11-01
- Estimated Expiration
- 2041-02-25
AI Technical Summary
Existing JavaScript framework recognition technologies mainly rely on keyword matching, and their accuracy depends on the keyword rule base and the developers' development habits, which has limitations.
The scripts to be identified for network application services are obtained by traversal, formatted to generate a syntax tree, function declarations or expression nodes are pruned and preserved, node feature attribute vectors are calculated, cross-referenced with the script framework library, and the framework is determined based on similarity.
It reduces the difficulty of customizing and maintaining keyword matching methods, improves recognition accuracy, reduces reliance on source code writing habits, and simplifies the maintenance process.
Smart Images

Figure CN114968184B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of software development, and in particular to a script framework identification method and device thereof, and a computer-readable storage medium. Background Art
[0002] JavaScript is a high-level scripting language for the Internet. It has been widely used in Web application development and is often used to add a variety of dynamic functions to web pages to provide users with a smoother and more beautiful browsing experience.
[0003] In the research of key technologies for automated penetration of Web application services, automatic identification of JavaScript frameworks is the foundation of technical research. Existing JavaScript framework identification technologies mainly use keyword matching methods, based on a custom keyword rule library, to match the source code of Web application services. The accuracy of the matching results depends on the custom rules of the keyword rule library and the naming habits of developers, which has certain limitations. Summary of the invention
[0004] A technical problem solved by the present disclosure is to provide a script framework identification method.
[0005] According to one aspect of the present disclosure, a script framework identification method is provided, comprising: traversing and acquiring a script to be identified of a network application service; formatting the script to be identified, and generating a syntax tree through lexical analysis and syntax analysis; pruning the syntax tree, retaining nodes whose node types are function declarations or function expressions and their child nodes, and generating a function node tree array with the node type being the function declaration or the function expression as the root node; calculating a feature attribute vector of each node of the function node tree array according to the node type of each node of the function node tree array and the defined script feature attributes; cross-comparing the function node tree array of the script to be identified and the function node tree array of a sample script framework in a script framework library to calculate the number of nodes with the same feature attribute vector; calculating the feature similarity between the script to be identified and the sample script framework according to the number of nodes with the same feature attribute vector; and determining that the sample script framework is the framework of the script to be identified when the feature similarity is greater than a threshold.
[0006] In some embodiments, the step of calculating the characteristic attribute vector of each node of the function node tree array includes: calculating the self-characteristic attribute vector of each node of the function node tree array according to the node type of the function node tree array and the defined script characteristic attributes; and calculating the characteristic attribute vector of the parent node in the function node tree array, wherein the characteristic attribute vector of the parent node is the sum of the self-characteristic attribute vector of the parent node and the characteristic attribute vector of the child node of the parent node, and the self-characteristic attribute vector of the child node at the end of the function node tree array is used as the characteristic attribute vector of the child node.
[0007] In some embodiments, the script feature attributes include: literals, variable declarations, flow control statements, loop statements, other statements except the flow control statements and the loop statements, and expressions.
[0008] In some embodiments, the relationship for calculating the feature similarity is: Among them, I SIM is the feature similarity between the script to be identified and the sample script framework, SimNode is the number of nodes with the same feature attribute vector, Num web Num is the number of nodes corresponding to the function node tree array of the script to be identified. fra The number of nodes corresponding to the function node tree array of the sample script framework.
[0009] In some embodiments, the script framework identification method further includes: before traversing and acquiring the script to be identified, establishing the script framework library, wherein the script framework library includes multiple versions of the script framework.
[0010] In some embodiments, the step of establishing the script framework library includes: generating a function node tree array of the sample script framework based on the source code of the sample script framework in the script framework library; and calculating a feature attribute vector of each node in the function node tree array of the sample script framework based on the node type of each node in the function node tree array of the sample script framework and the script feature attribute.
[0011] In some embodiments, the script to be identified is a JavaScript script to be identified; and the sample script framework is a JavaScript sample script framework.
[0012] According to another aspect of the present disclosure, a script framework identification device is provided, comprising: an acquisition unit, configured to traverse and acquire a script to be identified of a network application service; a generation unit, configured to format the script to be identified, generate a syntax tree through lexical analysis and grammatical analysis, prune the syntax tree, retain nodes whose node types are function declarations or function expressions and their child nodes, and generate a function node tree array with the node type being the function declaration or the function expression as a root node; a calculation unit, configured to calculate a feature attribute vector of each node of the function node tree array according to the node type of each node of the function node tree array and a defined script feature attribute, cross-compare the function node tree array of the script to be identified and the function node tree array of a sample script framework in a script framework library to calculate the number of nodes with the same feature attribute vector, and calculate the feature similarity between the script to be identified and the sample script framework according to the number of nodes with the same feature attribute vector; and a determination unit, configured to determine that the sample script framework is the framework of the script to be identified when the feature similarity is greater than a threshold.
[0013] In some embodiments, the calculation unit is used to calculate the self-feature attribute vector of each node of the function node tree array according to the node type of the function node tree array and the defined script feature attributes, and calculate the feature attribute vector of the parent node in the function node tree array, wherein the feature attribute vector of the parent node is the sum of the self-feature attribute vector of the parent node and the feature attribute vector of the child node of the parent node, and the self-feature attribute vector of the child node at the end of the function node tree array is used as the feature attribute vector of the child node.
[0014] In some embodiments, the script feature attributes include: literals, variable declarations, flow control statements, loop statements, other statements except the flow control statements and the loop statements, and expressions.
[0015] In some embodiments, the calculation unit calculates the feature similarity as follows: Among them, I SIM is the feature similarity between the script to be identified and the sample script framework, SimNode is the number of nodes with the same feature attribute vector, Num web Num is the number of nodes corresponding to the function node tree array of the script to be identified. fra The number of nodes corresponding to the function node tree array of the sample script framework.
[0016] In some embodiments, the script framework identification device further includes: a framework library establishment unit, configured to establish the script framework library, wherein the script framework library includes multiple versions of the script framework.
[0017] In some embodiments, the framework library establishment unit is used to generate a function node tree array of the sample script framework based on the source code of the sample script framework in the script framework library, and calculate a feature attribute vector of each node in the function node tree array of the sample script framework based on the node type of each node in the function node tree array of the sample script framework and the script feature attribute.
[0018] In some embodiments, the script to be identified is a JavaScript script to be identified; and the sample script framework is a JavaScript sample script framework.
[0019] According to another aspect of the present disclosure, a script framework identification device is provided, comprising: a memory; and a processor coupled to the memory, wherein the processor is configured to execute the aforementioned method based on instructions stored in the memory.
[0020] According to another aspect of the present disclosure, a computer-readable storage medium is provided, on which computer program instructions are stored. When the instructions are executed by a processor, the method described above is implemented.
[0021] The above script framework identification method identifies the framework of the script to be identified. The above method disclosed in the present invention reduces the difficulty of custom maintenance of the matching rule library in the prior art, and solves the limitation problem of the keyword matching method in the prior art as much as possible. Compared with the keyword matching method in the prior art, the above method disclosed in the present invention is easier to maintain and reduces the dependence on the writing habits of the source code.
[0022] Other features and advantages of the present disclosure will become apparent from the following detailed description of exemplary embodiments of the present disclosure with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] The accompanying drawings, which constitute a part of the specification, illustrate embodiments of the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0024] The present disclosure may be more clearly understood from the following detailed description with reference to the accompanying drawings, in which:
[0025] Figure 1 is a flowchart illustrating a script framework identification method according to some embodiments of the present disclosure;
[0026] Figure 2 is a schematic diagram showing a syntax tree according to some embodiments of the present disclosure;
[0027] Figure 3 is a schematic diagram showing a function node tree array according to some embodiments of the present disclosure;
[0028] Figure 4 is a schematic diagram showing the structure of a script framework identification device according to some embodiments of the present disclosure;
[0029] Figure 5 is a schematic diagram showing the structure of a script framework identification device according to other embodiments of the present disclosure;
[0030] Figure 6 is a schematic diagram showing the structure of a script framework identification device according to other embodiments of the present disclosure;
[0031] Figure 7 It is a schematic diagram showing the structure of a script framework identification device according to some other embodiments of the present disclosure. DETAILED DESCRIPTION
[0032] Various exemplary embodiments of the present disclosure will now be described in detail with reference to the accompanying drawings. It should be noted that the relative arrangement of components and steps, numerical expressions and numerical values set forth in these embodiments do not limit the scope of the present disclosure unless otherwise specifically stated.
[0033] At the same time, it should be understood that for the convenience of description, the sizes of the various parts shown in the drawings are not drawn according to the actual proportional relationship.
[0034] The following description of at least one exemplary embodiment is merely illustrative in nature and is in no way intended to limit the present disclosure, its application, or uses.
[0035] Technologies, methods, and equipment known to ordinary technicians in the relevant art may not be discussed in detail, but where appropriate, the technologies, methods, and equipment should be considered part of the specification.
[0036] In all examples shown and discussed herein, any specific values should be interpreted as merely exemplary and not as limiting. Therefore, other examples of the exemplary embodiments may have different values.
[0037] It should be noted that like reference numerals and letters refer to similar items in the following figures, and therefore, once an item is defined in one figure, it need not be further discussed in subsequent figures.
[0038] Figure 1 is a flowchart illustrating a script framework identification method according to some embodiments of the present disclosure. Figure 2 is a schematic diagram showing a syntax tree according to some embodiments of the present disclosure. Figure 3 is a schematic diagram showing a function node tree array according to some embodiments of the present disclosure. Figures 1 to 3 The script framework identification method according to some embodiments of the present disclosure is described in detail. Figure 1As shown, the script framework identification method includes steps S102 to S114.
[0039] like Figure 1 As shown, in step S102, the script to be identified of the network application service is traversed and obtained. For example, the script to be identified is a JavaScript script to be identified. For example, the JavaScript script to be identified of the Web application service can be traversed and obtained from the Web source code, and the JavaScript script can contain all JavaScript contents of the script (including external scripts).
[0040] In step S104, the script to be recognized is formatted, and a syntax tree is generated through lexical analysis and grammatical analysis.
[0041] Different JavaScript scripts may use different syntaxes, such as ECMAScript, JSX, ES6, etc. The formatting process in this step can convert JavaScript scripts with different syntaxes into scripts with the same syntax, which serves as the basis for later work.
[0042] It can be formatted as follows:
[0043]
[0044] var a=function(){…}
[0045] After the script to be recognized is formatted, a syntax tree is generated through lexical analysis and grammatical analysis, such as Figure 2 shown.
[0046] like Figure 2 As shown in the figure, the syntax tree includes: Program, Function Declaration, Variable Declaration, Block Statement, Function Expression, If Statement, Return Statement, Member Expression, Binary Expression, Throw Statement, Null Literal and Call Expression, etc.
[0047] In step S106, the syntax tree is pruned to retain nodes whose node types are function declarations or function expressions and their child nodes, and a function node tree array is generated with the node whose node type is function declarations or function expressions as the root node.
[0048] For example, Figure 2 As shown, there is a node whose node type is function declaration and another node whose node type is function expression in the syntax tree. The nodes can be pruned to keep the node whose node type is function declaration or function expression and its child nodes, and generate a function node tree array with function declaration or function expression as the root node. For example, Figure 3 As shown, after pruning, two function node trees are generated, one of which is a function node tree with the function declaration as the root node, and the other is a function node tree with the function expression as the root node.
[0049] In step S108, a feature attribute vector of each node in the function node tree array is calculated according to the node type of each node in the function node tree array and the defined script feature attribute.
[0050] For example, the defined script feature attributes include: literals, variable declarations, flow control statements, loop statements, other statements except the flow control statements and the loop statements, and expressions. In this way, the feature attribute vector can be: (literals, variable declarations, flow control statements, loop statements, other statements except the flow control statements and the loop statements, expressions). For example, if the current node is a variable declaration, the feature attribute vector is (0, 1, 0, 0, 0, 0). For another example, if the current node is a binary expression node, the feature attribute vector of the node is (0, 0, 0, 0, 0, 1).
[0051] In some embodiments, the step of calculating the characteristic attribute vector of each node of the function node tree array includes: calculating the self-characteristic attribute vector of each node of the function node tree array according to the node type of the function node tree array and the defined script characteristic attributes; and calculating the characteristic attribute vector of the parent node in the function node tree array, wherein the characteristic attribute vector of the parent node is the sum of the self-characteristic attribute vector of the parent node and the characteristic attribute vector of the child node of the parent node, and the self-characteristic attribute vector of the child node at the end of the function node tree array is used as the characteristic attribute vector of the child node.
[0052] Here, the self-characteristic attribute vector of each node refers to the current characteristic attribute vector of each node. In the function node tree array, the characteristic attribute vector of the parent node = the self-characteristic attribute vector of the parent node + the characteristic attribute vector of the child node of the parent node.
[0053] For example, Figure 3Take the binary expression node in as an example. The binary expression node is the parent node, and its child node is the literal node. According to the definition of feature attributes, the feature attribute vector of the literal node is (1,0,0,0,0,0,0), and the self-feature attribute vector of the binary expression node is (0,0,0,0,0,1). Then the feature attribute vector of the binary expression node is (0,0,0,0,0,1)+(1,0,0,0,0,0)=(1,0,0,0,0,1).
[0054] For example, Figure 3 Take the conditional statement node in as an example. The conditional statement node is the parent node, and its child nodes are the binary expression node and the throw statement node. According to the above calculation process, the characteristic attribute vector of the binary expression node is (1,0,0,0,0,1); similarly, the characteristic attribute vector of the throw statement node is (0,0,0,0,1,1). Since the conditional statement belongs to the flow control statement, the self-characteristic attribute vector of the conditional statement node is (0,0,1,0,0,0), then the characteristic attribute vector of the conditional statement node is (0,0,1,0,0,0)+(1,0,0,0,0,1)+(0,0,0,0,1,1)=(1,0,1,0,1,2).
[0055] In step S110, the function node tree array of the script to be identified is cross-compared with the function node tree array of the sample script framework in the script framework library to calculate the number of nodes with the same characteristic attribute vector. For example, the sample script framework is a JavaScript sample script framework.
[0056] Here, in this step, the function node is taken as the root node, and all child nodes with the same feature attribute vector are calculated.
[0057] The following example illustrates the process of cross-comparing the function node tree array of the script to be identified and the function node tree array of the sample script framework in the script framework library to calculate the number of nodes with the same feature attribute vector.
[0058] For example, for the JavaScript script whose frame is to be identified, the function node tree array with the function declaration or function expression as the root node is [a1, b1, c1, d1], where a1, b1, c1, d1 are the node trees of the function declaration or function expression. A JavaScript sample script frame is obtained from the script frame library, and its corresponding node tree array is [a2, b2, c2, d2]. First, calculate the number of nodes with the same feature attribute vector in a1 and a2, b2, c2, d2 (referred to as the number of nodes, the same below), and take the maximum value Sim-a. Here, Figure 3Take the function declaration in as an example, define it as node tree a1, and compare it with the sample node tree a2 of the script framework library. First, compare the characteristic attribute vector of the block statement node in node tree a1 with the characteristic attribute vector of the first-level child node in sample node tree a2. If they are the same, Sim-a is increased by 1. Then compare the variable declaration node in node tree a1 with the second-level child node in sample node tree a2. If the characteristic attribute vectors are the same, Sim-a is increased by 1. And so on, Sim-a is calculated.
[0059] After calculating Sim-a, the number of nodes with the same characteristic attribute vectors as b1, a2, b2, c2, and d2 is calculated respectively, and the maximum value Sim-b is taken. Similarly, the number of all identical nodes is calculated as SimNode = Sim-a + Sim-b + ..., which is the number of nodes with the same characteristic attribute vector that needs to be calculated.
[0060] In step S112, the feature similarity between the script to be identified and the sample script framework is calculated according to the number of nodes having the same feature attribute vector.
[0061] In some embodiments, the relationship between the feature similarity between the script to be identified and the sample script framework is calculated as follows:
[0062]
[0063] Among them, I SIM is the feature similarity between the script to be identified and the sample script framework, SimNode is the number of nodes with the same feature attribute vector, Num web Num is the number of nodes corresponding to the function node tree array of the script to be identified. fra The number of nodes corresponding to the function node tree array of the sample script framework.
[0064] In step S114, when the feature similarity is greater than a threshold, the sample script framework is determined to be the framework of the script to be identified. In this way, the framework of the script to be identified is identified.
[0065] For example, the threshold value may be 80% to 85%. Here, it should be noted that the threshold value may be determined according to actual conditions or actual needs, for example, a reasonable threshold value may be obtained after multiple training tests. Therefore, the scope of the present disclosure is not limited to the range of the threshold value disclosed herein.
[0066] In some embodiments, when the feature similarity is less than or equal to a threshold value and it is determined that the sample script framework is not the framework of the script to be identified, another sample script framework can be selected from the script framework library, and after steps S110 to S114, it is determined whether the other sample script framework is the framework of the script to be identified, and the process is executed in a loop until the framework of the script to be identified is identified.
[0067] So far, a script framework identification method according to some embodiments of the present disclosure is provided. The method includes: traversing and obtaining the script to be identified of the network application service; formatting the script to be identified, generating a syntax tree through lexical analysis and syntax analysis; pruning the syntax tree, retaining the node type of the function declaration or function expression and its child nodes, and generating a function node tree array with the node type of the function declaration or function expression as the root node; calculating the characteristic attribute vector of each node of the function node tree array according to the node type of each node of the function node tree array and the defined script characteristic attribute; cross-comparing the function node tree array of the script to be identified and the function node tree array of the sample script framework in the script framework library to calculate the number of nodes with the same characteristic attribute vector; calculating the characteristic similarity between the script to be identified and the sample script framework according to the number of nodes with the same characteristic attribute vector; and determining that the sample script framework is the framework of the script to be identified when the characteristic similarity is greater than a threshold. In this way, the framework of the script to be identified is identified. The above method of the present disclosure reduces the difficulty of custom maintenance of the matching rule library in the prior art, and solves the limitation problem of the keyword matching method of the prior art as much as possible. Compared with the keyword matching method in the prior art, the above method disclosed in the present invention is simpler to maintain and reduces the dependence on source code writing habits.
[0068] Furthermore, since in JavaScript scripts, function declarations or function expressions are the main content, in the process of pruning the syntax tree, nodes whose node types are function declarations or function expressions and their child nodes are retained, and a function node tree array with the function declaration or function expression as the root node is generated. This can increase the accuracy of subsequent operations and improve the practicability of the above method.
[0069] In some embodiments, the script framework identification method may further include: before traversing and obtaining the script to be identified, establishing a script framework library. The script framework library includes multiple versions (e.g., all versions) of the script framework. For example, the script framework library includes all sample frameworks of JavaScript scripts, such as Angular, React, Vue, JQuery framework, etc.
[0070] In some embodiments, the step of establishing a script framework library includes: generating a function node tree array of a sample script framework based on the source code of the sample script framework in the script framework library; and calculating a feature attribute vector of each node in the function node tree array of the sample script framework based on the node type and script feature attributes of each node in the function node tree array of the sample script framework.
[0071] The process of generating the function node tree array of the sample script framework is similar to the process of the previous steps S104 and S106, and the process of calculating the characteristic attribute vector of each node of the function node tree array of the sample script framework is similar to the specific process of the previous step S108, which will not be repeated here. This facilitates the cross-comparison operation between the function node tree array of the script to be identified and the function node tree array of the sample script framework in the script framework library.
[0072] Figure 4 FIG. 2 is a schematic diagram showing a structure of a script framework identification device according to some embodiments of the present disclosure. Figure 4 As shown, the script framework identification device includes an acquisition unit 402 , a generation unit 404 , a calculation unit 406 and a determination unit 408 .
[0073] The acquisition unit 402 is used to traverse and acquire the script to be identified of the network application service. For example, the script to be identified is a JavaScript script to be identified.
[0074] The generation unit 404 is used to format the script to be recognized, generate a syntax tree through lexical analysis and grammatical analysis, prune the syntax tree, retain nodes whose node types are function declarations or function expressions and their child nodes, and generate a function node tree array with the node type being function declarations or function expressions as the root node.
[0075] The calculation unit 406 is used to calculate the characteristic attribute vector of each node of the function node tree array according to the node type of each node of the function node tree array and the defined script characteristic attribute, cross-compare the function node tree array of the script to be identified and the function node tree array of the sample script framework in the script framework library to calculate the number of nodes with the same characteristic attribute vector, and calculate the characteristic similarity between the script to be identified and the sample script framework according to the number of nodes with the same characteristic attribute vector. For example, the sample script framework is a JavaScript sample script framework.
[0076] In some embodiments, the script feature attributes include: literals, variable declarations, flow control statements, loop statements, statements other than flow control statements and loop statements, and expressions.
[0077] The determination unit 408 is configured to determine that the sample script framework is the framework of the script to be identified when the feature similarity is greater than a threshold.
[0078] So far, a script framework identification device according to some embodiments of the present disclosure is provided. The script framework identification device includes an acquisition unit, a generation unit, a calculation unit and a determination unit. The script framework identification device identifies the framework of the script to be identified. The above-mentioned device of the present disclosure reduces the difficulty of custom maintenance of the matching rule library in the prior art, and solves the limitation problem of the keyword matching method of the prior art as much as possible. Compared with the keyword matching method of the prior art, the above-mentioned device of the present disclosure is simpler to maintain and reduces the dependence on the writing habits of the source code.
[0079] In some embodiments, the calculation unit 406 can be used to calculate the self-feature attribute vector of each node of the function node tree array according to the node type of the function node tree array and the defined script feature attributes, and calculate the feature attribute vector of the parent node in the function node tree array, wherein the feature attribute vector of the parent node is the sum of the self-feature attribute vector of the parent node and the feature attribute vector of the child node of the parent node, and the self-feature attribute vector of the child node at the end of the function node tree array is used as the feature attribute vector of the child node.
[0080] In some embodiments, the calculation unit 406 calculates the feature similarity as follows:
[0081]
[0082] Among them, I SIM is the feature similarity between the script to be identified and the sample script framework, SimNode is the number of nodes with the same feature attribute vector, Num web Num is the number of nodes corresponding to the function node tree array of the script to be identified. fra The number of nodes corresponding to the function node tree array of the sample script framework.
[0083] Figure 5 FIG. 2 is a schematic diagram showing the structure of a script framework identification device according to other embodiments of the present disclosure. Figure 5 As shown, the script framework identification device includes an acquisition unit 402 , a generation unit 404 , a calculation unit 406 and a determination unit 408 .
[0084] In some embodiments, Figure 5 As shown, the script framework identification device may further include a framework library establishment unit 510. The framework library establishment unit 510 is used to establish a script framework library, wherein the script framework library includes multiple versions (eg, all versions) of the script framework.
[0085] In some embodiments, the framework library establishment unit 510 is used to generate a function node tree array of the sample script framework according to the source code of the sample script framework in the script framework library, and calculate the characteristic attribute vector of each node of the function node tree array of the sample script framework according to the node type and script characteristic attribute of each node in the function node tree array of the sample script framework. Here, the process of the framework library establishment unit 510 generating the function node tree array of the sample script framework is similar to the process of the generation unit 404 generating the function node tree array, and the process of the framework library establishment unit 510 calculating the characteristic attribute vector of each node of the function node tree array of the sample script framework is similar to the process of the calculation unit 406 calculating the characteristic attribute vector of each node of the function node tree array, which will not be repeated here.
[0086] Figure 6 6 is a schematic diagram showing the structure of a script frame identification device according to other embodiments of the present disclosure. The script frame identification device includes a memory 610 and a processor 620. Among them:
[0087] The memory 610 can be a disk, a flash memory, or any other non-volatile storage medium. The memory is used to store Figure 1 The instructions in the corresponding embodiment.
[0088] The processor 620 is coupled to the memory 610 and can be implemented as one or more integrated circuits, such as a microprocessor or a microcontroller. The processor 620 is used to execute instructions stored in the memory and identify the framework of the script to be identified. The device reduces the difficulty of custom maintenance of the matching rule library in the prior art and solves the limitation problem of the keyword matching method in the prior art as much as possible.
[0089] In some embodiments, it is also possible to Figure 7 As shown, the script framework identification device 700 includes a memory 710 and a processor 720. The processor 720 is coupled to the memory 710 via a BUS bus 730. The script framework identification device 700 can also be connected to an external storage device 750 via a storage interface 740 to call external data, and can also be connected to a network or another computer system (not shown) via a network interface 760, which will not be described in detail here.
[0090] In this embodiment, the memory stores data instructions, and the processor processes the instructions to identify the framework of the script to be identified. The device reduces the difficulty of custom maintenance of the matching rule library in the prior art and solves the limitation problem of the keyword matching method in the prior art as much as possible.
[0091] In some other embodiments, the present disclosure further provides a computer-readable storage medium having computer program instructions stored thereon, which are executed by a processor to implement Figure 1 The steps of the method in the corresponding embodiment. Those skilled in the art will appreciate that the embodiments of the present disclosure may be provided as methods, devices, or computer program products. Therefore, the present disclosure may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present disclosure may take the form of a computer program product implemented on one or more computer-usable non-transient storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0092] The present disclosure is described with reference to flowcharts and / or block diagrams of methods, devices (systems) and computer program products according to embodiments of the present disclosure. It should be understood that each process and / or block in the flowchart and / or block diagram and the combination of processes and / or blocks in the flowchart and / or block diagram can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0093] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0094] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0095] So far, the present disclosure has been described in detail. In order to avoid obscuring the concept of the present disclosure, some details known in the art are not described. Based on the above description, those skilled in the art can fully understand how to implement the technical solution disclosed here.
[0096] Although some specific embodiments of the present disclosure have been described in detail by way of example, it should be understood by those skilled in the art that the above examples are for illustration only and are not intended to limit the scope of the present disclosure. It should be understood by those skilled in the art that the above embodiments may be modified without departing from the scope and spirit of the present disclosure. The scope of the present disclosure is defined by the appended claims.
Claims
1. A script frame identification method, comprising: Traverse and obtain the script to be identified of the network application service; Formatting the script to be recognized, and generating a syntax tree through lexical analysis and grammatical analysis; The syntax tree is pruned to retain nodes whose node types are function declarations or function expressions and their child nodes, and a function node tree array is generated with the node whose node type is the function declaration or the function expression as the root node; Calculate a feature attribute vector of each node of the function node tree array according to the node type of each node of the function node tree array and the defined script feature attribute; Cross-comparing the function node tree array of the script to be identified with the function node tree array of the sample script framework in the script framework library to calculate the number of nodes with the same characteristic attribute vector; Calculating the feature similarity between the to-be-identified script and the sample script framework according to the number of nodes with the same feature attribute vector; and When the feature similarity is greater than a threshold, determining that the sample script framework is the framework of the script to be identified; The step of calculating the characteristic attribute vector of each node of the function node tree array includes: calculating the self-characteristic attribute vector of each node of the function node tree array according to the node type of the function node tree array and the defined script characteristic attribute; and calculating the characteristic attribute vector of the parent node in the function node tree array, wherein the characteristic attribute vector of the parent node is the sum of the self-characteristic attribute vector of the parent node and the characteristic attribute vector of the child node of the parent node, and the self-characteristic attribute vector of the child node at the end of the function node tree array is used as the characteristic attribute vector of the child node; The relationship for calculating the feature similarity is: Among them, I SIM is the feature similarity between the script to be identified and the sample script framework, SimNode is the number of nodes with the same feature attribute vector, Num web Num is the number of nodes corresponding to the function node tree array of the script to be identified. fra The number of nodes corresponding to the function node tree array of the sample script framework.
2. The script frame identification method according to claim 1, wherein: The script feature attributes include: literals, variable declarations, flow control statements, loop statements, other statements except the flow control statements and the loop statements, and expressions.
3. The script framework identification method according to claim 1, further comprising: Before traversing and acquiring the script to be identified, the script framework library is established, wherein the script framework library includes multiple versions of the script framework.
4. The script frame identification method according to claim 3, wherein: The steps of establishing the script framework library include: Generate a function node tree array of the sample script framework according to the source code of the sample script framework in the script framework library; and A feature attribute vector of each node in the function node tree array of the sample script framework is calculated according to the node type of each node in the function node tree array of the sample script framework and the script feature attribute.
5. The script frame identification method according to claim 1, wherein: The script to be identified is a JavaScript script to be identified; The sample script framework is a JavaScript sample script framework.
6. A script framework identification device, comprising: An acquisition unit, used for traversing and acquiring a script to be identified by a network application service; A generating unit, configured to format the script to be recognized, generate a syntax tree through lexical analysis and grammatical analysis, prune the syntax tree, retain nodes whose node types are function declarations or function expressions and their child nodes, and generate a function node tree array with the node whose node type is the function declaration or the function expression as the root node; a calculation unit, configured to calculate a characteristic attribute vector of each node of the function node tree array according to a node type of each node of the function node tree array and a defined script characteristic attribute, cross-compare the function node tree array of the script to be identified and the function node tree array of a sample script framework in a script framework library to calculate the number of nodes having the same characteristic attribute vector, and calculate the characteristic similarity between the script to be identified and the sample script framework according to the number of nodes having the same characteristic attribute vector; as well as A determination unit, configured to determine that the sample script framework is the framework of the script to be identified when the feature similarity is greater than a threshold; The calculation unit is used to calculate the self-feature attribute vector of each node of the function node tree array according to the node type of the function node tree array and the defined script feature attribute, and calculate the feature attribute vector of the parent node in the function node tree array, wherein the feature attribute vector of the parent node is the sum of the self-feature attribute vector of the parent node and the feature attribute vector of the child node of the parent node, and the self-feature attribute vector of the child node at the end of the function node tree array is used as the feature attribute vector of the child node; The relationship formula for calculating the feature similarity by the calculation unit is: Among them, I SIM is the feature similarity between the script to be identified and the sample script framework, SimNode is the number of nodes with the same feature attribute vector, Num web Num is the number of nodes corresponding to the function node tree array of the script to be identified. fra The number of nodes corresponding to the function node tree array of the sample script framework.
7. The script frame identification device according to claim 6, wherein: The script feature attributes include: literals, variable declarations, flow control statements, loop statements, other statements except the flow control statements and the loop statements, and expressions.
8. The script frame identification device according to claim 6, further comprising: The framework library establishing unit is used to establish the script framework library, wherein the script framework library includes multiple versions of the script framework.
9. The script frame identification device according to claim 8, wherein: The framework library establishment unit is used to generate a function node tree array of the sample script framework according to the source code of the sample script framework in the script framework library, and calculate a feature attribute vector of each node in the function node tree array of the sample script framework according to the node type of each node in the function node tree array of the sample script framework and the script feature attribute.
10. The script frame identification device according to claim 6, wherein: The script to be identified is a JavaScript script to be identified; The sample script framework is a JavaScript sample script framework.
11. A script framework identification device, comprising: Memory; as well as A processor coupled to the memory, wherein the processor is configured to execute the method according to any one of claims 1 to 5 based on instructions stored in the memory.
12. A computer-readable storage medium having computer program instructions stored thereon, wherein the instructions, when executed by a processor, implement the method according to any one of claims 1 to 5.
