Code dynamic binding analysis method, device, equipment and storage medium

Through recursive query and call point analysis technology, the parent class and child class method call points in object-oriented programming are extracted and combined, which solves the problem of difficult to identify dynamically bound call points in static code analysis, and improves recognition accuracy.

CN119148999BActive Publication Date: 2025-02-11SECZONE TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411659331.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-20
Publication Date
2025-02-11
Estimated Expiration
2044-11-20

AI Technical Summary

Technical Problem

In object-oriented programming, static code analysis is difficult to accurately identify dynamic bound call points that call subclass rewrite methods through parent class type references, especially under complex polymorphic and inheritance relationships.

Method used

By extracting the parent class method corresponding to the preset format code, recursively querying the call points of the parent class method, identifying and analyzing the call points of the subclass method related to the call points of the parent class method, combining the call points of the subclass method and the initial The direct call point of query to obtain complete call information.

Benefits of technology

It significantly improves the recognition accuracy of dynamic binding method calls, reduces the possibility of false positives and missed reports, and ensures that all relevant dynamic binding calls are accurately captured.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119148999B_ABST
    Figure CN119148999B_ABST
Patent Text Reader

Abstract

The present application discloses a method, device, equipment and storage medium for analyzing code dynamic binding, and relates to the field of object-oriented programming technology. The method comprises: extracting a parent class method corresponding to a code in a preset format, and recursively querying the call point of the parent class method; identifying and analyzing the call point of the subclass method related to the call point of the parent class method; combining the call point of the subclass method with the direct call point of the initial query to obtain complete call information. The method ensures that all relevant dynamic binding calls are accurately captured through a recursive query mechanism, and combines data flow analysis and type verification technology to reduce the possibility of false positives and false negatives to a certain extent, thereby significantly improving the recognition accuracy of dynamic binding method calls.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of object-oriented programming, and in particular to a method, apparatus, device and storage medium for dynamic code binding analysis. Background Art

[0002] In object-oriented languages, when a subclass overrides a parent class method and these overridden methods are called in the code through a type reference of the parent class, static code analysis may not be able to directly identify which subclass implementation will actually be bound to when trying to find direct calls to a specific subclass overridden method, because this decision is made at runtime through a dynamic binding process.

[0003] Therefore, when trying to find direct calls to specific subclass override methods through static analysis, if these method calls are made through references of the parent class type, static analysis tools often cannot directly locate the call site associated with the specific subclass implementation. This is because static analysis can only reveal the reference type used when the method is called, and cannot predict or determine which subclass override version will actually be executed at runtime. Only when the method is called directly using a reference of the subclass type can static analysis be more directly associated with the specific subclass implementation, but this is not always possible, especially when there are complex polymorphism and inheritance relationships. Summary of the invention

[0004] The main purpose of this application is to provide a code dynamic binding analysis method, device, equipment and storage medium, aiming to solve the technical problem of how to improve the accuracy of identifying object-oriented dynamic binding calls.

[0005] To achieve the above objectives, the present application proposes a code dynamic binding analysis method, the method comprising:

[0006] Extract the parent class method corresponding to the code in a preset format, and recursively query the calling point of the parent class method;

[0007] Identify and analyze the call points of the subclass method related to the call points of the parent class method;

[0008] The call point of the subclass method is combined with the direct call point of the initial query to obtain complete call information.

[0009] In one embodiment, before the step of extracting the parent class method corresponding to the code in the preset format and recursively querying the calling point of the parent class method, the following steps are included:

[0010] Identify source code through the scanning engine and start the corresponding parser or compiler;

[0011] The source code is converted into a code in a preset format by the parser or the compiler.

[0012] In one embodiment, before the step of extracting the parent class method corresponding to the code in the preset format and recursively querying the calling point of the parent class method, the step further includes:

[0013] Query the direct call location of the code in the preset format to obtain the direct call point of the initial query.

[0014] In one embodiment, the step of extracting the parent class method corresponding to the code language in the preset format and recursively querying the calling point of the parent class method includes:

[0015] Analyze the declaration of the class where the specific method is located in the code language of the preset format to identify the interface information corresponding to the specific method;

[0016] Based on the interface information, the parent class method that matches the specific method is recursively queried, and the calling point of the parent class method is obtained.

[0017] In one embodiment, the step of identifying and analyzing the call points of the subclass method related to the call points of the parent class method includes:

