Skip to content

Instantly share code, notes, and snippets.

@int3
Created July 20, 2011 03:15
Show Gist options
  • Save int3/1094257 to your computer and use it in GitHub Desktop.
Save int3/1094257 to your computer and use it in GitHub Desktop.
De-anonymize JS functions
#! /usr/bin/env python
"""
Usage: cat [infile] | python deanon.py > [outfile]
Anonymous functions will be renamed to anon_[lineno]_*
where * is a number that gets incremented for each functionon the line
"""
from sys import stdin, stdout, stderr, argv
import re
if len(argv) > 1:
lines = open(argv[1]).readlines()
out = open(argv[1], 'w')
else:
lines = stdin.readlines()
out = stdout
x = {}
x["anon_count"] = 0
def make_repl_func(lineno):
x["anon_line_count"] = 0
def create_id(match):
unique_id = str(lineno + 1) + "_" + str(x["anon_line_count"])
x["anon_line_count"] += 1
x["anon_count"] += 1
return "function anon_%s(" % unique_id
return create_id
for lineno, line in enumerate(lines):
out.write(re.sub("function *\(", make_repl_func(lineno), line))
stderr.write("De-anonymized %d functions.\n" % x["anon_count"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment