Automatic identification method and system for software development kit (SDK) application program interface (API) of Internet of Things equipment
By building the function call graph and heuristic rules identification API of the SDK of the IoT device SDK, the problem of inefficient development caused by the complexity of the SDK is solved, and an automated recognition and recommendation system is provided to help developers quickly understand the device functions and APIs, improving development efficiency and accuracy.
Patent Information
- Application Number
- CN202410914820.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-09
- Publication Date
- 2024-11-12
AI Technical Summary
The complexity and incomplete documentation of IoT device SDKs make developers inefficient in device integration and testing, making it difficult to identify and use device control and status query APIs, increasing development difficulty and error risk.
By building a function call graph of the SDK of the IoT device, identifying network protocol methods, and identifying candidate APIs from the call path based on heuristic rules, providing an automated identification and recommendation system to help developers understand device functions and API usage.
It significantly improves the efficiency of developers understanding device functions and APIs without in-depth analysis of the SDK, reduces learning costs and development time, and accelerates the implementation and deployment of IoT projects.
Smart Images

Figure CN118939530A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to an automatic identification method and system of an Internet of Things device SDK API, belonging to the technical field of computer software. Background Art
[0002] In recent years, the field of Internet of Things (IoT) has achieved remarkable development, promoting widespread applications in various industries and bringing greater convenience, more choices and personalized services to end users. The emergence of open source IoT platforms has further accelerated this trend, enabling DIY enthusiasts to integrate and customize various IoT devices. In the IoT ecosystem, IoT device software development kits (SDKs) play a vital role. As a key component, device SDKs simplify the communication and interaction between devices and cloud services, mobile applications and other devices, helping developers to build and integrate IoT device applications more easily. Device SDKs are not only crucial for device integration in IoT platforms, but also provide necessary support when testing device firmware because they are able to interact directly with physical devices. However, for many DIY enthusiasts, understanding and using device SDKs is not an easy task. The complexity of the SDK and the incomplete and imperfect documentation make the development of device integration quite difficult.
[0003] The complexity of SDKs poses many challenges to developers when integrating and testing devices. In order to successfully integrate devices into the IoT platform, developers must manually identify the required device control and status query APIs, which is not only time-consuming but also error-prone. SDKs usually contain a large number of files, each of which may involve hundreds of different functions. In this case, finding the key device control and status query APIs from the numerous functions is like finding a needle in a haystack. In addition, the documentation of device SDKs is often incomplete, outdated, and inconsistent with the code. These documentation defects further increase the difficulty for developers to understand the SDK, making it difficult to effectively utilize device functions. These problems not only hinder development efficiency, but also increase the risk of errors in the development process, significantly increasing the complexity and difficulty of IoT device integration.
[0004] At present, the identification and recommendation of SDK APIs has attracted the attention of the academic community and has achieved some results. Existing work mainly identifies and recommends SDK APIs from the perspective of real-time recommendation, that is, recommending APIs that developers may need to use during the user development process. For example, PyART (He X, Xu L, Zhang X, et al. Pyart: Python API recommendation in real-time. ICSE 2021) is a real-time API recommendation system specifically for Python programs. It uses lightweight analysis to derive optimistic data flows to simulate local data flow information that can be manually derived, and extracts three features: data flow, token similarity, and token co-occurrence, and uses a random forest algorithm to train a prediction model. This method can recommend suitable APIs in real time during the development process, thereby improving development efficiency. MULAPI (Xu C, Sun X, Li B, et al. MULAPI: Improving API method recommendation with API usage location. Journal of Systems and Software 2018) recommends APIs and their usage locations based on historical requests and description similarity. MULAPI considers the target source code, historical function request library and API library, adopts feature location technology to identify API usage locations, locates files related to features, and uses components based on API usage locations, components based on historical requests and components based on description similarity to make API recommendations.
[0005] These API identification and recommendation methods mainly focus on code completion, that is, suggesting API usage to developers during the development process, thereby improving development efficiency and code quality. However, they lack a holistic analysis of the SDK and are difficult to help developers fully understand the capabilities of IoT devices. Therefore, designing an automated method to help developers analyze device SDKs and identify device control and status query APIs is of great value and significance. Summary of the invention
[0006] The present invention aims to solve the problem of low efficiency when developers use device SDK for device integration and testing, and proposes an automatic identification method and system for IoT device SDK API, so that developers can understand device functions and use related APIs more quickly.
[0007] The technical solution adopted by the present invention is as follows:
[0008] An automatic identification method for an IoT device SDK API, the method comprising:
[0009] Constructing a function call graph of an IoT device SDK, wherein the function call graph includes: explicit call relationships between functions and implicit call relationships generated by data dependencies;
[0010] Identify the network protocol method used in the IoT device SDK, and extract all call paths leading to the network protocol method in the function call graph;
[0011] Candidate IoT device SDK APIs are identified from the extracted call paths based on heuristic rules.
[0012] Furthermore, the construction of the call graph of the IoT device SDK includes:
[0013] Get the source code of the IoT device SDK;
[0014] Constructing an abstract syntax tree of the source code, and extracting explicit calling relationships between functions by parsing the abstract syntax tree;
[0015] Converting the source code into an intermediate representation, wherein the intermediate representation is composed of identifier definitions, the identifier definitions including: an identifier type and a namespace composed of identifier names, the identifier type including modules, classes, functions, and variables;
[0016] Analyze the source code, and construct an identifier assignment graph in combination with the intermediate representation, wherein the identifier assignment graph is used to record the assignment and pointing relationship between identifiers in the source code;
[0017] Extracting implicit call relationships generated by data dependency based on the identifier assignment graph;
[0018] The function call graph of the IoT device SDK is constructed by taking the functions in the IoT device SDK as nodes of the call graph and combining the explicit call relationship between functions and the implicit call relationship generated by data dependency.
[0019] Further, analyzing the source code and constructing an identifier assignment graph in combination with the intermediate representation includes:
[0020] Add the pointing relationship of the identifier implied in the assignment statement to the identifier assignment graph;
[0021] and,
[0022] For the assignment statement of the variable attribute, the identifier definition of the variable attribute and the identifier definition of the identifier are taken as nodes in the identifier assignment graph, and an edge from the identifier definition of the variable attribute to the identifier definition of the identifier is added;
[0023] and,
[0024] For the assignment statement of type annotation, the identifier definition of the identifier and the identifier definition of the annotation type are taken as nodes in the identifier assignment graph, and an edge is added from the identifier definition of the identifier to the identifier definition of the annotation type;
[0025] and,
[0026] For the assignment statement of the function call, the identifier definition of the identifier and the identifier definition of the function call are taken as nodes in the identifier assignment graph, and an edge is added from the identifier definition of the identifier to the identifier definition of the function call;
[0027] and,
[0028] For the creation statement of the class instance, the identifier definition of the identifier and the identifier definition of the function call are taken as nodes in the identifier assignment graph, and an edge is added from the identifier definition of the identifier to the identifier definition of the function call;
[0029] and,
[0030] For the return value statement of the function, the identifier definition of the virtual identifier and the identifier definition of the return value identifier are taken as nodes in the identifier assignment graph, and an edge is added from the identifier definition of the virtual identifier to the identifier definition of the return value identifier;
[0031] and,
[0032] When a function is called, if the formal parameter is assigned a value by an actual parameter, the identifier definition of the formal parameter and the identifier definition of the actual parameter are used as nodes in the identifier assignment graph, and an edge is added from the identifier definition of the formal parameter to the identifier definition of the actual parameter.
[0033] and,
[0034] For the import statement, the identifier definition of the current module and the identifier definition of the module to be imported are taken as nodes in the identifier assignment graph, and an edge is added from the identifier definition of the current module to the identifier definition of the module to be imported;
[0035] and,
[0036] For a for statement, the identifier definition of the current iteration element and the identifier definition of the iterable object are taken as nodes in the identifier assignment graph, and an edge is added from the identifier definition of the current iteration element to the identifier definition of the iterable object.
[0037] Furthermore, the implicit calling relationship generated by data dependency is extracted according to the identifier assignment graph, including:
[0038] For any two different identifier definition nodes d1 and identifier definition nodes d2 in the identifier assignment graph, verify whether the identifier definition node d1 and the identifier definition node d2 are both identifier definitions of return value types;
[0039] In the case where both the identifier definition node d1 and the identifier definition node d2 are identifier definitions of return value types, it is determined whether there is a pointing relationship path from the identifier definition node d1 to the identifier definition node d2;
[0040] In the case where there is a pointing relationship path from the identifier definition node d1 to the identifier definition node d2, an implicit calling relationship from the function corresponding to the identifier definition node d1 to the function corresponding to the identifier definition node d2 is obtained.
[0041] Further, the method for identifying the network protocol used in the IoT device SDK includes:
[0042] Collect and analyze Python network protocol libraries, and obtain network protocol methods in each Python network protocol library;
[0043] The network protocol method is matched with the function nodes in the function call graph to obtain the network protocol method used in the IoT device SDK.
[0044] Furthermore, all calling paths leading to the network protocol method are extracted from the function call graph, including:
[0045] Performing backtracking based on the function nodes corresponding to the network protocol method;
[0046] Extract all call paths CP that reach the function node corresponding to the network protocol method<fs,···,fp> ; Wherein, CP is a function call relationship path including at least two functions, fs is a source node, fp is an end node and the end node fp is a function node corresponding to the network protocol method.
[0047] Furthermore, the heuristic rules include:
[0048] The source node function corresponding to the source node fs is selected as a candidate IoT device SDK API;
[0049] and,
[0050] When the source node function corresponding to the source node fs calls one of the subsequent n functions to form n different calling paths, and the n different calling paths converge to a subsequent node of the n functions, the n functions are used as candidate IoT device SDK APIs.
[0051] An automatic identification system for an IoT device SDK API, the system comprising:
[0052] A graph construction module is used to construct a function call graph of the IoT device SDK, wherein the function call graph includes: explicit call relationships between functions and implicit call relationships generated by data dependencies;
[0053] A path extraction module, used to identify the network protocol method used in the IoT device SDK, and extract all call paths leading to the network protocol method in the function call graph;
[0054] The API identification module is used to identify candidate IoT device SDK APIs from the extracted call paths based on heuristic rules.
[0055] An electronic device, characterized in that the electronic device comprises: a processor and a memory storing computer program instructions; when the processor executes the computer program instructions, the automatic identification method of the IoT device SDK API described in any one of the above items is implemented.
[0056] A computer-readable storage medium, characterized in that computer program instructions are stored on the computer-readable storage medium, and when the computer program instructions are executed by a processor, the automatic identification method of the IoT device SDKAPI described in any one of the above is implemented.
[0057] Compared with the prior art, the present invention can help IoT developers easily understand the functions of IoT devices and the device SDK APIs that need to be called during the development process without in-depth analysis of the device SDK. Through the present invention, IoT developers can more efficiently explore device functions and develop applications, greatly reducing the learning cost and development time caused by the complexity of the SDK, thereby accelerating the implementation and deployment of IoT projects. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] Figure 1 The figure is an example diagram of the overall process of the invention method.
[0059] Figure 2 Rules for constructing the identifier assignment graph IAG.
[0060] Figure 3 SDK source code example for the MyStromBulb device.
[0061] Figure 4 This is an example diagram of the identifier assignment diagram IAG.
[0062] Figure 5 This is a partial function call graph of the SDK for the Miio-Yeelight device.
[0063] Figure 6 This is a partial function call graph of the SDK for the MyStromBulb device. DETAILED DESCRIPTION
[0064] In order to make the purpose, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below through specific embodiments and drawings.
[0065] The overall process of the method of the present invention is as follows Figure 1 As shown. The present invention generates a data flow enhanced function call graph DECG for the device SDK through static program analysis to capture the explicit and implicit calling relationships between functions. Subsequently, based on the pre-collected domain knowledge of common network protocol libraries, the network protocol methods used in the SDK are identified, and the calling paths to these methods are extracted from the function call graph. Finally, according to the position of the API in the calling path, potential device SDK APIs are identified and recommendations are provided to developers.
[0066] 1. Dataflow-enhanced function call graph generation.
[0067] The present invention constructs a data flow enhanced function call graph (DECG) based on the source code by statically analyzing the source code of the SDK of the Internet of Things device. The call graph includes explicit call relationships between functions and implicit call relationships generated by data dependency.
[0068] Specifically, the present invention first parses the source code of the device SDK, converts it into a series of intermediate representations (IR), and constructs an identifier assignment graph (IAG) according to a series of rules to record the assignment and pointing relationship between identifiers in the program. Next, the explicit calling relationship between functions is identified by parsing the source code, and the implicit calling relationship between functions is identified by analyzing the data dependency in the identifier assignment graph IAG. Finally, the function call graph DECG is generated by combining the explicit and implicit calling relationships. Among them, the intermediate representation (IR) is composed of a series of identifier definitions (Definition), each identifier definition is composed of two parts: identifier type and namespace. The identifier type includes module (Module), class (Class), function (Function) and variable (Variable), and the namespace is generated by splicing and combining the identifier names.
[0069] In one embodiment, the identifier assignment graph is defined as IAG=<Vi,Ei> , where: Vi represents the identifier definitions (Definition) of the intermediate representation IR, which serve as the nodes of IAG; Ei represents the set of assignment and pointing relationships between identifier definitions Definition, which serve as the edges of IAG.
[0070] In one embodiment, the present invention constructs IAG by analyzing the source code of SDK. Figure 2 The construction rules of IAG are shown. The meaning of each rule is as follows:
[0071] Rule 1 [Assign] adds the pointing relationship of the identifiers implied in the assignment statement to IAG. For example, for the assignment statement y=x, first create the identifier definitions Definition(y) and Definition(x) corresponding to the identifiers y and x, then add them to the identifier assignment graph IAG as nodes of IAG, and finally add a directed edge from Definition(y) to Definition(x) in IAG to indicate the pointing relationship between y and x;
[0072] Rule 2 [Attr_Assign] processes variable attribute assignment statements. For the assignment statement y.attr = x, the identifier definitions Definition(y.attr) and Definition(x) are created and used as nodes of the IAG, and then a directed edge from Definition(y.attr) to Definition(x) is added;
[0073] Rule 3 [Ann_Assign] processes assignment statements involving type annotations and adds the pointing relationship from the identifier to the annotation type to the IAG. For the assignment statement y = x:z, the identifier definitions Definition(y), Definition(x), and Definition(z) are created and used as nodes of the IAG, and then directed edges from Definition(y) to Definition(x) and from Definition(z) to Definition(z) are added;
[0074] Rule 4 [Call_Assign] handles assignment statements involving function calls. For an assignment statement y = x(…), the identifier definitions Definition(y) and Definition(x. <ret>) as a node of IAG, and then add Definition(y) pointing to Definition(x. <ret>), where <ret>A virtual identifier for the function's return value;
[0075] Rule 5 [New] processes the creation statement of a class instance. For the creation statement y = new x (…) of a class instance, the identifier definitions Definition(y) and Definition(x) are created and used as nodes of the IAG, and then a directed edge from Definition(y) to Definition(x) is added;
[0076] Rule 6 [Return] in function return value identifiers and virtual identifiers <ret>Add a pointing relationship between them. For the return value statement return x of function y(), an identifier definition Definition(y. <ret>) and Definition(x) as nodes of IAG, and then add Definition(y. <ret>) is a directed edge pointing to Definition(x);
[0077] Rule 7 [Call_Args] adds a pointing relationship between actual parameters and formal parameters in function calls. For function z() and its formal parameter y, when function z() is called, if y is assigned a value by actual parameter x, identifier definitions Definition(y) and Definition(x) are created and used as nodes of IAG, and then a directed edge from Definition(y) to Definition(x) is added;
[0078] Rule 8 [Import] is responsible for processing the identifier pointing relationship in the import statement. If the current module is m1, and the statement is from m2 import x, the identifier definitions Definition(m1.x) and Definition(m2.x) will be created and used as nodes of the IAG, and then a directed edge from Definition(m1.x) to Definition(m2.x) will be added;
[0079] Rule 9 [For] is responsible for processing the identifier pointing relationship in the for statement. For the statement for x in y, the identifier definitions Definition(x) and Definition(y) are created and used as nodes of the IAG, and then a directed edge from Definition(x) to Definition(y) is added.
[0080] Figure 3 The SDK code snippet of the device MyStromBulb is used as an embodiment of the present invention to construct the identifier assignment graph IAG, and finally the following can be generated: Figure 4 Specifically, the SDK code is analyzed line by line. In the mode() function, the return value of the mode() function depends on the instance attribute self._mode (lines 2-4). Then according to rule 6 [Return], the identifier definition nodes self._mode and mode. in the IAG are constructed. <ret>, and add mode at the same time. <ret>To self._mode. Continuing to analyze the code, in the get_state() function, the variable response is assigned the return value of the request() function (line 8). Then according to rule 4 [Call_Assign], the identifier definition nodes response and request in the IAG will be constructed. <ret>, and add response to request. <ret>Finally, the instance attribute self._mode is assigned to the variable response (line 9). According to rule 2 [Attr_Assign], the IAG will add a pointing relationship from self._mode to response. Therefore, according to this SDK code, an IAG with four nodes and three edges can be generated.
[0081] After parsing the SDK source code, generating IR, and building IAG, continue to identify explicit and implicit call relationships. Conventional call relationships are called explicit calls, which can be directly extracted by parsing the abstract syntax tree of the source code. For example, in Figure 3 In the code, the get_state() function explicitly calls the request() function (line 8). Unlike explicit calls, implicit calls mean that the caller does not directly call the callee, but the return value of the caller depends on the return value of the callee. This implicit call usually originates from data processing and conversion, that is, the data interaction and processing between the potential SDK API and the underlying network protocol method.
[0082] The present invention designs an algorithm for identifying implicit calling relationships of functions by analyzing data dependencies. The algorithm takes an identifier assignment graph IAG as input and outputs an implicit calling relationship set IC. For any two different identifier definition nodes d1 and d2 in IAG, the algorithm first verifies whether d1 and d2 are both identifier definitions of return value types. If so, the algorithm will continue to determine whether there is a pointing relationship path from d1 to d2. After confirming that the path exists, the algorithm will add the implicit calling relationship from the function corresponding to d1 to the function corresponding to d2 to IC. Finally, all implicit calling relationships are identified.
[0083] by Figure 4 The execution flow of the algorithm is explained in the corresponding embodiment. Figure 4 The identifier assignment graph IAG contains mode. <ret>, self._mode, response and request. <ret>There are 4 identifiers defined. First, the algorithm verifies the mode. <ret>and request. <ret>These are all identifiers of the return value type. Next, the algorithm determines the mode. <ret>and request. <ret>There is a pointing relationship path between them, namely (mode. <ret>,self._mode,response,request. <ret>). Thus, the algorithm identifies the mode. <ret>The corresponding mode() function is the same as request. <ret>The implicit calling relationship between the corresponding request() functions is added to the IC.
[0084] After identifying all explicit calls and implicit calls, the present invention synthesizes a complete function call graph DECG according to these call relationships.
[0085] 2. Extraction of call path.
[0086] The present invention identifies the network protocol library and network protocol method used by the device SDK by matching with the common network protocol library, and then performs a slicing operation centered on the network protocol method on the data flow enhanced function call graph DECG to extract all calling paths leading to these network protocol methods.
[0087] Specifically, the present invention performs slicing based on the network protocol method on the synthesized DECG, and extracts all call paths that can reach the network protocol method. Since most SDKs only import a single network protocol library, and the commonly used and popular network protocol libraries are limited and enumerable, the present invention pre-constructs the domain knowledge of Python network protocol libraries and methods, and summarizes the methods used by each network protocol library to establish connections and send and receive data. At present, the constructed domain knowledge covers 8 types of network protocols including TCP, HTTP, Bluetooth, Modbus, etc., and a total of 20 Python network protocol libraries, which are: socket, requests, aiohttp, asyncio, bleak, bluepy, serial, paho, aiocoap, httpx, urllib, websockets, requests_oauthlib, websocket, serial_asyncio, requests_toolbelt, socketio, nclib, pymodbus and http.
[0088] Given the function call graph DECG of the device SDK, the method of the present invention matches the network protocol methods in the domain knowledge with the nodes in the graph to identify the network protocol methods used in the SDK. Subsequently, the method of the present invention backtracks from these network protocol method nodes and extracts all call paths CP that can reach these network protocol methods.<fs,···,fp> . Among them, CP is a function call relationship path containing at least two functions; fs is a source node, usually the function in the source node fs will not be called by other functions in the SDK, and explicitly or implicitly calls the next function in the path; fp is the end node in CP, and it is a network protocol method.
[0089] exist Figure 5 In the SDK call graph of the corresponding device Miio-Yeelight, the present invention first matches the network protocol method used by the SDK as socket.socket(), then backtracks from the socket.socket() node, and finally finds three call paths, which are<Yeelight.set_brightness(),Device.send(),…,socket.socket()> ,<Yeelight.set_power(),Yeelight.on(),Device.send(),…,socket.socket()> and<Yeelight.set_power(),Yeelight.on(),Device.send(),…,socket.socket()> .
[0090] 3. Identification of SDK API.
[0091] The method of the present invention identifies candidate device control and status query APIs from the extracted call path. Since the call path may contain many functions, the present invention proposes two heuristic rules to select the correct function as the recommended API:
[0092] Rule 1: Most functional SDK APIs are usually not called by other functions, which indicates that they exist as source nodes in the call path. Figure 5 In the corresponding embodiment, the calling path<Yeelight.set_brightness(),Device.send(),…,socket.socket()> The first function Yeelight.set_brightness() in the code will be identified as a candidate API because it is not called by other functions.
[0093] Rule 2: The source node function can conditionally call one of n subsequent functions, forming n different calling paths; in addition, these n paths eventually converge to a certain subsequent node. In this case, these n functions are considered potential SDK APIs. The principle behind this is that these secondary functions perform more fine-grained functions of communicating with the device, while the source node function may be a higher-level encapsulation that can conditionally execute one of these functions. Figure 5 In the corresponding embodiment, the two calling paths including Yeelight.set_power() diverge at Yeelight.on() and Yeelight.off() and converge at Device.send(). The reason for this is that Yeelight.set_power() encapsulates two functions of turning the light on and off. It may execute one of the functions based on specific inputs and conditions. At this time, both Yeelight.on() and Yeelight.off() will be identified as candidate APIs.
[0094] Based on these two heuristic rules, the method of the present invention identifies all possible device APIs in the SDK and recommends them to the user. Figure 5 In the corresponding embodiment, four functions are identified as SDK APIs. According to Rule 1, Yeelight.set_power() and Yeelight.set_brightness() are identified because they are both source node functions. According to Rule 2, Yeelight.on() and Yeelight.off() are identified because the source node function Yeelight.set_power() is a functional encapsulation of them.
[0095] A specific embodiment of the complete process is provided below to illustrate the operation of the present invention.
[0096] Taking the SDK of the device MyStromBulb as an example, the present invention is used to identify and extract the device control and status query API in the SDK.
[0097] like Figure 6 As shown, the present invention first generates a data flow enhanced function call graph DECG of SDK MyStromBulb, and the DECG includes both explicit calls and implicit calls.
[0098] Next, by matching with the network protocol library domain knowledge, we found out that the network protocol library used by the SDK is aiohttp, and the network protocol function of the network is aiohttp.ClientSession.request(), thus extracting <bulb.MyStromBulb.set_white(),bulb.MyStromBulb.set_color_hsv(),__init__._request(),aiohttp.ClientSession.request()> And other calling paths.
[0099] According to the heuristic rules, we traced back the call library and finally identified and extracted a total of 15 device control and status query APIs, including 8 APIs that only have explicit calls in the call path, namely bulb.MyStromBulb.set_on(), bulb.MyStromBulb.get_state(), bulb.MyStromBulb.set_rainbow(), bulb.MyStromBulb.set_off(), bulb.MyStromBulb.set_flashing(), bulb.MyStromBulb.set_color_hex(), bulb.MyStromBulb.set_wh ite() and bulb.MyStromBulb.set_sunrise(); and 7 APIs that contain both explicit and implicit calls in the call path, namely bulb.MyStromBulb.transition_time(), bulb.MyStromBulb.state(), bulb.MyStromBulb.bulb_type(), bulb.MyStromBulb.consumption(), bulb.MyStromBulb.mode(), bulb.MyStromBulb.firmware(), and bulb.MyStromBulb.color().
[0100] The contents not described in detail in the technical solution of the present invention can be implemented by using the existing technology.
[0101] The above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit the same. A person skilled in the art may modify or make equivalent substitutions for the technical solutions of the present invention without departing from the principle and scope of the present invention. The protection scope of the present invention shall be subject to the claims.< / ret> < / ret> < / ret> < / ret> < / ret> < / ret> < / ret> < / ret> < / ret> < / ret> < / ret> < / ret> < / ret> < / ret> < / ret> < / ret> < / ret> < / ret> < / ret> < / ret>
Claims
1. An automated identification method for IoT device SDK API, characterized in that: The method comprises: Constructing a function call graph of an IoT device SDK, wherein the function call graph includes: explicit call relationships between functions and implicit call relationships generated by data dependencies; Identify the network protocol method used in the IoT device SDK, and extract all call paths leading to the network protocol method in the function call graph; Candidate IoT device SDK APIs are identified from the extracted call paths based on heuristic rules.
2. The method for automatically identifying the SDK API of an IoT device according to claim 1, characterized in that: The construction of the call graph of the IoT device SDK includes: Get the source code of the IoT device SDK; Constructing an abstract syntax tree of the source code, and extracting explicit calling relationships between functions by parsing the abstract syntax tree; Converting the source code into an intermediate representation, wherein the intermediate representation is composed of identifier definitions, the identifier definitions including: an identifier type and a namespace composed of identifier names, the identifier type including modules, classes, functions, and variables; Analyze the source code, and construct an identifier assignment graph in combination with the intermediate representation, wherein the identifier assignment graph is used to record the assignment and pointing relationship between identifiers in the source code; Extracting implicit call relationships generated by data dependency based on the identifier assignment graph; The function call graph of the IoT device SDK is constructed by taking the functions in the IoT device SDK as nodes of the call graph and combining the explicit call relationship between functions and the implicit call relationship generated by data dependency.
3. The method for automatically identifying the SDK API of an IoT device according to claim 2, characterized in that: Analyzing the source code and constructing an identifier assignment graph in combination with the intermediate representation, including: Add the pointing relationship of the identifier implied in the assignment statement to the identifier assignment graph; and, For the assignment statement of the variable attribute, the identifier definition of the variable attribute and the identifier definition of the identifier are taken as nodes in the identifier assignment graph, and an edge from the identifier definition of the variable attribute to the identifier definition of the identifier is added; and, For the assignment statement of type annotation, the identifier definition of the identifier and the identifier definition of the annotation type are taken as nodes in the identifier assignment graph, and an edge is added from the identifier definition of the identifier to the identifier definition of the annotation type; and, For the assignment statement of the function call, the identifier definition of the identifier and the identifier definition of the function call are taken as nodes in the identifier assignment graph, and an edge is added from the identifier definition of the identifier to the identifier definition of the function call; and, For the creation statement of the class instance, the identifier definition of the identifier and the identifier definition of the function call are taken as nodes in the identifier assignment graph, and an edge is added from the identifier definition of the identifier to the identifier definition of the function call; and, For the return value statement of the function, the identifier definition of the virtual identifier and the identifier definition of the return value identifier are taken as nodes in the identifier assignment graph, and an edge is added from the identifier definition of the virtual identifier to the identifier definition of the return value identifier; and, When a function is called, if the formal parameter is assigned a value by an actual parameter, the identifier definition of the formal parameter and the identifier definition of the actual parameter are used as nodes in the identifier assignment graph, and an edge is added from the identifier definition of the formal parameter to the identifier definition of the actual parameter. and, For the import statement, the identifier definition of the current module and the identifier definition of the module to be imported are taken as nodes in the identifier assignment graph, and an edge is added from the identifier definition of the current module to the identifier definition of the module to be imported; and, For a for statement, the identifier definition of the current iteration element and the identifier definition of the iterable object are taken as nodes in the identifier assignment graph, and an edge is added from the identifier definition of the current iteration element to the identifier definition of the iterable object.
4. The method for automatically identifying the SDK API of an IoT device according to claim 2, characterized in that: Extracting implicit call relationships caused by data dependency based on the identifier assignment graph includes: For any two different identifier definition nodes d1 and identifier definition nodes d2 in the identifier assignment graph, verify whether the identifier definition node d1 and the identifier definition node d2 are both identifier definitions of return value types; In the case where both the identifier definition node d1 and the identifier definition node d2 are identifier definitions of return value types, it is determined whether there is a pointing relationship path from the identifier definition node d1 to the identifier definition node d2; In the case where there is a pointing relationship path from the identifier definition node d1 to the identifier definition node d2, an implicit calling relationship from the function corresponding to the identifier definition node d1 to the function corresponding to the identifier definition node d2 is obtained.
5. The method for automatically identifying the SDK API of an IoT device according to claim 1, characterized in that: The method for identifying the network protocol used in the IoT device SDK includes: Collect and analyze Python network protocol libraries, and obtain network protocol methods in each Python network protocol library; The network protocol method is matched with the function nodes in the function call graph to obtain the network protocol method used in the IoT device SDK.
6. The method for automatically identifying the SDK API of an IoT device according to claim 5, characterized in that: All calling paths leading to the network protocol method are extracted from the function call graph, including: Performing backtracking based on the function nodes corresponding to the network protocol method; Extract all call paths CP that reach the function node corresponding to the network protocol method<fs,···,fp> ; Wherein, CP is a function call relationship path including at least two functions, fs is a source node, fp is an end node and the end node fp is a function node corresponding to the network protocol method.
7. The method for automatically identifying the SDK API of an IoT device according to claim 6, characterized in that: The heuristic rules include: The source node function corresponding to the source node fs is selected as a candidate IoT device SDK API; and, When the source node function corresponding to the source node fs calls one of the subsequent n functions to form n different calling paths, and the n different calling paths converge to a subsequent node of the n functions, the n functions are used as candidate IoT device SDK APIs.
8. An automated identification system for IoT device SDK API, characterized in that: The system comprises: A graph construction module is used to construct a function call graph of the IoT device SDK, wherein the function call graph includes: explicit call relationships between functions and implicit call relationships generated by data dependencies; A path extraction module, used to identify the network protocol method used in the IoT device SDK, and extract all call paths leading to the network protocol method in the function call graph; The API identification module is used to identify candidate IoT device SDK APIs from the extracted call paths based on heuristic rules.
9. An electronic device, characterized in that: The electronic device comprises: a processor and a memory storing computer program instructions; when the processor executes the computer program instructions, the automatic identification method of the IoT device SDK API as described in any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer program instructions, and when the computer program instructions are executed by the processor, the automatic identification method of the IoT device SDK API according to any one of claims 1 to 7 is implemented.
