Skip to content
Closed
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
9 changes: 7 additions & 2 deletions pwnlib/util/packing.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,14 +576,14 @@ def fit(pieces, **kwargs):
>>> fit({12: 0x41414141,
... 24: 'Hello',
... })
'aaaabaaacaaaAAAAdaaaeaaaHello'
'aaaabaaacaaaAAAAeaaafaaaHello'
>>> fit({'caaa': ''})
'aaaabaaa'
>>> fit({12: 'XXXX'}, filler = 'AB', length = 20)
'ABABABABABABXXXXABAB'
>>> fit({ 8: [0x41414141, 0x42424242],
... 20: 'CCCC'})
'aaaabaaaAAAABBBBcaaaCCCC'
'aaaabaaaAAAABBBBeaaaCCCC'

"""
# HACK: To avoid circular imports we need to delay the import of `cyclic`
Expand Down Expand Up @@ -627,6 +627,11 @@ def fit(pieces, **kwargs):
out.append(filler.next())
v = _flat([v], preprocessor, packer)
l = k + len(v)

# consume the filler for each byte of actual data
for i in range(len(out), l):
filler.next()

out[k:l] = v

# truncate/pad output
Expand Down