Dynamic link library file loading method, device and electronic device
By determining and injecting or replacing the loading path of the dynamic link library file of the third-party framework after the application is started, the problem of increasing application installation packages and reducing maintainability after the third-party framework is introduced is solved, and efficient loading and scalability of the application is achieved.
Patent Information
- Application Number
- CN202210415454.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-18
- Publication Date
- 2025-06-06
- Estimated Expiration
- 2042-04-18
AI Technical Summary
After the introduction of a third-party framework in the application, the dynamic link library file occupies a lot of space, resulting in the increase in the application installation package. Moreover, due to the different loading logic of the system dynamic link library file and the business dynamic link library file, it is difficult to implement a custom loading path, which reduces the maintainability and scalability of the application.
After the target application is started, determine the system dynamic link library files and business dynamic link library files corresponding to the third-party framework, and inject their corresponding storage paths into the load path list or replace them into the original constructor, and load the corresponding dynamic link library files based on these paths.
It realizes dynamically modifying the loading path without interfering with the original loading logic of the dynamic link library file, improving the maintainability and scalability of the application.
Smart Images

Figure CN114968394B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of file loading, and in particular to a method, device and electronic equipment for loading a dynamic link library file. Background Art
[0002] If a third-party framework is introduced into an application, the installation package of the application will also increase, and the dynamic link library files will occupy most of the space. Therefore, the dynamic link library files in the application installation package are usually filtered, and then loaded through a custom loading path, so as to achieve the effect of application slimming.
[0003] The integration product of a third-party framework usually includes the framework's underlying library (system dynamic link library file) and business logic library (business dynamic link library file). Since the loading logic of these two libraries is different, when customizing the loading path, it is necessary to modify the framework's source code or initialization logic, which reduces the maintainability and scalability of the application. Summary of the invention
[0004] In view of this, an object of the present invention is to provide a method, device and electronic device for loading a dynamic link library file to improve the maintainability and scalability of an application program.
[0005] In a first aspect, an embodiment of the present invention provides a method for loading a dynamic link library file, which is applied to an electronic device, on which a target application is running. The method includes: after the target application is started, determining a system dynamic link library file and a business dynamic link library file corresponding to a third-party framework; injecting a first storage path corresponding to the system dynamic link library file into a loading path list of the system dynamic link library file; replacing a second storage path corresponding to the business dynamic link library file with an original constructor of the third-party framework; loading the system dynamic link library file corresponding to the third-party framework based on the first storage path, and loading the business dynamic link library file based on the second storage path.
[0006] The above-mentioned determination of the system dynamic link library files and the business dynamic link library files corresponding to the third-party framework includes: detecting whether the system dynamic link library files and the business dynamic link library files corresponding to the third-party framework exist locally; if the system dynamic link library files and the business dynamic link library files corresponding to the third-party framework exist locally, determining the system dynamic link library files and the business dynamic link library files corresponding to the local third-party framework; if the system dynamic link library files and the business dynamic link library files corresponding to the third-party framework do not exist locally, downloading the system dynamic link library files and the business dynamic link library files corresponding to the third-party framework.
[0007] The above-mentioned detection of whether system dynamic link library files and business dynamic link library files corresponding to the third-party framework exist locally includes: detecting whether system dynamic link library files corresponding to the third-party framework exist locally according to a preset first message digest value, and detecting whether business dynamic link library files corresponding to the third-party framework exist locally according to a preset second message digest value.
[0008] The above-mentioned injecting the first storage path corresponding to the system dynamic link library file into the loading path list of the system dynamic link library file includes: obtaining the class loader of the target application, the class loader includes the loading path list of the system dynamic link library file; adding the first storage path corresponding to the system dynamic link library file to the loading path list.
[0009] The above-mentioned method of obtaining the class loader of the target application, the class loader includes a loading path list of the system dynamic link library file, including: obtaining the class loader of the target application through a reflection mechanism, the subclass of the class loader includes a basic bytecode class loader; extracting the loading path list of the system dynamic link library file from the basic bytecode class loader.
[0010] The above-mentioned replacement of the second storage path corresponding to the business dynamic link library file to the original constructor of the third-party framework includes: before the third-party framework is initialized, intercepting the original constructor of the third-party framework through a hook function; generating a target constructor according to the application information object of the third-party framework, wherein the local library loading path in the target constructor is the second storage path corresponding to the business dynamic link library file.
[0011] The above hook function uses the hook function in the epic framework.
[0012] The above-mentioned method generates a target constructor based on the application information object of the third-party framework, wherein the local library loading path in the target constructor is the second storage path corresponding to the business dynamic link library file, including: obtaining the application information object of the third-party framework, and creating a new constructor based on the application information object; replacing the local library loading path in the new constructor with the second storage path corresponding to the business dynamic link library file to obtain the target constructor.
[0013] The above-mentioned loading of the system dynamic link library file corresponding to the third-party framework based on the first storage path and loading of the business dynamic link library file based on the second storage path include: loading the system dynamic link library file corresponding to the third-party framework according to the first storage path in the loading path list, and initializing the third-party framework according to the second storage path in the original constructor to load the business dynamic link library file corresponding to the third-party framework.
[0014] In a second aspect, an embodiment of the present invention provides a dynamic link library file loading device, which is applied to an electronic device, on which a target application is running, and the device includes: a determination module, which is used to determine the system dynamic link library file and the business dynamic link library file corresponding to a third-party framework after the target application is started; an injection module, which is used to inject a first storage path corresponding to the system dynamic link library file into a loading path list of the system dynamic link library file; a replacement module, which is used to replace the second storage path corresponding to the business dynamic link library file with the original constructor of the third-party framework; and a loading module, which is used to load the system dynamic link library file corresponding to the third-party framework based on the first storage path, and load the business dynamic link library file based on the second storage path.
[0015] In a third aspect, an embodiment of the present invention provides an electronic device, including a processor and a memory, wherein the memory stores machine executable instructions that can be executed by the processor, and the processor executes the machine executable instructions to implement the above-mentioned dynamic link library file loading method.
[0016] In a fourth aspect, an embodiment of the present invention provides a machine-readable storage medium, which stores machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to implement the above-mentioned dynamic link library file loading method.
[0017] The embodiments of the present invention bring the following beneficial effects:
[0018] The above-mentioned method, device and electronic device for loading dynamic link library files determine the system dynamic link library files and business dynamic link library files corresponding to the third-party framework after the target application is started; inject the first storage path corresponding to the system dynamic link library files into the loading path list of the system dynamic link library files; replace the second storage path corresponding to the business dynamic link library files with the original constructor of the third-party framework; load the system dynamic link library files corresponding to the third-party framework based on the first storage path, and load the business dynamic link library files based on the second storage path. In this method, after the target application is started, the system dynamic link library files and business dynamic link library files corresponding to the third-party framework in the local folder are determined, and the custom paths that need to be modified, namely the first storage path corresponding to the system dynamic link library files and the second storage path corresponding to the business dynamic link library files, are obtained. Without interfering with the original loading logic of the dynamic link library files, the first storage path is injected into the loading path list of the system dynamic link library files, and the second storage path is replaced with the original constructor of the third-party framework, so that the target application loads the system dynamic link library files and business dynamic link library files corresponding to the third-party framework under the custom path according to the original loading logic, thereby improving the maintainability and scalability of the application.
[0019] Other features and advantages of the present invention will be described in the following description, and partly become apparent from the description, or understood by practicing the present invention. The purpose and other advantages of the present invention are realized and obtained by the structures particularly pointed out in the description, claims and drawings.
[0020] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without paying any creative work.
[0022] Figure 1 A flowchart of a first embodiment of a method for loading a dynamic link library file in an embodiment of the present invention;
[0023] Figure 2 A flow chart of a second embodiment of a method for loading a dynamic link library file according to an embodiment of the present invention;
[0024] Figure 3 A flowchart of a third embodiment of a method for loading a dynamic link library file in an embodiment of the present invention;
[0025] Figure 4 A schematic diagram of a device for loading a dynamic link library file provided by an embodiment of the present invention;
[0026] Figure 5 A schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0027] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0028] For ease of understanding, the specific process of the embodiment of the present invention is described below. Figure 1 , a first embodiment of a method for loading a dynamic link library file in an embodiment of the present invention includes:
[0029] Step S10: after the target application is started, determine the system dynamic link library file and the business dynamic link library file corresponding to the third-party framework;
[0030] It should be noted that a method, device and electronic device for loading a dynamic link library file provided in an embodiment of the present invention can be run on a terminal device or a server. The terminal device can be a local terminal device. When the method for loading a dynamic link library file runs on a server, the method can be implemented and executed based on a cloud interaction system, wherein the cloud interaction system includes a server and a client device. In a feasible implementation, the method for loading a dynamic link library file provided in an embodiment of the present invention is applied to an electronic device, and a target application is running on the electronic device.
[0031] It can be understood that the third-party framework is integrated into the target application, and the integrated product includes system dynamic link library files and business dynamic link library files. The target application is installed on the electronic device through an installation package, wherein the installation package of the target application filters the system dynamic link library files and business dynamic link library files corresponding to the third-party framework during the compilation and packaging process. In other words, the installation package of the target application does not contain the system dynamic link library files and business dynamic link library files corresponding to the third-party framework, which greatly reduces the size of the installation package of the target application and improves the installation efficiency.
[0032] As an example but not limitation, the third-party framework can be any application development framework among native frameworks (such as Android), web frameworks (such as Vue), hybrid frameworks (such as Cordova), progressive frameworks (such as Taro), bridge frameworks (such as Weex) and self-drawn frameworks (such as Flutter), or other functional frameworks, engines, components, plug-ins, toolkits, etc., without specific limitation. For ease of understanding, the subsequent examples are based on the self-drawn framework Flutter.
[0033] It should be noted that the system dynamic link library file refers to the underlying library file of the third-party framework, which can be loaded through the system interface. For example, the system interface loads Flutter: System.loadLibrary("flutter"). The business dynamic link library file refers to the business library file implemented based on the third-party framework. It cannot be loaded through the system interface, and its loading method is implemented in the initialization logic of the third-party framework. In view of the difference in loading methods of these two types of dynamic link library files, there are mainly three existing ways to implement custom loading paths to load dynamic link library files:
[0034] (1) Modify the dynamic link library file loading path in the third-party framework source code and recompile the third-party framework;
[0035] (2) Modify the initialization logic of the third-party framework through bytecode instrumentation to modify the loading path of the dynamic link library file originally passed in;
[0036] (3) Inherit the base class of the third-party framework and rewrite the base class function to modify the original initialization logic of the third-party framework.
[0037] All three methods above require modifying the source code or initialization logic of the framework, which reduces the stability of the third-party framework and makes it inconvenient for subsequent maintenance and upgrades of the application.
[0038] Based on the above, the embodiments of the present invention provide a method, device and electronic device for loading a dynamic link library file. This technology can be applied to applications integrated with a third-party framework, or other applications that require a customized dynamic link library file loading path.
[0039] In one embodiment, after filtering the system dynamic link library files and business dynamic link library files corresponding to the third-party framework, the system dynamic link library files and business dynamic link library files corresponding to the third-party framework are uploaded to the server. The above-mentioned determination of the system dynamic link library files and business dynamic link library files corresponding to the third-party framework includes: detecting whether the system dynamic link library files and business dynamic link library files corresponding to the third-party framework exist locally; if the system dynamic link library files and business dynamic link library files corresponding to the third-party framework exist locally, determining the system dynamic link library files and business dynamic link library files corresponding to the local third-party framework; if the system dynamic link library files and business dynamic link library files corresponding to the third-party framework do not exist locally, downloading the system dynamic link library files and business dynamic link library files corresponding to the third-party framework. In order to avoid re-downloading the system dynamic link library files and business dynamic link library files every time the target application is started, after the target application is started and before the third-party framework in the target application is loaded, first check whether there are system dynamic link library files and business dynamic link library files corresponding to the third-party framework in all local folders under the installation directory of the target application. If there are no system dynamic link library files and business dynamic link library files corresponding to the third-party framework in all local folders under the installation directory of the target application, it means that the system dynamic link library files and business dynamic link library files have not been downloaded successfully. In this case, download the system dynamic link library files and business dynamic link library files corresponding to the third-party framework from the server to the local folders. Folder, obtain the first storage path corresponding to the system dynamic link library file and the second storage path corresponding to the business dynamic link library file. After the download is completed, the system dynamic link library file and the business dynamic link library file corresponding to the third-party framework are determined according to the first storage path and the second storage path. If the system dynamic link library file and the business dynamic link library file corresponding to the third-party framework exist in all local folders under the installation directory of the target application, there is no need to download again, directly obtain the first storage path corresponding to the system dynamic link library file and the second storage path corresponding to the business dynamic link library file, and determine the system dynamic link library file and the business dynamic link library file corresponding to the third-party framework according to the first storage path and the second storage path. Based on the above, the first storage path is used to indicate the local storage path of the system dynamic link library file, and the second storage path is used to indicate the local storage path of the business dynamic link library file.
[0040] Based on the above, different versions of target applications correspond to a unique system dynamic link library file and a business dynamic link library file. In one embodiment, the above detection of whether there are system dynamic link library files and business dynamic link library files corresponding to the third-party framework locally includes: detecting whether there are system dynamic link library files corresponding to the third-party framework locally according to the preset first message digest value, and detecting whether there are business dynamic link library files corresponding to the third-party framework locally according to the preset second message digest value. After the target application is started, the preset first message digest value and the preset second message digest value are obtained according to the version information of the target application, and the preset first message digest value and the preset second message digest value are compared with the message digest values corresponding to all dynamic link library files in the local folder to detect whether there are system dynamic link library files and business dynamic link library files corresponding to the third-party framework locally. If there is a message digest value that is the same as the preset first message digest value and the preset second message digest value among the message digest values corresponding to all dynamic link library files in the local folder, it is determined that there are system dynamic link library files and business dynamic link library files corresponding to the third-party framework locally, and then the system dynamic link library files and business dynamic link library files corresponding to the third-party framework are determined. This embodiment detects the correctness of the dynamic link library file by presetting the first message digest value and the second message digest value, so as to timely discover whether the dynamic link library file has been tampered with or intercepted during the download process, and quickly perform file detection, thereby improving the security of file transmission and the efficiency of file detection.
[0041] The above-mentioned message digest values (including the preset first message digest value, the preset second message digest value and the message digest values corresponding to all dynamic link library files in the local folder) are all generated by a preset message digest algorithm, wherein the preset message digest algorithm includes but is not limited to a message digest (message digest, MD) algorithm, a secure hash algorithm (securehash algorithm, SHA) and a message authentication code (message authentication code, MAC) algorithm. As an example but not a limitation, the preset message digest algorithm adopts the MD5 algorithm in the MD algorithm, and the generated preset first message digest value, the preset second message digest value and the message digest values corresponding to all dynamic link library files in the local folder are all MD5 values. The MD5 algorithm can quickly calculate the message digest of a file, thereby improving the efficiency of file detection.
[0042] Step S20, injecting the first storage path corresponding to the system dynamic link library file into the load path list of the system dynamic link library file;
[0043] It should be noted that the principle of the target application loading the system dynamic link library file is to improve the loading of the loading path list of the system dynamic link library file. The list is an array structure, which contains the loading paths of all the system dynamic link library files of the target application. Since the system dynamic link library files corresponding to the third-party framework are not packaged into the installation package when compiling and packaging the target application, after the target application is started, the loading path list of the system dynamic link library file does not contain the first storage path corresponding to the system dynamic link library file. It is necessary to write the first storage path corresponding to the system dynamic link library file into the loading path list of the system dynamic link library file, so that when the target application traverses the loading path list of the system dynamic link library file, the first storage path corresponding to the system dynamic link library file can be obtained, so that the first storage path corresponding to the system dynamic link library file can be read and successfully loaded. This embodiment can dynamically inject a custom loading path based on the principle of system loading dynamic link library files, while maintaining the original loading mechanism of the third-party framework, without changing the source code to achieve dynamic replacement of dynamic link library files, so that the maintainability and scalability of the application are improved.
[0044] Step S30: Replace the second storage path corresponding to the business dynamic link library file with the original constructor of the third-party framework;
[0045] It should be noted that the loading logic of the business dynamic link library file is in the initialization program of the third-party framework. When the third-party framework is initialized, an application information object (such as FlutterApplicationInfo) will be created. The constructor of the application information object (i.e., the original constructor) contains the loading path and name corresponding to the business dynamic link library file. Therefore, when implementing the dynamic loading of the business dynamic link library file, the second storage path corresponding to the business dynamic link library file is replaced with the original constructor of the third-party framework. Specifically, according to the second storage path and file name corresponding to the business dynamic link library file, the loading path and name corresponding to the business dynamic link library file in the original constructor are modified. This implementation method can dynamically inject a custom loading path based on the initialization logic of the third-party framework. While maintaining the original loading mechanism of the third-party framework, it is possible to achieve dynamic replacement of dynamic link library files without changing the source code, thereby improving the maintainability and scalability of the application.
[0046] Step S40: Load the system dynamic link library file corresponding to the third-party framework based on the first storage path, and load the business dynamic link library file based on the second storage path.
[0047] Based on the above, the system dynamic link library file is loaded according to the loading path list after the first storage path is injected, so as to load the system dynamic link library file corresponding to the third-party framework, and the third-party framework is initialized according to the original constructor after the second storage path is replaced, so as to load the business dynamic link library file corresponding to the third-party framework, that is, the system dynamic link library file corresponding to the third-party framework is loaded according to the first storage path in the loading path list, and the third-party framework is initialized according to the second storage path in the original constructor, so as to load the business dynamic link library file corresponding to the third-party framework. This loading process is the same as the original loading process. This implementation method can realize the loading path modification of the dynamic link library file while maintaining the original loading mechanism of the target application and the third-party framework, without changing the source code and initialization logic of the third-party framework, so as to improve the maintainability and scalability of the application.
[0048] The method for loading dynamic link library files provided in the above implementation manner, after the target application is started, determines the system dynamic link library files and business dynamic link library files corresponding to the third-party framework; injects the first storage path corresponding to the system dynamic link library files into the loading path list of the system dynamic link library files; replaces the second storage path corresponding to the business dynamic link library files into the original constructor of the third-party framework; loads the system dynamic link library files corresponding to the third-party framework based on the first storage path, and loads the business dynamic link library files based on the second storage path. In this method, after the target application is started, the system dynamic link library files and business dynamic link library files corresponding to the third-party framework in the local folder are determined, and the custom paths that need to be modified, namely the first storage path corresponding to the system dynamic link library files and the second storage path corresponding to the business dynamic link library files, are obtained, without interfering with the original loading logic of the dynamic link library files, the first storage path is injected into the loading path list of the system dynamic link library files, and the second storage path is replaced into the original constructor of the third-party framework, so that the target application loads the system dynamic link library files and business dynamic link library files corresponding to the third-party framework under the custom path according to the original loading logic, thereby improving the maintainability and scalability of the application.
[0049] See also Figure 2 , a second embodiment of the method for loading a dynamic link library file in an embodiment of the present invention includes:
[0050] S201, obtaining a class loader of a target application, wherein the class loader includes a loading path list of a system dynamic link library file;
[0051] It can be understood that the class loader (ClassLoader) of the target application is responsible for loading class objects, that is, it is responsible for converting the bytecode form of each class into a class object in memory form, so as to load all class objects into the virtual machine running the target application, wherein the loading path list of the system dynamic link library file is also included in the subclass of the class loader. In order to inject the first storage path corresponding to the system dynamic link library file into the loading path list of the system dynamic link library file, the class loader of the target application is read, and the loading path list (pathList) of the system dynamic link library file in the class loader is extracted to realize the subsequent modification of the loading path list.
[0052] Based on the above, the class loader of the target application is obtained, and the class loader includes a loading path list of the system dynamic link library file, including: obtaining the class loader of the target application through the reflection mechanism, and the subclass of the class loader includes the basic bytecode class loader; extracting the loading path list of the system dynamic link library file from the basic bytecode class loader. Among them, the core of the reflection mechanism is to dynamically load the class (object) and obtain the detailed information of the class (object) when the program is running, so as to operate the properties and methods of the class or object. It can be understood that for the application development language that is compiled first and then run, the type of the class or object in the program is determined at the compile time, and not all classes or objects will be loaded into the virtual machine. Therefore, when the target application needs to dynamically load some classes or objects that are not loaded into the virtual machine during operation, it is necessary to dynamically obtain, create or call the target class or object (class loader) during the operation of the target application through reflection operation, and then decompile the target class or object to obtain the detailed information (subclass) in the target class or object. The specific implementation class of the loading path list of the system dynamic link library file in this embodiment is the basic bytecode class loader (BaseDexClassLoader), and the loading path list of the system dynamic link library file is extracted from the basic bytecode class loader to realize the subsequent modification of the loading path list. This embodiment can flexibly process class objects during the operation of the application through the reflection mechanism, without modifying the source code of the third-party framework, thereby improving the maintainability and scalability of the application.
[0053] S202: Add a first storage path corresponding to the system dynamic link library file to the loading path list.
[0054] It can be understood that after obtaining the loading path list of the system dynamic link library file through the reflection mechanism, the first storage path corresponding to the system dynamic link library file is added to the loading path list, so that after the target application is started, the system dynamic link library file under the first storage path is read through the loading path list, and the initialization of the third-party framework is realized through the system dynamic link library file.
[0055] See also Figure 3 , a third embodiment of the method for loading a dynamic link library file in an embodiment of the present invention includes:
[0056] S301, before the third-party framework is initialized, the original constructor of the third-party framework is intercepted through a hook function;
[0057] It can be understood that the hook function is also called the Hook function. The Hook function can intercept (capture) the original constructor before the third-party framework is initialized, that is, before the original constructor of the third-party framework is called, and obtain control of the original constructor, thereby injecting the second storage path corresponding to the business dynamic link library file into the original constructor, so that the third-party framework executes the initialization program according to the original constructor after the second storage path corresponding to the business dynamic link library file is injected, thereby realizing dynamic modification of the dynamic link library file loading path.
[0058] Among them, the hook function can use the hook function in the Xposed framework or the hook function in the epic framework. The Xposed framework needs to be based on the highest authority (root) of the operating system to implement the hook function, which is suitable for electronic devices that already have the highest authority of the operating system, while the epic framework does not need to be based on the highest authority of the operating system to implement the hook function, which is suitable for all electronic devices. Therefore, this implementation method uses the hook function in the epic framework to break the restriction on the operating authority of the operating system.
[0059] S302: Generate a target constructor according to the application information object of the third-party framework, wherein the local library loading path in the target constructor is a second storage path corresponding to the business dynamic link library file.
[0060] It should be noted that since the original constructor of the third-party framework is contained in the application information object of the third-party framework (such as FlutterApplicationInfo), after intercepting the original constructor of the third-party framework, all parameters contained in the original constructor are extracted from the application information object of the third-party framework, and the local library loading path in all the parameters contained in the obtained original constructor is modified to the second storage path corresponding to the business dynamic link library file to obtain the target constructor, so that the subsequent third-party framework executes the initialization program according to the target constructor.
[0061] Based on the above, according to the application information object of the third-party framework, a target constructor is generated, wherein the local library loading path in the target constructor is the second storage path corresponding to the business dynamic link library file, including: obtaining the application information object of the third-party framework, and creating a new constructor according to the application information object; replacing the local library loading path in the new constructor with the second storage path corresponding to the business dynamic link library file to obtain the target constructor. In order to obtain the application information object of the third-party framework, the application information object (such as ApplicationInfo) of the target application can be obtained first, and the application information object of the third-party framework can be extracted from the application information object of the target application. Since the application information object of the third-party framework contains all the parameters required for the creation of the original constructor, a new constructor is created according to the application information object of the third-party framework, that is, the original constructor in the application information object of the third-party framework is copied to obtain a new constructor, and then the second storage path corresponding to the business dynamic link library file is replaced with the local library loading path in the new constructor to obtain the target constructor, so that the subsequent third-party framework executes the initialization program according to the target constructor. This embodiment can dynamically modify the dynamic link library file loading path without changing the initialization program of the third-party framework, thereby improving the maintainability and scalability of the application.
[0062] Corresponding to the above method embodiment, see Figure 4 The schematic diagram of a device for loading a dynamic link library file is shown, which is applied to an electronic device, and a target application is running on the electronic device. The device includes:
[0063] A determination module 40, for determining a system dynamic link library file and a business dynamic link library file corresponding to a third-party framework after the target application is started;
[0064] An injection module 42, configured to inject a first storage path corresponding to a system dynamic link library file into a load path list of the system dynamic link library file;
[0065] A replacement module 44, used to replace the second storage path corresponding to the business dynamic link library file to the original constructor of the third-party framework;
[0066] The loading module 46 is used to load the system dynamic link library file corresponding to the third-party framework based on the first storage path, and load the business dynamic link library file based on the second storage path.
[0067] The above-mentioned dynamic link library file loading device determines the system dynamic link library file and the business dynamic link library file corresponding to the third-party framework after the target application is started; injects the first storage path corresponding to the system dynamic link library file into the loading path list of the system dynamic link library file; replaces the second storage path corresponding to the business dynamic link library file with the original constructor of the third-party framework; loads the system dynamic link library file corresponding to the third-party framework based on the first storage path, and loads the business dynamic link library file based on the second storage path. In this method, after the target application is started, the system dynamic link library file and the business dynamic link library file corresponding to the third-party framework in the local folder are determined to obtain the custom path that needs to be modified, that is, the first storage path corresponding to the system dynamic link library file and the second storage path corresponding to the business dynamic link library file. Without interfering with the original loading logic of the dynamic link library file, the first storage path is injected into the loading path list of the system dynamic link library file, and the second storage path is replaced with the original constructor of the third-party framework, so that the target application loads the system dynamic link library file and the business dynamic link library file corresponding to the third-party framework under the custom path according to the original loading logic, thereby improving the maintainability and scalability of the application.
[0068] The above-mentioned determination module is also used to: detect whether there are system dynamic link library files and business dynamic link library files corresponding to the third-party framework locally; if there are system dynamic link library files and business dynamic link library files corresponding to the third-party framework locally, determine the system dynamic link library files and business dynamic link library files corresponding to the local third-party framework; if there are no system dynamic link library files and business dynamic link library files corresponding to the third-party framework locally, download the system dynamic link library files and business dynamic link library files corresponding to the third-party framework.
[0069] The above-mentioned determination module is also used to: detect whether there is a system dynamic link library file corresponding to the third-party framework locally according to the preset first message digest value, and detect whether there is a business dynamic link library file corresponding to the third-party framework locally according to the preset second message digest value.
[0070] The injection module is further used to: obtain the class loader of the target application, the class loader includes a loading path list of the system dynamic link library file; and add the first storage path corresponding to the system dynamic link library file to the loading path list.
[0071] The injection module is also used to: obtain the class loader of the target application through the reflection mechanism, the subclasses of the class loader include the basic bytecode class loader; extract the loading path list of the system dynamic link library file from the basic bytecode class loader.
[0072] The above-mentioned replacement module is also used to: intercept the original constructor of the third-party framework through a hook function before the third-party framework is initialized; generate a target constructor based on the application information object of the third-party framework, wherein the local library loading path in the target constructor is the second storage path corresponding to the business dynamic link library file.
[0073] The hook function in the above replacement module adopts the hook function in the epic framework.
[0074] The above replacement module is also used to: obtain the application information object of the third-party framework and create a new constructor based on the application information object; replace the local library loading path in the new constructor with the second storage path corresponding to the business dynamic link library file to obtain the target constructor.
[0075] The above-mentioned loading module is also used to: load the system dynamic link library file corresponding to the third-party framework according to the first storage path in the loading path list, and initialize the third-party framework according to the second storage path in the original constructor to load the business dynamic link library file corresponding to the third-party framework.
[0076] This embodiment also provides an electronic device, including a processor and a memory, wherein the memory stores machine executable instructions that can be executed by the processor, and the processor executes the machine executable instructions to implement the above-mentioned method for loading the dynamic link library file. The electronic device can be a server or a terminal device.
[0077] See also Figure 5 As shown, the electronic device includes a processor 100 and a memory 101, wherein the memory 101 stores machine executable instructions that can be executed by the processor 100, and the processor 100 executes the machine executable instructions to implement the above-mentioned dynamic link library file loading method.
[0078] Further, Figure 5 The electronic device shown further includes a bus 102 and a communication interface 103 , and the processor 100 , the communication interface 103 and the memory 101 are connected via the bus 102 .
[0079] The memory 101 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk storage. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 103 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used. The bus 102 may be an ISA bus, a PCI bus, or an EISA bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0080] The processor 100 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 100. The above processor 100 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present invention can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in conjunction with the embodiments of the present invention can be directly embodied as a hardware decoding processor for execution, or a combination of hardware and software modules in the decoding processor for execution. The software module may be located in a storage medium mature in the art, such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 101, and the processor 100 reads the information in the memory 101 and completes the steps of the method of the above embodiment in combination with its hardware.
[0081] This embodiment also provides a machine-readable storage medium, which stores machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to implement the above-mentioned dynamic link library file loading method.
[0082] The computer program product of the dynamic link library file loading method, device, electronic device and storage medium provided in the embodiments of the present invention includes a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the method described in the previous method embodiment. The specific implementation can be referred to the method embodiment, which will not be repeated here.
[0083] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system and device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0084] In addition, in the description of the embodiments of the present invention, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium, and it can be the internal communication of two components. For those skilled in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0085] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc., which can store program codes.
[0086] In the description of the present invention, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc., indicating the orientation or positional relationship, are based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the present invention. In addition, the terms "first", "second", and "third" are used for descriptive purposes only, and cannot be understood as indicating or implying relative importance.
[0087] Finally, it should be noted that the above embodiments are only specific implementations of the present invention, which are used to illustrate the technical solutions of the present invention, rather than to limit them. The protection scope of the present invention is not limited thereto. Although the present invention is described in detail with reference to the above embodiments, those skilled in the art should understand that any person skilled in the art can still modify the technical solutions recorded in the above embodiments within the technical scope disclosed by the present invention, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.
Claims
1. A method for loading a dynamic link library file, It is characterized in that Applied to an electronic device, the target application is running on the electronic device, and the method includes: After the target application is started, determining the system dynamic link library file and the business dynamic link library file corresponding to the third-party framework; Injecting the first storage path corresponding to the system dynamic link library file into the load path list of the system dynamic link library file; Replacing the second storage path corresponding to the business dynamic link library file with the original constructor of the third-party framework; The system dynamic link library file corresponding to the third-party framework is loaded based on the first storage path, and the business dynamic link library file is loaded based on the second storage path.
2. The method according to claim 1, It is characterized in that The determining of the system dynamic link library file and the business dynamic link library file corresponding to the third-party framework includes: Detect whether there are system dynamic link library files and business dynamic link library files corresponding to the third-party framework locally; If the system dynamic link library file and the business dynamic link library file corresponding to the third-party framework exist locally, then determining the system dynamic link library file and the business dynamic link library file corresponding to the third-party framework locally; If the system dynamic link library file and the service dynamic link library file corresponding to the third-party framework do not exist locally, the system dynamic link library file and the service dynamic link library file corresponding to the third-party framework are downloaded.
3. The method according to claim 2, It is characterized in that The detecting whether there are system dynamic link library files and business dynamic link library files corresponding to the third-party framework locally includes: According to the preset first message digest value, it is detected whether the system dynamic link library file corresponding to the third-party framework exists locally, and according to the preset second message digest value, it is detected whether the service dynamic link library file corresponding to the third-party framework exists locally.
4. The method according to claim 1, It is characterized in that The step of injecting the first storage path corresponding to the system dynamic link library file into the load path list of the system dynamic link library file comprises: Obtaining a class loader of the target application, wherein the class loader includes a loading path list of a system dynamic link library file; Add the first storage path corresponding to the system dynamic link library file to the loading path list.
5. The method according to claim 4, It is characterized in that The obtaining of the class loader of the target application, wherein the class loader includes a loading path list of a system dynamic link library file, includes: Obtaining the class loader of the target application through a reflection mechanism, wherein the subclasses of the class loader include a basic bytecode class loader; A loading path list of a system dynamic link library file is extracted from the basic bytecode class loader.
6. The method according to claim 1, It is characterized in that The step of replacing the second storage path corresponding to the business dynamic link library file with the original constructor of the third-party framework includes: Before the third-party framework is initialized, the original constructor of the third-party framework is intercepted through a hook function; A target constructor is generated according to the application information object of the third-party framework, wherein the local library loading path in the target constructor is the second storage path corresponding to the business dynamic link library file.
7. The method according to claim 6, It is characterized in that The hook function adopts the hook function in the epic framework.
8. The method according to claim 6, It is characterized in that The generating a target constructor according to the application information object of the third-party framework, wherein the local library loading path in the target constructor is the second storage path corresponding to the business dynamic link library file, includes: Obtaining an application information object of the third-party framework, and creating a new constructor according to the application information object; The local library loading path in the new constructor is replaced with the second storage path corresponding to the business dynamic link library file to obtain the target constructor.
9. The method according to claim 1, It is characterized in that The loading of the system dynamic link library file corresponding to the third-party framework based on the first storage path, and the loading of the business dynamic link library file based on the second storage path, include: The system dynamic link library file corresponding to the third-party framework is loaded according to the first storage path in the loading path list, and the third-party framework is initialized according to the second storage path in the original constructor to load the business dynamic link library file corresponding to the third-party framework.
10. A device for loading a dynamic link library file, It is characterized in that Applied to an electronic device, a target application is running on the electronic device, and the device comprises: A determination module, used to determine the system dynamic link library file and the business dynamic link library file corresponding to the third-party framework after the target application is started; An injection module, used for injecting a first storage path corresponding to the system dynamic link library file into a load path list of the system dynamic link library file; A replacement module, used to replace the second storage path corresponding to the business dynamic link library file to the original constructor of the third-party framework; A loading module is used to load the system dynamic link library file corresponding to the third-party framework based on the first storage path, and to load the business dynamic link library file based on the second storage path.
11. An electronic device, It is characterized in that It comprises a processor and a memory, wherein the memory stores machine executable instructions that can be executed by the processor, and the processor executes the machine executable instructions to implement the dynamic link library file loading method according to any one of claims 1 to 9.
12. A machine-readable storage medium, It is characterized in that The machine-readable storage medium stores machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to implement the method for loading a dynamic link library file according to any one of claims 1 to 9.
Citation Information
Patent Citations
DLL (dynamic link library) file intercepting method and device as well as terminal equipment
CN106203069A
Library file loading method and device
CN107038045A