Created
March 18, 2016 20:12
-
-
Save riking/cd875948f21ae508271b to your computer and use it in GitHub Desktop.
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 | |
import re | |
import fileinput | |
import base64 | |
import ast | |
rgx = re.compile("\"(\w+)\":") | |
compact = re.compile("^([A-Za-z0-9_=-]*)\\.[A-Za-z0-9_-]*=?=?.[A-Za-z0-9_-]*=?=?$") | |
def processjson(line): | |
found = set() | |
foundany = False | |
for m in re.finditer(rgx, line): | |
foundany = True | |
s = m.group(1) | |
if s.lower() != s: | |
print("uppercase %s: %s" % (s, line)) | |
if s in found: | |
print("duplicate %s: %s" % (s, line)) | |
found.add(s) | |
return foundany | |
for line in fileinput.input(): | |
line = ast.literal_eval(line) | |
foundany = False | |
m = compact.match(line) | |
if m: | |
b64 = m.group(1) | |
if len(b64) % 4 != 0: | |
b64 = b64 + "=" | |
if len(b64) % 4 != 0: | |
b64 = b64 + "=" | |
#print(line) | |
#print(b64) | |
hdr = base64.b64decode(b64) | |
#print(hdr) | |
foundany = processjson(hdr) | |
if not foundany: | |
print("no matches: %s" % hdr) | |
else: | |
foundany = processjson(line) | |
if not foundany: | |
print("no matches: %s" % line) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment