forked from lunixbochs/patchkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatch
executable file
·39 lines (29 loc) · 1.17 KB
/
patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
import os
import sys
from core import Patcher
from optparse import OptionParser
if __name__ == '__main__':
parser = OptionParser(usage='Usage: patcher [options] <binary> <patchdir> [patchdir...]')
parser.add_option('-o', '--out', dest="out", help="output filename (default = <binary>.patched)")
parser.add_option('-v', '--verbose', dest="verbose", action="store_true", help="verbose output")
parser.add_option('-n', '--new', dest='new', help="create new binary from template/<new>")
parser.add_option('--cflags', dest='cflags', help="add compiler flags to injected C")
options, args = parser.parse_args()
if len(args) < 2:
parser.print_help()
sys.exit(1)
args = map(os.path.abspath, args)
patchdirs = args[1:]
if options.new:
binary = os.path.join(os.path.dirname(__file__), 'template', options.new)
defout = args[0]
else:
binary = args[0]
defout = (binary + '.patched')
out = os.path.abspath(options.out or defout)
patch = Patcher(binary, verbose=options.verbose, cflags=options.cflags)
for d in patchdirs:
patch.add(d)
patch.patch()
patch.save(out)