com.android.dx.cf.iface.ParseObserver Java Examples

The following examples show how to use com.android.dx.cf.iface.ParseObserver. 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 File: StdAttributeFactory.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Parses a {@code LocalVariableTable} attribute.
 */
private Attribute localVariableTable(DirectClassFile cf, int offset,
        int length, ParseObserver observer) {
    if (length < 2) {
        return throwSeverelyTruncated();
    }

    ByteArray bytes = cf.getBytes();
    int count = bytes.getUnsignedShort(offset);

    if (observer != null) {
        observer.parsed(bytes, offset, 2,
                "local_variable_table_length: " + Hex.u2(count));
    }

    LocalVariableList list = parseLocalVariables(
            bytes.slice(offset + 2, offset + length), cf.getConstantPool(),
            observer, count, false);
    return new AttLocalVariableTable(list);
}
 
Example #2
Source File: StdAttributeFactory.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Parses an {@code Exceptions} attribute.
 */
private Attribute exceptions(DirectClassFile cf, int offset, int length,
        ParseObserver observer) {
    if (length < 2) {
        return throwSeverelyTruncated();
    }

    ByteArray bytes = cf.getBytes();
    int count = bytes.getUnsignedShort(offset); // number_of_exceptions

    if (observer != null) {
        observer.parsed(bytes, offset, 2,
                        "number_of_exceptions: " + Hex.u2(count));
    }

    offset += 2;
    length -= 2;

    if (length != (count * 2)) {
        throwBadLength((count * 2) + 2);
    }

    TypeList list = cf.makeTypeList(offset, count);
    return new AttExceptions(list);
}
 
Example #3
Source File: StdAttributeFactory.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Parses a {@code SourceFile} attribute.
 */
private Attribute sourceFile(DirectClassFile cf, int offset, int length,
        ParseObserver observer) {
    if (length != 2) {
        throwBadLength(2);
    }

    ByteArray bytes = cf.getBytes();
    ConstantPool pool = cf.getConstantPool();
    int idx = bytes.getUnsignedShort(offset);
    CstString cst = (CstString) pool.get(idx);
    Attribute result = new AttSourceFile(cst);

    if (observer != null) {
        observer.parsed(bytes, offset, 2, "source: " + cst);
    }

    return result;
}
 
Example #4
Source File: StdAttributeFactory.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Parses a {@code Signature} attribute.
 */
private Attribute signature(DirectClassFile cf, int offset, int length,
        ParseObserver observer) {
    if (length != 2) {
        throwBadLength(2);
    }

    ByteArray bytes = cf.getBytes();
    ConstantPool pool = cf.getConstantPool();
    int idx = bytes.getUnsignedShort(offset);
    CstString cst = (CstString) pool.get(idx);
    Attribute result = new AttSignature(cst);

    if (observer != null) {
        observer.parsed(bytes, offset, 2, "signature: " + cst);
    }

    return result;
}
 
Example #5
Source File: StdAttributeFactory.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Parses a {@code ConstantValue} attribute.
 */
private Attribute constantValue(DirectClassFile cf, int offset, int length,
        ParseObserver observer) {
    if (length != 2) {
        return throwBadLength(2);
    }

    ByteArray bytes = cf.getBytes();
    ConstantPool pool = cf.getConstantPool();
    int idx = bytes.getUnsignedShort(offset);
    TypedConstant cst = (TypedConstant) pool.get(idx);
    Attribute result = new AttConstantValue(cst);

    if (observer != null) {
        observer.parsed(bytes, offset, 2, "value: " + cst);
    }

    return result;
}
 
Example #6
Source File: StdAttributeFactory.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Parses a {@code ConstantValue} attribute.
 */
private Attribute constantValue(DirectClassFile cf, int offset, int length,
        ParseObserver observer) {
    if (length != 2) {
        return throwBadLength(2);
    }

    ByteArray bytes = cf.getBytes();
    ConstantPool pool = cf.getConstantPool();
    int idx = bytes.getUnsignedShort(offset);
    TypedConstant cst = (TypedConstant) pool.get(idx);
    Attribute result = new AttConstantValue(cst);

    if (observer != null) {
        observer.parsed(bytes, offset, 2, "value: " + cst);
    }

    return result;
}
 
