1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // This file contains the interface for an iterator over a portable executable 6 // file's resources. 7 8 #ifndef CHROME_INSTALLER_TEST_PE_IMAGE_RESOURCES_H_ 9 #define CHROME_INSTALLER_TEST_PE_IMAGE_RESOURCES_H_ 10 11 #include <windows.h> 12 13 #include <string> 14 #include <vector> 15 16 #include "base/basictypes.h" 17 #include "base/logging.h" 18 19 namespace base { namespace win { class PEImage; } } 20 21 namespace upgrade_test { 22 23 // A CopyConstructible and Assignable identifier for resource directory 24 // entries. 25 class EntryId { 26 public: EntryId(WORD number)27 explicit EntryId(WORD number) : number_(number) { } EntryId(const std::wstring & name)28 explicit EntryId(const std::wstring& name) : name_(name), number_() { 29 DCHECK_NE(static_cast<std::wstring::size_type>(0), name.size()); 30 } IsNamed()31 bool IsNamed() const { return !name_.empty(); } number()32 WORD number() const { return number_; } name()33 const std::wstring& name() const { return name_; } 34 private: 35 std::wstring name_; 36 WORD number_; 37 }; // class EntryId 38 39 // A sequence of identifiers comprising the path from the root of an image's 40 // resource directory to an individual resource. 41 typedef std::vector<EntryId> EntryPath; 42 43 // A callback function invoked once for each data entry in the image's 44 // directory of resources. 45 // |path| - the full path of the data entry, 46 // |data| - the address of the entry's data. 47 // |size| - the size, in bytes, of the entry's data. 48 // |code_page| - the code page to be used to interpret string data in the 49 // entry's data. 50 // |context| - the context given to EnumResources. 51 typedef void (*EnumResource_Fn)(const EntryPath& path, uint8* data, 52 DWORD size, DWORD code_page, uintptr_t context); 53 54 // Enumerates all data entries in |image|'s resource directory. |callback| is 55 // invoked (and provided with |context|) once per entry. Returns false if 56 // some or all of the resource directory could not be parsed. 57 bool EnumResources(const base::win::PEImage& image, EnumResource_Fn callback, 58 uintptr_t context); 59 60 } // namespace upgrade_test 61 62 #endif // CHROME_INSTALLER_TEST_PE_IMAGE_RESOURCES_H_ 63