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
|
from __future__ import absolute_import
from __future__ import division
import sys
import pwnlib.args
pwnlib.args.free_form = False
from pwn import *
from pwnlib.commandline import common
p = common.parser_commands.add_parser(
'elfpatch',
help = 'Patch an ELF file',
description = 'Patch an ELF file'
)
p.add_argument('elf',help="File to patch")
p.add_argument('offset',help="Offset to patch in virtual address (hex encoded)")
p.add_argument('bytes',help='Bytes to patch (hex encoded)')
def main(a):
if not a.offset.startswith('0x'):
a.offset = '0x' + a.offset
offset = int(a.offset, 16)
bytes = unhex(a.bytes)
with context.silent:
elf = ELF(a.elf)
elf.write(offset, bytes)
getattr(sys.stdout, 'buffer', sys.stdout).write(elf.get_data())
if __name__ == '__main__':
pwnlib.commandline.common.main(__file__, main)
|