p-rename-1.4

16:50:53.317 INFO  jd.cli.Main - Decompiling p-rename-1.4.jar
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.asm;

import java.util.Map;
import org.objectweb.asm.MethodAdapter;
import org.objectweb.asm.MethodVisitor;
import p.rn.ClassInfo.MemberInfo;

class ScanBridgeAdapter$1
  extends MethodAdapter
{
  ScanBridgeAdapter$1(ScanBridgeAdapter paramScanBridgeAdapter, MethodVisitor x0, ClassInfo.MemberInfo paramMemberInfo)
  {
    super(x0);
  }
  
  public void visitMethodInsn(int opcode, String owner, String name, String desc)
  {
    super.visitMethodInsn(opcode, owner, name, desc);
    if (!name.equals(val$member.name)) {
      ScanBridgeAdapter.access$000(this$0).put(owner + '.' + name + desc.substring(0, desc.lastIndexOf(')') + 1), val$member);
    }
  }
}

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

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.commons.EmptyVisitor;
import p.rn.ClassInfo;
import p.rn.ClassInfo.MemberInfo;

public class ScanLibVisitor
  extends EmptyVisitor
{
  private ClassInfo clz;
  private Map<String, ClassInfo> map = new HashMap();
  
  public Map<String, ClassInfo> getClassMap()
  {
    return Collections.unmodifiableMap(map);
  }
  
  public void visit(int version, int access, String name, String signature, String superName, String[] interfaces)
  {
    clz = new ClassInfo();
    clz.access = access;
    clz.name = name;
    if (superName != null) {
      clz.parent.add(superName);
    }
    if (interfaces != null) {
      clz.parent.addAll(Arrays.asList(interfaces));
    }
    map.put(name, clz);
  }
  
  public FieldVisitor visitField(int access, String name, String desc, String signature, Object value)
  {
    ClassInfo.MemberInfo f = new ClassInfo.MemberInfo();
    List<ClassInfo.MemberInfo> fs = (List)clz.members.get(name);
    if (fs == null)
    {
      fs = new ArrayList();
      clz.members.put(name, fs);
    }
    name = name;
    desc = desc;
    access = access;
    value = value;
    fs.add(f);
    return null;
  }
  
  public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions)
  {
    if (("<init>".equals(name)) || ("<cinit>".equals(name))) {
      return null;
    }
    ClassInfo.MemberInfo m = new ClassInfo.MemberInfo();
    int index = desc.lastIndexOf(')');
    String key = name + desc.substring(0, index + 1);
    List<ClassInfo.MemberInfo> ms = (List)clz.members.get(key);
    if (ms == null)
    {
      ms = new ArrayList();
      clz.members.put(key, ms);
    }
    name = name;
    desc = desc;
    access = access;
    ms.add(m);
    return null;
  }
}

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

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.objectweb.asm.ClassAdapter;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodAdapter;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.commons.EmptyVisitor;
import p.rn.ClassInfo.MemberInfo;
import p.rn.util.AccUtils;

public class ScanBridgeAdapter
  extends ClassAdapter
{
  private Map<String, ClassInfo.MemberInfo> bridge = new HashMap();
  
  public ScanBridgeAdapter(ClassVisitor cv)
  {
    super(cv);
  }
  
  public Map<String, ClassInfo.MemberInfo> getBridge()
  {
    return Collections.unmodifiableMap(bridge);
  }
  
  public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions)
  {
    MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
    if ((AccUtils.isBridge(access)) && (AccUtils.isSynthetic(access)))
    {
      if (mv == null) {
        mv = new EmptyVisitor();
      }
      final ClassInfo.MemberInfo member = new ClassInfo.MemberInfo();
      access = access;
      desc = desc;
      name = name;
      mv = new MethodAdapter(mv)
      {
        public void visitMethodInsn(int opcode, String owner, String name, String desc)
        {
          super.visitMethodInsn(opcode, owner, name, desc);
          if (!name.equals(membername)) {
            bridge.put(owner + '.' + name + desc.substring(0, desc.lastIndexOf(')') + 1), member);
          }
        }
      };
    }
    return mv;
  }
}

/* Location:
 * Qualified Name:     p.rn.asm.ScanBridgeAdapter
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
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;

final 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.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 ex)
      {
        if (shouldRename(cName)) {
          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);
    for (Iterator i$ = map.values().iterator(); i$.hasNext();)
    {
      info = (ClassInfo)i$.next();
      doClass(name);
      for (List<ClassInfo.MemberInfo> ms : members.values()) {
        if (ms.size() == 1)
        {
          for (ClassInfo.MemberInfo m : ms) {
            doMethod(name, m, 0);
          }
        }
        else
        {
          i = 1;
          for (ClassInfo.MemberInfo m : ms) {
            doMethod(name, m, i++);
          }
        }
      }
    }
    ClassInfo info;
    int 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.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), 0);
        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.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();
    for (Iterator i$ = clzMap.values().iterator(); i$.hasNext();)
    {
      classInfo = (ClassInfo)i$.next();
      for (List<ClassInfo.MemberInfo> fs : members.values()) {
        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");
          }
        }
      }
    }
    ClassInfo classInfo;
    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)
        {
          for (String p : parent)
          {
            String 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), 0);
            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.Map;
import org.objectweb.asm.commons.SimpleRemapper;

class Renamer$4
  extends SimpleRemapper
{
  Renamer$4(Renamer paramRenamer, Map x0)
  {
    super(x0);
  }
  
  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.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
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();
    for (File f : configDir.listFiles()) {
      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;
    List<String> s = new ArrayList(config.size() + 1);
    s.add("init");
    s.addAll(config);
    for (String f : s)
    {
      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.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.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.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)
    {
      for (String p : parent)
      {
        String 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$000(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$000(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$000(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;

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.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(val$slv, 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(val$slv, 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.util;

public class AccUtils
{
  public static boolean isBridge(int acc)
  {
    return (acc & 0x40) != 0;
  }
  
  public static boolean isEnum(int acc)
  {
    return (acc & 0x4000) != 0;
  }
  
  public static boolean isFinal(int acc)
  {
    return (acc & 0x10) != 0;
  }
  
  public static boolean isPrivate(int acc)
  {
    return (acc & 0x2) != 0;
  }
  
  public static boolean isProtected(int acc)
  {
    return (acc & 0x4) != 0;
  }
  
  public static boolean isPublic(int acc)
  {
    return (acc & 0x1) != 0;
  }
  
  public static boolean isStatic(int acc)
  {
    return (acc & 0x8) != 0;
  }
  
  public static boolean isSynthetic(int acc)
  {
    return (acc & 0x1000) != 0;
  }
}

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

import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashSet;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.apache.commons.io.IOUtils;

class FileOut$ZipOutHandler
  implements FileOut.OutHandler
{
  private Set<String> dirs = new HashSet();
  private ZipOutputStream zos;
  
  public FileOut$ZipOutHandler(OutputStream os)
  {
    zos = new ZipOutputStream(os);
  }
  
  private void check(String dir)
  {
    if (dirs.contains(dir)) {
      return;
    }
    dirs.add(dir);
    int i = dir.lastIndexOf('/');
    if (i > 0) {
      check(dir.substring(0, i));
    }
  }
  
  public void close()
  {
    IOUtils.closeQuietly(zos);
  }
  
  public void write(boolean isDir, String name, byte[] data, Object nameObject)
    throws IOException
  {
    zos.putNextEntry(buildEntry(name, nameObject));
    if (!isDir) {
      zos.write(data);
    }
    zos.closeEntry();
  }
  
  public void write(boolean isDir, String name, InputStream is, Object nameObject)
    throws IOException
  {
    zos.putNextEntry(buildEntry(name, nameObject));
    if (!isDir) {
      IOUtils.copy(is, zos);
    }
    zos.closeEntry();
  }
  
  private ZipEntry buildEntry(String name, Object nameObject)
  {
    int i = name.lastIndexOf('/');
    if (i > 0) {
      check(name.substring(0, i));
    }
    if ((nameObject instanceof ZipEntry))
    {
      ZipEntry ze = (ZipEntry)nameObject;
      if (name.equals(ze.getName()))
      {
        ZipEntry nZe = new ZipEntry(name);
        nZe.setComment(ze.getComment());
        nZe.setTime(ze.getTime());
        return nZe;
      }
    }
    return new ZipEntry(name);
  }
  
  public OutputStream openOutput(String name, Object nameObject)
    throws IOException
  {
    zos.putNextEntry(buildEntry(name, nameObject));
    new FilterOutputStream(zos)
    {
      public void close()
        throws IOException
      {
        flush();
        zos.closeEntry();
      }
    };
  }
}

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

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;

class FileOut$FileOutHandler
  implements FileOut.OutHandler
{
  File dir;
  
  public void close()
    throws IOException
  {}
  
  public FileOut$FileOutHandler(File dir)
  {
    this.dir = dir;
  }
  
  public void write(boolean isDir, String name, InputStream is, Object nameObject)
    throws IOException
  {
    if (!isDir)
    {
      FileOutputStream fos = null;
      try
      {
        fos = FileUtils.openOutputStream(new File(dir, name));
        IOUtils.copy(is, fos);
      }
      finally
      {
        IOUtils.closeQuietly(fos);
      }
    }
  }
  
  public void write(boolean isDir, String name, byte[] data, Object nameObject)
    throws IOException
  {
    if (!isDir) {
      FileUtils.writeByteArrayToFile(new File(dir, name), data);
    }
  }
  
  public OutputStream openOutput(String name, Object nameObject)
    throws IOException
  {
    return FileUtils.openOutputStream(new File(dir, name));
  }
}

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

import java.io.Closeable;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashSet;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;

public class FileOut
{
  public static OutHandler create(File dirORzip)
    throws IOException
  {
    return create(dirORzip, dirORzip.exists() ? dirORzip.isFile() : true);
  }
  
  public static OutHandler create(File dirORzip, boolean isZip)
    throws IOException
  {
    if (isZip) {
      return new ZipOutHandler(FileUtils.openOutputStream(dirORzip));
    }
    return new FileOutHandler(dirORzip);
  }
  
  public static abstract interface OutHandler
    extends Closeable
  {
    public abstract void write(boolean paramBoolean, String paramString, InputStream paramInputStream, Object para
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