Livepatch is a tool that can hot patch running processes. It can easily modify the variables in the running process, replace the functions in the running process, and use the new library function to replace the functions in the original main process!
1. livepatch source code download:
Http://sourcehoge.net/Software/livepatch/
2. binutil download (the author uses version 2.15 ):
Http://ftp.gnu.org/gnu/binutils/
3. Compile the binutil package:
The binutil package of version 2.15 has a small bug. This error is reported during compilation:
Gcc-dhave_config_h-I. -ihttp: // www.cnblogs.com/binutils-2.15/gas-I. -d_gnu_source-I. -ihttp: // www.cnblogs.com/binutils-2.15/gas-I .. /BFD-ihttp: // www.cnblogs.com/binutils-2.15/gas/config-ihttp: // your-ihttp: // www.cnblogs.com/binutils-2.15/gas /.. -ihttp: // www.cnblogs.com/binutils-2.15/gas/./bfd-ihttp: // www.cnblogs.com/binutils-2.15/gas/./intl-I .. /Intl-dlocaledir = "\"/home/public/study/binutils/target_x86/build/share/locale \ ""-w-wall-wstrict-prototypes-wmissing-prototypes- g-O2-C http://www.cnblogs.com/binutils-2.15/gas/app.c
In file encoded ded from./targ-cpu.h: 1,
From http://www.cnblogs.com/binutils-2.15/gas/config/obj-elf.h:42,
From./obj-format.h: 1,
From http://www.cnblogs.com/binutils-2.15/gas/config/te-linux.h:4,
From./targ-env.h: 1,
From http://www.cnblogs.com/binutils-2.15/gas/as.h:626,
From http://www.cnblogs.com/binutils-2.15/gas/app.c:30:
Http://www.cnblogs.com/binutils-2.15/gas/config/tc-i386.h:451: error: array type has incomplete element type
Make [3]: *** [App. O] Error 1
Make [3]: Leaving directory '/home/public/study/binutils/target_x86/Gas'
Make [2]: *** [All-recursive] Error 1
Make [2]: Leaving directory '/home/public/study/binutils/target_x86/Gas'
Make [1]: *** [all] Error 2
Make [1]: Leaving directory '/home/public/study/binutils/target_x86/Gas'
Make: *** [All-gas] Error 2
Jimmy @ Linux-JIMMY:/home/public/study/binutils/target_x86>
Modification method:
(1), put the ../binutils-2.15/Gas/config/tc-i386.h file 451st lines:
Extern const struct relax_type md_relax_table [];
To:
Extern const struct relax_type * md_relax_table;
Change the data structure corresponding to ../binutils-2.15/Gas/config/tc-i386.c to const struct relax_type md_relax_table_ex [];
Add: const struct relax_type * md_relax_table = md_relax_table_ex;
Patch: Diff-Nur binutils-2.15 binutils-2.15.jimmy/
Diff-Nur binutils-2.15/Gas/config/tc-i386.c binutils-2.15.jimmy/Gas/config/tc-i386.c
--- Binutils-2.15/Gas/config/tc-i386.c 03:36:09. 000000000 + 0800
+ + Binutils-2.15.jimmy/Gas/config/tc-i386.c 2010-02-22 21:29:41. 000000000 + 0800
@-363,7 + 363,7 @@
Prefix), and doesn't work, unless the destination is in the bottom
64 K of the code segment (the top 16 bits of EIP are zeroed ).*/
-Const relax_types md_relax_table [] =
+ Const relax_types md_relax_table_ex [] =
{
/* The fields are:
1) most positive reach of this state,
@-402,6 + 402,8 @@
{0, 0, 4, 0}
};
+ Const relax_types * md_relax_table = md_relax_table_ex;
+
Static const arch_entry cpu_arch [] = {
{"I8086", cpu086 },
{"I186", cpu086 | cpu186 },
Diff-Nur binutils-2.15/Gas/config/tc-i386.h binutils-2.15.jimmy/Gas/config/tc-i386.h
--- Binutils-2.15/Gas/config/tc-i386.h 03:36:09. 000000000 + 0800
+ + Binutils-2.15.jimmy/Gas/config/tc-i386.h 2010-02-22 21:26:12. 000000000 + 0800
@-448,7 + 448,7 @@
# Define md_operand (X)
-Extern const struct relax_type md_relax_table [];
+ Extern const struct relax_type * md_relax_table;
# Define tc_generic_relax_table md_relax_table
Extern int optimize_align_code;
4. Compile the livepatch package:
Modify makefile here:
Jimmy @ Linux-JIMMY:/home/public/study/livepatch/source> CAT makefile
#
# Makefile for livepatch
# $ ID: makefile 330 11: 38: 02z Ukai $
# Copyright (c) 2004 fumitoshi Ukai <ukai@debian.or.jp>
# All Rights Reserved.
# This is free software with absolutely no warranty.
#
# You can redistribute it and/or modify it under the terms
# The GNU General Public License version 2.
#
Binutils_dir =/home/public/study/binutils/target_x86/build
Cflags =-wall-O2-g-I $ (binutils_dir)/include
ALL: livepatch
Livepatch: livepatch. o
$ (CC)-o $ @ $ <-L $ (binutils_dir)/lib-lbfd-liberty-lopcodes
Fixup: fixup. o
$ (CC)-o $ @ $ <-L $ (binutils_dir)/lib-lbfd-liberty-lopcodes
BFD: BFD. o
$ (CC)-o $ @ $ <-L $ (bin_utils_dir)/lib-lbfd-liberty-lopcodes
Clean:
-Rm-f *. o
-Rm-F livepatch fixup BFD
# EOF
5. test:
Jimmy @ Linux-JIMMY:/home/public/study/livepatch/test>./test. Sh
In main process test_func: 0
In main process test_func_x: 0
In main process test_func: 1
In main process test_func_x: 1
In main process test_func: 2
In main process test_func_x: 2
In main process test_func: 3
In main process test_func_x: 3
In main process test_func: 4
In main process test_func_x: 4
Bfd_openr: no such file or directory
DL test @ 0xb7f0f000 [8220] libtest. So
JMP 0x804841f 0xb7f0f45c <-Install the patch. The main process calls the function to the patch and changes the database!
In livepatch test_func: 5
In main process test_func_x:-5 <-The patch function calls back the function in the main process.
In livepatch test_func: 6
In main process test_func_x:-6
In livepatch test_func: 7
In main process test_func_x:-7
In livepatch test_func: 8
In main process test_func_x:-8
In livepatch test_func: 9
In main process test_func_x:-9
In livepatch test_func: 10
In main process test_func_x:-10
./Test. sh: Line 11: 8195 killed./test
Jimmy @ Linux-JIMMY:/home/public/study/livepatch/test>
6. complete source code and test package (excluding binutils ):
Http://files.cnblogs.com/WuCountry/livepatch.rar