CN105354045A - Patch making method and apparatus and patch activation method and apparatus - Google Patents

Patch making method and apparatus and patch activation method and apparatus Download PDF

Info

Publication number
CN105354045A
CN105354045A CN201410416228.9A CN201410416228A CN105354045A CN 105354045 A CN105354045 A CN 105354045A CN 201410416228 A CN201410416228 A CN 201410416228A CN 105354045 A CN105354045 A CN 105354045A
Authority
CN
China
Prior art keywords
patch
code
module
instruction
script
Prior art date
Legal status (The legal status 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 status listed.)
Withdrawn
Application number
CN201410416228.9A
Other languages
Chinese (zh)
Inventor
蒋勇
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
ZTE Corp
Original Assignee
ZTE Corp
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 ZTE Corp filed Critical ZTE Corp
Priority to CN201410416228.9A priority Critical patent/CN105354045A/en
Priority to PCT/CN2014/090497 priority patent/WO2015117434A1/en
Publication of CN105354045A publication Critical patent/CN105354045A/en
Withdrawn legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/65Updates
    • G06F8/658Incremental updates; Differential updates

Abstract

The invention discloses a patch making method and apparatus and a patch activation method and apparatus. The patch making method comprises: writing a patch script corresponding to at least one row of replaced codes in a source code where patched functions are by utilizing a script language, wherein the patch script comprises patch codes corresponding to the replaced codes and the positions of the replaced codes in the source code; generating patch modules for replacing the replaced codes according to the patch script; and locating the replaced codes to starting positions and stopping positions of corresponding instructions in a binary program according to the positions of the replaced codes in the source code, and adding the replaced codes into the patch modules. According to the method, the problems of tedious patch making process, relatively large repair granularity and incapability of well solving the problem in mutual reference of multiple patched functions during existing program upgrading can be solved.

Description

The Activiation method of the method for making of patch and device, patch and device
Technical field
The present invention relates to field of computer technology, particularly relate to a kind of method for making of patch and device, the Activiation method of patch and device.
Background technology
Program on-line upgrading refers to program not reset routine and method of replacing the operation code section of program in operational process, is widely used in all kinds of highly reliable server OS.
Particularly for the industry that running software stability requirement is high, such as financial telecommunications industry, needs, when not affecting original business and normally running, to complete the reparation to system software mistake or renewal.The mode of present procedure online upgrading patch substantially all in units of function, namely by start a leak or need upgrade function repair, to realize the reparation to this application program.
Prior art is all the program repair mode adopting function level, its principle of work is the instruction jumped in replacement function by replacing by the Article 1 instruction of patch function, programming jump is performed to new function position, after replacement function is complete, redirect is got back in the code calling old function, thus completes whole invoked procedure.The China that can be CN101937340A, CN103218262A, CN103744709A, CN103197942A see publication number applies for a patent.There is following defect in this function substitute mode:
1) which patch make loaded down with trivial details, make patch time need by by patch function all references to macro definition, structure, enumeration type etc. all copy one time;
2) which is comparatively thick to the reparation size ratio of program, needs to be replaced by patch function whole to solve a minor issue;
3) which well can not solve multiple problem mutually quoted by patch function.
Summary of the invention
The main technical problem to be solved in the present invention is, a kind of method for making of patch and device, the Activiation method of patch and device are provided, solve patch that existing program upgrade exists make loaded down with trivial details, to repair size ratio comparatively thick and well can not solve multiple problem mutually quoted by patch function.
For solving the problems of the technologies described above, the invention provides a kind of method for making of patch, comprising the steps:
Utilize scripting language by the source code of patch function place at least a line be replaced patch script corresponding to code line, described patch script comprises patch code corresponding to described replacement code and is describedly replaced the position of code in described source code;
The patch module being replaced code described in replacement is generated according to described patch script;
Be replaced according to described starting position and the end position that the position of code in described source code navigates to corresponding instruction in binary program, and add in described patch module.
Further, the described step being replaced the patch module of code according to described patch script generation replacement comprises:
Described patch script is converted to the code of predefined type language and is compiled into the kernel module that can load;
Described kernel module is compiled into the patch module of binary program form.
Further, described predefined type language comprises C language.
Also for ease of and solve above-mentioned technical matters, present invention also offers a kind of Activiation method of patch, comprise the steps:
Obtain patch module, described patch module comprise by the source code of patch function place at least a line be replaced patch code corresponding to code and described starting position and the end position being replaced code instruction corresponding in binary program;
Arranging for jumping to the jump instruction performing described patch code according to described starting position, making when performing described starting position, run described jump instruction and jump to patch code in the described patch module of execution;
Be arranged on turn back to according to described end position after executing described patch code described by patch function relaying reforwarding line code.
Further, described setting according to described starting position comprises for the step jumping to the jump instruction performing described patch code:
Be for jumping to the jump instruction performing described patch code by performing the modifying of order at described starting position place.
Further, described method also comprises: sensing point and the reentry point of installing described patch module, and described sensing point is described starting position, and described reentry point is described end position; When installing described sensing point, breakpoint abnormality processing function is associated with this sensing point;
Described is that step for jumping to the jump instruction performing described patch code comprises by performing the modifying of order at described starting position place:
Be for being jumped to the break-poing instruction performing described patch code by breakpoint abnormality processing function by the modifying of order that is detected of described sensing point, making when performing described sensing point, running described break-poing instruction and jumping to patch code in the described patch module of execution by breakpoint abnormality processing function.
Further, the described modifying of order that is detected by described sensing point is that step for being jumped to the break-poing instruction performing described patch code by breakpoint abnormality processing function is comprised:
Be detected instruction described in backup, then by described be detected first or multiple byte in instruction replace with for by breakpoint abnormality processing function perform break-poing instruction be used for jumping to by breakpoint abnormality processing function the break-poing instruction performing described patch code.
Also for ease of and solve above-mentioned technical matters, present invention also offers a kind of producing device of patch, comprising: script editor module, locating module and patch generation module;
Described script editor module for utilize scripting language by the source code of patch function place at least a line be replaced patch script corresponding to code line, described patch script comprises patch code corresponding to described replacement code and is describedly replaced the position of code in described source code;
Described patch generation module is used for generating according to described patch script the patch module being replaced code described in replacement;
Described locating module is used for being replaced starting position and the end position that the position of code in described source code navigates to corresponding instruction in binary program described in basis, and adds in described patch module.
Further, described patch generation module comprises: script translater and patch module compiles device;
Described script translater is used for described patch script being converted to the code of predefined type language and being compiled into the kernel module that can load;
Described patch module compiles device is used for the patch module described kernel module being compiled into binary program form.
Also for ease of and solve above-mentioned technical matters, present invention also offers a kind of active device of patch, comprise acquisition module, instruction arranges module and return and arrange module;
Described acquisition module for obtaining patch module, described patch module comprise by the source code of patch function place at least a line be replaced patch code corresponding to code and described starting position and the end position being replaced code instruction corresponding in binary program;
Described instruction arranges module for arranging for jumping to the jump instruction performing described patch code according to described starting position, makes when performing described starting position, runs described jump instruction and jumps to patch code in the described patch module of execution;
Described Returning equipment module be used for being arranged on execute described patch code after turn back to according to described end position described by patch function relaying reforwarding line code.
Further, described instruction arranges module for being for jumping to the jump instruction performing described patch code by performing the modifying of order at described starting position place.
Further, described device also comprises: installation module;
Described installation module is for installing sensing point and the reentry point of described patch module, and described sensing point is described starting position, and described reentry point is described end position, and when installing described sensing point, breakpoint abnormality processing function is associated with this sensing point;
Described instruction arranges module for being for being jumped to the break-poing instruction performing described patch code by breakpoint abnormality processing function by the modifying of order that is detected of described sensing point, making when performing described sensing point, running described break-poing instruction and jumping to patch code in the described patch module of execution by breakpoint abnormality processing function.
Further, described instruction arranges module and be detected instruction described in backing up, then by described be detected first or multiple byte in instruction replace with for by breakpoint abnormality processing function perform break-poing instruction be used for jumping to by breakpoint abnormality processing function the break-poing instruction performing described patch code.
The invention has the beneficial effects as follows:
The invention provides a kind of method for making of patch and device, the Activiation method of patch and device, can realize replacing by a line or lines of code in the source code of patch function place, thus the upgrading realized software program or reparation; The method for making of patch of the present invention comprises: utilize scripting language by the source code of patch function place at least a line be replaced patch script corresponding to code, described patch script comprises patch code corresponding to described replacement code and is describedly replaced the position of code in described source code; The patch module being replaced code described in replacement is generated according to described patch script; Be replaced according to described starting position and the end position that the position of code in described source code navigates to corresponding instruction in binary program, and add in described patch module; Method of the present invention can produce patch for a line in source code or lines of code, utilizes this patch can realize replacing a line or lines of code in function source code, thus realizes the upgrading to software; Owing to being make patch for code line, so manufacturing process simple and fast, and the patch that application invention makes is upgraded to software, avoids, in order to a minor issue is just replaced whole function, reducing the reparation granularity to program; The patch that application method for making of the present invention is produced in addition can carry out online upgrading to function multiple in original program, need not consider the mutual call relation between multiple function; Compared with prior art, the efficiency of software upgrading can be improved, reduce patch making complexity, improve safety and reliability during patch upgrading.
The patch module that corresponding said method is produced, present invention also offers a kind of anti-activating method of patch, can activate the patch module utilizing above-mentioned method for making to make, realize replacing a line in source code or lines of code; The anti-activating method of patch of the present invention comprises: obtain patch module, described patch module comprise by the source code of patch function place at least a line be replaced patch code corresponding to code and described starting position and the end position being replaced code instruction corresponding in binary program; Arranging for jumping to the jump instruction performing described patch code according to described starting position, making when performing described starting position, run described jump instruction and jump to patch code in the described patch module of execution; Be arranged on turn back to according to described end position after executing described patch code described by patch function relaying reforwarding line code; Adopt Activiation method of the present invention can make when kernel runs to starting position, run described jump instruction and jump to patch code in the described patch module of execution, achieve and can replace for a line or lines of code in software upgrade process.
Accompanying drawing explanation
The schematic flow sheet of the method for making of a kind of patch that Fig. 1 provides for the embodiment of the present invention one;
The schematic diagram of a kind of processing procedure concrete to patch script that Fig. 2 provides for the embodiment of the present invention one;
The schematic flow sheet of the Activiation method of a kind of patch that Fig. 3 provides for the embodiment of the present invention two;
Fig. 4 realizes the schematic flow sheet of program upgrade for a kind of Activiation method applying the present embodiment that the embodiment of the present invention two provides;
A kind of on-line software updating method integrated stand composition that Fig. 5 provides for the embodiment of the present invention three;
The structural representation of the producing device of a kind of patch that Fig. 6 provides for the embodiment of the present invention four;
The structural representation of the producing device of the another kind of patch that Fig. 7 provides for the embodiment of the present invention four;
The structural representation of the active device of a kind of patch that Fig. 8 provides for the embodiment of the present invention five;
The structural representation of the active device of the another kind of patch that Fig. 9 provides for the embodiment of the present invention five.
Embodiment
By reference to the accompanying drawings the present invention is described in further detail below by embodiment.
Embodiment one:
Consider the program upgrade of existing function level substitute mode exist patch make loaded down with trivial details, to repair size ratio comparatively thick and well can not solve multiple problem mutually quoted by patch function; The present invention proposes and a line in software or multiple code line are upgraded, be i.e. code line level substitute mode upgrading; In order to this object can be reached, present embodiments provide a kind of method for making of patch, as shown in Figure 1, comprise the steps:
Step 101: utilize scripting language by the source code of patch function place at least a line be replaced patch script corresponding to code line, described patch script comprises patch code corresponding to described replacement code and is describedly replaced the position of code in described source code.
The present embodiment method adopts script to write patch, numerous types of data and control structure is had in the patch script write, the all local variables and global variable that can access can be accessed in by patch function in patch script, and by all structures can accessed in patch function.Overall situation functions all in original program and static function can be accessed in script
Preferably, patch script adopts a kind of similar explanation execution script language, and it use three kinds of data types, integer, character string and Associate array, it has complete control structure, comprises code block, condition, circulation sum functions.Variable does not need Examples of types of claims, can based on context automatically infer and check.
Patch script is made up of the patch code needing when probe and trigger probe to perform and probe in the present embodiment; And probe specifies the scope that will be replaced code segment, be and replace the starting position of code in source code and end position.Such as below introduce a kind of patch script, this patch script middle probe specifies the scope that will be replaced code segment, the code from page_alloc.c file 3336 row to 3341;
kernel.statement("*mm/page_alloc.c:3336").end("*mm/page_alloc.c:3341")
What follow below at probe is the patch code that will use, the code that this patch code will be replaced from page_alloc.c file 3336 row to 3341.
This script also provides and is similar to the operational character that is necessary conventional in C language, and usage is also the same, there is arithmetic operator, binary operator, assignment operator and pointer dereferences, also comprise character string connection, Associate array element and union operator.
Step 102: generate the patch module being replaced code described in replacement according to described patch script.
Step 103: be replaced according to described starting position and the end position that the position of code in described source code navigates to corresponding instruction in binary program, and add in described patch module.
The present embodiment method can utilize and be replaced starting position and the end position that code position in source code navigates to the corresponding instruction of binary program, is then added in patch module in the starting position of corresponding instruction and end position.In the present embodiment, starting position and end position refer to start address and the end address of instruction.
The start address in source code and end address is specified in the present embodiment method patch script, through the conversion of patch locating module, the start address of specifying in script and end address are converted to the start address in binary program and end address, are then kept in the code of patch module.
Particularly, the process of positioning instruction starting position and end position comprises: resolve patch script, then obtain starting position and the end position of corresponding instruction in binary program according to the position being replaced code line in patch script, be finally synthesized in patch module.Such as the code of page_alloc.c file 3336 row 3341 corresponding instruction start address in binary program is stext+0x12adad, end address is pc=_stext+0x12add0, so the above-mentioned patch write for the code segment of page_alloc.c file 3336 row 3341 can comprise following content:
kernel.statement("build_all_zonelistsmm/page_alloc.c:3336")/*pc=_stext+0x12adad*/.end("build_all_zonelistsmm/page_alloc.c:3343")/*pc=_stext+0x12add0*/
The patch module that the present embodiment method generates at least comprises: be replaced the position of code in described source code and navigate to the starting position of corresponding instruction in binary program and end position and patch code.
The method that the present embodiment provides can produce patch for a line in source code or lines of code, utilizes this patch can realize replacing a line or lines of code in function source code, thus realizes the upgrading to software; Owing to being make patch for code line, so manufacturing process simple and fast, and the patch that application invention makes is upgraded to software, avoids, in order to a minor issue is just replaced whole function, reducing the reparation granularity to program; The patch that application method for making of the present invention is produced in addition can carry out online upgrading to function multiple in original program, need not consider the mutual call relation between multiple function; Compared with prior art, the efficiency of software upgrading can be improved, reduce patch making complexity, improve safety and reliability during patch upgrading.
Preferably, above-mentioned steps 102 can comprise:
Described patch script is converted to the code of predefined type language and is compiled into the kernel module that can load;
Described kernel module is compiled into the patch module of binary program form.
Such as patch file translation is become the code of C language, then generate a kernel module that can load to after the link of C language code compilation; Last in patch module kernel module being compiled into binary program form.The patch module of such generation can be used upgrading by kernel.Same for the patch script of above-mentioned page_alloc.c file 3336 row 3341 correspondence, after this script is converted to C language code, particular content is as follows:
Be finally executable binary program by above-mentioned C language code compilation.
As shown in Figure 2, concrete to patch script in the present embodiment method processing procedure can comprise:
Step 201: resolve patch script.Script adopts and is similar to the script of awk, and script resolution phase mainly checks whether input script exists grammar mistake, and such as whether braces mates, variable-definition whether specification etc.; Also to check the security of script.
Step 202: the function defined in patch script is launched according to script bank.
This stage, mainly to the sensing point defined in patch script or the functional expansion used, not only needs to launch predefine script bank, goes back the Debugging message of Water demand kernel or kernel module.It is exactly the instruction address will determining sensing point and reentry point at this one-phase.
Step 203: the file translation after launching is become C file and C file is compiled as a kernel module that can load.
In this stage, convert the script after launching to C file.Particularly, when being C language by file translation, need the function call function call in script being converted into kernel, after being linked by C code compilation, generate a kernel module that can load.
Step 204: the C file translated is compiled as executable binary program.
Particularly, can be executable binary program by the C code compilation translated by the binary tools chain that comprises in system; In addition, also can link with the run-time library function of script bank in compilation process.The binary program that this step generates is patch module.The start address that location can be replaced on code in binary program afterwards and end address are added in this patch module.
By the flow process shown in Fig. 2, the patch module of binary mode can be produced, can be brought by all kernels and carry out software upgrading.
Embodiment two:
As shown in Figure 3, present embodiments provide a kind of Activiation method of patch, patch module activation embodiment one generated, make it replacement former in code line in patch function, particularly, comprise the steps:
Step 301: obtain patch module, described patch module comprise by the source code of patch function place at least a line be replaced patch code corresponding to code and described starting position and the end position being replaced code instruction corresponding in binary program.
Step 302: arrange for jumping to the jump instruction performing described patch code according to described starting position, makes when performing described starting position, runs described jump instruction and jumps to patch code in the described patch module of execution.
Step 303: be arranged on turn back to according to described end position after executing described patch code described by patch function relaying reforwarding line code.
The present embodiment Activiation method can arrange an agency to complete above-mentioned step in kernel, the working mechanism of this agency is: when kernel performs the start address being replaced code instruction in binary program, runs jump instruction and jumps to the patch code performing and be replaced code; When kernel executes patch code, return original function continuation operation code according to being replaced code end address of instruction in binary program.
Adopt the Activiation method of the present embodiment can realize replacing by a line in patch function or lines of code, thus realize ground program upgrade or reparation.
Preferably, arranging according to described starting position in above-mentioned steps 303 and can comprise for the process jumping to the jump instruction performing described patch code: being for jumping to the jump instruction performing described patch code by execution to the modifying of order at described starting position place.
Kernel can be made to jump to execution patch code by the mode of modify instruction in the present embodiment, thus realize program upgrade.
Preferably, the present embodiment anti-activating method can be jumped to by the mode of breakpoint exception and perform the replacement of patch code realization to code line.Particularly, the present embodiment method can also comprise: sensing point and the reentry point of installing described patch module, and described sensing point is described starting position, and described reentry point is described end position; When installing described sensing point, breakpoint abnormality processing function is associated with this sensing point; Now, described above is that step for jumping to the jump instruction performing described patch code comprises by performing the modifying of order at described starting position place: be for being jumped to the break-poing instruction performing described patch code by breakpoint abnormality processing function by the modifying of order that is detected of described sensing point, making when performing described sensing point, running described break-poing instruction and jumping to patch code in the described patch module of execution by breakpoint abnormality processing function.
In the present embodiment, sensing point essence refers to the start address will replacing programmed instruction (being replaced the instruction that code line is corresponding in binary program), and reentry point essence refers to the end address will replacing programmed instruction.Sensing point and reentry point are determined in patch module making process.In the case, the work of above-mentioned stake agency can be the setting of sensing point and reentry point, can automatically enter into breakpoint abnormal function, in breakpoint abnormal function, call patch code when CPU runs to sensing point after setting up.
Particularly, the process of installing reentry point comprises: described patch code is executed later return address and is kept in the storehouse of breakpoint exception, makes after breakpoint executes extremely, automatically jump to this return address and performs.The installation of reentry point described in the present embodiment method is exactly in the storehouse of breakpoint exception, correctly insert described patch code execute later return address.
The modifying of order that is detected of sensing point can be break-poing instruction by the present embodiment, makes kernel run break-poing instruction when performing sensing point, thus triggering breakpoints abnormality processing, jump to execution patch code by breakpoint abnormality processing.Particularly, breakpoint abnormality processing function can be associated with sensing point, when kernel performs this sensing point, trap operation will be performed because of running interruption instruction, that will cause the register preserving CPU, enter breakpoint abnormality processing function, in breakpoint abnormality processing function, search corresponding patch module according to the code section address of current C PU, then call the patch code performed in corresponding patch module.
The present embodiment deactivation arranges and can trigger following process: CPU perform during sensing point can running interruption instruction and trigger the trap exception of CPU, can preserve the context of current function and the CPU register suction parameter as patch modules interrupts point process function in trap abnormality processing function; Final redirect performs the patch code in patch module.
Preferably, be detected first or multiple byte in instruction replace with described for being jumped to the break-poing instruction performing described patch code by breakpoint abnormality processing mode in the present embodiment method.
As shown in Figure 4, the Activiation method introducing application the present embodiment is in detail realized the process of program upgrade, comprise the steps:
Step 401: when installing a sensing point and reentry point, first stake agency backs up the instruction be detected, and then uses CPU break-poing instruction (the int3 instruction of such as i386 and x86_64) to replace first or the several byte that are detected instruction.
Install whether the address that must check sensing point before sensing point is in kernel address space, or in the address space of certain kernel module.
Step 402: when CPU performs sensing point, will perform breakpoint abnormal operation because of running interruption instruction, and that, by causing the register preserving CPU, calls corresponding breakpoint abnormality processing function.
Step 403: the patch code that can call sensing point registration in breakpoint abnormality processing function, calls structure suction parameter for this function.
Step 404: the patch code performing sensing point registration.
Step 405: in order to make to turn back to the correct reentry point of specifying in patch after the patch code of sensing point registration processes, need the return address recalculating breakpoint exception, the return address in amendment exception stack.
Specifically the return address in breakpoint exception stack is revised as the return address that patch module is specified, makes after executing patch code, can turn back to and be continued to run by tram in patch function.
Step 406, owing to opening single-step debug pattern, need after executing sensing point process function burst types be 1 exception, turn back to by patch function relaying reforwarding row.
The replacement that application embodiment of the present invention Activiation method can be achieved instruction in working procedure by the breakpoint exception of CPU and abnormal later the recalculating of return address of breakpoint, certain a line in the corresponding source code of instruction of replacement or the code of a few row; The present embodiment realizes the break-poing instruction adopting CPU when instruction is replaced simultaneously, this instruction is atomic operation, can ensure safe and reliable when carrying out the online upgrading of program under multi-CPU or multithreading condition, can not cause the situation that running state of programs is inconsistent, this instruction uses in a large number in program debugger.
Embodiment three:
As shown in Figure 5, present embodiments provide a kind of on-line software updating method integrated stand composition, include the ELF binary program file of Debugging message, need the source code file of patch installing and required all header files, script translater, ELF format parser, patch module compiles device, kernel patch stake is acted on behalf of.
The described ELF binary program file including Debugging message can be the image file of kernel, also can be the binary program of kernel module.All symbolic information, relocation information and the code compilation information used by patch function can be read by this binary program, the instruction starting and ending address corresponding to code line can be navigated to by this binary program.
Described source code file and header file are used for making patch script, can be got the title of all global variables by used in patch, local variable by this source file and header file, and the member variable of data structure.
Described script translater is used for patch file translation to become the code of C language, being specific address by what quote in patch script by the variable reorientation in patch, will be that specific address adds member variable side-play amount to the reorientation of quoting of structure member variable in source code in patch script.Meanwhile, script translater increases necessary lock and safety check code as required.When file translation is C language by script translater, need the function call function call in script being converted into kernel, after the C code compilation link of generation, generate a kernel module that can load.
The instruction address of described ELF format parser in the symbolic address of helping in script translater Search and Orientation binary program and the binary program corresponding to code line.
Described patch module compiles device refers to the binary program translation and compiling environment comprised in system, is used for patch module compiles to become binary executable.
Described kernel patch stake agency has been used for the management work such as loading, activation, deactivation, unloading of patch module.
Wherein the loading of patch module refers to by patch module loading to kernel spacing, and distributes corresponding system resource.
Wherein the activation of patch module refers to the sensing point and reentry point of installing patch module.Sensing point and reentry point are determined in patch module making process.Sensing point essence refers to the start address will replacing programmed instruction, and reentry point essence refers to the end address will replacing programmed instruction.The start address of programmed instruction to be replaced and end address can be calculated by the DWARF Debugging message of the code line position in source code in conjunction with ELF form.CPU perform during sensing point can running interruption instruction and trigger the trap exception of CPU, can preserve the context of current function and the CPU register suction parameter as patch modules interrupts point process function in trap abnormality processing function.
Wherein the deactivation of patch module refers to and the former instruction backed up during patch activation is returned to sensing point address, break-poing instruction of can not reruning when CPU performs sensing point address like this and enter breakpoint process function.
Wherein the unloading of patch module refers to and from kernel spacing, removes the system resource that release patch module is applied for patch module.
Embodiment four:
As shown in Figure 6, present embodiments provide a kind of producing device of patch, comprising: script editor module 601, locating module 603 and patch generation module 602;
Described script editor module 601 for utilize scripting language by the source code of patch function place at least a line be replaced patch script corresponding to code line, described patch script comprises patch code corresponding to described replacement code and is describedly replaced the position of code in described source code;
Described patch generation module 602 is for generating the patch module being replaced code described in replacement according to described patch script;
Described locating module 603 navigates to starting position and the end position of corresponding instruction in binary program for being replaced the position of code in described source code described in basis, and adds in described patch module.
As shown in Figure 7, on the basis of said apparatus, described patch generation module 602 comprises: script translater 6021 and patch module compiles device 6022; Described script translater 6021 is for being converted to the code of predefined type language by described patch script and being compiled into the kernel module that can load; Described patch module compiles device 6022 is for being compiled into the patch module of binary program form by described kernel module.
The device of the present embodiment utilizes this patch can realize replacing a line or lines of code in function source code, thus realizes the upgrading to software; Owing to being make patch for code line, so manufacturing process simple and fast, and the patch that application invention makes is upgraded to software, avoids, in order to a minor issue is just replaced whole function, reducing the reparation granularity to program; The patch that application method for making of the present invention is produced in addition can carry out online upgrading to function multiple in original program, need not consider the mutual call relation between multiple function; Compared with prior art, the efficiency of software upgrading can be improved, reduce patch making complexity, improve safety and reliability during patch upgrading.
Embodiment five:
As shown in Figure 8, present embodiments provide a kind of active device of patch, comprise acquisition module 801, instruction arranges module 802 and return and arrange module 803;
Described acquisition module 801 for obtaining patch module, described patch module comprise by the source code of patch function place at least a line be replaced patch code corresponding to code line and described starting position and the end position being replaced code instruction corresponding in binary program;
Described instruction arranges module 802 for arranging for jumping to the jump instruction performing described patch code according to described starting position, makes when performing described starting position, runs described jump instruction and jumps to patch code in the described patch module of execution;
Described Returning equipment module 803 for be arranged on execute described patch code after turn back to according to described end position described by patch function relaying reforwarding line code.
On above-mentioned active device basis, described instruction arranges module 802 for being for jumping to the jump instruction performing described patch code by performing the modifying of order at described starting position place.
As shown in Figure 9, on above-mentioned active device basis, installation module 804 can also be comprised;
Described installation module 804 is for installing sensing point and the reentry point of described patch module, and described sensing point is described starting position, and described reentry point is described end position, and when installing described sensing point, breakpoint abnormality processing function is associated with this sensing point;
Described instruction arranges module 802 for being for being jumped to the break-poing instruction performing described patch code by breakpoint abnormality processing function by the modifying of order that is detected of described sensing point, making when performing described sensing point, running described break-poing instruction and jumping to patch code in the described patch module of execution by breakpoint abnormality processing function.
Preferably, described instruction arranges module 802 and be detected instruction described in backing up, then by described be detected first or multiple byte in instruction replace with for by breakpoint abnormality processing function perform break-poing instruction be used for jumping to by breakpoint abnormality processing function the break-poing instruction performing described patch code.
Adopt the active device of the present embodiment can make when kernel runs to starting position, run described jump instruction and jump to patch code in the described patch module of execution, achieve and can replace for a line or lines of code in software upgrade process.
Above content is in conjunction with concrete embodiment further description made for the present invention, can not assert that specific embodiment of the invention is confined to these explanations.For general technical staff of the technical field of the invention, without departing from the inventive concept of the premise, some simple deduction or replace can also be made, all should be considered as belonging to protection scope of the present invention.

Claims (13)

1. a method for making for patch, is characterized in that, comprises the steps:
Utilize scripting language by the source code of patch function place at least a line be replaced patch script corresponding to code, described patch script comprises patch code corresponding to described replacement code and is describedly replaced the position of code in described source code;
The patch module being replaced code described in replacement is generated according to described patch script;
Be replaced according to described starting position and the end position that the position of code in described source code navigates to corresponding instruction in binary program, and add in described patch module.
2. the method for claim 1, is characterized in that, the described step being replaced the patch module of code according to described patch script generation replacement comprises:
Described patch script is converted to the code of predefined type language and is compiled into the kernel module that can load;
Described kernel module is compiled into the patch module of binary program form.
3. method as claimed in claim 2, it is characterized in that, described predefined type language comprises C language.
4. an Activiation method for patch, is characterized in that, comprises the steps:
Obtain patch module, described patch module comprise by the source code of patch function place at least a line be replaced patch code corresponding to code and described starting position and the end position being replaced code instruction corresponding in binary program;
Arranging for jumping to the jump instruction performing described patch code according to described starting position, making when performing described starting position, run described jump instruction and jump to patch code in the described patch module of execution;
Be arranged on turn back to according to described end position after executing described patch code described by patch function relaying reforwarding line code.
5. method as claimed in claim 4, is characterized in that,
Described setting according to described starting position comprises for the step jumping to the jump instruction performing described patch code:
Be for jumping to the jump instruction performing described patch code by performing the modifying of order at described starting position place.
6. method as claimed in claim 5, it is characterized in that, also comprise: sensing point and the reentry point of installing described patch module, described sensing point is described starting position, and described reentry point is described end position;
When installing described sensing point, breakpoint abnormality processing function is associated with this sensing point;
Described is that step for jumping to the jump instruction performing described patch code comprises by performing the modifying of order at described starting position place:
Be for being jumped to the break-poing instruction performing described patch code by breakpoint abnormality processing function by the modifying of order that is detected of described sensing point, making when performing described sensing point, running described break-poing instruction and jumping to patch code in the described patch module of execution by breakpoint abnormality processing function.
7. method as claimed in claim 6, is characterized in that, the described modifying of order that is detected by described sensing point is that step for being jumped to the break-poing instruction performing described patch code by breakpoint abnormality processing function is comprised:
Be detected instruction described in backup, then by described be detected first or multiple byte in instruction replace with for by breakpoint abnormality processing function perform break-poing instruction be used for jumping to by breakpoint abnormality processing function the break-poing instruction performing described patch code.
8. a producing device for patch, is characterized in that, comprising: script editor module, locating module and patch generation module;
Described script editor module for utilize scripting language by the source code of patch function place at least a line be replaced patch script corresponding to code, described patch script comprises patch code corresponding to described replacement code and is describedly replaced the position of code in described source code;
Described patch generation module is used for generating according to described patch script the patch module being replaced code described in replacement;
Described locating module is used for being replaced starting position and the end position that the position of code in described source code navigates to corresponding instruction in binary program described in basis, and adds in described patch module.
9. device as claimed in claim 8, it is characterized in that, described patch generation module comprises: script translater and patch module compiles device;
Described script translater is used for described patch script being converted to the code of predefined type language and being compiled into the kernel module that can load;
Described patch module compiles device is used for the patch module described kernel module being compiled into binary program form.
10. an active device for patch, is characterized in that, comprises acquisition module, instruction arranges module and return and arrange module;
Described acquisition module for obtaining patch module, described patch module comprise by the source code of patch function place at least a line be replaced patch code corresponding to code and described starting position and the end position being replaced code instruction corresponding in binary program;
Described instruction arranges module for arranging for jumping to the jump instruction performing described patch code according to described starting position, makes when performing described starting position, runs described jump instruction and jumps to patch code in the described patch module of execution;
Described Returning equipment module be used for being arranged on execute described patch code after turn back to according to described end position described by patch function relaying reforwarding line code.
11. devices as claimed in claim 10, is characterized in that, described instruction arranges module for being for jumping to the jump instruction performing described patch code by performing the modifying of order at described starting position place.
12. devices as claimed in claim 11, is characterized in that, also comprise: installation module;
Described installation module is for installing sensing point and the reentry point of described patch module, and described sensing point is described starting position, and described reentry point is described end position, and when installing described sensing point, breakpoint abnormality processing function is associated with this sensing point;
Described instruction arranges module for being for being jumped to the break-poing instruction performing described patch code by breakpoint abnormality processing function by the modifying of order that is detected of described sensing point, making when performing described sensing point, running described break-poing instruction and jumping to patch code in the described patch module of execution by breakpoint abnormality processing function.
13. devices as claimed in claim 12, it is characterized in that, described instruction arranges module and be detected instruction described in backing up, then by described be detected first or multiple byte in instruction replace with for by breakpoint abnormality processing function perform break-poing instruction be used for jumping to by breakpoint abnormality processing function the break-poing instruction performing described patch code.
CN201410416228.9A 2014-08-21 2014-08-21 Patch making method and apparatus and patch activation method and apparatus Withdrawn CN105354045A (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN201410416228.9A CN105354045A (en) 2014-08-21 2014-08-21 Patch making method and apparatus and patch activation method and apparatus
PCT/CN2014/090497 WO2015117434A1 (en) 2014-08-21 2014-11-06 Method and device for manufacturing patch, and method and device for activating patch

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201410416228.9A CN105354045A (en) 2014-08-21 2014-08-21 Patch making method and apparatus and patch activation method and apparatus

Publications (1)

Publication Number Publication Date
CN105354045A true CN105354045A (en) 2016-02-24

Family

ID=53777246

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201410416228.9A Withdrawn CN105354045A (en) 2014-08-21 2014-08-21 Patch making method and apparatus and patch activation method and apparatus

Country Status (2)

Country Link
CN (1) CN105354045A (en)
WO (1) WO2015117434A1 (en)

Cited By (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106569863A (en) * 2016-11-10 2017-04-19 福州智永信息科技有限公司 Android app resource updating and repairing method based on resource and code modularization
CN107451474A (en) * 2016-05-31 2017-12-08 百度在线网络技术(北京)有限公司 Software vulnerability restorative procedure and device for terminal
CN107463375A (en) * 2017-07-18 2017-12-12 上海斐讯数据通信技术有限公司 A kind of method and system for detecting source code
CN107506293A (en) * 2016-06-14 2017-12-22 中兴通讯股份有限公司 A kind of software performance data acquisition method and device
CN107908402A (en) * 2017-08-15 2018-04-13 口碑(上海)信息技术有限公司 The hot restorative procedure of Java server-sides and system
CN108009429A (en) * 2017-12-11 2018-05-08 北京奇虎科技有限公司 A kind of patch function generation method and device
CN109725923A (en) * 2018-12-27 2019-05-07 广州华多网络科技有限公司 A kind of software light weight update method, device and equipment
CN111796832A (en) * 2020-06-30 2020-10-20 苏州三六零智能安全科技有限公司 Hot patch file generation method, device, equipment and storage medium
CN111930413A (en) * 2020-05-22 2020-11-13 无锡中感微电子股份有限公司 Automatic patch generation method, device and system

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106843933A (en) * 2016-12-27 2017-06-13 北京五八信息技术有限公司 A kind of leak restorative procedure of application program, mobile terminal and patch server

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101561764A (en) * 2009-05-18 2009-10-21 华为技术有限公司 Patching method and patching device under multi-core environment
CN103077062A (en) * 2012-11-30 2013-05-01 华为技术有限公司 Method and device for detecting code change
US8468516B1 (en) * 2008-12-19 2013-06-18 Juniper Networks, Inc. Creating hot patches for embedded systems
CN103207779A (en) * 2012-01-16 2013-07-17 国际商业机器公司 Apparatus And Method Useful For Source Code Patches

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1230744C (en) * 2002-08-16 2005-12-07 华为技术有限公司 realization of isertion type system soft ware patch and control method

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8468516B1 (en) * 2008-12-19 2013-06-18 Juniper Networks, Inc. Creating hot patches for embedded systems
CN101561764A (en) * 2009-05-18 2009-10-21 华为技术有限公司 Patching method and patching device under multi-core environment
CN103207779A (en) * 2012-01-16 2013-07-17 国际商业机器公司 Apparatus And Method Useful For Source Code Patches
CN103077062A (en) * 2012-11-30 2013-05-01 华为技术有限公司 Method and device for detecting code change

Cited By (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107451474A (en) * 2016-05-31 2017-12-08 百度在线网络技术(北京)有限公司 Software vulnerability restorative procedure and device for terminal
CN107451474B (en) * 2016-05-31 2020-06-26 百度在线网络技术(北京)有限公司 Software bug fixing method and device for terminal
CN107506293B (en) * 2016-06-14 2022-04-22 中兴通讯股份有限公司 Software performance data acquisition method and device
CN107506293A (en) * 2016-06-14 2017-12-22 中兴通讯股份有限公司 A kind of software performance data acquisition method and device
CN106569863A (en) * 2016-11-10 2017-04-19 福州智永信息科技有限公司 Android app resource updating and repairing method based on resource and code modularization
CN106569863B (en) * 2016-11-10 2020-01-17 福州智永信息科技有限公司 Resource and code modularization-based android app resource updating and repairing method
CN107463375A (en) * 2017-07-18 2017-12-12 上海斐讯数据通信技术有限公司 A kind of method and system for detecting source code
CN107908402A (en) * 2017-08-15 2018-04-13 口碑(上海)信息技术有限公司 The hot restorative procedure of Java server-sides and system
CN108009429A (en) * 2017-12-11 2018-05-08 北京奇虎科技有限公司 A kind of patch function generation method and device
CN109725923A (en) * 2018-12-27 2019-05-07 广州华多网络科技有限公司 A kind of software light weight update method, device and equipment
CN111930413A (en) * 2020-05-22 2020-11-13 无锡中感微电子股份有限公司 Automatic patch generation method, device and system
CN111930413B (en) * 2020-05-22 2023-07-21 无锡中感微电子股份有限公司 Automatic patch generation method, device and system
CN111796832A (en) * 2020-06-30 2020-10-20 苏州三六零智能安全科技有限公司 Hot patch file generation method, device, equipment and storage medium
CN111796832B (en) * 2020-06-30 2022-11-04 苏州三六零智能安全科技有限公司 Hot patch file generation method, device, equipment and storage medium

Also Published As

Publication number Publication date
WO2015117434A1 (en) 2015-08-13

Similar Documents

Publication Publication Date Title
CN105354045A (en) Patch making method and apparatus and patch activation method and apparatus
CN101799763B (en) Method, device and system for patching kernel on line
US6948164B2 (en) Method and system for modifying executable code to add additional functionality
CN102402427B (en) A kind of update method of java application and device
US9672133B2 (en) Systems and methods for debugging applications using dual code generation
US8745596B2 (en) Program debugging with dynamically inserted instrumentation
CN105630557B (en) Hot patch method and apparatus
CN101667154A (en) Apparatus and method for improving emulation speed of high-level languages in on-chip emulation systems
CN105528231A (en) Intermediate auxiliary function-based method and intermediate auxiliary function-based system for dynamically updating software
US20100275185A1 (en) System and Method for High Performance Coverage Analysis
CN102364433B (en) Method for realizing Wine construction tool transplanting on ARM (Advanced RISC Machines) processor
Romano et al. An empirical study of bugs in webassembly compilers
Borchert et al. Protecting the dynamic dispatch in C++ by dependability aspects
CN102722438A (en) Kernel debugging method and equipment
EP3891613B1 (en) Software checkpoint-restoration between distinctly compiled executables
CN102662845B (en) A kind of method, Apparatus and system realized through property data breakpoint
CN109144849B (en) Embedded software debugging method
US20170344350A1 (en) Triage self-repair for statically compiled executables
CN111984329B (en) Boot software standardized generation and execution method and system
CN111309444B (en) Method, device, system and storage medium for anti-debugging by using process virtual machine
Huang et al. {PYLIVE}:{On-the-Fly} Code Change for Python-based Online Services
He et al. Demystifying and mitigating cross-layer deficiencies of soft error protection in instruction duplication
Cui et al. WhirlingFuzzwork: a taint-analysis-based API in-memory fuzzing framework
Császár et al. Building fast and reliable reverse engineering tools with Frida and Rust
Mehlich CheckPointer-AC Memory Access Validator

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
WW01 Invention patent application withdrawn after publication

Application publication date: 20160224

WW01 Invention patent application withdrawn after publication