Chromium Code Reviews| 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 #ifndef CHROME_UTILITY_SAFE_BROWSING_MAC_UDIF_H_ | 5 #ifndef CHROME_UTILITY_SAFE_BROWSING_MAC_UDIF_H_ |
| 6 #define CHROME_UTILITY_SAFE_BROWSING_MAC_UDIF_H_ | 6 #define CHROME_UTILITY_SAFE_BROWSING_MAC_UDIF_H_ |
| 7 | 7 |
| 8 #include <CoreFoundation/CoreFoundation.h> | 8 #include <CoreFoundation/CoreFoundation.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 // | 40 // |
| 41 // The following references are useful for understanding the UDIF format: | 41 // The following references are useful for understanding the UDIF format: |
| 42 // - http://newosxbook.com/DMG.html | 42 // - http://newosxbook.com/DMG.html |
| 43 // - http://www.macdisk.com/dmgen.php | 43 // - http://www.macdisk.com/dmgen.php |
| 44 class UDIFParser { | 44 class UDIFParser { |
| 45 public: | 45 public: |
| 46 // Constructs an instance from a stream. | 46 // Constructs an instance from a stream. |
| 47 explicit UDIFParser(ReadStream* stream); | 47 explicit UDIFParser(ReadStream* stream); |
| 48 ~UDIFParser(); | 48 ~UDIFParser(); |
| 49 | 49 |
| 50 // Parses the trailer structure. Only actually parses data from the file the | |
| 51 // first time it is called -- after that just returns the previous result when | |
| 52 // parsing was attempted. | |
| 53 bool ParseTrailer(); | |
|
Robert Sesek
2017/06/12 16:38:39
This should be private, callers should only call P
mortonm
2017/06/12 18:31:16
Yeah, that does seem like a better interface. One
mortonm
2017/06/12 20:04:01
Actually, there is another issue to consider here.
Robert Sesek
2017/06/12 20:52:34
Yes, that's definitely a security issue. We should
mortonm
2017/06/12 21:39:49
As addressed in the later comment, we think we nee
| |
| 54 | |
| 50 // Parses the UDIF file. This method must be called before any other method. | 55 // Parses the UDIF file. This method must be called before any other method. |
| 51 // If this returns false, it is not legal to call any other methods. | 56 // If this returns false, it is not legal to call any other methods. |
| 52 bool Parse(); | 57 bool Parse(); |
| 53 | 58 |
| 54 // Returns the number of partitions in this UDIF image. | 59 // Returns the number of partitions in this UDIF image. |
| 55 size_t GetNumberOfPartitions(); | 60 size_t GetNumberOfPartitions(); |
| 56 | 61 |
| 57 // Returns the partition name for a given partition number, in the range of | 62 // Returns the partition name for a given partition number, in the range of |
| 58 // [0,GetNumberOfPartitions()). This will include the number, name, and type | 63 // [0,GetNumberOfPartitions()). This will include the number, name, and type |
| 59 // of partition. E.g., "disk image (Apple_HFS : 2)". | 64 // of partition. E.g., "disk image (Apple_HFS : 2)". |
| 60 std::string GetPartitionName(size_t part_number); | 65 std::string GetPartitionName(size_t part_number); |
| 61 | 66 |
| 62 // Returns the partition type as a string for the given partition number. | 67 // Returns the partition type as a string for the given partition number. |
| 63 // E.g., "Apple_HFS" and "Apple_Free". | 68 // E.g., "Apple_HFS" and "Apple_Free". |
| 64 std::string GetPartitionType(size_t part_number); | 69 std::string GetPartitionType(size_t part_number); |
| 65 | 70 |
| 66 // Returns the size of the partition in bytes. | 71 // Returns the size of the partition in bytes. |
| 67 size_t GetPartitionSize(size_t part_number); | 72 size_t GetPartitionSize(size_t part_number); |
| 68 | 73 |
| 69 // Returns a stream of the raw partition data for the given partition | 74 // Returns a stream of the raw partition data for the given partition |
| 70 // number. | 75 // number. |
| 71 std::unique_ptr<ReadStream> GetPartitionReadStream(size_t part_number); | 76 std::unique_ptr<ReadStream> GetPartitionReadStream(size_t part_number); |
| 72 | 77 |
| 73 private: | 78 private: |
| 74 // Parses the blkx plist trailer structure. | 79 // Parses the blkx plist structure. |
| 75 bool ParseBlkx(); | 80 bool ParseBlkx(); |
| 76 | 81 |
| 77 ReadStream* const stream_; // The stream backing the UDIF image. Weak. | 82 ReadStream* const stream_; // The stream backing the UDIF image. Weak. |
| 78 std::vector<std::string> partition_names_; // The names of all partitions. | 83 std::vector<std::string> partition_names_; // The names of all partitions. |
| 79 // All blocks in the UDIF image. | 84 // All blocks in the UDIF image. |
| 80 std::vector<std::unique_ptr<const UDIFBlock>> blocks_; | 85 std::vector<std::unique_ptr<const UDIFBlock>> blocks_; |
| 81 uint16_t block_size_; // The image's block size, in bytes. | 86 uint16_t block_size_; // The image's block size, in bytes. |
| 87 uint32_t trailer_signature_; | |
| 88 uint64_t plist_length_; | |
| 89 uint64_t plist_offset_; | |
| 90 bool trailer_successfully_parsed_; | |
| 82 | 91 |
| 83 DISALLOW_COPY_AND_ASSIGN(UDIFParser); | 92 DISALLOW_COPY_AND_ASSIGN(UDIFParser); |
| 84 }; | 93 }; |
| 85 | 94 |
| 86 } // namespace dmg | 95 } // namespace dmg |
| 87 } // namespace safe_browsing | 96 } // namespace safe_browsing |
| 88 | 97 |
| 89 #endif // CHROME_UTILITY_SAFE_BROWSING_MAC_UDIF_H_ | 98 #endif // CHROME_UTILITY_SAFE_BROWSING_MAC_UDIF_H_ |
| OLD | NEW |