org.ow2.asmdex.util
Class AsmDexifierApplicationVisitor

java.lang.Object
  extended by org.ow2.asmdex.ApplicationVisitor
      extended by org.ow2.asmdex.util.AsmDexifierApplicationVisitor

public class AsmDexifierApplicationVisitor
extends ApplicationVisitor

An ApplicationVisitor that prints the AsmDex code that generates the Application it visits. This Application visitor can be used to quickly write ASM code to generate some given bytecode:

NOTE:

Author:
Julien Névo, based on the ASM Framework.

Field Summary
static java.lang.String OPCODES_FULLY_QUALIFIED_NAME
          Fully qualified name of the Opcodes class.
protected  java.io.PrintWriter pw
          The print writer to be used to print the Application.
 
Fields inherited from class org.ow2.asmdex.ApplicationVisitor
api, av
 
Constructor Summary
AsmDexifierApplicationVisitor(int api, java.io.PrintWriter pw)
          Constructs a new AsmDexifierApplicationVisitor object.
AsmDexifierApplicationVisitor(int api, java.io.PrintWriter pw, java.lang.String packageName, java.lang.String filenameOutput)
          Constructs a new AsmDexifierApplicationVisitor object.
 
Method Summary
 java.lang.String getAcceptableMethodName(java.lang.String className)
          Returns a correct Method name from the given Class name, which may probably be fully qualified.
static java.lang.String getOpcodeName(int opcode)
          Returns the opcode name from the given opcode, or Null if the opcode isn't found.
static void main(java.lang.String[] args)
          Prints the ASM source code to generate the given Application to the standard output.
static void setDexFileName(java.lang.String name)
          Sets the dex filename, which mustn't contain path and extension.
static java.lang.String trimDexFileName(java.lang.String fullFileName)
          Trims the given Dex filename of its path and extension.
 void visit()
          Visits the header of the application.
 ClassVisitor visitClass(int access, java.lang.String name, java.lang.String[] signature, java.lang.String superName, java.lang.String[] interfaces)
          Visits a class of the application.
 void visitEnd()
          Visits the end of the application.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OPCODES_FULLY_QUALIFIED_NAME

public static final java.lang.String OPCODES_FULLY_QUALIFIED_NAME
Fully qualified name of the Opcodes class.

See Also:
Constant Field Values

pw

protected final java.io.PrintWriter pw
The print writer to be used to print the Application.

Constructor Detail

AsmDexifierApplicationVisitor

public AsmDexifierApplicationVisitor(int api,
                                     java.io.PrintWriter pw)
Constructs a new AsmDexifierApplicationVisitor object.

Parameters:
api - API level
pw - the print writer to be used to print the class.

AsmDexifierApplicationVisitor

public AsmDexifierApplicationVisitor(int api,
                                     java.io.PrintWriter pw,
                                     java.lang.String packageName,
                                     java.lang.String filenameOutput)
Constructs a new AsmDexifierApplicationVisitor object.

Parameters:
api - API level
pw - the print writer to be used to print the class.
packageName - name of the package, or Null if none should be written.
filenameOutput - possible path and filename of the file where to save the output. If not Null, a Main method will be created.
Method Detail

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Prints the ASM source code to generate the given Application to the standard output. Not to give classes means visiting all the classes of the Dex file.

Usage: ASMifierClassVisitor [-debug] <Dex file to open> [<fully qualified class names>]

Parameters:
args - the command line arguments.
Throws:
java.lang.Exception - if the class cannot be found, or if an IO exception occurs.

trimDexFileName

public static java.lang.String trimDexFileName(java.lang.String fullFileName)
Trims the given Dex filename of its path and extension.

Parameters:
fullFileName - name that can contain the path and the extension.
Returns:
name of the dex file, without the path and the extension.

setDexFileName

public static void setDexFileName(java.lang.String name)
Sets the dex filename, which mustn't contain path and extension. It is useful to name the class generated (prefixed with "Dump").

Parameters:
name - the dex filename.

visit

public void visit()
Description copied from class: ApplicationVisitor
Visits the header of the application.

Overrides:
visit in class ApplicationVisitor

visitClass

public ClassVisitor visitClass(int access,
                               java.lang.String name,
                               java.lang.String[] signature,
                               java.lang.String superName,
                               java.lang.String[] interfaces)
Description copied from class: ApplicationVisitor
Visits a class of the application. This method must return a new ClassVisitor instance (or null) each time it is called, i.e., it should not return a previously returned visitor.

Overrides:
visitClass in class ApplicationVisitor
Parameters:
access - the access flags of the class (see Opcodes).
name - the internal name of the class.
signature - the signature of this class. May be null if the class is not a generic one, and does not extend or implement generic classes or interfaces.
superName - the internal of name of the super class. For interfaces, the super class is Object. May be null, but only for the Object class.
interfaces - the internal names of the class's interfaces. May be null.
Returns:
an object to visit the byte code of the application, or null if this application visitor is not interested in visiting the code of this class.

visitEnd

public void visitEnd()
Description copied from class: ApplicationVisitor
Visits the end of the application. This method, which is the last one to be called, is used to inform the visitor that the whole Application has been visited.

Overrides:
visitEnd in class ApplicationVisitor

getOpcodeName

public static java.lang.String getOpcodeName(int opcode)
Returns the opcode name from the given opcode, or Null if the opcode isn't found.

Parameters:
opcode - the opcode.
Returns:
the opcode name from the given opcode, or Null if the opcode isn't found.

getAcceptableMethodName

public java.lang.String getAcceptableMethodName(java.lang.String className)
Returns a correct Method name from the given Class name, which may probably be fully qualified. If also must not already be in the dumpMethods list, in which case a number is added to the name.

Parameters:
className -
Returns:
a correct Class name.