| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/utility/safe_browsing/mac/hfs.h" | 5 #include "chrome/utility/safe_browsing/mac/hfs.h" |
| 6 | 6 |
| 7 #include <libkern/OSByteOrder.h> | 7 #include <libkern/OSByteOrder.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 | 10 |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 return leaf_records_read_ < header_.leafRecords; | 505 return leaf_records_read_ < header_.leafRecords; |
| 506 } | 506 } |
| 507 | 507 |
| 508 bool HFSBTreeIterator::Next() { | 508 bool HFSBTreeIterator::Next() { |
| 509 if (!ReadCurrentLeaf()) | 509 if (!ReadCurrentLeaf()) |
| 510 return false; | 510 return false; |
| 511 | 511 |
| 512 GetLeafData<uint16_t>(); // keyLength | 512 GetLeafData<uint16_t>(); // keyLength |
| 513 auto parent_id = OSSwapBigToHostInt32(*GetLeafData<uint32_t>()); | 513 auto parent_id = OSSwapBigToHostInt32(*GetLeafData<uint32_t>()); |
| 514 auto key_string_length = OSSwapBigToHostInt16(*GetLeafData<uint16_t>()); | 514 auto key_string_length = OSSwapBigToHostInt16(*GetLeafData<uint16_t>()); |
| 515 auto key_string = | 515 auto* key_string = |
| 516 reinterpret_cast<uint16_t*>(&leaf_data_[current_leaf_offset_]); | 516 reinterpret_cast<uint16_t*>(&leaf_data_[current_leaf_offset_]); |
| 517 for (uint16_t i = 0; | 517 for (uint16_t i = 0; |
| 518 i < key_string_length; | 518 i < key_string_length; |
| 519 ++i, current_leaf_offset_ += sizeof(uint16_t)) { | 519 ++i, current_leaf_offset_ += sizeof(uint16_t)) { |
| 520 key_string[i] = OSSwapBigToHostInt16(key_string[i]); | 520 key_string[i] = OSSwapBigToHostInt16(key_string[i]); |
| 521 } | 521 } |
| 522 base::string16 key(key_string, key_string_length); | 522 base::string16 key(key_string, key_string_length); |
| 523 | 523 |
| 524 // Read the record type and then rewind as the field is part of the catalog | 524 // Read the record type and then rewind as the field is part of the catalog |
| 525 // structure that is read next. | 525 // structure that is read next. |
| 526 current_record_.record_type = OSSwapBigToHostInt16(*GetLeafData<int16_t>()); | 526 current_record_.record_type = OSSwapBigToHostInt16(*GetLeafData<int16_t>()); |
| 527 current_record_.unexported = false; | 527 current_record_.unexported = false; |
| 528 current_leaf_offset_ -= sizeof(int16_t); | 528 current_leaf_offset_ -= sizeof(int16_t); |
| 529 switch (current_record_.record_type) { | 529 switch (current_record_.record_type) { |
| 530 case kHFSPlusFolderRecord: { | 530 case kHFSPlusFolderRecord: { |
| 531 auto folder = GetLeafData<HFSPlusCatalogFolder>(); | 531 auto* folder = GetLeafData<HFSPlusCatalogFolder>(); |
| 532 ConvertBigEndian(folder); | 532 ConvertBigEndian(folder); |
| 533 ++leaf_records_read_; | 533 ++leaf_records_read_; |
| 534 ++current_leaf_records_read_; | 534 ++current_leaf_records_read_; |
| 535 | 535 |
| 536 // If this key is unexported, or the parent folder is, then mark the | 536 // If this key is unexported, or the parent folder is, then mark the |
| 537 // record as such. | 537 // record as such. |
| 538 if (IsKeyUnexported(key) || | 538 if (IsKeyUnexported(key) || |
| 539 unexported_parents_.find(parent_id) != unexported_parents_.end()) { | 539 unexported_parents_.find(parent_id) != unexported_parents_.end()) { |
| 540 unexported_parents_.insert(folder->folderID); | 540 unexported_parents_.insert(folder->folderID); |
| 541 current_record_.unexported = true; | 541 current_record_.unexported = true; |
| 542 } | 542 } |
| 543 | 543 |
| 544 // Update the CNID map to construct the path tree. | 544 // Update the CNID map to construct the path tree. |
| 545 if (parent_id != 0) { | 545 if (parent_id != 0) { |
| 546 auto parent_name = folder_cnid_map_.find(parent_id); | 546 auto parent_name = folder_cnid_map_.find(parent_id); |
| 547 if (parent_name != folder_cnid_map_.end()) | 547 if (parent_name != folder_cnid_map_.end()) |
| 548 key = parent_name->second + kFilePathSeparator + key; | 548 key = parent_name->second + kFilePathSeparator + key; |
| 549 } | 549 } |
| 550 folder_cnid_map_[folder->folderID] = key; | 550 folder_cnid_map_[folder->folderID] = key; |
| 551 | 551 |
| 552 current_record_.path = key; | 552 current_record_.path = key; |
| 553 current_record_.folder = folder; | 553 current_record_.folder = folder; |
| 554 break; | 554 break; |
| 555 } | 555 } |
| 556 case kHFSPlusFileRecord: { | 556 case kHFSPlusFileRecord: { |
| 557 auto file = GetLeafData<HFSPlusCatalogFile>(); | 557 auto* file = GetLeafData<HFSPlusCatalogFile>(); |
| 558 ConvertBigEndian(file); | 558 ConvertBigEndian(file); |
| 559 ++leaf_records_read_; | 559 ++leaf_records_read_; |
| 560 ++current_leaf_records_read_; | 560 ++current_leaf_records_read_; |
| 561 | 561 |
| 562 base::string16 path = | 562 base::string16 path = |
| 563 folder_cnid_map_[parent_id] + kFilePathSeparator + key; | 563 folder_cnid_map_[parent_id] + kFilePathSeparator + key; |
| 564 current_record_.path = path; | 564 current_record_.path = path; |
| 565 current_record_.file = file; | 565 current_record_.file = file; |
| 566 current_record_.unexported = | 566 current_record_.unexported = |
| 567 unexported_parents_.find(parent_id) != unexported_parents_.end(); | 567 unexported_parents_.find(parent_id) != unexported_parents_.end(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 if (!SeekToNode(current_leaf_number_)) { | 614 if (!SeekToNode(current_leaf_number_)) { |
| 615 DLOG(ERROR) << "Failed to seek to node " << current_leaf_number_; | 615 DLOG(ERROR) << "Failed to seek to node " << current_leaf_number_; |
| 616 return false; | 616 return false; |
| 617 } | 617 } |
| 618 | 618 |
| 619 if (!stream_->ReadExact(&leaf_data_[0], header_.nodeSize)) { | 619 if (!stream_->ReadExact(&leaf_data_[0], header_.nodeSize)) { |
| 620 DLOG(ERROR) << "Failed to read node " << current_leaf_number_; | 620 DLOG(ERROR) << "Failed to read node " << current_leaf_number_; |
| 621 return false; | 621 return false; |
| 622 } | 622 } |
| 623 | 623 |
| 624 auto leaf = reinterpret_cast<BTNodeDescriptor*>(&leaf_data_[0]); | 624 auto* leaf = reinterpret_cast<BTNodeDescriptor*>(&leaf_data_[0]); |
| 625 ConvertBigEndian(leaf); | 625 ConvertBigEndian(leaf); |
| 626 if (leaf->kind != kBTLeafNode) { | 626 if (leaf->kind != kBTLeafNode) { |
| 627 DLOG(ERROR) << "Node " << current_leaf_number_ << " is not a leaf"; | 627 DLOG(ERROR) << "Node " << current_leaf_number_ << " is not a leaf"; |
| 628 return false; | 628 return false; |
| 629 } | 629 } |
| 630 current_leaf_ = leaf; | 630 current_leaf_ = leaf; |
| 631 current_leaf_offset_ = sizeof(BTNodeDescriptor); | 631 current_leaf_offset_ = sizeof(BTNodeDescriptor); |
| 632 current_leaf_records_read_ = 0; | 632 current_leaf_records_read_ = 0; |
| 633 read_current_leaf_ = true; | 633 read_current_leaf_ = true; |
| 634 return true; | 634 return true; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 645 return object; | 645 return object; |
| 646 } | 646 } |
| 647 | 647 |
| 648 bool HFSBTreeIterator::IsKeyUnexported(const base::string16& key) { | 648 bool HFSBTreeIterator::IsKeyUnexported(const base::string16& key) { |
| 649 return key == kHFSDirMetadataFolder || | 649 return key == kHFSDirMetadataFolder || |
| 650 key == kHFSMetadataFolder; | 650 key == kHFSMetadataFolder; |
| 651 } | 651 } |
| 652 | 652 |
| 653 } // namespace dmg | 653 } // namespace dmg |
| 654 } // namespace safe_browsing | 654 } // namespace safe_browsing |
| OLD | NEW |