A method and system for cross-dll relocation repair

By using hook points or hardware write breakpoints during DLL loading to detect repair opportunities, the problem of cross-DLL relocation repair is solved, ensuring that function code runs normally in the target DLL.

CN115408181BActive Publication Date: 2026-04-24WUHAN DOUYU NETWORK TECHNOLOGY CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
WUHAN DOUYU NETWORK TECHNOLOGY CO LTD
Filing Date
2021-05-26
Publication Date
2026-04-24

AI Technical Summary

Technical Problem

Existing technology cannot achieve relocation repair across DLLs, causing program crashes when function code is copied to another DLL.

Method used

When the system loads the second DLL, it detects the repair opportunity by searching for relocation data items in its relocation table and adding a hook point or setting a hardware write breakpoint after the code segment corresponding to the last relocation data item, and repairs the relocation data items in the copied function code.

Benefits of technology

It ensures the correct repair of relocated data items across DLLs, guaranteeing that function code can be called normally in the target DLL and avoiding program errors.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115408181B_ABST
    Figure CN115408181B_ABST
Patent Text Reader

Abstract

The application provides a DLL-crossing relocation repair method and system. The method comprises: when a second DLL is loaded in a system, a repair opportunity for a relocation data item in copied function code is obtained, wherein the copied function code is function code copied from a first DLL to the second DLL; and the relocation data item in the copied function code is repaired based on the repair opportunity. When the second DLL is loaded, the application uses a certain method to capture a repair opportunity for a relocation data item of the function code copied from the first DLL, and the relocation data item across DLLs is repaired based on the captured repair opportunity, so that the relocation data item across DLLs is repaired.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computers, and more specifically, to a method and system for cross-DLL relocation repair. Background Technology

[0002] For client programs, there may be multiple DLL (Dynamic Link Library) components, each with its own independent functionality. When a function or piece of code from one DLL needs to be copied to another DLL for execution, if the function or code contains relocated data, it can cause the program to crash when the other DLL calls it.

[0003] Therefore, relocation repair needs to be performed in another DLL. In traditional solutions, relocation repair is performed on the same DLL and there has never been a cross-DLL situation. Summary of the Invention

[0004] This invention addresses the problem of cross-DLL relocation in existing technologies by providing a method and system for repairing cross-DLL relocation.

[0005] According to a first aspect of the present invention, a cross-DLL relocation repair method is provided, comprising: when a second DLL is loaded in the system, obtaining a repair timing for relocation data items in copied function code, wherein the copied function code is function code copied from the first DLL to the second DLL; and repairing the relocation data items in the copied function code based on the repair timing.

[0006] Based on the above technical solution, the present invention can also be improved as follows.

[0007] Optionally, when loading the second DLL in the system, obtaining the repair timing of the relocation data items in the copied function code includes: searching for all relocation data items in the relocation table of the second DLL, adding a hook point after the code segment corresponding to the last relocation data item, and when the system has repaired all the relocation data items in the second DLL, the hook point is triggered, thus sensing the repair timing of the copied function code.

[0008] Optionally, adding a Hook point after the code segment corresponding to the last relocated data item includes: detecting the current operating system type and version; querying the corresponding Hook scheme on the server based on the current operating system type and version; and adding a Hook point after the code segment corresponding to the last relocated data item based on the Hook scheme. The server is configured with Hook schemes corresponding to different types and versions of systems.

[0009] Optionally, when loading the second DLL in the system, obtaining the repair timing for relocation data items in the copied function code includes: searching for all relocation data items in the relocation table of the second DLL, setting a hardware write breakpoint after the code segment corresponding to the last relocation data item, and when the system copies function code to the hardware write breakpoint after repairing all relocation data items in the second DLL, the hardware write breakpoint is triggered, thus sensing the repair timing of the copied function code.

[0010] Optionally, the step of repairing the relocation data items in the copied function code based on the repair timing includes: searching for all relocation data items of the copied function code in the relocation table of the first DLL according to the copied function code; for any relocation data item, obtaining the offset address of the relocation data item in the first DLL; calculating the offset address of the relocation data item in the copied function code; calculating the actual memory address of the relocation data item in the second DLL; and calculating the first preset loading address of the relocation data item in the second DLL based on the actual memory address of the relocation data item in the second DLL.

[0011] Optionally, the relocation table stores the memory address of each relocation data item. The step of searching for all relocation data items of the copied function code in the relocation table of the first DLL, based on the copied function code, includes: for any relocation data item in the relocation table, if the memory address of any relocation data item falls between the start and end addresses of the copied function code, then that relocation data item is a relocation data item of the copied function code; traversing all relocation data items in the relocation table to find all relocation data items of the copied function code.

[0012] Optionally, calculating the offset address of any relocation data item in the copied function code includes: obtaining the starting address addrSrc of the first DLL loaded into memory; obtaining the starting address Src_Addr of the copied function code in the first DLL = addrSrc + offset1, where offset1 is the offset address of the copied function code in the first DLL; and calculating the offset address Addr1 of any relocation data item in the copied function code = VirtualAddress - Src_Addr based on the offset address VirtualAddress of any relocation data item in the first DLL and the starting address of the copied function code in the first DLL.

[0013] Optionally, calculating the actual memory address of any relocation data item in the second DLL includes: obtaining the starting address addrDST of the second DLL loaded into memory;

[0014] Obtain the starting memory address of the copied function code in the second DLL, Dst_Addr = addrDst + offset2, where offset2 is the offset address of the copied function code in the second DLL; based on the offset address of any relocation data item in the copied function code, the starting address of the second DLL loaded into memory, addrDST, and the starting memory address of the copied function code in the second DLL, Dst_Addr, calculate the actual memory address of any relocation data item in the second DLL.

[0015] Optionally, calculating the first preset load address of the relocated data item in the second DLL based on the actual memory address of the relocated data item in the second DLL includes: calculating the difference Diff between the starting address of the first DLL loaded into memory and the first preset load address; and calculating the second preset load address of the relocated data item in the second DLL based on the actual memory address of the relocated data item in the second DLL and the difference.

[0016] According to a second aspect of the present invention, a cross-DLL relocation repair system is provided, comprising: an acquisition module, configured to acquire a repair timing for relocation data items in copied function code when a second DLL is loaded in the system, wherein the copied function code is function code copied from a first DLL to a second DLL; and a repair module, configured to repair the relocation data items in the copied function code based on the repair timing.

[0017] According to a third aspect of the present invention, an electronic device is provided, including a memory and a processor, wherein the processor is configured to implement a cross-DLL relocation repair method when executing a computer management program stored in the memory.

[0018] According to a fourth aspect of the present invention, a computer-readable storage medium is provided having a computer management class program stored thereon, which, when executed by a processor, implements the steps of a cross-DLL relocation repair method.

[0019] This invention provides a method and system for cross-DLL relocation repair. When loading a second DLL, a certain method is used to capture the opportunity to relocate and repair the relocation data items of the function code copied from the first DLL. Based on the captured repair opportunity, the cross-DLL relocation data items are repaired, thus realizing the relocation repair of cross-DLL relocation data items. Attached Figure Description

[0020] Figure 1 A flowchart of a cross-DLL relocation repair method provided by the present invention;

[0021] Figure 2 A schematic diagram of a cross-DLL relocation repair system structure provided by the present invention;

[0022] Figure 3 A schematic diagram of the hardware structure of a possible electronic device provided by the present invention;

[0023] Figure 4 This is a schematic diagram of the hardware structure of a possible computer-readable storage medium provided by the present invention. Detailed Implementation

[0024] The specific embodiments of the present invention will be described in further detail below with reference to the accompanying drawings and examples. The following examples are for illustrative purposes only and are not intended to limit the scope of the invention.

[0025] Before describing the embodiments of the present invention, the DLL relocation repair technology will be explained. A DLL is loaded by the program, and at the time of compilation, the default starting address of the DLL loaded into memory is 0x100000. There are some global variables, global functions, etc. in the DLL. If these global variables or global functions are referenced in the code, their addresses will be added to the DLL's relocation table. The relocation table stores all the relocation data.

[0026] Since a DLL cannot be loaded at the default address of 0x100000 during actual loading, if the DLL is loaded at a different address, then all relocation data in the DLL needs to be repaired. Specifically, the relocation data that needs to be repaired is obtained by looking up the relocation table and traversing all the relocation data in the relocation table, and then repairing this relocation data in the DLL.

[0027] For a DLL, when a function uses a global variable, its code will inevitably contain relocation data items, which will be added to the DLL file's relocation table. When the system loads the DLL, it will iterate through the relocation table and correct the data for each relocation item.

[0028] When there are two DLLs, if function code with relocation data is copied from one DLL to the other DLL, the relocation data for that function code is not added to the other DLL, making the function code unusable in the other DLL. Therefore, it is necessary to solve the relocation problem between different DLLs.

[0029] When a function's code from one DLL is copied to another DLL (the original DLL is named DLLSRC, and the copied DLL is named DLLDST), the relocation data entry in the original DLLSRC is not deleted. Meanwhile, the new DLLDST may or may not have its own relocation table. If it has a relocation table, it may not be able to add a relocation data entry because it might be full. If it doesn't have a relocation table, there's no way to add a relocation data entry. Therefore, adding a relocation data entry for a newly copied function to the relocation table of DLLDST can be complex and may require adjustments based on different scenarios.

[0030] Because the copied function code has relocation data items, but these items are not added to the relocation table in DLLDST, when DLLDST is loaded, the system will repair all relocation data items in the DLLDST relocation table, but the relocation data items of the copied function code will not be repaired. If the code in DLLDST calls the copied function code before repairing its relocation data items, it will cause a program error. Therefore, the repair of the relocation data items of the copied function code needs to be performed before any function calls it.

[0031] See Figure 1 This invention provides a flowchart of a cross-DLL relocation repair method according to an embodiment of the present invention. The cross-DLL relocation repair method mainly includes the following steps:

[0032] Step S10: When the second DLL is loaded in the system, obtain the repair timing for the relocation data items in the copied function code, where the copied function code is the function code copied from the first DLL to the second DLL.

[0033] In step S10, when loading the second DLL (DLLDST), the second DLL contains function code copied from the first DLL (DLLSRC). During loading the second DLL, relocation data items in the second DLL need to be repaired. The function code copied from the first DLL (referred to as the copied function code) also contains relocation data items that need repair. Therefore, the timing of repairing the relocation data items of the copied function code in the second DLL is crucial. When the second DLL is loaded into the system, a certain method is used to determine the appropriate time to repair the relocation data items in the copied function code.

[0034] In this step, when the second DLL is loaded, the timing of data relocation repair in the function code copied from the first DLL is captured, thus realizing the function of cross-DLL data repair.

[0035] Step S20: Based on the repair timing, repair the relocated data items in the copied function code.

[0036] In step S10 above, the opportunity to repair the relocation data in the function code copied from the first DLL in the second DLL was obtained. Based on this repair opportunity, this step repairs the relocation data items in the copied function code so as to successfully perform the relocation data of the copied function code in the first DLL in the second DLL.

[0037] In step S10, when loading the second DLL, a certain method is used to capture the opportunity to relocate and repair the relocation data items of the function code copied from the first DLL. In step S20, based on the captured repair opportunity, the relocation data items across DLLs are repaired, thus realizing the relocation and repair of the relocation data items across DLLs. This allows the function code in the first DLL to be called in the second DLL, thereby achieving the implementation of cross-DLL function functionality.

[0038] In this embodiment of the invention, step S10, when loading the second DLL in the system, obtains the repair timing of the relocation data items in the copied function code, including: searching for all relocation data items in the relocation table of the second DLL, adding a Hook point after the code segment corresponding to the last relocation data item, and when the system has repaired all the relocation data items in the second DLL, the Hook point is triggered, and the repair timing of the copied function code is detected.

[0039] It is understandable that when loading the second DLL, since the second DLL contains function code copied from the first DLL, and the function code copied from the first DLL also contains relocation data items, it is crucial to repair the relocation data items in the two DLLs in an orderly manner. The timing of repairing the relocation data items in the first DLL is related to whether the program can load normally.

[0040] Specifically, in the process of capturing the timing of relocation repair of relocation data items for function code copied from the first DLL, the `loadlibrary` function that loads the DLL can be hooked to detect when the system repairs the relocation. The hook point can be placed after the system has loaded the second DLL into memory and completed the repair of the second DLL's relocation data items. The hook function then operates at this point. When the system loads the second DLL, it will repair and relocate all relocation data items of this DLL. Once the repair is complete, the set hook point will be triggered, allowing the repair of the relocation data items for the copied function code to occur within the hook function logic.

[0041] In this step, a hook point is added after the code segment corresponding to the last relocation data item in the second DLL. When the system has repaired all the relocation data items in the second DLL, the hook point is triggered, which then repairs the relocation data items in the first DLL. This allows the second DLL to successfully complete the repair of the relocation data items in both the second and first DLLs after loading, thus enabling the second DLL to load successfully.

[0042] In one possible embodiment, the step of adding a hook point after the code segment corresponding to the last relocated data item in the above steps includes: detecting the current operating system type and version; querying the corresponding hook scheme on the server according to the current operating system type and version; and adding a hook point after the code segment corresponding to the last relocated data item based on the hook scheme. The server is configured with hook schemes corresponding to different types and versions of operating systems.

[0043] Understandably, when using the hook function to capture the timing of the repair of relocation data items in copied function code, it's done by hooking the system function LoadLibrary. This allows the hook to precisely detect when all relocation data items in the second DLL have been repaired. However, hooking the LoadLibrary function requires consideration of practical realities. Different operating systems have different internal implementations of the LoadLibrary function, and these differences must be taken into account. Furthermore, there's the possibility of adapting to newer operating systems in the future. Therefore, hooking is closely related to the operating system version, and all hooks must consider the system version.

[0044] Based on this, this step detects the current operating system type and version when the system loads the second DLL. According to the current operating system type and version, it queries the server for the corresponding Hook scheme and adds a hook point after the code segment corresponding to the last relocated data item based on the Hook scheme. Specifically, different Hook schemes are configured on the server for different operating systems and different operating system versions.

[0045] In one possible embodiment, step S10, when loading the second DLL in the system, involves obtaining the timing for repairing relocation data items in the copied function code by: searching for all relocation data items in the relocation table of the second DLL, setting a hardware write breakpoint after the code segment corresponding to the last relocation data item, and when the system copies function code to the hardware write breakpoint after repairing all relocation data items in the second DLL, the hardware write breakpoint is triggered, thus sensing the timing for repairing the copied function code.

[0046] It is understandable that in step S10, when the second DLL is loaded into the system, the method used to obtain the repair timing for the relocation data items in the copied function code can include various methods. Among them, the above step is to search for all relocation data items in the relocation table of the second DLL and add a hook point after the code segment corresponding to the last relocation data item. However, hooking the system function Loadlibrary requires consideration of the actual situation. The actual situation is that different systems have some differences in the internal implementation of the Loadlibrary function, and these differences need to be taken into account. At the same time, there is also the possibility that new systems will be released in the future, and adaptation to the new systems will be required. Therefore, its hook is closely related to the operating system version. All hooks need to take the system version into account and different hook schemes need to be configured based on different versions of the operating system, which is quite cumbersome.

[0047] Therefore, this step utilizes hardware write breakpoints to determine the timing of code repair for the copied function. For all relocation data items in the second DLL, repairing the last relocation data item indicates the end of the DLL's relocation repair function. By setting a hardware write breakpoint at this point, the breakpoint will be triggered when the system writes data to it. This timing ensures that the relocation repair timing is precise, neither too early nor too late, thus maximizing the correctness of the relocation repair function.

[0048] Specifically, the system searches the relocation table of the second DLL for all relocation data items, locates the last relocation data item, finds the code segment corresponding to that last relocation data item, and sets a hardware write breakpoint at that code segment. When the system has repaired all the relocation data items in the second DLL, the hardware write breakpoint is triggered, allowing the repair of the relocation data items of the copied function code.

[0049] The specific implementation of setting a hardware write breakpoint involves registering an exception by calling the API function AddVectoredExceptionHandler. The function is PVOID WINAPIAddVectoredExceptionHandler(

[0050] ULONG FirstHandler,

[0051] PVECTORED_EXCEPTION_HANDLERVectoredHandler);

[0052] The FirstHandler setting is 0, indicating that this registered exception handling function will take over the exception after the best relocated data item has been repaired.

[0053] Since system repair and relocation may be performed in any thread of the process, hardware write breakpoints need to be set for all threads. This can be achieved by traversing all threads to obtain their handles. The method for setting hardware write breakpoints in each thread is as follows: For each thread, first, the thread's context information is obtained by calling the API function GetThreadContext. The parameter CONTEXT_DEBUG_REGISTERS passed to the GetThreadContext function indicates the register information of the thread context. The four registers for CPU hardware breakpoints are Dr0, Dr1, Dr2, and Dr3.

[0054] In this embodiment of the invention, memory read / write access is selected for Dr0. Therefore, ctx.Dr0 = Reloc_Address needs to be set, where Reloc_Address is the memory address of the data item to be relocated. ctx.Dr7| = 0xd0501, this value indicates that only write breakpoints are monitored. After setting the register values, the API function SetThreadContext is called to set the register values ​​into the thread's context. Once this function is called, monitoring of access to the set memory address begins. When a hardware write breakpoint is triggered, the previously written exception handling function AddVectoredExceptionHandler is called to register the exception handling function.

[0055] Therefore, a hardware write breakpoint exception handling function `void Handler(){` can be written. This function will be called when an exception occurs, triggering the system's repair and relocation functionality. Therefore, the relocated data items of the copied function code can be repaired here.}

[0056] In this step, hardware write breakpoints are set to obtain the repair timing of the copied function code. Regardless of the differences in the operating system, hardware write breakpoints can be set to accurately capture the repair timing of the copied function code when the second DLL is loaded.

[0057] Step S20, based on the repair timing, repairs the relocated data items in the copied function code, including:

[0058] Step S201: Based on the copied function code, search for all relocation data items of the copied function code in the relocation table of the first DLL.

[0059] It is understood that the above embodiments introduce two repair timings for capturing relocation data items of copied function code. When the repair timing arrives, the relocation data items of the function code copied from the first DLL in the second DLL are repaired.

[0060] In step S201, since the relocation table of the second DLL (DLLDST) does not store the relocation data items from the first DLL, it is necessary to search for relocation data in the original DLLSRC's relocation table. Specifically, the relocation table of the original first DLL is used to query which relocation data items exist in the copied function code. This query is performed by traversing the relocation table of the first DLL, which stores the memory addresses of the relocation data items for all function code. Based on the memory address of each relocation data item, it is determined whether it falls within the address range between the start and end addresses of the copied function code. If it does, the relocation data item is a relocation data item of the copied function code; otherwise, it is not. Finally, after traversing all the relocation data items, all the relocation data items of the copied function code can be obtained.

[0061] Step S202: For any relocation data item, obtain the offset address of the relocation data item in the first DLL; calculate the offset address of the relocation data item in the copied function code.

[0062] In step S202, when calculating the offset address of any relocation data item in the copied function code, the starting address addrSrc of the first DLL loaded into memory is obtained; the starting address Src_Addr of the copied function code in the first DLL is obtained as addrSrc + offset1, where offset1 is the offset address of the copied function code in the first DLL; based on the offset address VirtualAddress of any relocation data item in the first DLL and the starting address of the copied function code in the first DLL, the offset address Addr1 of the relocation data item in the copied function code is calculated as VirtualAddress - Src_Addr.

[0063] Step S203: Calculate the actual memory address of any relocated data item in the second DLL.

[0064] In step S203, calculating the actual memory address of any relocation data item in the second DLL includes: obtaining the starting address addrDST of the second DLL loaded into memory; obtaining the starting memory address Dst_Addr of the copied function code in the second DLL = addrDst + offset2, where offset2 is the offset address of the copied function code in the second DLL; and calculating the actual memory address of the any relocation data item in the second DLL based on the offset address of the relocation data item in the copied function code, the starting address addrDST of the second DLL loaded into memory, and the starting memory address Dst_Addr of the copied function code in the second DLL.

[0065] Step S204: Based on the actual memory address of any relocated data item in the second DLL, calculate the first preset load address of any relocated data item in the second DLL.

[0066] In step S204, the difference Diff between the starting address of the first DLL loaded into memory and the first preset loading address is calculated; based on the actual memory address of any relocation data item in the second DLL and the difference, the second preset loading address of any relocation data item in the second DLL is calculated.

[0067] Based on the second preset load address of any relocation data item in the second DLL calculated in step S204, each relocation data item of the copied function code is repaired. The repair mainly includes the following steps:

[0068] (1) Obtain the starting address of DLLSRC loaded into memory.

[0069] DWORD addrSrc = GetModuleHandle(“DLLSRC”); By passing the name of DLLSRC to the system function GetModuleHandle, you can obtain the starting address of DLLSRC.

[0070] (2) Obtain the starting address of the copied function code in DLLSRC.

[0071] We need to obtain the starting address of the function code copied into DLLDST within DLLSRC to facilitate subsequent calculations of relocation data. This starting address is represented by the variable `Src_Addr`. This can be obtained by looking at the offset address of the copied function code in DLLSRC and then adding it to the starting address of DLLSRC. The formula is: `Src_Addr = addrSrc + offset1`, where `offset1` is the offset address of the copied function code in DLLSRC.

[0072] (3) Obtain the starting address of DLLDST loaded into memory.

[0073] DWORD addrDst = GetModuleHandle(“DLLDST”); By passing the name of DLLDST to the system function GetModuleHandle, the starting address of DLLDST can be obtained.

[0074] (4) Obtain the starting memory address of the copy function code in DLLDST.

[0075] Since the copied function code is copied from DLLSRC to DLLDST, the starting memory address in DLLDST can be recorded during the copying process. Specifically, if a code segment is added to DLLDST, the function can be copied to the starting address of this new code segment. Obtaining the starting address of this newly added code segment in DLLDST yields the address of the copied function code. Therefore, a variable Dst_Addr = addrDst + offset2 is set, where Dst_Addr is the starting memory address of the copied function code in DLLDST, addrDst is the starting address of DLLDST when loaded into memory, and offset2 is the offset address of the copied function code in DLLDST.

[0076] (5) Calculation of specific relocation for each relocated data item:

[0077] First, it's necessary to calculate the difference between the actual address of the DLLSRC after it's loaded into memory and the default load address set during compilation. The default load address of the DLLSRC can be obtained by parsing this field from the DLLSRC's format header; its value is OptionalHeader.ImageBase, which is the module's default load address.

[0078] Diff=addrSrc-OptionalHeader.ImageBase;

[0079] Where addrSrc is the starting address of DLLSRC when it is actually loaded into memory. By subtracting the two values, we can obtain their relative difference, Diff.

[0080] This difference is the difference that needs to be corrected for each relocation data item in the copied function code. At the same time, the relocation data item of the copied function code represents the global variables or global functions in DLLSRC that it uses. Therefore, the repair of the relocation data items also needs to be repaired according to the use of global variables in DLLSRC. The result of the repair is that although the copied function code is in DLLDST, the global variables or global functions inside its function still call those in DLLSRC.

[0081] The repair calculation for each relocation data item is as follows: VirtualAddress represents the offset address of the relocation data item relative to the DLL. This address is the offset address of the relocation data item relative to DLLSRC. Since this function has been copied to DLLDST, it is necessary to calculate the position of the relocation data item in DLLDST.

[0082] The specific calculation formula is as follows: Calculate the offset address of any relocated data item in the copied function, Addr1 = VirtualAddress - Src_Addr, and calculate Addr1. Then calculate the actual address of the relocated data item in DLLDST, Addr2 = Addr1 + addrDST + Dst_Addr, where addrDST represents the actual starting address of DLLDST loaded into memory, and Dst_Addr is the offset address of the copied function code in DLLDST.

[0083] Since there is a certain difference between the actual load address and the preset load address, the preset load address of the relocation data item in DLLDST is *Addr2 = Addr2 + Diff, thus obtaining the final relocation repair address of the relocation data item.

[0084] For all relocated data items in the copied function code, the above method is used to calculate the repaired address in DLLDST, thereby repairing all relocated data items in the copied function code and realizing the relocation repair of all relocated data items in the copied function code.

[0085] This invention provides a method for relocating and repairing cross-DLL data items. When loading a second DLL, a certain method is used to capture the opportunity to relocate and repair the relocation data items of the function code copied from the first DLL. Based on the captured repair opportunity, the relocation data items of cross-DLL data items are repaired, thereby realizing the relocation and repair of cross-DLL data items.

[0086] When loading the second DLL into the system, two different methods are provided to obtain the repair timing of the relocation data items in the copied function code. One method involves adding a hook point to the code of the second DLL to capture the repair timing of the relocation data items in the copied function code, and the other method involves setting a hardware write breakpoint at the code containing the last relocation data item in the second DLL to obtain the repair timing of the relocation data items in the copied function code. The appropriate method can be used to capture the repair timing depending on the situation.

[0087] Figure 2 A cross-DLL relocation repair system structure diagram is provided as an embodiment of the present invention, such as... Figure 2 As shown, a cross-DLL relocation repair system includes an acquisition module 201 and a repair module 202, wherein:

[0088] The acquisition module 201 is used to acquire the repair timing of relocation data items in the copied function code when the second DLL is loaded in the system, wherein the copied function code is the function code copied from the first DLL to the second DLL;

[0089] Repair module 202 is used to repair the relocated data items in the copied function code based on the repair timing.

[0090] It is understood that the cross-DLL relocation repair system provided by the present invention corresponds to the cross-DLL relocation repair method provided in the foregoing embodiments. The relevant technical features of the cross-DLL relocation repair system can be referred to the relevant technical features of the cross-DLL relocation repair method, and will not be repeated here.

[0091] Please see Figure 3 , Figure 3 This is a schematic diagram illustrating an embodiment of the electronic device provided in this invention. For example... Figure 3 As shown, an embodiment of the present invention provides an electronic device, including a memory 310, a processor 320, and a computer program 311 stored in the memory 310 and executable on the processor 320. When the processor 320 executes the computer program 311, it performs the following steps: when a second DLL is loaded in the system, it obtains the repair opportunity for relocation data items in the copied function code, wherein the copied function code is function code copied from the first DLL to the second DLL; based on the repair opportunity, it repairs the relocation data items in the copied function code.

[0092] Please see Figure 4 , Figure 4This is a schematic diagram illustrating an embodiment of a computer-readable storage medium provided by the present invention. (See diagram below.) Figure 4 As shown, this embodiment provides a computer-readable storage medium 400, on which a computer program 411 is stored. When the computer program 411 is executed by a processor, it performs the following steps: when a second DLL is loaded in the system, it obtains the repair opportunity for relocation data items in the copied function code, wherein the copied function code is the function code copied from the first DLL to the second DLL; based on the repair opportunity, it repairs the relocation data items in the copied function code.

[0093] It should be noted that the descriptions of each embodiment in the above embodiments have different focuses. For parts that are not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.

[0094] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0095] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0096] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0097] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0098] Although preferred embodiments of the invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including both the preferred embodiments and all changes and modifications falling within the scope of the invention.

[0099] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of the claims of this invention and their equivalents, this invention also intends to include these modifications and variations.

