BearParser
Portable Executable parsing library (from PE-bear)
Loading...
Searching...
No Matches
parser
pe
rsrc
ResourcesAlbum.cpp
Go to the documentation of this file.
1
#include "
pe/rsrc/ResourcesAlbum.h
"
2
#include "
pe/rsrc/ResourceStringsWrapper.h
"
3
4
5
void
ResourcesContainer::putWrapper
(
ResourceContentWrapper
* wrapper)
6
{
7
if
(wrapper == NULL)
return
;
8
//TODO: check if already exist...
9
wrappers
.push_back(wrapper);
10
}
11
12
ResourceContentWrapper
*
ResourcesContainer::getWrapperAt
(
size_t
index)
13
{
14
if
(index >=
wrappers
.size())
return
NULL;
15
return
wrappers
.at(index);
16
}
17
18
size_t
ResourcesContainer::entriesCount
()
19
{
20
size_t
totalCount = 0;
21
size_t
wrappersCount = this->
count
();
22
23
for
(
size_t
i = 0; i < wrappersCount; i++) {
24
ResourceContentWrapper
* wrapper = this->
getWrapperAt
(i);
25
if
(wrapper == NULL) {
26
continue
;
27
}
28
size_t
count
= wrapper->
getFieldsCount
();
29
totalCount +=
count
;
30
}
31
return
totalCount;
32
}
33
34
//----------------------------------------------------------------------
35
void
ResourcesAlbum::clearLeafsContent
()
36
{
37
std::map<ResourceLeafWrapper*, ResourceContentWrapper*>::iterator itr;
38
for
(itr =
leafToContentWrapper
.begin(); itr !=
leafToContentWrapper
.end(); ++itr) {
39
ResourceContentWrapper
* cw = itr->second;
40
delete
cw;
41
}
42
leafToContentWrapper
.clear();
43
}
44
45
void
ResourcesAlbum::clear
()
46
{
47
clearLeafsContent
();
48
//---
49
std::map<ResourceLeafWrapper*, ResourceContentWrapper*>::iterator cntItr;
50
for
(cntItr =
leafToContentWrapper
.begin(); cntItr !=
leafToContentWrapper
.end(); ++cntItr) {
51
ResourceContentWrapper
* cntWr = cntItr->second;
52
delete
cntWr;
53
}
54
leafToContentWrapper
.clear();
55
//---
56
allLeafs
.clear();
57
allTypes
.clear();
58
}
59
60
void
ResourcesAlbum::putLeaf
(
ResourceLeafWrapper
* leaf,
long
topEntryId)
61
{
62
if
(!leaf)
return
;
63
allLeafs
[topEntryId].push_back(leaf);
64
}
65
66
void
ResourcesAlbum::wrapLeafsContent
()
67
{
68
std::map<long, std::vector<ResourceLeafWrapper*> >::iterator itr;
69
for
(itr =
allLeafs
.begin(); itr !=
allLeafs
.end(); ++itr) {
70
71
std::vector<ResourceLeafWrapper*> &leafVec = itr->second;
72
long
topEntryId = itr->first;
73
74
for
(
size_t
i = 0; i < leafVec.size(); i++) {
75
ResourceLeafWrapper
* leaf = leafVec.at(i);
76
pe::resource_type type =
idToLeafType
[topEntryId];
77
//printf("topEntryId %d type: %d\n", topEntryId, type);
78
//TODO: finish it!
79
ResourceContentWrapper
* cw =
ResourceContentFactory::makeResContentWrapper
(type, leaf);
80
if
(cw) {
81
leafToContentWrapper
[leaf] = cw;
82
this->
allWrappers
[type].putWrapper(cw);
83
}
84
}
85
}
86
initResourceTypes
();
87
}
88
89
size_t
ResourcesAlbum::entriesCountAt
(
long
topEntryId)
90
{
91
if
(
hasTopEntry
(topEntryId) ==
false
) {
92
return
0;
93
}
94
return
allLeafs
[topEntryId].size();
95
}
96
97
std::vector<ResourceLeafWrapper*>*
ResourcesAlbum::entriesAt
(
long
topEntryId)
98
{
99
if
(
hasTopEntry
(topEntryId) ==
false
) {
100
return
NULL;
101
}
102
return
&(
allLeafs
[topEntryId]);
103
}
104
105
ResourcesContainer
*
ResourcesAlbum::getResourcesOfType
(pe::resource_type typeId)
106
{
107
if
(
hasType
(typeId) ==
false
) {
108
return
NULL;
109
}
110
return
&(
allWrappers
[typeId]);
111
}
112
113
void
ResourcesAlbum::initResourceTypes
()
114
{
115
this->
allTypes
.clear();
116
std::map<pe::resource_type, ResourcesContainer>::iterator itr;
117
118
for
( itr = this->
allWrappers
.begin(); itr != this->allWrappers.end(); ++itr ) {
119
pe::resource_type type = itr->first;
120
this->
allTypes
.push_back(type);
121
}
122
}
123
/*
124
std::vector<pe::resource_type> ResourcesAlbum::getResourceTypes()
125
{
126
std::vector<pe::resource_type> typesVec;
127
std::map<pe::resource_type, ResourcesContainer>::iterator itr;
128
129
for ( itr = allWrappers.begin(); itr != allWrappers.end(); ++itr ) {
130
pe::resource_type type = itr->first;
131
typesVec.push_back(type);
132
}
133
return typesVec;
134
}
135
*/
ResourceStringsWrapper.h
ResourcesAlbum.h
ResourceContentFactory::makeResContentWrapper
static ResourceContentWrapper * makeResContentWrapper(pe::resource_type typeId, ResourceLeafWrapper *leaf)
Definition
ResourceContentFactory.cpp:5
ResourceContentWrapper
Definition
ResourceContentWrapper.h:10
ResourceContentWrapper::getFieldsCount
virtual size_t getFieldsCount()
Definition
ResourceContentWrapper.h:26
ResourceLeafWrapper
Definition
ResourceLeafWrapper.h:10
ResourcesAlbum::entriesCountAt
size_t entriesCountAt(long topEntryId)
Definition
ResourcesAlbum.cpp:89
ResourcesAlbum::clear
void clear()
Definition
ResourcesAlbum.cpp:45
ResourcesAlbum::leafToContentWrapper
std::map< ResourceLeafWrapper *, ResourceContentWrapper * > leafToContentWrapper
Definition
ResourcesAlbum.h:61
ResourcesAlbum::clearLeafsContent
void clearLeafsContent()
Definition
ResourcesAlbum.cpp:35
ResourcesAlbum::wrapLeafsContent
void wrapLeafsContent()
Definition
ResourcesAlbum.cpp:66
ResourcesAlbum::initResourceTypes
void initResourceTypes()
Definition
ResourcesAlbum.cpp:113
ResourcesAlbum::allTypes
std::vector< pe::resource_type > allTypes
Definition
ResourcesAlbum.h:56
ResourcesAlbum::putLeaf
void putLeaf(ResourceLeafWrapper *leaf, long topEntryId)
Definition
ResourcesAlbum.cpp:60
ResourcesAlbum::allLeafs
std::map< long, std::vector< ResourceLeafWrapper * > > allLeafs
Definition
ResourcesAlbum.h:58
ResourcesAlbum::getResourcesOfType
ResourcesContainer * getResourcesOfType(pe::resource_type typeId)
Definition
ResourcesAlbum.cpp:105
ResourcesAlbum::hasTopEntry
bool hasTopEntry(long topEntryId)
Definition
ResourcesAlbum.h:54
ResourcesAlbum::entriesAt
std::vector< ResourceLeafWrapper * > * entriesAt(long topEntryId)
Definition
ResourcesAlbum.cpp:97
ResourcesAlbum::idToLeafType
std::map< long, pe::resource_type > idToLeafType
Definition
ResourcesAlbum.h:60
ResourcesAlbum::hasType
bool hasType(pe::resource_type typeId)
Definition
ResourcesAlbum.h:46
ResourcesAlbum::allWrappers
std::map< pe::resource_type, ResourcesContainer > allWrappers
Definition
ResourcesAlbum.h:57
ResourcesContainer
Definition
ResourcesAlbum.h:12
ResourcesContainer::count
size_t count()
Definition
ResourcesAlbum.h:20
ResourcesContainer::putWrapper
void putWrapper(ResourceContentWrapper *wrapper)
Definition
ResourcesAlbum.cpp:5
ResourcesContainer::getWrapperAt
ResourceContentWrapper * getWrapperAt(size_t index)
Definition
ResourcesAlbum.cpp:12
ResourcesContainer::entriesCount
size_t entriesCount()
Definition
ResourcesAlbum.cpp:18
ResourcesContainer::wrappers
std::vector< ResourceContentWrapper * > wrappers
Definition
ResourcesAlbum.h:24
Generated by
1.12.0