Skip to content

Instantly share code, notes, and snippets.

@endofline endofline/test_a.py
Created Feb 15, 2017

Embed
What would you like to do?
subverting imported libraries
# test_a.py
# in the bot, this represents the new hangups library
this_is_a_constant = 'ABCD'
def print_constant():
print(repr(this_is_a_constant))
# test_b.py
# in the bot, this represents the plugin
import test_a
# test_c.py
# in the bot, this file is the plugin loader
import test_b # plugin is loaded
import test_d # we replace the test_a module inside the plugin with this in EXAMPLE 2
# EXAMPLE 1: replace constant
# setattr(test_b.test_a, 'this_is_a_constant', 'no longer constant');
# EXAMPLE 2: replace module
# setattr(test_b, 'test_a', test_d) # replaces module with another one
test_b.test_a.print_constant()
# in example 1, this prints 'no longer constant'
# in example 2, this prints '3.142'
# test_d.py
# in the bot, this replaces new hangups (test_a.py) with the compatibility layer
def print_constant():
print('3.142');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.