@Nonnull public String getString(int index) { if (index >= size) { throw new InvalidOatFileException("String index is out of bounds"); } int start = offset + index; int end = start; while (buf[end] != 0) { end++; if (end >= offset + size) { throw new InvalidOatFileException("String extends past end of string table"); } } return new String(buf, start, end-start, Charset.forName("US-ASCII")); } }
@Nonnull public String getString(int index) { if (index >= size) { throw new InvalidOatFileException("String index is out of bounds"); } int start = offset + index; int end = start; while (buf[end] != 0) { end++; if (end >= offset + size) { throw new InvalidOatFileException("String extends past end of string table"); } } return new String(buf, start, end-start, Charset.forName("US-ASCII")); } }
@Nullable public String getKeyValue(@Nonnull String key) { int size = getKeyValueStoreSize(); int offset = headerOffset + keyValueStoreOffset; int endOffset = offset + size; while (offset < endOffset) { int keyStartOffset = offset; while (offset < endOffset && buf[offset] != '\0') { offset++; } if (offset >= endOffset) { throw new InvalidOatFileException("Oat file contains truncated key value store"); } int keyEndOffset = offset; String k = new String(buf, keyStartOffset, keyEndOffset - keyStartOffset); if (k.equals(key)) { int valueStartOffset = ++offset; while (offset < endOffset && buf[offset] != '\0') { offset++; } if (offset >= endOffset) { throw new InvalidOatFileException("Oat file contains truncated key value store"); } int valueEndOffset = offset; return new String(buf, valueStartOffset, valueEndOffset - valueStartOffset); } offset++; } return null; }
throw new InvalidOatFileException("The ELF section headers extend past the end of the file");
throw new InvalidOatFileException("The ELF section headers extend past the end of the file");
@Nullable public String getKeyValue(@Nonnull String key) { int size = getKeyValueStoreSize(); int offset = headerOffset + keyValueStoreOffset; int endOffset = offset + size; while (offset < endOffset) { int keyStartOffset = offset; while (offset < endOffset && buf[offset] != '\0') { offset++; } if (offset >= endOffset) { throw new InvalidOatFileException("Oat file contains truncated key value store"); } int keyEndOffset = offset; String k = new String(buf, keyStartOffset, keyEndOffset - keyStartOffset); if (k.equals(key)) { int valueStartOffset = ++offset; while (offset < endOffset && buf[offset] != '\0') { offset++; } if (offset >= endOffset) { throw new InvalidOatFileException("Oat file contains truncated key value store"); } int valueEndOffset = offset; return new String(buf, valueStartOffset, valueEndOffset - valueStartOffset); } offset++; } return null; }
is64bit = true; } else { throw new InvalidOatFileException(String.format("Invalid word-size value: %x", buf[5])); throw new InvalidOatFileException("Oat file has no oatdata symbol"); throw new InvalidOatFileException("Invalid oat magic value");
is64bit = true; } else { throw new InvalidOatFileException(String.format("Invalid word-size value: %x", buf[5])); throw new InvalidOatFileException("Oat file has no oatdata symbol"); throw new InvalidOatFileException("Invalid oat magic value");
public int getFileOffset() { SectionHeader sectionHeader; try { sectionHeader = getSections().get(getSectionIndex()); } catch (IndexOutOfBoundsException ex) { throw new InvalidOatFileException("Section index for symbol is out of bounds"); } long sectionAddress = sectionHeader.getAddress(); int sectionOffset = sectionHeader.getOffset(); int sectionSize = sectionHeader.getSize(); long symbolAddress = getValue(); if (symbolAddress < sectionAddress || symbolAddress >= sectionAddress + sectionSize) { throw new InvalidOatFileException("symbol address lies outside it's associated section"); } long fileOffset = (sectionOffset + (getValue() - sectionAddress)); assert fileOffset <= Integer.MAX_VALUE; return (int)fileOffset; } }
public int getFileOffset() { SectionHeader sectionHeader; try { sectionHeader = getSections().get(getSectionIndex()); } catch (IndexOutOfBoundsException ex) { throw new InvalidOatFileException("Section index for symbol is out of bounds"); } long sectionAddress = sectionHeader.getAddress(); int sectionOffset = sectionHeader.getOffset(); int sectionSize = sectionHeader.getSize(); long symbolAddress = getValue(); if (symbolAddress < sectionAddress || symbolAddress >= sectionAddress + sectionSize) { throw new InvalidOatFileException("symbol address lies outside it's associated section"); } long fileOffset = (sectionOffset + (getValue() - sectionAddress)); assert fileOffset <= Integer.MAX_VALUE; return (int)fileOffset; } }
public SymbolTable(@Nonnull SectionHeader header) { try { this.stringTable = new StringTable(getSections().get(header.getLink())); } catch (IndexOutOfBoundsException ex) { throw new InvalidOatFileException("String table section index is invalid"); } this.offset = header.getOffset(); this.entrySize = header.getEntrySize(); this.entryCount = header.getSize() / entrySize; if (offset + entryCount * entrySize > buf.length) { throw new InvalidOatFileException("Symbol table extends past end of file"); } }
public StringTable(@Nonnull SectionHeader header) { this.offset = header.getOffset(); this.size = header.getSize(); if (offset + size > buf.length) { throw new InvalidOatFileException("String table extends past end of file"); } }
@Nonnull private SymbolTable getSymbolTable() { for (SectionHeader header: getSections()) { if (header.getType() == SectionHeader.TYPE_DYNAMIC_SYMBOL_TABLE) { return new SymbolTable(header); } } throw new InvalidOatFileException("Oat file has no symbol table"); }
public SymbolTable(@Nonnull SectionHeader header) { try { this.stringTable = new StringTable(getSections().get(header.getLink())); } catch (IndexOutOfBoundsException ex) { throw new InvalidOatFileException("String table section index is invalid"); } this.offset = header.getOffset(); this.entrySize = header.getEntrySize(); this.entryCount = header.getSize() / entrySize; if (offset + entryCount * entrySize > buf.length) { throw new InvalidOatFileException("Symbol table extends past end of file"); } }
@Nonnull private StringTable getSectionNameStringTable() { int index = readUshort(50); if (index == 0) { throw new InvalidOatFileException("There is no section name string table"); } try { return new StringTable(getSections().get(index)); } catch (IndexOutOfBoundsException ex) { throw new InvalidOatFileException("The section index for the section name string table is invalid"); } }
@Nonnull private SymbolTable getSymbolTable() { for (SectionHeader header: getSections()) { if (header.getType() == SectionHeader.TYPE_DYNAMIC_SYMBOL_TABLE) { return new SymbolTable(header); } } throw new InvalidOatFileException("Oat file has no symbol table"); }
@Nonnull private StringTable getSectionNameStringTable() { int index = readUshort(50); if (index == 0) { throw new InvalidOatFileException("There is no section name string table"); } try { return new StringTable(getSections().get(index)); } catch (IndexOutOfBoundsException ex) { throw new InvalidOatFileException("The section index for the section name string table is invalid"); } }
public StringTable(@Nonnull SectionHeader header) { this.offset = header.getOffset(); this.size = header.getSize(); if (offset + size > buf.length) { throw new InvalidOatFileException("String table extends past end of file"); } }