1 21 package proguard.obfuscate; 22 23 import java.io.*; 24 25 26 32 public class MappingReader 33 { 34 private File mappingFile; 35 36 37 public MappingReader(File mappingFile) 38 { 39 this.mappingFile = mappingFile; 40 } 41 42 43 47 public void pump(MappingProcessor mappingProcessor) throws IOException 48 { 49 LineNumberReader reader = new LineNumberReader( 50 new BufferedReader( 51 new FileReader(mappingFile))); 52 try 53 { 54 String className = null; 55 56 while (true) 58 { 59 String line = reader.readLine(); 60 61 if (line == null) 62 { 63 break; 64 } 65 66 if (!line.startsWith(" ")) 69 { 70 className = processClassMapping(line, mappingProcessor); 73 } 74 else if (className != null) 75 { 76 processClassMemberMapping(className, line, mappingProcessor); 79 } 80 } 81 } 82 catch (IOException ex) 83 { 84 throw new IOException("Can't process mapping file (" + ex.getMessage() + ")"); 85 } 86 finally 87 { 88 try 89 { 90 reader.close(); 91 } 92 catch (IOException ex) 93 { 94 } 95 } 96 } 97 98 99 104 private String processClassMapping(String line, 105 MappingProcessor mappingProcessor) 106 { 107 110 line = line.trim(); 111 112 int arrowIndex = line.indexOf("->"); 113 if (arrowIndex < 0) 114 { 115 return null; 116 } 117 118 int colonIndex = line.indexOf(':', arrowIndex + 2); 119 if (colonIndex < 0) 120 { 121 return null; 122 } 123 124 String className = line.substring(0, arrowIndex).trim(); 126 String newClassName = line.substring(arrowIndex + 2, colonIndex).trim(); 127 128 boolean interested = mappingProcessor.processClassMapping(className, newClassName); 130 131 return interested ? className : null; 132 } 133 134 135 139 private void processClassMemberMapping(String className, 140 String line, 141 MappingProcessor mappingProcessor) 142 { 143 147 line = line.trim(); 148 149 int colonIndex1 = line.indexOf(':'); 150 int colonIndex2 = line.indexOf(':', colonIndex1 + 1); 151 152 int spaceIndex = line.indexOf(' ', colonIndex2 + 1); 153 if (spaceIndex < 0) 154 { 155 return; 156 } 157 158 int arrowIndex = line.indexOf("->", spaceIndex + 1); 159 if (arrowIndex < 1) 160 { 161 return; 162 } 163 164 int firstLineNumber = colonIndex1 < 0 ? 0 : 165 Integer.parseInt(line.substring(0, colonIndex1).trim()); 166 167 int lastLineNumber = colonIndex1 < 0 || 168 colonIndex2 < 0 ? 0 : 169 Integer.parseInt(line.substring(colonIndex1 + 1, colonIndex2).trim()); 170 171 String type = line.substring(colonIndex2 + 1, spaceIndex).trim(); 173 String name = line.substring(spaceIndex + 1, arrowIndex).trim(); 174 String newName = line.substring(arrowIndex + 2).trim(); 175 176 if (type.length() > 0 && name.length() > 0) 178 { 179 if (name.charAt(name.length() - 1) != ')') 180 { 181 mappingProcessor.processFieldMapping(className, type, name, newName); 182 } 183 else 184 { 185 mappingProcessor.processMethodMapping(className, firstLineNumber, lastLineNumber, type, name, newName); 186 } 187 } 188 } 189 } 190 | Popular Tags |