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

Tubes with context.encoding #1317

Merged
merged 10 commits into from
Jun 22, 2019
Merged

Tubes with context.encoding #1317

merged 10 commits into from
Jun 22, 2019

Conversation

Arusekk
Copy link
Member

@Arusekk Arusekk commented Jun 21, 2019

This is an example of what can be done. I can work more on the doctests so that they cover the new code.

Closes #1315

@Arusekk Arusekk self-assigned this Jun 21, 2019
@zachriggle
Copy link
Member

zachriggle commented Jun 22, 2019

Thanks for the work on these! I think it might be easier (and more maintainable) to have these declared dynamically.

Consider sticking something at the end of tube.py that looks like this:

for func in [tube.recv, 
             tube.recvn, 
             tube.recvlines, 
             tube.recvuntil]:
    def make_wrapper(func):
        def wrapper(self, *a, **kw):
            return bytearray(func(self, *a, **kw))
        wrapper.__doc__ = 'Same as {func.__name__}, but returns a bytearray'.format(func=func)
        wrapper.__name__ = func.__name__ + 'b'
        return wrapper
    wrapper = make_wrapper(func)
    setattr(tube, wrapper.__name__, wrapper)

# Clean up module scope
del make_wrapper
del wrapper

You can then do the following:

>>> help(tube.recvb)
Help on method recvb in module pwnlib.tubes.tube:

recvb(self, *a, **kw) unbound pwnlib.tubes.tube.tube method
    Same as recv, but returns a bytearray

>>> t=tube()
>>> t.unrecv('asdfasdf')
>>> t.recvnb(3)
bytearray(b'asd')
>>> t.recvnb(3)
bytearray(b'fas')
>>> t.recvnb(3)
EOFError

@Arusekk Arusekk requested a review from zachriggle June 22, 2019 13:52
@Arusekk Arusekk merged commit b2130e3 into Gallopsled:dev3 Jun 22, 2019
@Arusekk Arusekk deleted the context-encoding branch June 22, 2019 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants