jar-rename-1.6

16:36:59.616 INFO  jd.cli.Main - Decompiling jar-rename-1.6.jar
package p.rn;

import java.io.IOException;
import org.objectweb.asm.ClassReader;
import p.rn.asm.ScanBridgeAdapter;
import p.rn.util.FileWalker.StreamHandler;
import p.rn.util.FileWalker.StreamOpener;

class Scann$1
  implements FileWalker.StreamHandler
{
  Scann$1(ScanBridgeAdapter paramScanBridgeAdapter) {}
  
  public void handle(boolean isDir, String name, FileWalker.StreamOpener current, Object nameObject)
    throws IOException
  {
    if ((!isDir) && (name.endsWith(".class"))) {
      new ClassReader(current.get()).accept(val$slv, 0);
    }
  }
}

/* Location:
 * Qualified Name:     p.rn.Scann.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package p.rn;

public class ClassInfo$MemberInfo
{
  public int access;
  public String desc;
  public String name;
  public Object value;
}

/* Location:
 * Qualified Name:     p.rn.ClassInfo.MemberInfo
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package p.rn;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class ClassInfo
{
  public int access;
  public Map<String, List<MemberInfo>> members = new HashMap();
  public String name;
  public Set<String> parent = new HashSet();
  
  public boolean equals(Object o)
  {
    return name.equals(name);
  }
  
  public int hashCode()
  {
    return name.hashCode();
  }
  
  public String toString()
  {
    return name;
  }
  
  public static class MemberInfo
  {
    public int access;
    public String desc;
    public String name;
    public Object value;
  }
}

/* Location:
 * Qualified Name:     p.rn.ClassInfo
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package p.rn.name;

import java.io.IOException;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.commons.Remapper;
import org.objectweb.asm.commons.RemappingClassAdapter;
import p.rn.util.FileOut.OutHandler;
import p.rn.util.FileWalker.StreamHandler;
import p.rn.util.FileWalker.StreamOpener;

class Renamer$2
  implements FileWalker.StreamHandler
{
  Renamer$2(Renamer paramRenamer, Remapper paramRemapper, FileOut.OutHandler paramOutHandler) {}
  
  public void handle(boolean isDir, String name, FileWalker.StreamOpener current, Object nameObject)
    throws IOException
  {
    if (!isDir) {
      if (name.endsWith(".class"))
      {
        ClassWriter cw = new ClassWriter(0);
        new ClassReader(current.get()).accept(new RemappingClassAdapter(cw, val$xRemapper), 
          8);
        name = name.substring(0, name.length() - ".class".length());
        name = val$xRemapper.map(name);
        val$zo.write(false, name + ".class", cw.toByteArray(), null);
      }
      else
      {
        val$zo.write(false, name, current.get(), nameObject);
      }
    }
  }
}

/* Location:
 * Qualified Name:     p.rn.name.Renamer.2
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package p.rn.name;

import java.util.Map;
import org.objectweb.asm.commons.SimpleRemapper;

class Renamer$4
  extends SimpleRemapper
{
  Renamer$4(Renamer paramRenamer, Map $anonymous0)
  {
    super($anonymous0);
  }
  
  public String mapFieldName(String owner, String name, String desc)
  {
    String s = map(owner + '.' + name + "[" + desc + "]");
    if ((s == null) || (name.equals(s))) {
      s = map(owner + '.' + name);
    }
    return s == null ? name : s;
  }
  
  public String mapMethodName(String owner, String name, String desc)
  {
    String s = map(owner + '.' + name + desc);
    if ((s == null) || (name.equals(s))) {
      s = map(owner + '.' + name + desc.substring(0, desc.indexOf(')') + 1));
    }
    return s == null ? name : s;
  }
}

/* Location:
 * Qualified Name:     p.rn.name.Renamer.4
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package p.rn.name;

import java.util.HashMap;
import java.util.Map;
import org.apache.commons.collections.Transformer;

class Renamer$3
  implements Transformer
{
  Renamer$3(Renamer paramRenamer, Map paramMap1, Map paramMap2, Map paramMap3) {}
  
  private StringBuilder doClass(String str)
  {
    int index = str.lastIndexOf('$');
    if (index > 0)
    {
      String nName = (String)val$clz.get(str);
      if (nName == null) {
        nName = str.substring(index + 1);
      }
      return doClass(str.substring(0, index)).append("$").append(nName);
    }
    index = str.lastIndexOf('/');
    String nName = (String)val$clz.get(str);
    if (index > 0)
    {
      if (nName == null) {
        nName = str.substring(index + 1);
      }
      return doPkg(str.substring(0, index)).append('/').append(nName);
    }
    if (nName == null) {
      nName = str;
    }
    return new StringBuilder(nName);
  }
  
  private Map<String, String> pkgCache = new HashMap();
  
  private StringBuilder doPkg(String str)
  {
    String x = (String)pkgCache.get(str);
    if (x != null) {
      return new StringBuilder(x);
    }
    int index = str.lastIndexOf('/');
    String nName = (String)val$pkg.get(str);
    StringBuilder sb;
    StringBuilder sb;
    if (index > 0)
    {
      if (nName == null) {
        nName = str.substring(index + 1);
      }
      sb = doPkg(str.substring(0, index)).append('/').append(nName);
    }
    else
    {
      if (nName == null) {
        nName = str;
      }
      sb = new StringBuilder(nName);
    }
    pkgCache.put(str, sb.toString());
    return sb;
  }
  
  public Object transform(Object input)
  {
    String key = input.toString();
    int index = key.indexOf('.');
    if (index > 0)
    {
      String desc = key.substring(index + 1);
      String nName = (String)val$member.get(key);
      if (nName == null)
      {
        index = desc.indexOf('(');
        if (index > 0)
        {
          nName = desc.substring(0, index);
        }
        else
        {
          index = desc.indexOf('[');
          if (index > 0) {
            nName = desc.substring(0, index);
          } else {
            nName = desc;
          }
        }
      }
      return nName;
    }
    return doClass(key).toString();
  }
}

/* Location:
 * Qualified Name:     p.rn.name.Renamer.3
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package p.rn.name;

import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import org.apache.commons.collections.Transformer;
import org.apache.commons.collections.map.LazyMap;
import org.apache.commons.io.FileUtils;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.commons.Remapper;
import org.objectweb.asm.commons.RemappingClassAdapter;
import org.objectweb.asm.commons.SimpleRemapper;
import p.rn.ClassInfo;
import p.rn.ClassInfo.MemberInfo;
import p.rn.Scann;
import p.rn.util.AccUtils;
import p.rn.util.FileOut;
import p.rn.util.FileOut.OutHandler;
import p.rn.util.FileWalker;
import p.rn.util.FileWalker.StreamHandler;
import p.rn.util.FileWalker.StreamOpener;

public class Renamer
{
  private static final Remapper EmptyRemapper = new SimpleRemapper(Collections.emptyMap());
  private File from;
  private Remapper remapper;
  private File to;
  
  private static String doReplace(Collection<E> replace, String str)
  {
    for (E e : replace) {
      str = str.replaceAll(key, value);
    }
    return str;
  }
  
  private void check()
  {
    if ((from == null) || (to == null)) {
      throw new RuntimeException("from and to must be set");
    }
    if (remapper == null) {
      remapper = EmptyRemapper;
    }
  }
  
  private void doRename()
    throws IOException
  {
    check();
    
    final Map<String, ClassInfo> clzMap = Scann.scanLib(from);
    final Map<String, String> _enum = new HashMap();
    Iterator localIterator2;
    for (Iterator localIterator1 = clzMap.values().iterator(); localIterator1.hasNext(); localIterator2.hasNext())
    {
      ClassInfo classInfo = (ClassInfo)localIterator1.next();
      localIterator2 = members.values().iterator(); continue;List<ClassInfo.MemberInfo> fs = (List)localIterator2.next();
      for (ClassInfo.MemberInfo f : fs)
      {
        int access = access;
        if ((AccUtils.isEnum(access)) && 
          (AccUtils.isSynthetic(access)) && (AccUtils.isPrivate(access)) && (AccUtils.isStatic(access)) && (AccUtils.isFinal(access)) && 
          (desc.equals("[L" + name + ";")) && (!"ENUM$VALUES".equals(name))) {
          _enum.put(name + "." + name, "ENUM$VALUES");
        }
        if ((AccUtils.isSynthetic(access)) && (!AccUtils.isPrivate(access)) && (!AccUtils.isPublic(access)) && (!AccUtils.isProtected(access)) && 
          (AccUtils.isStatic(access)) && (desc.equals("Z")) && (!"$assertionsDisabled".equals(name))) {
          _enum.put(name + "." + name, "$assertionsDisabled");
        }
      }
    }
    final Remapper xRemapper = new Remapper()
    {
      private String findOwner(String clz, String name, String desc)
      {
        ClassInfo classInfo = (ClassInfo)clzMap.get(clz);
        int index = desc.indexOf(')');
        String key = index >= 0 ? name + desc.substring(0, index + 1) : name;
        if (classInfo != null)
        {
          List<ClassInfo.MemberInfo> members = (List)members.get(key);
          if (members != null) {
            for (ClassInfo.MemberInfo m : members) {
              if ((name.equals(name)) && (desc.equals(desc)) && (AccUtils.isPrivate(access))) {
                return clz;
              }
            }
          }
          for (String p : parent)
          {
            String oS = findOwnerNotPrivate(p, name, desc, key);
            if (oS != null) {
              return oS;
            }
          }
        }
        return null;
      }
      
      private String findOwnerNotPrivate(String clz, String name, String desc, String key)
      {
        ClassInfo classInfo = (ClassInfo)clzMap.get(clz);
        if (classInfo != null)
        {
          String oS;
          for (String p : parent)
          {
            oS = findOwnerNotPrivate(p, name, desc, key);
            if (oS != null) {
              return oS;
            }
          }
          List<ClassInfo.MemberInfo> members = (List)members.get(key);
          if (members != null) {
            for (ClassInfo.MemberInfo m : members) {
              if ((name.equals(name)) && (desc.equals(desc)) && (!AccUtils.isPrivate(access))) {
                return clz;
              }
            }
          }
        }
        return null;
      }
      
      public String map(String typeName)
      {
        if ((typeName.startsWith("java/")) || (typeName.startsWith("javax/"))) {
          return typeName;
        }
        if ((typeName.charAt(0) == 'L') && (typeName.charAt(typeName.length() - 1) == ';')) {
          return 'L' + map(typeName.substring(1, typeName.length() - 1)) + ';';
        }
        return remapper.map(typeName);
      }
      
      public String mapFieldName(String owner, String name, String desc)
      {
        if ((owner.startsWith("java/")) || (owner.startsWith("javax/"))) {
          return name;
        }
        String nName = (String)_enum.get(owner + "." + name);
        if (nName != null) {
          return nName;
        }
        String nOwner = findOwner(owner, name, desc);
        return remapper.mapFieldName(nOwner == null ? owner : nOwner, name, desc);
      }
      
      public String mapMethodName(String owner, String name, String desc)
      {
        if ((owner.startsWith("java/")) || (owner.startsWith("javax/")) || (name.startsWith("<"))) {
          return name;
        }
        String nOwner = findOwner(owner, name, desc);
        return remapper.mapMethodName(nOwner == null ? owner : nOwner, name, desc);
      }
    };
    final FileOut.OutHandler zo = FileOut.create(to);
    
    new FileWalker().withStreamHandler(new FileWalker.StreamHandler()
    {
      public void handle(boolean isDir, String name, FileWalker.StreamOpener current, Object nameObject)
        throws IOException
      {
        if (!isDir) {
          if (name.endsWith(".class"))
          {
            ClassWriter cw = new ClassWriter(0);
            new ClassReader(current.get()).accept(new RemappingClassAdapter(cw, xRemapper), 
              8);
            name = name.substring(0, name.length() - ".class".length());
            name = xRemapper.map(name);
            zo.write(false, name + ".class", cw.toByteArray(), null);
          }
          else
          {
            zo.write(false, name, current.get(), nameObject);
          }
        }
      }
    }).walk(from);
    zo.close();
  }
  
  public Renamer from(File file)
  {
    from = file;
    return this;
  }
  
  public void to(File to)
    throws IOException
  {
    this.to = to;
    doRename();
  }
  
  private static class E
    implements Comparable<E>
  {
    public String key;
    public String value;
    
    public int compareTo(E arg0)
    {
      int i = key.length() - key.length();
      return i == 0 ? key.compareTo(key) : i;
    }
  }
  
  public Renamer withConfig(File config)
    throws IOException
  {
    final Map<String, String> clz = new HashMap();
    final Map<String, String> pkg = new HashMap();
    final Map<String, String> member = new HashMap();
    Set<E> replace = new TreeSet();
    if (config != null) {
      for (String ln : FileUtils.readLines(config, "UTF-8")) {
        if ((!"".equals(ln)) && (!ln.startsWith("#")))
        {
          int index = ln.lastIndexOf('=');
          if (index > 0)
          {
            String key = ln.substring(2, index);
            String value = ln.substring(index + 1);
            switch (ln.charAt(0))
            {
            case 'F': 
            case 'M': 
            case 'f': 
            case 'm': 
              member.put(doReplace(replace, key), value);
              break;
            case 'C': 
            case 'c': 
              clz.put(doReplace(replace, key), value);
              break;
            case 'P': 
            case 'p': 
              pkg.put(doReplace(replace, key), value);
              break;
            case '@': 
              E e = new E(null);
              key = ('@' + key);
              value = doReplace(replace, value);
              replace.add(e);
            }
          }
        }
      }
    }
    withTransformer(new Transformer()
    {
      private StringBuilder doClass(String str)
      {
        int index = str.lastIndexOf('$');
        if (index > 0)
        {
          String nName = (String)clz.get(str);
          if (nName == null) {
            nName = str.substring(index + 1);
          }
          return doClass(str.substring(0, index)).append("$").append(nName);
        }
        index = str.lastIndexOf('/');
        String nName = (String)clz.get(str);
        if (index > 0)
        {
          if (nName == null) {
            nName = str.substring(index + 1);
          }
          return doPkg(str.substring(0, index)).append('/').append(nName);
        }
        if (nName == null) {
          nName = str;
        }
        return new StringBuilder(nName);
      }
      
      private Map<String, String> pkgCache = new HashMap();
      
      private StringBuilder doPkg(String str)
      {
        String x = (String)pkgCache.get(str);
        if (x != null) {
          return new StringBuilder(x);
        }
        int index = str.lastIndexOf('/');
        String nName = (String)pkg.get(str);
        StringBuilder sb;
        StringBuilder sb;
        if (index > 0)
        {
          if (nName == null) {
            nName = str.substring(index + 1);
          }
          sb = doPkg(str.substring(0, index)).append('/').append(nName);
        }
        else
        {
          if (nName == null) {
            nName = str;
          }
          sb = new StringBuilder(nName);
        }
        pkgCache.put(str, sb.toString());
        return sb;
      }
      
      public Object transform(Object input)
      {
        String key = input.toString();
        int index = key.indexOf('.');
        if (index > 0)
        {
          String desc = key.substring(index + 1);
          String nName = (String)member.get(key);
          if (nName == null)
          {
            index = desc.indexOf('(');
            if (index > 0)
            {
              nName = desc.substring(0, index);
            }
            else
            {
              index = desc.indexOf('[');
              if (index > 0) {
                nName = desc.substring(0, index);
              } else {
                nName = desc;
              }
            }
          }
          return nName;
        }
        return doClass(key).toString();
      }
    });
  }
  
  public Renamer withRemapper(Remapper remapper)
  {
    this.remapper = remapper;
    return this;
  }
  
  public Renamer withTransformer(Transformer tf)
    throws IOException
  {
    withRemapper(new SimpleRemapper(LazyMap.decorate(new HashMap(), tf))
    {
      public String mapFieldName(String owner, String name, String desc)
      {
        String s = map(owner + '.' + name + "[" + desc + "]");
        if ((s == null) || (name.equals(s))) {
          s = map(owner + '.' + name);
        }
        return s == null ? name : s;
      }
      
      public String mapMethodName(String owner, String name, String desc)
      {
        String s = map(owner + '.' + name + desc);
        if ((s == null) || (name.equals(s))) {
          s = map(owner + '.' + name + desc.substring(0, desc.indexOf(')') + 1));
        }
        return s == null ? name : s;
      }
    });
  }
}

/* Location:
 * Qualified Name:     p.rn.name.Renamer
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package p.rn.name;

import java.util.List;
import java.util.Map;
import org.objectweb.asm.commons.Remapper;
import p.rn.ClassInfo;
import p.rn.ClassInfo.MemberInfo;
import p.rn.util.AccUtils;

class Renamer$1
  extends Remapper
{
  Renamer$1(Renamer paramRenamer, Map paramMap1, Map paramMap2) {}
  
  private String findOwner(String clz, String name, String desc)
  {
    ClassInfo classInfo = (ClassInfo)val$clzMap.get(clz);
    int index = desc.indexOf(')');
    String key = index >= 0 ? name + desc.substring(0, index + 1) : name;
    if (classInfo != null)
    {
      List<ClassInfo.MemberInfo> members = (List)members.get(key);
      if (members != null) {
        for (ClassInfo.MemberInfo m : members) {
          if ((name.equals(name)) && (desc.equals(desc)) && (AccUtils.isPrivate(access))) {
            return clz;
          }
        }
      }
      for (String p : parent)
      {
        String oS = findOwnerNotPrivate(p, name, desc, key);
        if (oS != null) {
          return oS;
        }
      }
    }
    return null;
  }
  
  private String findOwnerNotPrivate(String clz, String name, String desc, String key)
  {
    ClassInfo classInfo = (ClassInfo)val$clzMap.get(clz);
    if (classInfo != null)
    {
      String oS;
      for (String p : parent)
      {
        oS = findOwnerNotPrivate(p, name, desc, key);
        if (oS != null) {
          return oS;
        }
      }
      List<ClassInfo.MemberInfo> members = (List)members.get(key);
      if (members != null) {
        for (ClassInfo.MemberInfo m : members) {
          if ((name.equals(name)) && (desc.equals(desc)) && (!AccUtils.isPrivate(access))) {
            return clz;
          }
        }
      }
    }
    return null;
  }
  
  public String map(String typeName)
  {
    if ((typeName.startsWith("java/")) || (typeName.startsWith("javax/"))) {
      return typeName;
    }
    if ((typeName.charAt(0) == 'L') && (typeName.charAt(typeName.length() - 1) == ';')) {
      return 'L' + map(typeName.substring(1, typeName.length() - 1)) + ';';
    }
    return Renamer.access$0(this$0).map(typeName);
  }
  
  public String mapFieldName(String owner, String name, String desc)
  {
    if ((owner.startsWith("java/")) || (owner.startsWith("javax/"))) {
      return name;
    }
    String nName = (String)val$_enum.get(owner + "." + name);
    if (nName != null) {
      return nName;
    }
    String nOwner = findOwner(owner, name, desc);
    return Renamer.access$0(this$0).mapFieldName(nOwner == null ? owner : nOwner, name, desc);
  }
  
  public String mapMethodName(String owner, String name, String desc)
  {
    if ((owner.startsWith("java/")) || (owner.startsWith("javax/")) || (name.startsWith("<"))) {
      return name;
    }
    String nOwner = findOwner(owner, name, desc);
    return Renamer.access$0(this$0).mapMethodName(nOwner == null ? owner : nOwner, name, desc);
  }
}

/* Location:
 * Qualified Name:     p.rn.name.Renamer.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package p.rn.name;

class Renamer$E
  implements Comparable<E>
{
  public String key;
  public String value;
  
  public int compareTo(E arg0)
  {
    int i = key.length() - key.length();
    return i == 0 ? key.compareTo(key) : i;
  }
}

/* Location:
 * Qualified Name:     p.rn.name.Renamer.E
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package p.rn.name;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import org.apache.commons.io.FileUtils;
import p.rn.ClassInfo;
import p.rn.ClassInfo.MemberInfo;
import p.rn.Scann;
import p.rn.util.AccUtils;

public class InitOut
{
  private static Set<String> keywords = new HashSet(Arrays.asList(new String[] { "abstract", "continue", "for", "new", 
    "switch", "assert", "default", "goto", "package", "synchronized", "boolean", "do", "if", "private", "this", 
    "break", "double", "implements", "protected", "throw", "byte", "else", "import", "public", "throws", 
    "case", "enum", "instanceof", "return", "transient", "catch", "extends", "int", "short", "try", "char", 
    "final", "interface", "static", "void", "class", "finally", "long", "strictfp", "volatile", "const", 
    "float", "native", "super", "while" }));
  private int clzIndex = 0;
  private Set<String> clzMap = new TreeSet();
  private Set<String> clzSet = new TreeSet();
  private File from;
  private int maxLength = 40;
  private Set<String> memberMap = new TreeSet();
  private int minLength = 2;
  private int pkgIndex = 0;
  private Set<String> pkgMap = new TreeSet();
  private Set<String> pkgSet = new TreeSet();
  
  private void doClass(String clz)
  {
    if (clzSet.contains(clz)) {
      return;
    }
    clzSet.add(clz);
    
    int index = clz.lastIndexOf('$');
    if (index > 0)
    {
      doClass(clz.substring(0, index));
      String cName = clz.substring(index + 1);
      try
      {
        Integer.parseInt(cName);
      }
      catch (Exception localException)
      {
        if (!shouldRename(cName)) {
          return;
        }
      }
      clzMap.add(String.format("c %s=CI%03d%s", new Object[] { clz, Integer.valueOf(clzIndex++), short4LongName(cName) }));
    }
    else
    {
      index = clz.lastIndexOf('/');
      if (index > 0)
      {
        doPkg(clz.substring(0, index));
        String cName = clz.substring(index + 1);
        if (shouldRename(cName)) {
          clzMap.add(String.format("c %s=C%03d%s", new Object[] { clz, Integer.valueOf(clzIndex++), short4LongName(cName) }));
        }
      }
      else if (shouldRename(clz))
      {
        clzMap.add(String.format("c %s=CI_%03d%s", new Object[] { clz, Integer.valueOf(clzIndex++), short4LongName(clz) }));
      }
    }
  }
  
  private String short4LongName(String name)
  {
    if (name.length() > maxLength) {
      return "x" + Integer.toHexString(name.hashCode());
    }
    return name;
  }
  
  private void doMethod(String owner, ClassInfo.MemberInfo member, int x)
  {
    if ((x > 0) || (shouldRename(name))) {
      if (desc.indexOf('(') >= 0)
      {
        StringBuilder sb = new StringBuilder();
        sb.append(AccUtils.isStatic(access) ? "M" : "m");
        if (AccUtils.isPrivate(access)) {
          sb.append("p");
        } else if (AccUtils.isPublic(access)) {
          sb.append("P");
        }
        if (x > 0) {
          sb.append(x);
        }
        sb.append(short4LongName(name));
        if (x > 0) {
          memberMap.add("m " + owner + "." + name + desc + "=" + sb.toString());
        } else {
          memberMap.add("m " + owner + "." + name + 
            desc.substring(0, desc.indexOf(')') + 1) + "=" + sb.toString());
        }
      }
      else
      {
        StringBuilder sb = new StringBuilder();
        sb.append(AccUtils.isStatic(access) ? "F" : "f");
        if (AccUtils.isPrivate(access)) {
          sb.append("p");
        } else if (AccUtils.isPublic(access)) {
          sb.append("P");
        }
        if (x > 0) {
          sb.append(x);
        }
        sb.append(short4LongName(name));
        if (x > 0) {
          memberMap.add("m " + owner + "." + name + "[" + desc + "]" + "=" + sb.toString());
        } else {
          memberMap.add("m " + owner + "." + name + "=" + sb.toString());
        }
      }
    }
  }
  
  private void doOut()
    throws IOException
  {
    Map<String, ClassInfo> map = Scann.scanLib(from);
    Iterator localIterator2;
    for (Iterator localIterator1 = map.values().iterator(); localIterator1.hasNext(); localIterator2.hasNext())
    {
      ClassInfo info = (ClassInfo)localIterator1.next();
      doClass(name);
      localIterator2 = members.values().iterator(); continue;List<ClassInfo.MemberInfo> ms = (List)localIterator2.next();
      if (ms.size() == 1)
      {
        for (ClassInfo.MemberInfo m : ms) {
          doMethod(name, m, 0);
        }
      }
      else
      {
        int i = 1;
        for (ClassInfo.MemberInfo m : ms) {
          doMethod(name, m, i++);
        }
      }
    }
  }
  
  private void doPkg(String pkg)
  {
    if (pkgSet.contains(pkg)) {
      return;
    }
    pkgSet.add(pkg);
    int index = pkg.lastIndexOf('/');
    if (index > 0)
    {
      doPkg(pkg.substring(0, index));
      String cName = pkg.substring(index + 1);
      if (shouldRename(cName)) {
        pkgMap.add(String.format("p %s=p%02d%s", new Object[] { pkg, Integer.valueOf(pkgIndex++), short4LongName(cName) }));
      }
    }
    else if (shouldRename(pkg))
    {
      pkgMap.add(String.format("p %s=p%02d%s", new Object[] { pkg, Integer.valueOf(pkgIndex++), short4LongName(pkg) }));
    }
  }
  
  public InitOut from(File from)
  {
    this.from = from;
    return this;
  }
  
  public InitOut maxLength(int m)
  {
    maxLength = m;
    return this;
  }
  
  public InitOut minLength(int m)
  {
    minLength = m;
    return this;
  }
  
  private boolean shouldRename(String s)
  {
    return (s.length() > maxLength) || (s.length() < minLength) || (keywords.contains(s));
  }
  
  public void to(File config)
    throws IOException
  {
    doOut();
    List<String> list = new ArrayList();
    list.addAll(pkgMap);
    list.addAll(clzMap);
    list.addAll(memberMap);
    FileUtils.writeLines(config, "UTF-8", list);
  }
}

/* Location:
 * Qualified Name:     p.rn.name.InitOut
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package p.rn.name;

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

public class RenamerMain
{
  public static void main(String[] args)
    throws IOException
  {
    File srcJar = new File("org.jar");
    File configDir = new File(".");
    File distDir = new File(".");
    Set<String> config = new TreeSet();
    int j = (localObject1 = configDir.listFiles()).length;
    for (int i = 0; i < j; i++)
    {
      File f = localObject1[i];
      if ((f.isFile()) && (f.getName().endsWith(".txt"))) {
        config.add(f.getName().substring(0, f.getName().length() - ".txt".length()));
      }
    }
    config.remove("init");
    config.remove("org");
    File lastJar = srcJar;
    Object s = new ArrayList(config.size() + 1);
    ((List)s).add("init");
    ((List)s).addAll(config);
    for (Object localObject1 = ((List)s).iterator(); ((Iterator)localObject1).hasNext();)
    {
      String f = (String)((Iterator)localObject1).next();
      File thisJarFile = new File(distDir, f + ".jar");
      new Renamer().from(lastJar).withConfig(new File(configDir, f + ".txt")).to(thisJarFile);
      System.out.println(thisJarFile.getCanonicalPath());
      lastJar = thisJarFile;
    }
  }
}

/* Location:
 * Qualified Name:     p.rn.name.RenamerMain
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package p.rn;

import java.io.File;
import java.io.IOException;
import java.util.Map;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.commons.EmptyVisitor;
import p.rn.asm.ScanBridgeAdapter;
import p.rn.asm.ScanLibVisitor;
import p.rn.util.FileWalker;
import p.rn.util.FileWalker.StreamHandler;
import p.rn.util.FileWalker.StreamOpener;

public class Scann
{
  public static Map<String, ClassInfo.MemberInfo> scanBridge(File file)
    throws IOException
  {
    ScanBridgeAdapter slv = new ScanBridgeAdapter(new EmptyVisitor());
    
    new FileWalker().withStreamHandler(new FileWalker.StreamHandler()
    {
      public void handle(boolean isDir, String name, FileWalker.StreamOpener current, Object nameObject)
        throws IOException
      {
        if ((!isDir) && (name.endsWith(".class"))) {
          new ClassReader(current.get()).accept(Scann.this, 0);
        }
      }
    }).walk(file);
    return slv.getBridge();
  }
  
  public static Map<String, ClassInfo> scanLib(File file)
    throws IOException
  {
    ScanLibVisitor slv = new ScanLibVisitor();
    new FileWalker().withStreamHandler(new FileWalker.StreamHandler()
    {
      public void handle(boolean isDir, String name, FileWalker.StreamOpener current, Object nameObject)
        throws IOException
      {
        if ((!isDir) && (name.endsWith(".class"))) {
          new ClassReader(current.get()).accept(Scann.this, 1);
        }
      }
    }).walk(file);
    return slv.getClassMap();
  }
}

/* Location:
 * Qualified Name:     p.rn.Scann
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package p.rn.owner;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.jar.Attributes;
import java.util.jar.Attributes.Name;
import java.util.jar.Manifest;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.objectweb.asm.ClassAdapter;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodAdapter;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.commons.RemappingClassAdapter;
import org.objectweb.asm.commons.SimpleRemapper;
import p.rn.util.FileOut.OutHandler;
import p.rn.util.FileWalker.StreamHandler;
import p.rn.util.FileWalker.StreamOpener;

public class ReOwner
{
  public byte[] reOwnerOne(String className, InputStream is)
    throws IOException
  {
    return reOwnerOne(className, IOUtils.toByteArray(is));
  }
  
  public byte[] reOwnerOne(String className, byte[] data)
    throws IOException
  {
    if (ignores.contains(className)) {
      return data;
    }
    ClassWriter cw = new ClassWriter(0);
    new ClassReader(data).accept(new RemappingClassAdapter(new ClassAdapter(cw)
    
      new SimpleRemapper
      {
        public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions)
        {
          MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
          if (mv == null) {
            return null;
          }
          new MethodAdapter(mv)
          {
            public void visitMethodInsn(int opcode, String owner, String name, String desc)
            {
              String nOwner = (String)mz.get(owner + "." + name);
              String nName = name;
              if (nOwner == null) {
                nOwner = (String)mz.get(owner + "." + name + desc.substring(0, desc.lastIndexOf(')') + 1));
              }
              if (nOwner == null)
              {
                nOwner = owner;
              }
              else
              {
                int index = nOwner.indexOf('.');
                if (index > 0)
                {
                  nName = nOwner.substring(index + 1);
                  nOwner = nOwner.substring(0, index);
                }
              }
              super.visitMethodInsn(opcode, nOwner, nName, desc);
            }
          };
        }
      }, new SimpleRemapper(clz)), 8);
      return cw.toByteArray();
    }
    
    private Map<String, String> mz = new HashMap();
    private Set<String> ignores = new HashSet();
    private Map<String, String> clz = new HashMap();
    
    /* Error */
    public void reOwner(File from, File to)
      throws IOException
    {
      // Byte code:
      //   0: aload_2
      //   1: invokestatic 97	p/rn/util/FileOut:create	(Ljava/io/File;)Lp/rn/util/FileOut$OutHandler;
      //   4: astore_3
      //   5: new 103	p/rn/util/FileWalker
      //   8: dup
      //   9: invokespecial 105	p/rn/util/FileWalker:<init>	()V
      //   12: new 106	p/rn/owner/ReOwner$2
      //   15: dup
      //   16: aload_0
      //   17: aload_3
      //   18: invokespecial 108	p/rn/owner/ReOwner$2:<init>	(Lp/rn/owner/ReOwner;Lp/rn/util/FileOut$OutHandler;)V
      //   21: invokevirtual 111	p/rn/util/FileWalker:withStreamHandler	(Lp/rn/util/FileWalker$StreamHandler;)Lp/rn/util/FileWalker;
      //   24: aload_1
      //   25: invokevirtual 115	p/rn/util/FileWalker:walk	(Ljava/io/File;)V
      //   28: goto +12 -> 40
      //   31: astore 4
      //   33: aload_3
      //   34: invokestatic 119	org/apache/commons/io/IOUtils:closeQuietly	(Ljava/io/Closeable;)V
      //   37: aload 4
      //   39: athrow
      //   40: aload_3
      //   41: invokestatic 119	org/apache/commons/io/IOUtils:closeQuietly	(Ljava/io/Closeable;)V
      //   44: return
      // Line number table:
      //   Java source line #82	-> byte code offset #0
      //   Java source line #84	-> byte code offset #5
      //   Java source line #118	-> byte code offset #24
      //   Java source line #119	-> byte code offset #31
      //   Java source line #120	-> byte code offset #33
      //   Java source line #121	-> byte code offset #37
      //   Java source line #120	-> byte code offset #40
      //   Java source line #122	-> byte code offset #44
      // Local variable table:
      //   start	length	slot	name	signature
      //   0	45	0	this	ReOwner
      //   0	45	1	from	File
      //   0	45	2	to	File
      //   4	37	3	zo	FileOut.OutHandler
      //   31	7	4	localObject	Object
      // Exception table:
      //   from	to	target	type
      //   5	31	31	finally
    }
    
    public ReOwner withConfig(File config)
      throws IOException
    {
      if (config != null)
      {
        InputStream is = null;
        try
        {
          is = FileUtils.openInputStream(config);
          return withConfig(is);
        }
        finally
        {
          IOUtils.closeQuietly(is);
        }
      }
      return this;
    }
    
    public ReOwner withConfig(InputStream is)
      throws IOException
    {
      if (is != null) {
        for (String ln : IOUtils.readLines(is, "UTF-8")) {
          if ((!"".equals(ln)) && (!ln.startsWith("#"))) {
            switch (ln.charAt(0))
            {
            case 'I': 
            case 'i': 
              ignores.add(ln.substring(2));
              break;
            case 'C': 
            case 'c': 
              int index = ln.lastIndexOf('=');
              if (index > 0)
              {
                String key = ln.substring(2, index);
                String value = ln.substring(index + 1);
                clz.put(key, value);
                ignores.add(value);
              }
              break;
            case 'R': 
            case 'r': 
              int index = ln.lastIndexOf('=');
              if (index > 0)
              {
                String key = ln.substring(2, index);
                String value = ln.substring(index + 1);
                index = key.lastIndexOf(')');
                if (index > 0) {
                  mz.put(key.substring(0, index + 1), value);
                } else {
                  mz.put(key, value);
                }
                index = value.indexOf('.');
                if (index > 0) {
                  ignores.add(value.substring(0, index - 1));
                } else {
                  ignores.add(value);
                }
              }
              break;
            }
          }
        }
      }
      return this;
    }
  }

/* Location:
 * Qualified Name:     p.rn.owner.ReOwner
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package p.rn.owner;

import java.util.Map;
import org.objectweb.asm.ClassAdapter;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodAdapter;
import org.objectweb.asm.MethodVisitor;

class ReOwner$1
  extends ClassAdapter
{
  ReOwner$1(ReOwner paramReOwner, ClassVisitor $anonymous0)
  {
    super($anonymous0);
  }
  
  public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions)
  {
    MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
    if (mv == null) {
      return null;
    }
    new MethodAdapter(mv)
    {
      public void visitMethodInsn(int opcode, String owner, String name, String desc)
      {
        String nOwner = (String)ReOwner.access$0(this$0).get(owner + "." + name);
        String nName = name;
        if (nOwner == null) {
          nOwner = (String)ReOwner.access$0(this$0).get(owner + "." + name + desc.substring(0, desc.lastIndexOf(')') + 1));
        }
        if (nOwner == null)
        {
          nOwner = owner;
        }
        else
        {
          int index = nOwner.indexOf('.');
          if (index > 0)
          {
            nName = nOwner.substring(index + 1);
            nOwner = nOwner.substring(0, index);
          }
        }
        super.visitMethodInsn(opcode, nOwner, nName, desc);
      }
    };
  }
}

/* Location:
 * Qualified Name:     p.rn.owner.ReOwner.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package p.rn.owner;

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.io.FileUtils;

public class WebApp
{
  public static void main(String[] args)
    throws IOException
  {
    if (args.length < 2)
    {
      System.out.println("webapp pathToWebApp config [ignoreJarConfig]");
      return;
    }
    File webApp = new File(args[0]);
    File config = new File(args[1]);
    File jarIgnore = args.length > 2 ? new File(args[2]) : null;
    
    File clz = new File(webApp, "WEB-INF/classes");
    File tmpClz = new File(webApp, "WEB-INF/tmp-classes");
    ReOwner ro = new ReOwner().withConfig(config);
    if (tmpClz.exists()) {
      FileUtils.deleteDirectory(tmpClz);
    }
    FileUtils.copyDirectory(clz, tmpClz);
    System.out.println("ReOwner from [" + tmpClz + "] to [" + clz + "]");
    ro.reOwner(tmpClz, clz);
    FileUtils.deleteDirectory(tmpClz);
    
    File lib = new File(webApp, "WEB-INF/lib");
    File tmpLib = new File(webApp, "WEB-INF/Nlib");
    
    Set<String> ignores = new HashSet();
1 2

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd