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

Gallopsled / pwntools / 0696c5cb4f6b03219b64b58dbfac850cb6b65d99

pending completion
0696c5cb4f6b03219b64b58dbfac850cb6b65d99

push

github-actions

web-flow
shellcraft/*/freebsd: match linux in switching cs (#2232)

* shellcraft/*/freebsd: match linux in switching cs

* shellcraft: note trashed registers in switching cs

3768 of 6275 branches covered (60.05%)

12270 of 16705 relevant lines covered (73.45%)

2.2 hits per line

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

75.71
/pwnlib/commandline/cyclic.py
1
#!/usr/bin/env python2
2
from __future__ import absolute_import
3✔
3
from __future__ import division
3✔
4

5
import argparse
3✔
6
import six
3✔
7
import string
3✔
8
import sys
3✔
9

10
import pwnlib.args
3✔
11
pwnlib.args.free_form = False
3✔
12

13
from pwn import *
3✔
14
from pwnlib.commandline import common
3✔
15

16
parser = common.parser_commands.add_parser(
3✔
17
    'cyclic',
18
    help = "Cyclic pattern creator/finder",
19
    description = "Cyclic pattern creator/finder"
20
)
21

22
parser.add_argument(
3✔
23
    '-a', '--alphabet',
24
    metavar = 'alphabet',
25
    default = string.ascii_lowercase.encode(),
26
    type = packing._encode,
27
    help = 'The alphabet to use in the cyclic pattern (defaults to all lower case letters)',
28
)
29

30
parser.add_argument(
3✔
31
    '-n', '--length',
32
    metavar = 'length',
33
    default = 4,
34
    type = int,
35
    help = 'Size of the unique subsequences (defaults to 4).'
36
)
37

38
parser.add_argument(
3✔
39
    '-c', '--context',
40
    metavar = 'context',
41
    action = 'append',
42
    type   = common.context_arg,
43
    choices = common.choices,
44
    help = 'The os/architecture/endianness/bits the shellcode will run in (default: linux/i386), choose from: %s' % common.choices,
45
)
46

47
group = parser.add_mutually_exclusive_group(required=False)
3✔
48
group.add_argument(
3✔
49
    '-l', '-o', '--offset', '--lookup',
50
    dest = 'lookup',
51
    metavar = 'lookup_value',
52
    help = 'Do a lookup instead printing the alphabet',
53
)
54

55
group.add_argument(
3✔
56
    'count',
57
    type=int,
58
    nargs='?',
59
    default=None,
60
    help='Number of characters to print'
61
)
62

63
def main(args):
3✔
64
    alphabet = args.alphabet
3✔
65
    subsize  = args.length
3✔
66

67
    if args.lookup:
3✔
68
        pat = args.lookup
3✔
69

70
        if six.PY3:
3!
71
            pat = bytes(pat, encoding='utf-8')
×
72

73
        try:
3✔
74
            pat = int(pat, 0)
3✔
75
            pat = pack(pat, 'all')
3✔
76
        except ValueError:
×
77
            pass
×
78
        pat = flat(pat, bytes=args.length)
3✔
79

80
        if len(pat) < subsize:
3!
81
            log.critical('Subpattern must be at least %d bytes' % subsize)
×
82
            sys.exit(1)
×
83
        else:
84
            pat = pat[:subsize]
3✔
85

86
        if not all(c in alphabet for c in pat):
3!
87
            log.critical('Pattern contains characters not present in the alphabet')
×
88
            sys.exit(1)
×
89

90
        offset = cyclic_find(pat, alphabet, subsize)
3✔
91

92
        if offset == -1:
3!
93
            log.critical('Given pattern does not exist in cyclic pattern')
×
94
            sys.exit(1)
×
95
        else:
96
            print(offset)
3✔
97
    else:
98
        want   = args.count
3✔
99
        result = cyclic(want, alphabet, subsize)
3✔
100
        got    = len(result)
3✔
101
        if want is not None and got < want:
3!
102
            log.failure("Alphabet too small (max length = %i)" % got)
×
103

104
        out = getattr(sys.stdout, 'buffer', sys.stdout)
3✔
105
        out.write(result)
3✔
106

107
        if out.isatty():
3!
108
            out.write(b'\n')
×
109

110
if __name__ == '__main__':
3✔
111
    pwnlib.commandline.common.main(__file__)
3✔
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