• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Gallopsled / pwntools / 11306567235

12 Oct 2024 02:57PM CUT coverage: 74.25%. First build
11306567235

Pull #2486

github

web-flow
Merge b9c0426e6 into 78dd77773
Pull Request #2486: Test Python version >= 3.10 in CI and fix tests on Python 3.12

3679 of 6140 branches covered (59.92%)

20 of 34 new or added lines in 22 files covered. (58.82%)

12973 of 17472 relevant lines covered (74.25%)

0.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

40.54
/pwnlib/commandline/pwnstrip.py
1
from __future__ import absolute_import
1✔
2
from __future__ import division
1✔
3

4
import argparse
1✔
5

6
import pwnlib.args
1✔
7
pwnlib.args.free_form = False
1✔
8

9
from pwn import *
1✔
10
from pwnlib.commandline import common
1✔
11

12
p = common.parser_commands.add_parser(
1✔
13
    'pwnstrip',
14
    help = 'Strip binaries for CTF usage',
15
    description = 'Strip binaries for CTF usage'
16
)
17

18
g = p.add_argument_group("actions")
1✔
19
g.add_argument('-b', '--build-id', help="Strip build ID", action='store_true')
1✔
20
g.add_argument('-p', '--patch', metavar='FUNCTION', help="Patch function", action='append')
1✔
21
p.add_argument('-o', '--output', type=argparse.FileType('wb'), default=getattr(sys.stdout, 'buffer', sys.stdout))
1✔
22
p.add_argument('file', type=argparse.FileType('rb'))
1✔
23

24
def main(args):
1✔
25
    if not (args.patch or args.build_id):
×
26
        sys.stderr.write("Must specify at least one action\n")
×
27
        sys.stderr.write(p.format_usage())
×
28
        sys.exit(0)
×
29

30
    elf = ELF(args.file.name)
×
31
    context.clear(arch=elf.arch)
×
32

33
    if args.build_id:
×
34
        for offset in pwnlib.libcdb.get_build_id_offsets():
×
35
            data = elf.read(elf.address + offset + 0xC, 4)
×
36
            if data == 'GNU\x00':
×
37
                elf.write(elf.address + offset + 0x10, os.urandom(20))
×
38

39
    for function in args.patch:
×
40
        if function not in elf.symbols:
×
41
            log.error("Could not find function %r" % function)
×
42

43
        trap = asm(shellcraft.trap())
×
44
        offset = elf.symbols[function]
×
45

46
        elf.write(elf.address + offset, trap)
×
47

48
    result = elf.data
×
49

50
    if args.output.isatty():
×
51
        result = enhex(result).encode('ascii')
×
52

53
    args.output.write(result)
×
54

55
if __name__ == '__main__':
1!
NEW
56
    pwnlib.commandline.common.main(__file__, main)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc