Created
July 20, 2011 03:15
-
-
Save int3/1094257 to your computer and use it in GitHub Desktop.
De-anonymize JS functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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