Skip to content

Instantly share code, notes, and snippets.

@kecs
Created March 11, 2019 13:13
Show Gist options
  • Save kecs/aa3bff33919245b112b211fd8858655e to your computer and use it in GitHub Desktop.
Save kecs/aa3bff33919245b112b211fd8858655e to your computer and use it in GitHub Desktop.
import os, re, sys
"""
Recursively traverse a php repo, add a line that logs fn calls.
Non overlapping matches!
Arg: output file full path
"""
OUTFILE = sys.argv[1]
for root, dirs, files in os.walk(os.getcwd(), topdown=False):
for name in files:
try:
if name.endswith('.php'):
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("{}", "a") or die("FUUUCK");fwrite($f, "{} :: function \2");fclose($f);'.format(OUTFILE, filename),
f.read())
f.seek(0)
f.write(processed)
except UnicodeDecodeError as e:
print('[*] Unicode error at ', filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment