blob: b45684dbce36bab67bc4e195a853a8bee9a1b4b5 [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2010 The Chromium Authors
[email protected]c744d292010-11-23 15:01:222// 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]c744d292010-11-23 15:01:2210
11#include <windows.h>
Brian Manthosb1d716f2020-06-08 03:40:4912
avi2729e442015-12-26 05:27:4513#include <stddef.h>
14#include <stdint.h>
[email protected]c744d292010-11-23 15:01:2215
16#include <string>
17#include <vector>
18
Hans Wennborg1f38a152020-06-22 06:38:4119#include "base/check_op.h"
[email protected]c744d292010-11-23 15:01:2220
Brian Manthosb1d716f2020-06-08 03:40:4921namespace base {
22namespace win {
23class PEImage;
24}
25} // namespace base
[email protected]c744d292010-11-23 15:01:2226
27namespace upgrade_test {
28
29// A CopyConstructible and Assignable identifier for resource directory
30// entries.
31class EntryId {
32 public:
Brian Manthosb1d716f2020-06-08 03:40:4933 explicit EntryId(WORD number) : number_(number) {}
[email protected]c744d292010-11-23 15:01:2234 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 Manthosb1d716f2020-06-08 03:40:4940
[email protected]c744d292010-11-23 15:01:2241 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.
48typedef 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.
avi2729e442015-12-26 05:27:4558typedef void (*EnumResource_Fn)(const EntryPath& path,
59 uint8_t* data,
60 DWORD size,
61 DWORD code_page,
62 uintptr_t context);
[email protected]c744d292010-11-23 15:01:2263
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 Manthosb1d716f2020-06-08 03:40:4967bool EnumResources(const base::win::PEImage& image,
68 EnumResource_Fn callback,
[email protected]c744d292010-11-23 15:01:2269 uintptr_t context);
70
71} // namespace upgrade_test
72
73#endif // CHROME_INSTALLER_TEST_PE_IMAGE_RESOURCES_H_