Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2010 The Chromium Authors |
[email protected] | c744d29 | 2010-11-23 15:01:22 | [diff] [blame] | 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_ |
[email protected] | c744d29 | 2010-11-23 15:01:22 | [diff] [blame] | 10 | |
| 11 | #include <windows.h> |
Brian Manthos | b1d716f | 2020-06-08 03:40:49 | [diff] [blame] | 12 | |
avi | 2729e44 | 2015-12-26 05:27:45 | [diff] [blame] | 13 | #include <stddef.h> |
| 14 | #include <stdint.h> |
[email protected] | c744d29 | 2010-11-23 15:01:22 | [diff] [blame] | 15 | |
| 16 | #include <string> |
| 17 | #include <vector> |
| 18 | |
Hans Wennborg | 1f38a15 | 2020-06-22 06:38:41 | [diff] [blame] | 19 | #include "base/check_op.h" |
[email protected] | c744d29 | 2010-11-23 15:01:22 | [diff] [blame] | 20 | |
Brian Manthos | b1d716f | 2020-06-08 03:40:49 | [diff] [blame] | 21 | namespace base { |
| 22 | namespace win { |
| 23 | class PEImage; |
| 24 | } |
| 25 | } // namespace base |
[email protected] | c744d29 | 2010-11-23 15:01:22 | [diff] [blame] | 26 | |
| 27 | namespace upgrade_test { |
| 28 | |
| 29 | // A CopyConstructible and Assignable identifier for resource directory |
| 30 | // entries. |
| 31 | class EntryId { |
| 32 | public: |
Brian Manthos | b1d716f | 2020-06-08 03:40:49 | [diff] [blame] | 33 | explicit EntryId(WORD number) : number_(number) {} |
[email protected] | c744d29 | 2010-11-23 15:01:22 | [diff] [blame] | 34 | explicit EntryId(const std::wstring& name) : name_(name), number_() { |
| 35 | DCHECK_NE(static_cast<std::wstring::size_type>(0), name.size()); |
| 36 | } |
| 37 | bool IsNamed() const { return !name_.empty(); } |
| 38 | WORD number() const { return number_; } |
| 39 | const std::wstring& name() const { return name_; } |
Brian Manthos | b1d716f | 2020-06-08 03:40:49 | [diff] [blame] | 40 | |
[email protected] | c744d29 | 2010-11-23 15:01:22 | [diff] [blame] | 41 | private: |
| 42 | std::wstring name_; |
| 43 | WORD number_; |
| 44 | }; // class EntryId |
| 45 | |
| 46 | // A sequence of identifiers comprising the path from the root of an image's |
| 47 | // resource directory to an individual resource. |
| 48 | typedef std::vector<EntryId> EntryPath; |
| 49 | |
| 50 | // A callback function invoked once for each data entry in the image's |
| 51 | // directory of resources. |
| 52 | // |path| - the full path of the data entry, |
| 53 | // |data| - the address of the entry's data. |
| 54 | // |size| - the size, in bytes, of the entry's data. |
| 55 | // |code_page| - the code page to be used to interpret string data in the |
| 56 | // entry's data. |
| 57 | // |context| - the context given to EnumResources. |
avi | 2729e44 | 2015-12-26 05:27:45 | [diff] [blame] | 58 | typedef void (*EnumResource_Fn)(const EntryPath& path, |
| 59 | uint8_t* data, |
| 60 | DWORD size, |
| 61 | DWORD code_page, |
| 62 | uintptr_t context); |
[email protected] | c744d29 | 2010-11-23 15:01:22 | [diff] [blame] | 63 | |
| 64 | // Enumerates all data entries in |image|'s resource directory. |callback| is |
| 65 | // invoked (and provided with |context|) once per entry. Returns false if |
| 66 | // some or all of the resource directory could not be parsed. |
Brian Manthos | b1d716f | 2020-06-08 03:40:49 | [diff] [blame] | 67 | bool EnumResources(const base::win::PEImage& image, |
| 68 | EnumResource_Fn callback, |
[email protected] | c744d29 | 2010-11-23 15:01:22 | [diff] [blame] | 69 | uintptr_t context); |
| 70 | |
| 71 | } // namespace upgrade_test |
| 72 | |
| 73 | #endif // CHROME_INSTALLER_TEST_PE_IMAGE_RESOURCES_H_ |