WO2016101503A1 - Hot patching realization method and apparatus - Google Patents

Hot patching realization method and apparatus Download PDF

Info

Publication number
WO2016101503A1
WO2016101503A1 PCT/CN2015/078896 CN2015078896W WO2016101503A1 WO 2016101503 A1 WO2016101503 A1 WO 2016101503A1 CN 2015078896 W CN2015078896 W CN 2015078896W WO 2016101503 A1 WO2016101503 A1 WO 2016101503A1
Authority
WO
WIPO (PCT)
Prior art keywords
file
function
executable file
patch
information
Prior art date
Application number
PCT/CN2015/078896
Other languages
French (fr)
Chinese (zh)
Inventor
魏煜帆
刘爱丽
朱怀云
于光波
熊珍
Original Assignee
中兴通讯股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 中兴通讯股份有限公司 filed Critical 中兴通讯股份有限公司
Publication of WO2016101503A1 publication Critical patent/WO2016101503A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating

Definitions

  • the present invention relates to the field of communications, and in particular, to a method and an apparatus for implementing a hot patch.
  • Hot patching is a quick, low-cost way to fix product software bugs. Compared with the upgraded software version, the main advantage of the hot patch is that it will not interrupt the current running of the device, that is, the defect of the current software version of the device can be repaired without restarting the device.
  • Hot patch processing is basically based on functions, that is, by repairing a function that has a vulnerability or needs to be replaced, to fix the current software version. That is, the hot patch works by replacing the first instruction of the patched function with the instruction that jumps to the replacement function, causing the program to jump to the location where the new function (replacement function) is located, when replacing the patch in the function. After the code is executed, it returns to the code that calls the old function, thus completing the entire calling process.
  • the hot patch method disclosed in the related art is divided into two steps: 1) First, on the host, a patching tool is used to create a redirectable hot patch file according to the hot patch source. 2) Then download the hot patch file to the target machine, and the patch control module on the target machine loads the system file and the hot patch file of the target machine, and relocates according to the symbol table provided by the system file to generate a final target hot patch file, 3 Finally, the target hot patch file is activated, and the target system is started from the entry of the target system file.
  • the implementation of the hot patch will cause a waste of memory space, and also increase the complexity of the loading process. Even multiple copies of the same function or variable in memory may cause inconsistency in function calls or variable references, which may result in serious system breakdown.
  • the embodiment of the invention provides a method and a device for implementing a hot patch.
  • the technical problem to be solved is how to reduce the complexity of reducing the patch loading.
  • the embodiment of the present invention provides the following technical solutions:
  • a method for implementing a hot patch includes: obtaining file information of a replacement function from a patch object file, where the replacement function is used to replace a function that needs to be patched on the target side; and according to the file information, the patch is required
  • the function generates a new executable file; determines address information corresponding to the new executable file when the target side runs; generates, according to the address information, when the new executable file runs on the target side Corresponding replacement instruction information; notifying the target side to run the new executable file by using the replacement instruction information.
  • the file information of the replacement function includes file information obtained by performing an extraction operation of the .text.bss.rodata.data segment on the patch object file.
  • generating, according to the file information, a new executable file for the function to be patched comprising: generating a structure file of the new executable file by using the file information; and adjusting a function call in the structure file Relationship and a reference relationship of the variable; after completing the adjustment operation, generating a section header table of the executable file, and obtaining the new executable file according to the section header table of the executable file.
  • Determining address information corresponding to the new executable file when the target file is run including: obtaining a symbol table and a corresponding symbol address table; and according to the symbol address table, weighting the symbol address in the executable file Positioned as a memory call address.
  • the starting position of the executable file is run, and after the replacement function is executed, it returns to the function that calls the function that needs to be replaced.
  • An apparatus for implementing a hot patch comprising: an obtaining module, configured to obtain file information of a replacement function from a patch object file, wherein the replacement function is used to replace a function requiring a patch on a target side; the first generating module is set to And generating, according to the file information, a new executable file for the function that needs to be patched; the determining module is configured to determine address information corresponding to when the new executable file runs on the target side; and a second generating module, Is configured to generate corresponding replacement instruction information when the new executable file is run on the target side according to the address information; and the notification module is configured to notify the target side to run the new by using the replacement instruction information Executable file.
  • the file information of the replacement function includes file information obtained by performing an extraction operation of the .text.bss.rodata.data segment on the patch object file.
  • the first generation module includes: a first generation unit configured to generate a structure file of the new executable file by using the file information; and an adjustment unit configured to adjust a call relationship of a function in the structure file and a reference relationship of the variable; the second generating unit is configured to generate a section header table of the executable file after completing the adjusting operation, and obtain the new executable file according to the section header table of the executable file.
  • the determining module includes: an obtaining unit, configured to acquire a symbol table and a corresponding symbol address table; and a relocating unit configured to relocate the symbol address in the executable file to a memory calling address according to the symbol address table .
  • the second generation module is further configured to: jump to the start position of the executable file by replacing the first instruction of the function requiring the patch, and return to the call after the replacement function is executed.
  • the function of the function that needs to be replaced is further configured to: jump to the start position of the executable file by replacing the first instruction of the function requiring the patch, and return to the call after the replacement function is executed.
  • the function of the function that needs to be replaced is further configured to: jump to the start position of the executable file by replacing the first instruction of the function requiring the patch, and return to the call after the replacement function is executed.
  • the function of the function that needs to be replaced.
  • Embodiments of the present invention also provide a computer program, including program instructions, that when executed by a computer, cause the computer to perform the above method.
  • Embodiments of the present invention also provide a computer readable storage medium carrying the above computer program.
  • the embodiment provided by the present invention extracts the code segment and the data segment of the entire object file from the related art, and then constructs the target hot patch file, and compares the implementation manner of writing all the memory space when the hot patch is loaded.
  • the embodiment of the present invention only generates a patch file for a function that needs to be patched, which not only reduces the size of the patch, but also reduces the reserved memory space required for loading the patch, and is convenient for management, avoiding inconsistency of function calls, and reducing the patch.
  • the purpose of loading complexity is not only reduces the size of the patch, but also reduces the reserved memory space required for loading the patch, and is convenient for management, avoiding inconsistency of function calls, and reducing the patch.
  • FIG. 1 is a schematic flowchart diagram of a method for implementing a hot patch according to an embodiment of the present disclosure
  • FIG. 2 is a schematic diagram of a target side management patch according to an embodiment of the present invention.
  • FIG. 3 is a schematic flowchart diagram of an apparatus for implementing a hot patch according to an embodiment of the present invention.
  • FIG. 1 is a schematic flowchart diagram of a method for implementing a hot patch according to an embodiment of the present invention.
  • the method embodiment shown in Figure 1 includes:
  • Step 101 Obtain file information of a replacement function from a patch object file, where the replacement function is used to replace a function that needs to be patched on the target side;
  • Step 102 Generate a new executable file for the function that requires a patch according to the file information.
  • Step 103 Determine address information corresponding to the new executable file running on the target side
  • Step 104 Generate corresponding replacement instruction information for the new executable file to run on the target side according to the address information.
  • Step 105 Notify the target side to run the new executable file by using the replacement instruction information.
  • the code segment and the data segment of the entire object file are extracted, and then constructed into a target hot patch file, and compared to the implementation manner in which the hot patch is all written into the memory space,
  • the embodiment of the invention only generates a patch file for the function that needs to be patched, which not only reduces the size of the patch, but also reduces the reserved memory space required for loading the patch, and is convenient for management, avoiding inconsistency of function calls, and reducing patch loading.
  • the purpose of complexity is not only reduces the size of the patch, but also reduces the reserved memory space required for loading the patch, and is convenient for management, avoiding inconsistency of function calls, and reducing patch loading.
  • step 101 when the software patch is created, the patch source file is first analyzed according to the source file to be patched (the patch source file is compiled as a patch target file), and the patch object file is made to .text.bss.rodata.
  • the extraction operation of the .data segment obtains the file information.
  • Step 102 generating, according to the file information, a new function for the function that requires a patch.
  • Executable files including:
  • the new executable file is obtained according to the section header table of the executable file.
  • a new executable file is obtained according to the section header table of the executable file, including:
  • Step 103 The determining the address information corresponding to the new executable file when the target file is run includes:
  • the address of the relocation symbol is completed on the host side, and the symbol information of the target version is first analyzed, and the symbol information is generated into an index table, where the index table includes a symbol address, the symbol includes: a global variable, a global function, a static variable, a static function, and Static local variables, and then find the symbol to be relocated in the index table to obtain the actual real address.
  • Analyze the new ELF file find the relocation symbol address in the ELF object file by looking up the real address of the symbol in the image file, complete the relocation work, and determine the function call and the variable address.
  • the symbol address referenced in the input object file is relocated to the real memory address of the symbol.
  • step 104 the generating, according to the address information, the corresponding replacement instruction information for the new executable file when the target file is run, including: replacing the first instruction of the function that requires the patch by replacing To jump to the starting position of the executable file run, and after the replacement function is executed, return to the function that calls the function that needs to be replaced.
  • a replacement function table is generated according to the source address and the target address of the replacement function, and the target machine side performs an instruction jump operation.
  • the source address is the symbol address before the patch is modified
  • the target address is the modified symbol address of the patch, which is located in the patch area.
  • the instruction list is replaced by the host side constructor according to the reserved patch area address.
  • the jump instruction is constructed according to different CPU architectures. The main working principle is that by replacing the first instruction of the original old function, the instruction jumps to the new function, so that the program jumps to the position where the new function is located, and when the patch code in the new function is executed, Go to the code that calls the old function and complete the entire call process.
  • the relocation symbol is relocated on the host side, the symbol table in the original image file is analyzed, a corresponding address correspondence table is generated for different types of symbols, and then the relocation symbol address of the target file is searched.
  • FIG. 2 is a schematic diagram of a target side management patch according to an embodiment of the present invention.
  • the target side implements loading, activation, patch automatic activation, deactivation, and uninstallation of the patch.
  • the state transition control is operated in a command-driven manner and controlled by the state machine to ensure the correct state transition. described as follows:
  • Patch loading process First, determine whether the patch and the version number of the system software are consistent. If they are inconsistent, directly exit. If they are consistent, load the patch file into the flash, and then read the function replacement table in the file and load the patch as needed. The address of the reserved area, the code segment of the replacement function, the read-only data segment is written into the memory. After the patch is loaded, the status of the patch is inactive and the status of the patch is written to the corresponding configuration file.
  • Patch activation Replace the table according to the instruction, change the instruction at the patch function address to the instruction to jump to the replacement function, and write the status of the patch to the configuration file.
  • the patch is automatically activated: the patch status is changed to the automatic activation state and saved in the patch configuration file. The patch will continue to take effect the next time it is restarted, and the status of the patch is written to the configuration file.
  • Patch deactivation Replace the table with the instruction, and replace the jump instruction at the patch function address with the original instruction. After successful, the patch status is changed to inactive and the status of the patch is written to the configuration file.
  • Patch unloading release the flash space occupied by the patch file, and the memory space, and replace the jump instruction at the patch function address with the original instruction, and write the status of the patch to the configuration file.
  • Patch status query By reading the configuration file, you can view the status of the current patch.
  • the hot patching method provided by the embodiment of the present invention can still modify the related process according to the patching manner of the related art. Therefore, the solution provided by the embodiment of the present invention has strong applicability.
  • FIG. 3 is a schematic structural diagram of an apparatus for implementing a hot patch according to an embodiment of the present invention.
  • the apparatus shown in FIG. 3 includes:
  • the obtaining module 301 is configured to obtain file information of the replacement function from the patch object file, where the replacement function is used to replace the function that needs to be patched on the target side;
  • the first generating module 302 is configured to generate a new executable file for the function requiring the patch according to the file information
  • a determining module 303 configured to determine address information corresponding to when the new executable file runs on the target side
  • the second generation module 304 is configured to generate corresponding replacement instruction information when the new executable file is run on the target side according to the address information;
  • the notification module 305 is configured to notify the target side to run the new executable file by using the replacement instruction information.
  • the file information of the replacement function includes an extraction operation of the .text.bss.rodata.data segment of the target file, and the file information is obtained.
  • the first generation module 302 includes:
  • a first generating unit configured to generate a structural file of the new executable file by using the file information
  • An adjusting unit connected to the first generating unit, configured to adjust a calling relationship of a function in the structure file and a reference relationship of the variable;
  • the second generating unit is connected to the adjusting unit, and is configured to generate a section header table of the executable file after completing the adjusting operation, and obtain the new executable file according to the section header table of the executable file.
  • the determining module 303 includes:
  • Obtaining a unit configured to obtain a symbol table and a corresponding symbol address table
  • the relocation unit is configured to relocate the symbol address in the executable file to a memory call address according to the symbol address table.
  • the second generation module 304 is configured to:
  • the first instruction that replaces the function requiring the patch is to jump to the start position of the executable file, and after the replacement function is executed, returns to the function that calls the function that needs to be replaced.
  • the code segment and the data segment of the entire object file are extracted, and then constructed into a target hot patch file, and compared to the implementation manner in which the hot patch is all written into the memory space,
  • the embodiment of the invention only generates a patch file for the function that needs to be patched, which not only reduces the size of the patch, but also reduces the reserved memory space required for loading the patch, and is convenient for management, avoiding inconsistency of function calls, and reducing patch loading.
  • the purpose of complexity is not only reduces the size of the patch, but also reduces the reserved memory space required for loading the patch, and is convenient for management, avoiding inconsistency of function calls, and reducing patch loading.
  • all or part of the steps of the above embodiments may also be implemented by using an integrated circuit. These steps may be separately fabricated into individual integrated circuit modules, or multiple modules or steps may be fabricated into a single integrated circuit module. achieve. Thus, the invention is not limited to any specific combination of hardware and software.
  • the devices/function modules/functional units in the above embodiments may be implemented by a general-purpose computing device, which may be centralized on a single computing device or distributed over a network of multiple computing devices.
  • each device/function module/functional unit in the above embodiment When each device/function module/functional unit in the above embodiment is implemented in the form of a software function module and sold or used as a stand-alone product, it can be stored in a computer readable storage medium.
  • the above mentioned computer readable storage medium may be a read only memory, a magnetic disk or an optical disk or the like.
  • the above embodiment only generates a patch file for the function that needs to be patched, which not only reduces the size of the patch, but also reduces the reserved memory space required for loading the patch, and is convenient for management, avoiding inconsistency of function calls, and reducing patch loading.
  • the purpose of complexity is only generates a patch file for the function that needs to be patched, which not only reduces the size of the patch, but also reduces the reserved memory space required for loading the patch, and is convenient for management, avoiding inconsistency of function calls, and reducing patch loading.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)
  • Debugging And Monitoring (AREA)

Abstract

Disclosed are a hot patching realization method and apparatus. The method comprises: acquiring file information of a substitute function from a target file, wherein the substitute function is used for substituting a function requiring patching on a target side; generating a new executable file for the function requiring patching according to the file information; determining corresponding address information of the new executable file when run on the target side; according to the address information, generating corresponding substitution command information for the new executable file when run on the target side; and notifying the target side to utilize the substitution command information to run the new executable file.

Description

一种热补丁的实现方法和装置Method and device for implementing hot patch 技术领域Technical field
本发明涉及通信领域,尤其涉及一种热补丁的实现方法和装置。The present invention relates to the field of communications, and in particular, to a method and an apparatus for implementing a hot patch.
背景技术Background technique
热补丁是一种快速、低成本修复产品软件版本缺陷的方式。与升级软件版本相比,热补丁的主要优势是不会使设备当前正在运行的业务中断,即在不重启设备的情况下,可以对设备当前软件版本的缺陷进行修复。热补丁的处理方式基本是以函数为单位,即通过对出现漏洞或者需要替换的函数进行修复,以实现对当前软件版本的修复。即,热补丁的工作原理是通过替换被补丁函数的第一条指令为跳转到替换函数中的指令,使程序跳转到新函数(替换函数)所在位置处执行,当替换函数中的补丁代码执行完毕后,回到调用老函数的代码中,从而完成整个调用过程。Hot patching is a quick, low-cost way to fix product software bugs. Compared with the upgraded software version, the main advantage of the hot patch is that it will not interrupt the current running of the device, that is, the defect of the current software version of the device can be repaired without restarting the device. Hot patch processing is basically based on functions, that is, by repairing a function that has a vulnerability or needs to be replaced, to fix the current software version. That is, the hot patch works by replacing the first instruction of the patched function with the instruction that jumps to the replacement function, causing the program to jump to the location where the new function (replacement function) is located, when replacing the patch in the function. After the code is executed, it returns to the code that calls the old function, thus completing the entire calling process.
相关技术中公开了的热补丁方法分为两步骤执行:1)首先在主机上,用补丁制作工具根据热补丁源码制作出可重定向的热补丁文件。2)然后将该热补丁文件下载到目标机上,目标机上的补丁控制模块加载目标机的系统文件和热补丁文件,根据系统文件提供的符号表进行重定位,生成最终的目标热补丁文件,3)最后激活目标热补丁文件,从目标机的系统文件的入口启动目标机系统。The hot patch method disclosed in the related art is divided into two steps: 1) First, on the host, a patching tool is used to create a redirectable hot patch file according to the hot patch source. 2) Then download the hot patch file to the target machine, and the patch control module on the target machine loads the system file and the hot patch file of the target machine, and relocates according to the symbol table provided by the system file to generate a final target hot patch file, 3 Finally, the target hot patch file is activated, and the target system is started from the entry of the target system file.
热补丁的实现方法会造成内存空间的浪费,也会增加加载过程的复杂度,甚至同一个函数或变量在内存中有多个拷贝,可能会造成函数调用或变量引用的不一致,严重的会导致系统崩溃。The implementation of the hot patch will cause a waste of memory space, and also increase the complexity of the loading process. Even multiple copies of the same function or variable in memory may cause inconsistency in function calls or variable references, which may result in serious system breakdown.
发明内容Summary of the invention
本发明实施例提供一种热补丁的实现方法和装置,要解决的技术问题是如何减少降低补丁加载的复杂度。The embodiment of the invention provides a method and a device for implementing a hot patch. The technical problem to be solved is how to reduce the complexity of reducing the patch loading.
为解决上述技术问题,本发明实施例提供了如下技术方案: In order to solve the above technical problem, the embodiment of the present invention provides the following technical solutions:
一种热补丁的实现方法,包括:从补丁目标文件中获取替换函数的文件信息,其中所述替换函数用于替换目标侧上需要补丁的函数;根据所述文件信息,为所述需要补丁的函数生成新的可执行文件;确定所述新的可执行文件在所述目标侧运行时对应的地址信息;根据所述地址信息,为所述新的可执行文件在所述目标侧运行时生成对应的替换指令信息;通知所述目标侧利用所述替换指令信息运行所述新的可执行文件。A method for implementing a hot patch includes: obtaining file information of a replacement function from a patch object file, where the replacement function is used to replace a function that needs to be patched on the target side; and according to the file information, the patch is required The function generates a new executable file; determines address information corresponding to the new executable file when the target side runs; generates, according to the address information, when the new executable file runs on the target side Corresponding replacement instruction information; notifying the target side to run the new executable file by using the replacement instruction information.
其中,所述替换函数的文件信息包括通过对补丁目标文件做.text.bss.rodata.data段的提取操作,得到的文件信息。The file information of the replacement function includes file information obtained by performing an extraction operation of the .text.bss.rodata.data segment on the patch object file.
其中,根据所述文件信息,为所述待补丁的函数生成新的可执行文件,包括:利用所述文件信息生成所述新的可执行文件的结构文件;调整所述结构文件中函数的调用关系以及变量的引用关系;在完成调整操作后,生成所述可执行文件的节头表,根据所述可执行文件的节头表得到所述新的可执行文件。And generating, according to the file information, a new executable file for the function to be patched, comprising: generating a structure file of the new executable file by using the file information; and adjusting a function call in the structure file Relationship and a reference relationship of the variable; after completing the adjustment operation, generating a section header table of the executable file, and obtaining the new executable file according to the section header table of the executable file.
其中,确定所述新的可执行文件在所述目标文件运行时对应的地址信息,包括:获取符号表以及对应的符号地址表;根据符号地址表,把所述可执行文件中的符号地址重定位成内存调用地址。Determining address information corresponding to the new executable file when the target file is run, including: obtaining a symbol table and a corresponding symbol address table; and according to the symbol address table, weighting the symbol address in the executable file Positioned as a memory call address.
其中,所述根据所述地址信息,为所述新的可执行文件在所述目标文件运行时生成对应的替换指令信息,包括:通过替换需要补丁的函数的第一条指令为跳转到所述可执行文件运行的起始位置,并在所述替换函数执行完毕后,回到调用需要被替换的函数的函数中。The generating, according to the address information, the corresponding replacement instruction information for the new executable file when the target file is run, including: jumping to the first instruction by replacing the first instruction of the function requiring the patch The starting position of the executable file is run, and after the replacement function is executed, it returns to the function that calls the function that needs to be replaced.
一种热补丁的实现装置,包括:获取模块,设置为从补丁目标文件中获取替换函数的文件信息,其中所述替换函数用于替换目标侧上需要补丁的函数;第一生成模块,设置为根据所述文件信息,为所述需要补丁的函数生成新的可执行文件;确定模块,设置为确定所述新的可执行文件在所述目标侧运行时对应的地址信息;第二生成模块,设置为根据所述地址信息,为所述新的可执行文件在所述目标侧运行时生成对应的替换指令信息;通知模块,设置为通知所述目标侧利用所述替换指令信息运行所述新的可执行文件。An apparatus for implementing a hot patch, comprising: an obtaining module, configured to obtain file information of a replacement function from a patch object file, wherein the replacement function is used to replace a function requiring a patch on a target side; the first generating module is set to And generating, according to the file information, a new executable file for the function that needs to be patched; the determining module is configured to determine address information corresponding to when the new executable file runs on the target side; and a second generating module, Is configured to generate corresponding replacement instruction information when the new executable file is run on the target side according to the address information; and the notification module is configured to notify the target side to run the new by using the replacement instruction information Executable file.
其中,所述替换函数的文件信息包括通过对补丁目标文件做.text.bss.rodata.data段的提取操作,得到的文件信息。 The file information of the replacement function includes file information obtained by performing an extraction operation of the .text.bss.rodata.data segment on the patch object file.
其中,所述第一生成模块包括:第一生成单元,设置为利用所述文件信息生成所述新的可执行文件的结构文件;调整单元,设置为调整所述结构文件中函数的调用关系以及变量的引用关系;第二生成单元,设置为在完成调整操作后,生成所述可执行文件的节头表,根据所述可执行文件的节头表得到所述新的可执行文件。The first generation module includes: a first generation unit configured to generate a structure file of the new executable file by using the file information; and an adjustment unit configured to adjust a call relationship of a function in the structure file and a reference relationship of the variable; the second generating unit is configured to generate a section header table of the executable file after completing the adjusting operation, and obtain the new executable file according to the section header table of the executable file.
其中,所述确定模块包括:获取单元,设置为获取符号表以及对应的符号地址表;重定位单元,设置为根据符号地址表,把所述可执行文件中的符号地址重定位成内存调用地址。The determining module includes: an obtaining unit, configured to acquire a symbol table and a corresponding symbol address table; and a relocating unit configured to relocate the symbol address in the executable file to a memory calling address according to the symbol address table .
其中,所述第二生成模块还设置为:通过替换需要补丁的函数的第一条指令跳转到所述可执行文件运行的起始位置,并在所述替换函数执行完毕后,回到调用需要被替换的函数的函数中。The second generation module is further configured to: jump to the start position of the executable file by replacing the first instruction of the function requiring the patch, and return to the call after the replacement function is executed. The function of the function that needs to be replaced.
本发明实施例还提供了一种计算机程序,包括程序指令,当该程序指令被计算机执行时,使得该计算机可执行上述的方法。Embodiments of the present invention also provide a computer program, including program instructions, that when executed by a computer, cause the computer to perform the above method.
本发明实施例还提供了一种载有上述计算机程序的计算机可读存储介质。Embodiments of the present invention also provide a computer readable storage medium carrying the above computer program.
本发明提供的实施例,与相关技术中把整个目标文件的代码段和数据段都提取出来,然后构造成目标热补丁文件,并在该热补丁加载时全部写入内存空间的实现方式相比,本发明实施例只对需要补丁的函数生成补丁文件,这样不仅可以减少补丁的尺寸,还可以减少加载补丁所需要的预留内存空间,而且便于管理,避免函数调用的不一致性,达到降低补丁加载的复杂度的目的。The embodiment provided by the present invention extracts the code segment and the data segment of the entire object file from the related art, and then constructs the target hot patch file, and compares the implementation manner of writing all the memory space when the hot patch is loaded. The embodiment of the present invention only generates a patch file for a function that needs to be patched, which not only reduces the size of the patch, but also reduces the reserved memory space required for loading the patch, and is convenient for management, avoiding inconsistency of function calls, and reducing the patch. The purpose of loading complexity.
附图概述BRIEF abstract
图1为本发明实施例提供的热补丁的实现方法的流程示意图;FIG. 1 is a schematic flowchart diagram of a method for implementing a hot patch according to an embodiment of the present disclosure;
图2为本发明实施例提供的目标侧管理补丁的示意图;2 is a schematic diagram of a target side management patch according to an embodiment of the present invention;
图3为本发明实施例提供的热补丁的实现装置的流程示意图。 FIG. 3 is a schematic flowchart diagram of an apparatus for implementing a hot patch according to an embodiment of the present invention.
本发明的较佳实施方式Preferred embodiment of the invention
下面将结合附图对本发明实施例作进一步的详细描述。需要说明的是,在不冲突的情况下,本申请中的实施例及实施例中的特征可以相互任意组合。The embodiments of the present invention will be further described in detail below with reference to the accompanying drawings. It should be noted that, in the case of no conflict, the features in the embodiments and the embodiments in the present application may be arbitrarily combined with each other.
图1为本发明实施例提供的热补丁的实现方法的流程示意图。图1所示方法实施例,包括:FIG. 1 is a schematic flowchart diagram of a method for implementing a hot patch according to an embodiment of the present invention. The method embodiment shown in Figure 1 includes:
步骤101、从补丁目标文件中获取替换函数的文件信息,其中所述替换函数用于替换目标侧上需要补丁的函数;Step 101: Obtain file information of a replacement function from a patch object file, where the replacement function is used to replace a function that needs to be patched on the target side;
步骤102、根据所述文件信息,为所述需要补丁的函数生成新的可执行文件;Step 102: Generate a new executable file for the function that requires a patch according to the file information.
步骤103、确定所述新的可执行文件在所述目标侧运行时对应的地址信息;Step 103: Determine address information corresponding to the new executable file running on the target side;
步骤104、根据所述地址信息,为所述新的可执行文件在所述目标侧运行生成对应的替换指令信息;Step 104: Generate corresponding replacement instruction information for the new executable file to run on the target side according to the address information.
步骤105、通知所述目标侧利用所述替换指令信息运行所述新的可执行文件。Step 105: Notify the target side to run the new executable file by using the replacement instruction information.
本发明实施例,与相关技术中把整个目标文件的代码段和数据段都提取出来,然后构造成目标热补丁文件,并在该热补丁加载时全部写入内存空间的实现方式相比,本发明实施例只对需要补丁的函数生成补丁文件,这样不仅可以减少补丁的尺寸,还可以减少加载补丁所需要的预留内存空间,而且便于管理,避免函数调用的不一致性,达到降低补丁加载的复杂度的目的。In the embodiment of the present invention, in the related art, the code segment and the data segment of the entire object file are extracted, and then constructed into a target hot patch file, and compared to the implementation manner in which the hot patch is all written into the memory space, The embodiment of the invention only generates a patch file for the function that needs to be patched, which not only reduces the size of the patch, but also reduces the reserved memory space required for loading the patch, and is convenient for management, avoiding inconsistency of function calls, and reducing patch loading. The purpose of complexity.
下面对本发明实施例提供的方法做进一步说明:The method provided by the embodiment of the present invention is further described below:
步骤101中,在制作软件补丁时,根据需要打补丁的源文件,首先分析补丁目标文件(打补丁的源文件经过编译后即为补丁目标文件),对补丁目标文件做.text.bss.rodata.data段的提取操作,得到所述文件信息。In step 101, when the software patch is created, the patch source file is first analyzed according to the source file to be patched (the patch source file is compiled as a patch target file), and the patch object file is made to .text.bss.rodata. The extraction operation of the .data segment obtains the file information.
,步骤102,所述根据所述文件信息,为所述需要补丁的函数生成新的 可执行文件,包括: Step 102, generating, according to the file information, a new function for the function that requires a patch. Executable files, including:
利用所述文件信息生成所述新的可执行文件的结构文件;调整所述结构文件中函数的调用关系以及变量的引用关系;在完成调整操作后,生成所述可执行文件的节头表,根据所述可执行文件的节头表得到所述新的可执行文件。Generating a structure file of the new executable file by using the file information; adjusting a calling relationship of a function in the structure file and a reference relationship of a variable; and after completing the adjusting operation, generating a section header table of the executable file, The new executable file is obtained according to the section header table of the executable file.
可选的,根据所述可执行文件的节头表得到新的可执行文件,包括:Optionally, a new executable file is obtained according to the section header table of the executable file, including:
读取可执行文件(Executable and Linking Format,ELF)的结构文件的头部,并根据ELF的结构文件的头部信息提供的节头地址addr和节头大小size,读取每个节头记录的信息和内存地址存储的信息;Read the header of the structure file of the Executable and Linking Format (ELF), and read each section header record according to the section header address addr and the section header size provided by the header information of the ELF structure file. Information and information stored in the memory address;
分析.text节,在.text节中抽取替换函数的代码段;Analyze the .text section and extract the code segment of the replacement function in the .text section;
分析.rodata节,在.rodata节中抽取替换函数引用到的只读数据,并合并成一个新的.rodata节;Analyze the .rodata section, extract the read-only data referenced by the replacement function in the .rodata section, and merge them into a new .rodata section;
构建只包含替换函数的代码段、rodata节和符号节的ELF结构目标文件,并以.text.bss.rodata.data作为基地址,addend作为偏移量重设重定位的信息;Construct an ELF structure object file containing only the code segment of the replacement function, the rodata section, and the symbol section, and use .text.bss.rodata.data as the base address, addend as the offset to reset the relocation information;
重新设置每个节头部的addr以及size,构建新的ELF文件。Reset the addr and size of each section header to build a new ELF file.
步骤103,所述确定所述新的可执行文件在所述目标文件运行时对应的地址信息,包括:Step 103: The determining the address information corresponding to the new executable file when the target file is run includes:
获取符号表以及对应的符号地址表;根据符号地址表,把所述可执行文件中的符号地址重定位成内存调用地址,包括:Obtaining a symbol table and a corresponding symbol address table; relocating the symbol address in the executable file to a memory call address according to the symbol address table, including:
在主机侧完成重定位符号的地址,首先分析目标版本的符号信息,将符号信息生成一个索引表,该索引表包括符号地址,所述符号包括:全局变量、全局函数、静态变量、静态函数和静态局部变量,然后在该索引表中查找待重定位的符号,获取到实际真实地址。分析新的ELF文件,通过查找镜像文件中符号的真实地址,去替换ELF目标文件中重定位符号地址,完成重定位的工作,把函数调用和变量地址确定下来。The address of the relocation symbol is completed on the host side, and the symbol information of the target version is first analyzed, and the symbol information is generated into an index table, where the index table includes a symbol address, the symbol includes: a global variable, a global function, a static variable, a static function, and Static local variables, and then find the symbol to be relocated in the index table to obtain the actual real address. Analyze the new ELF file, find the relocation symbol address in the ELF object file by looking up the real address of the symbol in the image file, complete the relocation work, and determine the function call and the variable address.
重定位的过程如下:The process of relocation is as follows:
读取内核镜像原文件中的预留补丁区域,符号表以及对应的符号地址 表;Read the reserved patch area, symbol table and corresponding symbol address in the original file of the kernel image table;
根据符号地址表,把输入目标文件中所引用的符号地址重定位成符号真实的内存地址。According to the symbol address table, the symbol address referenced in the input object file is relocated to the real memory address of the symbol.
可选的,步骤104,所述根据所述地址信息,为所述新的可执行文件在所述目标文件运行时生成对应的替换指令信息,包括:通过替换需要补丁的函数的第一条指令为跳转到所述可执行文件运行的起始位置,并在所述替换函数执行完毕后,回到调用需要被替换的函数的函数中。Optionally, in step 104, the generating, according to the address information, the corresponding replacement instruction information for the new executable file when the target file is run, including: replacing the first instruction of the function that requires the patch by replacing To jump to the starting position of the executable file run, and after the replacement function is executed, return to the function that calls the function that needs to be replaced.
根据替换函数的源地址和目标地址生成一个替换函数表,供目标机侧做指令跳转操作。其中源地址是补丁修改前的符号地址,目标地址是补丁修改后的符号地址,它位于补丁区中。根据预留补丁区域地址,在主机侧构造函数替换指令表。根据不同CPU构架,构造跳转指令。其主要工作原理是,通过替换原老函数的第一条指令为跳转到新函数中的指令,使程序跳转到新函数所在位置处执行,当新函数中的补丁代码执行完毕后,回到调用老函数的代码中,完成整个调用过程。A replacement function table is generated according to the source address and the target address of the replacement function, and the target machine side performs an instruction jump operation. The source address is the symbol address before the patch is modified, and the target address is the modified symbol address of the patch, which is located in the patch area. The instruction list is replaced by the host side constructor according to the reserved patch area address. The jump instruction is constructed according to different CPU architectures. The main working principle is that by replacing the first instruction of the original old function, the instruction jumps to the new function, so that the program jumps to the position where the new function is located, and when the patch code in the new function is executed, Go to the code that calls the old function and complete the entire call process.
由上可以看出,上述补丁制作过程,全部在主机侧完成,且对目标文件做.text.bss.rodata.data段的提取操作,提取需要的ELF段做补丁,有效地减少了补丁大小,降低了目标机侧的内存消耗;It can be seen from the above that the above patch making process is completed on the host side, and the extracting operation of the .text.bss.rodata.data segment is performed on the target file, and the required ELF segment is extracted for patching, thereby effectively reducing the patch size. Reduced memory consumption on the target side;
另外,在主机侧对重定位符号进行重定位操作,分析镜像原文件中的符号表,对不同类型的符号生成对应的地址对应表,然后查找目标文件的重定位符号地址。In addition, the relocation symbol is relocated on the host side, the symbol table in the original image file is analyzed, a corresponding address correspondence table is generated for different types of symbols, and then the relocation symbol address of the target file is searched.
例如,普通非静态函数func_name:For example, the normal non-static function func_name:
{func_name,地址}{func_name, address}
全局变量global_var_name:Global variable global_var_name:
{global_var_name,地址}{global_var_name, address}
对于静态符号,采用加前缀的方法来标识,其中file表示符号所在的文件,function表示符号所在的函数。For static symbols, use the prefix method to identify, where file represents the file in which the symbol is located, and function represents the function in which the symbol is located.
静态局部变量static_localvar_name:Static local variable static_localvar_name:
{file_function_static_localvar_name,地址} {file_function_static_localvar_name, address}
静态变量static_var_name:Static variable static_var_name:
{file_static_var_name,地址}{file_static_var_name, address}
静态函数static_func_name:Static function static_func_name:
{file_static_func_name,地址}{file_static_func_name, address}
然后,根据地址对应表,实现普通函数,全局变量,静态局部变量,静态变量和静态函数等符号的重定位,并且上述操作都是在主机侧完成,而无需修改目标机侧的代码,从而大大提高了补丁制作的灵活性和可移植性。Then, according to the address correspondence table, relocation of symbols such as ordinary functions, global variables, static local variables, static variables, and static functions is implemented, and the above operations are all performed on the host side without modifying the code on the target side, thereby greatly Increased flexibility and portability of patch production.
图2为本发明实施例提供的目标侧管理补丁的示意图。图2所示示意图中目标侧实现补丁的加载,激活,补丁自动激活,去激活,卸载操作。其状态转换控制采用命令驱动的方式运行,由状态机来控制,保证状态迁移正确性。说明如下:FIG. 2 is a schematic diagram of a target side management patch according to an embodiment of the present invention. In the schematic diagram shown in FIG. 2, the target side implements loading, activation, patch automatic activation, deactivation, and uninstallation of the patch. The state transition control is operated in a command-driven manner and controlled by the state machine to ensure the correct state transition. described as follows:
补丁加载流程:首先判断补丁和系统软件的版本号是否符合一致,如果不一致直接退出;如果一致,则将补丁文件加载写入到flash中,然后读取该文件中函数替换表,根据需要加载补丁预留区域的地址,把替换函数的代码段,只读数据段写入到内存中。补丁加载后,补丁的状态为非激活状态,并把补丁的状态写入到相应的配置文件中。Patch loading process: First, determine whether the patch and the version number of the system software are consistent. If they are inconsistent, directly exit. If they are consistent, load the patch file into the flash, and then read the function replacement table in the file and load the patch as needed. The address of the reserved area, the code segment of the replacement function, the read-only data segment is written into the memory. After the patch is loaded, the status of the patch is inactive and the status of the patch is written to the corresponding configuration file.
补丁激活:根据指令替换表,将被补丁函数地址处的指令改成跳转到替换函数的指令,并把补丁的状态写入到配置文件中。Patch activation: Replace the table according to the instruction, change the instruction at the patch function address to the instruction to jump to the replacement function, and write the status of the patch to the configuration file.
补丁自动激活:将补丁状态修改为自动激活状态,保存在补丁配置文件中,下次重起时会加载补丁继续生效,并把补丁的状态写入到配置文件中。The patch is automatically activated: the patch status is changed to the automatic activation state and saved in the patch configuration file. The patch will continue to take effect the next time it is restarted, and the status of the patch is written to the configuration file.
补丁去激活:根据指令替换表,将被补丁函数地址处的跳转指令替换为原来的指令。成功后,补丁状态修改为非激活状态,并把补丁的状态写入到配置文件中。Patch deactivation: Replace the table with the instruction, and replace the jump instruction at the patch function address with the original instruction. After successful, the patch status is changed to inactive and the status of the patch is written to the configuration file.
补丁卸载:释放补丁文件所占用的flash空间,以及内存空间,并把补丁函数地址处的跳转指令替换为原来的指令,并把补丁的状态写入到配置文件中。Patch unloading: release the flash space occupied by the patch file, and the memory space, and replace the jump instruction at the patch function address with the original instruction, and write the status of the patch to the configuration file.
补丁状态查询:通过读取配置文件,可以查看当前补丁所处的状态。 Patch status query: By reading the configuration file, you can view the status of the current patch.
由此可以看出,采用了本发明实施例提供的热补丁方式,目标侧仍可以按照相关技术的补丁方式,对相关流程改动小,因此本发明实施例提供的方案适用性强。It can be seen that the hot patching method provided by the embodiment of the present invention can still modify the related process according to the patching manner of the related art. Therefore, the solution provided by the embodiment of the present invention has strong applicability.
图3为本发明实施例提供的热补丁的实现装置的结构示意图。结合图1所示的方法实施例,图3所示装置包括:FIG. 3 is a schematic structural diagram of an apparatus for implementing a hot patch according to an embodiment of the present invention. With reference to the method embodiment shown in FIG. 1, the apparatus shown in FIG. 3 includes:
获取模块301,设置为从补丁目标文件中获取替换函数的文件信息,其中所述替换函数用于替换目标侧上需要补丁的函数;The obtaining module 301 is configured to obtain file information of the replacement function from the patch object file, where the replacement function is used to replace the function that needs to be patched on the target side;
第一生成模块302,设置为根据所述文件信息,为所述需要补丁的函数生成新的可执行文件;The first generating module 302 is configured to generate a new executable file for the function requiring the patch according to the file information;
确定模块303,设置为确定所述新的可执行文件在所述目标侧运行时对应的地址信息;a determining module 303, configured to determine address information corresponding to when the new executable file runs on the target side;
第二生成模块304,设置为根据所述地址信息,为所述新的可执行文件在所述目标侧运行时生成对应的替换指令信息;The second generation module 304 is configured to generate corresponding replacement instruction information when the new executable file is run on the target side according to the address information;
通知模块305,设置为通知所述目标侧利用所述替换指令信息运行所述新的可执行文件。The notification module 305 is configured to notify the target side to run the new executable file by using the replacement instruction information.
其中,所述替换函数的文件信息包括对目标文件做.text.bss.rodata.data段的提取操作,得到所述文件信息。The file information of the replacement function includes an extraction operation of the .text.bss.rodata.data segment of the target file, and the file information is obtained.
其中,所述第一生成模块302包括:The first generation module 302 includes:
第一生成单元,设置为利用所述文件信息生成所述新的可执行文件的结构文件;a first generating unit, configured to generate a structural file of the new executable file by using the file information;
调整单元,与所述第一生成单元相连,设置为调整所述结构文件中函数的调用关系以及变量的引用关系;An adjusting unit, connected to the first generating unit, configured to adjust a calling relationship of a function in the structure file and a reference relationship of the variable;
第二生成单元,与所述调整单元相连,设置为在完成调整操作后,生成所述可执行文件的节头表,根据所述可执行文件的节头表得到所述新的可执行文件。The second generating unit is connected to the adjusting unit, and is configured to generate a section header table of the executable file after completing the adjusting operation, and obtain the new executable file according to the section header table of the executable file.
其中,所述确定模块303包括: The determining module 303 includes:
获取单元,设置为获取符号表以及对应的符号地址表;Obtaining a unit, configured to obtain a symbol table and a corresponding symbol address table;
重定位单元,设置为根据符号地址表,把所述可执行文件中的符号地址重定位成内存调用地址。The relocation unit is configured to relocate the symbol address in the executable file to a memory call address according to the symbol address table.
其中,所述第二生成模块304设置为:The second generation module 304 is configured to:
通过替换需要补丁的函数的第一条指令为跳转到所述可执行文件运行的起始位置,并在所述替换函数执行完毕后,回到调用需要被替换的函数的函数中。The first instruction that replaces the function requiring the patch is to jump to the start position of the executable file, and after the replacement function is executed, returns to the function that calls the function that needs to be replaced.
本发明实施例,与相关技术中把整个目标文件的代码段和数据段都提取出来,然后构造成目标热补丁文件,并在该热补丁加载时全部写入内存空间的实现方式相比,本发明实施例只对需要补丁的函数生成补丁文件,这样不仅可以减少补丁的尺寸,还可以减少加载补丁所需要的预留内存空间,而且便于管理,避免函数调用的不一致性,达到降低补丁加载的复杂度的目的。In the embodiment of the present invention, in the related art, the code segment and the data segment of the entire object file are extracted, and then constructed into a target hot patch file, and compared to the implementation manner in which the hot patch is all written into the memory space, The embodiment of the invention only generates a patch file for the function that needs to be patched, which not only reduces the size of the patch, but also reduces the reserved memory space required for loading the patch, and is convenient for management, avoiding inconsistency of function calls, and reducing patch loading. The purpose of complexity.
本领域普通技术人员可以理解上述实施例的全部或部分步骤可以使用计算机程序流程来实现,所述计算机程序可以存储于一计算机可读存储介质中,所述计算机程序在相应的硬件平台上(如系统、设备、装置、器件等)执行,在执行时,包括方法实施例的步骤之一或其组合。One of ordinary skill in the art will appreciate that all or a portion of the steps of the above-described embodiments can be implemented using a computer program flow, which can be stored in a computer readable storage medium, such as on a corresponding hardware platform (eg, The system, device, device, device, etc. are executed, and when executed, include one or a combination of the steps of the method embodiments.
可选地,上述实施例的全部或部分步骤也可以使用集成电路来实现,这些步骤可以被分别制作成一个个集成电路模块,或者将它们中的多个模块或步骤制作成单个集成电路模块来实现。这样,本发明不限制于任何特定的硬件和软件结合。Alternatively, all or part of the steps of the above embodiments may also be implemented by using an integrated circuit. These steps may be separately fabricated into individual integrated circuit modules, or multiple modules or steps may be fabricated into a single integrated circuit module. achieve. Thus, the invention is not limited to any specific combination of hardware and software.
上述实施例中的各装置/功能模块/功能单元可以采用通用的计算装置来实现,它们可以集中在单个的计算装置上,也可以分布在多个计算装置所组成的网络上。The devices/function modules/functional units in the above embodiments may be implemented by a general-purpose computing device, which may be centralized on a single computing device or distributed over a network of multiple computing devices.
上述实施例中的各装置/功能模块/功能单元以软件功能模块的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。上述提到的计算机可读取存储介质可以是只读存储器,磁盘或光盘等。When each device/function module/functional unit in the above embodiment is implemented in the form of a software function module and sold or used as a stand-alone product, it can be stored in a computer readable storage medium. The above mentioned computer readable storage medium may be a read only memory, a magnetic disk or an optical disk or the like.
以上所述,仅为本发明的具体实施方式,但本发明的保护范围并不局限 于此,任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本发明的保护范围之内。因此,本发明的保护范围应以权利要求所述的保护范围为准。The above description is only a specific embodiment of the present invention, but the scope of protection of the present invention is not limited. In this regard, any person skilled in the art can easily conceive changes or substitutions within the scope of the present invention. Therefore, the scope of the invention should be determined by the scope of the claims.
工业实用性Industrial applicability
上述实施例只对需要补丁的函数生成补丁文件,这样不仅可以减少补丁的尺寸,还可以减少加载补丁所需要的预留内存空间,而且便于管理,避免函数调用的不一致性,达到降低补丁加载的复杂度的目的。 The above embodiment only generates a patch file for the function that needs to be patched, which not only reduces the size of the patch, but also reduces the reserved memory space required for loading the patch, and is convenient for management, avoiding inconsistency of function calls, and reducing patch loading. The purpose of complexity.

Claims (12)

  1. 一种热补丁的实现方法,包括:A method for implementing a hot patch, comprising:
    从补丁目标文件中获取替换函数的文件信息,其中所述替换函数用于替换目标侧上需要补丁的函数;Obtaining file information of the replacement function from the patch object file, wherein the replacement function is used to replace the function that needs to be patched on the target side;
    根据所述文件信息,为所述需要补丁的函数生成新的可执行文件;Generating a new executable file for the function requiring the patch according to the file information;
    确定所述新的可执行文件在所述目标侧运行时对应的地址信息;Determining address information corresponding to the new executable file running on the target side;
    根据所述地址信息,为所述新的可执行文件在所述目标侧运行时生成对应的替换指令信息;Generating corresponding replacement instruction information when the new executable file is run on the target side according to the address information;
    通知所述目标侧利用所述替换指令信息运行所述新的可执行文件。Notifying the target side to run the new executable file using the replacement instruction information.
  2. 根据权利要求1所述的方法,其中,所述替换函数的文件信息包括通过对补丁目标文件做.text.bss.rodata.data段的提取操作,得到的文件信息。The method according to claim 1, wherein the file information of the replacement function includes file information obtained by performing an extraction operation of a .text.bss.rodata.data segment on the patch object file.
  3. 根据权利要求2所述的方法,其中,根据所述文件信息,为所述待补丁的函数生成新的可执行文件,包括:The method of claim 2, wherein generating a new executable file for the function to be patched according to the file information comprises:
    利用所述文件信息生成所述新的可执行文件的结构文件;Generating a structure file of the new executable file by using the file information;
    调整所述结构文件中函数的调用关系以及变量的引用关系;Adjusting the calling relationship of the function in the structure file and the reference relationship of the variable;
    在完成调整操作后,生成所述可执行文件的节头表,根据所述可执行文件的节头表得到所述新的可执行文件。After the adjustment operation is completed, a section header table of the executable file is generated, and the new executable file is obtained according to the section header table of the executable file.
  4. 根据权利要求1所述的方法,其中,确定所述新的可执行文件在所述目标文件运行时对应的地址信息,包括:The method of claim 1, wherein determining the address information corresponding to the new executable file when the target file is run comprises:
    获取符号表以及对应的符号地址表;Obtaining a symbol table and a corresponding symbol address table;
    根据符号地址表,把所述可执行文件中的符号地址重定位成内存调用地址。The symbol address in the executable file is relocated to a memory call address according to the symbol address table.
  5. 根据权利要求1所述的方法,其中,所述根据所述地址信息,为所述新的可执行文件在所述目标文件运行时生成对应的替换指令信息,包括: The method according to claim 1, wherein the generating, according to the address information, the corresponding replacement instruction information when the target file is run for the new executable file comprises:
    通过替换需要补丁的函数的第一条指令跳转到所述可执行文件运行的起始位置,并在所述替换函数执行完毕后,回到调用需要被替换的函数的函数中。The first instruction that replaces the function requiring the patch jumps to the start position of the execution of the executable file, and after the replacement function is executed, returns to the function that calls the function that needs to be replaced.
  6. 一种热补丁的实现装置,包括:A device for implementing a hot patch, comprising:
    获取模块,设置为从补丁目标文件中获取替换函数的文件信息,其中所述替换函数用于替换目标侧上需要补丁的函数;Obtaining a module, configured to obtain file information of the replacement function from the patch object file, wherein the replacement function is used to replace the function that needs to be patched on the target side;
    第一生成模块,设置为根据所述文件信息,为所述需要补丁的函数生成新的可执行文件;a first generating module, configured to generate a new executable file for the function requiring the patch according to the file information;
    确定模块,设置为确定所述新的可执行文件在所述目标侧运行时对应的地址信息;a determining module, configured to determine address information corresponding to when the new executable file runs on the target side;
    第二生成模块,设置为根据所述地址信息,为所述新的可执行文件在所述目标侧运行时生成对应的替换指令信息;a second generation module, configured to generate corresponding replacement instruction information when the new executable file is run on the target side according to the address information;
    通知模块,设置为通知所述目标侧利用所述替换指令信息运行所述新的可执行文件。The notification module is configured to notify the target side to run the new executable file by using the replacement instruction information.
  7. 根据权利要求6所述的装置,其中,所述替换函数的文件信息包括通过对补丁目标文件做.text.bss.rodata.data段的提取操作,得到的文件信息。The apparatus according to claim 6, wherein the file information of the replacement function includes file information obtained by performing an extraction operation of a .text.bss.rodata.data section on the patch object file.
  8. 根据权利要求7所述的装置,其中,所述第一生成模块包括:The apparatus of claim 7, wherein the first generation module comprises:
    第一生成单元,设置为利用所述文件信息生成所述新的可执行文件的结构文件;a first generating unit, configured to generate a structural file of the new executable file by using the file information;
    调整单元,设置为调整所述结构文件中函数的调用关系以及变量的引用关系;The adjusting unit is configured to adjust a calling relationship of the function in the structure file and a reference relationship of the variable;
    第二生成单元,设置为在完成调整操作后,生成所述可执行文件的节头表,根据所述可执行文件的节头表得到所述新的可执行文件。The second generating unit is configured to generate a section header table of the executable file after completing the adjusting operation, and obtain the new executable file according to the section header table of the executable file.
  9. 根据权利要求6所述的装置,其中,所述确定模块包括:The apparatus of claim 6 wherein said determining module comprises:
    获取单元,设置为获取符号表以及对应的符号地址表; Obtaining a unit, configured to obtain a symbol table and a corresponding symbol address table;
    重定位单元,设置为根据符号地址表,把所述可执行文件中的符号地址重定位成内存调用地址。The relocation unit is configured to relocate the symbol address in the executable file to a memory call address according to the symbol address table.
  10. 根据权利要求6所述的装置,其中,所述第二生成模块还设置为:The apparatus of claim 6, wherein the second generation module is further configured to:
    通过替换需要补丁的函数的第一条指令跳转到所述可执行文件运行的起始位置,并在所述替换函数执行完毕后,回到调用需要被替换的函数的函数中。The first instruction that replaces the function requiring the patch jumps to the start position of the execution of the executable file, and after the replacement function is executed, returns to the function that calls the function that needs to be replaced.
  11. 一种计算机程序,包括程序指令,当该程序指令被计算机执行时,使得该计算机可执行权利要求1~5中任一项所述的方法。A computer program comprising program instructions which, when executed by a computer, cause the computer to perform the method of any one of claims 1 to 5.
  12. 一种载有权利要求11所述计算机程序的计算机可读存储介质。 A computer readable storage medium carrying the computer program of claim 11.
PCT/CN2015/078896 2014-12-24 2015-05-13 Hot patching realization method and apparatus WO2016101503A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201410816631.0 2014-12-24
CN201410816631.0A CN105786537A (en) 2014-12-24 2014-12-24 Hot patch realization method and device

Publications (1)

Publication Number Publication Date
WO2016101503A1 true WO2016101503A1 (en) 2016-06-30

Family

ID=56149087

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2015/078896 WO2016101503A1 (en) 2014-12-24 2015-05-13 Hot patching realization method and apparatus

Country Status (2)

Country Link
CN (1) CN105786537A (en)
WO (1) WO2016101503A1 (en)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107656753A (en) * 2016-07-25 2018-02-02 中兴通讯股份有限公司 A kind of patch-realizing method and device
CN110045980A (en) * 2019-05-22 2019-07-23 东信和平科技股份有限公司 Remote upgrade method, equipment and the system of a kind of pair of NB-IOT equipment
CN111897555A (en) * 2019-05-06 2020-11-06 阿里巴巴集团控股有限公司 Dynamic updating method, device and system of client and terminal equipment
CN113760340A (en) * 2020-06-05 2021-12-07 大唐移动通信设备有限公司 Hot patching method and device applied to Linux system
CN114020504A (en) * 2021-10-19 2022-02-08 北京五八信息技术有限公司 Data processing method and device, electronic equipment and storage medium
CN111897555B (en) * 2019-05-06 2024-06-07 阿里巴巴集团控股有限公司 Dynamic updating method, device and system of client and terminal equipment

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107357622B (en) * 2017-07-17 2020-09-22 迈普通信技术股份有限公司 Hot patch implementation method and communication equipment
CN107643924A (en) * 2017-09-29 2018-01-30 郑州云海信息技术有限公司 A kind of upgrade method, system, equipment and the storage medium of kernel state client
CN111399892A (en) * 2020-03-18 2020-07-10 深圳Tcl数字技术有限公司 Middleware program repairing method and device and computer readable storage medium
CN111796832B (en) * 2020-06-30 2022-11-04 苏州三六零智能安全科技有限公司 Hot patch file generation method, device, equipment and storage medium
CN111949290B (en) * 2020-07-14 2022-10-14 锐捷网络股份有限公司 Hot patch management method and device, electronic equipment and storage medium
CN112084112B (en) * 2020-09-11 2024-04-26 北京金山云网络技术有限公司 Thermal patch testing method, device and server
CN114579181A (en) * 2020-11-30 2022-06-03 华为技术有限公司 Patching method, related equipment and system

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101799763A (en) * 2009-02-10 2010-08-11 华为技术有限公司 Method, device and system for patching kernel on line
CN101937340A (en) * 2009-06-29 2011-01-05 中兴通讯股份有限公司 Method and device for dynamically updating and controlling software by using patches
CN103019787A (en) * 2012-12-14 2013-04-03 华为技术有限公司 Function call relation determining method, hotfix updating method and hotfix updating device
WO2014117169A1 (en) * 2013-01-28 2014-07-31 Rackspace Us, Inc. Methods and systems of function-specific tracing

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101799763A (en) * 2009-02-10 2010-08-11 华为技术有限公司 Method, device and system for patching kernel on line
CN101937340A (en) * 2009-06-29 2011-01-05 中兴通讯股份有限公司 Method and device for dynamically updating and controlling software by using patches
CN103019787A (en) * 2012-12-14 2013-04-03 华为技术有限公司 Function call relation determining method, hotfix updating method and hotfix updating device
WO2014117169A1 (en) * 2013-01-28 2014-07-31 Rackspace Us, Inc. Methods and systems of function-specific tracing

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107656753A (en) * 2016-07-25 2018-02-02 中兴通讯股份有限公司 A kind of patch-realizing method and device
CN111897555A (en) * 2019-05-06 2020-11-06 阿里巴巴集团控股有限公司 Dynamic updating method, device and system of client and terminal equipment
CN111897555B (en) * 2019-05-06 2024-06-07 阿里巴巴集团控股有限公司 Dynamic updating method, device and system of client and terminal equipment
CN110045980A (en) * 2019-05-22 2019-07-23 东信和平科技股份有限公司 Remote upgrade method, equipment and the system of a kind of pair of NB-IOT equipment
CN110045980B (en) * 2019-05-22 2022-09-02 东信和平科技股份有限公司 Method, device and system for remotely upgrading NB-IOT (NB-IOT) device
CN113760340A (en) * 2020-06-05 2021-12-07 大唐移动通信设备有限公司 Hot patching method and device applied to Linux system
CN113760340B (en) * 2020-06-05 2024-02-20 大唐移动通信设备有限公司 Hot patching method and device applied to Linux system
CN114020504A (en) * 2021-10-19 2022-02-08 北京五八信息技术有限公司 Data processing method and device, electronic equipment and storage medium

Also Published As

Publication number Publication date
CN105786537A (en) 2016-07-20

Similar Documents

Publication Publication Date Title
WO2016101503A1 (en) Hot patching realization method and apparatus
CN102236621B (en) Computer interface information configuration system and method
CN101937340B (en) Method and device for dynamically updating and controlling software by using patches
CN106095620B (en) A kind of development approach of built-in Linux partition holding
US8423991B2 (en) Embedded network device and firmware upgrading method
CN104102506B (en) A kind of Android Acceleration of starting methods based on ARM platforms
CN105446712B (en) Application program defect repairing method and device
JP2021002317A (en) Method, apparatus, device and storage medium for upgrading application
CN104360877A (en) ECU (electronic control unit) firmware updating method based on Bootloader self update
WO2016091071A1 (en) Linux kernel driver loading method and device
WO2016078263A1 (en) Upgrading control device and terminal, terminal upgrading method and system, and storage medium
CN110874237A (en) Software upgrading method, device, terminal and readable storage medium
WO2015154538A1 (en) Memory booting method and device
CN115017058B (en) Test method and device of kernel module, electronic equipment and storage medium
CA3155732A1 (en) Business process configuring method, business request processing method, and devices
CN108829465B (en) Local dynamic loading system and method based on direct read-write FLASH
CN112015491A (en) Method, device and computer storage medium for realizing function jump
US20220244931A1 (en) Image file obtaining method and apparatus
US20130159689A1 (en) Method and apparatus for initializing embedded device
CN105573913A (en) Program debugging method and program debugging system in optical network unit (ONU) system
CN105045718A (en) Linux embedded system based debug system, method and modification method
CN111142922B (en) Application program updating method, device, terminal and server
CN104461621A (en) Attribute information updating method and device
CN104866388A (en) Data processing method and device
CN108121561B (en) Application program repairing method, device and system

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 15871579

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 15871579

Country of ref document: EP

Kind code of ref document: A1