diff options
| author | 2018-07-17 19:14:08 +0200 | |
|---|---|---|
| committer | 2018-07-17 19:14:08 +0200 | |
| commit | a88175ffc95792b88a8724f66db6dda2b8cc32ee (patch) | |
| tree | 65895bbc6cf1766f4ca01e1257619ab1993e71dc /src/test/java/cuchaz/enigma/TestSignature.java | |
| parent | Merge pull request #3 from thiakil/src-jar (diff) | |
| download | enigma-fork-a88175ffc95792b88a8724f66db6dda2b8cc32ee.tar.gz enigma-fork-a88175ffc95792b88a8724f66db6dda2b8cc32ee.tar.xz enigma-fork-a88175ffc95792b88a8724f66db6dda2b8cc32ee.zip | |
ASM Based Class Translator (#1)
* Initial port to ASM
* Package updates
* Annotation + inner class translation
* Fix inner class mapping
* More bytecode translation
* Signature refactoring
* Fix highlighting of mapped names
* Fix parameter name offset
* Fix anonymous class generation
* Fix issues with inner class signature transformation
* Fix bridged method detection
* Fix compile issues
* Resolve all failed tests
* Apply deobfuscated name to transformed classes
* Fix class signatures not being translated
* Fix frame array type translation
* Fix frame array type translation
* Fix array translation in method calls
* Fix method reference and bridge detection
* Fix handling of null deobf mappings
* Parameter translation in interfaces
* Fix enum parameter index offset
* Fix parsed local variable indexing
* Fix stackoverflow on rebuilding method names
* Ignore invalid decompiled variable indices
* basic source jar
* Output directly to file on source export
* Make decompile parallel
* fix incorrect super calls
* Use previous save state to delete old mapping files
* Fix old mappings not properly being removed
* Fix old mappings not properly being removed
* make isMethodProvider public
(cherry picked from commit ebad6a9)
* speed up Deobfuscator's getSources by using a single TranslatingTypeloader and caching the ClassLoaderTypeloader
* ignore .idea project folders
* move SynchronizedTypeLoader to a non-inner
* fix signature remap of inners for now
* index & resolve method/field references for usages view
* Allow reader/writer subclasses to provide the underlying file operations
* fix giving obf classes a name not removing them from the panel
* buffer the ParsedJar class entry inputstream, allow use with a jarinputstream
* make CachingClasspathTypeLoader public
* make CachingClasspathTypeLoader public
* support enum switches with obfuscated SwitchMaps
Diffstat (limited to 'src/test/java/cuchaz/enigma/TestSignature.java')
| -rw-r--r-- | src/test/java/cuchaz/enigma/TestSignature.java | 270 |
1 files changed, 0 insertions, 270 deletions
diff --git a/src/test/java/cuchaz/enigma/TestSignature.java b/src/test/java/cuchaz/enigma/TestSignature.java deleted file mode 100644 index 534b43a..0000000 --- a/src/test/java/cuchaz/enigma/TestSignature.java +++ /dev/null | |||
| @@ -1,270 +0,0 @@ | |||
| 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 | |||
| 12 | package cuchaz.enigma; | ||
| 13 | |||
| 14 | import cuchaz.enigma.mapping.ClassNameReplacer; | ||
| 15 | import cuchaz.enigma.mapping.Signature; | ||
| 16 | import cuchaz.enigma.mapping.Type; | ||
| 17 | import org.junit.Test; | ||
| 18 | |||
| 19 | import static org.hamcrest.MatcherAssert.assertThat; | ||
| 20 | import static org.hamcrest.Matchers.contains; | ||
| 21 | import static org.hamcrest.Matchers.empty; | ||
| 22 | import static org.hamcrest.Matchers.is; | ||
| 23 | import static org.hamcrest.Matchers.not; | ||
| 24 | |||
| 25 | public class TestSignature { | ||
| 26 | |||
| 27 | @Test | ||
| 28 | public void easiest() { | ||
| 29 | final Signature sig = new Signature("()V"); | ||
| 30 | assertThat(sig.getArgumentTypes(), is(empty())); | ||
| 31 | assertThat(sig.getReturnType(), is(new Type("V"))); | ||
| 32 | } | ||
| 33 | |||
| 34 | @Test | ||
| 35 | public void primitives() { | ||
| 36 | { | ||
| 37 | final Signature sig = new Signature("(I)V"); | ||
| 38 | assertThat(sig.getArgumentTypes(), contains( | ||
| 39 | new Type("I") | ||
| 40 | )); | ||
| 41 | assertThat(sig.getReturnType(), is(new Type("V"))); | ||
| 42 | } | ||
| 43 | { | ||
| 44 | final Signature sig = new Signature("(I)I"); | ||
| 45 | assertThat(sig.getArgumentTypes(), contains( | ||
| 46 | new Type("I") | ||
| 47 | )); | ||
| 48 | assertThat(sig.getReturnType(), is(new Type("I"))); | ||
| 49 | } | ||
| 50 | { | ||
| 51 | final Signature sig = new Signature("(IBCJ)Z"); | ||
| 52 | assertThat(sig.getArgumentTypes(), contains( | ||
| 53 | new Type("I"), | ||
| 54 | new Type("B"), | ||
| 55 | new Type("C"), | ||
| 56 | new Type("J") | ||
| 57 | )); | ||
| 58 | assertThat(sig.getReturnType(), is(new Type("Z"))); | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | @Test | ||
| 63 | public void classes() { | ||
| 64 | { | ||
| 65 | final Signature sig = new Signature("([LFoo;)V"); | ||
| 66 | assertThat(sig.getArgumentTypes().size(), is(1)); | ||
| 67 | assertThat(sig.getArgumentTypes().get(0), is(new Type("[LFoo;"))); | ||
| 68 | assertThat(sig.getReturnType(), is(new Type("V"))); | ||
| 69 | } | ||
| 70 | { | ||
| 71 | final Signature sig = new Signature("(LFoo;)LBar;"); | ||
| 72 | assertThat(sig.getArgumentTypes(), contains( | ||
| 73 | new Type("LFoo;") | ||
| 74 | )); | ||
| 75 | assertThat(sig.getReturnType(), is(new Type("LBar;"))); | ||
| 76 | } | ||
| 77 | { | ||
| 78 | final Signature sig = new Signature("(LFoo;LMoo;LZoo;)LBar;"); | ||
| 79 | assertThat(sig.getArgumentTypes(), contains( | ||
| 80 | new Type("LFoo;"), | ||
| 81 | new Type("LMoo;"), | ||
| 82 | new Type("LZoo;") | ||
| 83 | )); | ||
| 84 | assertThat(sig.getReturnType(), is(new Type("LBar;"))); | ||
| 85 | } | ||
| 86 | } | ||
| 87 | |||
| 88 | @Test | ||
| 89 | public void arrays() { | ||
| 90 | { | ||
| 91 | final Signature sig = new Signature("([I)V"); | ||
| 92 | assertThat(sig.getArgumentTypes(), contains( | ||
| 93 | new Type("[I") | ||
| 94 | )); | ||
| 95 | assertThat(sig.getReturnType(), is(new Type("V"))); | ||
| 96 | } | ||
| 97 | { | ||
| 98 | final Signature sig = new Signature("([I)[J"); | ||
| 99 | assertThat(sig.getArgumentTypes(), contains( | ||
| 100 | new Type("[I") | ||
| 101 | )); | ||
| 102 | assertThat(sig.getReturnType(), is(new Type("[J"))); | ||
| 103 | } | ||
| 104 | { | ||
| 105 | final Signature sig = new Signature("([I[Z[F)[D"); | ||
| 106 | assertThat(sig.getArgumentTypes(), contains( | ||
| 107 | new Type("[I"), | ||
| 108 | new Type("[Z"), | ||
| 109 | new Type("[F") | ||
| 110 | )); | ||
| 111 | assertThat(sig.getReturnType(), is(new Type("[D"))); | ||
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 115 | @Test | ||
| 116 | public void mixed() { | ||
| 117 | { | ||
| 118 | final Signature sig = new Signature("(I[JLFoo;)Z"); | ||
| 119 | assertThat(sig.getArgumentTypes(), contains( | ||
| 120 | new Type("I"), | ||
| 121 | new Type("[J"), | ||
| 122 | new Type("LFoo;") | ||
| 123 | )); | ||
| 124 | assertThat(sig.getReturnType(), is(new Type("Z"))); | ||
| 125 | } | ||
| 126 | { | ||
| 127 | final Signature sig = new Signature("(III)[LFoo;"); | ||
| 128 | assertThat(sig.getArgumentTypes(), contains( | ||
| 129 | new Type("I"), | ||
| 130 | new Type("I"), | ||
| 131 | new Type("I") | ||
| 132 | )); | ||
| 133 | assertThat(sig.getReturnType(), is(new Type("[LFoo;"))); | ||
| 134 | } | ||
| 135 | } | ||
| 136 | |||
| 137 | @Test | ||
| 138 | public void replaceClasses() { | ||
| 139 | { | ||
| 140 | final Signature oldSig = new Signature("()V"); | ||
| 141 | final Signature sig = new Signature(oldSig, new ClassNameReplacer() { | ||
| 142 | @Override | ||
| 143 | public String replace(String val) { | ||
| 144 | return null; | ||
| 145 | } | ||
| 146 | }); | ||
| 147 | assertThat(sig.getArgumentTypes(), is(empty())); | ||
| 148 | assertThat(sig.getReturnType(), is(new Type("V"))); | ||
| 149 | } | ||
| 150 | { | ||
| 151 | final Signature oldSig = new Signature("(IJLFoo;)V"); | ||
| 152 | final Signature sig = new Signature(oldSig, new ClassNameReplacer() { | ||
| 153 | @Override | ||
| 154 | public String replace(String val) { | ||
| 155 | return null; | ||
| 156 | } | ||
| 157 | }); | ||
| 158 | assertThat(sig.getArgumentTypes(), contains( | ||
| 159 | new Type("I"), | ||
| 160 | new Type("J"), | ||
| 161 | new Type("LFoo;") | ||
| 162 | )); | ||
| 163 | assertThat(sig.getReturnType(), is(new Type("V"))); | ||
| 164 | } | ||
| 165 | { | ||
| 166 | final Signature oldSig = new Signature("(LFoo;LBar;)LMoo;"); | ||
| 167 | final Signature sig = new Signature(oldSig, new ClassNameReplacer() { | ||
| 168 | @Override | ||
| 169 | public String replace(String val) { | ||
| 170 | if (val.equals("Foo")) { | ||
| 171 | return "Bar"; | ||
| 172 | } | ||
| 173 | return null; | ||
| 174 | } | ||
| 175 | }); | ||
| 176 | assertThat(sig.getArgumentTypes(), contains( | ||
| 177 | new Type("LBar;"), | ||
| 178 | new Type("LBar;") | ||
| 179 | )); | ||
| 180 | assertThat(sig.getReturnType(), is(new Type("LMoo;"))); | ||
| 181 | } | ||
| 182 | { | ||
| 183 | final Signature oldSig = new Signature("(LFoo;LBar;)LMoo;"); | ||
| 184 | final Signature sig = new Signature(oldSig, new ClassNameReplacer() { | ||
| 185 | @Override | ||
| 186 | public String replace(String val) { | ||
| 187 | if (val.equals("Moo")) { | ||
| 188 | return "Cow"; | ||
| 189 | } | ||
| 190 | return null; | ||
| 191 | } | ||
| 192 | }); | ||
| 193 | assertThat(sig.getArgumentTypes(), contains( | ||
| 194 | new Type("LFoo;"), | ||
| 195 | new Type("LBar;") | ||
| 196 | )); | ||
| 197 | assertThat(sig.getReturnType(), is(new Type("LCow;"))); | ||
| 198 | } | ||
| 199 | } | ||
| 200 | |||
| 201 | @Test | ||
| 202 | public void replaceArrayClasses() { | ||
| 203 | { | ||
| 204 | final Signature oldSig = new Signature("([LFoo;)[[[LBar;"); | ||
| 205 | final Signature sig = new Signature(oldSig, new ClassNameReplacer() { | ||
| 206 | @Override | ||
| 207 | public String replace(String val) { | ||
| 208 | if (val.equals("Foo")) { | ||
| 209 | return "Food"; | ||
| 210 | } else if (val.equals("Bar")) { | ||
| 211 | return "Beer"; | ||
| 212 | } | ||
| 213 | return null; | ||
| 214 | } | ||
| 215 | }); | ||
| 216 | assertThat(sig.getArgumentTypes(), contains( | ||
| 217 | new Type("[LFood;") | ||
| 218 | )); | ||
| 219 | assertThat(sig.getReturnType(), is(new Type("[[[LBeer;"))); | ||
| 220 | } | ||
| 221 | } | ||
| 222 | |||
| 223 | @Test | ||
| 224 | public void equals() { | ||
| 225 | |||
| 226 | // base | ||
| 227 | assertThat(new Signature("()V"), is(new Signature("()V"))); | ||
| 228 | |||
| 229 | // arguments | ||
| 230 | assertThat(new Signature("(I)V"), is(new Signature("(I)V"))); | ||
| 231 | assertThat(new Signature("(ZIZ)V"), is(new Signature("(ZIZ)V"))); | ||
| 232 | assertThat(new Signature("(LFoo;)V"), is(new Signature("(LFoo;)V"))); | ||
| 233 | assertThat(new Signature("(LFoo;LBar;)V"), is(new Signature("(LFoo;LBar;)V"))); | ||
| 234 | assertThat(new Signature("([I)V"), is(new Signature("([I)V"))); | ||
| 235 | assertThat(new Signature("([[D[[[J)V"), is(new Signature("([[D[[[J)V"))); | ||
| 236 | |||
| 237 | assertThat(new Signature("()V"), is(not(new Signature("(I)V")))); | ||
| 238 | assertThat(new Signature("(I)V"), is(not(new Signature("()V")))); | ||
| 239 | assertThat(new Signature("(IJ)V"), is(not(new Signature("(JI)V")))); | ||
| 240 | assertThat(new Signature("([[Z)V"), is(not(new Signature("([[LFoo;)V")))); | ||
| 241 | assertThat(new Signature("(LFoo;LBar;)V"), is(not(new Signature("(LFoo;LCow;)V")))); | ||
| 242 | assertThat(new Signature("([LFoo;LBar;)V"), is(not(new Signature("(LFoo;LCow;)V")))); | ||
| 243 | |||
| 244 | // return type | ||
| 245 | assertThat(new Signature("()I"), is(new Signature("()I"))); | ||
| 246 | assertThat(new Signature("()Z"), is(new Signature("()Z"))); | ||
| 247 | assertThat(new Signature("()[D"), is(new Signature("()[D"))); | ||
| 248 | assertThat(new Signature("()[[[Z"), is(new Signature("()[[[Z"))); | ||
| 249 | assertThat(new Signature("()LFoo;"), is(new Signature("()LFoo;"))); | ||
| 250 | assertThat(new Signature("()[LFoo;"), is(new Signature("()[LFoo;"))); | ||
| 251 | |||
| 252 | assertThat(new Signature("()I"), is(not(new Signature("()Z")))); | ||
| 253 | assertThat(new Signature("()Z"), is(not(new Signature("()I")))); | ||
| 254 | assertThat(new Signature("()[D"), is(not(new Signature("()[J")))); | ||
| 255 | assertThat(new Signature("()[[[Z"), is(not(new Signature("()[[Z")))); | ||
| 256 | assertThat(new Signature("()LFoo;"), is(not(new Signature("()LBar;")))); | ||
| 257 | assertThat(new Signature("()[LFoo;"), is(not(new Signature("()[LBar;")))); | ||
| 258 | } | ||
| 259 | |||
| 260 | @Test | ||
| 261 | public void testToString() { | ||
| 262 | assertThat(new Signature("()V").toString(), is("()V")); | ||
| 263 | assertThat(new Signature("(I)V").toString(), is("(I)V")); | ||
| 264 | assertThat(new Signature("(ZIZ)V").toString(), is("(ZIZ)V")); | ||
| 265 | assertThat(new Signature("(LFoo;)V").toString(), is("(LFoo;)V")); | ||
| 266 | assertThat(new Signature("(LFoo;LBar;)V").toString(), is("(LFoo;LBar;)V")); | ||
| 267 | assertThat(new Signature("([I)V").toString(), is("([I)V")); | ||
| 268 | assertThat(new Signature("([[D[[[J)V").toString(), is("([[D[[[J)V")); | ||
| 269 | } | ||
| 270 | } | ||