Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / installer / test / pe_image_resources.h
blob3ffdd6e9b94ae7c5c2abcada291f744602c05786
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.
5 // This file contains the interface for an iterator over a portable executable
6 // file's resources.
8 #ifndef CHROME_INSTALLER_TEST_PE_IMAGE_RESOURCES_H_
9 #define CHROME_INSTALLER_TEST_PE_IMAGE_RESOURCES_H_
11 #include <windows.h>
13 #include <string>
14 #include <vector>
16 #include "base/basictypes.h"
17 #include "base/logging.h"
19 namespace base { namespace win { class PEImage; } }
21 namespace upgrade_test {
23 // A CopyConstructible and Assignable identifier for resource directory
24 // entries.
25 class EntryId {
26 public:
27 explicit EntryId(WORD number) : number_(number) { }
28 explicit EntryId(const std::wstring& name) : name_(name), number_() {
29 DCHECK_NE(static_cast<std::wstring::size_type>(0), name.size());
31 bool IsNamed() const { return !name_.empty(); }
32 WORD number() const { return number_; }
33 const std::wstring& name() const { return name_; }
34 private:
35 std::wstring name_;
36 WORD number_;
37 }; // class EntryId
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;
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);
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);
60 } // namespace upgrade_test
62 #endif // CHROME_INSTALLER_TEST_PE_IMAGE_RESOURCES_H_