Created
August 13, 2018 00:10
-
-
Save Earthcomputer/f60af5bf6000204c7be5b3600a1eff32 to your computer and use it in GitHub Desktop.
Reverses a TSRG file
This file contains hidden or 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
classMap = {} | |
def mapDescriptor(desc): | |
global classMap | |
newDesc = "(" | |
index = 1 | |
while index < len(desc): | |
if desc[index] == "L": | |
endIndex = index + 1 | |
while desc[endIndex] != ";": | |
endIndex += 1 | |
newDesc += "L" | |
oldCls = desc[(index+1):endIndex] | |
newCls = oldCls | |
if oldCls in classMap: | |
newCls = classMap[oldCls] | |
newDesc += newCls | |
newDesc += ";" | |
index = endIndex + 1 | |
else: | |
newDesc += desc[index] | |
index += 1 | |
return newDesc | |
with open("joined.tsrg") as f: | |
for line in f: | |
line = line.rstrip() | |
if not line.startswith("\t"): | |
parts = line.split(" ") | |
if len(parts) == 2: | |
classMap[parts[0]] = parts[1] | |
with open("joined.tsrg") as fin: | |
with open("reverse.tsrg", "w") as fout: | |
for line in fin: | |
line = line.rstrip() | |
if line.startswith("\t"): | |
line = line[1:] | |
parts = line.split(" ") | |
if len(parts) == 2: # Field | |
fout.write("\t" + parts[1] + " " + parts[0] + "\n") | |
elif len(parts) == 3: # Method | |
fout.write("\t" + parts[2] + " " + mapDescriptor(parts[1]) + " " + parts[0] + "\n") | |
else: | |
parts = line.split(" ") | |
if len(parts) == 2: # Class | |
fout.write(parts[1] + " " + parts[0] + "\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment