summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/Deobfuscator.java
diff options
context:
space:
mode:
authorGravatar jeff2014-09-28 15:20:54 -0400
committerGravatar jeff2014-09-28 15:20:54 -0400
commitcf3ffcee30083a71e68e3edb9ecbb936cc255992 (patch)
treef9a6415d7eef1e76640b07238d2d08daecedde17 /src/cuchaz/enigma/Deobfuscator.java
parentimplemented mark-as-deobfuscated and reset-to-obfuscated (diff)
downloadenigma-fork-cf3ffcee30083a71e68e3edb9ecbb936cc255992.tar.gz
enigma-fork-cf3ffcee30083a71e68e3edb9ecbb936cc255992.tar.xz
enigma-fork-cf3ffcee30083a71e68e3edb9ecbb936cc255992.zip
added proper support for renaming constructors
Diffstat (limited to 'src/cuchaz/enigma/Deobfuscator.java')
-rw-r--r--src/cuchaz/enigma/Deobfuscator.java70
1 files changed, 43 insertions, 27 deletions
diff --git a/src/cuchaz/enigma/Deobfuscator.java b/src/cuchaz/enigma/Deobfuscator.java
index 44845ba..ff83d21 100644
--- a/src/cuchaz/enigma/Deobfuscator.java
+++ b/src/cuchaz/enigma/Deobfuscator.java
@@ -40,6 +40,7 @@ import cuchaz.enigma.analysis.JarIndex;
40import cuchaz.enigma.analysis.SourceIndex; 40import cuchaz.enigma.analysis.SourceIndex;
41import cuchaz.enigma.analysis.SourceIndexVisitor; 41import cuchaz.enigma.analysis.SourceIndexVisitor;
42import cuchaz.enigma.analysis.Token; 42import cuchaz.enigma.analysis.Token;
43import cuchaz.enigma.analysis.TreeDumpVisitor;
43import cuchaz.enigma.mapping.ArgumentEntry; 44import cuchaz.enigma.mapping.ArgumentEntry;
44import cuchaz.enigma.mapping.BehaviorEntry; 45import cuchaz.enigma.mapping.BehaviorEntry;
45import cuchaz.enigma.mapping.BehaviorEntryFactory; 46import cuchaz.enigma.mapping.BehaviorEntryFactory;
@@ -337,7 +338,7 @@ public class Deobfuscator
337 338
338 // DEBUG 339 // DEBUG
339 //sourceTree.acceptVisitor( new TreeDumpVisitor( new File( "tree.txt" ) ), null ); 340 //sourceTree.acceptVisitor( new TreeDumpVisitor( new File( "tree.txt" ) ), null );
340 341
341 // resolve all the classes in the source references 342 // resolve all the classes in the source references
342 for( Token token : index.referenceTokens() ) 343 for( Token token : index.referenceTokens() )
343 { 344 {
@@ -454,7 +455,8 @@ public class Deobfuscator
454 } 455 }
455 return new EntryReference<E,C>( 456 return new EntryReference<E,C>(
456 obfuscateEntry( deobfReference.entry ), 457 obfuscateEntry( deobfReference.entry ),
457 obfuscateEntry( deobfReference.context ) 458 obfuscateEntry( deobfReference.context ),
459 deobfReference
458 ); 460 );
459 } 461 }
460 462
@@ -466,75 +468,83 @@ public class Deobfuscator
466 } 468 }
467 return new EntryReference<E,C>( 469 return new EntryReference<E,C>(
468 deobfuscateEntry( obfReference.entry ), 470 deobfuscateEntry( obfReference.entry ),
469 deobfuscateEntry( obfReference.context ) 471 deobfuscateEntry( obfReference.context ),
472 obfReference
470 ); 473 );
471 } 474 }
472 475
476 public boolean isObfuscatedIdentifier( Entry obfEntry )
477 {
478 return m_jarIndex.containsObfEntry( obfEntry );
479 }
480
481 public boolean isRenameable( EntryReference<Entry,Entry> obfReference )
482 {
483 return obfReference.isNamed() && isObfuscatedIdentifier( obfReference.getNameableEntry() );
484 }
485
486
473 // NOTE: these methods are a bit messy... oh well 487 // NOTE: these methods are a bit messy... oh well
474 488
475 public void rename( Entry obfEntry, String newName ) 489 public boolean hasDeobfuscatedName( Entry obfEntry )
476 { 490 {
491 Translator translator = getTranslator( TranslationDirection.Deobfuscating );
477 if( obfEntry instanceof ClassEntry ) 492 if( obfEntry instanceof ClassEntry )
478 { 493 {
479 m_renamer.setClassName( (ClassEntry)obfEntry, Descriptor.toJvmName( newName ) ); 494 return translator.translate( (ClassEntry)obfEntry ) != null;
480 } 495 }
481 else if( obfEntry instanceof FieldEntry ) 496 else if( obfEntry instanceof FieldEntry )
482 { 497 {
483 m_renamer.setFieldName( (FieldEntry)obfEntry, newName ); 498 return translator.translate( (FieldEntry)obfEntry ) != null;
484 } 499 }
485 else if( obfEntry instanceof MethodEntry ) 500 else if( obfEntry instanceof MethodEntry )
486 { 501 {
487 m_renamer.setMethodTreeName( (MethodEntry)obfEntry, newName ); 502 return translator.translate( (MethodEntry)obfEntry ) != null;
488 } 503 }
489 else if( obfEntry instanceof ConstructorEntry ) 504 else if( obfEntry instanceof ConstructorEntry )
490 { 505 {
491 m_renamer.setClassName( obfEntry.getClassEntry(), newName ); 506 // constructors have no names
507 return false;
492 } 508 }
493 else if( obfEntry instanceof ArgumentEntry ) 509 else if( obfEntry instanceof ArgumentEntry )
494 { 510 {
495 m_renamer.setArgumentName( (ArgumentEntry)obfEntry, newName ); 511 return translator.translate( (ArgumentEntry)obfEntry ) != null;
496 } 512 }
497 else 513 else
498 { 514 {
499 throw new Error( "Unknown entry type: " + obfEntry.getClass().getName() ); 515 throw new Error( "Unknown entry type: " + obfEntry.getClass().getName() );
500 } 516 }
501
502 // clear caches
503 m_translatorCache.clear();
504 } 517 }
505 518
506 public boolean hasMapping( Entry obfEntry ) 519 public void rename( Entry obfEntry, String newName )
507 { 520 {
508 Translator translator = getTranslator( TranslationDirection.Deobfuscating );
509 if( obfEntry instanceof ClassEntry ) 521 if( obfEntry instanceof ClassEntry )
510 { 522 {
511 return translator.translate( (ClassEntry)obfEntry ) != null; 523 m_renamer.setClassName( (ClassEntry)obfEntry, Descriptor.toJvmName( newName ) );
512 } 524 }
513 else if( obfEntry instanceof FieldEntry ) 525 else if( obfEntry instanceof FieldEntry )
514 { 526 {
515 return translator.translate( (FieldEntry)obfEntry ) != null; 527 m_renamer.setFieldName( (FieldEntry)obfEntry, newName );
516 } 528 }
517 else if( obfEntry instanceof MethodEntry ) 529 else if( obfEntry instanceof MethodEntry )
518 { 530 {
519 return translator.translate( (MethodEntry)obfEntry ) != null; 531 m_renamer.setMethodTreeName( (MethodEntry)obfEntry, newName );
520 } 532 }
521 else if( obfEntry instanceof ConstructorEntry ) 533 else if( obfEntry instanceof ConstructorEntry )
522 { 534 {
523 return translator.translate( obfEntry.getClassEntry() ) != null; 535 throw new IllegalArgumentException( "Cannot rename constructors" );
524 } 536 }
525 else if( obfEntry instanceof ArgumentEntry ) 537 else if( obfEntry instanceof ArgumentEntry )
526 { 538 {
527 return translator.translate( (ArgumentEntry)obfEntry ) != null; 539 m_renamer.setArgumentName( (ArgumentEntry)obfEntry, newName );
528 } 540 }
529 else 541 else
530 { 542 {
531 throw new Error( "Unknown entry type: " + obfEntry.getClass().getName() ); 543 throw new Error( "Unknown entry type: " + obfEntry.getClass().getName() );
532 } 544 }
533 } 545
534 546 // clear caches
535 public boolean isObfuscatedIdentifier( Entry obfEntry ) 547 m_translatorCache.clear();
536 {
537 return m_jarIndex.containsObfEntry( obfEntry );
538 } 548 }
539 549
540 public void removeMapping( Entry obfEntry ) 550 public void removeMapping( Entry obfEntry )
@@ -553,7 +563,7 @@ public class Deobfuscator
553 } 563 }
554 else if( obfEntry instanceof ConstructorEntry ) 564 else if( obfEntry instanceof ConstructorEntry )
555 { 565 {
556 m_renamer.removeClassMapping( obfEntry.getClassEntry() ); 566 throw new IllegalArgumentException( "Cannot rename constructors" );
557 } 567 }
558 else if( obfEntry instanceof ArgumentEntry ) 568 else if( obfEntry instanceof ArgumentEntry )
559 { 569 {
@@ -563,6 +573,9 @@ public class Deobfuscator
563 { 573 {
564 throw new Error( "Unknown entry type: " + obfEntry ); 574 throw new Error( "Unknown entry type: " + obfEntry );
565 } 575 }
576
577 // clear caches
578 m_translatorCache.clear();
566 } 579 }
567 580
568 public void markAsDeobfuscated( Entry obfEntry ) 581 public void markAsDeobfuscated( Entry obfEntry )
@@ -581,7 +594,7 @@ public class Deobfuscator
581 } 594 }
582 else if( obfEntry instanceof ConstructorEntry ) 595 else if( obfEntry instanceof ConstructorEntry )
583 { 596 {
584 m_renamer.markClassAsDeobfuscated( obfEntry.getClassEntry() ); 597 throw new IllegalArgumentException( "Cannot rename constructors" );
585 } 598 }
586 else if( obfEntry instanceof ArgumentEntry ) 599 else if( obfEntry instanceof ArgumentEntry )
587 { 600 {
@@ -591,5 +604,8 @@ public class Deobfuscator
591 { 604 {
592 throw new Error( "Unknown entry type: " + obfEntry ); 605 throw new Error( "Unknown entry type: " + obfEntry );
593 } 606 }
607
608 // clear caches
609 m_translatorCache.clear();
594 } 610 }
595} 611}