com.android.dx.cf.direct.DirectClassFile Java Examples

The following examples show how to use com.android.dx.cf.direct.DirectClassFile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: Box   Author: lulululbj   File: ClassDumper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Does the dumping.
 */
public void dump() {
    byte[] bytes = getBytes();
    ByteArray ba = new ByteArray(bytes);
    DirectClassFile cf =
        new DirectClassFile(ba, getFilePath(), getStrictParse());

    cf.setAttributeFactory(StdAttributeFactory.THE_ONE);
    cf.setObserver(this);
    cf.getMagic(); // Force parsing to happen.

    int readBytes = getReadBytes();
    if (readBytes != bytes.length) {
        parsed(ba, readBytes, bytes.length - readBytes, "<extra data at end of file>");
    }
}
 
Example #2
Source Project: Box   Author: lulululbj   File: BlockDumper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Does the dumping.
 */
public void dump() {
    byte[] bytes = getBytes();
    ByteArray ba = new ByteArray(bytes);

    /*
     * First, parse the file completely, so we can safely refer to
     * attributes, etc.
     */
    classFile = new DirectClassFile(ba, getFilePath(), getStrictParse());
    classFile.setAttributeFactory(StdAttributeFactory.THE_ONE);
    classFile.getMagic(); // Force parsing to happen.

    // Next, reparse it and observe the process.
    DirectClassFile liveCf =
        new DirectClassFile(ba, getFilePath(), getStrictParse());
    liveCf.setAttributeFactory(StdAttributeFactory.THE_ONE);
    liveCf.setObserver(this);
    liveCf.getMagic(); // Force parsing to happen.
}
 
Example #3
Source Project: Box   Author: lulululbj   File: DotDumper.java    License: Apache License 2.0 6 votes vote down vote up
private void run() {
    ByteArray ba = new ByteArray(bytes);

    /*
     * First, parse the file completely, so we can safely refer to
     * attributes, etc.
     */
    classFile = new DirectClassFile(ba, filePath, strictParse);
    classFile.setAttributeFactory(StdAttributeFactory.THE_ONE);
    classFile.getMagic(); // Force parsing to happen.

    // Next, reparse it and observe the process.
    DirectClassFile liveCf =
        new DirectClassFile(ba, filePath, strictParse);
    liveCf.setAttributeFactory(StdAttributeFactory.THE_ONE);
    liveCf.setObserver(this);
    liveCf.getMagic(); // Force parsing to happen.
}
 
Example #4
Source Project: Box   Author: lulululbj   File: AnnotationLister.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Inspects a class annotation.
 *
 * @param cf {@code non-null;} class file
 * @param ann {@code non-null;} annotation
 */
private void visitClassAnnotation(DirectClassFile cf,
        BaseAnnotations ann) {

    if (!args.eTypes.contains(ElementType.TYPE)) {
        return;
    }

    for (Annotation anAnn : ann.getAnnotations().getAnnotations()) {
        String annClassName
                = anAnn.getType().getClassType().getClassName();
        if (args.aclass.equals(annClassName)) {
            printMatch(cf);
        }
    }
}
 
Example #5
Source Project: Box   Author: lulululbj   File: AnnotationLister.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Prints, or schedules for printing, elements related to a matching
 * class.
 *
 * @param cf {@code non-null;} matching class
 */
private void printMatch(DirectClassFile cf) {
    for (Main.PrintType pt : args.printTypes) {
        switch (pt) {
            case CLASS:
                String classname;
                classname =
                    cf.getThisClass().getClassType().getClassName();
                classname = classname.replace('/','.');
                System.out.println(classname);
                break;
            case INNERCLASS:
                matchInnerClassesOf.add(
                        cf.getThisClass().getClassType().getClassName());
                break;
            case METHOD:
                //TODO
                break;
            case PACKAGE:
                break;
        }
    }
}
 
Example #6
Source Project: Box   Author: lulululbj   File: ClassReferenceListBuilder.java    License: Apache License 2.0 6 votes vote down vote up
private void addDependencies(DirectClassFile classFile) {
    for (Constant constant : classFile.getConstantPool().getEntries()) {
        if (constant instanceof CstType) {
            checkDescriptor(((CstType) constant).getClassType().getDescriptor());
        } else if (constant instanceof CstFieldRef) {
            checkDescriptor(((CstFieldRef) constant).getType().getDescriptor());
        } else if (constant instanceof CstBaseMethodRef) {
            checkPrototype(((CstBaseMethodRef) constant).getPrototype());
        }
    }

    FieldList fields = classFile.getFields();
    int nbField = fields.size();
    for (int i = 0; i < nbField; i++) {
      checkDescriptor(fields.get(i).getDescriptor().getString());
    }

    MethodList methods = classFile.getMethods();
    int nbMethods = methods.size();
    for (int i = 0; i < nbMethods; i++) {
      checkPrototype(Prototype.intern(methods.get(i).getDescriptor().getString()));
    }
}
 
Example #7
Source Project: Box   Author: lulululbj   File: ClassReferenceListBuilder.java    License: Apache License 2.0 6 votes vote down vote up
private void addClassWithHierachy(String classBinaryName) {
    if (classNames.contains(classBinaryName)) {
        return;
    }

    try {
        DirectClassFile classFile = path.getClass(classBinaryName + CLASS_EXTENSION);
        classNames.add(classBinaryName);
        CstType superClass = classFile.getSuperclass();
        if (superClass != null) {
            addClassWithHierachy(superClass.getClassType().getClassName());
        }

        TypeList interfaceList = classFile.getInterfaces();
        int interfaceNumber = interfaceList.size();
        for (int i = 0; i < interfaceNumber; i++) {
            addClassWithHierachy(interfaceList.getType(i).getClassName());
        }
    } catch (FileNotFoundException e) {
        // Ignore: The referenced type is not in the path it must be part of the libraries.
    }
}
 
Example #8
Source Project: Box   Author: lulululbj   File: ClassDumper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Does the dumping.
 */
public void dump() {
    byte[] bytes = getBytes();
    ByteArray ba = new ByteArray(bytes);
    DirectClassFile cf =
        new DirectClassFile(ba, getFilePath(), getStrictParse());

    cf.setAttributeFactory(StdAttributeFactory.THE_ONE);
    cf.setObserver(this);
    cf.getMagic(); // Force parsing to happen.

    int readBytes = getReadBytes();
    if (readBytes != bytes.length) {
        parsed(ba, readBytes, bytes.length - readBytes, "<extra data at end of file>");
    }
}
 
Example #9
Source Project: Box   Author: lulululbj   File: BlockDumper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Does the dumping.
 */
public void dump() {
    byte[] bytes = getBytes();
    ByteArray ba = new ByteArray(bytes);

    /*
     * First, parse the file completely, so we can safely refer to
     * attributes, etc.
     */
    classFile = new DirectClassFile(ba, getFilePath(), getStrictParse());
    classFile.setAttributeFactory(StdAttributeFactory.THE_ONE);
    classFile.getMagic(); // Force parsing to happen.

    // Next, reparse it and observe the process.
    DirectClassFile liveCf =
        new DirectClassFile(ba, getFilePath(), getStrictParse());
    liveCf.setAttributeFactory(StdAttributeFactory.THE_ONE);
    liveCf.setObserver(this);
    liveCf.getMagic(); // Force parsing to happen.
}
 
Example #10
Source Project: Box   Author: lulululbj   File: DotDumper.java    License: Apache License 2.0 6 votes vote down vote up
private void run() {
    ByteArray ba = new ByteArray(bytes);

    /*
     * First, parse the file completely, so we can safely refer to
     * attributes, etc.
     */
    classFile = new DirectClassFile(ba, filePath, strictParse);
    classFile.setAttributeFactory(StdAttributeFactory.THE_ONE);
    classFile.getMagic(); // Force parsing to happen.

    // Next, reparse it and observe the process.
    DirectClassFile liveCf =
        new DirectClassFile(ba, filePath, strictParse);
    liveCf.setAttributeFactory(StdAttributeFactory.THE_ONE);
    liveCf.setObserver(this);
    liveCf.getMagic(); // Force parsing to happen.
}
 
Example #11
Source Project: Box   Author: lulululbj   File: AnnotationLister.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Inspects a class annotation.
 *
 * @param cf {@code non-null;} class file
 * @param ann {@code non-null;} annotation
 */
private void visitClassAnnotation(DirectClassFile cf,
        BaseAnnotations ann) {

    if (!args.eTypes.contains(ElementType.TYPE)) {
        return;
    }

    for (Annotation anAnn : ann.getAnnotations().getAnnotations()) {
        String annClassName
                = anAnn.getType().getClassType().getClassName();
        if (args.aclass.equals(annClassName)) {
            printMatch(cf);
        }
    }
}
 
Example #12
Source Project: buck   Author: facebook   File: ClassReferenceListBuilder.java    License: Apache License 2.0 6 votes vote down vote up
private void addClassWithHierarchy(String classBinaryName) {
    if (classNames.contains(classBinaryName)) {
        return;
    }

    try {
        DirectClassFile classFile = path.getClass(classBinaryName + CLASS_EXTENSION);
        if (CLASS_TO_CHECK != null && classBinaryName.contains(CLASS_TO_CHECK)) {
          found();
        }
        classNames.add(classBinaryName);
        CstType superClass = classFile.getSuperclass();
        if (superClass != null) {
            addClassWithHierarchy(superClass.getClassType().getClassName());
        }

        TypeList interfaceList = classFile.getInterfaces();
        int interfaceNumber = interfaceList.size();
        for (int i = 0; i < interfaceNumber; i++) {
            addClassWithHierarchy(interfaceList.getType(i).getClassName());
        }
    } catch (FileNotFoundException e) {
        // Ignore: The referenced type is not in the path it must be part of the libraries.
    }
}
 
Example #13
Source Project: Box   Author: lulululbj   File: AnnotationLister.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Prints, or schedules for printing, elements related to a matching
 * class.
 *
 * @param cf {@code non-null;} matching class
 */
private void printMatch(DirectClassFile cf) {
    for (Main.PrintType pt : args.printTypes) {
        switch (pt) {
            case CLASS:
                String classname;
                classname =
                    cf.getThisClass().getClassType().getClassName();
                classname = classname.replace('/','.');
                System.out.println(classname);
                break;
            case INNERCLASS:
                matchInnerClassesOf.add(
                        cf.getThisClass().getClassType().getClassName());
                break;
            case METHOD:
                //TODO
                break;
            case PACKAGE:
                break;
        }
    }
}
 
Example #14
Source Project: Box   Author: lulululbj   File: ClassReferenceListBuilder.java    License: Apache License 2.0 6 votes vote down vote up
private void addDependencies(DirectClassFile classFile) {
    for (Constant constant : classFile.getConstantPool().getEntries()) {
        if (constant instanceof CstType) {
            checkDescriptor(((CstType) constant).getClassType().getDescriptor());
        } else if (constant instanceof CstFieldRef) {
            checkDescriptor(((CstFieldRef) constant).getType().getDescriptor());
        } else if (constant instanceof CstBaseMethodRef) {
            checkPrototype(((CstBaseMethodRef) constant).getPrototype());
        }
    }

    FieldList fields = classFile.getFields();
    int nbField = fields.size();
    for (int i = 0; i < nbField; i++) {
      checkDescriptor(fields.get(i).getDescriptor().getString());
    }

    MethodList methods = classFile.getMethods();
    int nbMethods = methods.size();
    for (int i = 0; i < nbMethods; i++) {
      checkPrototype(Prototype.intern(methods.get(i).getDescriptor().getString()));
    }
}
 
Example #15
Source Project: Box   Author: lulululbj   File: ClassReferenceListBuilder.java    License: Apache License 2.0 6 votes vote down vote up
private void addClassWithHierachy(String classBinaryName) {
    if (classNames.contains(classBinaryName)) {
        return;
    }

    try {
        DirectClassFile classFile = path.getClass(classBinaryName + CLASS_EXTENSION);
        classNames.add(classBinaryName);
        CstType superClass = classFile.getSuperclass();
        if (superClass != null) {
            addClassWithHierachy(superClass.getClassType().getClassName());
        }

        TypeList interfaceList = classFile.getInterfaces();
        int interfaceNumber = interfaceList.size();
        for (int i = 0; i < interfaceNumber; i++) {
            addClassWithHierachy(interfaceList.getType(i).getClassName());
        }
    } catch (FileNotFoundException e) {
        // Ignore: The referenced type is not in the path it must be part of the libraries.
    }
}
 
Example #16
Source Project: rhino-android   Author: F43nd1r   File: BaseAndroidClassLoader.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Class<?> defineClass(String name, byte[] data) {
    try {
        DexOptions dexOptions = new DexOptions();
        DexFile dexFile = new DexFile(dexOptions);
        DirectClassFile classFile = new DirectClassFile(data, name.replace('.', '/') + ".class", true);
        classFile.setAttributeFactory(StdAttributeFactory.THE_ONE);
        classFile.getMagic();
        DxContext context = new DxContext();
        dexFile.add(CfTranslator.translate(context, classFile, null, new CfOptions(), dexOptions, dexFile));
        Dex dex = new Dex(dexFile.toDex(null, false));
        Dex oldDex = getLastDex();
        if (oldDex != null) {
            dex = new DexMerger(new Dex[]{dex, oldDex}, CollisionPolicy.KEEP_FIRST, context).merge();
        }
        return loadClass(dex, name);
    } catch (IOException | ClassNotFoundException e) {
        throw new FatalLoadingException(e);
    }
}
 
Example #17
Source Project: RocooFix   Author: dodola   File: ClassReferenceListBuilder.java    License: MIT License 6 votes vote down vote up
public void addSupperClass(String name){
        if (name.endsWith(CLASS_EXTENSION)) {
            classNames.add(name.substring(0, name.length() - CLASS_EXTENSION.length()));
        }
        if (name.endsWith(CLASS_EXTENSION)) {
            DirectClassFile classFile;
            try {
                classFile = path.getClass(name);
                CstType superClass = classFile.getSuperclass();
                if (superClass != null) {
                    String superClassName=superClass.getClassType().getClassName();
                    classNames.add(superClassName);
                }
            } catch (FileNotFoundException e) {
//                throw new IOException("Class " + name +
//                        " is missing form original class path " + path, e);
            }

        }
    }
 
Example #18
Source Project: RocooFix   Author: dodola   File: ClassReferenceListBuilder.java    License: MIT License 6 votes vote down vote up
public void addRootsV2(String name){
        if (name.endsWith(CLASS_EXTENSION)) {
            classNames.add(name.substring(0, name.length() - CLASS_EXTENSION.length()));
        }
        if (name.endsWith(CLASS_EXTENSION)) {
            DirectClassFile classFile;
            try {
                classFile = path.getClass(name);
                addDependencies(classFile);
            } catch (FileNotFoundException e) {
//                throw new IOException("Class " + name +
//                        " is missing form original class path " + path, e);
            }

        }
    }
 
Example #19
Source Project: RocooFix   Author: dodola   File: ClassReferenceListBuilder.java    License: MIT License 6 votes vote down vote up
private void addDependencies(DirectClassFile classFile) {
    for (Constant constant : classFile.getConstantPool().getEntries()) {
        if (constant instanceof CstType) {
            checkDescriptor(((CstType) constant).getClassType().getDescriptor());
        } else if (constant instanceof CstFieldRef) {
            checkDescriptor(((CstFieldRef) constant).getType().getDescriptor());
        } else if (constant instanceof CstBaseMethodRef) {
            checkPrototype(((CstBaseMethodRef) constant).getPrototype());
        }
    }
    FieldList fields = classFile.getFields();
    int nbField = fields.size();
    for (int i = 0; i < nbField; i++) {
      checkDescriptor(fields.get(i).getDescriptor().getString());
    }
    MethodList methods = classFile.getMethods();
    int nbMethods = methods.size();
    for (int i = 0; i < nbMethods; i++) {
      checkPrototype(Prototype.intern(methods.get(i).getDescriptor().getString()));
    }
}
 
Example #20
Source Project: RocooFix   Author: dodola   File: ClassReferenceListBuilder.java    License: MIT License 6 votes vote down vote up
private void addClassWithHierachy(String classBinaryName) {
    if (classNames.contains(classBinaryName)) {
        return;
    }
    try {
        DirectClassFile classFile = path.getClass(classBinaryName + CLASS_EXTENSION);
        classNames.add(classBinaryName);
        CstType superClass = classFile.getSuperclass();
        if (superClass != null) {
            addClassWithHierachy(superClass.getClassType().getClassName());
        }
        TypeList interfaceList = classFile.getInterfaces();
        int interfaceNumber = interfaceList.size();
        for (int i = 0; i < interfaceNumber; i++) {
            addClassWithHierachy(interfaceList.getType(i).getClassName());
        }
    } catch (FileNotFoundException e) {
        // Ignore: The referenced type is not in the path it must be part of the libraries.
    }
}
 
Example #21
Source Project: buck   Author: facebook   File: ClassDumper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Does the dumping.
 */
public void dump() {
    byte[] bytes = getBytes();
    ByteArray ba = new ByteArray(bytes);
    DirectClassFile cf =
        new DirectClassFile(ba, getFilePath(), getStrictParse());

    cf.setAttributeFactory(StdAttributeFactory.THE_ONE);
    cf.setObserver(this);
    cf.getMagic(); // Force parsing to happen.

    int at = getAt();
    if (at != bytes.length) {
        parsed(ba, at, bytes.length - at, "<extra data at end of file>");
    }
}
 
Example #22
Source Project: buck   Author: facebook   File: BlockDumper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Does the dumping.
 */
public void dump() {
    byte[] bytes = getBytes();
    ByteArray ba = new ByteArray(bytes);

    /*
     * First, parse the file completely, so we can safely refer to
     * attributes, etc.
     */
    classFile = new DirectClassFile(ba, getFilePath(), getStrictParse());
    classFile.setAttributeFactory(StdAttributeFactory.THE_ONE);
    classFile.getMagic(); // Force parsing to happen.

    // Next, reparse it and observe the process.
    DirectClassFile liveCf =
        new DirectClassFile(ba, getFilePath(), getStrictParse());
    liveCf.setAttributeFactory(StdAttributeFactory.THE_ONE);
    liveCf.setObserver(this);
    liveCf.getMagic(); // Force parsing to happen.
}
 
Example #23
Source Project: buck   Author: facebook   File: AnnotationLister.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Prints, or schedules for printing, elements related to a matching
 * class.
 *
 * @param cf {@code non-null;} matching class
 */
private void printMatch(DirectClassFile cf) {
    for (Main.PrintType pt : args.printTypes) {
        switch (pt) {
            case CLASS:
                String classname;
                classname =
                    cf.getThisClass().getClassType().getClassName();
                classname = classname.replace('/','.');
                System.out.println(classname);
                break;
            case INNERCLASS:
                matchInnerClassesOf.add(
                        cf.getThisClass().getClassType().getClassName());
                break;
            case METHOD:
                //TODO
                break;
            case PACKAGE:
                break;
        }
    }
}
 
Example #24
Source Project: buck   Author: facebook   File: AnnotationLister.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Inspects a class annotation.
 *
 * @param cf {@code non-null;} class file
 * @param ann {@code non-null;} annotation
 */
private void visitClassAnnotation(DirectClassFile cf,
        BaseAnnotations ann) {

    if (!args.eTypes.contains(ElementType.TYPE)) {
        return;
    }

    for (Annotation anAnn : ann.getAnnotations().getAnnotations()) {
        String annClassName
                = anAnn.getType().getClassType().getClassName();
        if (args.aclass.equals(annClassName)) {
            printMatch(cf);
        }
    }
}
 
Example #25
Source Project: Box   Author: lulululbj   File: AttributeTranslator.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Gets the annotations out of a given class, similar to {@link
 * #getAnnotations}, also including annotations for translations
 * of class-level attributes {@code EnclosingMethod} and
 * {@code InnerClasses}, if present. Additionally, if the
 * class is an annotation class, then this also includes a
 * representation of all the {@code AnnotationDefault}
 * values.
 *
 * @param cf {@code non-null;} the class in question
 * @param args {@code non-null;} the high-level options
 * @return {@code non-null;} the set of annotations, which may be empty
 */
public static Annotations getClassAnnotations(DirectClassFile cf,
        CfOptions args) {
    CstType thisClass = cf.getThisClass();
    AttributeList attribs = cf.getAttributes();
    Annotations result = getAnnotations(attribs);
    Annotation enclosingMethod = translateEnclosingMethod(attribs);

    try {
        Annotations innerClassAnnotations =
            translateInnerClasses(thisClass, attribs,
                    enclosingMethod == null);
        if (innerClassAnnotations != null) {
            result = Annotations.combine(result, innerClassAnnotations);
        }
    } catch (Warning warn) {
        args.warn.println("warning: " + warn.getMessage());
    }

    if (enclosingMethod != null) {
        result = Annotations.combine(result, enclosingMethod);
    }

    if (AccessFlags.isAnnotation(cf.getAccessFlags())) {
        Annotation annotationDefault =
            translateAnnotationDefaults(cf);
        if (annotationDefault != null) {
            result = Annotations.combine(result, annotationDefault);
        }
    }

    return result;
}
 
Example #26
Source Project: Box   Author: lulululbj   File: AttributeTranslator.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Gets the {@code AnnotationDefault} attributes out of a
 * given class, if any, reforming them as an
 * {@code AnnotationDefault} annotation.
 *
 * @param cf {@code non-null;} the class in question
 * @return {@code null-ok;} an appropriately-constructed
 * {@code AnnotationDefault} annotation, if there were any
 * annotation defaults in the class, or {@code null} if not
 */
private static Annotation translateAnnotationDefaults(DirectClassFile cf) {
    CstType thisClass = cf.getThisClass();
    MethodList methods = cf.getMethods();
    int sz = methods.size();
    Annotation result =
        new Annotation(thisClass, AnnotationVisibility.EMBEDDED);
    boolean any = false;

    for (int i = 0; i < sz; i++) {
        Method one = methods.get(i);
        AttributeList attribs = one.getAttributes();
        AttAnnotationDefault oneDefault = (AttAnnotationDefault)
            attribs.findFirst(AttAnnotationDefault.ATTRIBUTE_NAME);

        if (oneDefault != null) {
            NameValuePair pair = new NameValuePair(
                    one.getNat().getName(),
                    oneDefault.getValue());
            result.add(pair);
            any = true;
        }
    }

    if (! any) {
        return null;
    }

    result.setImmutable();
    return AnnotationUtils.makeAnnotationDefault(result);
}
 
Example #27
Source Project: buck   Author: facebook   File: MainDexListBuilder.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Keep classes annotated with runtime annotations.
 */
private void keepAnnotated(Path path) throws FileNotFoundException {
    for (ClassPathElement element : path.getElements()) {
        forClazz:
            for (String name : element.list()) {
                if (name.endsWith(CLASS_EXTENSION)) {
                    DirectClassFile clazz = path.getClass(name);
                    if (hasRuntimeVisibleAnnotation(clazz)) {
                        filesToKeep.add(name);
                    } else {
                        MethodList methods = clazz.getMethods();
                        for (int i = 0; i<methods.size(); i++) {
                            if (hasRuntimeVisibleAnnotation(methods.get(i))) {
                                filesToKeep.add(name);
                                continue forClazz;
                            }
                        }
                        FieldList fields = clazz.getFields();
                        for (int i = 0; i<fields.size(); i++) {
                            if (hasRuntimeVisibleAnnotation(fields.get(i))) {
                                filesToKeep.add(name);
                                continue forClazz;
                            }
                        }
                    }
                }
            }
    }
}
 
Example #28
Source Project: Box   Author: lulululbj   File: Main.java    License: Apache License 2.0 5 votes vote down vote up
private DirectClassFile parseClass(String name, byte[] bytes) {

        DirectClassFile cf = new DirectClassFile(bytes, name,
                args.cfOptions.strictNameCheck);
        cf.setAttributeFactory(StdAttributeFactory.THE_ONE);
        cf.getMagic(); // triggers the actual parsing
        return cf;
    }
 
Example #29
Source Project: Box   Author: lulululbj   File: Main.java    License: Apache License 2.0 5 votes vote down vote up
private ClassDefItem translateClass(byte[] bytes, DirectClassFile cf) {
    try {
        return CfTranslator.translate(context, cf, bytes, args.cfOptions,
                args.dexOptions, outputDex);
    } catch (ParseException ex) {
        context.err.println("\ntrouble processing:");
        if (args.debug) {
            ex.printStackTrace(context.err);
        } else {
            ex.printContext(context.err);
        }
    }
    errors.incrementAndGet();
    return null;
}
 
Example #30
Source Project: buck   Author: facebook   File: AnnotationLister.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Inspects a package annotation
 *
 * @param cf {@code non-null;} class file of "package-info" pseudo-class
 * @param ann {@code non-null;} annotation
 */
private void visitPackageAnnotation(
        DirectClassFile cf, BaseAnnotations ann) {

    if (!args.eTypes.contains(ElementType.PACKAGE)) {
        return;
    }

    String packageName = cf.getThisClass().getClassType().getClassName();

    int slashIndex = packageName.lastIndexOf('/');

    if (slashIndex == -1) {
        packageName = "";
    } else {
        packageName
                = packageName.substring(0, slashIndex);
    }


    for (Annotation anAnn : ann.getAnnotations().getAnnotations()) {
        String annClassName
                = anAnn.getType().getClassType().getClassName();
        if (args.aclass.equals(annClassName)) {
            printMatchPackage(packageName);
        }
    }
}