Skip to content
Open
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
44 changes: 44 additions & 0 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 Down Expand Up @@ -873,6 +875,45 @@ 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 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__,)),))
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 +954,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