diff options
| author | 2015-05-21 23:30:00 +0100 | |
|---|---|---|
| committer | 2015-05-21 23:30:00 +0100 | |
| commit | e3f452250e51b7271f3989c7dfd12e4422934942 (patch) | |
| tree | 5aa482f9a6e21eb318a3e23e7d8274d77c73faf6 /test/cuchaz/enigma/TokenChecker.java | |
| download | enigma-fork-e3f452250e51b7271f3989c7dfd12e4422934942.tar.gz enigma-fork-e3f452250e51b7271f3989c7dfd12e4422934942.tar.xz enigma-fork-e3f452250e51b7271f3989c7dfd12e4422934942.zip | |
Support Gradle alongside SSJB
This makes builds faster, simpler and better automated but still keeps
Cuchaz happy. :)
Diffstat (limited to 'test/cuchaz/enigma/TokenChecker.java')
| -rw-r--r-- | test/cuchaz/enigma/TokenChecker.java | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/test/cuchaz/enigma/TokenChecker.java b/test/cuchaz/enigma/TokenChecker.java new file mode 100644 index 0000000..7afb4cf --- /dev/null +++ b/test/cuchaz/enigma/TokenChecker.java | |||
| @@ -0,0 +1,65 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma; | ||
| 12 | |||
| 13 | import java.io.IOException; | ||
| 14 | import java.util.Collection; | ||
| 15 | import java.util.List; | ||
| 16 | import java.util.jar.JarFile; | ||
| 17 | |||
| 18 | import com.google.common.collect.Lists; | ||
| 19 | import com.strobel.decompiler.languages.java.ast.CompilationUnit; | ||
| 20 | |||
| 21 | import cuchaz.enigma.analysis.EntryReference; | ||
| 22 | import cuchaz.enigma.analysis.SourceIndex; | ||
| 23 | import cuchaz.enigma.analysis.Token; | ||
| 24 | import cuchaz.enigma.mapping.Entry; | ||
| 25 | |||
| 26 | public class TokenChecker { | ||
| 27 | |||
| 28 | private Deobfuscator m_deobfuscator; | ||
| 29 | |||
| 30 | protected TokenChecker(JarFile jarFile) | ||
| 31 | throws IOException { | ||
| 32 | m_deobfuscator = new Deobfuscator(jarFile); | ||
| 33 | } | ||
| 34 | |||
| 35 | protected String getDeclarationToken(Entry entry) { | ||
| 36 | // decompile the class | ||
| 37 | CompilationUnit tree = m_deobfuscator.getSourceTree(entry.getClassName()); | ||
| 38 | // DEBUG | ||
| 39 | // tree.acceptVisitor( new TreeDumpVisitor( new File( "tree." + entry.getClassName().replace( '/', '.' ) + ".txt" ) ), null ); | ||
| 40 | String source = m_deobfuscator.getSource(tree); | ||
| 41 | SourceIndex index = m_deobfuscator.getSourceIndex(tree, source); | ||
| 42 | |||
| 43 | // get the token value | ||
| 44 | Token token = index.getDeclarationToken(entry); | ||
| 45 | if (token == null) { | ||
| 46 | return null; | ||
| 47 | } | ||
| 48 | return source.substring(token.start, token.end); | ||
| 49 | } | ||
| 50 | |||
| 51 | @SuppressWarnings("unchecked") | ||
| 52 | protected Collection<String> getReferenceTokens(EntryReference<? extends Entry,? extends Entry> reference) { | ||
| 53 | // decompile the class | ||
| 54 | CompilationUnit tree = m_deobfuscator.getSourceTree(reference.context.getClassName()); | ||
| 55 | String source = m_deobfuscator.getSource(tree); | ||
| 56 | SourceIndex index = m_deobfuscator.getSourceIndex(tree, source); | ||
| 57 | |||
| 58 | // get the token values | ||
| 59 | List<String> values = Lists.newArrayList(); | ||
| 60 | for (Token token : index.getReferenceTokens((EntryReference<Entry,Entry>)reference)) { | ||
| 61 | values.add(source.substring(token.start, token.end)); | ||
| 62 | } | ||
| 63 | return values; | ||
| 64 | } | ||
| 65 | } | ||