diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/command/MapSpecializedMethodsCommand.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/command/MapSpecializedMethodsCommand.java | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/main/java/cuchaz/enigma/command/MapSpecializedMethodsCommand.java b/src/main/java/cuchaz/enigma/command/MapSpecializedMethodsCommand.java new file mode 100644 index 0000000..7696f0f --- /dev/null +++ b/src/main/java/cuchaz/enigma/command/MapSpecializedMethodsCommand.java | |||
| @@ -0,0 +1,67 @@ | |||
| 1 | package cuchaz.enigma.command; | ||
| 2 | |||
| 3 | import cuchaz.enigma.ProgressListener; | ||
| 4 | import cuchaz.enigma.analysis.ClassCache; | ||
| 5 | import cuchaz.enigma.analysis.index.BridgeMethodIndex; | ||
| 6 | import cuchaz.enigma.analysis.index.JarIndex; | ||
| 7 | import cuchaz.enigma.throwables.MappingParseException; | ||
| 8 | import cuchaz.enigma.translation.MappingTranslator; | ||
| 9 | import cuchaz.enigma.translation.Translator; | ||
| 10 | import cuchaz.enigma.translation.mapping.*; | ||
| 11 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | ||
| 12 | import cuchaz.enigma.translation.mapping.tree.EntryTreeNode; | ||
| 13 | import cuchaz.enigma.translation.mapping.tree.HashEntryTree; | ||
| 14 | import cuchaz.enigma.translation.representation.entry.MethodEntry; | ||
| 15 | import cuchaz.enigma.utils.Utils; | ||
| 16 | |||
| 17 | import java.io.IOException; | ||
| 18 | import java.nio.file.Path; | ||
| 19 | import java.nio.file.Paths; | ||
| 20 | import java.util.Map; | ||
| 21 | |||
| 22 | public class MapSpecializedMethodsCommand extends Command { | ||
| 23 | public MapSpecializedMethodsCommand() { | ||
| 24 | super("map-specialized-methods"); | ||
| 25 | } | ||
| 26 | |||
| 27 | @Override | ||
| 28 | public String getUsage() { | ||
| 29 | return "<jar> <source-format> <source> <result-format> <result>"; | ||
| 30 | } | ||
| 31 | |||
| 32 | @Override | ||
| 33 | public boolean isValidArgument(int length) { | ||
| 34 | return length == 5; | ||
| 35 | } | ||
| 36 | |||
| 37 | @Override | ||
| 38 | public void run(String... args) throws IOException, MappingParseException { | ||
| 39 | MappingSaveParameters saveParameters = new MappingSaveParameters(MappingFileNameFormat.BY_DEOBF); | ||
| 40 | EntryTree<EntryMapping> source = MappingCommandsUtil.read(args[1], Paths.get(args[2]), saveParameters); | ||
| 41 | EntryTree<EntryMapping> result = new HashEntryTree<>(); | ||
| 42 | Path jar = Paths.get(args[0]); | ||
| 43 | ClassCache classCache = ClassCache.of(jar); | ||
| 44 | JarIndex jarIndex = classCache.index(ProgressListener.none()); | ||
| 45 | BridgeMethodIndex bridgeMethodIndex = jarIndex.getBridgeMethodIndex(); | ||
| 46 | Translator translator = new MappingTranslator(source, jarIndex.getEntryResolver()); | ||
| 47 | |||
| 48 | // Copy all non-specialized methods | ||
| 49 | for (EntryTreeNode<EntryMapping> node : source) { | ||
| 50 | if (!(node.getEntry() instanceof MethodEntry) || !bridgeMethodIndex.isSpecializedMethod((MethodEntry) node.getEntry())) { | ||
| 51 | result.insert(node.getEntry(), node.getValue()); | ||
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 | // Add correct mappings for specialized methods | ||
| 56 | for (Map.Entry<MethodEntry, MethodEntry> entry : bridgeMethodIndex.getBridgeToSpecialized().entrySet()) { | ||
| 57 | MethodEntry bridge = entry.getKey(); | ||
| 58 | MethodEntry specialized = entry.getValue(); | ||
| 59 | String name = translator.translate(bridge).getName(); | ||
| 60 | result.insert(specialized, new EntryMapping(name)); | ||
| 61 | } | ||
| 62 | |||
| 63 | Path output = Paths.get(args[4]); | ||
| 64 | Utils.delete(output); | ||
| 65 | MappingCommandsUtil.write(result, args[3], output, saveParameters); | ||
| 66 | } | ||
| 67 | } | ||