dex-tools-0.0.9.11

16:35:21.568 INFO  jd.cli.Main - Decompiling dex-tools-0.0.9.11.jar
package com.googlecode.dex2jar.tools;

import java.io.File;
import java.io.PrintWriter;
import java.lang.annotation.Annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;

public abstract class BaseCmd
{
  @Opt(opt="h", longOpt="help", hasArg=false, description="Print this help message")
  private boolean printHelp = false;
  private final String cmdLineSyntax;
  protected CommandLine commandLine;
  private final String header;
  private Map<String, Field> map = new HashMap();
  protected final Options options = new Options();
  protected String[] remainingArgs;
  
  public BaseCmd(String cmdLineSyntax, String header)
  {
    this.cmdLineSyntax = cmdLineSyntax;
    this.header = header;
  }
  
  protected Object convert(String value, Class<?> type)
  {
    if (type.equals(String.class)) {
      return value;
    }
    if ((type.equals(Integer.TYPE)) || (type.equals(Integer.class))) {
      return Integer.valueOf(Integer.parseInt(value));
    }
    if ((type.equals(Long.TYPE)) || (type.equals(Long.class))) {
      return Long.valueOf(Long.parseLong(value));
    }
    if ((type.equals(Float.TYPE)) || (type.equals(Float.class))) {
      return Float.valueOf(Float.parseFloat(value));
    }
    if ((type.equals(Double.TYPE)) || (type.equals(Double.class))) {
      return Double.valueOf(Double.parseDouble(value));
    }
    if ((type.equals(Boolean.TYPE)) || (type.equals(Boolean.class))) {
      return Boolean.valueOf(Boolean.parseBoolean(value));
    }
    if (type.equals(File.class)) {
      return new File(value);
    }
    throw new RuntimeException("can't convert [" + value + "] to type " + type);
  }
  
  protected abstract void doCommandLine()
    throws Exception;
  
  public void doMain(String... args)
  {
    initOptions();
    CommandLineParser parser = new PosixParser();
    try
    {
      commandLine = parser.parse(options, args);
    }
    catch (ParseException ex)
    {
      usage();
      return;
    }
    remainingArgs = commandLine.getArgs();
    try
    {
      for (Option option : commandLine.getOptions())
      {
        String opt = option.getOpt();
        Field f = (Field)map.get(opt);
        if (f != null)
        {
          Object value;
          Object value;
          if (!option.hasArg()) {
            value = Boolean.valueOf(true);
          } else {
            value = convert(commandLine.getOptionValue(opt), f.getType());
          }
          f.set(this, value);
        }
      }
      if (printHelp) {
        usage();
      } else {
        doCommandLine();
      }
    }
    catch (Exception e)
    {
      e.printStackTrace(System.err);
    }
  }
  
  protected String getVersionString()
  {
    return "dex2jar dex-tool-" + BaseCmd.class.getPackage().getImplementationVersion() + ", Apache-2.0";
  }
  
  protected void initOptionFromClass(Class<?> clz)
  {
    if (clz == null) {
      return;
    }
    initOptionFromClass(clz.getSuperclass());
    
    Field[] fs = clz.getDeclaredFields();
    for (Field f : fs)
    {
      Opt opt = (Opt)f.getAnnotation(Opt.class);
      if (opt != null)
      {
        f.setAccessible(true);
        if (!opt.hasArg())
        {
          Class<?> type = f.getType();
          if (!type.equals(Boolean.TYPE)) {
            throw new RuntimeException("the type of " + f + " must be boolean, as it is declared as no args");
          }
          boolean b;
          try
          {
            b = ((Boolean)f.get(this)).booleanValue();
          }
          catch (Exception e)
          {
            throw new RuntimeException(e);
          }
          if (b) {
            throw new RuntimeException("the value of " + f + " must be false, as it is declared as no args");
          }
        }
        Option option = new Option(opt.opt(), opt.hasArg(), opt.description());
        option.setRequired(opt.required());
        if (!"".equals(opt.longOpt())) {
          option.setLongOpt(opt.longOpt());
        }
        if (!"".equals(opt.argName())) {
          option.setArgName(opt.argName());
        }
        options.addOption(option);
        map.put(opt.opt(), f);
      }
    }
  }
  
  protected void initOptions()
  {
    initOptionFromClass(getClass());
  }
  
  protected void usage()
  {
    HelpFormatter formatter = new HelpFormatter()
    {
      public void printHelp(PrintWriter pw, int width, String cmdLineSyntax, String header, Options options, int leftPad, int descPad, String footer, boolean autoUsage)
      {
        String xHeader = BaseCmd.this.header;
        if ((xHeader != null) && (!xHeader.equals(""))) {
          printWrapped(pw, width, xHeader);
        }
        super.printHelp(pw, width, cmdLineSyntax, header, options, leftPad, descPad, footer, autoUsage);
      }
    };
    formatter.printHelp(cmdLineSyntax, "options:", options, "version: " + getVersionString());
  }
  
  @Retention(RetentionPolicy.RUNTIME)
  @Target({java.lang.annotation.ElementType.FIELD})
  protected static @interface Opt
  {
    String argName() default "";
    
    String description();
    
    boolean hasArg() default true;
    
    boolean required() default false;
    
    String longOpt() default "";
    
    String opt();
  }
}

/* Location:
 * Qualified Name:     com.googlecode.dex2jar.tools.BaseCmd
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.googlecode.dex2jar.tools;

import java.io.PrintWriter;
import org.objectweb.asm.Label;
import org.objectweb.asm.Type;
import org.objectweb.asm.commons.EmptyVisitor;

class JasminifierClassAdapter$2
  extends EmptyVisitor
{
  JasminifierClassAdapter$2(JasminifierClassAdapter paramJasminifierClassAdapter) {}
  
  public void visitFrame(int type, int local, Object[] locals, int stack, Object[] stacks)
  {
    if ((type != 0) && (type != -1)) {
      throw new RuntimeException("Compressed frames unsupported, use EXPAND_FRAMES option");
    }
    this$0.pw.println(".stack");
    for (int i = 0; i < local; i++)
    {
      this$0.pw.print("locals ");
      this$0.printFrameType(locals[i]);
      this$0.pw.println();
    }
    for (int i = 0; i < stack; i++)
    {
      this$0.pw.print("stack ");
      this$0.printFrameType(stacks[i]);
      this$0.pw.println();
    }
    this$0.pw.println(".end stack");
  }
  
  public void visitInsn(int opcode)
  {
    this$0.print(opcode);
    this$0.pw.println();
  }
  
  public void visitIntInsn(int opcode, int operand)
  {
    this$0.print(opcode);
    if (opcode == 188)
    {
      switch (operand)
      {
      case 4: 
        this$0.pw.println(" boolean");
        break;
      case 5: 
        this$0.pw.println(" char");
        break;
      case 6: 
        this$0.pw.println(" float");
        break;
      case 7: 
        this$0.pw.println(" double");
        break;
      case 8: 
        this$0.pw.println(" byte");
        break;
      case 9: 
        this$0.pw.println(" short");
        break;
      case 10: 
        this$0.pw.println(" int");
        break;
      case 11: 
      default: 
        this$0.pw.println(" long");
        break;
      }
    }
    else
    {
      this$0.pw.print(' ');
      this$0.pw.println(operand);
    }
  }
  
  public void visitVarInsn(int opcode, int var)
  {
    this$0.print(opcode);
    this$0.pw.print(' ');
    this$0.pw.println(var);
  }
  
  public void visitTypeInsn(int opcode, String type)
  {
    this$0.print(opcode);
    this$0.pw.print(' ');
    this$0.pw.println(type);
  }
  
  public void visitFieldInsn(int opcode, String owner, String name, String desc)
  {
    this$0.print(opcode);
    this$0.pw.print(' ');
    this$0.pw.print(owner);
    this$0.pw.print('/');
    this$0.pw.print(name);
    this$0.pw.print(' ');
    this$0.pw.println(desc);
  }
  
  public void visitMethodInsn(int opcode, String owner, String name, String desc)
  {
    this$0.print(opcode);
    this$0.pw.print(' ');
    this$0.pw.print(owner);
    this$0.pw.print('/');
    this$0.pw.print(name);
    this$0.pw.print(desc);
    if (opcode == 185)
    {
      this$0.pw.print(' ');
      this$0.pw.print((Type.getArgumentsAndReturnSizes(desc) >> 2) - 1);
    }
    this$0.pw.println();
  }
  
  public void visitJumpInsn(int opcode, Label label)
  {
    this$0.print(opcode);
    this$0.pw.print(' ');
    this$0.print(label);
    this$0.pw.println();
  }
  
  public void visitLabel(Label label)
  {
    this$0.print(label);
    this$0.pw.println(':');
  }
  
  public void visitLdcInsn(Object cst)
  {
    if (((cst instanceof Integer)) || ((cst instanceof Float)))
    {
      this$0.pw.print("ldc_w ");
      this$0.print(cst);
    }
    else if (((cst instanceof Long)) || ((cst instanceof Double)))
    {
      this$0.pw.print("ldc2_w ");
      this$0.print(cst);
    }
    else
    {
      this$0.pw.print("ldc ");
      if ((cst instanceof Type)) {
        this$0.pw.print(((Type)cst).getInternalName());
      } else {
        this$0.print(cst);
      }
    }
    this$0.pw.println();
  }
  
  public void visitIincInsn(int var, int increment)
  {
    this$0.pw.print("iinc ");
    this$0.pw.print(var);
    this$0.pw.print(' ');
    this$0.pw.println(increment);
  }
  
  public void visitTableSwitchInsn(int min, int max, Label dflt, Label[] labels)
  {
    this$0.pw.print("tableswitch ");
    this$0.pw.println(min);
    for (int i = 0; i < labels.length; i++)
    {
      this$0.print(labels[i]);
      this$0.pw.println();
    }
    this$0.pw.print("default : ");
    this$0.print(dflt);
    this$0.pw.println();
  }
  
  public void visitLookupSwitchInsn(Label dflt, int[] keys, Label[] labels)
  {
    this$0.pw.println("lookupswitch");
    for (int i = 0; i < keys.length; i++)
    {
      this$0.pw.print(keys[i]);
      this$0.pw.print(" : ");
      this$0.print(labels[i]);
      this$0.pw.println();
    }
    this$0.pw.print("default : ");
    this$0.print(dflt);
    this$0.pw.println();
  }
  
  public void visitMultiANewArrayInsn(String desc, int dims)
  {
    this$0.pw.print("multianewarray ");
    this$0.pw.print(desc);
    this$0.pw.print(' ');
    this$0.pw.println(dims);
  }
  
  public void visitLineNumber(int line, Label start)
  {
    this$0.pw.print(".line ");
    this$0.pw.println(line);
  }
}

/* Location:
 * Qualified Name:     com.googlecode.dex2jar.tools.JasminifierClassAdapter.2
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.googlecode.dex2jar.tools;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
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.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
import p.rn.util.FileOut.OutHandler;
import p.rn.util.FileWalker.StreamHandler;
import p.rn.util.FileWalker.StreamOpener;

class JarAccessCmd$1
  implements FileWalker.StreamHandler
{
  JarAccessCmd$1(JarAccessCmd paramJarAccessCmd, FileOut.OutHandler paramOutHandler, int paramInt1, int paramInt2, int paramInt3, int paramInt4, int paramInt5, int paramInt6, int paramInt7) {}
  
  public void handle(boolean isDir, String name, FileWalker.StreamOpener current, Object nameObject)
    throws IOException
  {
    if ((isDir) || (!name.endsWith(".class")))
    {
      val$fo.write(isDir, name, current == null ? null : current.get(), nameObject);
      return;
    }
    OutputStream os = null;
    try
    {
      InputStream is = current.get();
      final ClassReader r = new ClassReader(is);
      ClassWriter cr = new ClassWriter(0);
      r.accept(new ClassAdapter(cr)
      {
        public void visit(int version, int access, String name, String signature, String superName, String[] interfaces)
        {
          int na = access & val$rc | val$ac;
          if (access != na) {
            System.out.println("c " + name);
          }
          super.visit(version, na, name, signature, superName, interfaces);
        }
        
        public FieldVisitor visitField(int access, String name, String desc, String signature, Object value)
        {
          int na = access & val$rf | val$af;
          if (na != access) {
            System.out.println("f " + r.getClassName() + "." + name);
          }
          return super.visitField(na, name, desc, signature, value);
        }
        
        public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions)
        {
          int na = access & val$rm | val$am;
          if (na != access) {
            System.out.println("m " + r.getClassName() + "." + name + desc);
          }
          return super.visitMethod(na, name, desc, signature, exceptions);
        }
      }, val$flags | 0x8);
      
      val$fo.write(isDir, name, cr.toByteArray(), nameObject);
    }
    catch (IOException ioe)
    {
      System.err.println("error in " + name);
      ioe.printStackTrace(System.err);
    }
    finally
    {
      IOUtils.closeQuietly(os);
    }
  }
}

/* Location:
 * Qualified Name:     com.googlecode.dex2jar.tools.JarAccessCmd.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.googlecode.dex2jar.tools;

import jasmin.ClassFile;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.Reader;
import org.apache.commons.io.IOUtils;
import p.rn.util.FileOut.OutHandler;
import p.rn.util.FileWalker.StreamHandler;
import p.rn.util.FileWalker.StreamOpener;

class Jasmin2Jar$1
  implements FileWalker.StreamHandler
{
  Jasmin2Jar$1(Jasmin2Jar paramJasmin2Jar, FileOut.OutHandler paramOutHandler) {}
  
  public void handle(boolean isDir, String name, FileWalker.StreamOpener current, Object nameObject)
    throws IOException
  {
    if ((isDir) || (!name.endsWith(".j"))) {
      return;
    }
    try
    {
      ClassFile classFile = new ClassFile();
      Reader reader = new InputStreamReader(current.get(), Jasmin2Jar.access$000(this$0));
      classFile.readJasmin(reader, name, this$0.autogenLines);
      
      int errorcount = classFile.errorCount();
      if (errorcount > 0)
      {
        System.err.println(name + ": Found " + errorcount + " errors");
        return;
      }
      String clzName = classFile.getClassName();
      OutputStream os = val$fo.openOutput(clzName.replace('.', '/') + ".class", nameObject);
      try
      {
        classFile.write(os);
      }
      finally
      {
        IOUtils.closeQuietly(os);
      }
    }
    catch (Exception ex)
    {
      ex.printStackTrace(System.err);
    }
  }
}

/* Location:
 * Qualified Name:     com.googlecode.dex2jar.tools.Jasmin2Jar.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.googlecode.dex2jar.tools;

import java.lang.annotation.Annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target({java.lang.annotation.ElementType.FIELD})
public @interface BaseCmd$Opt
{
  String argName() default "";
  
  String description();
  
  boolean hasArg() default true;
  
  boolean required() default false;
  
  String longOpt() default "";
  
  String opt();
}

/* Location:
 * Qualified Name:     com.googlecode.dex2jar.tools.BaseCmd.Opt
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.googlecode.dex2jar.tools;

import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.tree.ClassNode;

class JasminifierClassAdapter$1
  extends ClassNode
{
  JasminifierClassAdapter$1(ClassVisitor paramClassVisitor) {}
  
  public void visitEnd()
  {
    if (val$cv != null) {
      accept(val$cv);
    }
  }
}

/* Location:
 * Qualified Name:     com.googlecode.dex2jar.tools.JasminifierClassAdapter.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.googlecode.dex2jar.tools;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.List;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.analysis.Analyzer;
import org.objectweb.asm.tree.analysis.BasicVerifier;
import org.objectweb.asm.util.CheckClassAdapter;
import p.rn.util.FileWalker.StreamHandler;
import p.rn.util.FileWalker.StreamOpener;

class AsmVerify$1
  implements FileWalker.StreamHandler
{
  AsmVerify$1(AsmVerify paramAsmVerify) {}
  
  public void handle(boolean isDir, String name, FileWalker.StreamOpener current, Object nameObject)
    throws IOException
  {
    if ((isDir) || (!name.endsWith(".class"))) {
      return;
    }
    InputStream is = current.get();
    ClassReader cr = new ClassReader(is);
    ClassNode cn = new ClassNode();
    cr.accept(new CheckClassAdapter(cn, false), 2);
    
    List<?> methods = methods;
    for (int i = 0; i < methods.size(); i++)
    {
      MethodNode method = (MethodNode)methods.get(i);
      BasicVerifier verifier = new BasicVerifier();
      Analyzer a = new Analyzer(verifier);
      try
      {
        a.analyze(name, method);
      }
      catch (Exception ex)
      {
        System.err.println("Error verify method " + cr.getClassName() + "." + name + " " + desc);
        if (this$0.detail)
        {
          ex.printStackTrace(System.err);
          AsmVerify.printAnalyzerResult(method, a, new PrintWriter(System.err));
        }
      }
    }
  }
}

/* Location:
 * Qualified Name:     com.googlecode.dex2jar.tools.AsmVerify.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.googlecode.dex2jar.tools;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.PrintWriter;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.objectweb.asm.ClassReader;
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 Jar2Jasmin
  extends BaseCmd
{
  public static void main(String[] args)
  {
    new Jar2Jasmin().doMain(args);
  }
  
  @BaseCmd.Opt(opt="d", longOpt="debug", hasArg=false, description="disassemble debug info")
  private boolean debugInfo = false;
  @BaseCmd.Opt(opt="f", longOpt="force", hasArg=false, description="force overwrite")
  private boolean forceOverwrite = false;
  @BaseCmd.Opt(opt="o", longOpt="output", description="output dir of .j files, default is $current_dir/[jar-name]-jar2jasmin/", argName="out-dir")
  private File output;
  @BaseCmd.Opt(opt="e", longOpt="encoding", description="encoding for .j files, default is UTF-8", argName="enc")
  private String encoding = "UTF-8";
  
  public Jar2Jasmin()
  {
    super("d2j-jar2jasmin [options] <jar>", "Disassemble .class in jar file to jasmin file");
  }
  
  protected void doCommandLine()
    throws Exception
  {
    if (remainingArgs.length != 1)
    {
      usage();
      return;
    }
    File jar = new File(remainingArgs[0]);
    if (!jar.exists())
    {
      System.err.println(jar + " is not exists");
      usage();
      return;
    }
    if (output == null) {
      if (jar.isDirectory()) {
        output = new File(jar.getName() + "-jar2jasmin/");
      } else {
        output = new File(FilenameUtils.getBaseName(jar.getName()) + "-jar2jasmin/");
      }
    }
    if ((output.exists()) && (!forceOverwrite))
    {
      System.err.println(output + " exists, use --force to overwrite");
      usage();
      return;
    }
    System.out.println("disassemble " + jar + " -> " + output);
    final int flags = debugInfo ? 0 : 2;
    final FileOut.OutHandler fo = FileOut.create(output, false);
    try
    {
      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"))) {
            return;
          }
          OutputStream os = null;
          PrintWriter out = null;
          try
          {
            InputStream is = current.get();
            ClassReader r = new ClassReader(is);
            os = fo.openOutput(r.getClassName().replace('.', '/') + ".j", nameObject);
            out = new PrintWriter(new OutputStreamWriter(os, encoding));
            r.accept(new JasminifierClassAdapter(out, null), flags | 0x8);
          }
          catch (IOException ioe)
          {
            System.err.println("error in " + name);
            ioe.printStackTrace(System.err);
          }
          finally
          {
            IOUtils.closeQuietly(out);
            IOUtils.closeQuietly(os);
          }
        }
      }).walk(jar);
    }
    finally
    {
      IOUtils.closeQuietly(fo);
    }
  }
}

/* Location:
 * Qualified Name:     com.googlecode.dex2jar.tools.Jar2Jasmin
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.googlecode.dex2jar.tools;

import java.io.PrintWriter;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;

class BaseCmd$1
  extends HelpFormatter
{
  BaseCmd$1(BaseCmd paramBaseCmd) {}
  
  public void printHelp(PrintWriter pw, int width, String cmdLineSyntax, String header, Options options, int leftPad, int descPad, String footer, boolean autoUsage)
  {
    String xHeader = BaseCmd.access$000(this$0);
    if ((xHeader != null) && (!xHeader.equals(""))) {
      printWrapped(pw, width, xHeader);
    }
    super.printHelp(pw, width, cmdLineSyntax, header, options, leftPad, descPad, footer, autoUsage);
  }
}

/* Location:
 * Qualified Name:     com.googlecode.dex2jar.tools.BaseCmd.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.googlecode.dex2jar.tools;

import jasmin.ClassFile;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.Reader;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
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 Jasmin2Jar
  extends BaseCmd
{
  public static void main(String[] args)
    throws ClassNotFoundException, SecurityException, NoSuchMethodException
  {
    new Jasmin2Jar().doMain(args);
  }
  
  @BaseCmd.Opt(opt="g", longOpt="autogenerate-linenumbers", hasArg=false, description="autogenerate-linenumbers")
  boolean autogenLines = false;
  @BaseCmd.Opt(opt="f", longOpt="force", hasArg=false, description="force overwrite")
  private boolean forceOverwrite = false;
  @BaseCmd.Opt(opt="o", longOpt="output", description="output .jar file, default is $current_dir/[jar-name]-jasmin2jar.jar", argName="out-jar-file")
  private File output;
  @BaseCmd.Opt(opt="e", longOpt="encoding", description="encoding for .j files, default is UTF-8", argName="enc")
  private String encoding = "UTF-8";
  
  public Jasmin2Jar()
  {
    super("d2j-jasmin2jar [options] <dir>", "d2j-jasmin2jar - assemble .j files to .class file");
  }
  
  protected void doCommandLine()
    throws Exception
  {
    if (remainingArgs.length != 1)
    {
      usage();
      return;
    }
    File dir = new File(remainingArgs[0]);
    if (!dir.exists())
    {
      System.err.println(dir + " is not exists");
      usage();
      return;
    }
    if (output == null) {
      if (dir.isDirectory()) {
        output = new File(dir.getName() + "-jasmin2jar.jar");
      } else {
        output = new File(FilenameUtils.getBaseName(dir.getName()) + "-jasmin2jar.jar");
      }
    }
    if ((output.exists()) && (!forceOverwrite))
    {
      System.err.println(output + " exists, use --force to overwrite");
      usage();
      return;
    }
    System.out.println("assemble " + dir + " -> " + output);
    
    final FileOut.OutHandler fo = FileOut.create(output, true);
    try
    {
      new FileWalker().withStreamHandler(new FileWalker.StreamHandler()
      {
        public void handle(boolean isDir, String name, FileWalker.StreamOpener current, Object nameObject)
          throws IOException
        {
          if ((isDir) || (!name.endsWith(".j"))) {
            return;
          }
          try
          {
            ClassFile classFile = new ClassFile();
            Reader reader = new InputStreamReader(current.get(), encoding);
            classFile.readJasmin(reader, name, autogenLines);
            
            int errorcount = classFile.errorCount();
            if (errorcount > 0)
            {
              System.err.println(name + ": Found " + errorcount + " errors");
              return;
            }
            String clzName = classFile.getClassName();
            OutputStream os = fo.openOutput(clzName.replace('.', '/') + ".class", nameObject);
            try
            {
              classFile.write(os);
            }
            finally
            {
              IOUtils.closeQuietly(os);
            }
          }
          catch (Exception ex)
          {
            ex.printStackTrace(System.err);
          }
        }
      }).walk(dir);
    }
    finally
    {
      IOUtils.closeQuietly(fo);
    }
  }
}

/* Location:
 * Qualified Name:     com.googlecode.dex2jar.tools.Jasmin2Jar
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.googlecode.dex2jar.tools;

import java.io.File;
import java.io.PrintStream;
import org.apache.commons.io.FilenameUtils;
import p.rn.name.Renamer;

public class JarRemap
  extends BaseCmd
{
  public static void main(String[] args)
  {
    new JarRemap().doMain(args);
  }
  
  @BaseCmd.Opt(opt="f", longOpt="force", hasArg=false, description="force overwrite")
  private boolean forceOverwrite = false;
  @BaseCmd.Opt(opt="o", longOpt="output", description="output .jar file, default is $current_dir/[jar-name]-remap.jar", argName="out-jar")
  private File output;
  @BaseCmd.Opt(opt="c", longOpt="config", required=true, description="config file for remap, this is REQUIRED", argName="config")
  private File config;
  
  public JarRemap()
  {
    super("d2j-jar-remap [options] <jar>", "rename package/class/method/field name in a jar");
  }
  
  protected void doCommandLine()
    throws Exception
  {
    if (remainingArgs.length != 1)
    {
      usage();
      return;
    }
    File jar = new File(remainingArgs[0]);
    if (!jar.exists())
    {
      System.err.println(jar + " is not exists");
      usage();
      return;
    }
    if (output == null) {
      if (jar.isDirectory()) {
        output = new File(jar.getName() + "-remap.jar");
      } else {
        output = new File(FilenameUtils.getBaseName(jar.getName()) + "-remap.jar");
      }
    }
    if ((output.exists()) && (!forceOverwrite))
    {
      System.err.println(output + " exists, use --force to overwrite");
      usage();
      return;
    }
    System.out.println("remap " + jar + " -> " + output);
    new Renamer().from(jar).withConfig(config).to(output);
  }
}

/* Location:
 * Qualified Name:     com.googlecode.dex2jar.tools.JarRemap
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.googlecode.dex2jar.tools;

import java.io.File;
import java.io.PrintStream;
import org.apache.commons.io.FilenameUtils;
import p.rn.name.InitOut;

public class DeObfInitCmd
  extends BaseCmd
{
  public static void main(String[] args)
  {
    new DeObfInitCmd().doMain(args);
  }
  
  @BaseCmd.Opt(opt="f", longOpt="force", hasArg=false, description="force overwrite")
  private boolean forceOverwrite = false;
  @BaseCmd.Opt(opt="o", longOpt="output", description="output .jar file, default is $current_dir/[file-name]-deobf-init.txt", argName="out-file")
  private File output;
  @BaseCmd.Opt(opt="min", longOpt="min-length", description="do the rename if the length < MIN, default is 2", argName="MIN")
  private int min = 2;
  @BaseCmd.Opt(opt="max", longOpt="max-length", description="do the rename if the length > MIN, default is 40", argName="MAX")
  private int max = 40;
  
  public DeObfInitCmd()
  {
    super("d2j-init-deobf [options] <jar>", "generate an init config file for deObfuscate a jar");
  }
  
  protected void doCommandLine()
    throws Exception
  {
    if (remainingArgs.length != 1)
    {
      usage();
      return;
    }
    File jar = new File(remainingArgs[0]);
    if (!jar.exists())
    {
      System.err.println(jar + " is not exists");
      usage();
      return;
    }
    if (output == null) {
      if (jar.isDirectory()) {
        output = new File(jar.getName() + "-deobf-init.txt");
      } else {
        output = new File(FilenameUtils.getBaseName(jar.getName()) + "-deobf-init.txt");
      }
    }
    if ((output.exists()) && (!forceOverwrite))
    {
      System.err.println(output + " exists, use --force to overwrite");
      usage();
      return;
    }
    System.out.println("generate " + jar + " -> " + output);
    new InitOut().from(jar).maxLength(max).minLength(min).to(output);
  }
}

/* Location:
 * Qualified Name:     com.googlecode.dex2jar.tools.DeObfInitCmd
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.googlecode.dex2jar.tools;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import org.apache.commons.io.FilenameUtils;
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.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
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 JarAccessCmd
  extends BaseCmd
{
  public static void main(String[] args)
  {
    new JarAccessCmd().doMain(args);
  }
  
  public JarAccessCmd()
  {
    super("d2j-jar-access [options] <jar>", "add or remove class/method/field access in jar file");
  }
  
  @BaseCmd.Opt(opt="f", longOpt="force", hasArg=false, description="force overwrite")
  private boolean forceOverwrite = false;
  @BaseCmd.Opt(opt="o", longOpt="output", description="output dir of .j files, default is $current_dir/[jar-name]-access.jar", argName="out-dir")
  private File output;
  @BaseCmd.Opt(opt="rd", longOpt="remove-debug", hasArg=false, description="remove debug info")
  private boolean removeDebug = false;
  @BaseCmd.Opt(opt="rf", longOpt="remove-field-access", description="remove access from field", argName="ACC")
  private String removeFieldAccess;
  @BaseCmd.Opt(opt="rm", longOpt="remove-method-access", description="remove access from method", argName="ACC")
  private String removeMethodAccess;
  @BaseCmd.Opt(opt="rc", longOpt="remove-class-access", description="remove access from class", argName="ACC")
  private String removeClassAccess;
  @BaseCmd.Opt(opt="af", longOpt="add-field-access", description="add access from field", argName="ACC")
  private String addFieldAccess;
  @BaseCmd.Opt(opt="am", longOpt="add-method-access", description="add access from method", argName="ACC")
  private String addMethodAccess;
  @BaseCmd.Opt(opt="ac", longOpt="add-class-access", description="add access from class", argName="ACC")
  private String addClassAccess;
  
  static int str2acc(String s)
  {
    if (s == null) {
      return 0;
    }
    int result = 0;
    s = s.toLowerCase();
    if (s.contains("public")) {
      result |= 0x1;
    }
    if (s.contains("private")) {
      result |= 0x2;
    }
    if (s.contains("protected")) {
      result |= 0x4;
    }
    if (s.contains("final")) {
      result |= 0x10;
    }
    if (s.contains("static")) {
      result |= 0x8;
    }
    if (s.contains("super")) {
      result |= 0x20;
    }
    if (s.contains("synchronized")) {
      result |= 0x20;
    }
    if (s.contains("volatile")) {
      result |= 0x40;
    }
    if (s.contains("bridge")) {
      result |= 0x40;
    }
    if (s.contains("transient")) {
      result |= 0x80;
    }
    if (s.contains("varargs")) {
      result |= 0x80;
    }
    if (s.contains("native")) {
      result |= 0x100;
    }
    if (s.contains("strict")) {
      result |= 0x800;
    }
    if (s.contains("interface")) {
      result |= 0x200;
    }
    if (s.contains("abstract")) {
      result |= 0x400;
    }
    if (s.contains("synthetic")) {
      result |= 0x1000;
    }
    if (s.contains("annotation")) {
      result |= 0x2000;
    }
    if (s.contains("enum")) {
      result |= 0x4000;
    }
    if (s.contains("deprecated")) {
      result |= 0x20000;
    }
    return result;
  }
  
  protected void doCommandLine()
    throws Exception
  {
    if (remainingArgs.length != 1)
    {
      usage();
      return;
    }
    File jar = new File(remainingArgs[0]);
    if (!jar.exists())
    {
      System.err.println(jar + " is not exists");
      usage();
      return;
    }
    if (output == null) {
      if (jar.isDirectory()) {
        output = new File(jar.getName() + "-access.jar");
      } else {
        output = new File(FilenameUtils.getBaseName(jar.getName()) + "-access.jar");
      }
    }
    if ((output.exists()) && (!forceOverwrite))
    {
      System.err.println(output + " exists, use --force to overwrite");
      usage();
      return;
    }
    final int rf = str2acc(removeFieldAccess) ^ 0xFFFFFFFF;
    final int rm = str2acc(removeMethodAccess) ^ 0xFFFFFFFF;
    final int rc = str2acc(removeClassAccess) ^ 0xFFFFFFFF;
    
    final int af = str2acc(addFieldAccess);
    final int am = str2acc(addMethodAccess);
    final int ac = str2acc(addClassAccess);
    
    final int flags = removeDebug ? 2 : 0;
    final FileOut.OutHandler fo = FileOut.create(output, true);
    try
    {
      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")))
          {
            fo.write(isDir, name, current == null ? null : current.get(), nameObject);
            return;
          }
          OutputStream os = null;
          try
          {
            InputStream is = current.get();
            final ClassReader r = new ClassReader(is);
            ClassWriter cr = new ClassWriter(0);
            r.accept(new ClassAdapter(cr)
            {
              public void visit(int version, int access, String name, String signature, String superName, String[] interfaces)
              {
                int na = access & val$rc | val$ac;
                if (access != na) {
                  System.out.println("c " + name);
                }
                super.visit(version, na, name, signature, superName, interfaces);
              }
              
              public FieldVisitor visitField(int access, String name, String desc, String signature, Object value)
              {
                int na = access & val$rf | val$af;
                if (na != access) {
                  System.out.println("f " + r.getClassName() + "." + name);
                }
                return super.visitField(na, name, desc, signature, value);
              }
              
              public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions)
              {
                int na = access & val$rm | val$am;
                if (na != access) {
                  System.out.println("m " + r.getClassName() + "." + name + desc);
                }
                return super.visitMethod(na, name, desc, signature, exceptions);
              }
            }, flags | 0x8);
            
            fo.write(isDir, name, cr.toByteArray(), nameObject);
          }
          catch (IOException ioe)
          {
            System.err.println("error in " + name);
            ioe.printStackTrace(System.err);
          }
          finally
          {
            IOUtils.closeQuietly(os);
          }
        }
      }).walk(jar);
    }
    finally
    {
      IOUtils.closeQuietly(fo);
    }
  }
}

/* Location:
 * Qualified Name:     com.googlecode.dex2jar.tools.JarAccessCmd
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.googlecode.dex2jar.tools;

import org.objectweb.asm.util.TraceMethodVisitor;

class AsmVerify$XTraceMethodVisitor
  extends TraceMethodVisitor
{
  public StringBuffer getBuf()
  {
    return buf;
  }
}

/* Location:
 * Qualified Name:     com.googlecode.dex2jar.tools.AsmVerify.XTraceMethodVisitor
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.googlecode.dex2jar.tools;

import java.io.PrintStream;
import org.objectweb.asm.ClassAdapter;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;

class JarAccessCmd$1$1
  extends ClassAdapter
{
  JarAccessCmd$1$1(JarAccessCmd.1 param1, ClassVisitor x0, ClassReader paramClassReader)
  {
    super(x0);
  }
  
  public void visit(int version, int access, String name, String signature, String superName, String[] interfaces)
  {
    int na = access & this$1.val$rc | this$1.val$ac;
    if (access != na) {
      System.out.println("c " + name);
    }
    super.visit(version, na, name, signature, superName, interfaces);
  }
  
  public FieldVisitor visitField(int access, String name, String desc, String signature, Object value)
  {
    int na = access & this$1.val$rf | this$1.val$af;
    if (na != access) {
      System.out.println("f " + val$r.getClassName() + "." + name);
    }
    return super.visitField(na, name, desc, signature, value);
  }
  
  public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions)
  {
    int na = access & this$1.val$rm | this$1.val$am;
    if (na != access) {
      System.out.println("m " + val$r.getClassName() + "." + name + desc);
    }
    return super.visitMethod(na, name, desc, signature, exceptions);
  }
}

/* Location:
 * Qualified Name:     com.googlecode.dex2jar.tools.JarAccessCmd.1.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.googlecode.dex2jar.tools;

import java.io.File;
import java.io.PrintStream;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import p.rn.util.FileOut;
import p.rn.util.FileOut.OutHandler;
import p.rn.util.FileWalker;
import p.rn.util.FileWalker.OutAdapter;

public class Jar2Dex
  extends BaseCmd
{
  public static void main(String[] args)
  {
    new Jar2Dex().doMain(args);
  }
  
  @BaseCmd.Opt(opt="f", longOpt="force", hasArg=false, description="force overwrite")
  private boolean forceOverwrite = false;
  @BaseCmd.Opt(opt="o", longOpt="output", description="output .dex file, default is $current_dir/[jar-name]-jar2dex.dex", argName="out-dex-file")
  private File output;
  
  public Jar2Dex()
  {
    super("d
1 2 3

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