Git Product home page Git Product logo

Comments (5)

ebeip90 avatar ebeip90 commented on July 20, 2024

It looks like the only place for us to inject is threading.Thread.__bootstrap.

# At the end of 'context.py', add
class ContextPreservingThread(threading.Thread):
    def __init__(self, *args, **kwargs):
        super(ContextPreservingThread, self).__init__(*args, **kwargs)
        self.parent_ctx    = context._thread_ctx()
        self.__old_bootstrap = self._Thread__bootstrap
        self._Thread__bootstrap = self.__new_bootstrap

    def __new_bootstrap(self):
        context._ctxs.setdefault(
            threading.current_thread().ident, self.parent_ctx
        )
        return self.__old_bootstrap()
context.log_level = 'silent'
def bar():                                       
    print context.log_level
bar()
# 100
threading.Thread(target=bar).start()
# 20
ContextPreservingThread(target=bar).start()
# 100

The proper way to get it implemented is to replace all calls to threading.Thread within pwntools. The 'fuck it' way would be to:

threading.Thread = ContextPreservingThread

But this may have unintended side effects, and is probably a Bad Ideaβ„’.

from pwntools.

zachriggle avatar zachriggle commented on July 20, 2024

Sorry, posted on the wrong account. @ebeip90 is me.

from pwntools.

zachriggle avatar zachriggle commented on July 20, 2024

Is this an acceptable mechanism for implementation?

from pwntools.

TethysSvensson avatar TethysSvensson commented on July 20, 2024

I think we should avoid monkey-patching if possible.

I also think that your model of how to fix the context module is slightly too simple. But otherwise, yes, this is the way to do it.

from pwntools.

zachriggle avatar zachriggle commented on July 20, 2024

I'm merging #124 into my master and won't pursue any further

from pwntools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.