Skip to content

Commit 328b2cd

Browse files
Arusekkpeace-maker
andauthored
Drop six (#2547)
Co-authored-by: Peace-Maker <[email protected]>
1 parent 636b3b2 commit 328b2cd

File tree

607 files changed

+2492
-2021
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

607 files changed

+2492
-2021
lines changed

pwnlib/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
'libcdb',
2424
'log',
2525
'memleak',
26-
'pep237',
2726
'regsort',
2827
'replacements',
2928
'rop',

pwnlib/adb/adb.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
import os
5555
import re
5656
import shutil
57-
import six
5857
import stat
5958
import tempfile
6059
import time
@@ -85,7 +84,7 @@ def adb(argv, *a, **kw):
8584
>>> adb.adb(['shell', 'uname']) # it is better to use adb.process
8685
b'Linux\n'
8786
"""
88-
if isinstance(argv, (bytes, six.text_type)):
87+
if isinstance(argv, (bytes, str)):
8988
argv = [argv]
9089

9190
log.debug("$ " + ' '.join(context.adb + argv))
@@ -838,7 +837,7 @@ def process(argv, *a, **kw):
838837
>>> print(adb.process(['cat','/proc/version']).recvall().decode('utf-8')) # doctest: +ELLIPSIS
839838
Linux version ...
840839
"""
841-
if isinstance(argv, (bytes, six.text_type)):
840+
if isinstance(argv, (bytes, str)):
842841
argv = [argv]
843842

844843
message = "Starting %s process %r" % ('Android', argv[0])
@@ -1263,7 +1262,7 @@ def __eq__(self, other):
12631262
>>> adb.properties.ro.build.version.sdk == "24"
12641263
True
12651264
"""
1266-
if isinstance(other, six.string_types):
1265+
if isinstance(other, str):
12671266
return str(self) == other
12681267
return super(Property, self).__eq__(other)
12691268

pwnlib/adb/bootloader.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import ctypes
55
import io
66
import os
7-
import six
87
import sys
98

109
from pwnlib.log import getLogger
@@ -65,7 +64,7 @@ def extract(self, index_or_name):
6564
Returns:
6665
Contents of the image.
6766
"""
68-
if isinstance(index_or_name, six.integer_types):
67+
if isinstance(index_or_name, int):
6968
index = index_or_name
7069
else:
7170
for i in range(len(self.img_info)):

pwnlib/commandline/cyclic.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from __future__ import division
33

44
import argparse
5-
import six
65
import string
76
import sys
87

@@ -47,6 +46,7 @@
4746
group.add_argument(
4847
'-l', '-o', '--offset', '--lookup',
4948
dest = 'lookup',
49+
type = str.encode,
5050
metavar = 'lookup_value',
5151
help = 'Do a lookup instead printing the alphabet',
5252
)
@@ -66,9 +66,6 @@ def main(args):
6666
if args.lookup:
6767
pat = args.lookup
6868

69-
if six.PY3:
70-
pat = bytes(pat, encoding='utf-8')
71-
7269
try:
7370
pat = int(pat, 0)
7471
pat = pack(pat, 'all')

pwnlib/commandline/shellcraft.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import argparse
55
import os
6-
import six
76
import sys
87
import types
98

@@ -280,8 +279,8 @@ def main(args):
280279

281280
code_array = []
282281
for (name, func, func_args) in funcs:
283-
defargs = len(six.get_function_defaults(func) or ())
284-
reqargs = six.get_function_code(func).co_argcount - defargs
282+
defargs = len(func.__defaults__ or ())
283+
reqargs = func.__code__.co_argcount - defargs
285284

286285
if len(func_args) < reqargs:
287286
if defargs > 0:

pwnlib/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from __future__ import absolute_import
3636
from __future__ import division
3737

38-
from six.moves import configparser
38+
import configparser
3939
import os
4040

4141
registered_configs = {}

pwnlib/context/__init__.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import os.path
1616
import platform
1717
import shutil
18-
import six
1918
import socket
2019
import string
2120
import sys
@@ -1043,7 +1042,7 @@ def log_file(self, value):
10431042
>>> open(bar_txt).readlines()[-1] #doctest: +ELLIPSIS
10441043
'...:DEBUG:...:Hello from bar!\n'
10451044
"""
1046-
if isinstance(value, (bytes, six.text_type)):
1045+
if isinstance(value, (bytes, str)):
10471046
# check if mode was specified as "[value],[mode]"
10481047
from pwnlib.util.packing import _need_text
10491048
value = _need_text(value)
@@ -1261,7 +1260,7 @@ def terminal(self, value):
12611260
Can be a string or an iterable of strings. In the latter case the first
12621261
entry is the terminal and the rest are default arguments.
12631262
"""
1264-
if isinstance(value, (bytes, six.text_type)):
1263+
if isinstance(value, (bytes, str)):
12651264
return [value]
12661265
return value
12671266

@@ -1342,7 +1341,7 @@ def adb_port(self, value):
13421341
def device(self, device):
13431342
"""Sets the device being operated on.
13441343
"""
1345-
if isinstance(device, (bytes, six.text_type)):
1344+
if isinstance(device, (bytes, str)):
13461345
device = Device(device)
13471346
if isinstance(device, Device):
13481347
self.arch = device.arch or self.arch
@@ -1758,7 +1757,7 @@ def update_context_defaults(section):
17581757

17591758
default = ContextType.defaults[key]
17601759

1761-
if isinstance(default, six.string_types + six.integer_types + (tuple, list, dict)):
1760+
if isinstance(default, (str, int, tuple, list, dict)):
17621761
value = safeeval.expr(value)
17631762
else:
17641763
log.warn("Unsupported configuration option %r in section %r" % (key, 'context'))

pwnlib/data/syscalls/Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
ROOT=$(shell git rev-parse --show-toplevel)
2-
TEMPLATE_DIR="$ROOT/pwnlib/shellcraft/templates/common/linux/syscalls"
32

43
all: generate.py functions.py
54
python generate.py "$(ROOT)/pwnlib/shellcraft/templates/common/linux/syscalls"

pwnlib/data/syscalls/generate.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
# github.com/zachriggle/functions
1111
from functions import functions, Function, Argument
1212

13-
ARCHITECTURES = ['i386', 'amd64', 'arm', 'aarch64', 'mips']
13+
ARCHITECTURES = ['i386', 'amd64', 'arm', 'aarch64', 'mips', 'riscv64', 'powerpc64']
1414

1515
HEADER = '''
1616
<%
17+
# Auto-generated by pwnlib/data/syscalls/generate.py. DO NOT EDIT!
1718
import collections
1819
import pwnlib.abi
1920
import pwnlib.constants
2021
import pwnlib.shellcraft
21-
import six
2222
%>
2323
'''
2424

@@ -40,7 +40,7 @@
4040
<%page args="{arguments_default_values}"/>
4141
"""
4242

43-
CALL = """
43+
CALL = r"""
4444
<%
4545
abi = pwnlib.abi.ABI.syscall()
4646
stack = abi.stack
@@ -76,8 +76,8 @@
7676
7777
# The argument is not a register. It is a string value, and we
7878
# are expecting a string value
79-
elif name in can_pushstr and isinstance(arg, (six.binary_type, six.text_type)):
80-
if isinstance(arg, six.text_type):
79+
elif name in can_pushstr and isinstance(arg, (bytes, bytearray, str)):
80+
if isinstance(arg, str):
8181
arg = arg.encode('utf-8')
8282
string_arguments[name] = arg
8383
@@ -112,7 +112,7 @@
112112
%>
113113
/* {name}(${{', '.join(syscall_repr)}}) */
114114
%for name, arg in string_arguments.items():
115-
${{pwnlib.shellcraft.pushstr(arg, append_null=(b'\\x00' not in arg))}}
115+
${{pwnlib.shellcraft.pushstr(arg, append_null=(b'\x00' not in arg))}}
116116
${{pwnlib.shellcraft.mov(regs[argument_names.index(name)], abi.stack)}}
117117
%endfor
118118
%for name, arg in array_arguments.items():

pwnlib/elf/elf.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@
4141
import mmap
4242
import os
4343
import re
44-
import six
4544
import subprocess
4645
import tempfile
4746

48-
from six import BytesIO
47+
from io import BytesIO
4948

5049
from collections import namedtuple, defaultdict
5150

@@ -266,7 +265,7 @@ def __init__(self, path, checksec=True):
266265
#:
267266
#: See: :attr:`.ContextType.arch`
268267
self.arch = self.get_machine_arch()
269-
if isinstance(self.arch, (bytes, six.text_type)):
268+
if isinstance(self.arch, (bytes, str)):
270269
self.arch = self.arch.lower()
271270

272271
self._sections = None

pwnlib/encoders/i386/ascii_shellcode.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
from itertools import product
88

9-
import six
10-
119
from pwnlib.context import LocalContext
1210
from pwnlib.context import context
1311
from pwnlib.encoders.encoder import Encoder
@@ -43,10 +41,7 @@ def __init__(self, slop=20, max_subs=4):
4341
there are, the bigger the packed shellcode will be.
4442
Defaults to 4.
4543
"""
46-
if six.PY2:
47-
super(AsciiShellcodeEncoder, self).__init__()
48-
elif six.PY3:
49-
super().__init__()
44+
super().__init__()
5045
self.slop = slop
5146
self.max_subs = max_subs
5247

pwnlib/encoders/i386/delta.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import absolute_import
22
from __future__ import division
33

4-
import six
54
import collections
65
from random import choice
76
from random import randint
@@ -59,7 +58,7 @@ def __call__(self, raw_bytes, avoid, pcreg=''):
5958
table = collections.defaultdict(lambda: [])
6059
endchar = bytearray()
6160

62-
not_bad = lambda x: six.int2byte(x) not in avoid
61+
not_bad = lambda x: x not in avoid
6362
not_bad_or_term = lambda x: not_bad(x) and x != self.terminator
6463

6564
for i in filter(not_bad_or_term, range(0, 256)):

pwnlib/encoders/mips/xor.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from __future__ import absolute_import
2626
from __future__ import division
2727

28-
import six
2928
from pwnlib import asm
3029
from pwnlib import shellcraft
3130
from pwnlib.context import context
@@ -128,8 +127,8 @@ def __call__(self, raw_bytes, avoid, pcreg=''):
128127
sizehi = size >> 8
129128

130129
decoder = decoders[context.endian]
131-
decoder = decoder.replace(b'SIZ1', six.int2byte(sizehi))
132-
decoder = decoder.replace(b'SIZ2', six.int2byte(sizelo))
130+
decoder = decoder.replace(b'SIZ1', bytes([sizehi]))
131+
decoder = decoder.replace(b'SIZ2', bytes([sizelo]))
133132

134133
key, data = xor_key(raw_bytes, avoid=avoid)
135134

pwnlib/filepointer.py

-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
from pwnlib.context import context
2929
from pwnlib.log import getLogger
30-
from pwnlib.util.misc import python_2_bytes_compatible
3130
from pwnlib.util.packing import pack
3231

3332
log = getLogger(__name__)
@@ -98,7 +97,6 @@ def update_var(l):
9897
return var
9998

10099

101-
@python_2_bytes_compatible
102100
class FileStructure(object):
103101
r"""
104102
Crafts a FILE structure, with default values for some fields, like _lock which should point to null ideally, set.

pwnlib/filesystem/path.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
import six
21
import tempfile
32

4-
if six.PY3:
5-
from pathlib import *
6-
else:
7-
from pathlib2 import *
3+
from pathlib import *
84

95
@classmethod
106
def mktemp(cls):

pwnlib/filesystem/ssh.py

+4-18
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
Emulates pathlib as much as possible, but does so through duck typing.
66
"""
77
import os
8-
import six
98
import sys
109
import tempfile
1110
import time
@@ -14,10 +13,7 @@
1413
from pwnlib.util.misc import read, write
1514
from pwnlib.util.packing import _encode, _decode
1615

17-
if six.PY3:
18-
from pathlib import *
19-
else:
20-
from pathlib2 import *
16+
from pathlib import *
2117

2218
class SSHPath(PosixPath):
2319
r"""Represents a file that exists on a remote filesystem.
@@ -81,13 +77,8 @@ def _s(self, other):
8177
if isinstance(other, str):
8278
return other
8379

84-
# We don't want unicode
85-
if isinstance(other, six.text_type):
86-
return str(other)
87-
88-
# We also don't want binary
89-
if isinstance(other, six.binary_type):
90-
return str(_decode(other))
80+
# We don't want binary
81+
return _decode(other)
9182

9283
def _new(self, path, *a, **kw):
9384
kw['ssh'] = self.ssh
@@ -399,14 +390,9 @@ def resolve(self, strict=False):
399390
path = self.absolute().path
400391
path = os.path.normpath(path)
401392

402-
if six.PY2:
403-
error_type = IOError
404-
else:
405-
error_type = FileNotFoundError
406-
407393
try:
408394
return self._new(self.ssh.sftp.normalize(path))
409-
except error_type as e:
395+
except FileNotFoundError as e:
410396
raise ValueError("Could not normalize path: %r" % path)
411397

412398
def stat(self):

pwnlib/fmtstr.py

-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ def send_payload(payload):
9898
import logging
9999
import re
100100
from operator import itemgetter
101-
from six.moves import range
102101
from sortedcontainers import SortedList
103102

104103
from pwnlib.log import getLogger

0 commit comments

Comments
 (0)