MCPcopy Create free account
hub / github.com/CodingGay/BlackDex / CheckIntraSection

Method CheckIntraSection

Bcore/src/main/cpp/dex/dex_file_verifier.cc:1870–1961  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1868}
1869
1870bool DexFileVerifier::CheckIntraSection() {
1871 const DexFile::MapList* map = reinterpret_cast<const DexFile::MapList*>(begin_ + header_->map_off_);
1872 const DexFile::MapItem* item = map->list_;
1873 size_t offset = 0;
1874 uint32_t count = map->size_;
1875 ptr_ = begin_;
1876
1877 // Check the items listed in the map.
1878 while (count--) {
1879 const size_t current_offset = offset;
1880 uint32_t section_offset = item->offset_;
1881 uint32_t section_count = item->size_;
1882 DexFile::MapItemType type = static_cast<DexFile::MapItemType>(item->type_);
1883
1884 // Check for padding and overlap between items.
1885 if (!CheckPadding(offset, section_offset, type)) {
1886 return false;
1887 } else if (UNLIKELY(offset > section_offset)) {
1888 ErrorStringPrintf("Section overlap or out-of-order map: %zx, %x", offset, section_offset);
1889 return false;
1890 }
1891
1892 // Check each item based on its type.
1893 switch (type) {
1894 case DexFile::kDexTypeHeaderItem:
1895 if (UNLIKELY(section_count != 1)) {
1896 ErrorStringPrintf("Multiple header items");
1897 return false;
1898 }
1899 if (UNLIKELY(section_offset != 0)) {
1900 ErrorStringPrintf("Header at %x, not at start of file", section_offset);
1901 return false;
1902 }
1903 ptr_ = begin_ + header_->header_size_;
1904 offset = header_->header_size_;
1905 break;
1906 case DexFile::kDexTypeStringIdItem:
1907 case DexFile::kDexTypeTypeIdItem:
1908 case DexFile::kDexTypeProtoIdItem:
1909 case DexFile::kDexTypeFieldIdItem:
1910 case DexFile::kDexTypeMethodIdItem:
1911 case DexFile::kDexTypeClassDefItem:
1912 if (!CheckIntraIdSection(section_offset, section_count, type)) {
1913 return false;
1914 }
1915 offset = ptr_ - begin_;
1916 break;
1917 case DexFile::kDexTypeMapList:
1918 if (UNLIKELY(section_count != 1)) {
1919 ErrorStringPrintf("Multiple map list items");
1920 return false;
1921 }
1922 if (UNLIKELY(section_offset != header_->map_off_)) {
1923 ErrorStringPrintf("Map not at header-defined offset: %x, expected %x",
1924 section_offset, header_->map_off_);
1925 return false;
1926 }
1927 ptr_ += sizeof(uint32_t) + (map->size_ * sizeof(DexFile::MapItem));

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected