python - How detect code change? -
python - How detect code change? -
let's suppose code this:
class="lang-py prettyprint-override">class x: def myfunc(self): print "orig" def new_myfunc(self): print "new" x().myfunc() x.myfunc = new_myfunc x().myfunc() where new function injected cheater. functions can altered,others not. know how can observe code change. illustration create dict contain original function codes( "func_code" ) , check if changed how can run check @ every "import"? there way edit autoloader in python?
edit: do, automatically every import,how?
class="lang-py prettyprint-override">protection = {'x':'myfunc'} f = {} class x: def myfunc(self): print "orig" def new_myfunc(self): print "new" #system check key,value in protection.iteritems(): protectedfunc = getattr(eval(key), value) f[key] = { value : protectedfunc.func_code} #cheater code x.myfunc = new_myfunc #system check key,value in protection.iteritems(): protectedfunc = getattr(eval(key), value) if f[key][value] != protectedfunc.func_code: print 'detected' #call app x().myfunc()
i know several ways task. illustration can check md5 or other. variant can utilize diff. python has back upwards of one, two.
python
Comments
Post a Comment