Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop six #2547

Merged
merged 2 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 0 additions & 1 deletion pwnlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
'libcdb',
'log',
'memleak',
'pep237',
'regsort',
'replacements',
'rop',
Expand Down
7 changes: 3 additions & 4 deletions pwnlib/adb/adb.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import os
import re
import shutil
import six
import stat
import tempfile
import time
Expand Down Expand Up @@ -85,7 +84,7 @@ def adb(argv, *a, **kw):
>>> adb.adb(['shell', 'uname']) # it is better to use adb.process
b'Linux\n'
"""
if isinstance(argv, (bytes, six.text_type)):
if isinstance(argv, (bytes, str)):
argv = [argv]

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

message = "Starting %s process %r" % ('Android', argv[0])
Expand Down Expand Up @@ -1263,7 +1262,7 @@ def __eq__(self, other):
>>> adb.properties.ro.build.version.sdk == "24"
True
"""
if isinstance(other, six.string_types):
if isinstance(other, str):
return str(self) == other
return super(Property, self).__eq__(other)

Expand Down
3 changes: 1 addition & 2 deletions pwnlib/adb/bootloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import ctypes
import io
import os
import six
import sys

from pwnlib.log import getLogger
Expand Down Expand Up @@ -65,7 +64,7 @@ def extract(self, index_or_name):
Returns:
Contents of the image.
"""
if isinstance(index_or_name, six.integer_types):
if isinstance(index_or_name, int):
index = index_or_name
else:
for i in range(len(self.img_info)):
Expand Down
5 changes: 1 addition & 4 deletions pwnlib/commandline/cyclic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from __future__ import division

import argparse
import six
import string
import sys

Expand Down Expand Up @@ -47,6 +46,7 @@
group.add_argument(
'-l', '-o', '--offset', '--lookup',
dest = 'lookup',
type = str.encode,
metavar = 'lookup_value',
help = 'Do a lookup instead printing the alphabet',
)
Expand All @@ -66,9 +66,6 @@ def main(args):
if args.lookup:
pat = args.lookup

if six.PY3:
pat = bytes(pat, encoding='utf-8')

try:
pat = int(pat, 0)
pat = pack(pat, 'all')
Expand Down
5 changes: 2 additions & 3 deletions pwnlib/commandline/shellcraft.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import argparse
import os
import six
import sys
import types

Expand Down Expand Up @@ -280,8 +279,8 @@ def main(args):

code_array = []
for (name, func, func_args) in funcs:
defargs = len(six.get_function_defaults(func) or ())
reqargs = six.get_function_code(func).co_argcount - defargs
defargs = len(func.__defaults__ or ())
reqargs = func.__code__.co_argcount - defargs

if len(func_args) < reqargs:
if defargs > 0:
Expand Down
2 changes: 1 addition & 1 deletion pwnlib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from __future__ import absolute_import
from __future__ import division

from six.moves import configparser
import configparser
import os

registered_configs = {}
Expand Down
9 changes: 4 additions & 5 deletions pwnlib/context/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import os.path
import platform
import shutil
import six
import socket
import string
import sys
Expand Down Expand Up @@ -1043,7 +1042,7 @@ def log_file(self, value):
>>> open(bar_txt).readlines()[-1] #doctest: +ELLIPSIS
'...:DEBUG:...:Hello from bar!\n'
"""
if isinstance(value, (bytes, six.text_type)):
if isinstance(value, (bytes, str)):
# check if mode was specified as "[value],[mode]"
from pwnlib.util.packing import _need_text
value = _need_text(value)
Expand Down Expand Up @@ -1261,7 +1260,7 @@ def terminal(self, value):
Can be a string or an iterable of strings. In the latter case the first
entry is the terminal and the rest are default arguments.
"""
if isinstance(value, (bytes, six.text_type)):
if isinstance(value, (bytes, str)):
return [value]
return value

Expand Down Expand Up @@ -1342,7 +1341,7 @@ def adb_port(self, value):
def device(self, device):
"""Sets the device being operated on.
"""
if isinstance(device, (bytes, six.text_type)):
if isinstance(device, (bytes, str)):
device = Device(device)
if isinstance(device, Device):
self.arch = device.arch or self.arch
Expand Down Expand Up @@ -1758,7 +1757,7 @@ def update_context_defaults(section):

default = ContextType.defaults[key]

if isinstance(default, six.string_types + six.integer_types + (tuple, list, dict)):
if isinstance(default, (str, int, tuple, list, dict)):
value = safeeval.expr(value)
else:
log.warn("Unsupported configuration option %r in section %r" % (key, 'context'))
Expand Down
1 change: 0 additions & 1 deletion pwnlib/data/syscalls/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
ROOT=$(shell git rev-parse --show-toplevel)
TEMPLATE_DIR="$ROOT/pwnlib/shellcraft/templates/common/linux/syscalls"

all: generate.py functions.py
python generate.py "$(ROOT)/pwnlib/shellcraft/templates/common/linux/syscalls"
Expand Down
12 changes: 6 additions & 6 deletions pwnlib/data/syscalls/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
# github.com/zachriggle/functions
from functions import functions, Function, Argument

ARCHITECTURES = ['i386', 'amd64', 'arm', 'aarch64', 'mips']
ARCHITECTURES = ['i386', 'amd64', 'arm', 'aarch64', 'mips', 'riscv64', 'powerpc64']

HEADER = '''
<%
# Auto-generated by pwnlib/data/syscalls/generate.py. DO NOT EDIT!
import collections
import pwnlib.abi
import pwnlib.constants
import pwnlib.shellcraft
import six
%>
'''

Expand All @@ -40,7 +40,7 @@
<%page args="{arguments_default_values}"/>
"""

CALL = """
CALL = r"""
<%
abi = pwnlib.abi.ABI.syscall()
stack = abi.stack
Expand Down Expand Up @@ -76,8 +76,8 @@

# The argument is not a register. It is a string value, and we
# are expecting a string value
elif name in can_pushstr and isinstance(arg, (six.binary_type, six.text_type)):
if isinstance(arg, six.text_type):
elif name in can_pushstr and isinstance(arg, (bytes, bytearray, str)):
if isinstance(arg, str):
arg = arg.encode('utf-8')
string_arguments[name] = arg

Expand Down Expand Up @@ -112,7 +112,7 @@
%>
/* {name}(${{', '.join(syscall_repr)}}) */
%for name, arg in string_arguments.items():
${{pwnlib.shellcraft.pushstr(arg, append_null=(b'\\x00' not in arg))}}
${{pwnlib.shellcraft.pushstr(arg, append_null=(b'\x00' not in arg))}}
${{pwnlib.shellcraft.mov(regs[argument_names.index(name)], abi.stack)}}
%endfor
%for name, arg in array_arguments.items():
Expand Down
5 changes: 2 additions & 3 deletions pwnlib/elf/elf.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@
import mmap
import os
import re
import six
import subprocess
import tempfile

from six import BytesIO
from io import BytesIO

from collections import namedtuple, defaultdict

Expand Down Expand Up @@ -266,7 +265,7 @@ def __init__(self, path, checksec=True):
#:
#: See: :attr:`.ContextType.arch`
self.arch = self.get_machine_arch()
if isinstance(self.arch, (bytes, six.text_type)):
if isinstance(self.arch, (bytes, str)):
self.arch = self.arch.lower()

self._sections = None
Expand Down
7 changes: 1 addition & 6 deletions pwnlib/encoders/i386/ascii_shellcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

from itertools import product

import six

from pwnlib.context import LocalContext
from pwnlib.context import context
from pwnlib.encoders.encoder import Encoder
Expand Down Expand Up @@ -43,10 +41,7 @@ def __init__(self, slop=20, max_subs=4):
there are, the bigger the packed shellcode will be.
Defaults to 4.
"""
if six.PY2:
super(AsciiShellcodeEncoder, self).__init__()
elif six.PY3:
super().__init__()
super().__init__()
self.slop = slop
self.max_subs = max_subs

Expand Down
3 changes: 1 addition & 2 deletions pwnlib/encoders/i386/delta.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import absolute_import
from __future__ import division

import six
import collections
from random import choice
from random import randint
Expand Down Expand Up @@ -59,7 +58,7 @@ def __call__(self, raw_bytes, avoid, pcreg=''):
table = collections.defaultdict(lambda: [])
endchar = bytearray()

not_bad = lambda x: six.int2byte(x) not in avoid
not_bad = lambda x: x not in avoid
not_bad_or_term = lambda x: not_bad(x) and x != self.terminator

for i in filter(not_bad_or_term, range(0, 256)):
Expand Down
5 changes: 2 additions & 3 deletions pwnlib/encoders/mips/xor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from __future__ import absolute_import
from __future__ import division

import six
from pwnlib import asm
from pwnlib import shellcraft
from pwnlib.context import context
Expand Down Expand Up @@ -128,8 +127,8 @@ def __call__(self, raw_bytes, avoid, pcreg=''):
sizehi = size >> 8

decoder = decoders[context.endian]
decoder = decoder.replace(b'SIZ1', six.int2byte(sizehi))
decoder = decoder.replace(b'SIZ2', six.int2byte(sizelo))
decoder = decoder.replace(b'SIZ1', bytes([sizehi]))
decoder = decoder.replace(b'SIZ2', bytes([sizelo]))

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

Expand Down
2 changes: 0 additions & 2 deletions pwnlib/filepointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

from pwnlib.context import context
from pwnlib.log import getLogger
from pwnlib.util.misc import python_2_bytes_compatible
from pwnlib.util.packing import pack

log = getLogger(__name__)
Expand Down Expand Up @@ -98,7 +97,6 @@ def update_var(l):
return var


@python_2_bytes_compatible
class FileStructure(object):
r"""
Crafts a FILE structure, with default values for some fields, like _lock which should point to null ideally, set.
Expand Down
6 changes: 1 addition & 5 deletions pwnlib/filesystem/path.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import six
import tempfile

if six.PY3:
from pathlib import *
else:
from pathlib2 import *
from pathlib import *

@classmethod
def mktemp(cls):
Expand Down
22 changes: 4 additions & 18 deletions pwnlib/filesystem/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Emulates pathlib as much as possible, but does so through duck typing.
"""
import os
import six
import sys
import tempfile
import time
Expand All @@ -14,10 +13,7 @@
from pwnlib.util.misc import read, write
from pwnlib.util.packing import _encode, _decode

if six.PY3:
from pathlib import *
else:
from pathlib2 import *
from pathlib import *

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

# We don't want unicode
if isinstance(other, six.text_type):
return str(other)

# We also don't want binary
if isinstance(other, six.binary_type):
return str(_decode(other))
# We don't want binary
return _decode(other)

def _new(self, path, *a, **kw):
kw['ssh'] = self.ssh
Expand Down Expand Up @@ -399,14 +390,9 @@ def resolve(self, strict=False):
path = self.absolute().path
path = os.path.normpath(path)

if six.PY2:
error_type = IOError
else:
error_type = FileNotFoundError

try:
return self._new(self.ssh.sftp.normalize(path))
except error_type as e:
except FileNotFoundError as e:
raise ValueError("Could not normalize path: %r" % path)

def stat(self):
Expand Down
1 change: 0 additions & 1 deletion pwnlib/fmtstr.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ def send_payload(payload):
import logging
import re
from operator import itemgetter
from six.moves import range
from sortedcontainers import SortedList

from pwnlib.log import getLogger
Expand Down
Loading
Loading