Package soot.toDex

Class DexPrinter


  • public class DexPrinter
    extends Object

    Creates apk or jar file with compiled dex classes. Main entry point for the "dex" output format.

    Use add(SootClass) to add classes that should be printed as dex output and print() to finally print the classes.

    If the printer has found the original APK of an added class (via SourceLocator#classContainerFileClassIndex()), the files in the APK are copied to a new one, replacing it's classes.dex and excluding the signature files. Note that you have to sign and align the APK yourself, with jarsigner and zipalign, respectively.

    If Options.output_jar flag is set, the printer produces JAR file.

    If there is no original APK and Options.output_jar flag is not set the printer just emits a classes.dex.

    See Also:
    jarsigner documentation, zipalign documentation
    • Field Detail

      • SIGNATURE_FILE_PATTERN

        public static final Pattern SIGNATURE_FILE_PATTERN
      • originalApk

        protected File originalApk
    • Constructor Detail

      • DexPrinter

        public DexPrinter()
    • Method Detail

      • toFieldReference

        protected static org.jf.dexlib2.iface.reference.FieldReference toFieldReference​(SootField f)
      • toFieldReference

        protected static org.jf.dexlib2.iface.reference.FieldReference toFieldReference​(SootFieldRef ref)
      • toMethodReference

        protected static org.jf.dexlib2.iface.reference.MethodReference toMethodReference​(SootMethodRef m)
      • toTypeReference

        public static org.jf.dexlib2.iface.reference.TypeReference toTypeReference​(Type t)
      • makeConstantItem

        protected org.jf.dexlib2.iface.value.EncodedValue makeConstantItem​(SootField sf,
                                                                           Tag t)
      • addClassDefinition

        protected void addClassDefinition​(org.jf.dexlib2.iface.ClassDef classDef)
      • buildClassAnnotations

        protected Set<org.jf.dexlib2.iface.Annotation> buildClassAnnotations​(SootClass c)
      • writeMemberClasses

        protected void writeMemberClasses​(SootClass c,
                                          Set<String> skipList,
                                          Set<org.jf.dexlib2.iface.Annotation> annotations)
      • isIgnored

        protected boolean isIgnored​(SootMethod sm)
        Checks whether the given method shall be ignored, i.e., not written out to dex
        Parameters:
        sm - The method to check
        Returns:
        True to ignore the method while writing the dex file, false to write it out as normal
      • isIgnored

        protected boolean isIgnored​(SootField sf)
        Checks whether the given field shall be ignored, i.e., not written out to dex
        Parameters:
        sf - The field to check
        Returns:
        True to ignore the field while writing the dex file, false to write it out as normal
      • toMethodImplementation

        protected org.jf.dexlib2.iface.MethodImplementation toMethodImplementation​(SootMethod m)
      • buildStmtVisitor

        protected StmtVisitor buildStmtVisitor​(SootMethod belongingMethod,
                                               DexArrayInitDetector arrayInitDetector)
        Creates a statement visitor to build code for each statement. Allows subclasses to use own implementations
        Parameters:
        belongingMethod - the method
        arrayInitDetector - auxilliary class for detecting array initializations
        Returns:
        the statement visitor
      • writeTagsForStatement

        protected void writeTagsForStatement​(org.jf.dexlib2.builder.MethodImplementationBuilder builder,
                                             Stmt stmt)
        Writes out the information stored in the tags associated with the given statement
        Parameters:
        builder - The builder used to generate the Dalvik method implementation
        stmt - The statement for which to write out the tags
      • toTries

        protected void toTries​(Collection<Trap> traps,
                               org.jf.dexlib2.builder.MethodImplementationBuilder builder,
                               LabelAssigner labelAssigner)
      • print

        public void print()