Example #7
Source File: StdAttributeFactory.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Parses a {@code BootstrapMethods} attribute.
 */
private Attribute bootstrapMethods(DirectClassFile cf, int offset, int length,
        ParseObserver observer) {
    if (length < 2) {
        return throwSeverelyTruncated();
    }

    ByteArray bytes = cf.getBytes();
    int numMethods = bytes.getUnsignedShort(offset);
    if (observer != null) {
        observer.parsed(bytes, offset, 2,
                        "num_boostrap_methods: " + Hex.u2(numMethods));
    }

    offset += 2;
    length -= 2;

    BootstrapMethodsList methods = parseBootstrapMethods(bytes, cf.getConstantPool(),
                                                         cf.getThisClass(), numMethods,
                                                         offset, length, observer);
    return new AttBootstrapMethods(methods);
}
 
Example #8
Source File: StdAttributeFactory.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Parses an {@code Exceptions} attribute.
 */
private Attribute exceptions(DirectClassFile cf, int offset, int length,
        ParseObserver observer) {
    if (length < 2) {
        return throwSeverelyTruncated();
    }

    ByteArray bytes = cf.getBytes();
    int count = bytes.getUnsignedShort(offset); // number_of_exceptions

    if (observer != null) {
        observer.parsed(bytes, offset, 2,
                        "number_of_exceptions: " + Hex.u2(count));
    }

    offset += 2;
    length -= 2;

    if (length != (count * 2)) {
        throwBadLength((count * 2) + 2);
    }

    TypeList list = cf.makeTypeList(offset, count);
    return new AttExceptions(list);
}
 
Example #9
Source File: StdAttributeFactory.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Parses a {@code LocalVariableTable} attribute.
 */
private Attribute localVariableTable(DirectClassFile cf, int offset,
        int length, ParseObserver observer) {
    if (length < 2) {
        return throwSeverelyTruncated();
    }

    ByteArray bytes = cf.getBytes();
    int count = bytes.getUnsignedShort(offset);

    if (observer != null) {
        observer.parsed(bytes, offset, 2,
                "local_variable_table_length: " + Hex.u2(count));
    }

    LocalVariableList list = parseLocalVariables(
            bytes.slice(offset + 2, offset + length), cf.getConstantPool(),
            observer, count, false);
    return new AttLocalVariableTable(list);
}
 
Example #10
Source File: StdAttributeFactory.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Parses a {@code LocalVariableTypeTable} attribute.
 */
private Attribute localVariableTypeTable(DirectClassFile cf, int offset,
        int length, ParseObserver observer) {
    if (length < 2) {
        return throwSeverelyTruncated();
    }

    ByteArray bytes = cf.getBytes();
    int count = bytes.getUnsignedShort(offset);

    if (observer != null) {
        observer.parsed(bytes, offset, 2,
                "local_variable_type_table_length: " + Hex.u2(count));
    }

    LocalVariableList list = parseLocalVariables(
            bytes.slice(offset + 2, offset + length), cf.getConstantPool(),
            observer, count, true);
    return new AttLocalVariableTypeTable(list);
}
 
Example #11
Source File: StdAttributeFactory.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Parses an {@code EnclosingMethod} attribute.
 */
private Attribute enclosingMethod(DirectClassFile cf, int offset,
        int length, ParseObserver observer) {
    if (length != 4) {
        throwBadLength(4);
    }

    ByteArray bytes = cf.getBytes();
    ConstantPool pool = cf.getConstantPool();

    int idx = bytes.getUnsignedShort(offset);
    CstType type = (CstType) pool.get(idx);

    idx = bytes.getUnsignedShort(offset + 2);
    CstNat method = (CstNat) pool.get0Ok(idx);

    Attribute result = new AttEnclosingMethod(type, method);

    if (observer != null) {
        observer.parsed(bytes, offset, 2, "class: " + type);
        observer.parsed(bytes, offset + 2, 2, "method: " +
                        DirectClassFile.stringOrNone(method));
    }

    return result;
}
 
Example #12
Source File: StdAttributeFactory.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Parses a {@code ConstantValue} attribute.
 */
private Attribute constantValue(DirectClassFile cf, int offset, int length,
        ParseObserver observer) {
    if (length != 2) {
        return throwBadLength(2);
    }

    ByteArray bytes = cf.getBytes();
    ConstantPool pool = cf.getConstantPool();
    int idx = bytes.getUnsignedShort(offset);
    TypedConstant cst = (TypedConstant) pool.get(idx);
    Attribute result = new AttConstantValue(cst);

    if (observer != null) {
        observer.parsed(bytes, offset, 2, "value: " + cst);
    }

    return result;
}
 
Example #13
Source File: StdAttributeFactory.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Parses a {@code Signature} attribute.
 */
private Attribute signature(DirectClassFile cf, int offset, int length,
        ParseObserver observer) {
    if (length != 2) {
        throwBadLength(2);
    }

    ByteArray bytes = cf.getBytes();
    ConstantPool pool = cf.getConstantPool();
    int idx = bytes.getUnsignedShort(offset);
    CstString cst = (CstString) pool.get(idx);
    Attribute result = new AttSignature(cst);

    if (observer != null) {
        observer.parsed(bytes, offset, 2, "signature: " + cst);
    }

    return result;
}
 
Example #14
Source File: StdAttributeFactory.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Parses a {@code Signature} attribute.
 */
private Attribute signature(DirectClassFile cf, int offset, int length,
        ParseObserver observer) {
    if (length != 2) {
        throwBadLength(2);
    }

    ByteArray bytes = cf.getBytes();
    ConstantPool pool = cf.getConstantPool();
    int idx = bytes.getUnsignedShort(offset);
    CstString cst = (CstString) pool.get(idx);
    Attribute result = new AttSignature(cst);

    if (observer != null) {
        observer.parsed(bytes, offset, 2, "signature: " + cst);
    }

    return result;
}
 
Example #15
Source File: StdAttributeFactory.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Parses a {@code ConstantValue} attribute.
 */
private Attribute constantValue(DirectClassFile cf, int offset, int length,
        ParseObserver observer) {
    if (length != 2) {
        return throwBadLength(2);
    }

    ByteArray bytes = cf.getBytes();
    ConstantPool pool = cf.getConstantPool();
    int idx = bytes.getUnsignedShort(offset);
    TypedConstant cst = (TypedConstant) pool.get(idx);
    Attribute result = new AttConstantValue(cst);

    if (observer != null) {
        observer.parsed(bytes, offset, 2, "value: " + cst);
    }

    return result;
}
 
Example #16
Source File: StdAttributeFactory.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Parses an {@code EnclosingMethod} attribute.
 */
private Attribute enclosingMethod(DirectClassFile cf, int offset,
        int length, ParseObserver observer) {
    if (length != 4) {
        throwBadLength(4);
    }

    ByteArray bytes = cf.getBytes();
    ConstantPool pool = cf.getConstantPool();

    int idx = bytes.getUnsignedShort(offset);
    CstType type = (CstType) pool.get(idx);

    idx = bytes.getUnsignedShort(offset + 2);
    CstNat method = (CstNat) pool.get0Ok(idx);

    Attribute result = new AttEnclosingMethod(type, method);

    if (observer != null) {
        observer.parsed(bytes, offset, 2, "class: " + type);
        observer.parsed(bytes, offset + 2, 2, "method: " +
                        DirectClassFile.stringOrNone(method));
    }

    return result;
}
 
Example #17
Source File: StdAttributeFactory.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Parses a {@code LocalVariableTable} attribute.
 */
private Attribute localVariableTable(DirectClassFile cf, int offset,
        int length, ParseObserver observer) {
    if (length < 2) {
        return throwSeverelyTruncated();
    }

    ByteArray bytes = cf.getBytes();
    int count = bytes.getUnsignedShort(offset);

    if (observer != null) {
        observer.parsed(bytes, offset, 2,
                "local_variable_table_length: " + Hex.u2(count));
    }

    LocalVariableList list = parseLocalVariables(
            bytes.slice(offset + 2, offset + length), cf.getConstantPool(),
            observer, count, false);
    return new AttLocalVariableTable(list);
}
 
Example #18
Source File: StdAttributeFactory.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Parses a {@code LocalVariableTypeTable} attribute.
 */
private Attribute localVariableTypeTable(DirectClassFile cf, int offset,
        int length, ParseObserver observer) {
    if (length < 2) {
        return throwSeverelyTruncated();
    }

    ByteArray bytes = cf.getBytes();
    int count = bytes.getUnsignedShort(offset);

    if (observer != null) {
        observer.parsed(bytes, offset, 2,
                "local_variable_type_table_length: " + Hex.u2(count));
    }

    LocalVariableList list = parseLocalVariables(
            bytes.slice(offset + 2, offset + length), cf.getConstantPool(),
            observer, count, true);
    return new AttLocalVariableTypeTable(list);
}
 
Example #19
Source File: StdAttributeFactory.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Parses a {@code LocalVariableTable} attribute.
 */
private Attribute localVariableTable(DirectClassFile cf, int offset,
        int length, ParseObserver observer) {
    if (length < 2) {
        return throwSeverelyTruncated();
    }

    ByteArray bytes = cf.getBytes();
    int count = bytes.getUnsignedShort(offset);

    if (observer != null) {
        observer.parsed(bytes, offset, 2,
                "local_variable_table_length: " + Hex.u2(count));
    }

    LocalVariableList list = parseLocalVariables(
            bytes.slice(offset + 2, offset + length), cf.getConstantPool(),
            observer, count, false);
    return new AttLocalVariableTable(list);
}
 
Example #20
Source File: StdAttributeFactory.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Parses a {@code Signature} attribute.
 */
private Attribute signature(DirectClassFile cf, int offset, int length,
        ParseObserver observer) {
    if (length != 2) {
        throwBadLength(2);
    }

    ByteArray bytes = cf.getBytes();
    ConstantPool pool = cf.getConstantPool();
    int idx = bytes.getUnsignedShort(offset);
    CstString cst = (CstString) pool.get(idx);
    Attribute result = new AttSignature(cst);

    if (observer != null) {
        observer.parsed(bytes, offset, 2, "signature: " + cst);
    }

    return result;
}
 
Example #21
Source File: StdAttributeFactory.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Parses a {@code RuntimeVisibleParameterAnnotations} attribute.
 */
private Attribute runtimeVisibleParameterAnnotations(DirectClassFile cf,
        int offset, int length, ParseObserver observer) {
    if (length < 2) {
        throwSeverelyTruncated();
    }

    AnnotationParser ap =
        new AnnotationParser(cf, offset, length, observer);
    AnnotationsList list =
        ap.parseParameterAttribute(AnnotationVisibility.RUNTIME);

    return new AttRuntimeVisibleParameterAnnotations(list, length);
}
 
Example #22
Source File: StdAttributeFactory.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Parses a {@code Synthetic} attribute.
 */
private Attribute synthetic(DirectClassFile cf, int offset, int length,
        ParseObserver observer) {
    if (length != 0) {
        return throwBadLength(0);
    }

    return new AttSynthetic();
}
 
Example #23
Source File: AnnotationParser.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param cf {@code non-null;} class file to parse from
 * @param offset {@code >= 0;} offset into the class file data to parse at
 * @param length {@code >= 0;} number of bytes left in the attribute data
 * @param observer {@code null-ok;} parse observer to notify, if any
 */
public AnnotationParser(DirectClassFile cf, int offset, int length,
        ParseObserver observer) {
    if (cf == null) {
        throw new NullPointerException("cf == null");
    }

    this.cf = cf;
    this.pool = cf.getConstantPool();
    this.observer = observer;
    this.bytes = cf.getBytes().slice(offset, offset + length);
    this.input = bytes.makeDataInputStream();
    this.parseCursor = 0;
}
 
Example #24
Source File: StdAttributeFactory.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Parses a {@code RuntimeVisibleAnnotations} attribute.
 */
private Attribute runtimeVisibleAnnotations(DirectClassFile cf,
        int offset, int length, ParseObserver observer) {
    if (length < 2) {
        throwSeverelyTruncated();
    }

    AnnotationParser ap =
        new AnnotationParser(cf, offset, length, observer);
    Annotations annotations =
        ap.parseAnnotationAttribute(AnnotationVisibility.RUNTIME);

    return new AttRuntimeVisibleAnnotations(annotations, length);
}
 
Example #25
Source File: StdAttributeFactory.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Parses a {@code RuntimeInvisibleParameterAnnotations} attribute.
 */
private Attribute runtimeInvisibleParameterAnnotations(DirectClassFile cf,
        int offset, int length, ParseObserver observer) {
    if (length < 2) {
        throwSeverelyTruncated();
    }

    AnnotationParser ap =
        new AnnotationParser(cf, offset, length, observer);
    AnnotationsList list =
        ap.parseParameterAttribute(AnnotationVisibility.BUILD);

    return new AttRuntimeInvisibleParameterAnnotations(list, length);
}
 
Example #26
Source File: StdAttributeFactory.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Parses a {@code RuntimeVisibleParameterAnnotations} attribute.
 */
private Attribute runtimeVisibleParameterAnnotations(DirectClassFile cf,
        int offset, int length, ParseObserver observer) {
    if (length < 2) {
        throwSeverelyTruncated();
    }

    AnnotationParser ap =
        new AnnotationParser(cf, offset, length, observer);
    AnnotationsList list =
        ap.parseParameterAttribute(AnnotationVisibility.RUNTIME);

    return new AttRuntimeVisibleParameterAnnotations(list, length);
}
 
Example #27
Source File: StdAttributeFactory.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Parses a {@code SourceDebugExtesion} attribute.
 */
private Attribute sourceDebugExtension(DirectClassFile cf, int offset, int length,
                                       ParseObserver observer) {
    ByteArray bytes = cf.getBytes().slice(offset, offset + length);
    CstString smapString = new CstString(bytes);
    Attribute result = new AttSourceDebugExtension(smapString);

    if (observer != null) {
        String decoded = smapString.getString();
        observer.parsed(bytes, offset, length, "sourceDebugExtension: " + decoded);
    }

    return result;
}
 
Example #28
Source File: StdAttributeFactory.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Parses a {@code SourceDebugExtesion} attribute.
 */
private Attribute sourceDebugExtension(DirectClassFile cf, int offset, int length,
                                       ParseObserver observer) {
    ByteArray bytes = cf.getBytes().slice(offset, offset + length);
    CstString smapString = new CstString(bytes);
    Attribute result = new AttSourceDebugExtension(smapString);

    if (observer != null) {
        String decoded = smapString.getString();
        observer.parsed(bytes, offset, length, "sourceDebugExtension: " + decoded);
    }

    return result;
}
 
Example #29
Source File: StdAttributeFactory.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Parses a {@code RuntimeInvisibleAnnotations} attribute.
 */
private Attribute runtimeInvisibleAnnotations(DirectClassFile cf,
        int offset, int length, ParseObserver observer) {
    if (length < 2) {
        throwSeverelyTruncated();
    }

    AnnotationParser ap =
        new AnnotationParser(cf, offset, length, observer);
    Annotations annotations =
        ap.parseAnnotationAttribute(AnnotationVisibility.BUILD);

    return new AttRuntimeInvisibleAnnotations(annotations, length);
}
 
Example #30
Source File: StdAttributeFactory.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Parses a {@code RuntimeInvisibleAnnotations} attribute.
 */
private Attribute runtimeInvisibleAnnotations(DirectClassFile cf,
        int offset, int length, ParseObserver observer) {
    if (length < 2) {
        throwSeverelyTruncated();
    }

    AnnotationParser ap =
        new AnnotationParser(cf, offset, length, observer);
    Annotations annotations =
        ap.parseAnnotationAttribute(AnnotationVisibility.BUILD);

    return new AttRuntimeInvisibleAnnotations(annotations, length);
}