summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/command
diff options
context:
space:
mode:
authorGravatar Runemoro2019-11-22 15:40:50 -0500
committerGravatar modmuss502019-11-22 20:40:50 +0000
commit37cafdb5a837cbe29e4cc9a34737e24f496bc94f (patch)
tree413ec17d5593984465ffc6005f3fa3c096d7225f /src/main/java/cuchaz/enigma/command
parentTweak runemoro's stats generator to be compatible with multiple services (#178) (diff)
downloadenigma-fork-37cafdb5a837cbe29e4cc9a34737e24f496bc94f.tar.gz
enigma-fork-37cafdb5a837cbe29e4cc9a34737e24f496bc94f.tar.xz
enigma-fork-37cafdb5a837cbe29e4cc9a34737e24f496bc94f.zip
Correctly decompile bridges, and add command to add bridges to mappings (#180)
Diffstat (limited to 'src/main/java/cuchaz/enigma/command')
-rw-r--r--src/main/java/cuchaz/enigma/command/MapSpecializedMethodsCommand.java67
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 @@
1package cuchaz.enigma.command;
2
3import cuchaz.enigma.ProgressListener;
4import cuchaz.enigma.analysis.ClassCache;
5import cuchaz.enigma.analysis.index.BridgeMethodIndex;
6import cuchaz.enigma.analysis.index.JarIndex;
7import cuchaz.enigma.throwables.MappingParseException;
8import cuchaz.enigma.translation.MappingTranslator;
9import cuchaz.enigma.translation.Translator;
10import cuchaz.enigma.translation.mapping.*;
11import cuchaz.enigma.translation.mapping.tree.EntryTree;
12import cuchaz.enigma.translation.mapping.tree.EntryTreeNode;
13import cuchaz.enigma.translation.mapping.tree.HashEntryTree;
14import cuchaz.enigma.translation.representation.entry.MethodEntry;
15import cuchaz.enigma.utils.Utils;
16
17import java.io.IOException;
18import java.nio.file.Path;
19import java.nio.file.Paths;
20import java.util.Map;
21
22public 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}