[0018] Filtering the calling points of the parent class method to obtain the calling points of the child class method related to the calling points of the parent class method;

[0019] The calling point of the subclass method is analyzed to determine the object type in the assignment statement in the calling point of the subclass method.

[0020] In one embodiment, after the step of analyzing the calling point of the subclass method to determine the object type in the assignment statement and the initialization statement in the calling point of the subclass method, the method further includes:

[0021] Based on the object type in the assignment statement in the calling point of the subclass method, confirm the indirect calling point of the subclass method;

[0022] Verify whether the indirect call point of the subclass method points to a specific method overridden or implemented by the subclass method;

[0023] If so, the indirect call point of the subclass method is used as the effective indirect action point of the subclass method.

[0024] In one embodiment, the step of combining the call point of the subclass method with the direct call point of the initial query to obtain complete call information includes:

[0025] The effective indirect action points of the subclass method are merged with the direct call points of the initial query to form complete call information.

[0026] In addition, to achieve the above purpose, the present application also proposes a code dynamic binding analysis device, the code dynamic binding analysis device comprising:

[0027] A query module, used to extract the parent class method corresponding to the code in a preset format, and recursively query the call point of the parent class method;

[0028] An analysis module, used to identify and analyze the call points of the subclass method related to the call points of the parent class method;

[0029] The acquisition module is used to combine the call point of the subclass method with the direct call point of the initial query to obtain complete call information.

[0030] In addition, to achieve the above-mentioned purpose, the present application also proposes a code dynamic binding analysis device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, and the computer program is configured to implement the steps of the code dynamic binding analysis method described above.

[0031] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the code dynamic binding analysis method described above are implemented.

[0032] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the code dynamic binding analysis method described above are implemented.

[0033] The embodiment of the present application provides a method, device, equipment and storage medium for analyzing code dynamic binding, the method comprising: extracting the parent class method corresponding to the code in a preset format, and recursively querying the call point of the parent class method; identifying and analyzing the call point of the subclass method related to the call point of the parent class method; combining the call point of the subclass method with the direct call point of the initial query to obtain complete call information. The method ensures that all relevant dynamic binding calls are accurately captured through a recursive query mechanism, and combines data flow analysis and type verification technology to reduce the possibility of false positives and false negatives to a certain extent, thereby significantly improving the recognition accuracy of dynamic binding method calls. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0035] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0036] Figure 1 A flowchart of the first embodiment of the method for dynamic binding analysis of code in this application;

[0037] Figure 2 A flowchart diagram of the second embodiment of the method for dynamic binding analysis of code of this application;

[0038] Figure 3 A brief flowchart of the code dynamic binding analysis method provided in Example 1 of the present application;

[0039] Figure 4 This is a schematic diagram of the module structure of the code dynamic binding analysis device according to the embodiment of the present application;

[0040] Figure 5 This is a schematic diagram of the device structure of the hardware operating environment involved in the code dynamic binding analysis method in the embodiment of the present application.

[0041] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0042] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.

[0043] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.

[0044] The main solution of the embodiment of the present application is: extract the parent class method corresponding to the code in a preset format, and recursively query the call points of the parent class method; identify and analyze the call points of the subclass method related to the call points of the parent class method; combine the call points of the subclass method with the direct call points of the initial query to obtain complete call information.

[0045] Because in object-oriented languages, when a subclass overrides a parent class method and these overridden methods are called through the parent class type reference in the code, static code analysis (especially those based only on abstract syntax trees) may not be able to directly identify which subclass implementation will actually be bound to when trying to find direct calls to specific subclass overridden methods, because this decision is made at runtime through the dynamic binding process.

[0046] Therefore, when trying to find direct calls to specific subclass overridden methods through static analysis (such as analysis based on abstract syntax trees), if these method calls are made through references of parent class types, static analysis tools often cannot directly locate the call sites associated with the specific subclass implementation. This is because static analysis can only reveal the reference type used when calling the method (usually the parent class type), but cannot predict or determine which subclass overridden version will actually be executed at runtime. Only when a method is called directly using a reference of the subclass type, static analysis may be more directly associated with the specific subclass implementation in some cases, but this is not always possible, especially when there are complex polymorphism and inheritance relationships.

[0047] The following is a simplified Java code example to further illustrate the impact of polymorphism on static code analysis, showing a situation where a subclass overrides a parent class method and calls these methods through a parent class type reference.

[0048]

[0049] In the example above, the Animal class is the parent class and it has a makeSound method. Dog is a subclass of Animal and the makeSound method is overridden to provide animal-specific sounds. In the main method of the AnimalDemo class, instances of Dog are created but references of type Animal are used to refer to them. When the makeItSound method is called and these references are passed in, due to polymorphism, the makeSound method implementation in the subclass is actually executed. This mechanism allows us to handle different types of objects in a uniform way without knowing the specific type of the object.

[0050] The present application provides a solution, which extracts the parent class method corresponding to the code in a preset format and recursively queries the call point of the parent class method. Through the recursive query mechanism, it can flexibly cope with this complexity and ensure that all related dynamic binding calls are accurately captured; identify and analyze the call points of the subclass methods related to the call points of the parent class method, and effectively reduce the false positives and missed negatives that may occur when identifying dynamic binding calls by introducing call point filtering and data flow analysis technology; combine the call points of the subclass method with the direct call points of the initial query to obtain complete call information, and through in-depth analysis of polymorphism and inheritance mechanisms in object-oriented programming, significantly improve the recognition accuracy of dynamic binding method calls.

[0051] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device capable of realizing the above functions, etc. The following takes a personal computer as an example to illustrate this embodiment and the following embodiments.

[0052] Based on this, the embodiment of the present application provides a code dynamic binding analysis method, referring to Figure 1 , Figure 1 This is a flow chart of the first embodiment of the code dynamic binding analysis method of this application.

[0053] In this embodiment, the code dynamic binding analysis method includes steps S10 to S30:

[0054] Step S10, extracting the parent class method corresponding to the code in a preset format, and recursively querying the calling point of the parent class method;

[0055] It should be noted that in object-oriented programming, the parent class is the basis for other classes to inherit, and the parent class method refers to the method defined in the parent class. The call point of the parent class method refers to the location in the code where the parent class method is actually called. This can be a direct call in the same class or an indirect call in the child class through inheritance or overriding.

[0056] It is understandable that in order to facilitate the subsequent analysis of the dynamic binding identification method, the source code needs to be converted into a standard format before querying the parent class method.

[0057] Specifically, first, a scanning engine is used to read the source code file, and the programming language used is identified through specific identifiers and keywords. Once the programming language is confirmed, the system will start the corresponding parser or compiler. For example, for Java code, a Java compiler may be used; for Python code, a Python parser may be used. The parser or compiler then converts the source code into an abstract syntax tree specific to the language. An abstract syntax tree is a tree data structure in which each node represents a construct of the source code, such as an expression, statement, or declaration. In order to uniformly process codes in different programming languages, the language-specific abstract syntax tree will be further converted into a common abstract syntax tree format for subsequent processing. During this conversion process, the parent class and interface information of the current class will be identified and associated, and a preliminary class method call relationship will be generated. Dynamic binding is not considered at this time.

[0058] In addition, when it is necessary to query the specific call of a specific method in a code language of a preset format, the direct call position of the method is first directly queried to obtain the direct call point of the initial query of the method.

[0059] After converting the source code into an abstract syntax tree format and obtaining the direct call point of the initial query of a specific method in a preset format code language, execute the step of "extracting the parent class method corresponding to the preset format code and recursively querying the call point of the parent class method".

[0060] The step of "extracting the parent class method corresponding to the code in the preset format, and recursively querying the calling point of the parent class method" further includes steps S11 to S12:

[0061] Step S11, analyzing the declaration of the class where the specific method is located in the code language of the preset format to identify the interface information corresponding to the specific method;

[0062] It should be noted that a class declaration usually includes the class name, the inherited parent class, the implemented interface, and the methods and properties in the class.

[0063] Specifically, a class declaration containing a specific method in a code language of a preset format is searched, for example, in a Java code, a declaration of the Dog class is searched. Then, relevant information is extracted from the class declaration, including but not limited to the class name, a name used to identify the class, an inherited parent class, an implemented interface, and class members. A specific method is found in the class declaration, for example, a makeSound method.

[0064] Then, all interfaces listed in the class declaration are checked to determine which interface defines a particular method by examining the method signatures in the interfaces.

[0065] In the above steps, the interface information implemented by a specific method is identified by analyzing the declaration part of the class.

[0066] Step S12: based on the interface information, recursively search for the parent class method that matches the specific method, and obtain the calling point of the parent class method.

[0067] Based on the interface information identified in step S11, all possible parent class methods are recursively queried, and the calling points of these parent class methods are obtained.

[0068] Specifically, first create a collection to store all the found parent class method call sites. Starting from the current class, recursively check its parent class and implemented interfaces to query methods that match the specific method signature. If a matching method is found in the parent class method or interface, record the method's call site, including but not limited to the call location of each matching method, including file name, line number and other information.

[0069] After completing the query of the parent class method call point of the current class, continue to recursively query the parent class of the parent class until the root class is reached or there are no more parent classes.

[0070] Through the above steps, all call points of a specific method and its parent class methods can be comprehensively identified and recorded based on the recursive query mechanism, thereby ensuring accurate identification of dynamically bound method calls.

[0071] Step S20, identifying and analyzing the call points of the subclass method related to the call points of the parent class method;

[0072] It should be noted that in object-oriented programming, a subclass is a class that inherits from a parent class. A subclass can override (override) methods in the parent class, or add new methods and properties. The call point of a subclass refers to the location in the code where the subclass method is actually called. These call points can be direct calls or indirect calls through polymorphism.

[0073] It is worth noting that due to the polymorphic characteristics of object-oriented languages, this embodiment needs to filter the call points of the parent class method and only retain the call points referenced by the subclass methods related to the method.

[0074] Optionally, “identifying and analyzing the call points of the subclass method related to the call points of the parent class method” includes steps S21 to S23:

[0075] Step S21, filtering the call points of the parent class method to obtain the call points of the child class method related to the call points of the parent class method;

[0076] Specifically, from the call point set of all parent class methods obtained in step S10, all subclasses inherited from the parent class are queried, and the names of these subclasses are recorded. Specifically, for each call point of the parent class method, the actual type of the object that actually calls the method is checked. If the actual type of the object is a subclass, the call point is marked as a call point of the relevant subclass method.

[0077] Subsequently, the call sites marked as subclass method call sites are collected into a new set, which is the subclass method call sites associated with the parent class method call sites.

[0078] Through the above steps, the calling points of the subclass methods that are actually called are filtered out from all the identified parent class method calling points.

[0079] Step S22, analyzing the call point of the subclass method to determine the object type in the assignment statement and initialization statement of the subclass method;

[0080] It should be noted that the assignment statement is used to assign a new value to a declared variable. The initialization statement is used to assign an initial value when declaring a variable. The object type refers to the type of the object actually represented in memory. Even if the variable is declared as a parent class type, the actual object referenced may be a child class type.

[0081] Specifically, in the subclass method call point set obtained in step S21, according to the call point of each subclass method, the context in which it is located is searched, especially the assignment statement and the initialization statement. Then, the assignment statement and the initialization statement are analyzed to determine the actual type of the object assigned to the variable. Among them, analyzing the assignment statement involves parsing the constructor call on the right side of the assignment statement to determine the specific type of the created object. Analyzing the initialization statement includes parsing the constructor call on the right side of the statement to clarify the specific type of the created object; while analyzing the initialization statement involves understanding the type information specified in the object initialization process.

[0082] And record the actual type of the object in each assignment statement and initialization statement for subsequent analysis and verification.

[0083] Through the above steps, the calling sites of the subclass methods are analyzed to determine the actual types of objects involved in these calling sites.

[0084] Step S23, based on the object, identifying and verifying the indirect call point of the subclass method to confirm the validity of the indirect call point of the subclass method.

[0085] Specifically, the actual type of the object recorded in step S22 is used to further analyze the call points of the subclass method. This includes determining the call points of the method called through polymorphism. For example, if a variable is declared as a parent class type, but the subclass object is actually referenced, then the method call to the variable is an indirect call. Subsequently, it is verified whether these indirect call points actually point to the subclass method, and whether the subclass overrides the parent class method, and the method implementation of the subclass is actually called.

[0086] If the above conditions are met, it means that these indirect call points are valid indirect call points, and the indirect call points verified as valid are recorded as the final results.

[0087] Through the above steps, based on the actual type of the object, the indirect call sites of the subclass method are identified and verified to ensure that these call sites are indeed valid.

[0088] Step S30, combining the calling point of the subclass method with the direct calling point of the initial query to obtain complete calling information.

[0089] Finally, the valid indirect call points obtained after dynamic binding analysis are merged with the direct call points of the initial query, thereby obtaining comprehensive call information of a specific method of the preset format code, including but not limited to direct call points and indirect call points through dynamic binding. This method improves the accuracy of static analysis and makes the analysis results closer to the actual operation of the code.

[0090] In the above-mentioned embodiment method, by extracting the parent class method corresponding to the code in a preset format and recursively querying the call point of the parent class method, the recursive query mechanism can flexibly cope with this complexity and ensure that all relevant dynamic binding calls are accurately captured; identify and analyze the call points of the subclass methods related to the call points of the parent class method, and effectively reduce the false positives and missed negatives that may occur when identifying dynamic binding calls by introducing call point filtering and data flow analysis technology; combine the call points of the subclass method with the direct call points of the initial query to obtain complete call information, and through in-depth analysis of polymorphism and inheritance mechanisms in object-oriented programming, significantly improve the recognition accuracy of dynamic binding method calls.

[0091] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can be referred to the above introduction, and will not be repeated in the following. Figure 2 , step S23 specifically includes steps S231 to S233:

[0092] Step S231, based on the object type, confirm the indirect call point of the subclass method;

[0093] Step S232, verifying whether the indirect call point of the subclass method points to a specific method overridden or implemented by the subclass method;

[0094] Step S233: If yes, the indirect call point of the subclass method is used as the effective indirect action point of the subclass method.

[0095] Specifically, for each subclass method call site, find its context, especially the assignment statement and initialization statement.

[0096] Then, analyze the assignment statements and initialization statements to determine the actual type of the object assigned to the variable. Specifically, find all the assignment statements and initialization statements in the preset format code. Among them, the assignment statement is usually in the form of "AnimalmyDog; myDog = new Dog();"; the initialization statement is usually in the form of "Animal myDog = new Dog();". Subsequently, analyze the left and right parts of the assignment statement. The left part is a variable declaration, such as myDog, which indicates the name of the variable and its declared type (Animal). If the right side is an expression in the form of "new ClassName();", such as "newClassName();", the type of ClassName can be directly determined, that is, Dog. Similarly, the left side of the initialization statement is a variable declaration, such as Animal myDog. This indicates the name of the variable myDog and its declared type Animal. If the right side is an expression in the form of "new SubType();", such as "new Dog();", the type of SubType can be directly determined, that is, Dog. If the right side of an assignment or initialization statement is another variable or expression, the type of that variable or expression is recursively analyzed until the final object type can be determined. Finally, the actual type of the variable is recorded, even if the variable is declared as a superclass type.

[0097] Next, based on the actual type of the object, the call point for indirectly calling the subclass method through the polymorphic mechanism is confirmed. The polymorphic mechanism refers to the fact that in object-oriented programming, the subclass object can be assigned to the variable of the parent class type, and the subclass method can be called through the variable of the parent class type.

[0098] Then, for each indirect call site, check whether the corresponding subclass method overrides the parent class method. Among them, if there is a method in the subclass with the same name as the parent class and the parameter list (including parameter type, number and order) is exactly the same, then the subclass method is likely to be overridden. At the same time, in some languages, there are specific syntax or tags to explicitly indicate that the subclass method is overridden. For example, in Java, the @Override annotation can be used to explicitly indicate that a subclass method overrides the parent class method. And through static analysis to verify the actual method called by the method, it is confirmed whether the call site actually calls the overridden or implemented specific method of the subclass method.

[0099] If the indirect call site meets the above conditions, the indirect call site verified as valid will be recorded as a valid indirect action point of the subclass method.

[0100] Through the above-mentioned embodiment method, by checking the assignment or initialization operation of the parent class reference, the matching of its return value type and the method subclass type is verified, thereby reducing the possibility of false positives and false negatives to a certain extent.

[0101] For example, in order to help understand the implementation process of the code dynamic binding analysis method obtained by combining this embodiment with the above-mentioned embodiment 1, please refer to Figure 3 , Figure 3 A brief flowchart of a code dynamic binding analysis method is provided, specifically:

[0102] like Figure 3 As shown, Figure 3 It shows how subclass methods override parent class methods and call them through references to the parent class type, and then understands how static code analysis tries to identify the dynamic binding process behind these calls.

[0103] First, during the static code analysis, we first search for the makeSound method in the Dog class. Since direct calls to the Dog.makeSound() method are not provided in the code sample provided, the number of direct calls we can identify is 0 at this step.

[0104] Next, analyze the declaration of the Dog class and its inheritance relationship. During the analysis, you will find that the Dog class inherits from the Animal class, which means that the Dog class may have overridden the makeSound method defined in the Animal class. Therefore, during the analysis, you also need to pay attention to the makeSound method in the Animal class and how it is used in the code.

[0105] Then, search for all calls to the Animal.makeSound() method in the code. Suppose there are two calls, one through the Animal type variables myCat and myDog. On the surface, these two calls appear to be calls to the methods of the Animal class, but in fact, due to Java's dynamic binding mechanism, the method actually called will depend on the actual type of the runtime object.

[0106] In order to accurately identify which calls are actually to the makeSound method of the Dog class, this embodiment also needs to perform data flow analysis. The initialization statements of the two references myCat and myDog are analyzed to determine the object types they each reference. In this process, in the assignment statement of myDog, the right-hand expression (or its type deduction) indicates that it points to an object of type Dog.

[0107] Based on the analysis of the above steps, it is confirmed that the call to myDog.makeSound() will be resolved to the makeSound method of the Dog class at runtime, because myDog refers to an object of type Dog, and the Dog class overrides the makeSound method of the Animal class. Therefore, it can be confirmed that myDog.makeSound() is a valid indirect call to Dog.makeSound().

[0108] Through the above analysis process, the actual calling of a specific method (such as Dog.makeSound()) can be more accurately identified during the static code analysis phase, even in the face of the complexity of dynamic binding.

[0109] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the code dynamic binding analysis method of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.

[0110] This application also provides a code dynamic binding analysis device, please refer to Figure 4 , the code dynamic binding analysis device comprises:

[0111] A query module 10 is used to extract the parent class method corresponding to the code in a preset format, and recursively query the calling point of the parent class method;

[0112] An analysis module 20, for identifying and analyzing the call points of the subclass method related to the call points of the parent class method;

[0113] The acquisition module 30 is used to combine the call point of the subclass method with the direct call point of the initial query to acquire complete call information.

[0114] The code dynamic binding analysis device provided by the present application adopts the code dynamic binding analysis method in the above embodiment, which can solve the technical problem of how to improve the accuracy of identifying object-oriented dynamic binding calls. Compared with the prior art, the beneficial effects of the code dynamic binding analysis device provided by the present application are the same as the beneficial effects of the code dynamic binding analysis method provided by the above embodiment, and other technical features in the code dynamic binding analysis device are the same as the features disclosed in the above embodiment method, which will not be repeated here.

[0115] The present application provides a code dynamic binding analysis device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the code dynamic binding analysis method in the above-mentioned embodiment 1.

[0116] Reference below Figure 5 , which shows a schematic diagram of the structure of a code dynamic binding analysis device suitable for implementing the embodiment of the present application. The code dynamic binding analysis device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 5 The code dynamic binding analysis device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0117] like Figure 5 As shown, the code dynamic binding analysis device may include a processing device 1001 (such as a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the code dynamic binding analysis device are also stored. The processing device 1001, ROM1002 and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the code dynamic binding analysis device to communicate with other devices wirelessly or by wire to exchange data. Although the code dynamic binding analysis device with various systems is shown in the figure, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or provided instead.

[0118] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.

[0119] The code dynamic binding analysis device provided by the present application adopts the code dynamic binding analysis method in the above embodiment, which can solve the technical problem of how to improve the accuracy of identifying object-oriented dynamic binding calls. Compared with the prior art, the beneficial effects of the code dynamic binding analysis device provided by the present application are the same as the beneficial effects of the code dynamic binding analysis method provided by the above embodiment, and other technical features in the code dynamic binding analysis device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.

[0120] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.

[0121] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

[0122] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, wherein the computer-readable program instructions are used to execute the code dynamic binding analysis method in the above-mentioned embodiment.

[0123] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM: Random Access Memory), a read-only memory (ROM: Read Only Memory), an erasable programmable read-only memory (EPROM: Erasable Programmable Read Only Memory or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM: CD-Read Only Memory), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency: Radio Frequency), etc., or any suitable combination of the above.

[0124] The computer-readable storage medium may be included in the code dynamic binding analysis device; or may exist independently without being assembled into the code dynamic binding analysis device.

[0125] The above-mentioned computer-readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed by the code dynamic binding analysis device, the code dynamic binding analysis device: extracts the parent class method corresponding to the code in a preset format, and recursively queries the call points of the parent class method; identifies and analyzes the call points of the child class method related to the call points of the parent class method; combines the call points of the child class method with the direct call points of the initial query to obtain complete call information.

