pwnlib.tubes.buffer
— buffer implementation for tubes
- class pwnlib.tubes.buffer.Buffer(buffer_fill_size=None)[source]
List of strings with some helper routines.
Example
>>> b = Buffer() >>> b.add(b"A" * 10) >>> b.add(b"B" * 10) >>> len(b) 20 >>> b.get(1) b'A' >>> len(b) 19 >>> b.get(9999) b'AAAAAAAAABBBBBBBBBB' >>> len(b) 0 >>> b.get(1) b''
Implementation Details:
Implemented as a list. Strings are added onto the end. The
0th
item in the buffer is the oldest item, and will be received first.- __contains__(x)[source]
>>> b = Buffer() >>> b.add(b'asdf') >>> b'x' in b False >>> b.add(b'x') >>> b'x' in b True
- __len__()[source]
>>> b = Buffer() >>> b.add(b'lol') >>> len(b) == 3 True >>> b.add(b'foobar') >>> len(b) == 9 True
- get(want=inf)[source]
Retrieves bytes from the buffer.
- Parameters
want (int) – Maximum number of bytes to fetch
- Returns
Data as string
Example
>>> b = Buffer() >>> b.add(b'hello') >>> b.add(b'world') >>> b.get(1) b'h' >>> b.get() b'elloworld'
- get_fill_size(size=None)[source]
Retrieves the default fill size for this buffer class.
- Parameters
size (int) – (Optional) If set and not None, returns the size variable back.
- Returns
Fill size as integer if size is None, else size.
- index(x)[source]
>>> b = Buffer() >>> b.add(b'asdf') >>> b.add(b'qwert') >>> b.index(b't') == len(b) - 1 True