Skip to content
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
test:
strategy:
matrix:
python_version: ['3.10', '3.12', '3.13']
python_version: ['3.10', '3.12', '3.13', '3.14']
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
timeout-minutes: 30
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ The table below shows which release corresponds to each branch, and what date th
## 5.0.0 (`dev`)

- [#2638][2638] feat: add disable_corefiles context option
- [#2627][2627] remove pwnlib.util.iters.lookahead (broken anyway)
- [#2598][2598] aarch64: Fix ABI definition
- [#2419][2419] riscv: avoid compressed instructions (if you need compressed, use .option rvc)
- [#2551][2551] Detect when kitty is being used as terminal
Expand Down Expand Up @@ -106,6 +107,7 @@ The table below shows which release corresponds to each branch, and what date th
- [#2630][2630] support `preexec_fn` in `debug()`

[2638]: https://github.com/Gallopsled/pwntools/pull/2638
[2627]: https://github.com/Gallopsled/pwntools/pull/2627
[2598]: https://github.com/Gallopsled/pwntools/pull/2598
[2419]: https://github.com/Gallopsled/pwntools/pull/2419
[2551]: https://github.com/Gallopsled/pwntools/pull/2551
Expand Down
85 changes: 53 additions & 32 deletions pwnlib/util/iters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

import collections
import copy
import marshal
import multiprocessing
import operator
import random
import time
import types
from itertools import *

from pwnlib.context import context
Expand All @@ -26,7 +28,6 @@
'group' ,
'iter_except' ,
'lexicographic' ,
'lookahead' ,
'nth' ,
'pad' ,
'pairwise' ,
Expand Down Expand Up @@ -679,37 +680,6 @@ def random_combination_with_replacement(iterable, r):
indices = sorted(random.randrange(n) for i in range(r))
return tuple(pool[i] for i in indices)

def lookahead(n, iterable):
"""lookahead(n, iterable) -> object

Inspects the upcoming element at index `n` without advancing the iterator.
Raises ``IndexError`` if `iterable` has too few elements.

Arguments:
n(int): Index of the element to return.
iterable: An iterable.

Returns:
The element in `iterable` at index `n`.

Examples:

>>> i = count()
>>> lookahead(4, i)
4
>>> next(i)
0
>>> i = count()
>>> nth(4, i)
4
>>> next(i)
5
>>> lookahead(4, i)
10
"""
for value in islice(copy.copy(iterable), n, None):
return value
raise IndexError(n)

def lexicographic(alphabet):
"""lexicographic(alphabet) -> iterator
Expand Down Expand Up @@ -873,6 +843,54 @@ def _mbruteforcewrap(func, alphabet, length, method, start, databag):
databag["result"] = res


class CustomPickler:
def __init__(self, *reduction):
self.reduction = reduction

def __reduce__(self):
return self.reduction

def __repr__(self):
return self.__class__.__name__ + repr(self.reduction)


def construct_func(*args):
return types.FunctionType(*args)


class PicklableFunc:
def __init__(self, f):
self.f = f

def __call__(self, *a, **kw):
return self.f(*a, **kw)

def __getattr__(self, a):
return getattr(self.f, a)

def __reduce__(self):
# Constructor types.FunctionType tries to be __main__.function;
# globs could likewise be <module>.__dict__. Neither
# type('FunctionType', (), {'__module__':'types'})
# nor
# def __reduce__(self): return "FunctionType"
# works because of checks for identity :(
globs = CustomPickler(vars, (CustomPickler(__import__, (self.f.__module__ or '__main__',)),))
return type(self), (CustomPickler(
construct_func, # ideally self.f.__class__
# but types.FunctionType tries to be __main__.function
(
CustomPickler(marshal.loads, (marshal.dumps(self.f.__code__),)),
globs,
self.f.__name__,
self.f.__defaults__,
self.f.__closure__,
self.f.__kwdefaults__,
),
self.f.__dict__,
),)


def mbruteforce(func, alphabet, length, method = 'upto', start = None, threads = None):
"""mbruteforce(func, alphabet, length, method = 'upto', start = None, threads = None)

Expand Down Expand Up @@ -913,6 +931,9 @@ def mbruteforce(func, alphabet, length, method = 'upto', start = None, threads =
(i2, N2) = start
totalchunks = threads * N2

if isinstance(func, types.FunctionType):
func = PicklableFunc(func)

for i in range(threads):
shareddata[i] = multiprocessing.Manager().dict()
shareddata[i]['result'] = None
Expand Down
2 changes: 1 addition & 1 deletion pwnlib/util/safeeval.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
'POP_TOP','ROT_TWO','ROT_THREE','ROT_FOUR','DUP_TOP',
'BUILD_LIST','BUILD_MAP', 'MAP_ADD', 'BUILD_TUPLE','BUILD_SET',
'BUILD_CONST_KEY_MAP', 'BUILD_STRING',
'LOAD_CONST','RETURN_VALUE','STORE_SUBSCR', 'STORE_MAP',
'LOAD_CONST','LOAD_SMALL_INT','RETURN_VALUE','STORE_SUBSCR', 'STORE_MAP',
'LIST_TO_TUPLE', 'LIST_EXTEND', 'SET_UPDATE', 'DICT_UPDATE', 'DICT_MERGE',
'COPY', 'RESUME', 'RETURN_CONST'
]
Expand Down
Loading