Claims

1. A method for relocation repair across DLLs, characterized in that, include: When the second DLL is loaded in the system, the timing for repairing the relocated data items in the copied function code is obtained, wherein the copied function code is the function code copied from the first DLL to the second DLL; Based on the aforementioned repair timing, the relocated data items in the copied function code are repaired; The method for determining the timing of repairing relocated data items in the copied function code when a second DLL is loaded into the system includes: Search for all relocation data items in the relocation table of the second DLL, and add a hook point after the code segment corresponding to the last relocation data item. When the system has repaired all the relocation data items in the second DLL, the hook point is triggered, and the repair timing of the copied function code is detected. The repair of relocated data items in the copied function code based on the repair timing includes: Based on the copied function code, search for all relocation data items of the copied function code in the relocation table of the first DLL; For any relocation data item, obtain the offset address of the relocation data item in the first DLL; Calculate the offset address of any of the relocated data items in the copied function code; Calculate the actual memory address of any of the relocated data items in the second DLL; Based on the actual memory address of any one of the relocation data items in the second DLL, calculate the first preset loading address of any one of the relocation data items in the second DLL; The relocation table stores the memory address of each relocation data item. The step of searching for all relocation data items of the copied function code in the relocation table of the first DLL, based on the copied function code, includes: For any relocation data item in the relocation table, if the memory address of any relocation data item falls between the start address and the end address of the copied function code, then any relocation data item is the relocation data item of the copied function code. Traverse all relocation data items in the relocation table to find all relocation data items of the copied function code.

2. The repositioning and repair method according to claim 1, characterized in that, Adding a hook point after the code segment corresponding to the last relocated data item includes: The system detects the current operating system type and version, queries the server for the corresponding Hook solution based on the current operating system type and version, and adds a Hook point after the code segment corresponding to the last relocated data item based on the Hook solution. The server is configured with Hook solutions corresponding to different types and versions of systems.

3. The repositioning and repair method according to claim 1, characterized in that, The method for determining the timing of repairing relocated data items in the copied function code when a second DLL is loaded into the system includes: In the relocation table of the second DLL, all relocation data items are searched. A hardware write breakpoint is set after the code segment corresponding to the last relocation data item. When the system copies function code to the hardware write breakpoint after repairing all relocation data items in the second DLL, the hardware write breakpoint is triggered, and the repair timing of the copied function code is detected.

4. The repositioning and repair method according to claim 1, characterized in that, The calculation of the offset address of any relocated data item in the copied function code includes: Get the starting address (addrSrc) of the first DLL loaded into memory; Get the starting address of the copied function code in the first DLL: Src_Addr = addrSrc + offset1, where offset1 is the offset address of the copied function code in the first DLL; Based on the offset address VirtualAddress of any relocation data item in the first DLL and the starting address of the copied function code in the first DLL, calculate the offset address Addr1 of any relocation data item in the copied function code as VirtualAddress - Src_Addr.

5. The repositioning and repair method according to claim 4, characterized in that, The calculation of the actual memory address of any relocation data item in the second DLL includes: Get the starting address (addrDST) of the second DLL loaded into memory; Get the starting memory address of the copied function code in the second DLL: Dst_Addr = addrDST + offset2, where offset2 is the offset address of the copied function code in the second DLL; Based on the offset address of any relocation data item in the copied function code, the starting address addrDST of the second DLL loaded into memory, and the starting address Dst_Addr of the copied function code in the second DLL, calculate the actual memory address of any relocation data item in the second DLL.

6. The repositioning and repair method according to claim 5, characterized in that, The step of calculating the first preset load address of any relocation data item in the second DLL based on the actual memory address of the relocation data item in the second DLL includes: Calculate the difference, Diff, between the starting address of the first DLL loaded into memory and the first preset loading address; Based on the actual memory address of any relocation data item in the second DLL and the difference, calculate the second preset loading address of any relocation data item in the second DLL.

Citation Information

Patent Citations

  • DLL file processing method and related device

    CN110298175A