summaryrefslogtreecommitdiff
path: root/tools/pe_bliss/pe_resource_viewer.h
blob: e585da6a87bcb6778b0422c4df827a9026e305ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*************************************************************************/
/* Copyright (c) 2015 dx, http://kaimi.ru                                */
/*                                                                       */
/* Permission is hereby granted, free of charge, to any person           */
/* obtaining a copy of this software and associated documentation        */
/* files (the "Software"), to deal in the Software without               */
/* restriction, including without limitation the rights to use,          */
/* copy, modify, merge, publish, distribute, sublicense, and/or          */
/* sell copies of the Software, and to permit persons to whom the        */
/* Software is furnished to do so, subject to the following conditions:  */
/* The above copyright notice and this permission notice shall be        */
/* included in all copies or substantial portions of the Software.       */
/*                                                                       */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
/*************************************************************************/
#pragma once
#include <map>
#include <string>
#include "pe_structures.h"
#include "pe_resources.h"
#include "message_table.h"
#include "resource_data_info.h"

namespace pe_bliss
{
	//PE resource manager allows to read resources from PE files
class pe_resource_viewer
{
public:
	//Resource type enumeration
	enum resource_type
	{
		resource_cursor = 1,
		resource_bitmap = 2,
		resource_icon = 3,
		resource_menu = 4,
		resource_dialog = 5,
		resource_string = 6,
		resource_fontdir = 7,
		resource_font = 8,
		resource_accelerator = 9,
		resource_rcdata = 10,
		resource_message_table = 11,
		resource_cursor_group = 12,
		resource_icon_group = 14,
		resource_version = 16,
		resource_dlginclude = 17,
		resource_plugplay = 19,
		resource_vxd = 20,
		resource_anicursor = 21,
		resource_aniicon = 22,
		resource_html = 23,
		resource_manifest = 24
	};

public:
	//Some useful typedefs
	typedef std::vector<uint32_t> resource_type_list;
	typedef std::vector<uint32_t> resource_id_list;
	typedef std::vector<std::wstring> resource_name_list;
	typedef std::vector<uint32_t> resource_language_list;
	
public:
	//Constructor from root resource_directory from PE file
	explicit pe_resource_viewer(const resource_directory& root_directory);

	const resource_directory& get_root_directory() const;

	//Lists resource types existing in PE file (non-named only)
	const resource_type_list list_resource_types() const;
	//Returns true if resource type exists
	bool resource_exists(resource_type type) const;
	//Returns true if resource name exists
	bool resource_exists(const std::wstring& root_name) const;

	//Lists resource names existing in PE file by resource type
	const resource_name_list list_resource_names(resource_type type) const;
	//Lists resource names existing in PE file by resource name
	const resource_name_list list_resource_names(const std::wstring& root_name) const;
	//Lists resource IDs existing in PE file by resource type
	const resource_id_list list_resource_ids(resource_type type) const;
	//Lists resource IDs existing in PE file by resource name
	const resource_id_list list_resource_ids(const std::wstring& root_name) const;
	//Returns resource count by type
	unsigned long get_resource_count(resource_type type) const;
	//Returns resource count by name
	unsigned long get_resource_count(const std::wstring& root_name) const;

	//Returns language count of resource by resource type and name
	unsigned long get_language_count(resource_type type, const std::wstring& name) const;
	//Returns language count of resource by resource names
	unsigned long get_language_count(const std::wstring& root_name, const std::wstring& name) const;
	//Returns language count of resource by resource type and ID
	unsigned long get_language_count(resource_type type, uint32_t id) const;
	//Returns language count of resource by resource name and ID
	unsigned long get_language_count(const std::wstring& root_name, uint32_t id) const;
	//Lists resource languages by resource type and name
	const resource_language_list list_resource_languages(resource_type type, const std::wstring& name) const;
	//Lists resource languages by resource names
	const resource_language_list list_resource_languages(const std::wstring& root_name, const std::wstring& name) const;
	//Lists resource languages by resource type and ID
	const resource_language_list list_resource_languages(resource_type type, uint32_t id) const;
	//Lists resource languages by resource name and ID
	const resource_language_list list_resource_languages(const std::wstring& root_name, uint32_t id) const;

	//Returns raw resource data by type, name and language
	const resource_data_info get_resource_data_by_name(uint32_t language, resource_type type, const std::wstring& name) const;
	//Returns raw resource data by root name, name and language
	const resource_data_info get_resource_data_by_name(uint32_t language, const std::wstring& root_name, const std::wstring& name) const;
	//Returns raw resource data by type, ID and language
	const resource_data_info get_resource_data_by_id(uint32_t language, resource_type type, uint32_t id) const;
	//Returns raw resource data by root name, ID and language
	const resource_data_info get_resource_data_by_id(uint32_t language, const std::wstring& root_name, uint32_t id) const;
	//Returns raw resource data by type, name and index in language directory (instead of language)
	const resource_data_info get_resource_data_by_name(resource_type type, const std::wstring& name, uint32_t index = 0) const;
	//Returns raw resource data by root name, name and index in language directory (instead of language)
	const resource_data_info get_resource_data_by_name(const std::wstring& root_name, const std::wstring& name, uint32_t index = 0) const;
	//Returns raw resource data by type, ID and index in language directory (instead of language)
	const resource_data_info get_resource_data_by_id(resource_type type, uint32_t id, uint32_t index = 0) const;
	//Returns raw resource data by root name, ID and index in language directory (instead of language)
	const resource_data_info get_resource_data_by_id(const std::wstring& root_name, uint32_t id, uint32_t index = 0) const;

protected:
	//Root resource directory. We're not copying it, because it might be heavy
	const resource_directory& root_dir_;

	//Helper function to get ID list from entry list
	static const resource_id_list get_id_list(const resource_directory::entry_list& entries);
	//Helper function to get name list from entry list
	static const resource_name_list get_name_list(const resource_directory::entry_list& entries);

protected:
	//Helper structure - finder of resource_directory_entry that is named
	struct has_name
	{
	public:
		bool operator()(const resource_directory_entry& entry) const;
	};

	//Helper structure - finder of resource_directory_entry that is not named (has id)
	struct has_id
	{
	public:
		bool operator()(const resource_directory_entry& entry) const;
	};
};
}