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

Method CheckHeader

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

Source from the content-addressed store, hash-verified

360}
361
362bool DexFileVerifier::CheckHeader() {
363 // Check file size from the header.
364 uint32_t expected_size = header_->file_size_;
365 if (size_ != expected_size) {
366 ErrorStringPrintf("Bad file size (%zd, expected %u)", size_, expected_size);
367 return false;
368 }
369
370 uint32_t adler_checksum = dex_file_->CalculateChecksum();
371 // Compute and verify the checksum in the header.
372 if (adler_checksum != header_->checksum_) {
373 if (verify_checksum_) {
374 ErrorStringPrintf("Bad checksum (%08x, expected %08x)", adler_checksum, header_->checksum_);
375 return false;
376 } else {
377 LOG(WARNING) << StringPrintf(
378 "Ignoring bad checksum (%08x, expected %08x)", adler_checksum, header_->checksum_);
379 }
380 }
381
382 // Check the contents of the header.
383 if (header_->endian_tag_ != DexFile::kDexEndianConstant) {
384 ErrorStringPrintf("Unexpected endian_tag: %x", header_->endian_tag_);
385 return false;
386 }
387
388 const uint32_t expected_header_size = dex_file_->IsCompactDexFile()
389 ? sizeof(CompactDexFile::Header)
390 : sizeof(StandardDexFile::Header);
391
392 if (header_->header_size_ != expected_header_size) {
393 ErrorStringPrintf("Bad header size: %ud expected %ud",
394 header_->header_size_,
395 expected_header_size);
396 return false;
397 }
398
399 // Check that all offsets are inside the file.
400 bool result =
401 CheckValidOffsetAndSize(header_->link_off_,
402 header_->link_size_,
403 0 /* unaligned */,
404 "link") &&
405 CheckValidOffsetAndSize(header_->map_off_,
406 header_->map_off_,
407 4,
408 "map") &&
409 CheckValidOffsetAndSize(header_->string_ids_off_,
410 header_->string_ids_size_,
411 4,
412 "string-ids") &&
413 CheckValidOffsetAndSize(header_->type_ids_off_,
414 header_->type_ids_size_,
415 4,
416 "type-ids") &&
417 CheckSizeLimit(header_->type_ids_size_, DexFile::kDexNoIndex16, "type-ids") &&
418 CheckValidOffsetAndSize(header_->proto_ids_off_,
419 header_->proto_ids_size_,

Callers

nothing calls this directly

Calls 3

StringPrintfFunction · 0.85
IsCompactDexFileMethod · 0.80
CalculateChecksumMethod · 0.45

Tested by

no test coverage detected