本文整理汇总了Java中org.jf.dexlib2.dexbacked.raw.HeaderItem类的典型用法代码示例。如果您正苦于以下问题:Java HeaderItem类的具体用法?Java HeaderItem怎么用?Java HeaderItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HeaderItem类属于org.jf.dexlib2.dexbacked.raw包,在下文中一共展示了HeaderItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DexBackedDexFile
import org.jf.dexlib2.dexbacked.raw.HeaderItem; //导入依赖的package包/类
private DexBackedDexFile(Opcodes opcodes, @Nonnull byte[] buf, int offset, boolean verifyMagic) {
super(buf);
this.type = DexFileDataType.FILETYPE;
this.opcodes = opcodes;
if (verifyMagic) {
verifyMagicAndByteOrder(buf, offset);
}
stringCount = readSmallUint(HeaderItem.STRING_COUNT_OFFSET);
stringStartOffset = readSmallUint(HeaderItem.STRING_START_OFFSET);
typeCount = readSmallUint(HeaderItem.TYPE_COUNT_OFFSET);
typeStartOffset = readSmallUint(HeaderItem.TYPE_START_OFFSET);
protoCount = readSmallUint(HeaderItem.PROTO_COUNT_OFFSET);
protoStartOffset = readSmallUint(HeaderItem.PROTO_START_OFFSET);
fieldCount = readSmallUint(HeaderItem.FIELD_COUNT_OFFSET);
fieldStartOffset = readSmallUint(HeaderItem.FIELD_START_OFFSET);
methodCount = readSmallUint(HeaderItem.METHOD_COUNT_OFFSET);
methodStartOffset = readSmallUint(HeaderItem.METHOD_START_OFFSET);
classCount = readSmallUint(HeaderItem.CLASS_COUNT_OFFSET);
classStartOffset = readSmallUint(HeaderItem.CLASS_START_OFFSET);
}
示例2: verifyMagicAndByteOrder
import org.jf.dexlib2.dexbacked.raw.HeaderItem; //导入依赖的package包/类
private static void verifyMagicAndByteOrder(@Nonnull byte[] buf, int offset) {
if (!HeaderItem.verifyMagic(buf, offset)) {
StringBuilder sb = new StringBuilder("Invalid magic value:");
for (int i=0; i<8; i++) {
sb.append(String.format(" %02x", buf[i]));
}
throw new NotADexFile(sb.toString());
}
int endian = HeaderItem.getEndian(buf, offset);
if (endian == HeaderItem.BIG_ENDIAN_TAG) {
throw new ExceptionWithContext("Big endian dex files are not currently supported");
}
if (endian != HeaderItem.LITTLE_ENDIAN_TAG) {
throw new ExceptionWithContext("Invalid endian tag: 0x%x", endian);
}
}
示例3: verifyDexHeader
import org.jf.dexlib2.dexbacked.raw.HeaderItem; //导入依赖的package包/类
/**
* Verifies that the dex header is valid and a supported version
*
* @param buf A byte array containing at least the first 44 bytes of a dex file
* @param offset The offset within the array to the dex header
* @throws NotADexFile If the file is not a dex file
* @throws InvalidFile If the header appears to be a dex file, but is not valid for some reason
* @throws UnsupportedFile If the dex header is valid, but uses unsupported functionality
*/
public static void verifyDexHeader( byte[] buf, int offset) {
int dexVersion = HeaderItem.getVersion(buf, offset);
if (dexVersion == -1) {
StringBuilder sb = new StringBuilder("Not a valid dex magic value:");
for (int i=0; i<8; i++) {
sb.append(String.format(" %02x", buf[i]));
}
throw new NotADexFile(sb.toString());
}
if (!HeaderItem.isSupportedDexVersion(dexVersion)) {
throw new UnsupportedFile(String.format("Dex version %03d is not supported", dexVersion));
}
int endian = HeaderItem.getEndian(buf, offset);
if (endian == HeaderItem.BIG_ENDIAN_TAG) {
throw new UnsupportedFile("Big endian dex files are not supported");
}
if (endian != HeaderItem.LITTLE_ENDIAN_TAG) {
throw new InvalidFile(String.format("Invalid endian tag: 0x%x", endian));
}
}
示例4: DexBackedDexFile
import org.jf.dexlib2.dexbacked.raw.HeaderItem; //导入依赖的package包/类
private DexBackedDexFile(@Nonnull Opcodes opcodes, @Nonnull byte[] buf, int offset, boolean verifyMagic) {
super(buf, offset);
this.opcodes = opcodes;
if (verifyMagic) {
verifyMagicAndByteOrder(buf, offset);
}
stringCount = readSmallUint(HeaderItem.STRING_COUNT_OFFSET);
stringStartOffset = readSmallUint(HeaderItem.STRING_START_OFFSET);
typeCount = readSmallUint(HeaderItem.TYPE_COUNT_OFFSET);
typeStartOffset = readSmallUint(HeaderItem.TYPE_START_OFFSET);
protoCount = readSmallUint(HeaderItem.PROTO_COUNT_OFFSET);
protoStartOffset = readSmallUint(HeaderItem.PROTO_START_OFFSET);
fieldCount = readSmallUint(HeaderItem.FIELD_COUNT_OFFSET);
fieldStartOffset = readSmallUint(HeaderItem.FIELD_START_OFFSET);
methodCount = readSmallUint(HeaderItem.METHOD_COUNT_OFFSET);
methodStartOffset = readSmallUint(HeaderItem.METHOD_START_OFFSET);
classCount = readSmallUint(HeaderItem.CLASS_COUNT_OFFSET);
classStartOffset = readSmallUint(HeaderItem.CLASS_START_OFFSET);
}
示例5: updateSignature
import org.jf.dexlib2.dexbacked.raw.HeaderItem; //导入依赖的package包/类
private void updateSignature(@Nonnull DexDataStore dataStore) throws IOException {
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-1");
} catch (NoSuchAlgorithmException ex) {
throw new RuntimeException(ex);
}
byte[] buffer = new byte[4 * 1024];
InputStream input = dataStore.readAt(HeaderItem.SIGNATURE_DATA_START_OFFSET);
int bytesRead = input.read(buffer);
while (bytesRead >= 0) {
md.update(buffer, 0, bytesRead);
bytesRead = input.read(buffer);
}
byte[] signature = md.digest();
if (signature.length != HeaderItem.SIGNATURE_SIZE) {
throw new RuntimeException("unexpected digest write: " + signature.length + " bytes");
}
// write signature
OutputStream output = dataStore.outputAt(HeaderItem.SIGNATURE_OFFSET);
output.write(signature);
output.close();
}
示例6: updateChecksum
import org.jf.dexlib2.dexbacked.raw.HeaderItem; //导入依赖的package包/类
private void updateChecksum(@Nonnull DexDataStore dataStore) throws IOException {
Adler32 a32 = new Adler32();
byte[] buffer = new byte[4 * 1024];
InputStream input = dataStore.readAt(HeaderItem.CHECKSUM_DATA_START_OFFSET);
int bytesRead = input.read(buffer);
while (bytesRead >= 0) {
a32.update(buffer, 0, bytesRead);
bytesRead = input.read(buffer);
}
// write checksum, utilizing logic in DexWriter to write the integer value properly
OutputStream output = dataStore.outputAt(HeaderItem.CHECKSUM_OFFSET);
DexDataWriter.writeInt(output, (int) a32.getValue());
output.close();
}
示例7: DexBackedDexFile
import org.jf.dexlib2.dexbacked.raw.HeaderItem; //导入依赖的package包/类
private DexBackedDexFile(Opcodes opcodes, @Nonnull byte[] buf, int offset, boolean verifyMagic) {
super(buf);
this.opcodes = opcodes;
if (verifyMagic) {
verifyMagicAndByteOrder(buf, offset);
}
stringCount = readSmallUint(HeaderItem.STRING_COUNT_OFFSET);
stringStartOffset = readSmallUint(HeaderItem.STRING_START_OFFSET);
typeCount = readSmallUint(HeaderItem.TYPE_COUNT_OFFSET);
typeStartOffset = readSmallUint(HeaderItem.TYPE_START_OFFSET);
protoCount = readSmallUint(HeaderItem.PROTO_COUNT_OFFSET);
protoStartOffset = readSmallUint(HeaderItem.PROTO_START_OFFSET);
fieldCount = readSmallUint(HeaderItem.FIELD_COUNT_OFFSET);
fieldStartOffset = readSmallUint(HeaderItem.FIELD_START_OFFSET);
methodCount = readSmallUint(HeaderItem.METHOD_COUNT_OFFSET);
methodStartOffset = readSmallUint(HeaderItem.METHOD_START_OFFSET);
classCount = readSmallUint(HeaderItem.CLASS_COUNT_OFFSET);
classStartOffset = readSmallUint(HeaderItem.CLASS_START_OFFSET);
}
示例8: verifyMagicAndByteOrder
import org.jf.dexlib2.dexbacked.raw.HeaderItem; //导入依赖的package包/类
private static void verifyMagicAndByteOrder(@Nonnull byte[] buf, int offset) {
if (!HeaderItem.verifyMagic(buf, offset)) {
StringBuilder sb = new StringBuilder("Invalid magic value:");
for (int i = 0; i < 8; i++) {
sb.append(String.format(" %02x", buf[i]));
}
throw new NotADexFile(sb.toString());
}
int endian = HeaderItem.getEndian(buf, offset);
if (endian == HeaderItem.BIG_ENDIAN_TAG) {
throw new ExceptionWithContext("Big endian dex files are not currently supported");
}
if (endian != HeaderItem.LITTLE_ENDIAN_TAG) {
throw new ExceptionWithContext("Invalid endian tag: 0x%x", endian);
}
}
示例9: readRawDexFile
import org.jf.dexlib2.dexbacked.raw.HeaderItem; //导入依赖的package包/类
public static DexBackedDexFile readRawDexFile(byte[] buf, int offset, Opcodes opcodes) throws IOException {
DexUtil.verifyDexHeader(buf, offset);
if (opcodes == null) {
int dexVersion = HeaderItem.getVersion(buf, offset);
opcodes = OpcodeUtils.getOpcodesFromDexVersion(dexVersion);
};
return new DexBackedDexFile(opcodes, buf, 0);
}
示例10: next
import org.jf.dexlib2.dexbacked.raw.HeaderItem; //导入依赖的package包/类
@Override public DexEntry next() {
int filenameLength = readSmallUint(offset);
offset += 4;
// TODO: what is the correct character encoding?
String filename = new String(buf, offset, filenameLength, Charset.forName("US-ASCII"));
offset += filenameLength;
offset += 4; // checksum
int dexOffset = readSmallUint(offset) + oatHeader.headerOffset;
offset += 4;
if (getOatVersion() >= 75) {
offset += 4; // offset to class offsets table
}
if (getOatVersion() >= 73) {
offset += 4; // lookup table offset
}
if (getOatVersion() < 75) {
// prior to 75, the class offsets are included here directly
int classCount = readSmallUint(dexOffset + HeaderItem.CLASS_COUNT_OFFSET);
offset += 4 * classCount;
}
index++;
return new DexEntry(filename, dexOffset);
}
示例11: getDataSectionOffset
import org.jf.dexlib2.dexbacked.raw.HeaderItem; //导入依赖的package包/类
private int getDataSectionOffset() {
return HeaderItem.ITEM_SIZE +
stringSection.getItems().size() * StringIdItem.ITEM_SIZE +
typeSection.getItems().size() * TypeIdItem.ITEM_SIZE +
protoSection.getItems().size() * ProtoIdItem.ITEM_SIZE +
fieldSection.getItems().size() * FieldIdItem.ITEM_SIZE +
methodSection.getItems().size() * MethodIdItem.ITEM_SIZE +
classSection.getItems().size() * ClassDefItem.ITEM_SIZE;
}
示例12: writeTo
import org.jf.dexlib2.dexbacked.raw.HeaderItem; //导入依赖的package包/类
public void writeTo(@Nonnull DexDataStore dest,
@Nonnull DeferredOutputStreamFactory tempFactory) throws IOException {
try {
int dataSectionOffset = getDataSectionOffset();
DexDataWriter headerWriter = outputAt(dest, 0);
DexDataWriter indexWriter = outputAt(dest, HeaderItem.ITEM_SIZE);
DexDataWriter offsetWriter = outputAt(dest, dataSectionOffset);
try {
writeStrings(indexWriter, offsetWriter);
writeTypes(indexWriter);
writeTypeLists(offsetWriter);
writeProtos(indexWriter);
writeFields(indexWriter);
writeMethods(indexWriter);
writeEncodedArrays(offsetWriter);
writeAnnotations(offsetWriter);
writeAnnotationSets(offsetWriter);
writeAnnotationSetRefs(offsetWriter);
writeAnnotationDirectories(offsetWriter);
writeDebugAndCodeItems(offsetWriter, tempFactory.makeDeferredOutputStream());
writeClasses(indexWriter, offsetWriter);
writeMapItem(offsetWriter);
writeHeader(headerWriter, dataSectionOffset, offsetWriter.getPosition());
} finally {
headerWriter.close();
indexWriter.close();
offsetWriter.close();
}
updateSignature(dest);
updateChecksum(dest);
} finally {
dest.close();
}
}
示例13: writeHeader
import org.jf.dexlib2.dexbacked.raw.HeaderItem; //导入依赖的package包/类
private void writeHeader(@Nonnull DexDataWriter writer, int dataOffset, int fileSize) throws IOException {
// always write the 035 version, there's no reason to use the 036 version for now
writer.write(HeaderItem.MAGIC_VALUES[0]);
// checksum placeholder
writer.writeInt(0);
// signature placeholder
writer.write(new byte[20]);
writer.writeInt(fileSize);
writer.writeInt(HeaderItem.ITEM_SIZE);
writer.writeInt(HeaderItem.LITTLE_ENDIAN_TAG);
// link
writer.writeInt(0);
writer.writeInt(0);
// map
writer.writeInt(mapSectionOffset);
// index sections
writeSectionInfo(writer, stringSection.getItems().size(), stringIndexSectionOffset);
writeSectionInfo(writer, typeSection.getItems().size(), typeSectionOffset);
writeSectionInfo(writer, protoSection.getItems().size(), protoSectionOffset);
writeSectionInfo(writer, fieldSection.getItems().size(), fieldSectionOffset);
writeSectionInfo(writer, methodSection.getItems().size(), methodSectionOffset);
writeSectionInfo(writer, classSection.getItems().size(), classIndexSectionOffset);
// data section
writer.writeInt(fileSize - dataOffset);
writer.writeInt(dataOffset);
}
示例14: getHighestDexVersionFromApiLevel
import org.jf.dexlib2.dexbacked.raw.HeaderItem; //导入依赖的package包/类
public static int getHighestDexVersionFromApiLevel(int apiLevel) {
return HeaderItem.getVersion(HeaderItem.getMagicForApi(apiLevel), 0);
}
示例15: getDexFiles
import org.jf.dexlib2.dexbacked.raw.HeaderItem; //导入依赖的package包/类
@Nonnull
public List<OatDexFile> getDexFiles() {
return new AbstractForwardSequentialList<OatDexFile>() {
@Override public int size() {
return oatHeader.getDexFileCount();
}
@Nonnull @Override public Iterator<OatDexFile> iterator() {
return new Iterator<OatDexFile>() {
int index = 0;
int offset = oatHeader.getDexListStart();
@Override public boolean hasNext() {
return index < size();
}
@Override public OatDexFile next() {
int filenameLength = readSmallUint(offset);
offset += 4;
// TODO: what is the correct character encoding?
String filename = new String(buf, offset, filenameLength, Charset.forName("US-ASCII"));
offset += filenameLength;
offset += 4; // checksum
int dexOffset = readSmallUint(offset) + oatHeader.offset;
offset += 4;
int classCount = readSmallUint(dexOffset + HeaderItem.CLASS_COUNT_OFFSET);
offset += 4 * classCount;
index++;
return new OatDexFile(dexOffset, filename);
}
@Override public void remove() {
throw new UnsupportedOperationException();
}
};
}
};
}