Dynamic library calling method, device, electronic device and storage medium
By searching and verifying the hash value of the dynamic library, it ensures that the dynamic library is only called under authorization when the interface is called, solving the problem of low security caused by unauthorized calls to the dynamic library and achieving higher security and legality. .
Patent Information
- Application Number
- CN202011259635.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-12
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2040-11-12
AI Technical Summary
In the existing technology, dynamic libraries are called without authorization, resulting in low security and lack of effective solutions.
By finding the dynamic library corresponding to the interface function address, extracting and calculating the hash value, and using the pre-stored hash signature for verification, it ensures that the interface call is only made under authorized circumstances.
It effectively prevents dynamic libraries from being called without authorization, improves security, and ensures the legality and integrity of the interface calling process.
Smart Images

Figure CN112434286B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method, device, electronic device and storage medium for calling a dynamic library. Background Art
[0002] The rapid development of computer and network technology has greatly promoted information exchange. At the same time, computer viruses have also been constantly evolving and updating with the development of technology. From the initial prank games to today, computer viruses have seriously threatened people's normal use of computers. Therefore, how to prevent virus attacks has become a focus of people's attention. However, with the development of virus detection technology, the means of fighting viruses and anti-virus software are constantly updated. Hooking is a technology that modifies the execution path. It activates the hook processing function by modifying the normal call process. This technology is widely used by security software and malicious programs.
[0003] During the programming process, the same piece of code or data may be applied to different programs, or called multiple times in the same program; in order to improve programming efficiency, these repeatedly applied codes and data are usually compiled into a common function library to facilitate program calls. The above function libraries include static libraries and dynamic libraries. Through the compiler, applications or dynamic libraries can be statically linked to static libraries, dynamically linked to dynamic libraries, or dynamically loaded through the Linux function dlopen. If a static library or dynamic library interface is an authorization authentication interface, the success or failure of these interface calls determines whether the application can be used normally. Therefore, malicious programs may try to bypass these authorization authentication interfaces in order to illegally use unauthorized applications.
[0004] The dynamic library in the related art is often based on the premise that the instructions in the dynamic library have not been modified and the dynamic library has been loaded. By reloading the dynamic library file into the memory image and calculating the function address in the image through the address offset, the function address is the original interface function address that has not been hooked, so as to achieve the purpose of bypassing the hook and calling the original interface function address. However, in this type of technical solution, when the instructions in the dynamic library are modified, because calling the dynamic library requires executing the instructions in the dynamic library, the call of the interface function address may still be bypassed, resulting in the dynamic library being called without authorization.
[0005] Currently, no effective solution has been proposed for the problem of low security caused by unauthorized calling of dynamic libraries in related technologies. Summary of the invention
[0006] The embodiments of the present application provide a method, device, electronic device and storage medium for calling a dynamic library, so as to at least solve the problem of low security caused by unauthorized calling of the dynamic library in the related art.
[0007] In a first aspect, an embodiment of the present application provides a method for calling a dynamic library, comprising: searching for a dynamic library corresponding to an interface function address of a first code library according to the interface function address of the first code library, wherein the first code library and the second code library are both pre-compiled into static libraries and linked to the dynamic library, and the operation of the second code library depends on an interface call to the first code library; extracting first key data in the dynamic library, and determining a first hash value of the first key data, wherein the first key data includes function instructions in the second code library; obtaining a hash signature pre-stored in the dynamic library, and decrypting the hash signature using a public key corresponding to the hash signature to obtain a second hash value, wherein the hash signature is used to verify the integrity of the dynamic library; and executing an interface call corresponding to the interface function address when the second hash value is the same as the first hash value.
[0008] In some of the embodiments, before searching for a dynamic library corresponding to an interface function address of a first code library according to the interface function address of the first code library, the method further includes: compiling the first code library to obtain a first static library; compiling the second code library to obtain a second static library, and linking the first static library and the second static library to the dynamic library respectively, wherein only the interface function symbols of the second code library are retained in the dynamic library; extracting second key data from the dynamic library, and performing a hash calculation on the second key data to obtain a second hash value, wherein the second key data includes function instructions in the second code library; performing an encryption operation on the second hash value to obtain a hash signature, and writing the hash signature into the dynamic library.
[0009] In some embodiments, compiling the second code library to obtain a second static library, and linking the first static library and the second static library to the dynamic library respectively includes: configuring the compilation tool chain to retain only the interface function symbols of the second code library; compiling the second code library through the compilation tool chain to obtain a second static library; linking the first static library and the second static library to the dynamic library respectively; removing non-essential symbols in the dynamic library, wherein the non-essential symbols include the interface function symbols of the first code library.
[0010] In some of the embodiments, before compiling the first code library to obtain the first static library, the method also includes: issuing a request to a key server to obtain a key pair, wherein the key pair includes a public key and a private key using an asymmetric encryption algorithm; and writing the public key into the second code library.
[0011] In some embodiments, performing an encryption operation on the second hash value to obtain a hash signature, and writing the hash signature into the dynamic library includes: performing an encryption operation on the second hash value using the private key in the key server to obtain a hash signature, and writing the hash signature into the dynamic library.
[0012] In some embodiments, writing the hash signature into the dynamic library includes: writing the hash signature into a custom section of the dynamic library.
[0013] In some of the embodiments, according to the interface function address of the first code library, searching for the dynamic library corresponding to the interface function address includes: reading the mapping range of the interface function address in the memory according to the interface function address of the first code library; according to the mapping range of the interface function address in the memory, searching for the dynamic library corresponding to the interface function address.
[0014] In the second aspect, an embodiment of the present application provides a dynamic library calling device, including a search module, used to search for a dynamic library corresponding to an interface function address of a first code library according to the interface function address of the first code library, wherein the first code library and the second code library are pre-compiled into static libraries and linked to the dynamic library, and the operation of the second code library depends on the interface call to the first code library; an extraction module, used to extract first key data in the dynamic library and determine a first hash value of the first key data, wherein the first key data includes function instructions in the second code library; a decryption module, used to obtain a hash signature pre-stored in the dynamic library, and use a public key corresponding to the hash signature to decrypt the hash signature to obtain a second hash value, wherein the hash signature is used to verify the integrity of the dynamic library; an execution module, used to execute the interface call corresponding to the interface function address when the second hash value is the same as the first hash value.
[0015] In a third aspect, an embodiment of the present application provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the method for calling a dynamic library as described in the first aspect above is implemented.
[0016] In a fourth aspect, an embodiment of the present application provides a storage medium on which a computer program is stored, and when the program is executed by a processor, the method for calling a dynamic library as described in the first aspect above is implemented.
[0017] Compared with the related art, the dynamic library calling method, device, electronic device and storage medium provided in the embodiments of the present application solve the problem of low security caused by the dynamic library being called without authorization in the related art, and achieve the technical effect of preventing the dynamic library from being called without authorization.
[0018] Details of one or more embodiments of the present application are set forth in the following drawings and description to make other features, objects, and advantages of the present application more readily apparent. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0020] Figure 1 is a flowchart of a method for calling a dynamic library according to an embodiment of the present application;
[0021] Figure 2 is a flowchart of a method for calling a dynamic library according to a preferred embodiment of the present application;
[0022] Figure 3 is a flowchart of a method for constructing a dynamic library according to an embodiment of the present application;
[0023] Figure 4 is a flowchart of a method for constructing a dynamic library according to a preferred embodiment of the present application;
[0024] Figure 5 is a structural block diagram of a dynamic library calling device according to an embodiment of the present application;
[0025] Figure 6 It is a schematic diagram of the hardware structure of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0026] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application is described and illustrated below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. Based on the embodiments provided in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present application. In addition, it can also be understood that although the efforts made in this development process may be complex and lengthy, for ordinary technicians in the field related to the contents disclosed in the present application, some changes such as design, manufacturing or production based on the technical contents disclosed in the present application are only conventional technical means, and should not be understood as insufficient contents disclosed in the present application.
[0027] Reference to "embodiments" in this application means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those of ordinary skill in the art that the embodiments described in this application may be combined with other embodiments without conflict.
[0028] Unless otherwise defined, the technical terms or scientific terms involved in this application should be understood by people with ordinary skills in the technical field to which this application belongs. The words "one", "a", "a", "the" and the like involved in this application do not indicate a quantitative limitation, and may represent the singular or plural. The terms "include", "comprise", "have" and any of their variations involved in this application are intended to cover non-exclusive inclusions; for example, a process, method, system, product or device that includes a series of steps or modules (units) is not limited to the listed steps or units, but may also include steps or units that are not listed, or may also include other steps or units inherent to these processes, methods, products or devices. The words "connect", "connected", "coupled" and the like involved in this application are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. The "multiple" involved in this application refers to greater than or equal to two. "And / or" describes the association relationship of associated objects, indicating that there can 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. The terms "first", "second", "third" and the like involved in the present application are merely used to distinguish similar objects and do not represent a specific ordering of the objects.
[0029] This embodiment provides a method for calling a dynamic library. Figure 1is a flowchart of a method for calling a dynamic library according to an embodiment of the present application, such as Figure 1 As shown, the process includes the following steps:
[0030] Step S101, according to the interface function address of the first code library, searching for the dynamic library corresponding to the interface function address, wherein the first code library and the second code library are pre-compiled into static libraries and linked to the dynamic library, and the operation of the second code library depends on the interface call to the first code library.
[0031] Step S102, extracting first key data in the dynamic library and determining a first hash value of the first key data, wherein the first key data includes function instructions in the second code library.
[0032] Step S103, obtaining a hash signature pre-stored in the dynamic library, and using a public key corresponding to the hash signature to decrypt the hash signature to obtain a second hash value, wherein the hash signature is used to verify the integrity of the dynamic library.
[0033] Step S104: when the second hash value is the same as the first hash value, executing the interface call corresponding to the interface function address.
[0034] In this embodiment, the call of the second code library can rely on the interface of the first code library, so the interface of the first code library needs to be protected from being hooked or illegally modified. For example, when the second code library is a core algorithm library, the first code library is required as an authorization library to verify whether the caller of the second code library has legal authorization.
[0035] If the caller needs to use the core algorithm, the second code library must be called. Since calling the second code library requires using the interface of the first code library, both the first code library and the second code library are linked to the dynamic library as static libraries. The static library needs to support static linking by other dynamic libraries. The interface of the first code library is hidden in the second code library, and the second code library is compiled to only retain the interface function symbols of the second code library. Therefore, the interface of the first code library cannot be hooked through the PLT table. If the caller wants to call the interface of the second code library, the interface of the first code library must be called to verify the authorization, ensuring that the second code library will not be used to bypass the authorization.
[0036] In some of the embodiments, according to the interface function address of the first code library, searching for the dynamic library corresponding to the interface function address includes: reading the mapping range of the interface function address in the memory according to the interface function address of the first code library; according to the mapping range of the interface function address in the memory, searching for the dynamic library corresponding to the interface function address.
[0037] In this embodiment, when the second code library needs to be called, it is necessary to first find the path of the dynamic library through the interface function address of the first code library, extract the first key data in the dynamic library, and perform hash calculation on the first key data to obtain the second hash value.
[0038] The hash calculation algorithm may include SHA256, and the hash algorithm is not limited.
[0039] In this embodiment, the hash signature can be obtained by extracting second key data in the dynamic library during the dynamic library construction process, determining a second hash value of the second key data, and encrypting the second hash value. The second key data can include function instructions in the dynamic library during the dynamic library construction process.
[0040] When the file instructions in the dynamic library are not modified, the content of the first key data should be the same as the second key data. Therefore, when the same hash calculation algorithm is used, the second hash value should also be the same as the first hash value. Therefore, the hash signature pre-stored in the dynamic library can be decrypted using the public key corresponding to the hash signature to obtain the second hash value, and the second hash value is compared with the first hash value to verify whether the hash signature is valid. If the first hash value is the same as the second hash value, the interface of the first code library is executed to call the second code library; if the first hash value is different from the second hash value, failure is returned.
[0041] In this embodiment, even if a cracker finds the instruction set in the dynamic library to call the first code library and tries to modify the instruction, since the dynamic library will check the integrity of the dynamic library by verifying whether the hash signature is valid, and the cracker destroys the integrity of the dynamic library by modifying the instruction, an error will occur when the cracker tries to call the second code library, thereby ensuring that the dynamic library cannot be bypassed for authorized use.
[0042] In some of these embodiments, writing the hash signature into the dynamic library may include writing the hash signature into a custom section of the dynamic library.
[0043] In this embodiment, the hash signature can be written into a custom section of the dynamic library. For example, a new section is added to the dynamic library file in the ELF file format, and the content of the section is the hash signature value, so that the hash signature value can be quickly extracted when the dynamic library is running.
[0044] Through the above steps S101 to S104, by pre-storing the hash signature in the dynamic library, and the hash signature is obtained by extracting the second key data in the dynamic library during the dynamic library construction process, determining the second hash value of the second key data, and encrypting the second hash value, the second key data may include the function instructions in the dynamic library during the dynamic library construction process. Therefore, the validity of the hash signature can be verified by comparing the second hash value with the first hash value. Even if the cracker finds the instruction set in the dynamic library to call the first code library and tries to modify the instruction, the dynamic library will check the integrity of the dynamic library by verifying whether the hash signature is valid, and the cracker destroys the integrity of the dynamic library by modifying the instruction. The cracker will make an error when trying to call the second code library, thereby ensuring that the dynamic library will not be bypassed for authorized use.
[0045] The embodiments of the present application are described and illustrated below through preferred embodiments.
[0046] Figure 2 is a flow chart of a method for calling a dynamic library according to a preferred embodiment of the present application, such as Figure 2 As shown, in some embodiments, the method includes:
[0047] Step S201, according to the interface function address of the first code library, searching for the dynamic library corresponding to the interface function address.
[0048] Step S202: extract the first key data in the dynamic library and determine the first hash value of the first key data.
[0049] Step S203, obtaining a hash signature pre-stored in the dynamic library.
[0050] Step S204: verify the hash signature.
[0051] Step S205: When the hash signature verification passes, execute the interface call corresponding to the interface function address.
[0052] The calling method of the dynamic library proposed in this embodiment has been described in detail in the above embodiments and will not be repeated here.
[0053] Figure 3 is a flowchart of a method for constructing a dynamic library according to an embodiment of the present application, such as Figure 3 As shown, the method includes:
[0054] Step S301, compile a first code library to obtain a first static library.
[0055] Step S302, compile the second code library to obtain a second static library, link the first static library and the second static library to the dynamic library respectively, wherein only the interface function symbols of the second code library are retained in the dynamic library.
[0056] Step S303, extracting second key data from the dynamic library, and performing hash calculation on the second key data to obtain a second hash value, wherein the second key data includes function instructions in the second code library.
[0057] Step S304: perform an encryption operation on the second hash value to obtain a hash signature, and write the hash signature into the dynamic library.
[0058] In some of the embodiments, before compiling the first code base to obtain the first static library, the method also includes: issuing a request to a key server to obtain a key pair, wherein the key pair includes a public key and a private key using an asymmetric encryption algorithm; and writing the public key into the second code base.
[0059] In this embodiment, the key pair may include a public key and a private key using an asymmetric encryption algorithm, and the asymmetric encryption algorithm may include an RSA algorithm and an ECC algorithm. At the same time, the public key needs to be written into the code of the second code library after code conversion, and the code conversion method is not limited.
[0060] In this embodiment, performing an encryption operation on the second hash value to obtain a hash signature, and writing the hash signature into the dynamic library includes: performing an encryption operation on the second hash value using a private key in a key server to obtain a hash signature, and writing the hash signature into the dynamic library.
[0061] In this embodiment, a hash signature can be requested from the key server, where the hash signature can only be generated in the key server to prevent the use of dynamic libraries without signatures or illegal signatures. The filling method of the hash signature can include PKCS1-V1_5. In other embodiments, other filling methods can also be used to obtain the hash signature.
[0062] The hash signature obtained after the private key encrypts the second hash value can be decrypted by the public key, so the public key can be used to verify the legitimacy of the hash signature.
[0063] In some of the embodiments, compiling the second code library to obtain the second static library, and linking the first static library and the second static library to the dynamic library respectively includes: configuring the compilation tool chain to retain only the interface function symbols of the second code library; compiling the second code library through the compilation tool chain to obtain the second static library; linking the first static library and the second static library to the dynamic library respectively; removing non-essential symbols in the dynamic library, wherein the non-essential symbols include the interface function symbols of the first code library.
[0064] Among them, the compilation tool chain can be implemented through the following link options:
[0065] -Wl,--retain-symbols-file=export.sym -Wl,--version-script=export.map, where the content of export.sym can be:
[0066]
[0067] export.map can be Func1; Func2; wherein Func1 and Func2 are both interface function symbols of the second code base, and other non-essential symbols, such as interface function symbols of the first code base, are hidden.
[0068] In this embodiment, by configuring the compilation tool chain to retain only the interface function symbols of the second code library, the second code library is compiled to retain only the interface function symbols of the second code library, and at the same time, unnecessary symbols of the interface function symbols of the first code library in the dynamic library are removed, thereby ensuring that the interface function symbols of the first code library cannot be found in the dynamic library. In the case of a large number of function instructions in the dynamic library, the interface function symbols of the first code library are difficult to be found and modified, thereby ensuring that the interface of the first code library will not be bypassed.
[0069] Through the above steps S301 to S304, the first code library whose interface needs to be prevented from being hooked is compiled and linked to the dynamic library that depends on the interface of the library, and the second code library is compiled to retain only the interface function symbols of the second code library, and the interface function symbols of the first code library are hidden, so that it is difficult for the cracker to find the interface function symbols of the first code library in the dynamic library, and it is also impossible to modify the interface function of the first code library, thereby ensuring that the second code library will not be bypassed for authorized use; at the same time, by presetting the hash signature in the dynamic library, while protecting the interface of the first code library, it also ensures that the caller's own instructions cannot be easily modified, further ensuring the security of the dynamic library.
[0070] Figure 4 is a flow chart of a method for constructing a dynamic library according to a preferred embodiment of the present application, such as Figure 4 As shown, in some embodiments, the method includes:
[0071] Step S401: Send a request to a key server to obtain a key pair.
[0072] Step S402: Convert the public key into code and write it into the second code library.
[0073] Step S403: compile the first code library to obtain a first static library.
[0074] Step S404: configure the compilation tool chain to retain only the interface function symbols of the second code base.
[0075] Step S405, compile the second code library to obtain a second static library and link the first static library and the second static library to the dynamic library respectively.
[0076] Step S406, removing unnecessary symbols in the dynamic library.
[0077] Step S407, extracting the second key data in the dynamic library and determining the second hash value.
[0078] Step S408: Request a hash signature from the key server.
[0079] Step S409, writing the hash signature into the custom section of the dynamic library.
[0080] The method for constructing the dynamic library proposed in this embodiment has been described in detail in the above embodiments and will not be repeated here.
[0081] This embodiment also provides a dynamic library calling device, which is used to implement the above embodiments and preferred implementations, which have been described and will not be repeated. Although the device described in the following embodiments is preferably implemented in software, hardware, or a combination of software and hardware is also possible and conceivable.
[0082] Figure 5 is a structural block diagram of a dynamic library calling device according to an embodiment of the present application, such as Figure 5 As shown, the device includes: a search module 51, used to search for a dynamic library corresponding to an interface function address according to the interface function address of the first code library, wherein the first code library and the second code library are pre-compiled into static libraries and linked to the dynamic library, and the operation of the second code library depends on an interface call to the first code library; an extraction module 52 coupled to the search module 51, used to extract first key data in the dynamic library and determine a first hash value of the first key data, wherein the first key data includes function instructions in the second code library; a decryption module 53 coupled to the extraction module 52, used to obtain a hash signature pre-stored in the dynamic library, and use a public key corresponding to the hash signature to decrypt the hash signature to obtain a second hash value, wherein the hash signature is used to verify the integrity of the dynamic library; an execution module 54 coupled to the decryption module 53, used to execute an interface call corresponding to the interface function address when the second hash value is the same as the first hash value.
[0083] In some of the embodiments, the device also includes a construction module 50 coupled to the search module 51, which is used to compile the first code library to obtain a first static library; compile the second code library to obtain a second static library, and link the first static library and the second static library to the dynamic library respectively, wherein only the interface function symbols of the second code library are retained in the dynamic library; extract the second key data in the dynamic library, and perform hash calculation on the second key data to obtain a second hash value, wherein the second key data includes function instructions in the second code library; perform encryption operation on the second hash value to obtain a hash signature, and write the hash signature into the dynamic library.
[0084] In some of the embodiments, the building module 50 is also configured to configure the compilation tool chain to retain only the interface function symbols of the second code library; compile the second code library through the compilation tool chain to obtain a second static library; link the first static library and the second static library to the dynamic library respectively; and remove non-essential symbols in the dynamic library, wherein the non-essential symbols include the interface function symbols of the first code library.
[0085] In some of the embodiments, the construction module 50 is further configured to issue a request to a key server to obtain a key pair, wherein the key pair includes a public key and a private key using an asymmetric encryption algorithm; and write the public key into the second code base.
[0086] In some of the embodiments, the construction module 50 is further configured to perform an encryption operation on the second hash value by using a private key in the key server to obtain a hash signature, and write the hash signature into the dynamic library.
[0087] In some of these embodiments, the construction module 50 is further configured to write the hash signature into a custom section of the dynamic library.
[0088] In some of the embodiments, the search module 51 is also configured to read the mapping range of the interface function address in the memory according to the interface function address of the first code library; and search for the dynamic library corresponding to the interface function address according to the mapping range of the interface function address in the memory.
[0089] It should be noted that the above modules can be functional modules or program modules, and can be implemented by software or hardware. For modules implemented by hardware, the above modules can be located in the same processor; or the above modules can be located in different processors in any combination.
[0090] This embodiment further provides an electronic device, including a memory 604 and a processor 602 , wherein the memory 604 stores a computer program, and the processor 602 is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0091] Specifically, the processor 602 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiments of the present application.
[0092] Among them, the memory 604 may include a large capacity memory 604 for data or instructions. For example, but not limitation, the memory 604 may include a hard disk drive (HDD), a floppy disk drive, a solid state drive (SSD), a flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a universal serial bus (USB) drive, or a combination of two or more of these. Where appropriate, the memory 604 may include a removable or non-removable (or fixed) medium. Where appropriate, the memory 604 may be inside or outside the data processing device. In a specific embodiment, the memory 604 is a non-volatile memory. In a specific embodiment, the memory 604 includes a read-only memory (ROM) and a random access memory (RAM). Where appropriate, the ROM may be a mask-programmed ROM, a programmable ROM (Programmable Read-Only Memory, PROM for short), an erasable PROM (ErasableProgrammable Read-Only Memory, EPROM for short), an electrically erasable PROM (Electrically ErasableProgrammable Read-Only Memory, EEPROM for short), an electrically alterable ROM (ElectricallyAlterable Read-Only Memory, EAROM for short) or a flash memory (FLASH) or a combination of two or more of these. Under appropriate circumstances, the RAM can be a static random access memory (Static Random-Access Memory, abbreviated as SRAM) or a dynamic random access memory (Dynamic Random Access Memory, abbreviated as DRAM), wherein the DRAM can be a fast page mode dynamic random access memory 604 (Fast Page Mode Dynamic Random Access Memory, abbreviated as FPMDRAM), an extended data output dynamic random access memory (Extended Date Out Dynamic Random Access Memory, abbreviated as EDODRAM), a synchronous dynamic random access memory (Synchronous Dynamic Random-Access Memory, abbreviated as SDRAM), etc.
[0093] The memory 604 may be used to store or cache various data files required for processing and / or communication, as well as possible computer program instructions executed by the processor 602 .
[0094] The processor 602 implements any one of the dynamic library calling methods in the above embodiments by reading and executing the computer program instructions stored in the memory 604 .
[0095] Optionally, the electronic device may further include a transmission device 606 and an input / output device 608 , wherein the transmission device 606 is connected to the processor 602 , and the input / output device 608 is connected to the processor 602 .
[0096] Optionally, in this embodiment, the processor 602 may be configured to perform the following steps through a computer program:
[0097] S1, according to the interface function address of the first code library, searching for the dynamic library corresponding to the interface function address, wherein the first code library and the second code library are both pre-compiled into static libraries and linked to the dynamic library, and the operation of the second code library depends on the interface call to the first code library.
[0098] S2, extracting first key data in the dynamic library and determining a first hash value of the first key data, wherein the first key data includes function instructions in the second code library.
[0099] S3, obtaining a hash signature pre-stored in the dynamic library, and decrypting the hash signature using a public key corresponding to the hash signature to obtain a second hash value, wherein the hash signature is used to verify the integrity of the dynamic library.
[0100] S4: When the second hash value is the same as the first hash value, execute an interface call corresponding to the interface function address.
[0101] It should be noted that the specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementation modes, and this embodiment will not be described in detail here.
[0102] In addition, in combination with the dynamic library calling method in the above embodiment, the present application embodiment can provide a storage medium for implementation. The storage medium stores a computer program; when the computer program is executed by a processor, any one of the dynamic library calling methods in the above embodiment is implemented.
[0103] Those skilled in the art should understand that the technical features of the above embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0104] The above embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A method for calling a dynamic library, characterized in that include: According to the interface function address of the first code library, searching for a dynamic library corresponding to the interface function address, wherein the first code library and the second code library are pre-compiled into static libraries and linked to the dynamic library, and the operation of the second code library depends on the interface call to the first code library, wherein only the interface function symbol of the second code library is retained in the dynamic library; removing non-essential symbols in the dynamic library, wherein the non-essential symbols include the interface function symbol of the first code library; Extracting first key data in the dynamic library and determining a first hash value of the first key data, wherein the first key data includes function instructions in the second code library; Obtaining a hash signature pre-stored in the dynamic library, and decrypting the hash signature using a public key corresponding to the hash signature to obtain a second hash value, wherein the hash signature is used to verify the integrity of the dynamic library; When the second hash value is the same as the first hash value, an interface call corresponding to the interface function address is executed.
2. The method for calling a dynamic library according to claim 1, characterized in that: Before searching for a dynamic library corresponding to the interface function address according to the interface function address of the first code library, the method further includes: Compiling the first code library to obtain a first static library; Compile the second code library to obtain a second static library, and link the first static library and the second static library to the dynamic library respectively; Extracting second key data from the dynamic library, and performing hash calculation on the second key data to obtain a second hash value, wherein the second key data includes function instructions in the second code library; when the file instructions in the dynamic library are not modified, the first key data is the same as the second key data; An encryption operation is performed on the second hash value to obtain a hash signature, and the hash signature is written into the dynamic library.
3. The method for calling a dynamic library according to claim 2, characterized in that: Compiling the second code library to obtain a second static library, and linking the first static library and the second static library to the dynamic library respectively comprises: Configuring the compilation tool chain to retain only the interface function symbols of the second code base; Compiling the second code library by using the compilation tool chain to obtain a second static library; The first static library and the second static library are linked to the dynamic library respectively.
4. The method for calling a dynamic library according to claim 2, characterized in that: Before compiling the first code library to obtain the first static library, the method further includes: Sending a request to a key server to obtain a key pair, wherein the key pair includes a public key and a private key using an asymmetric encryption algorithm; The public key is written into the second code base.
5. The method for calling a dynamic library according to claim 4, characterized in that: Performing an encryption operation on the second hash value to obtain a hash signature, and writing the hash signature into the dynamic library comprises: The second hash value is encrypted by the private key in the key server to obtain a hash signature, and the hash signature is written into the dynamic library.
6. The method for calling a dynamic library according to claim 2, characterized in that: Writing the hash signature into the dynamic library includes: The hash signature is written into a custom section of the dynamic library.
7. The method for calling a dynamic library according to claim 1, characterized in that: According to the interface function address of the first code library, searching for a dynamic library corresponding to the interface function address includes: According to the interface function address of the first code library, read the mapping range of the interface function address in the memory; According to the mapping range of the interface function address in the memory, the dynamic library corresponding to the interface function address is searched.
8. A dynamic library calling device, characterized in that: include: A search module, configured to search for a dynamic library corresponding to an interface function address of a first code library according to the interface function address of the first code library, wherein the first code library and the second code library are pre-compiled into static libraries and linked to the dynamic library, and the operation of the second code library depends on an interface call to the first code library; wherein only the interface function symbols of the second code library are retained in the dynamic library; and non-essential symbols in the dynamic library are removed, wherein the non-essential symbols include the interface function symbols of the first code library; an extraction module, configured to extract first key data from the dynamic library and determine a first hash value of the first key data, wherein the first key data includes function instructions in the second code library; A decryption module, used to obtain a hash signature pre-stored in the dynamic library, and decrypt the hash signature using a public key corresponding to the hash signature to obtain a second hash value, wherein the hash signature is used to verify the integrity of the dynamic library; An execution module is used to execute an interface call corresponding to the interface function address when the second hash value is the same as the first hash value.
9. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to run the computer program to execute the method for calling a dynamic library according to any one of claims 1 to 7.
10. A storage medium, characterized in that: The storage medium stores a computer program, wherein the computer program is configured to execute the calling method of the dynamic library according to any one of claims 1 to 7 when running.
Citation Information
Patent Citations
Method and device for processing dynamic link library (DLL) file
CN101908119A
Android system-based code compilation method and apparatus
CN107871066A