[0126] Computer program code for performing the operations of the present application may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0127] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0128] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.

[0129] The readable storage medium provided in the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned code dynamic binding analysis method, and can solve the technical problems of code dynamic binding analysis. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in the present application are the same as the beneficial effects of the code dynamic binding analysis method provided in the above-mentioned embodiment, and will not be elaborated here.

[0130] The present application also provides a computer program product, including a computer program, which implements the steps of the above-mentioned code dynamic binding analysis method when executed by a processor.

[0131] The computer program product provided by the present application can solve the technical problem of how to improve the accuracy of identifying object-oriented dynamic binding calls. Compared with the prior art, the beneficial effects of the computer program product provided by the present application are the same as the beneficial effects of the code dynamic binding analysis method provided by the above embodiment, which will not be repeated here.

[0132] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.

Claims

1. A code dynamic binding analysis method, characterized in that: The method comprises: Extract the parent class method corresponding to the code in a preset format, and recursively query the calling point of the parent class method; Identifying and analyzing the call points of the subclass method related to the call points of the parent class method, including: filtering the call points of the parent class method to obtain the call points of the subclass method related to the call points of the parent class method; Analyze the call point of the subclass method to determine the object type in the assignment statement and initialization statement of the subclass method; Based on the object type, identifying and verifying the indirect call site of the subclass method to confirm the validity of the indirect call site of the subclass method; The step of identifying and verifying the indirect call point of the subclass method based on the object type to confirm the validity of the indirect call point of the subclass method includes: Based on the object type, identifying indirect call sites of subclass methods; Verify whether the indirect call point of the subclass method points to a specific method overridden or implemented by the subclass method; If yes, then the indirect call point of the subclass method is used as the effective indirect action point of the subclass method; The call point of the subclass method is combined with the direct call point of the initial query to obtain complete call information.

2. The method according to claim 1, characterized in that Before the step of extracting the parent class method corresponding to the code in the preset format and recursively querying the calling point of the parent class method, the method includes: Identify source code through the scanning engine and start the corresponding parser or compiler; The source code is converted into a code in a preset format by the parser or the compiler.

3. The method according to claim 1, characterized in that Before the step of extracting the parent class method corresponding to the code in the preset format and recursively querying the calling point of the parent class method, the method further includes: Query the direct call location of the code in the preset format to obtain the direct call point of the initial query.

4. The method according to claim 1, characterized in that The step of extracting the parent class method corresponding to the code in the preset format and recursively querying the calling point of the parent class method includes: Analyze the declaration of the class where the specific method is located in the code language of the preset format to identify the interface information corresponding to the specific method; Based on the interface information, the parent class method that matches the specific method is recursively queried, and the calling point of the parent class method is obtained.

5. The method according to any one of claims 3 to 4, characterized in that The step of combining the call point of the subclass method with the direct call point of the initial query to obtain complete call information includes: The effective indirect action points of the subclass method are merged with the direct call points of the initial query to form complete call information.

6. A code dynamic binding analysis device, characterized in that: The device comprises: A query module, used to extract the parent class method corresponding to the code in a preset format, and recursively query the call point of the parent class method; An analysis module is used to identify and analyze the call points of the subclass method related to the call points of the parent class method, including: filtering the call points of the parent class method to obtain the call points of the subclass method related to the call points of the parent class method; Analyze the call point of the subclass method to determine the object type in the assignment statement and initialization statement of the subclass method; Based on the object type, identifying and verifying the indirect call site of the subclass method to confirm the validity of the indirect call site of the subclass method; The step of identifying and verifying the indirect call point of the subclass method based on the object type to confirm the validity of the indirect call point of the subclass method includes: Based on the object type, identifying indirect call sites of subclass methods; Verify whether the indirect call point of the subclass method points to a specific method overridden or implemented by the subclass method; If yes, then the indirect call point of the subclass method is used as the effective indirect action point of the subclass method; The acquisition module is used to combine the call point of the subclass method with the direct call point of the initial query to obtain complete call information.

7. A code dynamic binding analysis device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the code dynamic binding analysis method according to any one of claims 1 to 5.

8. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the code dynamic binding analysis method according to any one of claims 1 to 5 are implemented.

Citation Information

Patent Citations

  • Method, device and equipment for quickly identifying components of project open source component and medium

    CN118377466A