Advertisement
Guest User

Proguard Reflection Mapper

a guest
Jul 22nd, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.86 KB | None | 0 0
  1. package com;
  2.  
  3. import com.google.gson.GsonBuilder;
  4. import com.google.gson.reflect.TypeToken;
  5.  
  6. import java.io.*;
  7. import java.util.HashMap;
  8. import java.util.Map;
  9.  
  10. /**
  11.  * @author Daniel
  12.  */
  13. public final class ReflectionMapper {
  14.  
  15.     private final File txt = new File("./Mapping.txt");
  16.  
  17.     //TODO: GZIP
  18.     private final File json = new File("./Mapping.json");
  19.  
  20.     //TODO: Sort entries by name
  21.     private final Map<String, ObfuscatedClass> map = new HashMap<String, ObfuscatedClass>();
  22.  
  23.     private ReflectionMapper() {
  24.         map.clear();
  25.         mapChildren();
  26.         write();
  27.     }
  28.  
  29.     public static void initialize() {
  30.         new ReflectionMapper();
  31.     }
  32.  
  33.     private void mapChildren() {
  34.         try {
  35.             BufferedReader reader = new BufferedReader(new FileReader(txt));
  36.             String line;
  37.  
  38.             String regular = "";
  39.             String obfuscated;
  40.  
  41.             while ((line = reader.readLine()) != null) {
  42.                 String[] split = line.split(" -> ");
  43.                 if (line.startsWith("    ")) {
  44.                     String original = split[0].trim().split(" ")[1];
  45.                     if (original.contains("(")) {
  46.                         original = original.substring(0, original.indexOf("("));
  47.                     }
  48.                     map.get(regular).put(original, split[1]);
  49.                 } else {
  50.                     regular = split[0];
  51.                     obfuscated = split[1].substring(0, split[1].length() - 1);
  52.                     if (!map.containsKey(regular)) {
  53.                         map.put(regular, new ObfuscatedClass(obfuscated));
  54.                     }
  55.                 }
  56.             }
  57.             reader.close();
  58.         } catch (Exception ex) {
  59.             ex.printStackTrace();
  60.         }
  61.     }
  62.  
  63.     private void write() {
  64.         try {
  65.             BufferedWriter writer = new BufferedWriter(new FileWriter(json));
  66.             writer.write(new GsonBuilder().setPrettyPrinting().create().toJson(map, new TypeToken<Map<String, ObfuscatedClass>>() {}.getType()));
  67.             writer.newLine();
  68.             writer.flush();
  69.             writer.close();
  70.         } catch (Exception ex) {
  71.             ex.printStackTrace();
  72.         }
  73.     }
  74.  
  75. }
  76.  
  77. package com;
  78.  
  79. import java.io.Serializable;
  80. import java.util.HashMap;
  81. import java.util.Map;
  82.  
  83. /**
  84.  * @author Daniel
  85.  */
  86. public class ObfuscatedClass implements Serializable {
  87.  
  88.     private final String name;
  89.  
  90.     //TODO: Sort entries by name
  91.     private final Map<String, String> map;
  92.  
  93.     public ObfuscatedClass(String name) {
  94.         this.name = name;
  95.         this.map = new HashMap<>();
  96.     }
  97.  
  98.     public String getName() {
  99.         return name;
  100.     }
  101.  
  102.     public String get(String value) {
  103.         return map.get(value);
  104.     }
  105.  
  106.     public void put(String original, String modified) {
  107.         map.put(original, modified);
  108.     }
  109.  
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement