Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: chrome/common/safe_browsing/mach_o_image_reader_mac.cc

Issue 2802973003: Remove ScopedVector from chrome/ (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/common/safe_browsing/mach_o_image_reader_mac.h" 5 #include "chrome/common/safe_browsing/mach_o_image_reader_mac.h"
6 6
7 #include <libkern/OSByteOrder.h> 7 #include <libkern/OSByteOrder.h>
8 #include <mach-o/fat.h> 8 #include <mach-o/fat.h>
9 #include <mach-o/loader.h> 9 #include <mach-o/loader.h>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/ptr_util.h"
12 #include "base/numerics/safe_math.h" 13 #include "base/numerics/safe_math.h"
13 14
14 namespace safe_browsing { 15 namespace safe_browsing {
15 16
16 // ByteSlice is a bounds-checking view of an arbitrary byte array. 17 // ByteSlice is a bounds-checking view of an arbitrary byte array.
17 class ByteSlice { 18 class ByteSlice {
18 public: 19 public:
19 // Creates an invalid byte slice. 20 // Creates an invalid byte slice.
20 ByteSlice() : ByteSlice(nullptr, 0) {} 21 ByteSlice() : ByteSlice(nullptr, 0) {}
21 22
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 127
127 // Cannot refer back to headers of previous arches to cause 128 // Cannot refer back to headers of previous arches to cause
128 // recursive processing. 129 // recursive processing.
129 if (arch_offset < offset) 130 if (arch_offset < offset)
130 return false; 131 return false;
131 132
132 ByteSlice slice = data_->Slice(arch_offset, arch_size); 133 ByteSlice slice = data_->Slice(arch_offset, arch_size);
133 if (!slice.IsValid()) 134 if (!slice.IsValid())
134 return false; 135 return false;
135 136
136 fat_images_.push_back(new MachOImageReader()); 137 fat_images_.push_back(base::MakeUnique<MachOImageReader>());
137 if (!fat_images_.back()->Initialize(slice.data(), slice.size())) 138 if (!fat_images_.back()->Initialize(slice.data(), slice.size()))
138 return false; 139 return false;
139 140
140 offset += sizeof(*arch); 141 offset += sizeof(*arch);
141 } 142 }
142 143
143 return true; 144 return true;
144 } 145 }
145 146
146 bool do_swap = *magic == MH_CIGAM || *magic == MH_CIGAM_64; 147 bool do_swap = *magic == MH_CIGAM || *magic == MH_CIGAM_64;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 return true; 195 return true;
195 } 196 }
196 197
197 bool MachOImageReader::IsFat() { 198 bool MachOImageReader::IsFat() {
198 return is_fat_; 199 return is_fat_;
199 } 200 }
200 201
201 std::vector<MachOImageReader*> MachOImageReader::GetFatImages() { 202 std::vector<MachOImageReader*> MachOImageReader::GetFatImages() {
202 DCHECK(is_fat_); 203 DCHECK(is_fat_);
203 std::vector<MachOImageReader*> images; 204 std::vector<MachOImageReader*> images;
204 for (auto it = fat_images_.begin(); it != fat_images_.end(); ++it) 205 for (const auto& image : fat_images_)
205 images.push_back(*it); 206 images.push_back(image.get());
206 return images; 207 return images;
207 } 208 }
208 209
209 bool MachOImageReader::Is64Bit() { 210 bool MachOImageReader::Is64Bit() {
210 DCHECK(!is_fat_); 211 DCHECK(!is_fat_);
211 return is_64_bit_; 212 return is_64_bit_;
212 } 213 }
213 214
214 const mach_header* MachOImageReader::GetMachHeader() { 215 const mach_header* MachOImageReader::GetMachHeader() {
215 DCHECK(!is_fat_); 216 DCHECK(!is_fat_);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 if (lc_code_signature == nullptr) 249 if (lc_code_signature == nullptr)
249 return false; 250 return false;
250 251
251 info->resize(lc_code_signature->datasize); 252 info->resize(lc_code_signature->datasize);
252 return data_->CopyDataAt(lc_code_signature->dataoff, 253 return data_->CopyDataAt(lc_code_signature->dataoff,
253 lc_code_signature->datasize, 254 lc_code_signature->datasize,
254 &(*info)[0]); 255 &(*info)[0]);
255 } 256 }
256 257
257 } // namespace safe_browsing 258 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698