Skip to content

Instantly share code, notes, and snippets.

@kecs
Created November 1, 2019 13:23
Show Gist options
  • Save kecs/7a3c0d456473a79218e638b43e32bfa2 to your computer and use it in GitHub Desktop.
Save kecs/7a3c0d456473a79218e638b43e32bfa2 to your computer and use it in GitHub Desktop.
import sys
"""
Recursively traverse a php repo,
add a line that logs fn calls.
Non overlapping matches.
cd into project root.
"""
WHITELIST = [
'Services',
'Modules',
'src',
'goto.php',
'login.php',
]
def predicate(name):
return any([s in name for s in WHITELIST])
for root, dirs, files in os.walk(os.getcwd(), topdown=False):
for name in files:
try:
if name.endswith('.php') and predicate(name):
filename = os.path.join(root, name)
with open(filename, 'r+') as f:
processed = re.sub('(function\s([a-zA-Z1-9\s\$\(\)-_]+){)',
r'\1 $f = fopen("/home/mihaly_gabor_dev/fns", "a") or die("FUUUCK");fwrite($f, "{} :: function \2\\n");fclose($f);'.format(filename),
f.read())
f.seek(0)
f.write(processed)
except UnicodeDecodeError as e:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment