API capture method, device, electronic device, storage medium and program product
By modifying the registry path to the dynamic link library file path of the bridge layer in OpenGL application, the problem of failure of dynamic link library file injection and hook interception in the existing technology is solved, and a stable and reliable API crawling method is realized, which improves the success rate of API call tracking data acquisition.
Patent Information
- Application Number
- CN202411836986.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-12
- Publication Date
- 2025-04-04
AI Technical Summary
In the debugging and optimization of OpenGL application, there is a risk of failure of dynamic link library file injection and failure of hook interception in the existing technology, resulting in the inability to effectively crawl API call tracking data and trigger a security detection mechanism.
By modifying the path of the target table entry in the registry to the path of the dynamic link library file of the bridge layer, inserting the bridge layer between the runtime layer and the user-state driver layer, grab the API information called by the target application to achieve the acquisition of API call tracking data.
It improves the probability of successfully crawling the API information called by the target application, avoids the risk of failure of dynamic link library file injection and hook interception, does not trigger the security detection mechanism of the target application, and realizes a more stable and reliable API crawling method.
Smart Images

Figure CN119759689A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to an API capture method, an API capture device, an electronic device, a computer-readable storage medium, and a computer program product. Background Art
[0002] With the rapid development of computer graphics technology, OpenGL (Open Graphics Library) has been widely used in the field of 3D graphics rendering and visualization as a cross-platform, cross-language graphics programming interface. In the development and debugging of OpenGL applications, it has become an important technical requirement to capture the API (Application Programming Interface) called by the OpenGL application, obtain API call trace data, and analyze the performance and behavior of the OpenGL application based on the API call trace data. Summary of the invention
[0003] The present invention provides an API crawling technology solution.
[0004] According to one aspect of the present disclosure, there is provided an API crawling method, comprising:
[0005] Modify the target path corresponding to the target table item in the registry to the path of the dynamic link library file of the bridge layer; wherein the target table item corresponds to the dynamic link library file of the user-mode driver; the dynamic link library file of the bridge layer is used to export a first function set and implement a second function set, wherein the first function set represents a set of functions exported by the user-mode driver, and the second function set represents a set of exported functions constituting an API;
[0006] Running a target application, wherein the target application corresponds to a path corresponding to the target table entry;
[0007] The information of the API called by the target application is captured through the dynamic link library file of the bridge layer to obtain the API call tracking data of the target application.
[0008] In a possible implementation, the capturing of information of the API called by the target application through the dynamic link library file of the bridge layer includes:
[0009] Calling the dynamic link library file at runtime through the target application;
[0010] In response to the target application calling the target API through the dynamic link library file at runtime, the dynamic link library file of the bridge layer intercepts the call and captures the information of the target API called by the target application.
[0011] In a possible implementation, in response to the target application calling the target API through the runtime dynamic link library file, intercepting the call through the dynamic link library file of the bridge layer, and capturing information of the target API called by the target application, includes:
[0012] In response to the target application calling the target API through the runtime dynamic link library file, the dynamic link library file of the bridge layer replaces the pointer to the target API with a pointer to a wrapper function, wherein the wrapper function is used to capture the information of the target API called by the target application.
[0013] In a possible implementation, after capturing the information of the target API called by the target application, the method further includes:
[0014] In response to the wrapper function completing the crawl, calling the target API through the wrapper function;
[0015] The return value of the target API is passed back to the target application.
[0016] In a possible implementation, after obtaining the API call tracking data of the target application, the method further includes:
[0017] In response to the completion of the capture of the API called by the target application, the path corresponding to the target entry in the registration table is restored to the target path.
[0018] In a possible implementation, the API call tracking data includes at least the following:
[0019] The name of the API called by the target application;
[0020] The time when the target application calls the API;
[0021] Parameter information of the API called by the target application.
[0022] In a possible implementation manner, the target application is an OpennGL application.
[0023] According to one aspect of the present disclosure, there is provided an API capture device, comprising:
[0024] A modification module, used to modify the target path corresponding to the target table item in the registry to the path of the dynamic link library file of the bridge layer; wherein the target table item corresponds to the dynamic link library file of the user-mode driver; the dynamic link library file of the bridge layer is used to export a first function set and implement a second function set, wherein the first function set represents a set of functions exported by the user-mode driver, and the second function set represents a set of exported functions constituting an API;
[0025] A running module, used to run a target application, wherein the target application corresponds to a path corresponding to the target table entry;
[0026] The capture module is used to capture the information of the API called by the target application through the dynamic link library file of the bridge layer to obtain the API call tracking data of the target application.
[0027] In a possible implementation, the capture module is used to:
[0028] Calling the dynamic link library file at runtime through the target application;
[0029] In response to the target application calling the target API through the dynamic link library file at runtime, the dynamic link library file of the bridge layer intercepts the call and captures the information of the target API called by the target application.
[0030] In a possible implementation, the capture module is used to:
[0031] In response to the target application calling the target API through the runtime dynamic link library file, the dynamic link library file of the bridge layer replaces the pointer to the target API with a pointer to a wrapper function, wherein the wrapper function is used to capture the information of the target API called by the target application.
[0032] In a possible implementation manner, the device further includes:
[0033] A calling module, configured to call the target API through the wrapper function in response to the wrapper function completing the crawling;
[0034] The feedback module is used to transmit the return value of the target API back to the target application.
[0035] In a possible implementation manner, the device further includes:
[0036] The recovery module is used to restore the path corresponding to the target entry in the registration table to the target path in response to the completion of the API capture called by the target application.
[0037] In a possible implementation, the API call tracking data includes at least the following:
[0038] The name of the API called by the target application;
[0039] The time when the target application calls the API;
[0040] Parameter information of the API called by the target application.
[0041] In a possible implementation manner, the target application is an OpennGL application.
[0042] According to one aspect of the present disclosure, an electronic device is provided, comprising: one or more processors; a memory for storing executable instructions; wherein the one or more processors are configured to call the executable instructions stored in the memory to execute the above method.
[0043] According to one aspect of the present disclosure, a computer-readable storage medium is provided, on which computer program instructions are stored, and the computer program instructions implement the above method when executed by a processor.
[0044] According to one aspect of the present disclosure, a computer program product is provided, including a computer-readable code, or a non-volatile computer-readable storage medium carrying the computer-readable code. When the computer-readable code runs in an electronic device, a processor in the electronic device executes the above method.
[0045] In the embodiment of the present disclosure, by modifying the target path corresponding to the target table item in the registry to the path of the dynamic link library file of the bridge layer, wherein the target table item corresponds to the dynamic link library file of the user-mode driver, the dynamic link library file of the bridge layer is used to export a first function set and implement a second function set, wherein the first function set represents a set of functions exported by the user-mode driver, and the second function set represents a set of exported functions constituting an API, and running the target application, capturing the information of the API called by the target application through the dynamic link library file of the bridge layer, and obtaining the API call tracking data of the target application, thereby inserting a bridge layer between the runtime layer and the user-mode driver layer, capturing the information of the API called by the target application based on the bridge layer, without injecting the dynamic link library file into the target application, and without intercepting the runtime through the hook technology, the security detection mechanism of the target application will not be triggered, thereby improving the probability of successfully capturing the API called by the target application. Therefore, the embodiment of the present disclosure provides a more stable and reliable API capture method, which is crucial for improving the development efficiency and performance of applications.
[0046] It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure.
[0047] Further features and aspects of the present disclosure will become apparent from the following detailed description of exemplary embodiments with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present disclosure and are used to illustrate the technical solutions of the present disclosure together with the specification.
[0049] Figure 1 A flowchart of the API crawling method provided by an embodiment of the present disclosure is shown.
[0050] Figure 2 A schematic diagram of the API crawling method provided by an embodiment of the present disclosure is shown.
[0051] Figure 3 Another schematic diagram of the API crawling method provided by an embodiment of the present disclosure is shown.
[0052] Figure 4 Another schematic diagram of the API crawling method provided by an embodiment of the present disclosure is shown.
[0053] Figure 5 A block diagram of an API capture device provided by an embodiment of the present disclosure is shown.
[0054] Figure 6 A block diagram of an electronic device 1900 provided by an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0055] Various exemplary embodiments, features and aspects of the present disclosure will be described in detail below with reference to the accompanying drawings. The same reference numerals in the accompanying drawings represent elements with the same or similar functions. Although various aspects of the embodiments are shown in the accompanying drawings, the drawings are not necessarily drawn to scale unless otherwise specified.
[0056] The word “exemplary” is used exclusively herein to mean “serving as an example, example, or illustration.” Any embodiment described herein as “exemplary” is not necessarily to be construed as preferred or advantageous over other embodiments.
[0057] The term "and / or" herein is only a description of the association relationship of the associated objects, indicating that there may be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the term "at least one" herein represents any combination of at least two of any one or more of a plurality of. For example, including at least one of A, B, and C can represent including any one or more elements selected from the set consisting of A, B, and C.
[0058] In addition, in order to better illustrate the present disclosure, numerous specific details are given in the following specific embodiments. It should be understood by those skilled in the art that the present disclosure can also be implemented without certain specific details. In some examples, methods, means, components and circuits well known to those skilled in the art are not described in detail in order to highlight the subject matter of the present disclosure.
[0059] In the related art, the dynamic-link library (DLL) injection technology is usually used to capture the API called by the OpenGL application. Specifically, a dynamic-link library file is injected into the target application, and the runtime API call is intercepted in the dynamic-link library file through the hook technology, that is, the address of its exported function is redirected to the wrapper function (Warp function) in the dynamic-link library file. In the wrapper function, the parameters of the graphics API can be captured and serialized into the API call trace data. After obtaining the API call trace data, the parameters of each graphics API in the API call trace data can be restored by deserialization for playback.
[0060] However, dynamic link library injection can be easily detected by the target application because the injection behavior will change the memory layout and execution process of the target application, thereby triggering the security detection mechanism. Once the target application detects the dynamic link library file injection, it may take defensive measures, resulting in the failure of dynamic link library file injection and the inability to capture API call tracking data.
[0061] In addition, some applications or security software have the ability to detect hook behaviors. They can monitor the modification of API addresses and take corresponding countermeasures. In this case, even if the dynamic link library file is injected successfully, if the hook interception fails, it will also result in the inability to capture valid API call tracking data.
[0062] In summary, the API capture method based on dynamic link library injection in the related art has the risk of dynamic link library file injection failure and hook interception failure, which limits its application in OpenGL application debugging and optimization.
[0063] In order to solve the technical problems similar to those described above, the embodiment of the present disclosure provides an API capture method, by modifying the target path corresponding to the target table item in the registry to the path of the dynamic link library file of the bridge layer, wherein the target table item corresponds to the dynamic link library file of the user-mode driver, and the dynamic link library file of the bridge layer is used to export a first function set and implement a second function set, wherein the first function set represents a set of functions exported by the user-mode driver, and the second function set represents a set of exported functions constituting the API, and running the target application, capturing the information of the API called by the target application through the dynamic link library file of the bridge layer, and obtaining the API call tracking data of the target application, thereby inserting the bridge layer between the runtime layer and the user-mode driver layer, and capturing the information of the API called by the target application based on the bridge layer, without injecting the dynamic link library file into the target application, and without intercepting the runtime through the hook technology, and will not trigger the security detection mechanism of the target application, thereby being able to increase the probability of successfully capturing the API called by the target application. Therefore, the embodiment of the present disclosure provides a more stable and reliable API capture method, which is crucial for improving the development efficiency and performance of applications.
[0064] The API crawling method provided by the embodiment of the present disclosure is described in detail below with reference to the accompanying drawings.
[0065] Figure 1A flow chart of the API capture method provided by an embodiment of the present disclosure is shown. In one possible implementation, the execution subject of the API capture method may be an API capture device. For example, the API capture method may be executed by a terminal device or a server or other electronic device. The terminal device may be a user equipment (UE), a mobile device, a user terminal, a terminal, a cellular phone, a cordless phone, a personal digital assistant (PDA), a handheld device, a computing device, a vehicle-mounted device or a wearable device, etc. In some possible implementations, the API capture method may be implemented by a processor calling computer-readable instructions stored in a memory. For example Figure 1 As shown, the API crawling method includes steps S11 to S13.
[0066] In step S11, the target path corresponding to the target table entry in the registry is modified to the path of the dynamic link library file of the bridge layer; wherein the target table entry corresponds to the dynamic link library file of the user-state driver; the dynamic link library file of the bridge layer is used to export a first function set and implement a second function set, wherein the first function set represents a set of functions exported by the user-state driver, and the second function set represents a set of exported functions constituting an API.
[0067] In step S12, a target application is run, wherein the target application corresponds to the path corresponding to the target table entry.
[0068] In step S13, the information of the API called by the target application is captured through the dynamic link library file of the bridge layer to obtain the API call tracking data of the target application.
[0069] The API capture method provided in the embodiments of the present disclosure can be applied to various operating systems, such as Microsoft Server operating system (Windows Server 2003, TM ), a graphical user interface operating system launched by Apple (Mac OS X TM ), a free and open source Unix-like operating system (Linux TM ), etc. In the following, the Windows operating system is taken as an example for explanation.
[0070] In the embodiment of the present disclosure, the target application may be any application for which API capture is required, that is, the target application may represent any application for which the user wishes to monitor the API call status.
[0071] In a possible implementation, the target application is an OpenGL application. The OpenGL application may refer to an application developed using OpenGL. OpenGL is a cross-language, cross-platform professional graphics programming interface, and is a powerful, easy-to-call underlying graphics library. OpenGL provides a wealth of graphics functions, including drawing basic graphic elements such as points, lines, and polygons, performing operations such as texture mapping, lighting calculation, and animation processing, as well as implementing complex three-dimensional graphics rendering.
[0072] When the target application is an OpenGL application, the target application will call the OpenGL API to perform graphics rendering and other related operations during execution.
[0073] In this implementation, the target path corresponding to the target table item in the registry is modified to the path of the dynamic link library file of the bridge layer, wherein the target table item corresponds to the dynamic link library file of the user-mode driver, and the dynamic link library file of the bridge layer is used to export a first function set and implement a second function set, wherein the first function set represents a set of functions exported by the user-mode driver, and the second function set represents a set of exported functions constituting the OPENGL API, and the OpenGL application is run, and the information of the OPENGL API called by the OpenGL application is captured through the dynamic link library file of the bridge layer to obtain the OPENGL API call tracking data of the OpenGL application, thereby inserting a bridge layer between the runtime layer and the user-mode driver layer, and capturing the information of the OPENGL API called by the OpenGL application based on the bridge layer, without injecting the dynamic link library file into the OpenGL application, and without intercepting the runtime through the hook technology, the security detection mechanism of the OpenGL application will not be triggered, thereby improving the probability of successfully capturing the OPENGL API called by the OpenGL application.
[0074] In the disclosed embodiment, the dynamic link library file of the bridge layer can be pre-written by the R&D personnel. In addition, the dynamic link library file of the bridge layer is used to export the first function set and implement the second function set. In a possible implementation, the name of the dynamic link library file of the bridge layer can be BridgeLayer.dll.
[0075] In the disclosed embodiment, the first function set may represent a set of functions exported by a user-mode driver (UMD). For example, the first function set may include all functions exported by the user-mode driver, that is, the dynamic link library file of the bridge layer needs to export all functions exported by the user-mode driver.
[0076] A user-mode driver may represent a display driver installed in user mode. A user-mode driver may process calls from applications (e.g., OpenGL applications) and communicate with a kernel-mode driver (KMD) to complete graphics rendering tasks, etc. Among them, a kernel-mode driver may represent a driver running in kernel mode. The kernel-mode driver has the authority to directly access hardware resources and may be responsible for executing actual hardware calls and graphics rendering operations. In a possible implementation, the user-mode driver and the kernel-mode driver may be implemented in the form of dynamic link libraries, respectively.
[0077] In one possible implementation, the user-mode driver may be an Installable Client Driver (ICD). The Installable Client Driver is a part of the OpenGL driver that runs in user mode and is responsible for processing OpenGL API calls and converting them into commands that the hardware can understand. The Installable Client Driver is an interface-compatible driver that provides a set of predefined APIs for interacting with specific hardware or software components. These API functions are exported by the ICD for other software components or applications to call to achieve communication and control with the underlying hardware or software. By calling the functions exported by the ICD, the application can perform operations related to the hardware device, such as initializing the device, reading and writing data, sending control commands, and querying status information. These functions usually have standardized interfaces and clear functions so that different applications can interact with the ICD in a unified manner.
[0078] For example, the functions exported by ICD can include the drvMakeCurrent function. The drvMakeCurrent function is used to bind an OpenGL context with a drawing surface (usually a frame buffer). When the drvMakeCurrent function is called, it tells the Windows runtime environment that all subsequent OpenGL commands should be sent to this specific context and drawing surface. In this way, the application can start rendering operations in this context.
[0079] In the embodiment of the present disclosure, the second function set may represent a set of exported functions constituting an API. For example, the second function set may include all exported functions constituting an OpenGL API. In one example, the second function set may include all functions in GLDispatchTable. Among them, GLDispatchTable is a data structure composed of multiple function pointers, each pointer pointing to a specific implementation of an OpenGL function. That is, in GLDispatchTable, each entry is a function pointer, which points to the function implementation that actually executes the OpenG function. These functions cover various graphics operations defined in the OpenGL specification, such as drawing commands, state settings, texture management, buffer operations, etc. In the actual use of OpenGL, GLDispatchTable is provided by the graphics driver when creating an OpenGL context, and is associated with the current OpenGL context through functions such as wglMakeCurrent (Windows), glXMakeCurrent (X11) or CGLSetCurrentContext (Mac OS X). For example, in the Windows operating system, when an application calls the wglMakeCurrent API, GLDispatchTable is returned to the runtime by the ICD and then called by the application.
[0080] In a possible implementation manner, all functions in the first function set and the second function set can be found in gldrv.h.
[0081] In some application scenarios, the bridging layer may also be called a bridge layer or middleware, etc., which is not limited here.
[0082] In the disclosed embodiment, the first function set is exported and the second function set is implemented through the dynamic link library file of the bridge layer, thereby being able to capture the information of the API called by the target application without interfering with the normal operation of the target application.
[0083] In the disclosed embodiment, when it is necessary to capture the API called by the target application, the path corresponding to the target table item in the registry is replaced with the path of the dynamic link library file of the bridge layer. The target table item may represent the table item corresponding to the dynamic link library file of the user-mode driver. For example, the path of the dynamic link library file of the ICD in the registry is replaced with the path of BridgeLayer.dll. For example, the path of the dynamic link library file of the ICD in the registry is: HKLM / System / CurrentControlSet / Control / Class / {Adapter GUID} / 0000 / .
[0084] After modifying the path of the dynamic link library file of the user-mode driver in the registry to the path of the dynamic link library file of the bridge layer, when the target application calls the API, it will first enter the dynamic link library file of the bridge layer, so that the information of the API called by the target application can be captured through the dynamic link library file of the bridge layer.
[0085] In a possible implementation, the API call tracking data includes at least the following: the name of the API called by the target application; the time when the target application calls the API; and parameter information of the API called by the target application.
[0086] As an example of this implementation, the API call tracking data may include the names of specific APIs called by the target application (such as glClear, glDrawArrays of OpenGL, etc.). Knowing which APIs the target application calls can help developers understand the workflow and functions used by the target application. This is of great significance for performance analysis, error debugging, and application optimization of the target application.
[0087] As an example of this implementation, the API call tracking data may include the time when the target application calls the API, for example, it may include the precise timestamp or time interval when the target application calls a specific API. Time data is critical for performance analysis of the target application. By analyzing the timestamps of API calls, developers can determine which operations take a long time and may be performance bottlenecks. In addition, it can also help identify concurrency issues, synchronization issues, or delays in the application.
[0088] As an example of this implementation, API call tracking data may include parameter information of the API called by the target application, such as the value and type of the parameters passed by the target application when calling the API. For OpenGL, the parameter information of the API called by the target application may include vertex data, texture coordinates, shader programs, rendering states, etc. Parameter information is critical to understanding the specific context of the API call. It can help developers understand why the application renders a specific visual effect or why an error occurs. When debugging, parameter information can reveal invalid or unexpected values passed to the API. In addition, understanding the parameters used is also crucial for analyzing and optimizing rendering effects.
[0089] Of course, depending on the actual application scenario, the API call tracking data may also include other types of information, which are not limited here.
[0090] In one possible implementation, the capturing of information on the API called by the target application through the dynamic link library file of the bridge layer includes: calling the runtime dynamic link library file through the target application; in response to the target application calling the target API through the runtime dynamic link library file, intercepting the call through the dynamic link library file of the bridge layer, and capturing information on the target API called by the target application.
[0091] When the target application is running, the target application will first call the runtime dynamic link library file. After that, without capturing the API called by the target application, the runtime dynamic link library file will call the user-mode driver, the user-mode driver will call the kernel-mode driver, and the kernel-mode driver will call the hardware for rendering.
[0092] In this implementation, first, the target application is run. During the running process, the target application will call the dynamic link library file at runtime. When the target application attempts to call a specific target API through the dynamic link library file at runtime, the dynamic link library file of the bridge layer will intercept this API call and record the information of the target API called by the target application.
[0093] For example, on the Windows platform, the runtime dynamic link library file called by the OpenGL application may be opengl32.dll. The OpenGL application can interact with the OpenGL driver through opengl32.dll to execute graphics commands. Among them, opengl32.dll is a dynamic link library file that provides OpenGL API functions, which serves as an interface between the application and the underlying graphics driver.
[0094] Figure 2 A schematic diagram of the API crawling method provided by the embodiment of the present disclosure is shown. Figure 2 As shown, the rendering process of the target application involves three dynamic link library files, namely the runtime dynamic link library file opengl32.dll, the bridge layer dynamic link library file bridgelayer.dll and the user-mode driver dynamic link library file icd_drvier.dll. Among them, the runtime dynamic link library file opengl32.dll can be used to provide the core functions of OpenGL, and the user-mode driver dynamic link library file icd_drvier.dll can be used to provide an interface with specific graphics hardware (such as GPU).
[0095] like Figure 2As shown, the target application can call the runtime dynamic link library file opengl32.dll. In response to the target application calling the target API through the runtime dynamic link library file opengl32.dll, the dynamic link library file bridgelayer.dll of the bridge layer intercepts this call and captures the information (trace) of the target API called by the target application.
[0096] In one possible implementation, in response to the target application calling the target API through the dynamic link library file at runtime, the call is intercepted by the dynamic link library file of the bridge layer, and the information of the target API called by the target application is captured, including: in response to the target application calling the target API through the dynamic link library file at runtime, the pointer to the target API is replaced by a pointer to a wrapper function (wrap function) through the dynamic link library file of the bridge layer, wherein the wrapper function is used to capture the information of the target API called by the target application.
[0097] In this implementation, the target application will call specific APIs as needed during its operation. When the target application tries to call a target API, the dynamic link library file of the bridge layer will intervene in the process. Specifically, the dynamic link library file of the bridge layer can find the address of the target API in memory (usually a function pointer) and replace it with a pointer to a wrapper function. This wrapper function is provided by the bridge layer and is used to perform additional operations before or after the original API call. When the target application continues to execute and calls the replaced API, it is actually calling the wrapper function provided by the bridge layer. This wrapper function will first perform some necessary operations, such as recording information about the API call (such as API name, parameters, call time, etc.).
[0098] In this implementation, by replacing the pointer to the target API with a pointer to the wrapper function, the bridge layer can insert additional logic before or after the actual execution of the API call, such as recording API call information. This approach not only ensures the integrity of the original application, but also provides a high degree of flexibility and scalability, allowing developers to easily implement API call monitoring.
[0099] In a possible implementation, after capturing the information of the target API called by the target application, the method further includes: in response to the wrapper function completing the capture, calling the target API through the wrapper function; and passing the return value of the target API back to the target application.
[0100] In this implementation, after the wrapper function captures the information of the API called by the target application, it calls the original API (i.e., the target API) that the target application wants to call. In this way, the target application can continue to execute as usual, and the bridge layer can capture the information of the API call.
[0101] For example, when the target application calls OpenGL API, it will first enter the dynamic link library file BridgeLayer.dll of the bridge layer, so the function in the DispatchTable obtained by the target application will be the wrapper function in the dynamic link library file BridgeLayer.dll of the bridge layer. After the wrapper function in the dynamic link library file BridgeLayer.dll of the bridge layer captures the information of the target API called by the target application, the wrapper function calls the function of the same name in the DispatchTable, which does not affect the normal operation of the target application and can achieve the purpose of capturing the API.
[0102] In a possible implementation, after obtaining the API call tracking data of the target application, the method further includes: in response to completion of the API capture called by the target application, restoring the path corresponding to the target table entry in the registry to the target path.
[0103] In this implementation, after the API information called by the target application is captured, in order to avoid unnecessary interference to the system or application, the previous changes can be restored to the original state. That is, after the API call tracking is completed, the path of the dynamic link library file of the user-mode driver in the registry can be restored to the original value (i.e., the target path).
[0104] Figure 3 Another schematic diagram of the API crawling method provided by the embodiment of the present disclosure is shown. Figure 3In the example shown, in step 1 (Step 1), the dynamic link library file BridgeLayer.dll of the bridge layer can be pre-written by the R&D personnel. In step 2 (Step 2), the registry can be modified to change the path of the dynamic link library file of the user-mode driver (such as ICD) to the path of the dynamic link library file BridgeLayer.dll of the bridge layer. In step 3 (Step 3), the target application is run, and the information of the API called by the target application is captured through the dynamic link library file BridgeLayer.dll of the bridge layer to obtain the API call tracking data (Trace) of the target application. In step 4 (Step 4), in response to the completion of the capture of the API called by the target application, the path of the dynamic link library file of the user-mode driver in the registry can be restored.
[0105] The API capture method provided in the embodiments of the present disclosure can be applied to technical fields such as APITrace, API capture, API tracking, GPU performance tuning, etc., and is not limited here.
[0106] The following is an explanation of the standard process of graphics rendering by OpenGL applications in the Windows operating system:
[0107] In the first step, when an OpenGL application needs to perform graphics rendering operations, the OpenGL application will call the dynamic link library file opengl32.dll of the OpenGL runtime.
[0108] Second, once the OpenGL application issues OpenGL API calls through opengl32.dll, these OpenGL API calls are passed to ICD.
[0109] In the third step, after ICD processes the OpenGL API calls, it passes these commands to KMD.
[0110] In the fourth step, KMD calls the GPU hardware for rendering.
[0111] Figure 4 Another schematic diagram of the API capture method provided by the embodiment of the present disclosure is shown. The following is an explanation of the process of graphics rendering by an OpenGL application in a Windows operating system when the API capture method provided by the embodiment of the present disclosure is used:
[0112] In the first step, when an OpenGL application needs to perform graphics rendering operations, the OpenGL application will call the dynamic link library file opengl32.dll of the OpenGL runtime.
[0113] In the second step, the OpenGL application issues an OpenGL API call through opengl32.dll. The bridge layer's dynamic link library file bridgelayer.dll will intercept this call and capture the target OpenGL API information called by the OpenGL application through a wrapper function.
[0114] In the third step, after the wrapper function completes the fetch, it passes the OpenGL API call to the ICD.
[0115] In the fourth step, after ICD processes the OpenGL API calls, it passes these commands to KMD.
[0116] In the fifth step, KMD calls the GPU hardware for rendering.
[0117] It can be understood that the above-mentioned various method embodiments mentioned in the present disclosure can be combined with each other to form a combined embodiment without violating the principle logic. Due to space limitations, the present disclosure will not repeat them. It can be understood by those skilled in the art that in the above-mentioned method of the specific implementation method, the specific execution order of each step should be determined according to its function and possible internal logic.
[0118] In addition, the present disclosure also provides an API capture device, an electronic device, a computer-readable storage medium, and a computer program product, all of which can be used to implement any API capture method provided by the present disclosure. The corresponding technical solutions and technical effects can be found in the corresponding records in the method part and will not be repeated here.
[0119] Figure 5 FIG. 1 is a block diagram of an API capture device provided by an embodiment of the present disclosure. Figure 5 As shown, the API capture device includes:
[0120] A modification module 51 is used to modify the target path corresponding to the target table item in the registry to the path of the dynamic link library file of the bridge layer; wherein the target table item corresponds to the dynamic link library file of the user-mode driver; the dynamic link library file of the bridge layer is used to export a first function set and implement a second function set, wherein the first function set represents a set of functions exported by the user-mode driver, and the second function set represents a set of exported functions constituting an API;
[0121] A running module 52, configured to run a target application, wherein the target application corresponds to a path corresponding to the target entry;
[0122] The capture module 53 is used to capture the information of the API called by the target application through the dynamic link library file of the bridge layer to obtain the API call tracking data of the target application.
[0123] In a possible implementation, the capture module 53 is used to:
[0124] Calling the dynamic link library file at runtime through the target application;
[0125] In response to the target application calling the target API through the dynamic link library file at runtime, the dynamic link library file of the bridge layer intercepts the call and captures the information of the target API called by the target application.
[0126] In a possible implementation, the capture module 53 is used to:
[0127] In response to the target application calling the target API through the runtime dynamic link library file, the dynamic link library file of the bridge layer replaces the pointer to the target API with a pointer to a wrapper function, wherein the wrapper function is used to capture the information of the target API called by the target application.
[0128] In a possible implementation manner, the device further includes:
[0129] A calling module, configured to call the target API through the wrapper function in response to the wrapper function completing the crawling;
[0130] The feedback module is used to transmit the return value of the target API back to the target application.
[0131] In a possible implementation manner, the device further includes:
[0132] The recovery module is used to restore the path corresponding to the target entry in the registration table to the target path in response to the completion of the API capture called by the target application.
[0133] In a possible implementation, the API call tracking data includes at least the following:
[0134] The name of the API called by the target application;
[0135] The time when the target application calls the API;
[0136] Parameter information of the API called by the target application.
[0137] In a possible implementation manner, the target application is an OpennGL application.
[0138] In some embodiments, the functions or modules included in the device provided by the embodiments of the present disclosure can be used to execute the method described in the above method embodiments. Its specific implementation and technical effects can refer to the description of the above method embodiments. For the sake of brevity, they will not be repeated here.
[0139] The present disclosure also provides a computer-readable storage medium having computer program instructions stored thereon, wherein the computer program instructions implement the above method when executed by a processor. The computer-readable storage medium may be a non-volatile computer-readable storage medium, or may be a volatile computer-readable storage medium.
[0140] The embodiment of the present disclosure further provides a computer program, including a computer-readable code. When the computer-readable code is executed in an electronic device, a processor in the electronic device executes the above method.
[0141] The embodiments of the present disclosure also provide a computer program product, including a computer-readable code, or a non-volatile computer-readable storage medium carrying the computer-readable code. When the computer-readable code runs in an electronic device, a processor in the electronic device executes the above method.
[0142] An embodiment of the present disclosure also provides an electronic device, comprising: one or more processors; and a memory for storing executable instructions; wherein the one or more processors are configured to call the executable instructions stored in the memory to execute the above method.
[0143] The electronic device may be provided as a terminal, a server, or a device in other forms.
[0144] Figure 6 1 is a block diagram of an electronic device 1900 provided in an embodiment of the present disclosure. For example, the electronic device 1900 may be provided as a terminal device or a server. Figure 6 , the electronic device 1900 includes a processing component 1922, which further includes one or more processors, and a memory resource represented by a memory 1932 for storing instructions executable by the processing component 1922, such as an application. The application stored in the memory 1932 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 1922 is configured to execute instructions to perform the above method.
[0145] The electronic device 1900 may also include a power supply component 1926 configured to perform power management of the electronic device 1900, a wired or wireless network interface 1950 configured to connect the electronic device 1900 to a network, and an input / output interface 1958 (I / O interface). The electronic device 1900 may operate based on an operating system stored in the memory 1932, such as a Microsoft Server operating system (Windows Server 2003). TM ), a graphical user interface operating system launched by Apple (MacOS X TM ), a multi-user, multi-process computer operating system (Unix TM ), a free and open source Unix-like operating system (Linux TM ), an open source Unix-like operating system (FreeBSD TM ) or similar.
[0146] In an exemplary embodiment, a non-volatile computer-readable storage medium is also provided, such as a memory 1932 including computer program instructions, which can be executed by the processing component 1922 of the electronic device 1900 to perform the above method.
[0147] The present disclosure may be a system, a method and / or a computer program product. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for causing a processor to implement various aspects of the present disclosure.
[0148] A computer-readable storage medium may be a tangible device that can hold and store instructions used by an instruction execution device. A computer-readable storage medium may be, for example, but not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination of the foregoing. More specific examples of computer-readable storage media (a non-exhaustive list) include: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, such as a punch card or a raised structure in a groove on which instructions are stored, and any suitable combination of the foregoing. As used herein, a computer-readable storage medium is not to be interpreted as a transient signal per se, such as a radio wave or other freely propagating electromagnetic wave, an electromagnetic wave propagating through a waveguide or other transmission medium (e.g., a light pulse through a fiber optic cable), or an electrical signal transmitted through a wire.
[0149] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.
[0150] The computer program instructions for performing the operation of the present disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages, such as Smalltalk, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. Computer-readable program instructions may be executed completely on a user's computer, partially on a user's computer, as an independent software package, partially on a user's computer, partially on a remote computer, or completely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via 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., using an Internet service provider to connect via the Internet). In some embodiments, an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), may be customized by utilizing the state information of the computer-readable program instructions, and the electronic circuit may execute the computer-readable program instructions, thereby realizing various aspects of the present disclosure.
[0151] Various aspects of the present disclosure are described herein with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer-readable program instructions.
[0152] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processor of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0153] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0154] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to multiple embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a part of a module, program segment or instruction, and a part of the module, program segment or instruction includes one or more executable instructions for realizing the specified logical function. In some alternative implementations, the function marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous square boxes can actually be executed substantially in parallel, and they can sometimes be executed in reverse 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 the specified function or action, or can be implemented with a combination of special hardware and computer instructions.
[0155] The computer program product may be implemented in hardware, software or a combination thereof. In one optional embodiment, the computer program product is embodied as a computer storage medium, and in another optional embodiment, the computer program product is embodied as a software product, such as a software development kit (SDK) and the like.
[0156] The above description of various embodiments tends to emphasize the differences between the various embodiments. The same or similar aspects can be referenced to each other, and for the sake of brevity, they will not be repeated herein.
[0157] If the technical solution of the embodiments of the present disclosure involves personal information, the product using the technical solution of the embodiments of the present disclosure has clearly informed the personal information processing rules and obtained the individual's voluntary consent before processing the personal information. If the technical solution of the embodiments of the present disclosure involves sensitive personal information, the product using the technical solution of the embodiments of the present disclosure has obtained the individual's separate consent before processing the sensitive personal information, and at the same time meets the requirement of "explicit consent". For example, at personal information collection devices such as cameras, clear and prominent signs are set to inform that the personal information collection scope has been entered and personal information will be collected. If the individual voluntarily enters the collection scope, it is deemed that he or she agrees to collect his or her personal information; or on the device for processing personal information, when the personal information processing rules are notified by obvious signs / information, the individual's authorization is obtained through pop-up information or by asking the individual to upload his or her personal information; the personal information processing rules may include information such as the personal information processor, the purpose of personal information processing, the processing method, and the type of personal information processed.
[0158] The embodiments of the present disclosure have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.
Claims
1. An API crawling method, characterized in that: include: Modify the target path corresponding to the target table item in the registry to the path of the dynamic link library file of the bridge layer; wherein the target table item corresponds to the dynamic link library file of the user-mode driver; the dynamic link library file of the bridge layer is used to export a first function set and implement a second function set, wherein the first function set represents a set of functions exported by the user-mode driver, and the second function set represents a set of exported functions constituting an API; Running a target application, wherein the target application corresponds to a path corresponding to the target table entry; The information of the API called by the target application is captured through the dynamic link library file of the bridge layer to obtain the API call tracking data of the target application.
2. The method according to claim 1, characterized in that The capturing of information of the API called by the target application through the dynamic link library file of the bridge layer includes: Calling the dynamic link library file at runtime through the target application; In response to the target application calling the target API through the dynamic link library file at runtime, the dynamic link library file of the bridge layer intercepts the call and captures the information of the target API called by the target application.
3. The method according to claim 2, characterized in that In response to the target application calling the target API through the dynamic link library file at runtime, intercepting the call through the dynamic link library file of the bridge layer, and capturing information of the target API called by the target application, including: In response to the target application calling the target API through the runtime dynamic link library file, the dynamic link library file of the bridge layer replaces the pointer to the target API with a pointer to a wrapper function, wherein the wrapper function is used to capture the information of the target API called by the target application.
4. The method according to claim 3, characterized in that After capturing the information of the target API called by the target application, the method further includes: In response to the wrapper function completing the crawl, calling the target API through the wrapper function; The return value of the target API is passed back to the target application.
5. The method according to any one of claims 1 to 4, characterized in that: After obtaining the API call tracking data of the target application, the method further includes: In response to the completion of the capture of the API called by the target application, the path corresponding to the target entry in the registration table is restored to the target path.
6. The method according to any one of claims 1 to 4, characterized in that The API call tracking data includes at least the following: The name of the API called by the target application; The time when the target application calls the API; Parameter information of the API called by the target application.
7. The method according to any one of claims 1 to 4, characterized in that The target application is an OpennGL application.
8. An API grabbing device, characterized in that: include: A modification module, used to modify the target path corresponding to the target table item in the registry to the path of the dynamic link library file of the bridge layer; wherein the target table item corresponds to the dynamic link library file of the user-mode driver; the dynamic link library file of the bridge layer is used to export a first function set and implement a second function set, wherein the first function set represents a set of functions exported by the user-mode driver, and the second function set represents a set of exported functions constituting an API; A running module, used to run a target application, wherein the target application corresponds to a path corresponding to the target table entry; The capture module is used to capture the information of the API called by the target application through the dynamic link library file of the bridge layer to obtain the API call tracking data of the target application.
9. An electronic device, characterized in that: include: one or more processors; a memory for storing executable instructions; The one or more processors are configured to call the executable instructions stored in the memory to execute the method according to any one of claims 1 to 7.
10. A computer-readable storage medium having computer program instructions stored thereon, characterized in that: When the computer program instructions are executed by a processor, the method according to any one of claims 1 to 7 is implemented.
11. A computer program product comprising computer readable code, or a non-volatile computer readable storage medium carrying computer readable code, characterized in that: When the computer readable code is executed in an electronic device, a processor in the electronic device executes the method according to any one of claims 1 to 7.