BearParser
Portable Executable parsing library (from PE-bear)
Loading...
Searching...
No Matches
ResourcesAlbum.cpp
Go to the documentation of this file.
3
4
6{
7 if (wrapper == NULL) return;
8 //TODO: check if already exist...
9 wrappers.push_back(wrapper);
10}
11
13{
14 if (index >= wrappers.size()) return NULL;
15 return wrappers.at(index);
16}
17
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//----------------------------------------------------------------------
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 }
43}
44
46{
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 }
55 //---
56 allLeafs.clear();
57 allTypes.clear();
58}
59
60void ResourcesAlbum::putLeaf(ResourceLeafWrapper* leaf, long topEntryId)
61{
62 if (!leaf) return;
63 allLeafs[topEntryId].push_back(leaf);
64}
65
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!
80 if (cw) {
81 leafToContentWrapper[leaf] = cw;
82 this->allWrappers[type].putWrapper(cw);
83 }
84 }
85 }
87}
88
89size_t ResourcesAlbum::entriesCountAt(long topEntryId)
90{
91 if (hasTopEntry(topEntryId) == false) {
92 return 0;
93 }
94 return allLeafs[topEntryId].size();
95}
96
97std::vector<ResourceLeafWrapper*>* ResourcesAlbum::entriesAt(long topEntryId)
98{
99 if (hasTopEntry(topEntryId) == false) {
100 return NULL;
101 }
102 return &(allLeafs[topEntryId]);
103}
104
106{
107 if (hasType(typeId) == false) {
108 return NULL;
109 }
110 return &(allWrappers[typeId]);
111}
112
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/*
124std::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*/
static ResourceContentWrapper * makeResContentWrapper(pe::resource_type typeId, ResourceLeafWrapper *leaf)
size_t entriesCountAt(long topEntryId)
std::map< ResourceLeafWrapper *, ResourceContentWrapper * > leafToContentWrapper
std::vector< pe::resource_type > allTypes
void putLeaf(ResourceLeafWrapper *leaf, long topEntryId)
std::map< long, std::vector< ResourceLeafWrapper * > > allLeafs
ResourcesContainer * getResourcesOfType(pe::resource_type typeId)
bool hasTopEntry(long topEntryId)
std::vector< ResourceLeafWrapper * > * entriesAt(long topEntryId)
std::map< long, pe::resource_type > idToLeafType
bool hasType(pe::resource_type typeId)
std::map< pe::resource_type, ResourcesContainer > allWrappers
void putWrapper(ResourceContentWrapper *wrapper)
ResourceContentWrapper * getWrapperAt(size_t index)
std::vector< ResourceContentWrapper * > wrappers