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

Method CheckInterClassDefItem

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

Source from the content-addressed store, hash-verified

2249}
2250
2251bool DexFileVerifier::CheckInterClassDefItem() {
2252 const DexFile::ClassDef* item = reinterpret_cast<const DexFile::ClassDef*>(ptr_);
2253
2254 // Check that class_idx_ is representable as a uint16_t;
2255 if (UNLIKELY(!IsValidTypeId(item->class_idx_.index_, item->pad1_))) {
2256 ErrorStringPrintf("class with type idx outside uint16_t range '%x:%x'", item->pad1_,
2257 item->class_idx_.index_);
2258 return false;
2259 }
2260 // Check that superclass_idx_ is representable as a uint16_t;
2261 if (UNLIKELY(!IsValidOrNoTypeId(item->superclass_idx_.index_, item->pad2_))) {
2262 ErrorStringPrintf("class with superclass type idx outside uint16_t range '%x:%x'", item->pad2_,
2263 item->superclass_idx_.index_);
2264 return false;
2265 }
2266 // Check for duplicate class def.
2267 if (defined_classes_.find(item->class_idx_) != defined_classes_.end()) {
2268 ErrorStringPrintf("Redefinition of class with type idx: '%d'", item->class_idx_.index_);
2269 return false;
2270 }
2271 defined_classes_.insert(item->class_idx_);
2272
2273 LOAD_STRING_BY_TYPE(class_descriptor, item->class_idx_, "inter_class_def_item class_idx")
2274 if (UNLIKELY(!IsValidDescriptor(class_descriptor) || class_descriptor[0] != 'L')) {
2275 ErrorStringPrintf("Invalid class descriptor: '%s'", class_descriptor);
2276 return false;
2277 }
2278
2279 // Only allow non-runtime modifiers.
2280 if ((item->access_flags_ & ~kAccJavaFlagsMask) != 0) {
2281 ErrorStringPrintf("Invalid class flags: '%d'", item->access_flags_);
2282 return false;
2283 }
2284
2285 if (item->interfaces_off_ != 0 &&
2286 !CheckOffsetToTypeMap(item->interfaces_off_, DexFile::kDexTypeTypeList)) {
2287 return false;
2288 }
2289 if (item->annotations_off_ != 0 &&
2290 !CheckOffsetToTypeMap(item->annotations_off_, DexFile::kDexTypeAnnotationsDirectoryItem)) {
2291 return false;
2292 }
2293 if (item->class_data_off_ != 0 &&
2294 !CheckOffsetToTypeMap(item->class_data_off_, DexFile::kDexTypeClassDataItem)) {
2295 return false;
2296 }
2297 if (item->static_values_off_ != 0 &&
2298 !CheckOffsetToTypeMap(item->static_values_off_, DexFile::kDexTypeEncodedArrayItem)) {
2299 return false;
2300 }
2301
2302 if (item->superclass_idx_.IsValid()) {
2303 if (header_->GetVersion() >= DexFile::kClassDefinitionOrderEnforcedVersion) {
2304 // Check that a class does not inherit from itself directly (by having
2305 // the same type idx as its super class).
2306 if (UNLIKELY(item->superclass_idx_ == item->class_idx_)) {
2307 ErrorStringPrintf("Class with same type idx as its superclass: '%d'",
2308 item->class_idx_.index_);

Callers

nothing calls this directly

Calls 14

IsValidTypeIdFunction · 0.85
IsValidOrNoTypeIdFunction · 0.85
IsValidDescriptorFunction · 0.85
TypeIndexClass · 0.85
IsAlignedParamFunction · 0.85
GetVersionMethod · 0.80
FindClassDefMethod · 0.80
GetInterfacesListMethod · 0.80
StringByTypeIdxMethod · 0.80
findMethod · 0.45
endMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected