diff options
| author | 2019-05-15 22:03:13 -0700 | |
|---|---|---|
| committer | 2019-05-16 07:03:13 +0200 | |
| commit | cb8823eb0b446d5c1b9b580e5578866e691771d8 (patch) | |
| tree | 1e8c1a5b981f3ad42c393f5d7cb75754f25f51ba /src/main/java/cuchaz/enigma/command/CheckMappingsCommand.java | |
| parent | checkmappings command (#137) (diff) | |
| download | enigma-fork-cb8823eb0b446d5c1b9b580e5578866e691771d8.tar.gz enigma-fork-cb8823eb0b446d5c1b9b580e5578866e691771d8.tar.xz enigma-fork-cb8823eb0b446d5c1b9b580e5578866e691771d8.zip | |
Feature/weave (#138)
* Add weave/stitch style command system to enigma
Also fixed divide by zero stupidity
Signed-off-by: liach <liach@users.noreply.github.com>
* Add tests for package access index and command
Signed-off-by: liach <liach@users.noreply.github.com>
* Minor tweaks
Signed-off-by: liach <liach@users.noreply.github.com>
Diffstat (limited to 'src/main/java/cuchaz/enigma/command/CheckMappingsCommand.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/command/CheckMappingsCommand.java | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/main/java/cuchaz/enigma/command/CheckMappingsCommand.java b/src/main/java/cuchaz/enigma/command/CheckMappingsCommand.java new file mode 100644 index 0000000..7ec7679 --- /dev/null +++ b/src/main/java/cuchaz/enigma/command/CheckMappingsCommand.java | |||
| @@ -0,0 +1,62 @@ | |||
| 1 | package cuchaz.enigma.command; | ||
| 2 | |||
| 3 | import cuchaz.enigma.Deobfuscator; | ||
| 4 | import cuchaz.enigma.ProgressListener; | ||
| 5 | import cuchaz.enigma.analysis.index.JarIndex; | ||
| 6 | import cuchaz.enigma.translation.mapping.EntryMapping; | ||
| 7 | import cuchaz.enigma.translation.mapping.serde.MappingFormat; | ||
| 8 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | ||
| 9 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | ||
| 10 | |||
| 11 | import java.io.File; | ||
| 12 | import java.nio.file.Path; | ||
| 13 | import java.util.Set; | ||
| 14 | import java.util.jar.JarFile; | ||
| 15 | import java.util.stream.Collectors; | ||
| 16 | |||
| 17 | public class CheckMappingsCommand extends Command { | ||
| 18 | |||
| 19 | public CheckMappingsCommand() { | ||
| 20 | super("checkmappings"); | ||
| 21 | } | ||
| 22 | |||
| 23 | @Override | ||
| 24 | public String getUsage() { | ||
| 25 | return "<in jar> <mappings file>"; | ||
| 26 | } | ||
| 27 | |||
| 28 | @Override | ||
| 29 | public boolean isValidArgument(int length) { | ||
| 30 | return length == 2; | ||
| 31 | } | ||
| 32 | |||
| 33 | @Override | ||
| 34 | public void run(String... args) throws Exception { | ||
| 35 | File fileJarIn = getReadableFile(getArg(args, 0, "in jar", true)); | ||
| 36 | Path fileMappings = getReadablePath(getArg(args, 1, "mappings file", true)); | ||
| 37 | |||
| 38 | System.out.println("Reading JAR..."); | ||
| 39 | Deobfuscator deobfuscator = new Deobfuscator(new JarFile(fileJarIn)); | ||
| 40 | System.out.println("Reading mappings..."); | ||
| 41 | |||
| 42 | MappingFormat format = chooseEnigmaFormat(fileMappings); | ||
| 43 | EntryTree<EntryMapping> mappings = format.read(fileMappings, ProgressListener.VOID); | ||
| 44 | deobfuscator.setMappings(mappings); | ||
| 45 | |||
| 46 | JarIndex idx = deobfuscator.getJarIndex(); | ||
| 47 | |||
| 48 | boolean error = false; | ||
| 49 | |||
| 50 | for (Set<ClassEntry> partition : idx.getPackageVisibilityIndex().getPartitions()) { | ||
| 51 | long packages = partition.stream().map(deobfuscator.getMapper()::deobfuscate).map(ClassEntry::getPackageName).distinct().count(); | ||
| 52 | if (packages > 1) { | ||
| 53 | error = true; | ||
| 54 | System.err.println("ERROR: Must be in one package:\n" + partition.stream().map(deobfuscator.getMapper()::deobfuscate).map(ClassEntry::toString).sorted().collect(Collectors.joining("\n"))); | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | if (error) { | ||
| 59 | throw new IllegalStateException("Errors in package visibility detected, see SysErr above"); | ||
| 60 | } | ||
| 61 | } | ||
| 62 | } | ||