Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. import os
  2. import re
  3.  
  4. filename = "client"
  5. data = open(filename + ".txt").read() #Or server.txt
  6. lines = data.splitlines()
  7.  
  8. current_line, counter, deobf2obf = 0, 0, {}
  9.  
  10. out = ""
  11.  
  12.  
  13. def to_signature(ref):
  14. # Primitives
  15. if ref == "boolean":
  16. return "Z"
  17. if ref == "byte":
  18. return "B"
  19. if ref == "char":
  20. return "C"
  21. if ref == "short":
  22. return "S"
  23. if ref == "int":
  24. return "I"
  25. if ref == "long":
  26. return "J"
  27. if ref == "float":
  28. return "F"
  29. if ref == "double":
  30. return "D"
  31. if ref == "void":
  32. return "V"
  33.  
  34. # Arrays
  35. if ref.endswith("[]"):
  36. return "[" + to_signature(ref[0:-2])
  37.  
  38. # Mapped Classes
  39. if ref in deobf2obf:
  40. return "L" + deobf2obf[ref] + ";"
  41.  
  42. # Shouldn't happen, but this can occur if something went wrong during the building of the classname map
  43. if ref.startswith("net.minecraft"):
  44. raise Exception("Don't know how to handle " + ref)
  45.  
  46. # Classes
  47. return "L" + ref.replace(".", "/") + ";"
  48.  
  49.  
  50. def build_classname_map():
  51. for found in re.findall(r'(.+) -> (.+):', data):
  52. deobf2obf[found[0]] = found[1]
  53.  
  54.  
  55. def convert_class_name():
  56. global out, counter
  57. line = next_line()
  58. result = re.search(r'(.+) -> (.+):', line)
  59.  
  60. out += result.group(2).replace(".", "/") + " " + result.group(1).replace(".", "/") + "\n"
  61.  
  62. while current_line < len(lines) and lines[current_line].startswith(" "):
  63. line = next_line()
  64. method_search = re.search(r'\s*(?:\d+:\d+:)?(.+?)\s(.+)\((.*?)\) -> (.+)', line)
  65. if method_search is not None:
  66. if method_search.group(4) in ["<init>", "<clinit>"]:
  67. continue
  68. out += " " + method_search.group(4) + " ("
  69. if method_search.group(3) != "":
  70. for param in method_search.group(3).split(r","):
  71. out += to_signature(param)
  72. out += ")" + to_signature(method_search.group(1)) + " " + method_search.group(2) + "\n"
  73. continue
  74.  
  75. field_search = re.search(r'\s*(.+?)\s(.+?) -> (.+)', line)
  76. if field_search is not None:
  77. out += " " + field_search.group(3) + " " + field_search.group(2) + "\n"
  78. counter += 1
  79. print("Done " + str(round(counter / len(deobf2obf) * 10000) / 100) + "% : " + str(result.group(1)))
  80.  
  81.  
  82. def next_line():
  83. global current_line
  84. line = lines[current_line]
  85. current_line += 1
  86. if line.startswith("#") or line == "":
  87. return next_line()
  88. return line
  89.  
  90.  
  91. print("Setting up Classname map")
  92. build_classname_map()
  93. print("Classname map built! Started conversion.")
  94.  
  95. while current_line < len(lines):
  96. convert_class_name()
  97.  
  98. outFile = open(filename + ".tsrg", "w")
  99. outFile.write(out)
  100. outFile.close()
  101. print("Written to " + os.path.abspath(filename + ".tsrg"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement