Chromium Code Reviews| Index: chrome/browser/safe_browsing/disk_image_type_sniffer_mac.cc |
| diff --git a/chrome/browser/safe_browsing/disk_image_type_sniffer_mac.cc b/chrome/browser/safe_browsing/disk_image_type_sniffer_mac.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..323e6f73f4a1de6107583dae010ecbfd5bf17908 |
| --- /dev/null |
| +++ b/chrome/browser/safe_browsing/disk_image_type_sniffer_mac.cc |
| @@ -0,0 +1,44 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/safe_browsing/disk_image_type_sniffer_mac.h" |
| +#include "content/public/browser/browser_thread.h" |
| + |
| +namespace safe_browsing { |
| + |
| +namespace { |
| + |
| +const int kSizeKolySignatureInBytes = 4; |
|
Robert Sesek
2017/06/14 15:11:43
This could now be declared as:
constexpr size_t k
mortonm
2017/06/14 17:13:15
Done.
|
| +const int kSizeKolyTrailerInBytes = 512; |
| +const uint8_t kKolySignature[4] = {'k', 'o', 'l', 'y'}; |
| + |
| +} // namespace |
| + |
| +DiskImageTypeSnifferMac::DiskImageTypeSnifferMac() {} |
| + |
| +// static |
| +bool DiskImageTypeSnifferMac::IsAppleDiskImage(const base::FilePath& dmg_file) { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); |
| + |
| + base::File file(dmg_file, base::File::FLAG_OPEN | base::File::FLAG_READ); |
| + DCHECK(file.IsValid()); |
| + if (!file.IsValid()) |
| + return false; |
| + |
| + char data[kSizeKolySignatureInBytes]; |
| + |
| + if (file.Seek(base::File::FROM_END, -1 * kSizeKolyTrailerInBytes) == -1) |
| + return false; |
| + |
| + if (file.ReadAtCurrentPos(data, kSizeKolySignatureInBytes) != |
| + kSizeKolySignatureInBytes) |
| + return false; |
| + |
| + // Compare 4 bytes at given position in file to 'koly' in ascii. |
|
Robert Sesek
2017/06/14 15:11:43
I'd remove this comment now that the signature is
mortonm
2017/06/14 17:13:15
Done.
|
| + return (memcmp(data, kKolySignature, kSizeKolySignatureInBytes) == 0); |
| +} |
| + |
| +DiskImageTypeSnifferMac::~DiskImageTypeSnifferMac() = default; |
| + |
| +} // namespace safe_browsing |