use of com.android.dx.util.ByteArray in project buck by facebook.
the class StdAttributeFactory method constantValue.
/**
* 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;
}
use of com.android.dx.util.ByteArray in project buck by facebook.
the class DotDumper method run.
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);
// Force parsing to happen.
classFile.getMagic();
// Next, reparse it and observe the process.
DirectClassFile liveCf = new DirectClassFile(ba, filePath, strictParse);
liveCf.setAttributeFactory(StdAttributeFactory.THE_ONE);
liveCf.setObserver(this);
// Force parsing to happen.
liveCf.getMagic();
}
use of com.android.dx.util.ByteArray in project buck by facebook.
the class ConstantPoolParser method parseUtf8.
/**
* Parses a utf8 constant.
*
* @param at offset to the start of the constant (where the tag byte is)
* @return {@code non-null;} the parsed value
*/
private CstString parseUtf8(int at) {
int length = bytes.getUnsignedShort(at + 1);
// Skip to the data.
at += 3;
ByteArray ubytes = bytes.slice(at, at + length);
try {
return new CstString(ubytes);
} catch (IllegalArgumentException ex) {
// Translate the exception
throw new ParseException(ex);
}
}
use of com.android.dx.util.ByteArray in project buck by facebook.
the class StringDataItem method writeTo0.
/** {@inheritDoc} */
@Override
public void writeTo0(DexFile file, AnnotatedOutput out) {
ByteArray bytes = value.getBytes();
int utf16Size = value.getUtf16Size();
if (out.annotates()) {
out.annotate(Leb128.unsignedLeb128Size(utf16Size), "utf16_size: " + Hex.u4(utf16Size));
out.annotate(bytes.size() + 1, value.toQuoted());
}
out.writeUleb128(utf16Size);
out.write(bytes);
out.writeByte(0);
}
use of com.android.dx.util.ByteArray in project J2ME-Loader by nikita36078.
the class AttributeListParser method parse.
/**
* Does the actual parsing.
*/
private void parse() {
int sz = list.size();
// Skip the count.
int at = offset + 2;
ByteArray bytes = cf.getBytes();
if (observer != null) {
observer.parsed(bytes, offset, 2, "attributes_count: " + Hex.u2(sz));
}
for (int i = 0; i < sz; i++) {
try {
if (observer != null) {
observer.parsed(bytes, at, 0, "\nattributes[" + i + "]:\n");
observer.changeIndent(1);
}
Attribute attrib = attributeFactory.parse(cf, context, at, observer);
at += attrib.byteLength();
list.set(i, attrib);
if (observer != null) {
observer.changeIndent(-1);
observer.parsed(bytes, at, 0, "end attributes[" + i + "]\n");
}
} catch (ParseException ex) {
ex.addContext("...while parsing attributes[" + i + "]");
throw ex;
} catch (RuntimeException ex) {
ParseException pe = new ParseException(ex);
pe.addContext("...while parsing attributes[" + i + "]");
throw pe;
}
}
endOffset = at;
}
Aggregations