Package cuchaz.enigma.mapping

Examples of cuchaz.enigma.mapping.ClassEntry


 
  @Override
  public Void visitFieldDeclaration( FieldDeclaration node, SourceIndex index )
  {
    FieldDefinition def = node.getUserData( Keys.FIELD_DEFINITION );
    ClassEntry classEntry = new ClassEntry( def.getDeclaringType().getInternalName() );
    FieldEntry fieldEntry = new FieldEntry( classEntry, def.getName() );
    assert( node.getVariables().size() == 1 );
    VariableInitializer variable = node.getVariables().firstOrNullObject();
    index.addDeclaration( variable.getNameToken(), fieldEntry );
   
View Full Code Here


  @Override
  public Void visitEnumValueDeclaration( EnumValueDeclaration node, SourceIndex index )
  {
    // treat enum declarations as field declarations
    FieldDefinition def = node.getUserData( Keys.FIELD_DEFINITION );
    ClassEntry classEntry = new ClassEntry( def.getDeclaringType().getInternalName() );
    FieldEntry fieldEntry = new FieldEntry( classEntry, def.getName() );
    index.addDeclaration( node.getNameToken(), fieldEntry );
   
    return recurse( node, index );
  }
View Full Code Here

    // pass 1: look for any classes that got moved to inner classes
    Map<String,String> renames = Maps.newHashMap();
    for( ClassMapping classMapping : val.classes() )
    {
      // make sure we strip the packages off of obfuscated inner classes
      String innerClassName = new ClassEntry( classMapping.getObfName() ).getSimpleName();
      String outerClassName = m_jarIndex.getOuterClass( innerClassName );
      if( outerClassName != null )
      {
        // build the composite class name
        String newName = outerClassName + "$" + innerClassName;
       
        // add a rename
        renames.put( classMapping.getObfName(), newName );
       
        System.out.println( String.format( "Converted class mapping %s to %s", classMapping.getObfName(), newName ) );
      }
    }
    for( Map.Entry<String,String> entry : renames.entrySet() )
    {
      val.renameObfClass( entry.getKey(), entry.getValue() );
    }
   
    // pass 2: look for fields/methods that are actually declared in superclasses
    MappingsRenamer renamer = new MappingsRenamer( m_jarIndex, val );
    for( ClassMapping classMapping : val.classes() )
    {
      ClassEntry obfClassEntry = new ClassEntry( classMapping.getObfName() );
     
      // fields
      for( FieldMapping fieldMapping : Lists.newArrayList( classMapping.fields() ) )
      {
        FieldEntry fieldEntry = new FieldEntry( obfClassEntry, fieldMapping.getObfName() );
        ClassEntry resolvedObfClassEntry = m_jarIndex.resolveEntryClass( fieldEntry );
        if( resolvedObfClassEntry != null && !resolvedObfClassEntry.equals( fieldEntry.getClassEntry() ) )
        {
          boolean wasMoved = renamer.moveFieldToObfClass( classMapping, fieldMapping, resolvedObfClassEntry );
          if( wasMoved )
          {
            System.out.println( String.format( "Moved field %s to class %s", fieldEntry, resolvedObfClassEntry ) );
          }
          else
          {
            System.err.println( String.format( "WARNING: Would move field %s to class %s but the field was already there. Dropping instead.", fieldEntry, resolvedObfClassEntry ) );
          }
        }
      }
     
      // methods
      for( MethodMapping methodMapping : Lists.newArrayList( classMapping.methods() ) )
      {
        // skip constructors
        if( methodMapping.isConstructor() )
        {
          continue;
        }
       
        MethodEntry methodEntry = new MethodEntry( obfClassEntry, methodMapping.getObfName(), methodMapping.getObfSignature() );
        ClassEntry resolvedObfClassEntry = m_jarIndex.resolveEntryClass( methodEntry );
        if( resolvedObfClassEntry != null && !resolvedObfClassEntry.equals( methodEntry.getClassEntry() ) )
        {
          boolean wasMoved = renamer.moveMethodToObfClass( classMapping, methodMapping, resolvedObfClassEntry );
          if( wasMoved )
          {
            System.out.println( String.format( "Moved method %s to class %s", methodEntry, resolvedObfClassEntry ) );
View Full Code Here

  }
 
  private void checkClassMapping( List<ClassEntry> unknownClasses, ClassMapping classMapping )
  {
    // check the class
    ClassEntry classEntry = new ClassEntry( classMapping.getObfName() );
    String outerClassName = m_jarIndex.getOuterClass( classEntry.getSimpleName() );
    if( outerClassName != null )
    {
      classEntry = new ClassEntry( outerClassName + "$" + classMapping.getObfName() );
    }
    if( !m_jarIndex.getObfClassEntries().contains( classEntry ) )
    {
      unknownClasses.add( classEntry );
    }
View Full Code Here

      {
        continue;
      }
     
      // separate the classes
      ClassEntry deobfClassEntry = deobfuscateEntry( obfClassEntry );
      if( !deobfClassEntry.equals( obfClassEntry ) )
      {
        // if the class has a mapping, clearly it's deobfuscated
        deobfClasses.add( deobfClassEntry );
      }
      else if( !obfClassEntry.getPackageName().equals( Constants.NonePackage ) )
View Full Code Here

    {
      lookupClassName = classMapping.getDeobfName();
    }
   
    // is this class even in the jar?
    if( !m_jarIndex.containsObfClass( new ClassEntry( obfClassName ) ) )
    {
      return null;
    }
   
    // set the type loader
View Full Code Here

     
      // get the obfuscated entry
      Entry obfEntry = obfuscateEntry( deobfReference.entry );
     
      // try to resolve the class
      ClassEntry resolvedObfClassEntry = m_jarIndex.resolveEntryClass( obfEntry );
      if( resolvedObfClassEntry != null && !resolvedObfClassEntry.equals( obfEntry.getClassEntry() ) )
      {
        // change the class of the entry
        obfEntry = obfEntry.cloneToNewClass( resolvedObfClassEntry );
       
        // save the new deobfuscated reference
View Full Code Here

   
    // DEOBFUSCATE ALL THE THINGS!! @_@
    int i = 0;
    for( ClassEntry obfClassEntry : classEntries )
    {
      ClassEntry deobfClassEntry = deobfuscateEntry( new ClassEntry( obfClassEntry ) );
      if( progress != null )
      {
        progress.onProgress( i++, deobfClassEntry.toString() );
      }
     
      try
      {
        // get the source
        String source = getSource( getSourceTree( obfClassEntry.getName() ) );
       
        // write the file
        File file = new File( dirOut, deobfClassEntry.getName().replace( '.', '/' ) + ".java" );
        file.getParentFile().mkdirs();
        try( FileWriter out = new FileWriter( file ) )
        {
          out.write( source );
        }
      }
      catch( Throwable t )
      {
        throw new Error( "Unable to deobfuscate class " + deobfClassEntry.toString() + " (" + obfClassEntry.toString() + ")", t );
      }
    }
    if( progress != null )
    {
      progress.onProgress( i, "Done!" );
View Full Code Here

public class EntryFactory
{
  public static ClassEntry newClass( String name )
  {
    return new ClassEntry( name );
  }
View Full Code Here

    }
  }
 
  private byte[] loadType( String deobfClassName )
  {
    ClassEntry deobfClassEntry = new ClassEntry( deobfClassName );
    ClassEntry obfClassEntry = m_obfuscatingTranslator.translateEntry( deobfClassEntry );
   
    // is this an inner class referenced directly?
    String obfOuterClassName = m_jarIndex.getOuterClass( obfClassEntry.getSimpleName() );
    if( obfOuterClassName != null )
    {
      // this class doesn't really exist. Reference it by outer$inner instead
      System.err.println( String.format( "WARNING: class %s referenced by bare inner name instead of via outer class %s", deobfClassName, obfOuterClassName ) );
      return null;
    }
   
    /* DEBUG
    if( !Arrays.asList( "java", "org", "io" ).contains( deobfClassName.split( "/" )[0] ) )
    {
      System.out.println( String.format( "Looking for %s (%s)", deobfClassEntry.getName(), obfClassEntry.getName() ) );
    }
    */
   
    // get the jar entry
    String classFileName;
    if( obfClassEntry.isInnerClass() )
    {
      // use just the inner class name for inner classes
      classFileName = obfClassEntry.getInnerClassName();
    }
    else if( obfClassEntry.getPackageName().equals( Constants.NonePackage ) )
    {
      // use the outer class simple name for classes in the none package
      classFileName = obfClassEntry.getSimpleName();
    }
    else
    {
      // otherwise, just use the class name (ie for classes in packages)
      classFileName = obfClassEntry.getName();
    }
   
    JarEntry entry = m_jar.getJarEntry( classFileName + ".class" );
    if( entry == null )
    {
View Full Code Here

TOP

Related Classes of cuchaz.enigma.mapping.ClassEntry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.