diff options
| author | 2015-03-18 23:38:11 -0400 | |
|---|---|---|
| committer | 2015-03-18 23:38:11 -0400 | |
| commit | bfb3fad7e65ce5ebfa349c0ad3c2da49d9b1f4cc (patch) | |
| tree | b70a80d3cc02cdba134808f45048ecde95a18a68 | |
| parent | Added tag v0.10 beta for changeset 4026a62e9193 (diff) | |
| download | enigma-fork-0.10_beta.tar.gz enigma-fork-0.10_beta.tar.xz enigma-fork-0.10_beta.zip | |
translate class references hidden inside type parametersv0.10_beta
| -rw-r--r-- | src/cuchaz/enigma/bytecode/ClassRenamer.java | 102 |
1 files changed, 71 insertions, 31 deletions
diff --git a/src/cuchaz/enigma/bytecode/ClassRenamer.java b/src/cuchaz/enigma/bytecode/ClassRenamer.java index 8d25e72..e708b9d 100644 --- a/src/cuchaz/enigma/bytecode/ClassRenamer.java +++ b/src/cuchaz/enigma/bytecode/ClassRenamer.java | |||
| @@ -39,6 +39,7 @@ import javassist.bytecode.SignatureAttribute.NestedClassType; | |||
| 39 | import javassist.bytecode.SignatureAttribute.ObjectType; | 39 | import javassist.bytecode.SignatureAttribute.ObjectType; |
| 40 | import javassist.bytecode.SignatureAttribute.Type; | 40 | import javassist.bytecode.SignatureAttribute.Type; |
| 41 | import javassist.bytecode.SignatureAttribute.TypeArgument; | 41 | import javassist.bytecode.SignatureAttribute.TypeArgument; |
| 42 | import javassist.bytecode.SignatureAttribute.TypeParameter; | ||
| 42 | import javassist.bytecode.SignatureAttribute.TypeVariable; | 43 | import javassist.bytecode.SignatureAttribute.TypeVariable; |
| 43 | import cuchaz.enigma.mapping.ClassEntry; | 44 | import cuchaz.enigma.mapping.ClassEntry; |
| 44 | import cuchaz.enigma.mapping.ClassNameReplacer; | 45 | import cuchaz.enigma.mapping.ClassNameReplacer; |
| @@ -164,9 +165,9 @@ public class ClassRenamer { | |||
| 164 | // rename the class name itself last | 165 | // rename the class name itself last |
| 165 | // NOTE: don't use the map here, because setName() calls the buggy SignatureAttribute.renameClass() | 166 | // NOTE: don't use the map here, because setName() calls the buggy SignatureAttribute.renameClass() |
| 166 | // we only want to replace exactly this class name | 167 | // we only want to replace exactly this class name |
| 167 | String newName = replacer.replace(Descriptor.toJvmName(c.getName())); | 168 | String newName = renameClassName(c.getName(), map); |
| 168 | if (newName != null) { | 169 | if (newName != null) { |
| 169 | c.setName(Descriptor.toJavaName(newName)); | 170 | c.setName(newName); |
| 170 | } | 171 | } |
| 171 | 172 | ||
| 172 | // replace simple names in the InnerClasses attribute too | 173 | // replace simple names in the InnerClasses attribute too |
| @@ -284,7 +285,11 @@ public class ClassRenamer { | |||
| 284 | 285 | ||
| 285 | private static String renameClassSignature(String signature, ReplacerClassMap map) { | 286 | private static String renameClassSignature(String signature, ReplacerClassMap map) { |
| 286 | try { | 287 | try { |
| 287 | return getSignature(renameType(SignatureAttribute.toClassSignature(signature), map)); | 288 | ClassSignature type = renameType(SignatureAttribute.toClassSignature(signature), map); |
| 289 | if (type != null) { | ||
| 290 | return type.encode(); | ||
| 291 | } | ||
| 292 | return null; | ||
| 288 | } catch (BadBytecode ex) { | 293 | } catch (BadBytecode ex) { |
| 289 | throw new Error("Can't parse field signature: " + signature); | 294 | throw new Error("Can't parse field signature: " + signature); |
| 290 | } | 295 | } |
| @@ -292,7 +297,11 @@ public class ClassRenamer { | |||
| 292 | 297 | ||
| 293 | private static String renameFieldSignature(String signature, ReplacerClassMap map) { | 298 | private static String renameFieldSignature(String signature, ReplacerClassMap map) { |
| 294 | try { | 299 | try { |
| 295 | return getSignature(renameType(SignatureAttribute.toFieldSignature(signature), map)); | 300 | ObjectType type = renameType(SignatureAttribute.toFieldSignature(signature), map); |
| 301 | if (type != null) { | ||
| 302 | return type.encode(); | ||
| 303 | } | ||
| 304 | return null; | ||
| 296 | } catch (BadBytecode ex) { | 305 | } catch (BadBytecode ex) { |
| 297 | throw new Error("Can't parse class signature: " + signature); | 306 | throw new Error("Can't parse class signature: " + signature); |
| 298 | } | 307 | } |
| @@ -300,7 +309,11 @@ public class ClassRenamer { | |||
| 300 | 309 | ||
| 301 | private static String renameMethodSignature(String signature, ReplacerClassMap map) { | 310 | private static String renameMethodSignature(String signature, ReplacerClassMap map) { |
| 302 | try { | 311 | try { |
| 303 | return getSignature(renameType(SignatureAttribute.toMethodSignature(signature), map)); | 312 | MethodSignature type = renameType(SignatureAttribute.toMethodSignature(signature), map); |
| 313 | if (type != null) { | ||
| 314 | return type.encode(); | ||
| 315 | } | ||
| 316 | return null; | ||
| 304 | } catch (BadBytecode ex) { | 317 | } catch (BadBytecode ex) { |
| 305 | throw new Error("Can't parse method signature: " + signature); | 318 | throw new Error("Can't parse method signature: " + signature); |
| 306 | } | 319 | } |
| @@ -308,9 +321,17 @@ public class ClassRenamer { | |||
| 308 | 321 | ||
| 309 | private static ClassSignature renameType(ClassSignature type, ReplacerClassMap map) { | 322 | private static ClassSignature renameType(ClassSignature type, ReplacerClassMap map) { |
| 310 | 323 | ||
| 311 | // NOTE: don't have to translate type parameters | 324 | TypeParameter[] typeParamTypes = type.getParameters(); |
| 325 | if (typeParamTypes != null) { | ||
| 326 | typeParamTypes = Arrays.copyOf(typeParamTypes, typeParamTypes.length); | ||
| 327 | for (int i=0; i<typeParamTypes.length; i++) { | ||
| 328 | TypeParameter newParamType = renameType(typeParamTypes[i], map); | ||
| 329 | if (newParamType != null) { | ||
| 330 | typeParamTypes[i] = newParamType; | ||
| 331 | } | ||
| 332 | } | ||
| 333 | } | ||
| 312 | 334 | ||
| 313 | // translate superclass | ||
| 314 | ClassType superclassType = type.getSuperClass(); | 335 | ClassType superclassType = type.getSuperClass(); |
| 315 | if (superclassType != ClassType.OBJECT) { | 336 | if (superclassType != ClassType.OBJECT) { |
| 316 | ClassType newSuperclassType = renameType(superclassType, map); | 337 | ClassType newSuperclassType = renameType(superclassType, map); |
| @@ -319,7 +340,6 @@ public class ClassRenamer { | |||
| 319 | } | 340 | } |
| 320 | } | 341 | } |
| 321 | 342 | ||
| 322 | // translate interfaces | ||
| 323 | ClassType[] interfaceTypes = type.getInterfaces(); | 343 | ClassType[] interfaceTypes = type.getInterfaces(); |
| 324 | if (interfaceTypes != null) { | 344 | if (interfaceTypes != null) { |
| 325 | interfaceTypes = Arrays.copyOf(interfaceTypes, interfaceTypes.length); | 345 | interfaceTypes = Arrays.copyOf(interfaceTypes, interfaceTypes.length); |
| @@ -331,12 +351,21 @@ public class ClassRenamer { | |||
| 331 | } | 351 | } |
| 332 | } | 352 | } |
| 333 | 353 | ||
| 334 | return new ClassSignature(type.getParameters(), superclassType, interfaceTypes); | 354 | return new ClassSignature(typeParamTypes, superclassType, interfaceTypes); |
| 335 | } | 355 | } |
| 336 | 356 | ||
| 337 | private static MethodSignature renameType(MethodSignature type, ReplacerClassMap map) { | 357 | private static MethodSignature renameType(MethodSignature type, ReplacerClassMap map) { |
| 338 | 358 | ||
| 339 | // don't need to rename type params here either | 359 | TypeParameter[] typeParamTypes = type.getTypeParameters(); |
| 360 | if (typeParamTypes != null) { | ||
| 361 | typeParamTypes = Arrays.copyOf(typeParamTypes, typeParamTypes.length); | ||
| 362 | for (int i=0; i<typeParamTypes.length; i++) { | ||
| 363 | TypeParameter newParamType = renameType(typeParamTypes[i], map); | ||
| 364 | if (newParamType != null) { | ||
| 365 | typeParamTypes[i] = newParamType; | ||
| 366 | } | ||
| 367 | } | ||
| 368 | } | ||
| 340 | 369 | ||
| 341 | Type[] paramTypes = type.getParameterTypes(); | 370 | Type[] paramTypes = type.getParameterTypes(); |
| 342 | if (paramTypes != null) { | 371 | if (paramTypes != null) { |
| @@ -368,7 +397,7 @@ public class ClassRenamer { | |||
| 368 | } | 397 | } |
| 369 | } | 398 | } |
| 370 | 399 | ||
| 371 | return new MethodSignature(type.getTypeParameters(), paramTypes, returnType, exceptionTypes); | 400 | return new MethodSignature(typeParamTypes, paramTypes, returnType, exceptionTypes); |
| 372 | } | 401 | } |
| 373 | 402 | ||
| 374 | private static Type renameType(Type type, ReplacerClassMap map) { | 403 | private static Type renameType(Type type, ReplacerClassMap map) { |
| @@ -437,10 +466,10 @@ public class ClassRenamer { | |||
| 437 | } else { | 466 | } else { |
| 438 | 467 | ||
| 439 | // translate the name | 468 | // translate the name |
| 440 | String name = Descriptor.toJvmName(type.getName()); | 469 | String name = type.getName(); |
| 441 | String newName = map.get(name); | 470 | String newName = renameClassName(name, map); |
| 442 | if (newName != null) { | 471 | if (newName != null) { |
| 443 | name = Descriptor.toJavaName(newName); | 472 | name = newName; |
| 444 | } | 473 | } |
| 445 | 474 | ||
| 446 | return new ClassType(name, args); | 475 | return new ClassType(name, args); |
| @@ -456,6 +485,14 @@ public class ClassRenamer { | |||
| 456 | } | 485 | } |
| 457 | } | 486 | } |
| 458 | 487 | ||
| 488 | private static String renameClassName(String name, ReplacerClassMap map) { | ||
| 489 | String newName = map.get(Descriptor.toJvmName(name)); | ||
| 490 | if (newName != null) { | ||
| 491 | return Descriptor.toJavaName(newName); | ||
| 492 | } | ||
| 493 | return null; | ||
| 494 | } | ||
| 495 | |||
| 459 | private static TypeArgument renameType(TypeArgument type, ReplacerClassMap map) { | 496 | private static TypeArgument renameType(TypeArgument type, ReplacerClassMap map) { |
| 460 | ObjectType subType = type.getType(); | 497 | ObjectType subType = type.getType(); |
| 461 | if (subType != null) { | 498 | if (subType != null) { |
| @@ -481,24 +518,27 @@ public class ClassRenamer { | |||
| 481 | return null; | 518 | return null; |
| 482 | } | 519 | } |
| 483 | 520 | ||
| 484 | private static String getSignature(ObjectType type) { | 521 | private static TypeParameter renameType(TypeParameter type, ReplacerClassMap map) { |
| 485 | if (type == null) { | 522 | |
| 486 | return null; | 523 | ObjectType superclassType = type.getClassBound(); |
| 487 | } | 524 | if (superclassType != null) { |
| 488 | return type.encode(); | 525 | ObjectType newSuperclassType = renameType(superclassType, map); |
| 489 | } | 526 | if (newSuperclassType != null) { |
| 490 | 527 | superclassType = newSuperclassType; | |
| 491 | private static String getSignature(ClassSignature type) { | 528 | } |
| 492 | if (type == null) { | ||
| 493 | return null; | ||
| 494 | } | 529 | } |
| 495 | return type.encode(); | 530 | |
| 496 | } | 531 | ObjectType[] interfaceTypes = type.getInterfaceBound(); |
| 497 | 532 | if (interfaceTypes != null) { | |
| 498 | private static String getSignature(MethodSignature type) { | 533 | interfaceTypes = Arrays.copyOf(interfaceTypes, interfaceTypes.length); |
| 499 | if (type == null) { | 534 | for (int i=0; i<interfaceTypes.length; i++) { |
| 500 | return null; | 535 | ObjectType newInterfaceType = renameType(interfaceTypes[i], map); |
| 536 | if (newInterfaceType != null) { | ||
| 537 | interfaceTypes[i] = newInterfaceType; | ||
| 538 | } | ||
| 539 | } | ||
| 501 | } | 540 | } |
| 502 | return type.encode(); | 541 | |
| 542 | return new TypeParameter(type.getName(), superclassType, interfaceTypes); | ||
| 503 | } | 543 | } |
| 504 | } | 544 | } |