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

Gallopsled / pwntools / 8912ca5a8c3a9725c3ba6d30561607150a6faebe-PR-2205

pending completion
8912ca5a8c3a9725c3ba6d30561607150a6faebe-PR-2205

Pull #2205

github-actions

web-flow
Merge 81f463e2c into 8b4cacf8b
Pull Request #2205: Fix stable Python 2 installation from a built wheel

3878 of 6371 branches covered (60.87%)

12199 of 16604 relevant lines covered (73.47%)

0.73 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
1✔
3
from __future__ import division
1✔
4

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

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

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

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

22
parser.add_argument(
1✔
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(
1✔
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(
1✔
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)
1✔
48
group.add_argument(
1✔
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(
1✔
56
    'count',
57
    type=int,
58
    nargs='?',
59
    default=None,
60
    help='Number of characters to print'
61
)
62

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

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

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

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

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

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

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

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

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

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

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