Annotation of pkgsrc/pkgtools/binpatch/files/binpatch.1, revision 1.1
1.1 ! atatat 1: .\" $NetBSD$
! 2: .\"
! 3: .\" Copyright (c) 2004 by Andrew Brown <atatat@netbsd.org>
! 4: .\" Absolutely no warranty.
! 5: .\"
! 6: .Dd July 20, 2004
! 7: .Dt BINPATCH 1
! 8: .Sh NAME
! 9: .Nm binpatch
! 10: .Nd trivial binary patch applicator
! 11: .Sh SYNOPSIS
! 12: .Nm
! 13: .Pa file=...
! 14: .Pa size=...
! 15: .Pa offset=...
! 16: .Pa compare=...
! 17: .Pa skip=...
! 18: .Pa replace=...
! 19: .Sh DESCRIPTION
! 20: The
! 21: .Nm
! 22: utility can read and replace a small section of a given file.
! 23: It is designed for use in those instances where a problem exists with
! 24: a given binary that cannot be reconstructed from source code, but the
! 25: required change can be implemented by replacing a few bytes in the
! 26: existing binary.
! 27: All arguments must be given.
! 28: .Sh EXAMPLES
! 29: Given a binary called
! 30: .Dq a.out
! 31: of 10713 bytes in size with the following text segment:
! 32: .Bd -literal -offset indent
! 33: % objdump -h a.out
! 34: .sp
! 35: a.out: file format elf32-i386
! 36: .sp
! 37: Sections:
! 38: Idx Name Size VMA LMA File off Algn
! 39: [...]
! 40: 9 .text 00000be4 08048968 08048968 00000968 2**2
! 41: CONTENTS, ALLOC, LOAD, READONLY, CODE
! 42: [...]
! 43: % objdump -d -j .text a.out
! 44: [...]
! 45: 8048b0f: 83 ef 04 sub $0x4,%edi
! 46: 8048b12: ff d0 call *%eax
! 47: 8048b14: 83 fe ff cmp $0xffffffff,%esi
! 48: [...]
! 49: .sp
! 50: .Ed
! 51: where we wish to elide the call through
! 52: .Ar %eax
! 53: by replacing it with a series of
! 54: .Ar nop
! 55: (or
! 56: .Dq no operation )
! 57: instructions (the machine code for this on the i386 platform is 0x90),
! 58: we first calculate the offset into the file of the previous
! 59: .Ar sub
! 60: instruction. To do this, we take the address of the
! 61: .Ar sub
! 62: instruction as given by the dissassembly output, subtract the
! 63: .Dq LMA
! 64: and add the
! 65: .Dq File off
! 66: values from the objdump output (note that
! 67: .Xr bc 1
! 68: expects hexadecimal values to be given using upper case):
! 69: .Bd -literal -offset indent
! 70: % bc
! 71: ibase=16
! 72: 8048B0F-08048968+00000968
! 73: 2831
! 74: .sp
! 75: .Ed
! 76: The region of the binary we want to compare to before applying the
! 77: patch is the concatenation of the relevant machine codes from the
! 78: dissassembly dump (\c
! 79: .Ar 83ef04ffd083feff )
! 80: and the replacement is simply two
! 81: .Ar nop
! 82: instructions (\c
! 83: .Ar 9090 ) ,
! 84: that will replace the
! 85: .Ar ffd0
! 86: of the original call.
! 87: The offset of the replacement is 3, since that is the number of bytes
! 88: in the
! 89: .Ar sub
! 90: instruction.
! 91: From this we have our patch:
! 92: .Bd -literal -offset indent
! 93: % binpatch file=a.out size=10713 offset=2831 \\
! 94: compare=83ef04ffd083feff skip=3 replace=9090
! 95: % objdump -d -j .text a.out
! 96: [...]
! 97: 8048b0f: 83 ef 04 sub $0x4,%edi
! 98: 8048b12: 90 nop
! 99: 8048b13: 90 nop
! 100: 8048b14: 83 fe ff cmp $0xffffffff,%esi
! 101: [...]
! 102: .sp
! 103: .Ed
! 104: And thus the call is removed.
! 105: .Sh DIAGNOSTICS
! 106: The diagnostics are terse and almost unhelpful, but are more verbose
! 107: than users of
! 108: .Xr ed 1
! 109: might be used to.
! 110: They typically mention the command line argument that was in error.
! 111: .Sh SEE ALSO
! 112: .Xr bc 1 ,
! 113: .Xr objdump 1 ,
! 114: .Xr patch 1
! 115: .Sh AUTHORS
! 116: .An Andrew Brown Aq atatat@netbsd.org
CVSweb <webmaster@jp.NetBSD.org>