summaryrefslogtreecommitdiff
path: root/utils/zenutils/libraries/pelib-0.9
diff options
context:
space:
mode:
Diffstat (limited to 'utils/zenutils/libraries/pelib-0.9')
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/CMakeLists.txt40
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/BoundImportDirectory.cpp1022
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/BoundImportDirectory.h174
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/ComHeaderDirectory.cpp934
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/ComHeaderDirectory.h240
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/DebugDirectory.cpp766
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/DebugDirectory.h168
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/ExportDirectory.cpp1384
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/ExportDirectory.h266
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/IatDirectory.cpp358
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/IatDirectory.h116
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/ImportDirectory.h2278
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/MzHeader.cpp1168
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/MzHeader.h296
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/PeFile.cpp338
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/PeFile.h902
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/PeHeader.cpp180
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/PeHeader.h5370
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/PeLib.h54
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/PeLibAux.cpp550
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/PeLibAux.h1768
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/PeLibInc.h64
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/RelocationsDirectory.cpp422
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/RelocationsDirectory.h140
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/ResourceDirectory.cpp2994
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/ResourceDirectory.h1470
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/TlsDirectory.h608
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/buffer/InputBuffer.cpp116
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/buffer/InputBuffer.h104
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/buffer/OutputBuffer.cpp82
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/buffer/OutputBuffer.h102
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/changelog.txt640
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/license.htm68
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/readme.txt86
34 files changed, 12634 insertions, 12634 deletions
diff --git a/utils/zenutils/libraries/pelib-0.9/CMakeLists.txt b/utils/zenutils/libraries/pelib-0.9/CMakeLists.txt
index 540fa99c8c..3cdb6e71ff 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/CMakeLists.txt
+++ b/utils/zenutils/libraries/pelib-0.9/CMakeLists.txt
@@ -1,20 +1,20 @@
1PROJECT(pelib) 1PROJECT(pelib)
2 2
3# source files for pelib 3# source files for pelib
4SET(pelib_srcs 4SET(pelib_srcs
5 pelib/BoundImportDirectory.cpp 5 pelib/BoundImportDirectory.cpp
6 pelib/ComHeaderDirectory.cpp 6 pelib/ComHeaderDirectory.cpp
7 pelib/DebugDirectory.cpp 7 pelib/DebugDirectory.cpp
8 pelib/ExportDirectory.cpp 8 pelib/ExportDirectory.cpp
9 pelib/IatDirectory.cpp 9 pelib/IatDirectory.cpp
10 pelib/MzHeader.cpp 10 pelib/MzHeader.cpp
11 pelib/PeFile.cpp 11 pelib/PeFile.cpp
12 pelib/PeHeader.cpp 12 pelib/PeHeader.cpp
13 pelib/PeLibAux.cpp 13 pelib/PeLibAux.cpp
14 pelib/RelocationsDirectory.cpp 14 pelib/RelocationsDirectory.cpp
15 pelib/ResourceDirectory.cpp 15 pelib/ResourceDirectory.cpp
16 pelib/buffer/InputBuffer.cpp 16 pelib/buffer/InputBuffer.cpp
17 pelib/buffer/OutputBuffer.cpp 17 pelib/buffer/OutputBuffer.cpp
18) 18)
19 19
20ADD_LIBRARY(pelib ${pelib_srcs}) 20ADD_LIBRARY(pelib ${pelib_srcs})
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/BoundImportDirectory.cpp b/utils/zenutils/libraries/pelib-0.9/pelib/BoundImportDirectory.cpp
index 5b84931838..7c5ff74f0e 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/BoundImportDirectory.cpp
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/BoundImportDirectory.cpp
@@ -1,511 +1,511 @@
1/* 1/*
2* BoundImportDirectory.cpp - Part of the PeLib library. 2* BoundImportDirectory.cpp - Part of the PeLib library.
3* 3*
4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) 4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5* All rights reserved. 5* All rights reserved.
6* 6*
7* This software is licensed under the zlib/libpng License. 7* This software is licensed under the zlib/libpng License.
8* For more details see http://www.opensource.org/licenses/zlib-license.php 8* For more details see http://www.opensource.org/licenses/zlib-license.php
9* or the license information file (license.htm) in the root directory 9* or the license information file (license.htm) in the root directory
10* of PeLib. 10* of PeLib.
11*/ 11*/
12 12
13#include "PeLibInc.h" 13#include "PeLibInc.h"
14#include "BoundImportDirectory.h" 14#include "BoundImportDirectory.h"
15#include <numeric> 15#include <numeric>
16#include <set> 16#include <set>
17#include <map> 17#include <map>
18 18
19namespace PeLib 19namespace PeLib
20{ 20{
21 /** 21 /**
22 * Adds another bound import to the BoundImport directory. 22 * Adds another bound import to the BoundImport directory.
23 * @param strModuleName Name of the PE file which will be imported. 23 * @param strModuleName Name of the PE file which will be imported.
24 * @param dwTds Value of the TimeDateStamp of the bound import field. 24 * @param dwTds Value of the TimeDateStamp of the bound import field.
25 * @param wOmn Value of the OffsetModuleName of the bound import field. 25 * @param wOmn Value of the OffsetModuleName of the bound import field.
26 * @param wWfr Value of the NumberOfModuleForwarderRefs of the bound import field. 26 * @param wWfr Value of the NumberOfModuleForwarderRefs of the bound import field.
27 **/ 27 **/
28 int BoundImportDirectory::addBoundImport(const std::string& strModuleName, dword dwTds, word wOmn, word wWfr) 28 int BoundImportDirectory::addBoundImport(const std::string& strModuleName, dword dwTds, word wOmn, word wWfr)
29 { 29 {
30 for (unsigned int i=0;i<m_vIbd.size();i++) 30 for (unsigned int i=0;i<m_vIbd.size();i++)
31 { 31 {
32 if (isEqualNc(strModuleName, m_vIbd[i].strModuleName)) 32 if (isEqualNc(strModuleName, m_vIbd[i].strModuleName))
33 { 33 {
34 return ERROR_DUPLICATE_ENTRY; 34 return ERROR_DUPLICATE_ENTRY;
35 } 35 }
36 } 36 }
37 37
38 PELIB_IMAGE_BOUND_IMPORT_DESCRIPTOR ibidCurrent; 38 PELIB_IMAGE_BOUND_IMPORT_DESCRIPTOR ibidCurrent;
39 ibidCurrent.TimeDateStamp = dwTds; 39 ibidCurrent.TimeDateStamp = dwTds;
40 ibidCurrent.OffsetModuleName = wOmn; 40 ibidCurrent.OffsetModuleName = wOmn;
41 ibidCurrent.NumberOfModuleForwarderRefs = wWfr; 41 ibidCurrent.NumberOfModuleForwarderRefs = wWfr;
42 PELIB_IMAGE_BOUND_DIRECTORY ibdCurrent; 42 PELIB_IMAGE_BOUND_DIRECTORY ibdCurrent;
43 ibdCurrent.ibdDescriptor = ibidCurrent; 43 ibdCurrent.ibdDescriptor = ibidCurrent;
44 ibdCurrent.strModuleName = strModuleName; 44 ibdCurrent.strModuleName = strModuleName;
45 m_vIbd.push_back(ibdCurrent); 45 m_vIbd.push_back(ibdCurrent);
46 46
47 return NO_ERROR; 47 return NO_ERROR;
48 } 48 }
49 49
50 /** 50 /**
51 * Searches for the first instance of a module with the given modulename. 51 * Searches for the first instance of a module with the given modulename.
52 * @param strModuleName The name of a module. 52 * @param strModuleName The name of a module.
53 * @return The id of the module. 53 * @return The id of the module.
54 **/ 54 **/
55 int BoundImportDirectory::getModuleIndex(const std::string& strModuleName) const 55 int BoundImportDirectory::getModuleIndex(const std::string& strModuleName) const
56 { 56 {
57 std::vector<PELIB_IMAGE_BOUND_DIRECTORY>::const_iterator Iter = std::find_if(m_vIbd.begin(), m_vIbd.end(), std::bind2nd(std::mem_fun_ref(&PELIB_IMAGE_BOUND_DIRECTORY::equal), strModuleName)); 57 std::vector<PELIB_IMAGE_BOUND_DIRECTORY>::const_iterator Iter = std::find_if(m_vIbd.begin(), m_vIbd.end(), std::bind2nd(std::mem_fun_ref(&PELIB_IMAGE_BOUND_DIRECTORY::equal), strModuleName));
58 58
59 if (Iter == m_vIbd.end()) 59 if (Iter == m_vIbd.end())
60 { 60 {
61 return ERROR_ENTRY_NOT_FOUND; 61 return ERROR_ENTRY_NOT_FOUND;
62 } 62 }
63 63
64 return static_cast<int>(std::distance(m_vIbd.begin(), Iter)); 64 return static_cast<int>(std::distance(m_vIbd.begin(), Iter));
65 } 65 }
66 66
67 /** 67 /**
68 * @return Number of files in the current BoundImport directory. 68 * @return Number of files in the current BoundImport directory.
69 **/ 69 **/
70 unsigned int BoundImportDirectory::calcNumberOfModules() const 70 unsigned int BoundImportDirectory::calcNumberOfModules() const
71 { 71 {
72 return static_cast<unsigned int>(m_vIbd.size()); 72 return static_cast<unsigned int>(m_vIbd.size());
73 } 73 }
74 74
75 int BoundImportDirectory::read(InputBuffer& inpBuffer, unsigned char* data, unsigned int dwSize) 75 int BoundImportDirectory::read(InputBuffer& inpBuffer, unsigned char* data, unsigned int dwSize)
76 { 76 {
77 std::vector<PELIB_IMAGE_BOUND_DIRECTORY> currentDirectory; 77 std::vector<PELIB_IMAGE_BOUND_DIRECTORY> currentDirectory;
78 78
79 do 79 do
80 { 80 {
81 PELIB_IMAGE_BOUND_DIRECTORY ibdCurrent; 81 PELIB_IMAGE_BOUND_DIRECTORY ibdCurrent;
82 82
83 inpBuffer >> ibdCurrent.ibdDescriptor.TimeDateStamp; 83 inpBuffer >> ibdCurrent.ibdDescriptor.TimeDateStamp;
84 inpBuffer >> ibdCurrent.ibdDescriptor.OffsetModuleName; 84 inpBuffer >> ibdCurrent.ibdDescriptor.OffsetModuleName;
85 inpBuffer >> ibdCurrent.ibdDescriptor.NumberOfModuleForwarderRefs; 85 inpBuffer >> ibdCurrent.ibdDescriptor.NumberOfModuleForwarderRefs;
86 86
87 if (ibdCurrent.ibdDescriptor.TimeDateStamp == 0 && ibdCurrent.ibdDescriptor.OffsetModuleName == 0 && ibdCurrent.ibdDescriptor.NumberOfModuleForwarderRefs == 0) break; 87 if (ibdCurrent.ibdDescriptor.TimeDateStamp == 0 && ibdCurrent.ibdDescriptor.OffsetModuleName == 0 && ibdCurrent.ibdDescriptor.NumberOfModuleForwarderRefs == 0) break;
88 88
89 for (int i=0;i<ibdCurrent.ibdDescriptor.NumberOfModuleForwarderRefs;i++) 89 for (int i=0;i<ibdCurrent.ibdDescriptor.NumberOfModuleForwarderRefs;i++)
90 { 90 {
91 PELIB_IMAGE_BOUND_DIRECTORY currentForwarder; 91 PELIB_IMAGE_BOUND_DIRECTORY currentForwarder;
92 92
93 inpBuffer >> currentForwarder.ibdDescriptor.TimeDateStamp; 93 inpBuffer >> currentForwarder.ibdDescriptor.TimeDateStamp;
94 inpBuffer >> currentForwarder.ibdDescriptor.OffsetModuleName; 94 inpBuffer >> currentForwarder.ibdDescriptor.OffsetModuleName;
95 inpBuffer >> currentForwarder.ibdDescriptor.NumberOfModuleForwarderRefs; 95 inpBuffer >> currentForwarder.ibdDescriptor.NumberOfModuleForwarderRefs;
96 96
97 ibdCurrent.moduleForwarders.push_back(currentForwarder); 97 ibdCurrent.moduleForwarders.push_back(currentForwarder);
98 } 98 }
99 99
100 currentDirectory.push_back(ibdCurrent); 100 currentDirectory.push_back(ibdCurrent);
101 ibdCurrent.moduleForwarders.clear(); 101 ibdCurrent.moduleForwarders.clear();
102 } while (true); 102 } while (true);
103 103
104 for (unsigned int i=0;i<currentDirectory.size();i++) 104 for (unsigned int i=0;i<currentDirectory.size();i++)
105 { 105 {
106 dword wOmn = currentDirectory[i].ibdDescriptor.OffsetModuleName; 106 dword wOmn = currentDirectory[i].ibdDescriptor.OffsetModuleName;
107 if (wOmn > dwSize) 107 if (wOmn > dwSize)
108 { 108 {
109 return ERROR_INVALID_FILE; 109 return ERROR_INVALID_FILE;
110 } 110 }
111 111
112 currentDirectory[i].strModuleName = ""; 112 currentDirectory[i].strModuleName = "";
113 for (int k=0;data[wOmn + k] != 0 && k + wOmn < dwSize;k++) 113 for (int k=0;data[wOmn + k] != 0 && k + wOmn < dwSize;k++)
114 { 114 {
115 currentDirectory[i].strModuleName += data[wOmn + k]; 115 currentDirectory[i].strModuleName += data[wOmn + k];
116 } 116 }
117 117
118 for (unsigned int j=0;j<currentDirectory[i].moduleForwarders.size();j++) 118 for (unsigned int j=0;j<currentDirectory[i].moduleForwarders.size();j++)
119 { 119 {
120 dword wOmn = currentDirectory[i].moduleForwarders[j].ibdDescriptor.OffsetModuleName; 120 dword wOmn = currentDirectory[i].moduleForwarders[j].ibdDescriptor.OffsetModuleName;
121 121
122 if (wOmn > dwSize) 122 if (wOmn > dwSize)
123 { 123 {
124 return ERROR_INVALID_FILE; 124 return ERROR_INVALID_FILE;
125 } 125 }
126 126
127// m_vIbd[i].moduleForwarders[j].strModuleName.assign((char*)(&vBimpDir[wOmn])); 127// m_vIbd[i].moduleForwarders[j].strModuleName.assign((char*)(&vBimpDir[wOmn]));
128 currentDirectory[i].moduleForwarders[j].strModuleName = ""; 128 currentDirectory[i].moduleForwarders[j].strModuleName = "";
129 for (int k=0;data[wOmn + k] != 0 && k + wOmn < dwSize;k++) 129 for (int k=0;data[wOmn + k] != 0 && k + wOmn < dwSize;k++)
130 { 130 {
131 currentDirectory[i].moduleForwarders[j].strModuleName += data[wOmn + k]; 131 currentDirectory[i].moduleForwarders[j].strModuleName += data[wOmn + k];
132 } 132 }
133 } 133 }
134 } 134 }
135 135
136 std::swap(m_vIbd, currentDirectory); 136 std::swap(m_vIbd, currentDirectory);
137 137
138 return NO_ERROR; 138 return NO_ERROR;
139 } 139 }
140 140
141 /** 141 /**
142 * Reads the BoundImport directory from a PE file. 142 * Reads the BoundImport directory from a PE file.
143 * @param strModuleName The name of the PE file from which the BoundImport directory is read. 143 * @param strModuleName The name of the PE file from which the BoundImport directory is read.
144 * @param dwOffset The file offset where the BoundImport directory can be found (see #PeFile::PeHeader::getIDBoundImportRVA). 144 * @param dwOffset The file offset where the BoundImport directory can be found (see #PeFile::PeHeader::getIDBoundImportRVA).
145 * @param dwSize The size of the BoundImport directory (see #PeFile::PeHeader::getIDBoundImportSize). 145 * @param dwSize The size of the BoundImport directory (see #PeFile::PeHeader::getIDBoundImportSize).
146 **/ 146 **/
147 int BoundImportDirectory::read(const std::string& strModuleName, dword dwOffset, unsigned int uiSize) 147 int BoundImportDirectory::read(const std::string& strModuleName, dword dwOffset, unsigned int uiSize)
148 { 148 {
149 std::ifstream ifFile(strModuleName.c_str(), std::ios::binary); 149 std::ifstream ifFile(strModuleName.c_str(), std::ios::binary);
150 150
151 if (!ifFile) 151 if (!ifFile)
152 { 152 {
153 return ERROR_OPENING_FILE; 153 return ERROR_OPENING_FILE;
154 } 154 }
155 155
156 if (fileSize(ifFile) < dwOffset + uiSize) 156 if (fileSize(ifFile) < dwOffset + uiSize)
157 { 157 {
158 return ERROR_INVALID_FILE; 158 return ERROR_INVALID_FILE;
159 } 159 }
160 160
161 ifFile.seekg(dwOffset, std::ios::beg); 161 ifFile.seekg(dwOffset, std::ios::beg);
162 162
163 std::vector<unsigned char> vBimpDir(uiSize); 163 std::vector<unsigned char> vBimpDir(uiSize);
164 ifFile.read(reinterpret_cast<char*>(&vBimpDir[0]), uiSize); 164 ifFile.read(reinterpret_cast<char*>(&vBimpDir[0]), uiSize);
165 165
166 InputBuffer inpBuffer(vBimpDir); 166 InputBuffer inpBuffer(vBimpDir);
167 167
168 return read(inpBuffer, &vBimpDir[0], uiSize); 168 return read(inpBuffer, &vBimpDir[0], uiSize);
169 } 169 }
170 170
171 int BoundImportDirectory::read(unsigned char* pcBuffer, unsigned int uiSize) 171 int BoundImportDirectory::read(unsigned char* pcBuffer, unsigned int uiSize)
172 { 172 {
173 std::vector<unsigned char> vBimpDir(pcBuffer, pcBuffer + uiSize); 173 std::vector<unsigned char> vBimpDir(pcBuffer, pcBuffer + uiSize);
174 InputBuffer inpBuffer(vBimpDir); 174 InputBuffer inpBuffer(vBimpDir);
175 175
176 return read(inpBuffer, &vBimpDir[0], uiSize); 176 return read(inpBuffer, &vBimpDir[0], uiSize);
177 } 177 }
178 178
179 unsigned int BoundImportDirectory::totalModules() const 179 unsigned int BoundImportDirectory::totalModules() const
180 { 180 {
181 unsigned int modules = static_cast<unsigned int>(m_vIbd.size()); 181 unsigned int modules = static_cast<unsigned int>(m_vIbd.size());
182 182
183 for (unsigned int i=0;i<m_vIbd.size();i++) 183 for (unsigned int i=0;i<m_vIbd.size();i++)
184 { 184 {
185 modules += static_cast<unsigned int>(m_vIbd[i].moduleForwarders.size()); 185 modules += static_cast<unsigned int>(m_vIbd[i].moduleForwarders.size());
186 } 186 }
187 187
188 return modules; 188 return modules;
189 } 189 }
190 190
191 /** 191 /**
192 * Rebuilds the BoundImport directory. The rebuilded BoundImport directory can then be 192 * Rebuilds the BoundImport directory. The rebuilded BoundImport directory can then be
193 * written back to a PE file. 193 * written back to a PE file.
194 * @param vBuffer Buffer where the rebuilt BoundImport directory will be stored. 194 * @param vBuffer Buffer where the rebuilt BoundImport directory will be stored.
195 * @param fMakeValid If this flag is true a valid directory will be produced. 195 * @param fMakeValid If this flag is true a valid directory will be produced.
196 **/ 196 **/
197 void BoundImportDirectory::rebuild(std::vector<byte>& vBuffer, bool fMakeValid) const 197 void BoundImportDirectory::rebuild(std::vector<byte>& vBuffer, bool fMakeValid) const
198 { 198 {
199 std::map<std::string, word> filename_offsets; 199 std::map<std::string, word> filename_offsets;
200 200
201 OutputBuffer obBuffer(vBuffer); 201 OutputBuffer obBuffer(vBuffer);
202 202
203 word ulNameOffset = static_cast<word>((totalModules() + 1) * PELIB_IMAGE_BOUND_IMPORT_DESCRIPTOR::size()); 203 word ulNameOffset = static_cast<word>((totalModules() + 1) * PELIB_IMAGE_BOUND_IMPORT_DESCRIPTOR::size());
204 204
205 for (unsigned int i=0;i<m_vIbd.size();i++) 205 for (unsigned int i=0;i<m_vIbd.size();i++)
206 { 206 {
207 obBuffer << m_vIbd[i].ibdDescriptor.TimeDateStamp; 207 obBuffer << m_vIbd[i].ibdDescriptor.TimeDateStamp;
208 208
209 // Recalculate the offsets if a valid directory is wanted. 209 // Recalculate the offsets if a valid directory is wanted.
210 if (fMakeValid) 210 if (fMakeValid)
211 { 211 {
212 if (filename_offsets.find(m_vIbd[i].strModuleName) == filename_offsets.end()) 212 if (filename_offsets.find(m_vIbd[i].strModuleName) == filename_offsets.end())
213 { 213 {
214 filename_offsets[m_vIbd[i].strModuleName] = ulNameOffset; 214 filename_offsets[m_vIbd[i].strModuleName] = ulNameOffset;
215 obBuffer << ulNameOffset; 215 obBuffer << ulNameOffset;
216 ulNameOffset += static_cast<word>(m_vIbd[i].strModuleName.size() + 1); 216 ulNameOffset += static_cast<word>(m_vIbd[i].strModuleName.size() + 1);
217 } 217 }
218 else 218 else
219 { 219 {
220 obBuffer << filename_offsets[m_vIbd[i].strModuleName]; 220 obBuffer << filename_offsets[m_vIbd[i].strModuleName];
221 } 221 }
222 } 222 }
223 else // Otherwise just copy the old values into the buffer. 223 else // Otherwise just copy the old values into the buffer.
224 { 224 {
225 obBuffer << m_vIbd[i].ibdDescriptor.OffsetModuleName; 225 obBuffer << m_vIbd[i].ibdDescriptor.OffsetModuleName;
226 } 226 }
227 227
228 obBuffer << m_vIbd[i].ibdDescriptor.NumberOfModuleForwarderRefs; 228 obBuffer << m_vIbd[i].ibdDescriptor.NumberOfModuleForwarderRefs;
229 229
230 for (int j=0;j<calcNumberOfModuleForwarderRefs(i);j++) 230 for (int j=0;j<calcNumberOfModuleForwarderRefs(i);j++)
231 { 231 {
232 obBuffer << m_vIbd[i].moduleForwarders[j].ibdDescriptor.TimeDateStamp; 232 obBuffer << m_vIbd[i].moduleForwarders[j].ibdDescriptor.TimeDateStamp;
233 233
234 if (fMakeValid) 234 if (fMakeValid)
235 { 235 {
236 if (filename_offsets.find(m_vIbd[i].strModuleName) == filename_offsets.end()) 236 if (filename_offsets.find(m_vIbd[i].strModuleName) == filename_offsets.end())
237 { 237 {
238 filename_offsets[m_vIbd[i].moduleForwarders[j].strModuleName] = ulNameOffset; 238 filename_offsets[m_vIbd[i].moduleForwarders[j].strModuleName] = ulNameOffset;
239 obBuffer << ulNameOffset; 239 obBuffer << ulNameOffset;
240 ulNameOffset += static_cast<word>(m_vIbd[i].moduleForwarders[j].strModuleName.size() + 1); 240 ulNameOffset += static_cast<word>(m_vIbd[i].moduleForwarders[j].strModuleName.size() + 1);
241 } 241 }
242 else 242 else
243 { 243 {
244 obBuffer << filename_offsets[m_vIbd[i].moduleForwarders[j].strModuleName]; 244 obBuffer << filename_offsets[m_vIbd[i].moduleForwarders[j].strModuleName];
245 } 245 }
246 } 246 }
247 else // Otherwise just copy the old values into the buffer. 247 else // Otherwise just copy the old values into the buffer.
248 { 248 {
249 obBuffer << m_vIbd[i].moduleForwarders[j].ibdDescriptor.OffsetModuleName; 249 obBuffer << m_vIbd[i].moduleForwarders[j].ibdDescriptor.OffsetModuleName;
250 } 250 }
251 251
252 obBuffer << m_vIbd[i].moduleForwarders[j].ibdDescriptor.NumberOfModuleForwarderRefs; 252 obBuffer << m_vIbd[i].moduleForwarders[j].ibdDescriptor.NumberOfModuleForwarderRefs;
253 } 253 }
254 } 254 }
255 255
256 obBuffer << static_cast<dword>(0); 256 obBuffer << static_cast<dword>(0);
257 obBuffer << static_cast<word>(0); 257 obBuffer << static_cast<word>(0);
258 obBuffer << static_cast<word>(0); 258 obBuffer << static_cast<word>(0);
259 259
260 for (unsigned int i=0;i<m_vIbd.size();i++) 260 for (unsigned int i=0;i<m_vIbd.size();i++)
261 { 261 {
262 if (filename_offsets.find(m_vIbd[i].strModuleName) != filename_offsets.end()) 262 if (filename_offsets.find(m_vIbd[i].strModuleName) != filename_offsets.end())
263 { 263 {
264 obBuffer.add(getModuleName(i).c_str(), static_cast<unsigned long>(getModuleName(i).size() + 1)); 264 obBuffer.add(getModuleName(i).c_str(), static_cast<unsigned long>(getModuleName(i).size() + 1));
265 filename_offsets.erase(m_vIbd[i].strModuleName); 265 filename_offsets.erase(m_vIbd[i].strModuleName);
266 } 266 }
267 267
268 for (int j=0;j<calcNumberOfModuleForwarderRefs(i);j++) 268 for (int j=0;j<calcNumberOfModuleForwarderRefs(i);j++)
269 { 269 {
270 if (filename_offsets.find(getModuleName(i, j)) != filename_offsets.end()) 270 if (filename_offsets.find(getModuleName(i, j)) != filename_offsets.end())
271 { 271 {
272 obBuffer.add(getModuleName(i, j).c_str(), static_cast<unsigned long>(getModuleName(i, j).size() + 1)); 272 obBuffer.add(getModuleName(i, j).c_str(), static_cast<unsigned long>(getModuleName(i, j).size() + 1));
273 filename_offsets.erase(getModuleName(i, j)); 273 filename_offsets.erase(getModuleName(i, j));
274 } 274 }
275 } 275 }
276 } 276 }
277 } 277 }
278 278
279 /** 279 /**
280 * Removes all bound import files. 280 * Removes all bound import files.
281 **/ 281 **/
282 void BoundImportDirectory::clear() 282 void BoundImportDirectory::clear()
283 { 283 {
284 m_vIbd.clear(); 284 m_vIbd.clear();
285 } 285 }
286 286
287 /** 287 /**
288 * Removes a field specified by the parameter filename from the BoundImport directory. 288 * Removes a field specified by the parameter filename from the BoundImport directory.
289 * @param strModuleName Name of the file whose field will be removed from the BoundImport directory. 289 * @param strModuleName Name of the file whose field will be removed from the BoundImport directory.
290 **/ 290 **/
291 void BoundImportDirectory::removeBoundImport(const std::string& strModuleName) 291 void BoundImportDirectory::removeBoundImport(const std::string& strModuleName)
292 { 292 {
293 m_vIbd.erase(std::remove_if(m_vIbd.begin(), m_vIbd.end(), std::bind2nd(std::mem_fun_ref(&PELIB_IMAGE_BOUND_DIRECTORY::equal), strModuleName)), m_vIbd.end()); 293 m_vIbd.erase(std::remove_if(m_vIbd.begin(), m_vIbd.end(), std::bind2nd(std::mem_fun_ref(&PELIB_IMAGE_BOUND_DIRECTORY::equal), strModuleName)), m_vIbd.end());
294 } 294 }
295 295
296 /** 296 /**
297 * Returns the size of the rebuilt BoundImportDirectory. 297 * Returns the size of the rebuilt BoundImportDirectory.
298 * @return Size of the rebuilt BoundImportDirectory. 298 * @return Size of the rebuilt BoundImportDirectory.
299 **/ 299 **/
300 unsigned int BoundImportDirectory::size() const 300 unsigned int BoundImportDirectory::size() const
301 { 301 {
302 unsigned int size = PELIB_IMAGE_BOUND_IMPORT_DESCRIPTOR::size(); 302 unsigned int size = PELIB_IMAGE_BOUND_IMPORT_DESCRIPTOR::size();
303 303
304 std::set<std::string> filenames; 304 std::set<std::string> filenames;
305 305
306 for (unsigned int i = 0; i < m_vIbd.size(); i++) 306 for (unsigned int i = 0; i < m_vIbd.size(); i++)
307 { 307 {
308 filenames.insert(m_vIbd[i].strModuleName); 308 filenames.insert(m_vIbd[i].strModuleName);
309 309
310 size += PELIB_IMAGE_BOUND_IMPORT_DESCRIPTOR::size(); 310 size += PELIB_IMAGE_BOUND_IMPORT_DESCRIPTOR::size();
311 311
312 for (unsigned int j = 0; j < m_vIbd[i].moduleForwarders.size(); j++) 312 for (unsigned int j = 0; j < m_vIbd[i].moduleForwarders.size(); j++)
313 { 313 {
314 filenames.insert(m_vIbd[i].moduleForwarders[j].strModuleName); 314 filenames.insert(m_vIbd[i].moduleForwarders[j].strModuleName);
315 315
316 size += PELIB_IMAGE_BOUND_IMPORT_DESCRIPTOR::size(); 316 size += PELIB_IMAGE_BOUND_IMPORT_DESCRIPTOR::size();
317 } 317 }
318 } 318 }
319 319
320 for (std::set<std::string>::iterator iter = filenames.begin(); iter != filenames.end(); ++iter) 320 for (std::set<std::string>::iterator iter = filenames.begin(); iter != filenames.end(); ++iter)
321 { 321 {
322 size += static_cast<unsigned int>(iter->size()) + 1; 322 size += static_cast<unsigned int>(iter->size()) + 1;
323 } 323 }
324 324
325 return size; 325 return size;
326 } 326 }
327 327
328 /** 328 /**
329 * @param strFilename Name of the file. 329 * @param strFilename Name of the file.
330 * @param dwOffset File offset the bound importdirectory will be written to. 330 * @param dwOffset File offset the bound importdirectory will be written to.
331 * @param fMakeValid If this flag is true a valid directory will be produced. 331 * @param fMakeValid If this flag is true a valid directory will be produced.
332 **/ 332 **/
333 int BoundImportDirectory::write(const std::string& strFilename, dword dwOffset, bool fMakeValid) const 333 int BoundImportDirectory::write(const std::string& strFilename, dword dwOffset, bool fMakeValid) const
334 { 334 {
335 std::fstream ofFile(strFilename.c_str(), std::ios_base::in); 335 std::fstream ofFile(strFilename.c_str(), std::ios_base::in);
336 336
337 if (!ofFile) 337 if (!ofFile)
338 { 338 {
339 ofFile.clear(); 339 ofFile.clear();
340 ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary); 340 ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary);
341 } 341 }
342 else 342 else
343 { 343 {
344 ofFile.close(); 344 ofFile.close();
345 ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary); 345 ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary);
346 } 346 }
347 347
348 if (!ofFile) 348 if (!ofFile)
349 { 349 {
350 return ERROR_OPENING_FILE; 350 return ERROR_OPENING_FILE;
351 } 351 }
352 352
353 ofFile.seekp(dwOffset, std::ios::beg); 353 ofFile.seekp(dwOffset, std::ios::beg);
354 354
355 std::vector<unsigned char> vBuffer; 355 std::vector<unsigned char> vBuffer;
356 rebuild(vBuffer, fMakeValid); 356 rebuild(vBuffer, fMakeValid);
357 357
358 ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), static_cast<std::streamsize>(vBuffer.size())); 358 ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), static_cast<std::streamsize>(vBuffer.size()));
359 359
360 ofFile.close(); 360 ofFile.close();
361 361
362 return NO_ERROR; 362 return NO_ERROR;
363 } 363 }
364 364
365 /** 365 /**
366 * Retrieves the value of the TimeDateStamp value of a bound import field. 366 * Retrieves the value of the TimeDateStamp value of a bound import field.
367 * @param dwBidnr Number of the bound import field. 367 * @param dwBidnr Number of the bound import field.
368 * @return Value of the TimeDateStamp of the bound import field. 368 * @return Value of the TimeDateStamp of the bound import field.
369 **/ 369 **/
370 dword BoundImportDirectory::getTimeDateStamp(dword dwBidnr) const 370 dword BoundImportDirectory::getTimeDateStamp(dword dwBidnr) const
371 { 371 {
372 return m_vIbd[dwBidnr].ibdDescriptor.TimeDateStamp; 372 return m_vIbd[dwBidnr].ibdDescriptor.TimeDateStamp;
373 } 373 }
374 374
375 /** 375 /**
376 * Retrieves the value of the OffsetModuleName value of a bound import field. 376 * Retrieves the value of the OffsetModuleName value of a bound import field.
377 * @param dwBidnr Number of the bound import field. 377 * @param dwBidnr Number of the bound import field.
378 * @return Value of the OffsetModuleName of the bound import field. 378 * @return Value of the OffsetModuleName of the bound import field.
379 **/ 379 **/
380 word BoundImportDirectory::getOffsetModuleName(dword dwBidnr) const 380 word BoundImportDirectory::getOffsetModuleName(dword dwBidnr) const
381 { 381 {
382 return m_vIbd[dwBidnr].ibdDescriptor.OffsetModuleName; 382 return m_vIbd[dwBidnr].ibdDescriptor.OffsetModuleName;
383 } 383 }
384 384
385 /** 385 /**
386 * Retrieves the value of the NumberOfModuleForwarderRefs value of a bound import field. 386 * Retrieves the value of the NumberOfModuleForwarderRefs value of a bound import field.
387 * @param dwBidnr Number of the bound import field. 387 * @param dwBidnr Number of the bound import field.
388 * @return Value of the NumberOfModuleForwarderRefs of the bound import field. 388 * @return Value of the NumberOfModuleForwarderRefs of the bound import field.
389 **/ 389 **/
390 word BoundImportDirectory::getNumberOfModuleForwarderRefs(dword dwBidnr) const 390 word BoundImportDirectory::getNumberOfModuleForwarderRefs(dword dwBidnr) const
391 { 391 {
392 return m_vIbd[dwBidnr].ibdDescriptor.NumberOfModuleForwarderRefs; 392 return m_vIbd[dwBidnr].ibdDescriptor.NumberOfModuleForwarderRefs;
393 } 393 }
394 394
395 /** 395 /**
396 * Retrieves the value of the ModuleName value of a bound import field. 396 * Retrieves the value of the ModuleName value of a bound import field.
397 * @param dwBidnr Number of the bound import field. 397 * @param dwBidnr Number of the bound import field.
398 * @return Value of the ModuleName of the bound import field. 398 * @return Value of the ModuleName of the bound import field.
399 **/ 399 **/
400 std::string BoundImportDirectory::getModuleName(dword dwBidnr) const 400 std::string BoundImportDirectory::getModuleName(dword dwBidnr) const
401 { 401 {
402 return m_vIbd[dwBidnr].strModuleName; 402 return m_vIbd[dwBidnr].strModuleName;
403 } 403 }
404 404
405 /** 405 /**
406 * Changes the TimeDateStamp value of an existing bound import field. 406 * Changes the TimeDateStamp value of an existing bound import field.
407 * @param dwBidnr Number of the bound import field which will be changed. 407 * @param dwBidnr Number of the bound import field which will be changed.
408 * @param dwTds New value of the TimeDateStamp of the bound import field. 408 * @param dwTds New value of the TimeDateStamp of the bound import field.
409 **/ 409 **/
410 void BoundImportDirectory::setTimeDateStamp(dword dwBidnr, dword dwTds) 410 void BoundImportDirectory::setTimeDateStamp(dword dwBidnr, dword dwTds)
411 { 411 {
412 m_vIbd[dwBidnr].ibdDescriptor.TimeDateStamp = dwTds; 412 m_vIbd[dwBidnr].ibdDescriptor.TimeDateStamp = dwTds;
413 } 413 }
414 414
415 /** 415 /**
416 * Changes the OffsetModuleName value of an existing bound import field. 416 * Changes the OffsetModuleName value of an existing bound import field.
417 * @param dwBidnr Number of the bound import field which will be changed. 417 * @param dwBidnr Number of the bound import field which will be changed.
418 * @param wOmn New value of the OffsetModuleName of the bound import field. 418 * @param wOmn New value of the OffsetModuleName of the bound import field.
419 **/ 419 **/
420 void BoundImportDirectory::setOffsetModuleName(dword dwBidnr, word wOmn) 420 void BoundImportDirectory::setOffsetModuleName(dword dwBidnr, word wOmn)
421 { 421 {
422 m_vIbd[dwBidnr].ibdDescriptor.OffsetModuleName = wOmn; 422 m_vIbd[dwBidnr].ibdDescriptor.OffsetModuleName = wOmn;
423 } 423 }
424 424
425 /** 425 /**
426 * Changes the NumberOfModuleForwarderRefs value of an existing bound import field. 426 * Changes the NumberOfModuleForwarderRefs value of an existing bound import field.
427 * @param dwBidnr Number of the bound import field which will be changed. 427 * @param dwBidnr Number of the bound import field which will be changed.
428 * @param wMfr New value of the NumberOfModuleForwarderRefs of the bound import field. 428 * @param wMfr New value of the NumberOfModuleForwarderRefs of the bound import field.
429 **/ 429 **/
430 void BoundImportDirectory::setNumberOfModuleForwarderRefs(dword dwBidnr, word wMfr) 430 void BoundImportDirectory::setNumberOfModuleForwarderRefs(dword dwBidnr, word wMfr)
431 { 431 {
432 m_vIbd[dwBidnr].ibdDescriptor.NumberOfModuleForwarderRefs = wMfr; 432 m_vIbd[dwBidnr].ibdDescriptor.NumberOfModuleForwarderRefs = wMfr;
433 } 433 }
434 434
435 /** 435 /**
436 * Changes the ModuleName value of an existing bound import field. 436 * Changes the ModuleName value of an existing bound import field.
437 * @param dwBidnr Number of the bound import field which will be changed. 437 * @param dwBidnr Number of the bound import field which will be changed.
438 * @param strModuleName New value of the ModuleName of the bound import field. 438 * @param strModuleName New value of the ModuleName of the bound import field.
439 **/ 439 **/
440 void BoundImportDirectory::setModuleName(dword dwBidnr, const std::string& strModuleName) 440 void BoundImportDirectory::setModuleName(dword dwBidnr, const std::string& strModuleName)
441 { 441 {
442 m_vIbd[dwBidnr].strModuleName = strModuleName; 442 m_vIbd[dwBidnr].strModuleName = strModuleName;
443 } 443 }
444 444
445 dword BoundImportDirectory::getTimeDateStamp(dword dwBidnr, dword forwardedModule) const 445 dword BoundImportDirectory::getTimeDateStamp(dword dwBidnr, dword forwardedModule) const
446 { 446 {
447 return m_vIbd[dwBidnr].moduleForwarders[forwardedModule].ibdDescriptor.TimeDateStamp; 447 return m_vIbd[dwBidnr].moduleForwarders[forwardedModule].ibdDescriptor.TimeDateStamp;
448 } 448 }
449 449
450 word BoundImportDirectory::getOffsetModuleName(dword dwBidnr, dword forwardedModule) const 450 word BoundImportDirectory::getOffsetModuleName(dword dwBidnr, dword forwardedModule) const
451 { 451 {
452 return m_vIbd[dwBidnr].moduleForwarders[forwardedModule].ibdDescriptor.OffsetModuleName; 452 return m_vIbd[dwBidnr].moduleForwarders[forwardedModule].ibdDescriptor.OffsetModuleName;
453 } 453 }
454 454
455 word BoundImportDirectory::getNumberOfModuleForwarderRefs(dword dwBidnr, dword forwardedModule) const 455 word BoundImportDirectory::getNumberOfModuleForwarderRefs(dword dwBidnr, dword forwardedModule) const
456 { 456 {
457 return m_vIbd[dwBidnr].moduleForwarders[forwardedModule].ibdDescriptor.NumberOfModuleForwarderRefs; 457 return m_vIbd[dwBidnr].moduleForwarders[forwardedModule].ibdDescriptor.NumberOfModuleForwarderRefs;
458 } 458 }
459 459
460 std::string BoundImportDirectory::getModuleName(dword dwBidnr, dword forwardedModule) const 460 std::string BoundImportDirectory::getModuleName(dword dwBidnr, dword forwardedModule) const
461 { 461 {
462 return m_vIbd[dwBidnr].moduleForwarders[forwardedModule].strModuleName; 462 return m_vIbd[dwBidnr].moduleForwarders[forwardedModule].strModuleName;
463 } 463 }
464 464
465 void BoundImportDirectory::setTimeDateStamp(dword dwBidnr, dword forwardedModule, dword dwTds) 465 void BoundImportDirectory::setTimeDateStamp(dword dwBidnr, dword forwardedModule, dword dwTds)
466 { 466 {
467 m_vIbd[dwBidnr].moduleForwarders[forwardedModule].ibdDescriptor.TimeDateStamp = dwTds; 467 m_vIbd[dwBidnr].moduleForwarders[forwardedModule].ibdDescriptor.TimeDateStamp = dwTds;
468 } 468 }
469 469
470 void BoundImportDirectory::setOffsetModuleName(dword dwBidnr, dword forwardedModule, word wOmn) 470 void BoundImportDirectory::setOffsetModuleName(dword dwBidnr, dword forwardedModule, word wOmn)
471 { 471 {
472 m_vIbd[dwBidnr].moduleForwarders[forwardedModule].ibdDescriptor.OffsetModuleName = wOmn; 472 m_vIbd[dwBidnr].moduleForwarders[forwardedModule].ibdDescriptor.OffsetModuleName = wOmn;
473 } 473 }
474 474
475 void BoundImportDirectory::setNumberOfModuleForwarderRefs(dword dwBidnr, dword forwardedModule, word wMfr) 475 void BoundImportDirectory::setNumberOfModuleForwarderRefs(dword dwBidnr, dword forwardedModule, word wMfr)
476 { 476 {
477 m_vIbd[dwBidnr].moduleForwarders[forwardedModule].ibdDescriptor.NumberOfModuleForwarderRefs = wMfr; 477 m_vIbd[dwBidnr].moduleForwarders[forwardedModule].ibdDescriptor.NumberOfModuleForwarderRefs = wMfr;
478 } 478 }
479 479
480 void BoundImportDirectory::setModuleName(dword dwBidnr, dword forwardedModule, const std::string& strModuleName) 480 void BoundImportDirectory::setModuleName(dword dwBidnr, dword forwardedModule, const std::string& strModuleName)
481 { 481 {
482 m_vIbd[dwBidnr].moduleForwarders[forwardedModule].strModuleName = strModuleName; 482 m_vIbd[dwBidnr].moduleForwarders[forwardedModule].strModuleName = strModuleName;
483 } 483 }
484 484
485 word BoundImportDirectory::calcNumberOfModuleForwarderRefs(dword dwBidnr) const 485 word BoundImportDirectory::calcNumberOfModuleForwarderRefs(dword dwBidnr) const
486 { 486 {
487 return static_cast<word>(m_vIbd[dwBidnr].moduleForwarders.size()); 487 return static_cast<word>(m_vIbd[dwBidnr].moduleForwarders.size());
488 } 488 }
489 489
490 void BoundImportDirectory::addForwardedModule(dword dwBidnr, const std::string& name, dword timeStamp, word offsetModuleName, word forwardedModules) 490 void BoundImportDirectory::addForwardedModule(dword dwBidnr, const std::string& name, dword timeStamp, word offsetModuleName, word forwardedModules)
491 { 491 {
492 // XXX: Maybe test if there are already 0xFFFF forwarded modules. 492 // XXX: Maybe test if there are already 0xFFFF forwarded modules.
493 // XXX: Check for duplicate entries. Is it also necessary to check 493 // XXX: Check for duplicate entries. Is it also necessary to check
494 // non-forwarded entries and forwarded entries in other non-forwarded 494 // non-forwarded entries and forwarded entries in other non-forwarded
495 // entries? 495 // entries?
496 // XXX: Can forwarders forward recursively? 496 // XXX: Can forwarders forward recursively?
497 497
498 PELIB_IMAGE_BOUND_DIRECTORY ibdCurrent; 498 PELIB_IMAGE_BOUND_DIRECTORY ibdCurrent;
499 ibdCurrent.strModuleName = name; 499 ibdCurrent.strModuleName = name;
500 ibdCurrent.ibdDescriptor.TimeDateStamp = timeStamp; 500 ibdCurrent.ibdDescriptor.TimeDateStamp = timeStamp;
501 ibdCurrent.ibdDescriptor.OffsetModuleName = offsetModuleName; 501 ibdCurrent.ibdDescriptor.OffsetModuleName = offsetModuleName;
502 ibdCurrent.ibdDescriptor.NumberOfModuleForwarderRefs = forwardedModules; 502 ibdCurrent.ibdDescriptor.NumberOfModuleForwarderRefs = forwardedModules;
503 503
504 m_vIbd[dwBidnr].moduleForwarders.push_back(ibdCurrent); 504 m_vIbd[dwBidnr].moduleForwarders.push_back(ibdCurrent);
505 } 505 }
506 506
507 void BoundImportDirectory::removeForwardedModule(dword dwBidnr, word forwardedModule) 507 void BoundImportDirectory::removeForwardedModule(dword dwBidnr, word forwardedModule)
508 { 508 {
509 m_vIbd[dwBidnr].moduleForwarders.erase(m_vIbd[dwBidnr].moduleForwarders.begin() + forwardedModule); 509 m_vIbd[dwBidnr].moduleForwarders.erase(m_vIbd[dwBidnr].moduleForwarders.begin() + forwardedModule);
510 } 510 }
511} 511}
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/BoundImportDirectory.h b/utils/zenutils/libraries/pelib-0.9/pelib/BoundImportDirectory.h
index fd2bab56fd..142d78f710 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/BoundImportDirectory.h
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/BoundImportDirectory.h
@@ -1,87 +1,87 @@
1/* 1/*
2* BoundImportDirectory.h - Part of the PeLib library. 2* BoundImportDirectory.h - Part of the PeLib library.
3* 3*
4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) 4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5* All rights reserved. 5* All rights reserved.
6* 6*
7* This software is licensed under the zlib/libpng License. 7* This software is licensed under the zlib/libpng License.
8* For more details see http://www.opensource.org/licenses/zlib-license.php 8* For more details see http://www.opensource.org/licenses/zlib-license.php
9* or the license information file (license.htm) in the root directory 9* or the license information file (license.htm) in the root directory
10* of PeLib. 10* of PeLib.
11*/ 11*/
12 12
13#ifndef BOUNDIMPORTDIRECTORY_H 13#ifndef BOUNDIMPORTDIRECTORY_H
14#define BOUNDIMPORTDIRECTORY_H 14#define BOUNDIMPORTDIRECTORY_H
15 15
16#include "PeLibAux.h" 16#include "PeLibAux.h"
17 17
18namespace PeLib 18namespace PeLib
19{ 19{
20 /// Class that handles the BoundImport directory. 20 /// Class that handles the BoundImport directory.
21 /** 21 /**
22 * This class can read and modify the BoundImport directory table of a PE file. 22 * This class can read and modify the BoundImport directory table of a PE file.
23 **/ 23 **/
24 class BoundImportDirectory 24 class BoundImportDirectory
25 { 25 {
26 private: 26 private:
27 std::vector<PELIB_IMAGE_BOUND_DIRECTORY> m_vIbd; ///< Stores the individual BoundImport fields. 27 std::vector<PELIB_IMAGE_BOUND_DIRECTORY> m_vIbd; ///< Stores the individual BoundImport fields.
28 28
29 int read(InputBuffer& inpBuffer, unsigned char* data, unsigned int dwSize); 29 int read(InputBuffer& inpBuffer, unsigned char* data, unsigned int dwSize);
30 unsigned int totalModules() const; 30 unsigned int totalModules() const;
31 public: 31 public:
32 /// Adds another bound import. 32 /// Adds another bound import.
33 int addBoundImport(const std::string& strModuleName, dword dwTds, word dwOmn, word wWfr); // EXPORT 33 int addBoundImport(const std::string& strModuleName, dword dwTds, word dwOmn, word wWfr); // EXPORT
34 /// Identifies a module through it's name. 34 /// Identifies a module through it's name.
35 int getModuleIndex(const std::string& strModuleName) const; // EXPORT 35 int getModuleIndex(const std::string& strModuleName) const; // EXPORT
36 /// Returns the number of files in the BoundImport directory. 36 /// Returns the number of files in the BoundImport directory.
37 unsigned int calcNumberOfModules() const; // EXPORT 37 unsigned int calcNumberOfModules() const; // EXPORT
38 /// Reads the BoundImport directory table from a PE file. 38 /// Reads the BoundImport directory table from a PE file.
39 int read(const std::string& strFileName, dword dwOffset, unsigned int uiSize); // EXPORT 39 int read(const std::string& strFileName, dword dwOffset, unsigned int uiSize); // EXPORT
40 int read(unsigned char* pcBuffer, unsigned int uiSize); // EXPORT 40 int read(unsigned char* pcBuffer, unsigned int uiSize); // EXPORT
41 /// Rebuilds the BoundImport directory. 41 /// Rebuilds the BoundImport directory.
42 void rebuild(std::vector<byte>& vBuffer, bool fMakeValid = true) const; // EXPORT 42 void rebuild(std::vector<byte>& vBuffer, bool fMakeValid = true) const; // EXPORT
43 /// Empties the BoundImport directory. 43 /// Empties the BoundImport directory.
44 void clear(); // EXPORT 44 void clear(); // EXPORT
45 /// Removes a bound import. 45 /// Removes a bound import.
46 void removeBoundImport(const std::string& strModuleName); // EXPORT 46 void removeBoundImport(const std::string& strModuleName); // EXPORT
47 /// Returns the size of the BoundImport directory. 47 /// Returns the size of the BoundImport directory.
48 unsigned int size() const; // EXPORT 48 unsigned int size() const; // EXPORT
49 /// Writes the current bound import directory to a file. 49 /// Writes the current bound import directory to a file.
50 int write(const std::string& strFilename, dword dwOffset, bool fMakeValid = true) const; // EXPORT 50 int write(const std::string& strFilename, dword dwOffset, bool fMakeValid = true) const; // EXPORT
51 51
52 /// Retrieves the TimeDateStamp value of a bound import. 52 /// Retrieves the TimeDateStamp value of a bound import.
53 dword getTimeDateStamp(dword dwBidnr) const; // EXPORT 53 dword getTimeDateStamp(dword dwBidnr) const; // EXPORT
54 /// Retrieves the OffsetModuleName value of a bound import. 54 /// Retrieves the OffsetModuleName value of a bound import.
55 word getOffsetModuleName(dword dwBidnr) const; // EXPORT 55 word getOffsetModuleName(dword dwBidnr) const; // EXPORT
56 /// Retrieves the NumberOfModuleForwarderRefs value of a bound import. 56 /// Retrieves the NumberOfModuleForwarderRefs value of a bound import.
57 word getNumberOfModuleForwarderRefs(dword dwBidnr) const; // EXPORT 57 word getNumberOfModuleForwarderRefs(dword dwBidnr) const; // EXPORT
58 /// Retrieves the ModuleName value of a bound import. 58 /// Retrieves the ModuleName value of a bound import.
59 std::string getModuleName(dword dwBidnr) const; // EXPORT 59 std::string getModuleName(dword dwBidnr) const; // EXPORT
60 60
61 /// Updates the TimeDateStamp value of a bound import. 61 /// Updates the TimeDateStamp value of a bound import.
62 void setTimeDateStamp(dword dwBidnr, dword dwTds); // EXPORT 62 void setTimeDateStamp(dword dwBidnr, dword dwTds); // EXPORT
63 /// Updates the OffsetModuleName value of a bound import. 63 /// Updates the OffsetModuleName value of a bound import.
64 void setOffsetModuleName(dword dwBidnr, word wOmn); // EXPORT 64 void setOffsetModuleName(dword dwBidnr, word wOmn); // EXPORT
65 /// Updates the NumberOfModuleForwarderRefs value of a bound import. 65 /// Updates the NumberOfModuleForwarderRefs value of a bound import.
66 void setNumberOfModuleForwarderRefs(dword dwBidnr, word wMfr); // EXPORT 66 void setNumberOfModuleForwarderRefs(dword dwBidnr, word wMfr); // EXPORT
67 /// Updates the ModuleName value of a bound import. 67 /// Updates the ModuleName value of a bound import.
68 void setModuleName(dword dwBidnr, const std::string& strModuleName); // EXPORT 68 void setModuleName(dword dwBidnr, const std::string& strModuleName); // EXPORT
69 69
70 dword getTimeDateStamp(dword dwBidnr, dword forwardedModule) const; // EXPORT _module 70 dword getTimeDateStamp(dword dwBidnr, dword forwardedModule) const; // EXPORT _module
71 word getOffsetModuleName(dword dwBidnr, dword forwardedModule) const; // EXPORT _module 71 word getOffsetModuleName(dword dwBidnr, dword forwardedModule) const; // EXPORT _module
72 word getNumberOfModuleForwarderRefs(dword dwBidnr, dword forwardedModule) const; // EXPORT _module 72 word getNumberOfModuleForwarderRefs(dword dwBidnr, dword forwardedModule) const; // EXPORT _module
73 std::string getModuleName(dword dwBidnr, dword forwardedModule) const; // EXPORT _module 73 std::string getModuleName(dword dwBidnr, dword forwardedModule) const; // EXPORT _module
74 74
75 void setTimeDateStamp(dword dwBidnr, dword forwardedModule, dword dwTds); // EXPORT _module 75 void setTimeDateStamp(dword dwBidnr, dword forwardedModule, dword dwTds); // EXPORT _module
76 void setOffsetModuleName(dword dwBidnr, dword forwardedModule, word wOmn); // EXPORT _module 76 void setOffsetModuleName(dword dwBidnr, dword forwardedModule, word wOmn); // EXPORT _module
77 void setNumberOfModuleForwarderRefs(dword dwBidnr, dword forwardedModule, word wMfr); // EXPORT _module 77 void setNumberOfModuleForwarderRefs(dword dwBidnr, dword forwardedModule, word wMfr); // EXPORT _module
78 void setModuleName(dword dwBidnr, dword forwardedModule, const std::string& strModuleName); // EXPORT _module 78 void setModuleName(dword dwBidnr, dword forwardedModule, const std::string& strModuleName); // EXPORT _module
79 79
80 word calcNumberOfModuleForwarderRefs(dword dwBidnr) const; // EXPORT 80 word calcNumberOfModuleForwarderRefs(dword dwBidnr) const; // EXPORT
81 void addForwardedModule(dword dwBidnr, const std::string& name, dword timeStamp = 0, word offsetModuleName = 0, word forwardedModules = 0); // EXPORT 81 void addForwardedModule(dword dwBidnr, const std::string& name, dword timeStamp = 0, word offsetModuleName = 0, word forwardedModules = 0); // EXPORT
82 void removeForwardedModule(dword dwBidnr, word forwardedModule); // EXPORT 82 void removeForwardedModule(dword dwBidnr, word forwardedModule); // EXPORT
83 }; 83 };
84} 84}
85 85
86 86
87#endif 87#endif
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/ComHeaderDirectory.cpp b/utils/zenutils/libraries/pelib-0.9/pelib/ComHeaderDirectory.cpp
index 886348994e..fef12f4d8b 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/ComHeaderDirectory.cpp
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/ComHeaderDirectory.cpp
@@ -1,467 +1,467 @@
1/* 1/*
2* ComHeaderDirectory.cpp - Part of the PeLib library. 2* ComHeaderDirectory.cpp - Part of the PeLib library.
3* 3*
4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) 4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5* All rights reserved. 5* All rights reserved.
6* 6*
7* This software is licensed under the zlib/libpng License. 7* This software is licensed under the zlib/libpng License.
8* For more details see http://www.opensource.org/licenses/zlib-license.php 8* For more details see http://www.opensource.org/licenses/zlib-license.php
9* or the license information file (license.htm) in the root directory 9* or the license information file (license.htm) in the root directory
10* of PeLib. 10* of PeLib.
11*/ 11*/
12 12
13#include "PeLibInc.h" 13#include "PeLibInc.h"
14#include "ComHeaderDirectory.h" 14#include "ComHeaderDirectory.h"
15 15
16namespace PeLib 16namespace PeLib
17{ 17{
18 void ComHeaderDirectory::read(InputBuffer& inputbuffer) 18 void ComHeaderDirectory::read(InputBuffer& inputbuffer)
19 { 19 {
20 PELIB_IMAGE_COR20_HEADER ichCurr; 20 PELIB_IMAGE_COR20_HEADER ichCurr;
21 21
22 inputbuffer >> ichCurr.cb; 22 inputbuffer >> ichCurr.cb;
23 inputbuffer >> ichCurr.MajorRuntimeVersion; 23 inputbuffer >> ichCurr.MajorRuntimeVersion;
24 inputbuffer >> ichCurr.MinorRuntimeVersion; 24 inputbuffer >> ichCurr.MinorRuntimeVersion;
25 inputbuffer >> ichCurr.MetaData.VirtualAddress; 25 inputbuffer >> ichCurr.MetaData.VirtualAddress;
26 inputbuffer >> ichCurr.MetaData.Size; 26 inputbuffer >> ichCurr.MetaData.Size;
27 inputbuffer >> ichCurr.Flags; 27 inputbuffer >> ichCurr.Flags;
28 inputbuffer >> ichCurr.EntryPointToken; 28 inputbuffer >> ichCurr.EntryPointToken;
29 inputbuffer >> ichCurr.Resources.VirtualAddress; 29 inputbuffer >> ichCurr.Resources.VirtualAddress;
30 inputbuffer >> ichCurr.Resources.Size; 30 inputbuffer >> ichCurr.Resources.Size;
31 inputbuffer >> ichCurr.StrongNameSignature.VirtualAddress; 31 inputbuffer >> ichCurr.StrongNameSignature.VirtualAddress;
32 inputbuffer >> ichCurr.StrongNameSignature.Size; 32 inputbuffer >> ichCurr.StrongNameSignature.Size;
33 inputbuffer >> ichCurr.CodeManagerTable.VirtualAddress; 33 inputbuffer >> ichCurr.CodeManagerTable.VirtualAddress;
34 inputbuffer >> ichCurr.CodeManagerTable.Size; 34 inputbuffer >> ichCurr.CodeManagerTable.Size;
35 inputbuffer >> ichCurr.VTableFixups.VirtualAddress; 35 inputbuffer >> ichCurr.VTableFixups.VirtualAddress;
36 inputbuffer >> ichCurr.VTableFixups.Size; 36 inputbuffer >> ichCurr.VTableFixups.Size;
37 inputbuffer >> ichCurr.ExportAddressTableJumps.VirtualAddress; 37 inputbuffer >> ichCurr.ExportAddressTableJumps.VirtualAddress;
38 inputbuffer >> ichCurr.ExportAddressTableJumps.Size; 38 inputbuffer >> ichCurr.ExportAddressTableJumps.Size;
39 inputbuffer >> ichCurr.ManagedNativeHeader.VirtualAddress; 39 inputbuffer >> ichCurr.ManagedNativeHeader.VirtualAddress;
40 inputbuffer >> ichCurr.ManagedNativeHeader.Size; 40 inputbuffer >> ichCurr.ManagedNativeHeader.Size;
41 41
42 std::swap(ichCurr, m_ichComHeader); 42 std::swap(ichCurr, m_ichComHeader);
43 } 43 }
44 44
45 int ComHeaderDirectory::read(unsigned char* buffer, unsigned int buffersize) 45 int ComHeaderDirectory::read(unsigned char* buffer, unsigned int buffersize)
46 { 46 {
47 if (buffersize < PELIB_IMAGE_COR20_HEADER::size()) 47 if (buffersize < PELIB_IMAGE_COR20_HEADER::size())
48 { 48 {
49 return ERROR_INVALID_FILE; 49 return ERROR_INVALID_FILE;
50 } 50 }
51 51
52 std::vector<byte> vComDescDirectory(buffer, buffer + buffersize); 52 std::vector<byte> vComDescDirectory(buffer, buffer + buffersize);
53 53
54 InputBuffer ibBuffer(vComDescDirectory); 54 InputBuffer ibBuffer(vComDescDirectory);
55 read(ibBuffer); 55 read(ibBuffer);
56 return NO_ERROR; 56 return NO_ERROR;
57 } 57 }
58 58
59 /** 59 /**
60 * Reads a file's COM+ descriptor. 60 * Reads a file's COM+ descriptor.
61 * @param strFilename Name of the file. 61 * @param strFilename Name of the file.
62 * @param uiOffset File offset of the COM+ descriptor. 62 * @param uiOffset File offset of the COM+ descriptor.
63 * @param uiSize Size of the COM+ descriptor. 63 * @param uiSize Size of the COM+ descriptor.
64 **/ 64 **/
65 int ComHeaderDirectory::read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize) 65 int ComHeaderDirectory::read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize)
66 { 66 {
67 std::ifstream ifFile(strFilename.c_str(), std::ios::binary); 67 std::ifstream ifFile(strFilename.c_str(), std::ios::binary);
68 unsigned int ulFileSize = fileSize(ifFile); 68 unsigned int ulFileSize = fileSize(ifFile);
69 69
70 if (!ifFile) 70 if (!ifFile)
71 { 71 {
72 return ERROR_OPENING_FILE; 72 return ERROR_OPENING_FILE;
73 } 73 }
74 74
75 if (ulFileSize < uiOffset + uiSize) 75 if (ulFileSize < uiOffset + uiSize)
76 { 76 {
77 return ERROR_INVALID_FILE; 77 return ERROR_INVALID_FILE;
78 } 78 }
79 79
80 ifFile.seekg(uiOffset, std::ios::beg); 80 ifFile.seekg(uiOffset, std::ios::beg);
81 81
82 std::vector<byte> vComDescDirectory(uiSize); 82 std::vector<byte> vComDescDirectory(uiSize);
83 ifFile.read(reinterpret_cast<char*>(&vComDescDirectory[0]), uiSize); 83 ifFile.read(reinterpret_cast<char*>(&vComDescDirectory[0]), uiSize);
84 84
85 InputBuffer ibBuffer(vComDescDirectory); 85 InputBuffer ibBuffer(vComDescDirectory);
86 read(ibBuffer); 86 read(ibBuffer);
87 return NO_ERROR; 87 return NO_ERROR;
88 } 88 }
89 89
90 /** 90 /**
91 * Rebuilds the current COM+ descriptor. 91 * Rebuilds the current COM+ descriptor.
92 * @param vBuffer Buffer where the COM+ descriptor will be written to. 92 * @param vBuffer Buffer where the COM+ descriptor will be written to.
93 **/ 93 **/
94 void ComHeaderDirectory::rebuild(std::vector<byte>& vBuffer) const 94 void ComHeaderDirectory::rebuild(std::vector<byte>& vBuffer) const
95 { 95 {
96 OutputBuffer obBuffer(vBuffer); 96 OutputBuffer obBuffer(vBuffer);
97 97
98 obBuffer << m_ichComHeader.cb; 98 obBuffer << m_ichComHeader.cb;
99 obBuffer << m_ichComHeader.MajorRuntimeVersion; 99 obBuffer << m_ichComHeader.MajorRuntimeVersion;
100 obBuffer << m_ichComHeader.MinorRuntimeVersion; 100 obBuffer << m_ichComHeader.MinorRuntimeVersion;
101 obBuffer << m_ichComHeader.MetaData.VirtualAddress; 101 obBuffer << m_ichComHeader.MetaData.VirtualAddress;
102 obBuffer << m_ichComHeader.MetaData.Size; 102 obBuffer << m_ichComHeader.MetaData.Size;
103 obBuffer << m_ichComHeader.Flags; 103 obBuffer << m_ichComHeader.Flags;
104 obBuffer << m_ichComHeader.EntryPointToken; 104 obBuffer << m_ichComHeader.EntryPointToken;
105 obBuffer << m_ichComHeader.Resources.VirtualAddress; 105 obBuffer << m_ichComHeader.Resources.VirtualAddress;
106 obBuffer << m_ichComHeader.Resources.Size; 106 obBuffer << m_ichComHeader.Resources.Size;
107 obBuffer << m_ichComHeader.StrongNameSignature.VirtualAddress; 107 obBuffer << m_ichComHeader.StrongNameSignature.VirtualAddress;
108 obBuffer << m_ichComHeader.StrongNameSignature.Size; 108 obBuffer << m_ichComHeader.StrongNameSignature.Size;
109 obBuffer << m_ichComHeader.CodeManagerTable.VirtualAddress; 109 obBuffer << m_ichComHeader.CodeManagerTable.VirtualAddress;
110 obBuffer << m_ichComHeader.CodeManagerTable.Size; 110 obBuffer << m_ichComHeader.CodeManagerTable.Size;
111 obBuffer << m_ichComHeader.VTableFixups.VirtualAddress; 111 obBuffer << m_ichComHeader.VTableFixups.VirtualAddress;
112 obBuffer << m_ichComHeader.VTableFixups.Size; 112 obBuffer << m_ichComHeader.VTableFixups.Size;
113 obBuffer << m_ichComHeader.ExportAddressTableJumps.VirtualAddress; 113 obBuffer << m_ichComHeader.ExportAddressTableJumps.VirtualAddress;
114 obBuffer << m_ichComHeader.ExportAddressTableJumps.Size; 114 obBuffer << m_ichComHeader.ExportAddressTableJumps.Size;
115 obBuffer << m_ichComHeader.ManagedNativeHeader.VirtualAddress; 115 obBuffer << m_ichComHeader.ManagedNativeHeader.VirtualAddress;
116 obBuffer << m_ichComHeader.ManagedNativeHeader.Size; 116 obBuffer << m_ichComHeader.ManagedNativeHeader.Size;
117 } 117 }
118 118
119 /** 119 /**
120 * @return Size in bytes. 120 * @return Size in bytes.
121 **/ 121 **/
122 unsigned int ComHeaderDirectory::size() const 122 unsigned int ComHeaderDirectory::size() const
123 { 123 {
124 return PELIB_IMAGE_COR20_HEADER::size(); 124 return PELIB_IMAGE_COR20_HEADER::size();
125 } 125 }
126 126
127 /** 127 /**
128 * @param strFilename Name of the file. 128 * @param strFilename Name of the file.
129 * @param dwOffset File offset the COM+ descriptor will be written to. 129 * @param dwOffset File offset the COM+ descriptor will be written to.
130 **/ 130 **/
131 int ComHeaderDirectory::write(const std::string& strFilename, unsigned int dwOffset) const 131 int ComHeaderDirectory::write(const std::string& strFilename, unsigned int dwOffset) const
132 { 132 {
133 std::fstream ofFile(strFilename.c_str(), std::ios_base::in); 133 std::fstream ofFile(strFilename.c_str(), std::ios_base::in);
134 134
135 if (!ofFile) 135 if (!ofFile)
136 { 136 {
137 ofFile.clear(); 137 ofFile.clear();
138 ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary); 138 ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary);
139 } 139 }
140 else 140 else
141 { 141 {
142 ofFile.close(); 142 ofFile.close();
143 ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary); 143 ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary);
144 } 144 }
145 145
146 if (!ofFile) 146 if (!ofFile)
147 { 147 {
148 return ERROR_OPENING_FILE; 148 return ERROR_OPENING_FILE;
149 } 149 }
150 150
151 ofFile.seekp(dwOffset, std::ios::beg); 151 ofFile.seekp(dwOffset, std::ios::beg);
152 152
153 std::vector<unsigned char> vBuffer; 153 std::vector<unsigned char> vBuffer;
154 rebuild(vBuffer); 154 rebuild(vBuffer);
155 155
156 ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), static_cast<unsigned int>(vBuffer.size())); 156 ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), static_cast<unsigned int>(vBuffer.size()));
157 157
158 ofFile.close(); 158 ofFile.close();
159 159
160 return NO_ERROR; 160 return NO_ERROR;
161 } 161 }
162 162
163 /** 163 /**
164 * @return SizeOfHeader value of the current COM+ descriptor. 164 * @return SizeOfHeader value of the current COM+ descriptor.
165 **/ 165 **/
166 dword ComHeaderDirectory::getSizeOfHeader() const 166 dword ComHeaderDirectory::getSizeOfHeader() const
167 { 167 {
168 return m_ichComHeader.cb; 168 return m_ichComHeader.cb;
169 } 169 }
170 170
171 /** 171 /**
172 * @return MajorRuntimeVersion value of the current COM+ descriptor. 172 * @return MajorRuntimeVersion value of the current COM+ descriptor.
173 **/ 173 **/
174 word ComHeaderDirectory::getMajorRuntimeVersion() const 174 word ComHeaderDirectory::getMajorRuntimeVersion() const
175 { 175 {
176 return m_ichComHeader.MajorRuntimeVersion; 176 return m_ichComHeader.MajorRuntimeVersion;
177 } 177 }
178 178
179 /** 179 /**
180 * @return MinorRuntimeVersion value of the current COM+ descriptor. 180 * @return MinorRuntimeVersion value of the current COM+ descriptor.
181 **/ 181 **/
182 word ComHeaderDirectory::getMinorRuntimeVersion() const 182 word ComHeaderDirectory::getMinorRuntimeVersion() const
183 { 183 {
184 return m_ichComHeader.MinorRuntimeVersion; 184 return m_ichComHeader.MinorRuntimeVersion;
185 } 185 }
186 186
187 /** 187 /**
188 * @return MetaData (Virtual Address) value of the current COM+ descriptor. 188 * @return MetaData (Virtual Address) value of the current COM+ descriptor.
189 **/ 189 **/
190 dword ComHeaderDirectory::getMetaDataVa() const 190 dword ComHeaderDirectory::getMetaDataVa() const
191 { 191 {
192 return m_ichComHeader.MetaData.VirtualAddress; 192 return m_ichComHeader.MetaData.VirtualAddress;
193 } 193 }
194 194
195 /** 195 /**
196 * @return MetaData (Size) value of the current COM+ descriptor. 196 * @return MetaData (Size) value of the current COM+ descriptor.
197 **/ 197 **/
198 dword ComHeaderDirectory::getMetaDataSize() const 198 dword ComHeaderDirectory::getMetaDataSize() const
199 { 199 {
200 return m_ichComHeader.MetaData.Size; 200 return m_ichComHeader.MetaData.Size;
201 } 201 }
202 202
203 /** 203 /**
204 * @return Flags value of the current COM+ descriptor. 204 * @return Flags value of the current COM+ descriptor.
205 **/ 205 **/
206 dword ComHeaderDirectory::getFlags() const 206 dword ComHeaderDirectory::getFlags() const
207 { 207 {
208 return m_ichComHeader.Flags; 208 return m_ichComHeader.Flags;
209 } 209 }
210 210
211 /** 211 /**
212 * @return EntryPointToken value of the current COM+ descriptor. 212 * @return EntryPointToken value of the current COM+ descriptor.
213 **/ 213 **/
214 dword ComHeaderDirectory::getEntryPointToken() const 214 dword ComHeaderDirectory::getEntryPointToken() const
215 { 215 {
216 return m_ichComHeader.EntryPointToken; 216 return m_ichComHeader.EntryPointToken;
217 } 217 }
218 218
219 /** 219 /**
220 * @return Resources (Virtual Address) value of the current COM+ descriptor. 220 * @return Resources (Virtual Address) value of the current COM+ descriptor.
221 **/ 221 **/
222 dword ComHeaderDirectory::getResourcesVa() const 222 dword ComHeaderDirectory::getResourcesVa() const
223 { 223 {
224 return m_ichComHeader.Resources.VirtualAddress; 224 return m_ichComHeader.Resources.VirtualAddress;
225 } 225 }
226 226
227 /** 227 /**
228 * @return Resources (Size) value of the current COM+ descriptor. 228 * @return Resources (Size) value of the current COM+ descriptor.
229 **/ 229 **/
230 dword ComHeaderDirectory::getResourcesSize() 230 dword ComHeaderDirectory::getResourcesSize()
231 { 231 {
232 return m_ichComHeader.Resources.Size; 232 return m_ichComHeader.Resources.Size;
233 } 233 }
234 234
235 /** 235 /**
236 * @return StrongNameSignature (Virtual Address) value of the current COM+ descriptor. 236 * @return StrongNameSignature (Virtual Address) value of the current COM+ descriptor.
237 **/ 237 **/
238 dword ComHeaderDirectory::getStrongNameSignatureVa() const 238 dword ComHeaderDirectory::getStrongNameSignatureVa() const
239 { 239 {
240 return m_ichComHeader.StrongNameSignature.VirtualAddress; 240 return m_ichComHeader.StrongNameSignature.VirtualAddress;
241 } 241 }
242 242
243 /** 243 /**
244 * @return StrongNameSignature (Size) value of the current COM+ descriptor. 244 * @return StrongNameSignature (Size) value of the current COM+ descriptor.
245 **/ 245 **/
246 dword ComHeaderDirectory::getStrongNameSignagureSize() const 246 dword ComHeaderDirectory::getStrongNameSignagureSize() const
247 { 247 {
248 return m_ichComHeader.StrongNameSignature.Size; 248 return m_ichComHeader.StrongNameSignature.Size;
249 } 249 }
250 250
251 /** 251 /**
252 * @return CodeManagerTable (Virtual Address) value of the current COM+ descriptor. 252 * @return CodeManagerTable (Virtual Address) value of the current COM+ descriptor.
253 **/ 253 **/
254 dword ComHeaderDirectory::getCodeManagerTableVa() const 254 dword ComHeaderDirectory::getCodeManagerTableVa() const
255 { 255 {
256 return m_ichComHeader.CodeManagerTable.VirtualAddress; 256 return m_ichComHeader.CodeManagerTable.VirtualAddress;
257 } 257 }
258 258
259 /** 259 /**
260 * @return CodeManagerTable (Size) value of the current COM+ descriptor. 260 * @return CodeManagerTable (Size) value of the current COM+ descriptor.
261 **/ 261 **/
262 dword ComHeaderDirectory::getCodeManagerTableSize() const 262 dword ComHeaderDirectory::getCodeManagerTableSize() const
263 { 263 {
264 return m_ichComHeader.CodeManagerTable.Size; 264 return m_ichComHeader.CodeManagerTable.Size;
265 } 265 }
266 266
267 /** 267 /**
268 * @return VTableFixups (Virtual Address) value of the current COM+ descriptor. 268 * @return VTableFixups (Virtual Address) value of the current COM+ descriptor.
269 **/ 269 **/
270 dword ComHeaderDirectory::getVTableFixupsVa() const 270 dword ComHeaderDirectory::getVTableFixupsVa() const
271 { 271 {
272 return m_ichComHeader.VTableFixups.VirtualAddress; 272 return m_ichComHeader.VTableFixups.VirtualAddress;
273 } 273 }
274 274
275 /** 275 /**
276 * @return VTableFixups (Size) value of the current COM+ descriptor. 276 * @return VTableFixups (Size) value of the current COM+ descriptor.
277 **/ 277 **/
278 dword ComHeaderDirectory::getVTableFixupsSize() const 278 dword ComHeaderDirectory::getVTableFixupsSize() const
279 { 279 {
280 return m_ichComHeader.VTableFixups.Size; 280 return m_ichComHeader.VTableFixups.Size;
281 } 281 }
282 282
283 /** 283 /**
284 * @return ExportAddressTableJumps (Virtual Address) value of the current COM+ descriptor. 284 * @return ExportAddressTableJumps (Virtual Address) value of the current COM+ descriptor.
285 **/ 285 **/
286 dword ComHeaderDirectory::getExportAddressTableJumpsVa() const 286 dword ComHeaderDirectory::getExportAddressTableJumpsVa() const
287 { 287 {
288 return m_ichComHeader.ExportAddressTableJumps.VirtualAddress; 288 return m_ichComHeader.ExportAddressTableJumps.VirtualAddress;
289 } 289 }
290 290
291 /** 291 /**
292 * @return ExportAddressTableJumps (Size) value of the current COM+ descriptor. 292 * @return ExportAddressTableJumps (Size) value of the current COM+ descriptor.
293 **/ 293 **/
294 dword ComHeaderDirectory::getExportAddressTableJumpsSize() const 294 dword ComHeaderDirectory::getExportAddressTableJumpsSize() const
295 { 295 {
296 return m_ichComHeader.ExportAddressTableJumps.Size; 296 return m_ichComHeader.ExportAddressTableJumps.Size;
297 } 297 }
298 298
299 /** 299 /**
300 * @return ManagedNativeHeader (Virtual Address) value of the current COM+ descriptor. 300 * @return ManagedNativeHeader (Virtual Address) value of the current COM+ descriptor.
301 **/ 301 **/
302 dword ComHeaderDirectory::getManagedNativeHeaderVa() const 302 dword ComHeaderDirectory::getManagedNativeHeaderVa() const
303 { 303 {
304 return m_ichComHeader.ManagedNativeHeader.VirtualAddress; 304 return m_ichComHeader.ManagedNativeHeader.VirtualAddress;
305 } 305 }
306 306
307 /** 307 /**
308 * @return ManagedNativeHeader (Size) value of the current COM+ descriptor. 308 * @return ManagedNativeHeader (Size) value of the current COM+ descriptor.
309 **/ 309 **/
310 dword ComHeaderDirectory::getManagedNativeHeaderSize() const 310 dword ComHeaderDirectory::getManagedNativeHeaderSize() const
311 { 311 {
312 return m_ichComHeader.ManagedNativeHeader.Size; 312 return m_ichComHeader.ManagedNativeHeader.Size;
313 } 313 }
314 314
315 /** 315 /**
316 * @param dwValue New value for the current SizeOfHeader (cb) value. 316 * @param dwValue New value for the current SizeOfHeader (cb) value.
317 **/ 317 **/
318 void ComHeaderDirectory::setSizeOfHeader(dword dwValue) 318 void ComHeaderDirectory::setSizeOfHeader(dword dwValue)
319 { 319 {
320 m_ichComHeader.cb = dwValue; 320 m_ichComHeader.cb = dwValue;
321 } 321 }
322 322
323 /** 323 /**
324 * @param wValue New value for the current MajorRuntimeVersion value. 324 * @param wValue New value for the current MajorRuntimeVersion value.
325 **/ 325 **/
326 void ComHeaderDirectory::setMajorRuntimeVersion(word wValue) 326 void ComHeaderDirectory::setMajorRuntimeVersion(word wValue)
327 { 327 {
328 m_ichComHeader.MajorRuntimeVersion = wValue; 328 m_ichComHeader.MajorRuntimeVersion = wValue;
329 } 329 }
330 330
331 /** 331 /**
332 * @param wValue New value for the current MinorRuntimeVersion value. 332 * @param wValue New value for the current MinorRuntimeVersion value.
333 **/ 333 **/
334 void ComHeaderDirectory::setMinorRuntimeVersion(word wValue) 334 void ComHeaderDirectory::setMinorRuntimeVersion(word wValue)
335 { 335 {
336 m_ichComHeader.MinorRuntimeVersion = wValue; 336 m_ichComHeader.MinorRuntimeVersion = wValue;
337 } 337 }
338 338
339 /** 339 /**
340 * @param dwValue New value for the current MetaData (VirtualAddress) value. 340 * @param dwValue New value for the current MetaData (VirtualAddress) value.
341 **/ 341 **/
342 void ComHeaderDirectory::setMetaDataVa(dword dwValue) 342 void ComHeaderDirectory::setMetaDataVa(dword dwValue)
343 { 343 {
344 m_ichComHeader.MetaData.VirtualAddress = dwValue; 344 m_ichComHeader.MetaData.VirtualAddress = dwValue;
345 } 345 }
346 346
347 /** 347 /**
348 * @param dwValue New value for the current MetaData (Size) value. 348 * @param dwValue New value for the current MetaData (Size) value.
349 **/ 349 **/
350 void ComHeaderDirectory::setMetaDataSize(dword dwValue) 350 void ComHeaderDirectory::setMetaDataSize(dword dwValue)
351 { 351 {
352 m_ichComHeader.MetaData.Size = dwValue; 352 m_ichComHeader.MetaData.Size = dwValue;
353 } 353 }
354 354
355 /** 355 /**
356 * @param dwValue New value for the current Flags value. 356 * @param dwValue New value for the current Flags value.
357 **/ 357 **/
358 void ComHeaderDirectory::setFlags(dword dwValue) 358 void ComHeaderDirectory::setFlags(dword dwValue)
359 { 359 {
360 m_ichComHeader.Flags = dwValue; 360 m_ichComHeader.Flags = dwValue;
361 } 361 }
362 362
363 /** 363 /**
364 * @param dwValue New value for the current EntryPointToken value. 364 * @param dwValue New value for the current EntryPointToken value.
365 **/ 365 **/
366 void ComHeaderDirectory::setEntryPointToken(dword dwValue) 366 void ComHeaderDirectory::setEntryPointToken(dword dwValue)
367 { 367 {
368 m_ichComHeader.EntryPointToken = dwValue; 368 m_ichComHeader.EntryPointToken = dwValue;
369 } 369 }
370 370
371 /** 371 /**
372 * @param dwValue New value for the current Resources (VirtualAddress) value. 372 * @param dwValue New value for the current Resources (VirtualAddress) value.
373 **/ 373 **/
374 void ComHeaderDirectory::setResourcesVa(dword dwValue) 374 void ComHeaderDirectory::setResourcesVa(dword dwValue)
375 { 375 {
376 m_ichComHeader.Resources.VirtualAddress = dwValue; 376 m_ichComHeader.Resources.VirtualAddress = dwValue;
377 } 377 }
378 378
379 /** 379 /**
380 * @param dwValue New value for the current Resources (Size) value. 380 * @param dwValue New value for the current Resources (Size) value.
381 **/ 381 **/
382 void ComHeaderDirectory::setResourcesSize(dword dwValue) 382 void ComHeaderDirectory::setResourcesSize(dword dwValue)
383 { 383 {
384 m_ichComHeader.Resources.Size = dwValue; 384 m_ichComHeader.Resources.Size = dwValue;
385 } 385 }
386 386
387 /** 387 /**
388 * @param dwValue New value for the current StrongNameSignature (VirtualAddress) value. 388 * @param dwValue New value for the current StrongNameSignature (VirtualAddress) value.
389 **/ 389 **/
390 void ComHeaderDirectory::setStrongNameSignatureVa(dword dwValue) 390 void ComHeaderDirectory::setStrongNameSignatureVa(dword dwValue)
391 { 391 {
392 m_ichComHeader.StrongNameSignature.VirtualAddress = dwValue; 392 m_ichComHeader.StrongNameSignature.VirtualAddress = dwValue;
393 } 393 }
394 394
395 /** 395 /**
396 * @param dwValue New value for the current StrongNameSignature (Size) value. 396 * @param dwValue New value for the current StrongNameSignature (Size) value.
397 **/ 397 **/
398 void ComHeaderDirectory::setStrongNameSignagureSize(dword dwValue) 398 void ComHeaderDirectory::setStrongNameSignagureSize(dword dwValue)
399 { 399 {
400 m_ichComHeader.StrongNameSignature.Size = dwValue; 400 m_ichComHeader.StrongNameSignature.Size = dwValue;
401 } 401 }
402 402
403 /** 403 /**
404 * @param dwValue New value for the current CodeManagerTable (VirtualAddress) value. 404 * @param dwValue New value for the current CodeManagerTable (VirtualAddress) value.
405 **/ 405 **/
406 void ComHeaderDirectory::setCodeManagerTableVa(dword dwValue) 406 void ComHeaderDirectory::setCodeManagerTableVa(dword dwValue)
407 { 407 {
408 m_ichComHeader.CodeManagerTable.VirtualAddress = dwValue; 408 m_ichComHeader.CodeManagerTable.VirtualAddress = dwValue;
409 } 409 }
410 410
411 /** 411 /**
412 * @param dwValue New value for the current CodeManagerTable (Size) value. 412 * @param dwValue New value for the current CodeManagerTable (Size) value.
413 **/ 413 **/
414 void ComHeaderDirectory::setCodeManagerTableSize(dword dwValue) 414 void ComHeaderDirectory::setCodeManagerTableSize(dword dwValue)
415 { 415 {
416 m_ichComHeader.CodeManagerTable.Size = dwValue; 416 m_ichComHeader.CodeManagerTable.Size = dwValue;
417 } 417 }
418 418
419 /** 419 /**
420 * @param dwValue New value for the current VTableFixups (VirtualAddress) value. 420 * @param dwValue New value for the current VTableFixups (VirtualAddress) value.
421 **/ 421 **/
422 void ComHeaderDirectory::setVTableFixupsVa(dword dwValue) 422 void ComHeaderDirectory::setVTableFixupsVa(dword dwValue)
423 { 423 {
424 m_ichComHeader.VTableFixups.VirtualAddress = dwValue; 424 m_ichComHeader.VTableFixups.VirtualAddress = dwValue;
425 } 425 }
426 426
427 /** 427 /**
428 * @param dwValue New value for the current VTableFixups (Size) value. 428 * @param dwValue New value for the current VTableFixups (Size) value.
429 **/ 429 **/
430 void ComHeaderDirectory::setVTableFixupsSize(dword dwValue) 430 void ComHeaderDirectory::setVTableFixupsSize(dword dwValue)
431 { 431 {
432 m_ichComHeader.VTableFixups.Size = dwValue; 432 m_ichComHeader.VTableFixups.Size = dwValue;
433 } 433 }
434 434
435 /** 435 /**
436 * @param dwValue New value for the current ExportAddressTableJumps (VirtualAddress) value. 436 * @param dwValue New value for the current ExportAddressTableJumps (VirtualAddress) value.
437 **/ 437 **/
438 void ComHeaderDirectory::setExportAddressTableJumpsVa(dword dwValue) 438 void ComHeaderDirectory::setExportAddressTableJumpsVa(dword dwValue)
439 { 439 {
440 m_ichComHeader.ExportAddressTableJumps.VirtualAddress = dwValue; 440 m_ichComHeader.ExportAddressTableJumps.VirtualAddress = dwValue;
441 } 441 }
442 442
443 /** 443 /**
444 * @param dwValue New value for the current ExportAddressTableJumps (Size) value. 444 * @param dwValue New value for the current ExportAddressTableJumps (Size) value.
445 **/ 445 **/
446 void ComHeaderDirectory::setExportAddressTableJumpsSize(dword dwValue) 446 void ComHeaderDirectory::setExportAddressTableJumpsSize(dword dwValue)
447 { 447 {
448 m_ichComHeader.ExportAddressTableJumps.Size = dwValue; 448 m_ichComHeader.ExportAddressTableJumps.Size = dwValue;
449 } 449 }
450 450
451 /** 451 /**
452 * @param dwValue New value for the current ManagedNativeHeader (VirtualAddress) value. 452 * @param dwValue New value for the current ManagedNativeHeader (VirtualAddress) value.
453 **/ 453 **/
454 void ComHeaderDirectory::setManagedNativeHeaderVa(dword dwValue) 454 void ComHeaderDirectory::setManagedNativeHeaderVa(dword dwValue)
455 { 455 {
456 m_ichComHeader.ManagedNativeHeader.VirtualAddress = dwValue; 456 m_ichComHeader.ManagedNativeHeader.VirtualAddress = dwValue;
457 } 457 }
458 458
459 /** 459 /**
460 * @param dwValue New value for the current ManagedNativeHeader (Size) value. 460 * @param dwValue New value for the current ManagedNativeHeader (Size) value.
461 **/ 461 **/
462 void ComHeaderDirectory::setManagedNativeHeaderSize(dword dwValue) 462 void ComHeaderDirectory::setManagedNativeHeaderSize(dword dwValue)
463 { 463 {
464 m_ichComHeader.ManagedNativeHeader.Size = dwValue; 464 m_ichComHeader.ManagedNativeHeader.Size = dwValue;
465 } 465 }
466 466
467} 467}
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/ComHeaderDirectory.h b/utils/zenutils/libraries/pelib-0.9/pelib/ComHeaderDirectory.h
index 915813c1cc..cdc993df1f 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/ComHeaderDirectory.h
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/ComHeaderDirectory.h
@@ -1,120 +1,120 @@
1/* 1/*
2* ComHeaderDirectory.h - Part of the PeLib library. 2* ComHeaderDirectory.h - Part of the PeLib library.
3* 3*
4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) 4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5* All rights reserved. 5* All rights reserved.
6* 6*
7* This software is licensed under the zlib/libpng License. 7* This software is licensed under the zlib/libpng License.
8* For more details see http://www.opensource.org/licenses/zlib-license.php 8* For more details see http://www.opensource.org/licenses/zlib-license.php
9* or the license information file (license.htm) in the root directory 9* or the license information file (license.htm) in the root directory
10* of PeLib. 10* of PeLib.
11*/ 11*/
12 12
13#ifndef COMHEADERDIRECTORY_H 13#ifndef COMHEADERDIRECTORY_H
14#define COMHEADERDIRECTORY_H 14#define COMHEADERDIRECTORY_H
15 15
16namespace PeLib 16namespace PeLib
17{ 17{
18 /// Class that handles the COM+ descriptor directory. 18 /// Class that handles the COM+ descriptor directory.
19 /** 19 /**
20 * This class handles the COM+ Descriptor directory which was added to PE files 20 * This class handles the COM+ Descriptor directory which was added to PE files
21 * which work with the .NET runtime modules. 21 * which work with the .NET runtime modules.
22 **/ 22 **/
23 class ComHeaderDirectory 23 class ComHeaderDirectory
24 { 24 {
25 private: 25 private:
26 PELIB_IMAGE_COR20_HEADER m_ichComHeader; ///< The COM+ descriptor. 26 PELIB_IMAGE_COR20_HEADER m_ichComHeader; ///< The COM+ descriptor.
27 27
28 void read(InputBuffer& inputbuffer); 28 void read(InputBuffer& inputbuffer);
29 29
30 public: 30 public:
31 /// Read a file's COM+ runtime descriptor directory. 31 /// Read a file's COM+ runtime descriptor directory.
32 int read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize); // EXPORT 32 int read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize); // EXPORT
33 int read(unsigned char* buffer, unsigned int buffersize); // EXPORT 33 int read(unsigned char* buffer, unsigned int buffersize); // EXPORT
34 /// Rebuild the COM+ descriptor. 34 /// Rebuild the COM+ descriptor.
35 void rebuild(std::vector<byte>& vBuffer) const; // EXPORT 35 void rebuild(std::vector<byte>& vBuffer) const; // EXPORT
36 /// Returns the size of the current COM+ descriptor. 36 /// Returns the size of the current COM+ descriptor.
37 unsigned int size() const; // EXPORT 37 unsigned int size() const; // EXPORT
38 /// Writes the current COM+ descriptor directory to a file. 38 /// Writes the current COM+ descriptor directory to a file.
39 int write(const std::string& strFilename, unsigned int dwOffset) const; // EXPORT 39 int write(const std::string& strFilename, unsigned int dwOffset) const; // EXPORT
40 40
41 /// Get the COM+ descriptor's SizeOfHeader (cb) value. 41 /// Get the COM+ descriptor's SizeOfHeader (cb) value.
42 dword getSizeOfHeader() const; // EXPORT 42 dword getSizeOfHeader() const; // EXPORT
43 /// Get the COM+ descriptor's MajorRuntimeVersion value. 43 /// Get the COM+ descriptor's MajorRuntimeVersion value.
44 word getMajorRuntimeVersion() const; // EXPORT 44 word getMajorRuntimeVersion() const; // EXPORT
45 /// Get the COM+ descriptor's MinorRuntimeVersion value. 45 /// Get the COM+ descriptor's MinorRuntimeVersion value.
46 word getMinorRuntimeVersion() const; // EXPORT 46 word getMinorRuntimeVersion() const; // EXPORT
47 /// Get the COM+ descriptor's MetaData (Virtual Address) value. 47 /// Get the COM+ descriptor's MetaData (Virtual Address) value.
48 dword getMetaDataVa() const; // EXPORT 48 dword getMetaDataVa() const; // EXPORT
49 /// Get the COM+ descriptor's MetaData (Size) value. 49 /// Get the COM+ descriptor's MetaData (Size) value.
50 dword getMetaDataSize() const; // EXPORT 50 dword getMetaDataSize() const; // EXPORT
51 /// Get the COM+ descriptor's Flags value. 51 /// Get the COM+ descriptor's Flags value.
52 dword getFlags() const; // EXPORT 52 dword getFlags() const; // EXPORT
53 /// Get the COM+ descriptor's EntryPointToken value. 53 /// Get the COM+ descriptor's EntryPointToken value.
54 dword getEntryPointToken() const; // EXPORT 54 dword getEntryPointToken() const; // EXPORT
55 /// Get the COM+ descriptor's Resources (Virtual Address) value. 55 /// Get the COM+ descriptor's Resources (Virtual Address) value.
56 dword getResourcesVa() const; // EXPORT 56 dword getResourcesVa() const; // EXPORT
57 /// Get the COM+ descriptor's Resources (Size) value. 57 /// Get the COM+ descriptor's Resources (Size) value.
58 dword getResourcesSize(); // EXPORT 58 dword getResourcesSize(); // EXPORT
59 /// Get the COM+ descriptor's StrongNameSignature (Virtual Address) value. 59 /// Get the COM+ descriptor's StrongNameSignature (Virtual Address) value.
60 dword getStrongNameSignatureVa() const; // EXPORT 60 dword getStrongNameSignatureVa() const; // EXPORT
61 /// Get the COM+ descriptor's StrongNameSignature (Size) value. 61 /// Get the COM+ descriptor's StrongNameSignature (Size) value.
62 dword getStrongNameSignagureSize() const; // EXPORT 62 dword getStrongNameSignagureSize() const; // EXPORT
63 /// Get the COM+ descriptor's CodeManagerTable (Virtual Address) value. 63 /// Get the COM+ descriptor's CodeManagerTable (Virtual Address) value.
64 dword getCodeManagerTableVa() const; // EXPORT 64 dword getCodeManagerTableVa() const; // EXPORT
65 /// Get the COM+ descriptor's CodeManagerTable (Size) value. 65 /// Get the COM+ descriptor's CodeManagerTable (Size) value.
66 dword getCodeManagerTableSize() const; // EXPORT 66 dword getCodeManagerTableSize() const; // EXPORT
67 /// Get the COM+ descriptor's VTableFixup (Virtual Address) value. 67 /// Get the COM+ descriptor's VTableFixup (Virtual Address) value.
68 dword getVTableFixupsVa() const; // EXPORT 68 dword getVTableFixupsVa() const; // EXPORT
69 /// Get the COM+ descriptor's VTableFixup (Size) value. 69 /// Get the COM+ descriptor's VTableFixup (Size) value.
70 dword getVTableFixupsSize() const; // EXPORT 70 dword getVTableFixupsSize() const; // EXPORT
71 /// Get the COM+ descriptor's ExportAddressTable (Virtual Address) value. 71 /// Get the COM+ descriptor's ExportAddressTable (Virtual Address) value.
72 dword getExportAddressTableJumpsVa() const; // EXPORT 72 dword getExportAddressTableJumpsVa() const; // EXPORT
73 /// Get the COM+ descriptor's ExportAddressTable (Size) value. 73 /// Get the COM+ descriptor's ExportAddressTable (Size) value.
74 dword getExportAddressTableJumpsSize() const; // EXPORT 74 dword getExportAddressTableJumpsSize() const; // EXPORT
75 /// Get the COM+ descriptor's ManagedNativeHeader (Virtual Address) value. 75 /// Get the COM+ descriptor's ManagedNativeHeader (Virtual Address) value.
76 dword getManagedNativeHeaderVa() const; // EXPORT 76 dword getManagedNativeHeaderVa() const; // EXPORT
77 /// Get the COM+ descriptor's ManagedNativeHeader (Size) value. 77 /// Get the COM+ descriptor's ManagedNativeHeader (Size) value.
78 dword getManagedNativeHeaderSize() const; // EXPORT 78 dword getManagedNativeHeaderSize() const; // EXPORT
79 79
80 /// Change the COM+ descriptor's SizeOfHeader (cb) value. 80 /// Change the COM+ descriptor's SizeOfHeader (cb) value.
81 void setSizeOfHeader(dword dwValue); // EXPORT 81 void setSizeOfHeader(dword dwValue); // EXPORT
82 /// Change the COM+ descriptor's MajorRuntimeVersion value. 82 /// Change the COM+ descriptor's MajorRuntimeVersion value.
83 void setMajorRuntimeVersion(word wValue); // EXPORT 83 void setMajorRuntimeVersion(word wValue); // EXPORT
84 /// Change the COM+ descriptor's MinorRuntimeVersion value. 84 /// Change the COM+ descriptor's MinorRuntimeVersion value.
85 void setMinorRuntimeVersion(word wValue); // EXPORT 85 void setMinorRuntimeVersion(word wValue); // EXPORT
86 /// Change the COM+ descriptor's MetaData (VirtualAddress) value. 86 /// Change the COM+ descriptor's MetaData (VirtualAddress) value.
87 void setMetaDataVa(dword dwValue); // EXPORT 87 void setMetaDataVa(dword dwValue); // EXPORT
88 /// Change the COM+ descriptor's MetaData (Size) value. 88 /// Change the COM+ descriptor's MetaData (Size) value.
89 void setMetaDataSize(dword dwValue); // EXPORT 89 void setMetaDataSize(dword dwValue); // EXPORT
90 /// Change the COM+ descriptor's Flags value. 90 /// Change the COM+ descriptor's Flags value.
91 void setFlags(dword dwValue); // EXPORT 91 void setFlags(dword dwValue); // EXPORT
92 /// Change the COM+ descriptor's EntryPointToken value. 92 /// Change the COM+ descriptor's EntryPointToken value.
93 void setEntryPointToken(dword dwValue); // EXPORT 93 void setEntryPointToken(dword dwValue); // EXPORT
94 /// Change the COM+ descriptor's Resources (VirtualAddress) value. 94 /// Change the COM+ descriptor's Resources (VirtualAddress) value.
95 void setResourcesVa(dword dwValue); // EXPORT 95 void setResourcesVa(dword dwValue); // EXPORT
96 /// Change the COM+ descriptor's Resources (Size) value. 96 /// Change the COM+ descriptor's Resources (Size) value.
97 void setResourcesSize(dword dwValue); // EXPORT 97 void setResourcesSize(dword dwValue); // EXPORT
98 /// Change the COM+ descriptor's StrongNameSignatureVa (VirtualAddress) value. 98 /// Change the COM+ descriptor's StrongNameSignatureVa (VirtualAddress) value.
99 void setStrongNameSignatureVa(dword dwValue); // EXPORT 99 void setStrongNameSignatureVa(dword dwValue); // EXPORT
100 /// Change the COM+ descriptor's StrongNameSignatureVa (Size) value. 100 /// Change the COM+ descriptor's StrongNameSignatureVa (Size) value.
101 void setStrongNameSignagureSize(dword dwValue); // EXPORT 101 void setStrongNameSignagureSize(dword dwValue); // EXPORT
102 /// Change the COM+ descriptor's CodeManagerTable (VirtualAddress) value. 102 /// Change the COM+ descriptor's CodeManagerTable (VirtualAddress) value.
103 void setCodeManagerTableVa(dword dwValue); // EXPORT 103 void setCodeManagerTableVa(dword dwValue); // EXPORT
104 /// Change the COM+ descriptor's CodeManagerTable (Size) value. 104 /// Change the COM+ descriptor's CodeManagerTable (Size) value.
105 void setCodeManagerTableSize(dword dwValue); // EXPORT 105 void setCodeManagerTableSize(dword dwValue); // EXPORT
106 /// Change the COM+ descriptor's VTableFixups (VirtualAddress) value. 106 /// Change the COM+ descriptor's VTableFixups (VirtualAddress) value.
107 void setVTableFixupsVa(dword dwValue); // EXPORT 107 void setVTableFixupsVa(dword dwValue); // EXPORT
108 /// Change the COM+ descriptor's VTableFixups (Size) value. 108 /// Change the COM+ descriptor's VTableFixups (Size) value.
109 void setVTableFixupsSize(dword dwValue); // EXPORT 109 void setVTableFixupsSize(dword dwValue); // EXPORT
110 /// Change the COM+ descriptor's ExportAddressTableJumps (VirtualAddress) value. 110 /// Change the COM+ descriptor's ExportAddressTableJumps (VirtualAddress) value.
111 void setExportAddressTableJumpsVa(dword dwValue); // EXPORT 111 void setExportAddressTableJumpsVa(dword dwValue); // EXPORT
112 /// Change the COM+ descriptor's ExportAddressTableJumps (Size) value. 112 /// Change the COM+ descriptor's ExportAddressTableJumps (Size) value.
113 void setExportAddressTableJumpsSize(dword dwValue); // EXPORT 113 void setExportAddressTableJumpsSize(dword dwValue); // EXPORT
114 /// Change the COM+ descriptor's ManagedNativeHeader (VirtualAddress) value. 114 /// Change the COM+ descriptor's ManagedNativeHeader (VirtualAddress) value.
115 void setManagedNativeHeaderVa(dword dwValue); // EXPORT 115 void setManagedNativeHeaderVa(dword dwValue); // EXPORT
116 /// Change the COM+ descriptor's ManagedNativeHeader (Size) value. 116 /// Change the COM+ descriptor's ManagedNativeHeader (Size) value.
117 void setManagedNativeHeaderSize(dword dwValue); // EXPORT 117 void setManagedNativeHeaderSize(dword dwValue); // EXPORT
118 }; 118 };
119} 119}
120#endif 120#endif
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/DebugDirectory.cpp b/utils/zenutils/libraries/pelib-0.9/pelib/DebugDirectory.cpp
index eb3d5c5600..9a91c7b18c 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/DebugDirectory.cpp
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/DebugDirectory.cpp
@@ -1,383 +1,383 @@
1/* 1/*
2* DebugDirectory.cpp - Part of the PeLib library. 2* DebugDirectory.cpp - Part of the PeLib library.
3* 3*
4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) 4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5* All rights reserved. 5* All rights reserved.
6* 6*
7* This software is licensed under the zlib/libpng License. 7* This software is licensed under the zlib/libpng License.
8* For more details see http://www.opensource.org/licenses/zlib-license.php 8* For more details see http://www.opensource.org/licenses/zlib-license.php
9* or the license information file (license.htm) in the root directory 9* or the license information file (license.htm) in the root directory
10* of PeLib. 10* of PeLib.
11*/ 11*/
12 12
13#include "PeLibInc.h" 13#include "PeLibInc.h"
14#include "DebugDirectory.h" 14#include "DebugDirectory.h"
15 15
16namespace PeLib 16namespace PeLib
17{ 17{
18 void DebugDirectory::clear() 18 void DebugDirectory::clear()
19 { 19 {
20 m_vDebugInfo.clear(); 20 m_vDebugInfo.clear();
21 } 21 }
22 22
23 std::vector<PELIB_IMG_DEBUG_DIRECTORY> DebugDirectory::read(InputBuffer& ibBuffer, unsigned int uiSize) 23 std::vector<PELIB_IMG_DEBUG_DIRECTORY> DebugDirectory::read(InputBuffer& ibBuffer, unsigned int uiSize)
24 { 24 {
25 std::vector<PELIB_IMG_DEBUG_DIRECTORY> currDebugInfo; 25 std::vector<PELIB_IMG_DEBUG_DIRECTORY> currDebugInfo;
26 26
27 PELIB_IMG_DEBUG_DIRECTORY iddCurr; 27 PELIB_IMG_DEBUG_DIRECTORY iddCurr;
28 28
29 for (unsigned int i=0;i<uiSize/PELIB_IMAGE_DEBUG_DIRECTORY::size();i++) 29 for (unsigned int i=0;i<uiSize/PELIB_IMAGE_DEBUG_DIRECTORY::size();i++)
30 { 30 {
31 31
32 ibBuffer >> iddCurr.idd.Characteristics; 32 ibBuffer >> iddCurr.idd.Characteristics;
33 ibBuffer >> iddCurr.idd.TimeDateStamp; 33 ibBuffer >> iddCurr.idd.TimeDateStamp;
34 ibBuffer >> iddCurr.idd.MajorVersion; 34 ibBuffer >> iddCurr.idd.MajorVersion;
35 ibBuffer >> iddCurr.idd.MinorVersion; 35 ibBuffer >> iddCurr.idd.MinorVersion;
36 ibBuffer >> iddCurr.idd.Type; 36 ibBuffer >> iddCurr.idd.Type;
37 ibBuffer >> iddCurr.idd.SizeOfData; 37 ibBuffer >> iddCurr.idd.SizeOfData;
38 ibBuffer >> iddCurr.idd.AddressOfRawData; 38 ibBuffer >> iddCurr.idd.AddressOfRawData;
39 ibBuffer >> iddCurr.idd.PointerToRawData; 39 ibBuffer >> iddCurr.idd.PointerToRawData;
40 40
41 currDebugInfo.push_back(iddCurr); 41 currDebugInfo.push_back(iddCurr);
42 } 42 }
43 43
44 return currDebugInfo; 44 return currDebugInfo;
45 } 45 }
46 46
47 int DebugDirectory::read(unsigned char* buffer, unsigned int buffersize) 47 int DebugDirectory::read(unsigned char* buffer, unsigned int buffersize)
48 { 48 {
49 // XXX: Note, debug data is not read at all. This might or might not change 49 // XXX: Note, debug data is not read at all. This might or might not change
50 // in the future. 50 // in the future.
51 51
52 std::vector<byte> vDebugDirectory(buffer, buffer + buffersize); 52 std::vector<byte> vDebugDirectory(buffer, buffer + buffersize);
53 53
54 InputBuffer ibBuffer(vDebugDirectory); 54 InputBuffer ibBuffer(vDebugDirectory);
55 55
56 std::vector<PELIB_IMG_DEBUG_DIRECTORY> currDebugInfo = read(ibBuffer, buffersize); 56 std::vector<PELIB_IMG_DEBUG_DIRECTORY> currDebugInfo = read(ibBuffer, buffersize);
57 57
58 std::swap(currDebugInfo, m_vDebugInfo); 58 std::swap(currDebugInfo, m_vDebugInfo);
59 59
60 return NO_ERROR; 60 return NO_ERROR;
61 } 61 }
62 62
63 /** 63 /**
64 * @param strFilename Name of the file which will be read. 64 * @param strFilename Name of the file which will be read.
65 * @param uiOffset File offset of the Debug directory. 65 * @param uiOffset File offset of the Debug directory.
66 * @param uiSize Size of the Debug directory. 66 * @param uiSize Size of the Debug directory.
67 **/ 67 **/
68 int DebugDirectory::read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize) 68 int DebugDirectory::read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize)
69 { 69 {
70 std::ifstream ifFile(strFilename.c_str(), std::ios::binary); 70 std::ifstream ifFile(strFilename.c_str(), std::ios::binary);
71 unsigned int ulFileSize = fileSize(ifFile); 71 unsigned int ulFileSize = fileSize(ifFile);
72 72
73 if (!ifFile) 73 if (!ifFile)
74 { 74 {
75 return ERROR_OPENING_FILE; 75 return ERROR_OPENING_FILE;
76 } 76 }
77 77
78 if (ulFileSize < uiOffset + uiSize) 78 if (ulFileSize < uiOffset + uiSize)
79 { 79 {
80 return ERROR_INVALID_FILE; 80 return ERROR_INVALID_FILE;
81 } 81 }
82 82
83 ifFile.seekg(uiOffset, std::ios::beg); 83 ifFile.seekg(uiOffset, std::ios::beg);
84 84
85 std::vector<byte> vDebugDirectory(uiSize); 85 std::vector<byte> vDebugDirectory(uiSize);
86 ifFile.read(reinterpret_cast<char*>(&vDebugDirectory[0]), uiSize); 86 ifFile.read(reinterpret_cast<char*>(&vDebugDirectory[0]), uiSize);
87 87
88 InputBuffer ibBuffer(vDebugDirectory); 88 InputBuffer ibBuffer(vDebugDirectory);
89 89
90 std::vector<PELIB_IMG_DEBUG_DIRECTORY> currDebugInfo = read(ibBuffer, uiSize); 90 std::vector<PELIB_IMG_DEBUG_DIRECTORY> currDebugInfo = read(ibBuffer, uiSize);
91 91
92 for (unsigned int i=0;i<currDebugInfo.size();i++) 92 for (unsigned int i=0;i<currDebugInfo.size();i++)
93 { 93 {
94 ifFile.seekg(currDebugInfo[i].idd.PointerToRawData, std::ios::beg); 94 ifFile.seekg(currDebugInfo[i].idd.PointerToRawData, std::ios::beg);
95 currDebugInfo[i].data.resize(currDebugInfo[i].idd.SizeOfData); 95 currDebugInfo[i].data.resize(currDebugInfo[i].idd.SizeOfData);
96 ifFile.read(reinterpret_cast<char*>(&currDebugInfo[i].data[0]), currDebugInfo[i].idd.SizeOfData); 96 ifFile.read(reinterpret_cast<char*>(&currDebugInfo[i].data[0]), currDebugInfo[i].idd.SizeOfData);
97 if (!ifFile) return ERROR_INVALID_FILE; 97 if (!ifFile) return ERROR_INVALID_FILE;
98 } 98 }
99 99
100 std::swap(currDebugInfo, m_vDebugInfo); 100 std::swap(currDebugInfo, m_vDebugInfo);
101 101
102 return NO_ERROR; 102 return NO_ERROR;
103 } 103 }
104 104
105 /** 105 /**
106 * Rebuilds the current debug directory. 106 * Rebuilds the current debug directory.
107 * @param vBuffer Buffer where the rebuilt directory is stored. 107 * @param vBuffer Buffer where the rebuilt directory is stored.
108 **/ 108 **/
109 void DebugDirectory::rebuild(std::vector<byte>& vBuffer) const 109 void DebugDirectory::rebuild(std::vector<byte>& vBuffer) const
110 { 110 {
111 OutputBuffer obBuffer(vBuffer); 111 OutputBuffer obBuffer(vBuffer);
112 112
113 for (unsigned int i=0;i<m_vDebugInfo.size();i++) 113 for (unsigned int i=0;i<m_vDebugInfo.size();i++)
114 { 114 {
115 obBuffer << m_vDebugInfo[i].idd.Characteristics; 115 obBuffer << m_vDebugInfo[i].idd.Characteristics;
116 obBuffer << m_vDebugInfo[i].idd.TimeDateStamp; 116 obBuffer << m_vDebugInfo[i].idd.TimeDateStamp;
117 obBuffer << m_vDebugInfo[i].idd.MajorVersion; 117 obBuffer << m_vDebugInfo[i].idd.MajorVersion;
118 obBuffer << m_vDebugInfo[i].idd.MinorVersion; 118 obBuffer << m_vDebugInfo[i].idd.MinorVersion;
119 obBuffer << m_vDebugInfo[i].idd.Type; 119 obBuffer << m_vDebugInfo[i].idd.Type;
120 obBuffer << m_vDebugInfo[i].idd.SizeOfData; 120 obBuffer << m_vDebugInfo[i].idd.SizeOfData;
121 obBuffer << m_vDebugInfo[i].idd.AddressOfRawData; 121 obBuffer << m_vDebugInfo[i].idd.AddressOfRawData;
122 obBuffer << m_vDebugInfo[i].idd.PointerToRawData; 122 obBuffer << m_vDebugInfo[i].idd.PointerToRawData;
123 } 123 }
124 } 124 }
125 125
126 /** 126 /**
127 * @return Size of the debug directory. 127 * @return Size of the debug directory.
128 **/ 128 **/
129 unsigned int DebugDirectory::size() const 129 unsigned int DebugDirectory::size() const
130 { 130 {
131 return static_cast<unsigned int>(m_vDebugInfo.size()) * PELIB_IMAGE_DEBUG_DIRECTORY::size(); 131 return static_cast<unsigned int>(m_vDebugInfo.size()) * PELIB_IMAGE_DEBUG_DIRECTORY::size();
132 } 132 }
133 133
134 /** 134 /**
135 * @param strFilename Name of the file which will be written. 135 * @param strFilename Name of the file which will be written.
136 * @param uiOffset File offset where the debug directory will be stored. 136 * @param uiOffset File offset where the debug directory will be stored.
137 **/ 137 **/
138 int DebugDirectory::write(const std::string& strFilename, unsigned int uiOffset) const 138 int DebugDirectory::write(const std::string& strFilename, unsigned int uiOffset) const
139 { 139 {
140 std::fstream ofFile(strFilename.c_str(), std::ios_base::in); 140 std::fstream ofFile(strFilename.c_str(), std::ios_base::in);
141 141
142 if (!ofFile) 142 if (!ofFile)
143 { 143 {
144 ofFile.clear(); 144 ofFile.clear();
145 ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary); 145 ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary);
146 } 146 }
147 else 147 else
148 { 148 {
149 ofFile.close(); 149 ofFile.close();
150 ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary); 150 ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary);
151 } 151 }
152 152
153 if (!ofFile) 153 if (!ofFile)
154 { 154 {
155 return ERROR_OPENING_FILE; 155 return ERROR_OPENING_FILE;
156 } 156 }
157 157
158 ofFile.seekp(uiOffset, std::ios::beg); 158 ofFile.seekp(uiOffset, std::ios::beg);
159 159
160 std::vector<unsigned char> vBuffer; 160 std::vector<unsigned char> vBuffer;
161 rebuild(vBuffer); 161 rebuild(vBuffer);
162 162
163 ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), static_cast<unsigned int>(vBuffer.size())); 163 ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), static_cast<unsigned int>(vBuffer.size()));
164 164
165 ofFile.close(); 165 ofFile.close();
166 166
167 return NO_ERROR; 167 return NO_ERROR;
168 } 168 }
169 169
170 /** 170 /**
171 * @return Number of debug structures in the current Debug directory. 171 * @return Number of debug structures in the current Debug directory.
172 **/ 172 **/
173 unsigned int DebugDirectory::calcNumberOfEntries() const 173 unsigned int DebugDirectory::calcNumberOfEntries() const
174 { 174 {
175 return static_cast<unsigned int>(m_vDebugInfo.size()); 175 return static_cast<unsigned int>(m_vDebugInfo.size());
176 } 176 }
177 177
178 /** 178 /**
179 * Adds a new debug structure to the debug directory. The initial values of all members of the structure 179 * Adds a new debug structure to the debug directory. The initial values of all members of the structure
180 * are undefined. 180 * are undefined.
181 **/ 181 **/
182 void DebugDirectory::addEntry() 182 void DebugDirectory::addEntry()
183 { 183 {
184 PELIB_IMG_DEBUG_DIRECTORY p; 184 PELIB_IMG_DEBUG_DIRECTORY p;
185 m_vDebugInfo.push_back(p); 185 m_vDebugInfo.push_back(p);
186 } 186 }
187 187
188 /** 188 /**
189 * Removes a debug structure from the current debug directory. If an invalid structure is specified 189 * Removes a debug structure from the current debug directory. If an invalid structure is specified
190 * by the parameter uiIndex the result will be undefined behaviour. 190 * by the parameter uiIndex the result will be undefined behaviour.
191 * @param uiIndex Identifies the debug structure. 191 * @param uiIndex Identifies the debug structure.
192 **/ 192 **/
193 void DebugDirectory::removeEntry(unsigned int uiIndex) 193 void DebugDirectory::removeEntry(unsigned int uiIndex)
194 { 194 {
195 m_vDebugInfo.erase(m_vDebugInfo.begin() + uiIndex); 195 m_vDebugInfo.erase(m_vDebugInfo.begin() + uiIndex);
196 } 196 }
197 197
198 /** 198 /**
199 * Returns the Characteristics value of a debug structure. If an invalid structure is specified 199 * Returns the Characteristics value of a debug structure. If an invalid structure is specified
200 * by the parameter uiIndex the result will be undefined behaviour. 200 * by the parameter uiIndex the result will be undefined behaviour.
201 * @param uiIndex Identifies the debug structure. 201 * @param uiIndex Identifies the debug structure.
202 * @return Characteristics value of the debug structure. 202 * @return Characteristics value of the debug structure.
203 **/ 203 **/
204 dword DebugDirectory::getCharacteristics(unsigned int uiIndex) const 204 dword DebugDirectory::getCharacteristics(unsigned int uiIndex) const
205 { 205 {
206 return m_vDebugInfo[uiIndex].idd.Characteristics; 206 return m_vDebugInfo[uiIndex].idd.Characteristics;
207 } 207 }
208 208
209 /** 209 /**
210 * Returns the TimeDateStamp value of a debug structure. If an invalid structure is specified 210 * Returns the TimeDateStamp value of a debug structure. If an invalid structure is specified
211 * by the parameter uiIndex the result will be undefined behaviour. 211 * by the parameter uiIndex the result will be undefined behaviour.
212 * @param uiIndex Identifies the debug structure. 212 * @param uiIndex Identifies the debug structure.
213 * @return TimeDateStamp value of the debug structure. 213 * @return TimeDateStamp value of the debug structure.
214 **/ 214 **/
215 dword DebugDirectory::getTimeDateStamp(unsigned int uiIndex) const 215 dword DebugDirectory::getTimeDateStamp(unsigned int uiIndex) const
216 { 216 {
217 return m_vDebugInfo[uiIndex].idd.TimeDateStamp; 217 return m_vDebugInfo[uiIndex].idd.TimeDateStamp;
218 } 218 }
219 219
220 /** 220 /**
221 * Returns the MajorVersion value of a debug structure. If an invalid structure is specified 221 * Returns the MajorVersion value of a debug structure. If an invalid structure is specified
222 * by the parameter uiIndex the result will be undefined behaviour. 222 * by the parameter uiIndex the result will be undefined behaviour.
223 * @param uiIndex Identifies the debug structure. 223 * @param uiIndex Identifies the debug structure.
224 * @return MajorVersion value of the debug structure. 224 * @return MajorVersion value of the debug structure.
225 **/ 225 **/
226 word DebugDirectory::getMajorVersion(unsigned int uiIndex) const 226 word DebugDirectory::getMajorVersion(unsigned int uiIndex) const
227 { 227 {
228 return m_vDebugInfo[uiIndex].idd.MajorVersion; 228 return m_vDebugInfo[uiIndex].idd.MajorVersion;
229 } 229 }
230 230
231 /** 231 /**
232 * Returns the MinorVersion value of a debug structure. If an invalid structure is specified 232 * Returns the MinorVersion value of a debug structure. If an invalid structure is specified
233 * by the parameter uiIndex the result will be undefined behaviour. 233 * by the parameter uiIndex the result will be undefined behaviour.
234 * @param uiIndex Identifies the debug structure. 234 * @param uiIndex Identifies the debug structure.
235 * @return MinorVersion value of the debug structure. 235 * @return MinorVersion value of the debug structure.
236 **/ 236 **/
237 word DebugDirectory::getMinorVersion(unsigned int uiIndex) const 237 word DebugDirectory::getMinorVersion(unsigned int uiIndex) const
238 { 238 {
239 return m_vDebugInfo[uiIndex].idd.MinorVersion; 239 return m_vDebugInfo[uiIndex].idd.MinorVersion;
240 } 240 }
241 241
242 /** 242 /**
243 * Returns the Type value of a debug structure. If an invalid structure is specified 243 * Returns the Type value of a debug structure. If an invalid structure is specified
244 * by the parameter uiIndex the result will be undefined behaviour. 244 * by the parameter uiIndex the result will be undefined behaviour.
245 * @param uiIndex Identifies the debug structure. 245 * @param uiIndex Identifies the debug structure.
246 * @return Type value of the debug structure. 246 * @return Type value of the debug structure.
247 **/ 247 **/
248 dword DebugDirectory::getType(unsigned int uiIndex) const 248 dword DebugDirectory::getType(unsigned int uiIndex) const
249 { 249 {
250 return m_vDebugInfo[uiIndex].idd.Type; 250 return m_vDebugInfo[uiIndex].idd.Type;
251 } 251 }
252 252
253 /** 253 /**
254 * Returns the SizeOfData value of a debug structure. If an invalid structure is specified 254 * Returns the SizeOfData value of a debug structure. If an invalid structure is specified
255 * by the parameter uiIndex the result will be undefined behaviour. 255 * by the parameter uiIndex the result will be undefined behaviour.
256 * @param uiIndex Identifies the debug structure. 256 * @param uiIndex Identifies the debug structure.
257 * @return SizeOfData value of the debug structure. 257 * @return SizeOfData value of the debug structure.
258 **/ 258 **/
259 dword DebugDirectory::getSizeOfData(unsigned int uiIndex) const 259 dword DebugDirectory::getSizeOfData(unsigned int uiIndex) const
260 { 260 {
261 return m_vDebugInfo[uiIndex].idd.SizeOfData; 261 return m_vDebugInfo[uiIndex].idd.SizeOfData;
262 } 262 }
263 263
264 /** 264 /**
265 * Returns the AddressOfRawData value of a debug structure. If an invalid structure is specified 265 * Returns the AddressOfRawData value of a debug structure. If an invalid structure is specified
266 * by the parameter uiIndex the result will be undefined behaviour. 266 * by the parameter uiIndex the result will be undefined behaviour.
267 * @param uiIndex Identifies the debug structure. 267 * @param uiIndex Identifies the debug structure.
268 * @return AddressOfRawData value of the debug structure. 268 * @return AddressOfRawData value of the debug structure.
269 **/ 269 **/
270 dword DebugDirectory::getAddressOfRawData(unsigned int uiIndex) const 270 dword DebugDirectory::getAddressOfRawData(unsigned int uiIndex) const
271 { 271 {
272 return m_vDebugInfo[uiIndex].idd.AddressOfRawData; 272 return m_vDebugInfo[uiIndex].idd.AddressOfRawData;
273 } 273 }
274 274
275 /** 275 /**
276 * Returns the PointerToRawData value of a debug structure. If an invalid structure is specified 276 * Returns the PointerToRawData value of a debug structure. If an invalid structure is specified
277 * by the parameter uiIndex the result will be undefined behaviour. 277 * by the parameter uiIndex the result will be undefined behaviour.
278 * @param uiIndex Identifies the debug structure. 278 * @param uiIndex Identifies the debug structure.
279 * @return PointerToRawData value of the debug structure. 279 * @return PointerToRawData value of the debug structure.
280 **/ 280 **/
281 dword DebugDirectory::getPointerToRawData(unsigned int uiIndex) const 281 dword DebugDirectory::getPointerToRawData(unsigned int uiIndex) const
282 { 282 {
283 return m_vDebugInfo[uiIndex].idd.PointerToRawData; 283 return m_vDebugInfo[uiIndex].idd.PointerToRawData;
284 } 284 }
285 285
286 std::vector<byte> DebugDirectory::getData(unsigned int index) const 286 std::vector<byte> DebugDirectory::getData(unsigned int index) const
287 { 287 {
288 return m_vDebugInfo[index].data; 288 return m_vDebugInfo[index].data;
289 } 289 }
290 290
291 /** 291 /**
292 * Changes the Characteristics value of a debug structure. If an invalid structure is specified 292 * Changes the Characteristics value of a debug structure. If an invalid structure is specified
293 * by the parameter uiIndex the result will be undefined behaviour. 293 * by the parameter uiIndex the result will be undefined behaviour.
294 * @param uiIndex Identifies the debug structure. 294 * @param uiIndex Identifies the debug structure.
295 * @param dwValue New value of the Characteristics value of the debug structure. 295 * @param dwValue New value of the Characteristics value of the debug structure.
296 **/ 296 **/
297 void DebugDirectory::setCharacteristics(unsigned int uiIndex, dword dwValue) 297 void DebugDirectory::setCharacteristics(unsigned int uiIndex, dword dwValue)
298 { 298 {
299 m_vDebugInfo[uiIndex].idd.Characteristics = dwValue; 299 m_vDebugInfo[uiIndex].idd.Characteristics = dwValue;
300 } 300 }
301 301
302 /** 302 /**
303 * Changes the TimeDateStamp value of a debug structure. If an invalid structure is specified 303 * Changes the TimeDateStamp value of a debug structure. If an invalid structure is specified
304 * by the parameter uiIndex the result will be undefined behaviour. 304 * by the parameter uiIndex the result will be undefined behaviour.
305 * @param uiIndex Identifies the debug structure. 305 * @param uiIndex Identifies the debug structure.
306 * @param dwValue New value of the TimeDateStamp value of the debug structure. 306 * @param dwValue New value of the TimeDateStamp value of the debug structure.
307 **/ 307 **/
308 void DebugDirectory::setTimeDateStamp(unsigned int uiIndex, dword dwValue) 308 void DebugDirectory::setTimeDateStamp(unsigned int uiIndex, dword dwValue)
309 { 309 {
310 m_vDebugInfo[uiIndex].idd.TimeDateStamp = dwValue; 310 m_vDebugInfo[uiIndex].idd.TimeDateStamp = dwValue;
311 } 311 }
312 312
313 /** 313 /**
314 * Changes the MajorVersion value of a debug structure. If an invalid structure is specified 314 * Changes the MajorVersion value of a debug structure. If an invalid structure is specified
315 * by the parameter uiIndex the result will be undefined behaviour. 315 * by the parameter uiIndex the result will be undefined behaviour.
316 * @param uiIndex Identifies the debug structure. 316 * @param uiIndex Identifies the debug structure.
317 * @param wValue New value of the MajorVersion value of the debug structure. 317 * @param wValue New value of the MajorVersion value of the debug structure.
318 **/ 318 **/
319 void DebugDirectory::setMajorVersion(unsigned int uiIndex, word wValue) 319 void DebugDirectory::setMajorVersion(unsigned int uiIndex, word wValue)
320 { 320 {
321 m_vDebugInfo[uiIndex].idd.MajorVersion = wValue; 321 m_vDebugInfo[uiIndex].idd.MajorVersion = wValue;
322 } 322 }
323 323
324 /** 324 /**
325 * Changes the MinorVersion value of a debug structure. If an invalid structure is specified 325 * Changes the MinorVersion value of a debug structure. If an invalid structure is specified
326 * by the parameter uiIndex the result will be undefined behaviour. 326 * by the parameter uiIndex the result will be undefined behaviour.
327 * @param uiIndex Identifies the debug structure. 327 * @param uiIndex Identifies the debug structure.
328 * @param wValue New value of the MinorVersion value of the debug structure. 328 * @param wValue New value of the MinorVersion value of the debug structure.
329 **/ 329 **/
330 void DebugDirectory::setMinorVersion(unsigned int uiIndex, word wValue) 330 void DebugDirectory::setMinorVersion(unsigned int uiIndex, word wValue)
331 { 331 {
332 m_vDebugInfo[uiIndex].idd.MinorVersion = wValue; 332 m_vDebugInfo[uiIndex].idd.MinorVersion = wValue;
333 } 333 }
334 334
335 /** 335 /**
336 * Changes the Type value of a debug structure. If an invalid structure is specified 336 * Changes the Type value of a debug structure. If an invalid structure is specified
337 * by the parameter uiIndex the result will be undefined behaviour. 337 * by the parameter uiIndex the result will be undefined behaviour.
338 * @param uiIndex Identifies the debug structure. 338 * @param uiIndex Identifies the debug structure.
339 * @param dwValue New value of the Type value of the debug structure. 339 * @param dwValue New value of the Type value of the debug structure.
340 **/ 340 **/
341 void DebugDirectory::setType(unsigned int uiIndex, dword dwValue) 341 void DebugDirectory::setType(unsigned int uiIndex, dword dwValue)
342 { 342 {
343 m_vDebugInfo[uiIndex].idd.Type = dwValue; 343 m_vDebugInfo[uiIndex].idd.Type = dwValue;
344 } 344 }
345 345
346 /** 346 /**
347 * Changes the SizeOfData value of a debug structure. If an invalid structure is specified 347 * Changes the SizeOfData value of a debug structure. If an invalid structure is specified
348 * by the parameter uiIndex the result will be undefined behaviour. 348 * by the parameter uiIndex the result will be undefined behaviour.
349 * @param uiIndex Identifies the debug structure. 349 * @param uiIndex Identifies the debug structure.
350 * @param dwValue New value of the SizeOfData value of the debug structure. 350 * @param dwValue New value of the SizeOfData value of the debug structure.
351 **/ 351 **/
352 void DebugDirectory::setSizeOfData(unsigned int uiIndex, dword dwValue) 352 void DebugDirectory::setSizeOfData(unsigned int uiIndex, dword dwValue)
353 { 353 {
354 m_vDebugInfo[uiIndex].idd.SizeOfData = dwValue; 354 m_vDebugInfo[uiIndex].idd.SizeOfData = dwValue;
355 } 355 }
356 356
357 /** 357 /**
358 * Changes the AddressOfRawData value of a debug structure. If an invalid structure is specified 358 * Changes the AddressOfRawData value of a debug structure. If an invalid structure is specified
359 * by the parameter uiIndex the result will be undefined behaviour. 359 * by the parameter uiIndex the result will be undefined behaviour.
360 * @param uiIndex Identifies the debug structure. 360 * @param uiIndex Identifies the debug structure.
361 * @param dwValue New value of the AddressOfRawData value of the debug structure. 361 * @param dwValue New value of the AddressOfRawData value of the debug structure.
362 **/ 362 **/
363 void DebugDirectory::setAddressOfRawData(unsigned int uiIndex, dword dwValue) 363 void DebugDirectory::setAddressOfRawData(unsigned int uiIndex, dword dwValue)
364 { 364 {
365 m_vDebugInfo[uiIndex].idd.AddressOfRawData = dwValue; 365 m_vDebugInfo[uiIndex].idd.AddressOfRawData = dwValue;
366 } 366 }
367 367
368 /** 368 /**
369 * Changes the PointerToRawData value of a debug structure. If an invalid structure is specified 369 * Changes the PointerToRawData value of a debug structure. If an invalid structure is specified
370 * by the parameter uiIndex the result will be undefined behaviour. 370 * by the parameter uiIndex the result will be undefined behaviour.
371 * @param uiIndex Identifies the debug structure. 371 * @param uiIndex Identifies the debug structure.
372 * @param dwValue New value of the PointerToRawData value of the debug structure. 372 * @param dwValue New value of the PointerToRawData value of the debug structure.
373 **/ 373 **/
374 void DebugDirectory::setPointerToRawData(unsigned int uiIndex, dword dwValue) 374 void DebugDirectory::setPointerToRawData(unsigned int uiIndex, dword dwValue)
375 { 375 {
376 m_vDebugInfo[uiIndex].idd.PointerToRawData = dwValue; 376 m_vDebugInfo[uiIndex].idd.PointerToRawData = dwValue;
377 } 377 }
378 378
379 void DebugDirectory::setData(unsigned int index, const std::vector<byte>& data) 379 void DebugDirectory::setData(unsigned int index, const std::vector<byte>& data)
380 { 380 {
381 m_vDebugInfo[index].data = data; 381 m_vDebugInfo[index].data = data;
382 } 382 }
383} 383}
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/DebugDirectory.h b/utils/zenutils/libraries/pelib-0.9/pelib/DebugDirectory.h
index 0ffda38815..adfef6b52e 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/DebugDirectory.h
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/DebugDirectory.h
@@ -1,84 +1,84 @@
1/* 1/*
2* DebugDirectory.h - Part of the PeLib library. 2* DebugDirectory.h - Part of the PeLib library.
3* 3*
4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) 4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5* All rights reserved. 5* All rights reserved.
6* 6*
7* This software is licensed under the zlib/libpng License. 7* This software is licensed under the zlib/libpng License.
8* For more details see http://www.opensource.org/licenses/zlib-license.php 8* For more details see http://www.opensource.org/licenses/zlib-license.php
9* or the license information file (license.htm) in the root directory 9* or the license information file (license.htm) in the root directory
10* of PeLib. 10* of PeLib.
11*/ 11*/
12 12
13#ifndef DEBUGDIRECTORY_H 13#ifndef DEBUGDIRECTORY_H
14#define DEBUGDIRECTORY_H 14#define DEBUGDIRECTORY_H
15 15
16namespace PeLib 16namespace PeLib
17{ 17{
18 /// Class that handles the Debug directory. 18 /// Class that handles the Debug directory.
19 class DebugDirectory 19 class DebugDirectory
20 { 20 {
21 private: 21 private:
22 /// Stores the various DebugDirectory structures. 22 /// Stores the various DebugDirectory structures.
23 std::vector<PELIB_IMG_DEBUG_DIRECTORY> m_vDebugInfo; 23 std::vector<PELIB_IMG_DEBUG_DIRECTORY> m_vDebugInfo;
24 24
25 std::vector<PELIB_IMG_DEBUG_DIRECTORY> read(InputBuffer& ibBuffer, unsigned int uiSize); 25 std::vector<PELIB_IMG_DEBUG_DIRECTORY> read(InputBuffer& ibBuffer, unsigned int uiSize);
26 26
27 public: 27 public:
28 void clear(); // EXPORT 28 void clear(); // EXPORT
29 /// Reads the Debug directory from a file. 29 /// Reads the Debug directory from a file.
30 int read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize); // EXPORT 30 int read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize); // EXPORT
31 int read(unsigned char* buffer, unsigned int buffersize); 31 int read(unsigned char* buffer, unsigned int buffersize);
32 /// Rebuilds the current Debug directory. 32 /// Rebuilds the current Debug directory.
33 void rebuild(std::vector<byte>& obBuffer) const; // EXPORT 33 void rebuild(std::vector<byte>& obBuffer) const; // EXPORT
34 /// Returns the size the current Debug directory needs after rebuilding. 34 /// Returns the size the current Debug directory needs after rebuilding.
35 unsigned int size() const; 35 unsigned int size() const;
36 /// Writes the current Debug directory back to a file. 36 /// Writes the current Debug directory back to a file.
37 int write(const std::string& strFilename, unsigned int uiOffset) const; // EXPORT 37 int write(const std::string& strFilename, unsigned int uiOffset) const; // EXPORT
38 38
39 /// Returns the number of DebugDirectory image structures in the current DebugDirectory. 39 /// Returns the number of DebugDirectory image structures in the current DebugDirectory.
40 unsigned int calcNumberOfEntries() const; // EXPORT 40 unsigned int calcNumberOfEntries() const; // EXPORT
41 41
42 /// Adds a new debug structure. 42 /// Adds a new debug structure.
43 void addEntry(); // EXPORT 43 void addEntry(); // EXPORT
44 /// Removes a debug structure. 44 /// Removes a debug structure.
45 void removeEntry(unsigned int uiIndex); // EXPORT 45 void removeEntry(unsigned int uiIndex); // EXPORT
46 46
47 /// Returns the Characteristics value of a debug structure. 47 /// Returns the Characteristics value of a debug structure.
48 dword getCharacteristics(unsigned int uiIndex) const; // EXPORT 48 dword getCharacteristics(unsigned int uiIndex) const; // EXPORT
49 /// Returns the TimeDateStamp value of a debug structure. 49 /// Returns the TimeDateStamp value of a debug structure.
50 dword getTimeDateStamp(unsigned int uiIndex) const; // EXPORT 50 dword getTimeDateStamp(unsigned int uiIndex) const; // EXPORT
51 /// Returns the MajorVersion value of a debug structure. 51 /// Returns the MajorVersion value of a debug structure.
52 word getMajorVersion(unsigned int uiIndex) const; // EXPORT 52 word getMajorVersion(unsigned int uiIndex) const; // EXPORT
53 /// Returns the MinorVersion value of a debug structure. 53 /// Returns the MinorVersion value of a debug structure.
54 word getMinorVersion(unsigned int uiIndex) const; // EXPORT 54 word getMinorVersion(unsigned int uiIndex) const; // EXPORT
55 /// Returns the Type value of a debug structure. 55 /// Returns the Type value of a debug structure.
56 dword getType(unsigned int uiIndex) const; // EXPORT 56 dword getType(unsigned int uiIndex) const; // EXPORT
57 /// Returns the SizeOfData value of a debug structure. 57 /// Returns the SizeOfData value of a debug structure.
58 dword getSizeOfData(unsigned int uiIndex) const; // EXPORT 58 dword getSizeOfData(unsigned int uiIndex) const; // EXPORT
59 /// Returns the AddressOfRawData value of a debug structure. 59 /// Returns the AddressOfRawData value of a debug structure.
60 dword getAddressOfRawData(unsigned int uiIndex) const; // EXPORT 60 dword getAddressOfRawData(unsigned int uiIndex) const; // EXPORT
61 /// Returns the PointerToRawData value of a debug structure. 61 /// Returns the PointerToRawData value of a debug structure.
62 dword getPointerToRawData(unsigned int uiIndex) const; // EXPORT 62 dword getPointerToRawData(unsigned int uiIndex) const; // EXPORT
63 std::vector<byte> getData(unsigned int index) const; // EXPORT 63 std::vector<byte> getData(unsigned int index) const; // EXPORT
64 64
65 /// Sets the Characteristics value of a debug structure. 65 /// Sets the Characteristics value of a debug structure.
66 void setCharacteristics(unsigned int uiIndex, dword dwValue); // EXPORT 66 void setCharacteristics(unsigned int uiIndex, dword dwValue); // EXPORT
67 /// Sets the TimeDateStamp value of a debug structure. 67 /// Sets the TimeDateStamp value of a debug structure.
68 void setTimeDateStamp(unsigned int uiIndex, dword dwValue); // EXPORT 68 void setTimeDateStamp(unsigned int uiIndex, dword dwValue); // EXPORT
69 /// Sets the MajorVersion value of a debug structure. 69 /// Sets the MajorVersion value of a debug structure.
70 void setMajorVersion(unsigned int uiIndex, word wValue); // EXPORT 70 void setMajorVersion(unsigned int uiIndex, word wValue); // EXPORT
71 /// Sets the MinorVersion value of a debug structure. 71 /// Sets the MinorVersion value of a debug structure.
72 void setMinorVersion(unsigned int uiIndex, word wValue); // EXPORT 72 void setMinorVersion(unsigned int uiIndex, word wValue); // EXPORT
73 /// Sets the Type value of a debug structure. 73 /// Sets the Type value of a debug structure.
74 void setType(unsigned int uiIndex, dword dwValue); // EXPORT 74 void setType(unsigned int uiIndex, dword dwValue); // EXPORT
75 /// Sets the SizeOfData value of a debug structure. 75 /// Sets the SizeOfData value of a debug structure.
76 void setSizeOfData(unsigned int uiIndex, dword dwValue); // EXPORT 76 void setSizeOfData(unsigned int uiIndex, dword dwValue); // EXPORT
77 /// Sets the AddressOfRawData value of a debug structure. 77 /// Sets the AddressOfRawData value of a debug structure.
78 void setAddressOfRawData(unsigned int uiIndex, dword dwValue); // EXPORT 78 void setAddressOfRawData(unsigned int uiIndex, dword dwValue); // EXPORT
79 /// Sets the PointerToRawData value of a debug structure. 79 /// Sets the PointerToRawData value of a debug structure.
80 void setPointerToRawData(unsigned int uiIndex, dword dwValue); // EXPORT 80 void setPointerToRawData(unsigned int uiIndex, dword dwValue); // EXPORT
81 void setData(unsigned int index, const std::vector<byte>& data); // EXPORT 81 void setData(unsigned int index, const std::vector<byte>& data); // EXPORT
82 }; 82 };
83} 83}
84#endif 84#endif
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/ExportDirectory.cpp b/utils/zenutils/libraries/pelib-0.9/pelib/ExportDirectory.cpp
index aa9c28a50f..83c4b4e69d 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/ExportDirectory.cpp
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/ExportDirectory.cpp
@@ -1,692 +1,692 @@
1/* 1/*
2* ExportDirectory.cpp - Part of the PeLib library. 2* ExportDirectory.cpp - Part of the PeLib library.
3* 3*
4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) 4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5* All rights reserved. 5* All rights reserved.
6* 6*
7* This software is licensed under the zlib/libpng License. 7* This software is licensed under the zlib/libpng License.
8* For more details see http://www.opensource.org/licenses/zlib-license.php 8* For more details see http://www.opensource.org/licenses/zlib-license.php
9* or the license information file (license.htm) in the root directory 9* or the license information file (license.htm) in the root directory
10* of PeLib. 10* of PeLib.
11*/ 11*/
12 12
13//#ifdef false 13//#ifdef false
14 14
15#include "PeLibInc.h" 15#include "PeLibInc.h"
16#include "ExportDirectory.h" 16#include "ExportDirectory.h"
17 17
18namespace PeLib 18namespace PeLib
19{ 19{
20 /** 20 /**
21 * @param strFuncname Name of the function. 21 * @param strFuncname Name of the function.
22 * @param dwFuncAddr RVA of the function. 22 * @param dwFuncAddr RVA of the function.
23 **/ 23 **/
24 void ExportDirectory::addFunction(const std::string& strFuncname, dword dwFuncAddr) 24 void ExportDirectory::addFunction(const std::string& strFuncname, dword dwFuncAddr)
25 { 25 {
26 PELIB_EXP_FUNC_INFORMATION efiCurr; 26 PELIB_EXP_FUNC_INFORMATION efiCurr;
27 efiCurr.funcname = strFuncname; 27 efiCurr.funcname = strFuncname;
28 efiCurr.addroffunc = dwFuncAddr; 28 efiCurr.addroffunc = dwFuncAddr;
29 m_ied.functions.push_back(efiCurr); 29 m_ied.functions.push_back(efiCurr);
30 } 30 }
31 31
32 void ExportDirectory::removeFunction(unsigned int index) 32 void ExportDirectory::removeFunction(unsigned int index)
33 { 33 {
34 m_ied.functions.erase(m_ied.functions.begin() + index); 34 m_ied.functions.erase(m_ied.functions.begin() + index);
35 } 35 }
36 36
37 void ExportDirectory::clear() 37 void ExportDirectory::clear()
38 { 38 {
39 m_ied.functions.clear(); 39 m_ied.functions.clear();
40 } 40 }
41 41
42 unsigned int ExportDirectory::calcNumberOfFunctions() const 42 unsigned int ExportDirectory::calcNumberOfFunctions() const
43 { 43 {
44 return static_cast<unsigned int>(m_ied.functions.size()); 44 return static_cast<unsigned int>(m_ied.functions.size());
45 } 45 }
46 46
47 /** 47 /**
48 * Identifies an exported function through it's name. 48 * Identifies an exported function through it's name.
49 * @param strFunctionName Name of the function 49 * @param strFunctionName Name of the function
50 * @return Number which identifies the functions. 50 * @return Number which identifies the functions.
51 **/ 51 **/
52 int ExportDirectory::getFunctionIndex(const std::string& strFunctionName) const 52 int ExportDirectory::getFunctionIndex(const std::string& strFunctionName) const
53 { 53 {
54 std::vector<PELIB_EXP_FUNC_INFORMATION>::const_iterator Iter = std::find_if(m_ied.functions.begin(), m_ied.functions.end(), std::bind2nd(std::mem_fun_ref(&PELIB_EXP_FUNC_INFORMATION::equal), strFunctionName)); 54 std::vector<PELIB_EXP_FUNC_INFORMATION>::const_iterator Iter = std::find_if(m_ied.functions.begin(), m_ied.functions.end(), std::bind2nd(std::mem_fun_ref(&PELIB_EXP_FUNC_INFORMATION::equal), strFunctionName));
55 55
56 if (Iter == m_ied.functions.end()) 56 if (Iter == m_ied.functions.end())
57 { 57 {
58// throw Exceptions::InvalidName(ExportDirectoryId, __LINE__); 58// throw Exceptions::InvalidName(ExportDirectoryId, __LINE__);
59 return -1; 59 return -1;
60 } 60 }
61 61
62 return static_cast<int>(std::distance(m_ied.functions.begin(), Iter)); 62 return static_cast<int>(std::distance(m_ied.functions.begin(), Iter));
63 } 63 }
64 64
65 /** 65 /**
66 * @param strFilename Name of the file. 66 * @param strFilename Name of the file.
67 * @param uiOffset File offset of the export directory. 67 * @param uiOffset File offset of the export directory.
68 * @param uiSize Size of the export directory. 68 * @param uiSize Size of the export directory.
69 * @param pehHeader A valid PE header which is necessary because some RVA calculations need to be done. 69 * @param pehHeader A valid PE header which is necessary because some RVA calculations need to be done.
70 * \todo: Proper use of InputBuffer 70 * \todo: Proper use of InputBuffer
71 **/ 71 **/
72 int ExportDirectory::read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize, const PeHeader& pehHeader) 72 int ExportDirectory::read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize, const PeHeader& pehHeader)
73 { 73 {
74 std::ifstream ifFile(strFilename.c_str(), std::ios::binary); 74 std::ifstream ifFile(strFilename.c_str(), std::ios::binary);
75 75
76 if (!ifFile) 76 if (!ifFile)
77 { 77 {
78 return ERROR_OPENING_FILE; 78 return ERROR_OPENING_FILE;
79 } 79 }
80 80
81 unsigned int filesize = fileSize(ifFile); 81 unsigned int filesize = fileSize(ifFile);
82 82
83 if (filesize < uiOffset + uiSize) 83 if (filesize < uiOffset + uiSize)
84 { 84 {
85 return ERROR_INVALID_FILE; 85 return ERROR_INVALID_FILE;
86 } 86 }
87 87
88 ifFile.seekg(uiOffset, std::ios::beg); 88 ifFile.seekg(uiOffset, std::ios::beg);
89 89
90 PELIB_IMAGE_EXP_DIRECTORY iedCurr; 90 PELIB_IMAGE_EXP_DIRECTORY iedCurr;
91 91
92 std::vector<unsigned char> vExportdirectory(uiSize); 92 std::vector<unsigned char> vExportdirectory(uiSize);
93 ifFile.read(reinterpret_cast<char*>(&vExportdirectory[0]), uiSize); 93 ifFile.read(reinterpret_cast<char*>(&vExportdirectory[0]), uiSize);
94 94
95 InputBuffer inpBuffer(vExportdirectory); 95 InputBuffer inpBuffer(vExportdirectory);
96 96
97 inpBuffer >> iedCurr.ied.Characteristics; 97 inpBuffer >> iedCurr.ied.Characteristics;
98 inpBuffer >> iedCurr.ied.TimeDateStamp; 98 inpBuffer >> iedCurr.ied.TimeDateStamp;
99 inpBuffer >> iedCurr.ied.MajorVersion; 99 inpBuffer >> iedCurr.ied.MajorVersion;
100 inpBuffer >> iedCurr.ied.MinorVersion; 100 inpBuffer >> iedCurr.ied.MinorVersion;
101 inpBuffer >> iedCurr.ied.Name; 101 inpBuffer >> iedCurr.ied.Name;
102 inpBuffer >> iedCurr.ied.Base; 102 inpBuffer >> iedCurr.ied.Base;
103 inpBuffer >> iedCurr.ied.NumberOfFunctions; 103 inpBuffer >> iedCurr.ied.NumberOfFunctions;
104 inpBuffer >> iedCurr.ied.NumberOfNames; 104 inpBuffer >> iedCurr.ied.NumberOfNames;
105 inpBuffer >> iedCurr.ied.AddressOfFunctions; 105 inpBuffer >> iedCurr.ied.AddressOfFunctions;
106 inpBuffer >> iedCurr.ied.AddressOfNames; 106 inpBuffer >> iedCurr.ied.AddressOfNames;
107 inpBuffer >> iedCurr.ied.AddressOfNameOrdinals; 107 inpBuffer >> iedCurr.ied.AddressOfNameOrdinals;
108 108
109 if (const PeHeader32* p32 = dynamic_cast<const PeHeader32*>(&pehHeader)) 109 if (const PeHeader32* p32 = dynamic_cast<const PeHeader32*>(&pehHeader))
110 { 110 {
111 unsigned int offset = p32->rvaToOffset(iedCurr.ied.Name); 111 unsigned int offset = p32->rvaToOffset(iedCurr.ied.Name);
112 112
113 if (offset >= filesize) 113 if (offset >= filesize)
114 return ERROR_INVALID_FILE; 114 return ERROR_INVALID_FILE;
115 115
116 ifFile.seekg(offset, std::ios::beg); 116 ifFile.seekg(offset, std::ios::beg);
117 } 117 }
118 else if (const PeHeader64* p64 = dynamic_cast<const PeHeader64*>(&pehHeader)) 118 else if (const PeHeader64* p64 = dynamic_cast<const PeHeader64*>(&pehHeader))
119 { 119 {
120 // XXX: Files might be > 4 GB 120 // XXX: Files might be > 4 GB
121 unsigned int offset = static_cast<unsigned int>(p64->rvaToOffset(iedCurr.ied.Name)); 121 unsigned int offset = static_cast<unsigned int>(p64->rvaToOffset(iedCurr.ied.Name));
122 122
123 if (offset >= filesize) 123 if (offset >= filesize)
124 return ERROR_INVALID_FILE; 124 return ERROR_INVALID_FILE;
125 125
126 ifFile.seekg(offset, std::ios::beg); 126 ifFile.seekg(offset, std::ios::beg);
127 } 127 }
128 128
129 char c = 0; 129 char c = 0;
130 std::string strFname = ""; 130 std::string strFname = "";
131 do 131 do
132 { 132 {
133 ifFile.read(reinterpret_cast<char*>(&c), sizeof(c)); 133 ifFile.read(reinterpret_cast<char*>(&c), sizeof(c));
134 if (!ifFile) return ERROR_INVALID_FILE; 134 if (!ifFile) return ERROR_INVALID_FILE;
135 if (c) strFname += c; 135 if (c) strFname += c;
136 } 136 }
137 while (c != 0); 137 while (c != 0);
138 iedCurr.name = strFname; 138 iedCurr.name = strFname;
139 139
140 if (const PeHeader32* p32 = dynamic_cast<const PeHeader32*>(&pehHeader)) 140 if (const PeHeader32* p32 = dynamic_cast<const PeHeader32*>(&pehHeader))
141 { 141 {
142 unsigned int offset = p32->rvaToOffset(iedCurr.ied.AddressOfFunctions); 142 unsigned int offset = p32->rvaToOffset(iedCurr.ied.AddressOfFunctions);
143 143
144 if (offset >= filesize) 144 if (offset >= filesize)
145 return ERROR_INVALID_FILE; 145 return ERROR_INVALID_FILE;
146 146
147 ifFile.seekg(offset, std::ios::beg); 147 ifFile.seekg(offset, std::ios::beg);
148 } 148 }
149 else if (const PeHeader64* p64 = dynamic_cast<const PeHeader64*>(&pehHeader)) 149 else if (const PeHeader64* p64 = dynamic_cast<const PeHeader64*>(&pehHeader))
150 { 150 {
151 // XXX: File might be > 4 GB 151 // XXX: File might be > 4 GB
152 unsigned int offset = static_cast<unsigned int>(p64->rvaToOffset(iedCurr.ied.AddressOfFunctions)); 152 unsigned int offset = static_cast<unsigned int>(p64->rvaToOffset(iedCurr.ied.AddressOfFunctions));
153 153
154 if (offset >= filesize) 154 if (offset >= filesize)
155 return ERROR_INVALID_FILE; 155 return ERROR_INVALID_FILE;
156 156
157 ifFile.seekg(offset, std::ios::beg); 157 ifFile.seekg(offset, std::ios::beg);
158 } 158 }
159 159
160 PELIB_EXP_FUNC_INFORMATION efiCurr; 160 PELIB_EXP_FUNC_INFORMATION efiCurr;
161 efiCurr.ordinal = 0; efiCurr.addroffunc = 0; efiCurr.addrofname = 0; 161 efiCurr.ordinal = 0; efiCurr.addroffunc = 0; efiCurr.addrofname = 0;
162 162
163 for (unsigned int i=0;i<iedCurr.ied.NumberOfFunctions;i++) 163 for (unsigned int i=0;i<iedCurr.ied.NumberOfFunctions;i++)
164 { 164 {
165 if (const PeHeader32* p32 = dynamic_cast<const PeHeader32*>(&pehHeader)) 165 if (const PeHeader32* p32 = dynamic_cast<const PeHeader32*>(&pehHeader))
166 { 166 {
167 unsigned int offset = p32->rvaToOffset(iedCurr.ied.AddressOfFunctions) + i*sizeof(efiCurr.addroffunc); 167 unsigned int offset = p32->rvaToOffset(iedCurr.ied.AddressOfFunctions) + i*sizeof(efiCurr.addroffunc);
168 168
169 if (offset >= filesize) 169 if (offset >= filesize)
170 return ERROR_INVALID_FILE; 170 return ERROR_INVALID_FILE;
171 171
172 ifFile.seekg(offset, std::ios::beg); 172 ifFile.seekg(offset, std::ios::beg);
173 } 173 }
174 else if (const PeHeader64* p64 = dynamic_cast<const PeHeader64*>(&pehHeader)) 174 else if (const PeHeader64* p64 = dynamic_cast<const PeHeader64*>(&pehHeader))
175 { 175 {
176 // XXX: File might be > 4GB 176 // XXX: File might be > 4GB
177 unsigned int offset = static_cast<unsigned int>(p64->rvaToOffset(iedCurr.ied.AddressOfFunctions)) + i*sizeof(efiCurr.addroffunc); 177 unsigned int offset = static_cast<unsigned int>(p64->rvaToOffset(iedCurr.ied.AddressOfFunctions)) + i*sizeof(efiCurr.addroffunc);
178 178
179 if (offset >= filesize) 179 if (offset >= filesize)
180 return ERROR_INVALID_FILE; 180 return ERROR_INVALID_FILE;
181 181
182 ifFile.seekg(offset, std::ios::beg); 182 ifFile.seekg(offset, std::ios::beg);
183 } 183 }
184 184
185 ifFile.read(reinterpret_cast<char*>(&efiCurr.addroffunc), sizeof(efiCurr.addroffunc)); 185 ifFile.read(reinterpret_cast<char*>(&efiCurr.addroffunc), sizeof(efiCurr.addroffunc));
186 186
187 if (!ifFile) 187 if (!ifFile)
188 return ERROR_INVALID_FILE; 188 return ERROR_INVALID_FILE;
189 189
190 efiCurr.ordinal = i; 190 efiCurr.ordinal = i;
191 iedCurr.functions.push_back(efiCurr); 191 iedCurr.functions.push_back(efiCurr);
192 } 192 }
193 193
194 for (unsigned int i=0;i<iedCurr.ied.NumberOfNames;i++) 194 for (unsigned int i=0;i<iedCurr.ied.NumberOfNames;i++)
195 { 195 {
196 if (const PeHeader32* p32 = dynamic_cast<const PeHeader32*>(&pehHeader)) 196 if (const PeHeader32* p32 = dynamic_cast<const PeHeader32*>(&pehHeader))
197 { 197 {
198 unsigned int offset = p32->rvaToOffset(iedCurr.ied.AddressOfNameOrdinals) + i*sizeof(efiCurr.ordinal); 198 unsigned int offset = p32->rvaToOffset(iedCurr.ied.AddressOfNameOrdinals) + i*sizeof(efiCurr.ordinal);
199 199
200 if (offset >= filesize) 200 if (offset >= filesize)
201 return ERROR_INVALID_FILE; 201 return ERROR_INVALID_FILE;
202 202
203 ifFile.seekg(offset, std::ios::beg); 203 ifFile.seekg(offset, std::ios::beg);
204 } 204 }
205 else if (const PeHeader64* p64 = dynamic_cast<const PeHeader64*>(&pehHeader)) 205 else if (const PeHeader64* p64 = dynamic_cast<const PeHeader64*>(&pehHeader))
206 { 206 {
207 // XXX: File might be > 4 GB 207 // XXX: File might be > 4 GB
208 unsigned int offset = static_cast<unsigned int>(p64->rvaToOffset(iedCurr.ied.AddressOfNameOrdinals)) + i*sizeof(efiCurr.ordinal); 208 unsigned int offset = static_cast<unsigned int>(p64->rvaToOffset(iedCurr.ied.AddressOfNameOrdinals)) + i*sizeof(efiCurr.ordinal);
209 209
210 if (offset >= filesize) 210 if (offset >= filesize)
211 return ERROR_INVALID_FILE; 211 return ERROR_INVALID_FILE;
212 212
213 ifFile.seekg(offset, std::ios::beg); 213 ifFile.seekg(offset, std::ios::beg);
214 } 214 }
215 215
216 word ordinal; 216 word ordinal;
217 ifFile.read(reinterpret_cast<char*>(&ordinal), sizeof(ordinal)); 217 ifFile.read(reinterpret_cast<char*>(&ordinal), sizeof(ordinal));
218 218
219 if (!ifFile) 219 if (!ifFile)
220 return ERROR_INVALID_FILE; 220 return ERROR_INVALID_FILE;
221 221
222 iedCurr.functions[ordinal].ordinal = ordinal; 222 iedCurr.functions[ordinal].ordinal = ordinal;
223 223
224 if (const PeHeader32* p32 = dynamic_cast<const PeHeader32*>(&pehHeader)) 224 if (const PeHeader32* p32 = dynamic_cast<const PeHeader32*>(&pehHeader))
225 { 225 {
226 unsigned int offset = p32->rvaToOffset(iedCurr.ied.AddressOfNames) + i*sizeof(efiCurr.addrofname); 226 unsigned int offset = p32->rvaToOffset(iedCurr.ied.AddressOfNames) + i*sizeof(efiCurr.addrofname);
227 227
228 if (offset >= filesize) 228 if (offset >= filesize)
229 return ERROR_INVALID_FILE; 229 return ERROR_INVALID_FILE;
230 230
231 ifFile.seekg(offset, std::ios::beg); 231 ifFile.seekg(offset, std::ios::beg);
232 } 232 }
233 else if (const PeHeader64* p64 = dynamic_cast<const PeHeader64*>(&pehHeader)) 233 else if (const PeHeader64* p64 = dynamic_cast<const PeHeader64*>(&pehHeader))
234 { 234 {
235 // XXX: File might be > 4 GB. 235 // XXX: File might be > 4 GB.
236 unsigned int offset = static_cast<unsigned int>(p64->rvaToOffset(iedCurr.ied.AddressOfNames)) + i*sizeof(efiCurr.addrofname); 236 unsigned int offset = static_cast<unsigned int>(p64->rvaToOffset(iedCurr.ied.AddressOfNames)) + i*sizeof(efiCurr.addrofname);
237 237
238 if (offset >= filesize) 238 if (offset >= filesize)
239 return ERROR_INVALID_FILE; 239 return ERROR_INVALID_FILE;
240 240
241 ifFile.seekg(offset, std::ios::beg); 241 ifFile.seekg(offset, std::ios::beg);
242 } 242 }
243 243
244 ifFile.read(reinterpret_cast<char*>(&iedCurr.functions[ordinal].addrofname), sizeof(iedCurr.functions[ordinal].addrofname)); 244 ifFile.read(reinterpret_cast<char*>(&iedCurr.functions[ordinal].addrofname), sizeof(iedCurr.functions[ordinal].addrofname));
245 245
246 if (!ifFile) 246 if (!ifFile)
247 return ERROR_INVALID_FILE; 247 return ERROR_INVALID_FILE;
248 248
249 if (const PeHeader32* p32 = dynamic_cast<const PeHeader32*>(&pehHeader)) 249 if (const PeHeader32* p32 = dynamic_cast<const PeHeader32*>(&pehHeader))
250 { 250 {
251 unsigned int offset = p32->rvaToOffset(iedCurr.functions[ordinal].addrofname); 251 unsigned int offset = p32->rvaToOffset(iedCurr.functions[ordinal].addrofname);
252 252
253 if (offset >= filesize) 253 if (offset >= filesize)
254 return ERROR_INVALID_FILE; 254 return ERROR_INVALID_FILE;
255 255
256 ifFile.seekg(offset, std::ios::beg); 256 ifFile.seekg(offset, std::ios::beg);
257 } 257 }
258 else if (const PeHeader64* p64 = dynamic_cast<const PeHeader64*>(&pehHeader)) 258 else if (const PeHeader64* p64 = dynamic_cast<const PeHeader64*>(&pehHeader))
259 { 259 {
260 // XXX: File might be > 4 GB. 260 // XXX: File might be > 4 GB.
261 unsigned int offset = static_cast<unsigned int>(p64->rvaToOffset(iedCurr.functions[ordinal].addrofname)); 261 unsigned int offset = static_cast<unsigned int>(p64->rvaToOffset(iedCurr.functions[ordinal].addrofname));
262 262
263 if (offset >= filesize) 263 if (offset >= filesize)
264 return ERROR_INVALID_FILE; 264 return ERROR_INVALID_FILE;
265 265
266 ifFile.seekg(static_cast<unsigned int>(p64->rvaToOffset(iedCurr.functions[ordinal].addrofname)), std::ios::beg); 266 ifFile.seekg(static_cast<unsigned int>(p64->rvaToOffset(iedCurr.functions[ordinal].addrofname)), std::ios::beg);
267 } 267 }
268 268
269 char c = 0; 269 char c = 0;
270 std::string strFname = ""; 270 std::string strFname = "";
271 do 271 do
272 { 272 {
273 ifFile.read(reinterpret_cast<char*>(&c), sizeof(c)); 273 ifFile.read(reinterpret_cast<char*>(&c), sizeof(c));
274 274
275 if (!ifFile) 275 if (!ifFile)
276 return ERROR_INVALID_FILE; 276 return ERROR_INVALID_FILE;
277 277
278 if (c) strFname += c; 278 if (c) strFname += c;
279 } 279 }
280 while (c != 0); 280 while (c != 0);
281 281
282 iedCurr.functions[ordinal].funcname = strFname; 282 iedCurr.functions[ordinal].funcname = strFname;
283 } 283 }
284 284
285 std::swap(m_ied, iedCurr); 285 std::swap(m_ied, iedCurr);
286 286
287 return NO_ERROR; 287 return NO_ERROR;
288 } 288 }
289 289
290 /** 290 /**
291 * @param vBuffer Buffer where the rebuilt export directory is written to. 291 * @param vBuffer Buffer where the rebuilt export directory is written to.
292 * @param dwRva RVA of the export directory. 292 * @param dwRva RVA of the export directory.
293 * \todo fValid flag 293 * \todo fValid flag
294 **/ 294 **/
295 void ExportDirectory::rebuild(std::vector<byte>& vBuffer, dword dwRva) const 295 void ExportDirectory::rebuild(std::vector<byte>& vBuffer, dword dwRva) const
296 { 296 {
297 unsigned int uiSizeDirectory = sizeof(PELIB_IMAGE_EXPORT_DIRECTORY); 297 unsigned int uiSizeDirectory = sizeof(PELIB_IMAGE_EXPORT_DIRECTORY);
298 298
299 unsigned int uiSizeNames = 0; 299 unsigned int uiSizeNames = 0;
300 unsigned int uiSizeAddrFuncs = 0; 300 unsigned int uiSizeAddrFuncs = 0;
301 unsigned int uiSizeAddrNames = 0; 301 unsigned int uiSizeAddrNames = 0;
302 unsigned int uiSizeOrdinals = 0; 302 unsigned int uiSizeOrdinals = 0;
303 303
304 for (unsigned int i=0;i<m_ied.functions.size();i++) 304 for (unsigned int i=0;i<m_ied.functions.size();i++)
305 { 305 {
306 uiSizeNames += (m_ied.functions[i].funcname.empty()) ? 0 : static_cast<unsigned int>(m_ied.functions[i].funcname.size()) + 1; 306 uiSizeNames += (m_ied.functions[i].funcname.empty()) ? 0 : static_cast<unsigned int>(m_ied.functions[i].funcname.size()) + 1;
307 uiSizeAddrFuncs += sizeof(m_ied.functions[i].addroffunc); 307 uiSizeAddrFuncs += sizeof(m_ied.functions[i].addroffunc);
308 uiSizeAddrNames += (m_ied.functions[i].funcname.empty()) ? 0 : sizeof(m_ied.functions[i].addrofname); 308 uiSizeAddrNames += (m_ied.functions[i].funcname.empty()) ? 0 : sizeof(m_ied.functions[i].addrofname);
309 uiSizeOrdinals += (m_ied.functions[i].funcname.empty()) ? 0 : sizeof(m_ied.functions[i].ordinal); 309 uiSizeOrdinals += (m_ied.functions[i].funcname.empty()) ? 0 : sizeof(m_ied.functions[i].ordinal);
310 } 310 }
311 311
312 unsigned int uiFilenameSize = static_cast<unsigned int>(m_ied.name.size()) + 1; 312 unsigned int uiFilenameSize = static_cast<unsigned int>(m_ied.name.size()) + 1;
313 313
314 OutputBuffer obBuffer(vBuffer); 314 OutputBuffer obBuffer(vBuffer);
315 315
316 obBuffer << m_ied.ied.Characteristics; 316 obBuffer << m_ied.ied.Characteristics;
317 obBuffer << m_ied.ied.TimeDateStamp; 317 obBuffer << m_ied.ied.TimeDateStamp;
318 obBuffer << m_ied.ied.MajorVersion; 318 obBuffer << m_ied.ied.MajorVersion;
319 obBuffer << m_ied.ied.MinorVersion; 319 obBuffer << m_ied.ied.MinorVersion;
320 obBuffer << dwRva + uiSizeDirectory; 320 obBuffer << dwRva + uiSizeDirectory;
321 obBuffer << m_ied.ied.Base; 321 obBuffer << m_ied.ied.Base;
322 obBuffer << static_cast<unsigned int>(m_ied.functions.size()); 322 obBuffer << static_cast<unsigned int>(m_ied.functions.size());
323 323
324 // TODO: Not correct but sufficient for now. (Update: I forgot what this comment refers to, but I'll leave it in) 324 // TODO: Not correct but sufficient for now. (Update: I forgot what this comment refers to, but I'll leave it in)
325 obBuffer << static_cast<unsigned int>(m_ied.functions.size()); 325 obBuffer << static_cast<unsigned int>(m_ied.functions.size());
326 obBuffer << dwRva + uiSizeDirectory + uiFilenameSize; 326 obBuffer << dwRva + uiSizeDirectory + uiFilenameSize;
327 obBuffer << dwRva + uiSizeDirectory + uiFilenameSize + uiSizeAddrFuncs; 327 obBuffer << dwRva + uiSizeDirectory + uiFilenameSize + uiSizeAddrFuncs;
328 obBuffer << dwRva + uiSizeDirectory + uiFilenameSize + uiSizeAddrFuncs + uiSizeAddrNames; 328 obBuffer << dwRva + uiSizeDirectory + uiFilenameSize + uiSizeAddrFuncs + uiSizeAddrNames;
329 329
330 obBuffer.add(m_ied.name.c_str(), static_cast<unsigned int>(m_ied.name.size())+1); 330 obBuffer.add(m_ied.name.c_str(), static_cast<unsigned int>(m_ied.name.size())+1);
331 331
332 for (unsigned int i=0;i<m_ied.functions.size();i++) 332 for (unsigned int i=0;i<m_ied.functions.size();i++)
333 { 333 {
334 obBuffer << m_ied.functions[i].addroffunc; 334 obBuffer << m_ied.functions[i].addroffunc;
335 } 335 }
336 336
337 unsigned int ulFuncCounter = dwRva + uiSizeDirectory + uiFilenameSize + uiSizeAddrFuncs + uiSizeAddrNames + uiSizeOrdinals; 337 unsigned int ulFuncCounter = dwRva + uiSizeDirectory + uiFilenameSize + uiSizeAddrFuncs + uiSizeAddrNames + uiSizeOrdinals;
338 338
339 for (unsigned int i=0;i<m_ied.functions.size();i++) 339 for (unsigned int i=0;i<m_ied.functions.size();i++)
340 { 340 {
341 if (!m_ied.functions[i].funcname.empty()) 341 if (!m_ied.functions[i].funcname.empty())
342 { 342 {
343 obBuffer << ulFuncCounter; 343 obBuffer << ulFuncCounter;
344 ulFuncCounter += static_cast<unsigned int>(m_ied.functions[i].funcname.size()) + 1; 344 ulFuncCounter += static_cast<unsigned int>(m_ied.functions[i].funcname.size()) + 1;
345 } 345 }
346 } 346 }
347 347
348 for (unsigned int i=0;i<m_ied.functions.size();i++) 348 for (unsigned int i=0;i<m_ied.functions.size();i++)
349 { 349 {
350 if (!m_ied.functions[i].funcname.empty()) 350 if (!m_ied.functions[i].funcname.empty())
351 { 351 {
352 obBuffer << m_ied.functions[i].ordinal; 352 obBuffer << m_ied.functions[i].ordinal;
353 } 353 }
354 } 354 }
355 355
356 for (unsigned int i=0;i<m_ied.functions.size();i++) 356 for (unsigned int i=0;i<m_ied.functions.size();i++)
357 { 357 {
358 if (m_ied.functions[i].funcname.empty() && m_ied.functions[i].addroffunc) 358 if (m_ied.functions[i].funcname.empty() && m_ied.functions[i].addroffunc)
359 { 359 {
360 obBuffer << m_ied.functions[i].ordinal; 360 obBuffer << m_ied.functions[i].ordinal;
361 } 361 }
362 } 362 }
363 363
364 for (unsigned int i=0;i<m_ied.functions.size();i++) 364 for (unsigned int i=0;i<m_ied.functions.size();i++)
365 { 365 {
366 if (!m_ied.functions[i].funcname.empty()) 366 if (!m_ied.functions[i].funcname.empty())
367 { 367 {
368 obBuffer.add(m_ied.functions[i].funcname.c_str(), static_cast<unsigned int>(m_ied.functions[i].funcname.size()) + 1); 368 obBuffer.add(m_ied.functions[i].funcname.c_str(), static_cast<unsigned int>(m_ied.functions[i].funcname.size()) + 1);
369 } 369 }
370 } 370 }
371 } 371 }
372 372
373 /** 373 /**
374 * @return Size of the current export directory. 374 * @return Size of the current export directory.
375 **/ 375 **/
376 unsigned int ExportDirectory::size() const 376 unsigned int ExportDirectory::size() const
377 { 377 {
378 return m_ied.size(); 378 return m_ied.size();
379 } 379 }
380 380
381 /** 381 /**
382 * @param strFilename Name of the file. 382 * @param strFilename Name of the file.
383 * @param uiOffset File offset the export directory will be written to. 383 * @param uiOffset File offset the export directory will be written to.
384 * @param uiRva RVA of the export directory. 384 * @param uiRva RVA of the export directory.
385 * \todo Check if ofFile.write succeeded. 385 * \todo Check if ofFile.write succeeded.
386 **/ 386 **/
387 int ExportDirectory::write(const std::string& strFilename, unsigned int uiOffset, unsigned int uiRva) const 387 int ExportDirectory::write(const std::string& strFilename, unsigned int uiOffset, unsigned int uiRva) const
388 { 388 {
389 std::fstream ofFile(strFilename.c_str(), std::ios_base::in); 389 std::fstream ofFile(strFilename.c_str(), std::ios_base::in);
390 390
391 if (!ofFile) 391 if (!ofFile)
392 { 392 {
393 ofFile.clear(); 393 ofFile.clear();
394 ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary); 394 ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary);
395 } 395 }
396 else 396 else
397 { 397 {
398 ofFile.close(); 398 ofFile.close();
399 ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary); 399 ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary);
400 } 400 }
401 401
402 if (!ofFile) 402 if (!ofFile)
403 { 403 {
404 return ERROR_OPENING_FILE; 404 return ERROR_OPENING_FILE;
405 } 405 }
406 406
407 ofFile.seekp(uiOffset, std::ios::beg); 407 ofFile.seekp(uiOffset, std::ios::beg);
408 408
409 std::vector<unsigned char> vBuffer; 409 std::vector<unsigned char> vBuffer;
410 rebuild(vBuffer, uiRva); 410 rebuild(vBuffer, uiRva);
411 411
412 ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), static_cast<unsigned int>(vBuffer.size())); 412 ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), static_cast<unsigned int>(vBuffer.size()));
413 413
414 ofFile.close(); 414 ofFile.close();
415 415
416 return NO_ERROR; 416 return NO_ERROR;
417 } 417 }
418 418
419 /** 419 /**
420 * Changes the filename according to the export directory. 420 * Changes the filename according to the export directory.
421 * @param strFilename New filename. 421 * @param strFilename New filename.
422 **/ 422 **/
423 void ExportDirectory::setNameString(const std::string& strFilename) 423 void ExportDirectory::setNameString(const std::string& strFilename)
424 { 424 {
425 m_ied.name = strFilename; 425 m_ied.name = strFilename;
426 } 426 }
427 427
428 std::string ExportDirectory::getNameString() const 428 std::string ExportDirectory::getNameString() const
429 { 429 {
430 return m_ied.name; 430 return m_ied.name;
431 } 431 }
432 432
433 /** 433 /**
434 * @param dwIndex Number which identifies an exported function. 434 * @param dwIndex Number which identifies an exported function.
435 * @return The name of that function. 435 * @return The name of that function.
436 **/ 436 **/
437 std::string ExportDirectory::getFunctionName(dword dwIndex) const 437 std::string ExportDirectory::getFunctionName(dword dwIndex) const
438 { 438 {
439 return m_ied.functions[dwIndex].funcname; 439 return m_ied.functions[dwIndex].funcname;
440 } 440 }
441 441
442 /** 442 /**
443 * @param dwIndex Number which identifies an exported function. 443 * @param dwIndex Number which identifies an exported function.
444 * @return The ordinal of that function. 444 * @return The ordinal of that function.
445 **/ 445 **/
446 word ExportDirectory::getFunctionOrdinal(dword dwIndex) const 446 word ExportDirectory::getFunctionOrdinal(dword dwIndex) const
447 { 447 {
448 return m_ied.functions[dwIndex].ordinal; 448 return m_ied.functions[dwIndex].ordinal;
449 } 449 }
450 450
451 /** 451 /**
452 * @param dwIndex Number which identifies an exported function. 452 * @param dwIndex Number which identifies an exported function.
453 * @return The RVA of the name string of that function. 453 * @return The RVA of the name string of that function.
454 **/ 454 **/
455 dword ExportDirectory::getAddressOfName(dword dwIndex) const 455 dword ExportDirectory::getAddressOfName(dword dwIndex) const
456 { 456 {
457 return m_ied.functions[dwIndex].addrofname; 457 return m_ied.functions[dwIndex].addrofname;
458 } 458 }
459 459
460 /** 460 /**
461 * @param dwIndex Number which identifies an exported function. 461 * @param dwIndex Number which identifies an exported function.
462 * @return The RVA of that function. 462 * @return The RVA of that function.
463 **/ 463 **/
464 dword ExportDirectory::getAddressOfFunction(dword dwIndex) const 464 dword ExportDirectory::getAddressOfFunction(dword dwIndex) const
465 { 465 {
466 return m_ied.functions[dwIndex].addroffunc; 466 return m_ied.functions[dwIndex].addroffunc;
467 } 467 }
468 468
469 /** 469 /**
470 * @param dwIndex Number which identifies an exported function. 470 * @param dwIndex Number which identifies an exported function.
471 * @param strName The name of that function. 471 * @param strName The name of that function.
472 **/ 472 **/
473 void ExportDirectory::setFunctionName(dword dwIndex, const std::string& strName) 473 void ExportDirectory::setFunctionName(dword dwIndex, const std::string& strName)
474 { 474 {
475 m_ied.functions[dwIndex].funcname = strName; 475 m_ied.functions[dwIndex].funcname = strName;
476 } 476 }
477 477
478 /** 478 /**
479 * @param dwIndex Number which identifies an exported function. 479 * @param dwIndex Number which identifies an exported function.
480 * @param wValue The ordinal of that function. 480 * @param wValue The ordinal of that function.
481 **/ 481 **/
482 void ExportDirectory::setFunctionOrdinal(dword dwIndex, word wValue) 482 void ExportDirectory::setFunctionOrdinal(dword dwIndex, word wValue)
483 { 483 {
484 m_ied.functions[dwIndex].ordinal = wValue; 484 m_ied.functions[dwIndex].ordinal = wValue;
485 } 485 }
486 486
487 /** 487 /**
488 * @param dwIndex Number which identifies an exported function. 488 * @param dwIndex Number which identifies an exported function.
489 * @param dwValue The RVA of the name string of that function. 489 * @param dwValue The RVA of the name string of that function.
490 **/ 490 **/
491 void ExportDirectory::setAddressOfName(dword dwIndex, dword dwValue) 491 void ExportDirectory::setAddressOfName(dword dwIndex, dword dwValue)
492 { 492 {
493 m_ied.functions[dwIndex].addrofname = dwValue; 493 m_ied.functions[dwIndex].addrofname = dwValue;
494 } 494 }
495 495
496 /** 496 /**
497 * @param dwIndex Number which identifies an exported function. 497 * @param dwIndex Number which identifies an exported function.
498 * @param dwValue The RVA of that function. 498 * @param dwValue The RVA of that function.
499 **/ 499 **/
500 void ExportDirectory::setAddressOfFunction(dword dwIndex, dword dwValue) 500 void ExportDirectory::setAddressOfFunction(dword dwIndex, dword dwValue)
501 { 501 {
502 m_ied.functions[dwIndex].addroffunc = dwValue; 502 m_ied.functions[dwIndex].addroffunc = dwValue;
503 } 503 }
504 504
505 /** 505 /**
506 * @return The ordinal base of the export directory. 506 * @return The ordinal base of the export directory.
507 **/ 507 **/
508 dword ExportDirectory::getBase() const 508 dword ExportDirectory::getBase() const
509 { 509 {
510 return m_ied.ied.Base; 510 return m_ied.ied.Base;
511 } 511 }
512 512
513 /** 513 /**
514 * @return The characteristics of the export directory. 514 * @return The characteristics of the export directory.
515 **/ 515 **/
516 dword ExportDirectory::getCharacteristics() const 516 dword ExportDirectory::getCharacteristics() const
517 { 517 {
518 return m_ied.ied.Characteristics; 518 return m_ied.ied.Characteristics;
519 } 519 }
520 520
521 /** 521 /**
522 * @return The time/date stamp of the export directory. 522 * @return The time/date stamp of the export directory.
523 **/ 523 **/
524 dword ExportDirectory::getTimeDateStamp() const 524 dword ExportDirectory::getTimeDateStamp() const
525 { 525 {
526 return m_ied.ied.TimeDateStamp; 526 return m_ied.ied.TimeDateStamp;
527 } 527 }
528 528
529 /** 529 /**
530 * @return The MajorVersion of the export directory. 530 * @return The MajorVersion of the export directory.
531 **/ 531 **/
532 word ExportDirectory::getMajorVersion() const 532 word ExportDirectory::getMajorVersion() const
533 { 533 {
534 return m_ied.ied.MajorVersion; 534 return m_ied.ied.MajorVersion;
535 } 535 }
536 536
537 /** 537 /**
538 * @return The MinorVersion of the export directory. 538 * @return The MinorVersion of the export directory.
539 **/ 539 **/
540 word ExportDirectory::getMinorVersion() const 540 word ExportDirectory::getMinorVersion() const
541 { 541 {
542 return m_ied.ied.MinorVersion; 542 return m_ied.ied.MinorVersion;
543 } 543 }
544 544
545 /** 545 /**
546 * @return The RVA of the name of the file. 546 * @return The RVA of the name of the file.
547 **/ 547 **/
548 dword ExportDirectory::getName() const 548 dword ExportDirectory::getName() const
549 { 549 {
550 return m_ied.ied.Name; 550 return m_ied.ied.Name;
551 } 551 }
552 552
553 /** 553 /**
554 * @return The NumberOfFunctions of the export directory. 554 * @return The NumberOfFunctions of the export directory.
555 **/ 555 **/
556 dword ExportDirectory::getNumberOfFunctions() const 556 dword ExportDirectory::getNumberOfFunctions() const
557 { 557 {
558 return m_ied.ied.NumberOfFunctions; 558 return m_ied.ied.NumberOfFunctions;
559 } 559 }
560 560
561 /** 561 /**
562 * @return The NumberOfNames of the export directory. 562 * @return The NumberOfNames of the export directory.
563 **/ 563 **/
564 dword ExportDirectory::getNumberOfNames() const 564 dword ExportDirectory::getNumberOfNames() const
565 { 565 {
566 return m_ied.ied.NumberOfNames; 566 return m_ied.ied.NumberOfNames;
567 } 567 }
568 568
569 /** 569 /**
570 * @return The AddressOfFunctions of the export directory. 570 * @return The AddressOfFunctions of the export directory.
571 **/ 571 **/
572 dword ExportDirectory::getAddressOfFunctions() const 572 dword ExportDirectory::getAddressOfFunctions() const
573 { 573 {
574 return m_ied.ied.AddressOfFunctions; 574 return m_ied.ied.AddressOfFunctions;
575 } 575 }
576 576
577 /** 577 /**
578 * @return The AddressOfNames of the export directory. 578 * @return The AddressOfNames of the export directory.
579 **/ 579 **/
580 dword ExportDirectory::getAddressOfNames() const 580 dword ExportDirectory::getAddressOfNames() const
581 { 581 {
582 return m_ied.ied.AddressOfNames; 582 return m_ied.ied.AddressOfNames;
583 } 583 }
584 584
585/* dword ExportDirectory::getNumberOfNameOrdinals() const 585/* dword ExportDirectory::getNumberOfNameOrdinals() const
586 { 586 {
587 return static_cast<dword>(m_ied.functions.size()); 587 return static_cast<dword>(m_ied.functions.size());
588 } 588 }
589 589
590 dword ExportDirectory::getNumberOfAddressOfFunctionNames() const 590 dword ExportDirectory::getNumberOfAddressOfFunctionNames() const
591 { 591 {
592 return static_cast<dword>(m_ied.functions.size()); 592 return static_cast<dword>(m_ied.functions.size());
593 } 593 }
594 594
595 dword ExportDirectory::getNumberOfAddressOfFunctions() const 595 dword ExportDirectory::getNumberOfAddressOfFunctions() const
596 { 596 {
597 return static_cast<dword>(m_ied.functions.size()); 597 return static_cast<dword>(m_ied.functions.size());
598 } 598 }
599*/ 599*/
600 /** 600 /**
601 * @return The AddressOfNameOrdinals of the export directory. 601 * @return The AddressOfNameOrdinals of the export directory.
602 **/ 602 **/
603 dword ExportDirectory::getAddressOfNameOrdinals() const 603 dword ExportDirectory::getAddressOfNameOrdinals() const
604 { 604 {
605 return m_ied.ied.AddressOfNameOrdinals; 605 return m_ied.ied.AddressOfNameOrdinals;
606 } 606 }
607 607
608 /** 608 /**
609 * @param dwValue The ordinal base of the export directory. 609 * @param dwValue The ordinal base of the export directory.
610 **/ 610 **/
611 void ExportDirectory::setBase(dword dwValue) 611 void ExportDirectory::setBase(dword dwValue)
612 { 612 {
613 m_ied.ied.Base = dwValue; 613 m_ied.ied.Base = dwValue;
614 } 614 }
615 615
616 /** 616 /**
617 * @param dwValue The Characteristics of the export directory. 617 * @param dwValue The Characteristics of the export directory.
618 **/ 618 **/
619 void ExportDirectory::setCharacteristics(dword dwValue) 619 void ExportDirectory::setCharacteristics(dword dwValue)
620 { 620 {
621 m_ied.ied.Characteristics = dwValue; 621 m_ied.ied.Characteristics = dwValue;
622 } 622 }
623 623
624 /** 624 /**
625 * @param dwValue The TimeDateStamp of the export directory. 625 * @param dwValue The TimeDateStamp of the export directory.
626 **/ 626 **/
627 void ExportDirectory::setTimeDateStamp(dword dwValue) 627 void ExportDirectory::setTimeDateStamp(dword dwValue)
628 { 628 {
629 m_ied.ied.TimeDateStamp = dwValue; 629 m_ied.ied.TimeDateStamp = dwValue;
630 } 630 }
631 631
632 /** 632 /**
633 * @param wValue The MajorVersion of the export directory. 633 * @param wValue The MajorVersion of the export directory.
634 **/ 634 **/
635 void ExportDirectory::setMajorVersion(word wValue) 635 void ExportDirectory::setMajorVersion(word wValue)
636 { 636 {
637 m_ied.ied.MajorVersion = wValue; 637 m_ied.ied.MajorVersion = wValue;
638 } 638 }
639 639
640 /** 640 /**
641 * @param wValue The MinorVersion of the export directory. 641 * @param wValue The MinorVersion of the export directory.
642 **/ 642 **/
643 void ExportDirectory::setMinorVersion(word wValue) 643 void ExportDirectory::setMinorVersion(word wValue)
644 { 644 {
645 m_ied.ied.MinorVersion = wValue; 645 m_ied.ied.MinorVersion = wValue;
646 } 646 }
647 647
648 /** 648 /**
649 * @param dwValue The Name of the export directory. 649 * @param dwValue The Name of the export directory.
650 **/ 650 **/
651 void ExportDirectory::setName(dword dwValue) 651 void ExportDirectory::setName(dword dwValue)
652 { 652 {
653 m_ied.ied.Name = dwValue; 653 m_ied.ied.Name = dwValue;
654 } 654 }
655 655
656 /** 656 /**
657 * @param dwValue The NumberOfFunctions of the export directory. 657 * @param dwValue The NumberOfFunctions of the export directory.
658 **/ 658 **/
659 void ExportDirectory::setNumberOfFunctions(dword dwValue) 659 void ExportDirectory::setNumberOfFunctions(dword dwValue)
660 { 660 {
661 m_ied.ied.NumberOfFunctions = dwValue; 661 m_ied.ied.NumberOfFunctions = dwValue;
662 } 662 }
663 663
664 /** 664 /**
665 * @param dwValue The NumberOfNames of the export directory. 665 * @param dwValue The NumberOfNames of the export directory.
666 **/ 666 **/
667 void ExportDirectory::setNumberOfNames(dword dwValue) 667 void ExportDirectory::setNumberOfNames(dword dwValue)
668 { 668 {
669 m_ied.ied.NumberOfNames = dwValue; 669 m_ied.ied.NumberOfNames = dwValue;
670 } 670 }
671 671
672 /** 672 /**
673 * @param dwValue The AddressOfFunctions of the export directory. 673 * @param dwValue The AddressOfFunctions of the export directory.
674 **/ 674 **/
675 void ExportDirectory::setAddressOfFunctions(dword dwValue) 675 void ExportDirectory::setAddressOfFunctions(dword dwValue)
676 { 676 {
677 m_ied.ied.AddressOfFunctions = dwValue; 677 m_ied.ied.AddressOfFunctions = dwValue;
678 } 678 }
679 679
680 /** 680 /**
681 * @param dwValue The AddressOfNames of the export directory. 681 * @param dwValue The AddressOfNames of the export directory.
682 **/ 682 **/
683 void ExportDirectory::setAddressOfNames(dword dwValue) 683 void ExportDirectory::setAddressOfNames(dword dwValue)
684 { 684 {
685 m_ied.ied.AddressOfNames = dwValue; 685 m_ied.ied.AddressOfNames = dwValue;
686 } 686 }
687 687
688 void ExportDirectory::setAddressOfNameOrdinals(dword value) 688 void ExportDirectory::setAddressOfNameOrdinals(dword value)
689 { 689 {
690 m_ied.ied.AddressOfNameOrdinals = value; 690 m_ied.ied.AddressOfNameOrdinals = value;
691 } 691 }
692} 692}
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/ExportDirectory.h b/utils/zenutils/libraries/pelib-0.9/pelib/ExportDirectory.h
index 17a7e57020..19609b65a7 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/ExportDirectory.h
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/ExportDirectory.h
@@ -1,133 +1,133 @@
1/* 1/*
2* ExportDirectory.h - Part of the PeLib library. 2* ExportDirectory.h - Part of the PeLib library.
3* 3*
4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) 4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5* All rights reserved. 5* All rights reserved.
6* 6*
7* This software is licensed under the zlib/libpng License. 7* This software is licensed under the zlib/libpng License.
8* For more details see http://www.opensource.org/licenses/zlib-license.php 8* For more details see http://www.opensource.org/licenses/zlib-license.php
9* or the license information file (license.htm) in the root directory 9* or the license information file (license.htm) in the root directory
10* of PeLib. 10* of PeLib.
11*/ 11*/
12 12
13#ifndef EXPORTDIRECTORY_H 13#ifndef EXPORTDIRECTORY_H
14#define EXPORTDIRECTORY_H 14#define EXPORTDIRECTORY_H
15#include "PeHeader.h" 15#include "PeHeader.h"
16 16
17namespace PeLib 17namespace PeLib
18{ 18{
19 /// Class that handles the export directory. 19 /// Class that handles the export directory.
20 /** 20 /**
21 * This class handles the export directory. 21 * This class handles the export directory.
22 * \todo getNameString 22 * \todo getNameString
23 **/ 23 **/
24// template<int bits> 24// template<int bits>
25 class ExportDirectory 25 class ExportDirectory
26 { 26 {
27 private: 27 private:
28 /// Used to store all necessary information about a file's exported functions. 28 /// Used to store all necessary information about a file's exported functions.
29 PELIB_IMAGE_EXP_DIRECTORY m_ied; 29 PELIB_IMAGE_EXP_DIRECTORY m_ied;
30 30
31 public: 31 public:
32 /// Add another function to be exported. 32 /// Add another function to be exported.
33 void addFunction(const std::string& strFuncname, dword dwFuncAddr); // EXPORT 33 void addFunction(const std::string& strFuncname, dword dwFuncAddr); // EXPORT
34 unsigned int calcNumberOfFunctions() const; // EXPORT 34 unsigned int calcNumberOfFunctions() const; // EXPORT
35 void clear(); // EXPORT 35 void clear(); // EXPORT
36 /// Identifies a function through it's name. 36 /// Identifies a function through it's name.
37 int getFunctionIndex(const std::string& strFunctionName) const; // EXPORT 37 int getFunctionIndex(const std::string& strFunctionName) const; // EXPORT
38 /// Read a file's export directory. 38 /// Read a file's export directory.
39 int read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize, const PeHeader& pehHeader); // EXPORT 39 int read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize, const PeHeader& pehHeader); // EXPORT
40 /// Rebuild the current export directory. 40 /// Rebuild the current export directory.
41 void rebuild(std::vector<byte>& vBuffer, dword dwRva) const; // EXPORT 41 void rebuild(std::vector<byte>& vBuffer, dword dwRva) const; // EXPORT
42 void removeFunction(unsigned int index); // EXPORT 42 void removeFunction(unsigned int index); // EXPORT
43 /// Returns the size of the current export directory. 43 /// Returns the size of the current export directory.
44 unsigned int size() const; // EXPORT 44 unsigned int size() const; // EXPORT
45 /// Writes the current export directory to a file. 45 /// Writes the current export directory to a file.
46 int write(const std::string& strFilename, unsigned int uiOffset, unsigned int uiRva) const; // EXPORT 46 int write(const std::string& strFilename, unsigned int uiOffset, unsigned int uiRva) const; // EXPORT
47 47
48 /// Changes the name of the file (according to the export directory). 48 /// Changes the name of the file (according to the export directory).
49 void setNameString(const std::string& strFilename); // EXPORT 49 void setNameString(const std::string& strFilename); // EXPORT
50 std::string getNameString() const; // EXPORT 50 std::string getNameString() const; // EXPORT
51 51
52 /// Get the name of an exported function. 52 /// Get the name of an exported function.
53 std::string getFunctionName(unsigned int index) const; // EXPORT 53 std::string getFunctionName(unsigned int index) const; // EXPORT
54 /// Get the ordinal of an exported function. 54 /// Get the ordinal of an exported function.
55 word getFunctionOrdinal(unsigned int index) const; // EXPORT 55 word getFunctionOrdinal(unsigned int index) const; // EXPORT
56 /// Get the address of the name of an exported function. 56 /// Get the address of the name of an exported function.
57 dword getAddressOfName(unsigned int index) const; // EXPORT 57 dword getAddressOfName(unsigned int index) const; // EXPORT
58 /// Get the address of an exported function. 58 /// Get the address of an exported function.
59 dword getAddressOfFunction(unsigned int index) const; // EXPORT 59 dword getAddressOfFunction(unsigned int index) const; // EXPORT
60 60
61 /// Change the name of an exported function. 61 /// Change the name of an exported function.
62 void setFunctionName(unsigned int index, const std::string& strName); // EXPORT 62 void setFunctionName(unsigned int index, const std::string& strName); // EXPORT
63 /// Change the ordinal of an exported function. 63 /// Change the ordinal of an exported function.
64 void setFunctionOrdinal(unsigned int index, word wValue); // EXPORT 64 void setFunctionOrdinal(unsigned int index, word wValue); // EXPORT
65 /// Change the address of the name of an exported function. 65 /// Change the address of the name of an exported function.
66 void setAddressOfName(unsigned int index, dword dwValue); // EXPORT 66 void setAddressOfName(unsigned int index, dword dwValue); // EXPORT
67 /// Change the address of an exported function. 67 /// Change the address of an exported function.
68 void setAddressOfFunction(unsigned int index, dword dwValue); // EXPORT 68 void setAddressOfFunction(unsigned int index, dword dwValue); // EXPORT
69 69
70 /* 70 /*
71 word getFunctionOrdinal(std::string strFuncname) const; 71 word getFunctionOrdinal(std::string strFuncname) const;
72 dword getAddressOfName(std::string strFuncname) const; 72 dword getAddressOfName(std::string strFuncname) const;
73 dword getAddressOfFunction(std::string strFuncname) const; 73 dword getAddressOfFunction(std::string strFuncname) const;
74 74
75 void setFunctionOrdinal(std::string strFuncname, word wValue); 75 void setFunctionOrdinal(std::string strFuncname, word wValue);
76 void setAddressOfName(std::string strFuncname, dword dwValue); 76 void setAddressOfName(std::string strFuncname, dword dwValue);
77 void setAddressOfFunction(std::string strFuncname, dword dwValue); 77 void setAddressOfFunction(std::string strFuncname, dword dwValue);
78 */ 78 */
79 79
80 /// Return the Base value of the export directory. 80 /// Return the Base value of the export directory.
81 dword getBase() const; // EXPORT 81 dword getBase() const; // EXPORT
82 /// Return the Characteristics value of the export directory. 82 /// Return the Characteristics value of the export directory.
83 dword getCharacteristics() const; // EXPORT 83 dword getCharacteristics() const; // EXPORT
84 /// Return the TimeDateStamp value of the export directory. 84 /// Return the TimeDateStamp value of the export directory.
85 dword getTimeDateStamp() const; // EXPORT 85 dword getTimeDateStamp() const; // EXPORT
86 /// Return the MajorVersion value of the export directory. 86 /// Return the MajorVersion value of the export directory.
87 word getMajorVersion() const; // EXPORT 87 word getMajorVersion() const; // EXPORT
88 /// Return the MinorVersion value of the export directory. 88 /// Return the MinorVersion value of the export directory.
89 word getMinorVersion() const; // EXPORT 89 word getMinorVersion() const; // EXPORT
90 /// Return the Name value of the export directory. 90 /// Return the Name value of the export directory.
91 dword getName() const; // EXPORT 91 dword getName() const; // EXPORT
92 /// Return the NumberOfFunctions value of the export directory. 92 /// Return the NumberOfFunctions value of the export directory.
93 dword getNumberOfFunctions() const; // EXPORT 93 dword getNumberOfFunctions() const; // EXPORT
94 /// Return the NumberOfNames value of the export directory. 94 /// Return the NumberOfNames value of the export directory.
95 dword getNumberOfNames() const; // EXPORT 95 dword getNumberOfNames() const; // EXPORT
96 /// Return the AddressOfFunctions value of the export directory. 96 /// Return the AddressOfFunctions value of the export directory.
97 dword getAddressOfFunctions() const; // EXPORT 97 dword getAddressOfFunctions() const; // EXPORT
98 /// Return the AddressOfNames value of the export directory. 98 /// Return the AddressOfNames value of the export directory.
99 dword getAddressOfNames() const; // EXPORT 99 dword getAddressOfNames() const; // EXPORT
100 /// Returns the AddressOfNameOrdinals value. 100 /// Returns the AddressOfNameOrdinals value.
101 dword getAddressOfNameOrdinals() const; // EXPORT 101 dword getAddressOfNameOrdinals() const; // EXPORT
102 102
103/* /// Returns the number of NameOrdinals. 103/* /// Returns the number of NameOrdinals.
104 dword getNumberOfNameOrdinals() const; // EXPORT 104 dword getNumberOfNameOrdinals() const; // EXPORT
105 /// Returns the number of AddressOfFunctionNames values. 105 /// Returns the number of AddressOfFunctionNames values.
106 dword getNumberOfAddressOfFunctionNames() const; // EXPORT 106 dword getNumberOfAddressOfFunctionNames() const; // EXPORT
107 /// Returns the number of AddressOfFunction values. 107 /// Returns the number of AddressOfFunction values.
108 dword getNumberOfAddressOfFunctions() const; // EXPORT 108 dword getNumberOfAddressOfFunctions() const; // EXPORT
109*/ 109*/
110 /// Set the Base value of the export directory. 110 /// Set the Base value of the export directory.
111 void setBase(dword dwValue); // EXPORT 111 void setBase(dword dwValue); // EXPORT
112 /// Set the Characteristics value of the export directory. 112 /// Set the Characteristics value of the export directory.
113 void setCharacteristics(dword dwValue); // EXPORT 113 void setCharacteristics(dword dwValue); // EXPORT
114 /// Set the TimeDateStamp value of the export directory. 114 /// Set the TimeDateStamp value of the export directory.
115 void setTimeDateStamp(dword dwValue); // EXPORT 115 void setTimeDateStamp(dword dwValue); // EXPORT
116 /// Set the MajorVersion value of the export directory. 116 /// Set the MajorVersion value of the export directory.
117 void setMajorVersion(word wValue); // EXPORT 117 void setMajorVersion(word wValue); // EXPORT
118 /// Set the MinorVersion value of the export directory. 118 /// Set the MinorVersion value of the export directory.
119 void setMinorVersion(word wValue); // EXPORT 119 void setMinorVersion(word wValue); // EXPORT
120 /// Set the Name value of the export directory. 120 /// Set the Name value of the export directory.
121 void setName(dword dwValue); // EXPORT 121 void setName(dword dwValue); // EXPORT
122 /// Set the NumberOfFunctions value of the export directory. 122 /// Set the NumberOfFunctions value of the export directory.
123 void setNumberOfFunctions(dword dwValue); // EXPORT 123 void setNumberOfFunctions(dword dwValue); // EXPORT
124 /// Set the NumberOfNames value of the export directory. 124 /// Set the NumberOfNames value of the export directory.
125 void setNumberOfNames(dword dwValue); // EXPORT 125 void setNumberOfNames(dword dwValue); // EXPORT
126 /// Set the AddressOfFunctions value of the export directory. 126 /// Set the AddressOfFunctions value of the export directory.
127 void setAddressOfFunctions(dword dwValue); // EXPORT 127 void setAddressOfFunctions(dword dwValue); // EXPORT
128 /// Set the AddressOfNames value of the export directory. 128 /// Set the AddressOfNames value of the export directory.
129 void setAddressOfNames(dword dwValue); // EXPORT 129 void setAddressOfNames(dword dwValue); // EXPORT
130 void setAddressOfNameOrdinals(dword value); // EXPORT 130 void setAddressOfNameOrdinals(dword value); // EXPORT
131 }; 131 };
132} 132}
133#endif 133#endif
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/IatDirectory.cpp b/utils/zenutils/libraries/pelib-0.9/pelib/IatDirectory.cpp
index 36482fcbeb..b32cfb2a8e 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/IatDirectory.cpp
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/IatDirectory.cpp
@@ -1,179 +1,179 @@
1/* 1/*
2* IatDirectory.h - Part of the PeLib library. 2* IatDirectory.h - Part of the PeLib library.
3* 3*
4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) 4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5* All rights reserved. 5* All rights reserved.
6* 6*
7* This software is licensed under the zlib/libpng License. 7* This software is licensed under the zlib/libpng License.
8* For more details see http://www.opensource.org/licenses/zlib-license.php 8* For more details see http://www.opensource.org/licenses/zlib-license.php
9* or the license information file (license.htm) in the root directory 9* or the license information file (license.htm) in the root directory
10* of PeLib. 10* of PeLib.
11*/ 11*/
12 12
13#include "IatDirectory.h" 13#include "IatDirectory.h"
14 14
15namespace PeLib 15namespace PeLib
16{ 16{
17 int IatDirectory::read(InputBuffer& inputBuffer, unsigned int size) 17 int IatDirectory::read(InputBuffer& inputBuffer, unsigned int size)
18 { 18 {
19 dword dwAddr; 19 dword dwAddr;
20 20
21 std::vector<dword> vIat; 21 std::vector<dword> vIat;
22 22
23 for (unsigned int i=0;i<size/sizeof(dword);i++) 23 for (unsigned int i=0;i<size/sizeof(dword);i++)
24 { 24 {
25 inputBuffer >> dwAddr; 25 inputBuffer >> dwAddr;
26 vIat.push_back(dwAddr); 26 vIat.push_back(dwAddr);
27 } 27 }
28 28
29 std::swap(vIat, m_vIat); 29 std::swap(vIat, m_vIat);
30 30
31 return NO_ERROR; 31 return NO_ERROR;
32 } 32 }
33 33
34 /** 34 /**
35 * Reads the Import Address table from a file. 35 * Reads the Import Address table from a file.
36 * @param strFilename Name of the file. 36 * @param strFilename Name of the file.
37 * @param dwOffset File offset of the IAT (see #PeFile::PeHeader::getIDIatRVA). 37 * @param dwOffset File offset of the IAT (see #PeFile::PeHeader::getIDIatRVA).
38 * @param dwSize Size of the IAT (see #PeFile::PeHeader::getIDIatSize). 38 * @param dwSize Size of the IAT (see #PeFile::PeHeader::getIDIatSize).
39 **/ 39 **/
40 int IatDirectory::read(const std::string& strFilename, unsigned int dwOffset, unsigned int dwSize) 40 int IatDirectory::read(const std::string& strFilename, unsigned int dwOffset, unsigned int dwSize)
41 { 41 {
42 std::ifstream ifFile(strFilename.c_str(), std::ios::binary); 42 std::ifstream ifFile(strFilename.c_str(), std::ios::binary);
43 43
44 if (!ifFile) 44 if (!ifFile)
45 { 45 {
46 return ERROR_OPENING_FILE; 46 return ERROR_OPENING_FILE;
47 } 47 }
48 48
49 if (fileSize(ifFile) < dwOffset + dwSize) 49 if (fileSize(ifFile) < dwOffset + dwSize)
50 { 50 {
51 return ERROR_INVALID_FILE; 51 return ERROR_INVALID_FILE;
52 } 52 }
53 53
54 ifFile.seekg(dwOffset, std::ios::beg); 54 ifFile.seekg(dwOffset, std::ios::beg);
55 55
56 std::vector<byte> vBuffer(dwSize); 56 std::vector<byte> vBuffer(dwSize);
57 ifFile.read(reinterpret_cast<char*>(&vBuffer[0]), dwSize); 57 ifFile.read(reinterpret_cast<char*>(&vBuffer[0]), dwSize);
58 58
59 InputBuffer inpBuffer(vBuffer); 59 InputBuffer inpBuffer(vBuffer);
60 return read(inpBuffer, dwSize); 60 return read(inpBuffer, dwSize);
61 } 61 }
62 62
63 int IatDirectory::read(unsigned char* buffer, unsigned int buffersize) 63 int IatDirectory::read(unsigned char* buffer, unsigned int buffersize)
64 { 64 {
65 std::vector<byte> vBuffer(buffer, buffer + buffersize); 65 std::vector<byte> vBuffer(buffer, buffer + buffersize);
66 InputBuffer inpBuffer(vBuffer); 66 InputBuffer inpBuffer(vBuffer);
67 return read(inpBuffer, buffersize); 67 return read(inpBuffer, buffersize);
68 } 68 }
69 69
70 /** 70 /**
71 * Returns the number of fields in the IAT. This is equivalent to the number of 71 * Returns the number of fields in the IAT. This is equivalent to the number of
72 * imported functions. 72 * imported functions.
73 * @return Number of fields in the IAT. 73 * @return Number of fields in the IAT.
74 **/ 74 **/
75 unsigned int IatDirectory::calcNumberOfAddresses() const 75 unsigned int IatDirectory::calcNumberOfAddresses() const
76 { 76 {
77 return static_cast<unsigned int>(m_vIat.size()); 77 return static_cast<unsigned int>(m_vIat.size());
78 } 78 }
79 79
80 /** 80 /**
81 * Returns the dwValue of a field in the IAT. 81 * Returns the dwValue of a field in the IAT.
82 * @param dwAddrnr Number identifying the field. 82 * @param dwAddrnr Number identifying the field.
83 * @return dwValue of the field. 83 * @return dwValue of the field.
84 **/ 84 **/
85 dword IatDirectory::getAddress(unsigned int index) const 85 dword IatDirectory::getAddress(unsigned int index) const
86 { 86 {
87 return m_vIat[index]; 87 return m_vIat[index];
88 } 88 }
89 89
90 /** 90 /**
91 * Updates the dwValue of a field in the IAT. 91 * Updates the dwValue of a field in the IAT.
92 * @param dwAddrnr Number identifying the field. 92 * @param dwAddrnr Number identifying the field.
93 * @param dwValue New dwValue of the field. 93 * @param dwValue New dwValue of the field.
94 **/ 94 **/
95 void IatDirectory::setAddress(dword dwAddrnr, dword dwValue) 95 void IatDirectory::setAddress(dword dwAddrnr, dword dwValue)
96 { 96 {
97 m_vIat[dwAddrnr] = dwValue; 97 m_vIat[dwAddrnr] = dwValue;
98 } 98 }
99 99
100 /** 100 /**
101 * Adds another field to the IAT. 101 * Adds another field to the IAT.
102 * @param dwValue dwValue of the new field. 102 * @param dwValue dwValue of the new field.
103 **/ 103 **/
104 void IatDirectory::addAddress(dword dwValue) 104 void IatDirectory::addAddress(dword dwValue)
105 { 105 {
106 m_vIat.push_back(dwValue); 106 m_vIat.push_back(dwValue);
107 } 107 }
108 108
109 /** 109 /**
110 * Removes an address from the IAT. 110 * Removes an address from the IAT.
111 * @param dwAddrnr Number identifying the field. 111 * @param dwAddrnr Number identifying the field.
112 **/ 112 **/
113 void IatDirectory::removeAddress(unsigned int index) 113 void IatDirectory::removeAddress(unsigned int index)
114 { 114 {
115 std::vector<dword>::iterator pos = m_vIat.begin() + index; 115 std::vector<dword>::iterator pos = m_vIat.begin() + index;
116 m_vIat.erase(pos); 116 m_vIat.erase(pos);
117 } 117 }
118 118
119 /** 119 /**
120 * Delete all entries from the IAT. 120 * Delete all entries from the IAT.
121 **/ 121 **/
122 void IatDirectory::clear() 122 void IatDirectory::clear()
123 { 123 {
124 m_vIat.clear(); 124 m_vIat.clear();
125 } 125 }
126 126
127 /** 127 /**
128 * Rebuilds the complete Import Address Table. 128 * Rebuilds the complete Import Address Table.
129 * @param vBuffer Buffer where the rebuilt IAT will be stored. 129 * @param vBuffer Buffer where the rebuilt IAT will be stored.
130 **/ 130 **/
131 void IatDirectory::rebuild(std::vector<byte>& vBuffer) const 131 void IatDirectory::rebuild(std::vector<byte>& vBuffer) const
132 { 132 {
133 vBuffer.reserve(size()); 133 vBuffer.reserve(size());
134 OutputBuffer obBuffer(vBuffer); 134 OutputBuffer obBuffer(vBuffer);
135 135
136 for (unsigned int i=0;i<m_vIat.size();i++) 136 for (unsigned int i=0;i<m_vIat.size();i++)
137 { 137 {
138 obBuffer << m_vIat[i]; 138 obBuffer << m_vIat[i];
139 } 139 }
140 } 140 }
141 141
142 unsigned int IatDirectory::size() const 142 unsigned int IatDirectory::size() const
143 { 143 {
144 return static_cast<unsigned int>(m_vIat.size())* sizeof(dword); 144 return static_cast<unsigned int>(m_vIat.size())* sizeof(dword);
145 } 145 }
146 146
147 /// Writes the current IAT to a file. 147 /// Writes the current IAT to a file.
148 int IatDirectory::write(const std::string& strFilename, unsigned int uiOffset) const 148 int IatDirectory::write(const std::string& strFilename, unsigned int uiOffset) const
149 { 149 {
150 std::fstream ofFile(strFilename.c_str(), std::ios_base::in); 150 std::fstream ofFile(strFilename.c_str(), std::ios_base::in);
151 151
152 if (!ofFile) 152 if (!ofFile)
153 { 153 {
154 ofFile.clear(); 154 ofFile.clear();
155 ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary); 155 ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary);
156 } 156 }
157 else 157 else
158 { 158 {
159 ofFile.close(); 159 ofFile.close();
160 ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary); 160 ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary);
161 } 161 }
162 162
163 if (!ofFile) 163 if (!ofFile)
164 { 164 {
165 return ERROR_OPENING_FILE; 165 return ERROR_OPENING_FILE;
166 } 166 }
167 167
168 ofFile.seekp(uiOffset, std::ios::beg); 168 ofFile.seekp(uiOffset, std::ios::beg);
169 169
170 std::vector<unsigned char> vBuffer; 170 std::vector<unsigned char> vBuffer;
171 rebuild(vBuffer); 171 rebuild(vBuffer);
172 172
173 ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), static_cast<unsigned int>(vBuffer.size())); 173 ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), static_cast<unsigned int>(vBuffer.size()));
174 174
175 ofFile.close(); 175 ofFile.close();
176 176
177 return NO_ERROR; 177 return NO_ERROR;
178 } 178 }
179} 179}
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/IatDirectory.h b/utils/zenutils/libraries/pelib-0.9/pelib/IatDirectory.h
index 81ef77ed6a..26c5d4009c 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/IatDirectory.h
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/IatDirectory.h
@@ -1,58 +1,58 @@
1/* 1/*
2* IatDirectory.h - Part of the PeLib library. 2* IatDirectory.h - Part of the PeLib library.
3* 3*
4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) 4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5* All rights reserved. 5* All rights reserved.
6* 6*
7* This software is licensed under the zlib/libpng License. 7* This software is licensed under the zlib/libpng License.
8* For more details see http://www.opensource.org/licenses/zlib-license.php 8* For more details see http://www.opensource.org/licenses/zlib-license.php
9* or the license information file (license.htm) in the root directory 9* or the license information file (license.htm) in the root directory
10* of PeLib. 10* of PeLib.
11*/ 11*/
12 12
13#ifndef IATDIRECTORY_H 13#ifndef IATDIRECTORY_H
14#define IATDIRECTORY_H 14#define IATDIRECTORY_H
15 15
16#include "PeLibInc.h" 16#include "PeLibInc.h"
17 17
18namespace PeLib 18namespace PeLib
19{ 19{
20 /// Class that handles the Import Address Table (IAT) 20 /// Class that handles the Import Address Table (IAT)
21 /** 21 /**
22 * This class can read and modify the Import Address Table of a PE file. 22 * This class can read and modify the Import Address Table of a PE file.
23 **/ 23 **/
24 class IatDirectory 24 class IatDirectory
25 { 25 {
26 private: 26 private:
27 std::vector<dword> m_vIat; ///< Stores the individual IAT fields. 27 std::vector<dword> m_vIat; ///< Stores the individual IAT fields.
28 28
29 int read(InputBuffer& inputBuffer, unsigned int size); 29 int read(InputBuffer& inputBuffer, unsigned int size);
30 30
31 public: 31 public:
32 /// Reads the Import Address Table from a PE file. 32 /// Reads the Import Address Table from a PE file.
33 int read(const std::string& strFilename, unsigned int dwOffset, unsigned int dwSize); // EXPORT 33 int read(const std::string& strFilename, unsigned int dwOffset, unsigned int dwSize); // EXPORT
34 int read(unsigned char* buffer, unsigned int buffersize); // EXPORT 34 int read(unsigned char* buffer, unsigned int buffersize); // EXPORT
35 /// Returns the number of fields in the IAT. 35 /// Returns the number of fields in the IAT.
36 unsigned int calcNumberOfAddresses() const; // EXPORT 36 unsigned int calcNumberOfAddresses() const; // EXPORT
37 /// Adds another address to the IAT. 37 /// Adds another address to the IAT.
38 void addAddress(dword dwValue); // EXPORT 38 void addAddress(dword dwValue); // EXPORT
39 /// Removes an address from the IAT. 39 /// Removes an address from the IAT.
40 void removeAddress(unsigned int index); // EXPORT 40 void removeAddress(unsigned int index); // EXPORT
41 /// Empties the IAT. 41 /// Empties the IAT.
42 void clear(); // EXPORT 42 void clear(); // EXPORT
43 // Rebuilds the IAT. 43 // Rebuilds the IAT.
44 void rebuild(std::vector<byte>& vBuffer) const; // EXPORT 44 void rebuild(std::vector<byte>& vBuffer) const; // EXPORT
45 /// Returns the size of the current IAT. 45 /// Returns the size of the current IAT.
46 unsigned int size() const; // EXPORT 46 unsigned int size() const; // EXPORT
47 /// Writes the current IAT to a file. 47 /// Writes the current IAT to a file.
48 int write(const std::string& strFilename, unsigned int uiOffset) const; // EXPORT 48 int write(const std::string& strFilename, unsigned int uiOffset) const; // EXPORT
49 49
50 /// Retrieve the value of a field in the IAT. 50 /// Retrieve the value of a field in the IAT.
51 dword getAddress(unsigned int index) const; // EXPORT 51 dword getAddress(unsigned int index) const; // EXPORT
52 /// Change the value of a field in the IAT. 52 /// Change the value of a field in the IAT.
53 void setAddress(dword dwAddrnr, dword dwValue); // EXPORT 53 void setAddress(dword dwAddrnr, dword dwValue); // EXPORT
54 }; 54 };
55} 55}
56 56
57#endif 57#endif
58 58
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/ImportDirectory.h b/utils/zenutils/libraries/pelib-0.9/pelib/ImportDirectory.h
index 6578f0712a..42526f0c3c 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/ImportDirectory.h
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/ImportDirectory.h
@@ -1,1139 +1,1139 @@
1/* 1/*
2* ImportDirectory.h - Part of the PeLib library. 2* ImportDirectory.h - Part of the PeLib library.
3* 3*
4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) 4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5* All rights reserved. 5* All rights reserved.
6* 6*
7* This software is licensed under the zlib/libpng License. 7* This software is licensed under the zlib/libpng License.
8* For more details see http://www.opensource.org/licenses/zlib-license.php 8* For more details see http://www.opensource.org/licenses/zlib-license.php
9* or the license information file (license.htm) in the root directory 9* or the license information file (license.htm) in the root directory
10* of PeLib. 10* of PeLib.
11*/ 11*/
12 12
13#ifndef IMPORTDIRECTORY_H 13#ifndef IMPORTDIRECTORY_H
14#define IMPORTDIRECTORY_H 14#define IMPORTDIRECTORY_H
15 15
16#include "PeLibAux.h" 16#include "PeLibAux.h"
17#include "PeHeader.h" 17#include "PeHeader.h"
18 18
19namespace PeLib 19namespace PeLib
20{ 20{
21 /// Parameter for functions that can operate on the OLDDIR or new import directory. 21 /// Parameter for functions that can operate on the OLDDIR or new import directory.
22 enum currdir {OLDDIR = 1, NEWDIR}; 22 enum currdir {OLDDIR = 1, NEWDIR};
23 23
24 class PeLibException; 24 class PeLibException;
25 25
26 /// Class that handles import directories. 26 /// Class that handles import directories.
27 /** 27 /**
28 * This class can read import directories from existing PE files or start completely from scratch. 28 * This class can read import directories from existing PE files or start completely from scratch.
29 * Modifying import directories and writing them to files is also possible. 29 * Modifying import directories and writing them to files is also possible.
30 * It's worthy to note that many functions require an extra parameter of type currdir 30 * It's worthy to note that many functions require an extra parameter of type currdir
31 * because the structure of import directories make it necessary that the OLDDIR import directory 31 * because the structure of import directories make it necessary that the OLDDIR import directory
32 * must be preserved. That's why some functions (like adding and removing) imported functions 32 * must be preserved. That's why some functions (like adding and removing) imported functions
33 * only exist for the new import directory, not for the one which is already written to the file. 33 * only exist for the new import directory, not for the one which is already written to the file.
34 * \todo Adding functions by ordinal doesn't work yet (rebuild needs to be changed). 34 * \todo Adding functions by ordinal doesn't work yet (rebuild needs to be changed).
35 * \todo Somehow store the rvas of the chunks in the file. 35 * \todo Somehow store the rvas of the chunks in the file.
36 **/ 36 **/
37 template<int bits> 37 template<int bits>
38 class ImportDirectory 38 class ImportDirectory
39 { 39 {
40 typedef typename std::vector<PELIB_IMAGE_IMPORT_DIRECTORY<bits> >::iterator ImpDirFileIterator; 40 typedef typename std::vector<PELIB_IMAGE_IMPORT_DIRECTORY<bits> >::iterator ImpDirFileIterator;
41 typedef typename std::vector<PELIB_IMAGE_IMPORT_DIRECTORY<bits> >::const_iterator ConstImpDirFileIterator; 41 typedef typename std::vector<PELIB_IMAGE_IMPORT_DIRECTORY<bits> >::const_iterator ConstImpDirFileIterator;
42 42
43 private: 43 private:
44 /// Stores information about already imported DLLs. 44 /// Stores information about already imported DLLs.
45 std::vector<PELIB_IMAGE_IMPORT_DIRECTORY<bits> > m_vOldiid; 45 std::vector<PELIB_IMAGE_IMPORT_DIRECTORY<bits> > m_vOldiid;
46 /// Stores information about imported DLLs which will be added. 46 /// Stores information about imported DLLs which will be added.
47 std::vector<PELIB_IMAGE_IMPORT_DIRECTORY<bits> > m_vNewiid; 47 std::vector<PELIB_IMAGE_IMPORT_DIRECTORY<bits> > m_vNewiid;
48 48
49 // I can't convince Borland C++ to compile the function outside of the class declaration. 49 // I can't convince Borland C++ to compile the function outside of the class declaration.
50 // That's why the function definition is here. 50 // That's why the function definition is here.
51 /// Tests if a certain function is imported. 51 /// Tests if a certain function is imported.
52 template<typename T> bool hasFunction(std::string strFilename, T value, bool(PELIB_THUNK_DATA<bits>::* comp)(T) const) const 52 template<typename T> bool hasFunction(std::string strFilename, T value, bool(PELIB_THUNK_DATA<bits>::* comp)(T) const) const
53 { 53 {
54 ConstImpDirFileIterator FileIter = m_vOldiid.begin(); 54 ConstImpDirFileIterator FileIter = m_vOldiid.begin();
55 ConstImpDirFileIterator EndIter = m_vOldiid.end(); 55 ConstImpDirFileIterator EndIter = m_vOldiid.end();
56 56
57 for (int i=0;i<=1;i++) // Loop once for m_vOldiid and once for m_vNewiid 57 for (int i=0;i<=1;i++) // Loop once for m_vOldiid and once for m_vNewiid
58 { 58 {
59 do 59 do
60 { 60 {
61 FileIter = std::find_if(FileIter, EndIter, std::bind2nd(std::mem_fun_ref(&PELIB_IMAGE_IMPORT_DIRECTORY<bits>::operator==), strFilename)); 61 FileIter = std::find_if(FileIter, EndIter, std::bind2nd(std::mem_fun_ref(&PELIB_IMAGE_IMPORT_DIRECTORY<bits>::operator==), strFilename));
62 62
63 if (FileIter != EndIter) 63 if (FileIter != EndIter)
64 { 64 {
65 typename std::vector<PELIB_THUNK_DATA<bits> >::const_iterator Iter = std::find_if(FileIter->originalfirstthunk.begin(), FileIter->originalfirstthunk.end(), std::bind2nd(std::mem_fun_ref(comp), value)); 65 typename std::vector<PELIB_THUNK_DATA<bits> >::const_iterator Iter = std::find_if(FileIter->originalfirstthunk.begin(), FileIter->originalfirstthunk.end(), std::bind2nd(std::mem_fun_ref(comp), value));
66 if (Iter != FileIter->originalfirstthunk.end()) 66 if (Iter != FileIter->originalfirstthunk.end())
67 { 67 {
68 return true; 68 return true;
69 } 69 }
70 ++FileIter; 70 ++FileIter;
71 } 71 }
72 } 72 }
73 while (FileIter != EndIter); 73 while (FileIter != EndIter);
74 74
75 FileIter = m_vNewiid.begin(); 75 FileIter = m_vNewiid.begin();
76 EndIter = m_vNewiid.end(); 76 EndIter = m_vNewiid.end();
77 } 77 }
78 78
79 return false; 79 return false;
80 } 80 }
81 81
82 82
83 public: 83 public:
84 84
85 /// Add a function to the import directory. 85 /// Add a function to the import directory.
86 int addFunction(const std::string& strFilename, word wHint); // EXPORT _byHint 86 int addFunction(const std::string& strFilename, word wHint); // EXPORT _byHint
87 /// Add a function to the import directory. 87 /// Add a function to the import directory.
88 int addFunction(const std::string& strFilename, const std::string& strFuncname); // EXPORT _byName 88 int addFunction(const std::string& strFilename, const std::string& strFuncname); // EXPORT _byName
89 89
90 /// Get the ID of a file through it's name. 90 /// Get the ID of a file through it's name.
91 unsigned int getFileIndex(const std::string& strFilename, currdir cdDir) const; // EXPORT 91 unsigned int getFileIndex(const std::string& strFilename, currdir cdDir) const; // EXPORT
92 /// Get the ID of a function through it's name. 92 /// Get the ID of a function through it's name.
93 unsigned int getFunctionIndex(const std::string& strFilename, const std::string& strFuncname, currdir cdDir) const; // EXPORT 93 unsigned int getFunctionIndex(const std::string& strFilename, const std::string& strFuncname, currdir cdDir) const; // EXPORT
94 94
95 /// Get the name of an imported file. 95 /// Get the name of an imported file.
96 std::string getFileName(dword dwFilenr, currdir cdDir) const; // EXPORT 96 std::string getFileName(dword dwFilenr, currdir cdDir) const; // EXPORT
97 97
98 void setFileName(dword filenr, currdir dir, const std::string& name); // EXPORT 98 void setFileName(dword filenr, currdir dir, const std::string& name); // EXPORT
99 99
100 /// Get the hint of an imported function. 100 /// Get the hint of an imported function.
101 word getFunctionHint(dword dwFilenr, dword dwFuncnr, currdir cdDir) const; // EXPORT 101 word getFunctionHint(dword dwFilenr, dword dwFuncnr, currdir cdDir) const; // EXPORT
102 void setFunctionHint(dword dwFilenr, dword dwFuncnr, currdir cdDir, word value); // EXPORT 102 void setFunctionHint(dword dwFilenr, dword dwFuncnr, currdir cdDir, word value); // EXPORT
103 /// Get the name of an imported function. 103 /// Get the name of an imported function.
104 std::string getFunctionName(dword dwFilenr, dword dwFuncnr, currdir cdDir) const; // EXPORT 104 std::string getFunctionName(dword dwFilenr, dword dwFuncnr, currdir cdDir) const; // EXPORT
105 void setFunctionName(dword dwFilenr, dword dwFuncnr, currdir cdDir, const std::string& functionName); // EXPORT 105 void setFunctionName(dword dwFilenr, dword dwFuncnr, currdir cdDir, const std::string& functionName); // EXPORT
106 /// Get the number of files which are imported. 106 /// Get the number of files which are imported.
107 dword getNumberOfFiles(currdir cdDir) const; // EXPORT 107 dword getNumberOfFiles(currdir cdDir) const; // EXPORT
108 /// Get the number of fucntions which are imported by a specific file. 108 /// Get the number of fucntions which are imported by a specific file.
109 dword getNumberOfFunctions(dword dwFilenr, currdir cdDir) const; // EXPORT 109 dword getNumberOfFunctions(dword dwFilenr, currdir cdDir) const; // EXPORT
110 /// Read a file's import directory. 110 /// Read a file's import directory.
111 int read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize, const PeHeaderT<bits>& pehHeader); // EXPORT 111 int read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize, const PeHeaderT<bits>& pehHeader); // EXPORT
112 /// Rebuild the import directory. 112 /// Rebuild the import directory.
113 void rebuild(std::vector<byte>& vBuffer, dword dwRva, bool fixEntries = true) const; // EXPORT 113 void rebuild(std::vector<byte>& vBuffer, dword dwRva, bool fixEntries = true) const; // EXPORT
114 /// Remove a file from the import directory. 114 /// Remove a file from the import directory.
115 int removeFile(const std::string& strFilename); // EXPORT 115 int removeFile(const std::string& strFilename); // EXPORT
116 /// Remove a function from the import directory. 116 /// Remove a function from the import directory.
117 int removeFunction(const std::string& strFilename, const std::string& strFuncname); // EXPORT _byName 117 int removeFunction(const std::string& strFilename, const std::string& strFuncname); // EXPORT _byName
118 /// Remove a function from the import directory. 118 /// Remove a function from the import directory.
119 int removeFunction(const std::string& strFilename, word wHint); // EXPORT _byHint 119 int removeFunction(const std::string& strFilename, word wHint); // EXPORT _byHint
120 /// Returns the size of the current import directory. 120 /// Returns the size of the current import directory.
121 unsigned int size() const; // EXPORT 121 unsigned int size() const; // EXPORT
122 /// Writes the import directory to a file. 122 /// Writes the import directory to a file.
123 int write(const std::string& strFilename, unsigned int uiOffset, unsigned int uiRva); // EXPORT 123 int write(const std::string& strFilename, unsigned int uiOffset, unsigned int uiRva); // EXPORT
124 124
125 /// Returns the FirstThunk value of a function. 125 /// Returns the FirstThunk value of a function.
126 dword getFirstThunk(dword dwFilenr, dword dwFuncnr, currdir cdDir) const; // EXPORT _byNumber 126 dword getFirstThunk(dword dwFilenr, dword dwFuncnr, currdir cdDir) const; // EXPORT _byNumber
127 void setFirstThunk(dword dwFilenr, dword dwFuncnr, currdir cdDir, dword value); // EXPORT _byNumber 127 void setFirstThunk(dword dwFilenr, dword dwFuncnr, currdir cdDir, dword value); // EXPORT _byNumber
128 /// Returns the OriginalFirstThunk value of a function. 128 /// Returns the OriginalFirstThunk value of a function.
129 dword getOriginalFirstThunk(dword dwFilenr, dword dwFuncnr, currdir cdDir) const; // EXPORT _byNumber 129 dword getOriginalFirstThunk(dword dwFilenr, dword dwFuncnr, currdir cdDir) const; // EXPORT _byNumber
130 void setOriginalFirstThunk(dword dwFilenr, dword dwFuncnr, currdir cdDir, dword value); // EXPORT 130 void setOriginalFirstThunk(dword dwFilenr, dword dwFuncnr, currdir cdDir, dword value); // EXPORT
131 131
132// dword getFirstThunk(const std::string& strFilename, const std::string& strFuncname, currdir cdDir) const throw (PeLibException); 132// dword getFirstThunk(const std::string& strFilename, const std::string& strFuncname, currdir cdDir) const throw (PeLibException);
133// dword getOriginalFirstThunk(const std::string& strFilename, const std::string& strFuncname, currdir cdDir) const throw (PeLibException); 133// dword getOriginalFirstThunk(const std::string& strFilename, const std::string& strFuncname, currdir cdDir) const throw (PeLibException);
134 134
135 /// Returns the FirstThunk value of a file. 135 /// Returns the FirstThunk value of a file.
136 dword getFirstThunk(const std::string& strFilename, currdir cdDir) const; // EXPORT _byName 136 dword getFirstThunk(const std::string& strFilename, currdir cdDir) const; // EXPORT _byName
137 /// Returns the OriginalFirstThunk value of a file. 137 /// Returns the OriginalFirstThunk value of a file.
138 dword getOriginalFirstThunk(const std::string& strFilename, currdir cdDir) const; // EXPORT _byName 138 dword getOriginalFirstThunk(const std::string& strFilename, currdir cdDir) const; // EXPORT _byName
139 /// Returns the ForwarderChain value of a file. 139 /// Returns the ForwarderChain value of a file.
140 dword getForwarderChain(const std::string& strFilename, currdir cdDir) const; // EXPORT _byName 140 dword getForwarderChain(const std::string& strFilename, currdir cdDir) const; // EXPORT _byName
141 dword getRvaOfName(const std::string& strFilename, currdir cdDir) const; // EXPORT _byName 141 dword getRvaOfName(const std::string& strFilename, currdir cdDir) const; // EXPORT _byName
142 /// Returns the TimeDateStamp value of a file. 142 /// Returns the TimeDateStamp value of a file.
143 dword getTimeDateStamp(const std::string& strFilename, currdir cdDir) const; // EXPORT _byName 143 dword getTimeDateStamp(const std::string& strFilename, currdir cdDir) const; // EXPORT _byName
144 144
145 /// Returns the FirstThunk value of a file. 145 /// Returns the FirstThunk value of a file.
146 dword getFirstThunk(dword dwFilenr, currdir cdDir) const; // EXPORT 146 dword getFirstThunk(dword dwFilenr, currdir cdDir) const; // EXPORT
147 void setFirstThunk(dword dwFilenr, currdir cdDir, dword value); // EXPORT _byNumber_function 147 void setFirstThunk(dword dwFilenr, currdir cdDir, dword value); // EXPORT _byNumber_function
148 /// Returns the OriginalFirstThunk value of a file. 148 /// Returns the OriginalFirstThunk value of a file.
149 dword getOriginalFirstThunk(dword dwFilenr, currdir cdDir) const; // EXPORT 149 dword getOriginalFirstThunk(dword dwFilenr, currdir cdDir) const; // EXPORT
150 void setOriginalFirstThunk(dword dwFilenr, currdir cdDir, dword value); // EXPORT _byNumber_function 150 void setOriginalFirstThunk(dword dwFilenr, currdir cdDir, dword value); // EXPORT _byNumber_function
151 /// Returns the ForwarderChain value of a file. 151 /// Returns the ForwarderChain value of a file.
152 dword getForwarderChain(dword dwFilenr, currdir cdDir) const; // EXPORT _byNumber 152 dword getForwarderChain(dword dwFilenr, currdir cdDir) const; // EXPORT _byNumber
153 void setForwarderChain(dword dwFilenr, currdir cdDir, dword value); // EXPORT _byNumber_function 153 void setForwarderChain(dword dwFilenr, currdir cdDir, dword value); // EXPORT _byNumber_function
154 dword getRvaOfName(dword dwFilenr, currdir cdDir) const; // EXPORT _byNumber 154 dword getRvaOfName(dword dwFilenr, currdir cdDir) const; // EXPORT _byNumber
155 void setRvaOfName(dword dwFilenr, currdir cdDir, dword value); // EXPORT 155 void setRvaOfName(dword dwFilenr, currdir cdDir, dword value); // EXPORT
156 /// Returns the TimeDateStamp value of a file. 156 /// Returns the TimeDateStamp value of a file.
157 dword getTimeDateStamp(dword dwFilenr, currdir cdDir) const; // EXPORT 157 dword getTimeDateStamp(dword dwFilenr, currdir cdDir) const; // EXPORT
158 void setTimeDateStamp(dword dwFilenr, currdir cdDir, dword value); // EXPORT _byNumber 158 void setTimeDateStamp(dword dwFilenr, currdir cdDir, dword value); // EXPORT _byNumber
159 159
160// word getFunctionHint(const std::string& strFilename, const std::string& strFuncname, currdir cdDir) const throw (PeLibException); 160// word getFunctionHint(const std::string& strFilename, const std::string& strFuncname, currdir cdDir) const throw (PeLibException);
161 }; 161 };
162 162
163 /** 163 /**
164 * Add another import (by Ordinal) to the current file. Note that the import table is not automatically updated. 164 * Add another import (by Ordinal) to the current file. Note that the import table is not automatically updated.
165 * The new imported functions will be added when you recalculate the import table as it's necessary 165 * The new imported functions will be added when you recalculate the import table as it's necessary
166 * to specify the address the import table will have in the file. 166 * to specify the address the import table will have in the file.
167 * @param strFilename The name of a DLL. 167 * @param strFilename The name of a DLL.
168 * @param wHint The ordinal of the function in the DLL. 168 * @param wHint The ordinal of the function in the DLL.
169 **/ 169 **/
170 template<int bits> 170 template<int bits>
171 int ImportDirectory<bits>::addFunction(const std::string& strFilename, word wHint) 171 int ImportDirectory<bits>::addFunction(const std::string& strFilename, word wHint)
172 { 172 {
173 if (hasFunction(strFilename, wHint, &PELIB_THUNK_DATA<bits>::equalHint)) 173 if (hasFunction(strFilename, wHint, &PELIB_THUNK_DATA<bits>::equalHint))
174 { 174 {
175 return ERROR_DUPLICATE_ENTRY; 175 return ERROR_DUPLICATE_ENTRY;
176 } 176 }
177 177
178 // Find the imported file. 178 // Find the imported file.
179 ImpDirFileIterator FileIter = std::find_if(m_vNewiid.begin(), m_vNewiid.end(), std::bind2nd(std::mem_fun_ref(&PELIB_IMAGE_IMPORT_DIRECTORY<bits>::operator==), strFilename)); 179 ImpDirFileIterator FileIter = std::find_if(m_vNewiid.begin(), m_vNewiid.end(), std::bind2nd(std::mem_fun_ref(&PELIB_IMAGE_IMPORT_DIRECTORY<bits>::operator==), strFilename));
180 180
181 PELIB_IMAGE_IMPORT_DIRECTORY<bits> iid; 181 PELIB_IMAGE_IMPORT_DIRECTORY<bits> iid;
182 PELIB_THUNK_DATA<bits> td; 182 PELIB_THUNK_DATA<bits> td;
183 td.hint = wHint; 183 td.hint = wHint;
184 td.itd.Ordinal = wHint | PELIB_IMAGE_ORDINAL_FLAGS<bits>::IMAGE_ORDINAL_FLAG; 184 td.itd.Ordinal = wHint | PELIB_IMAGE_ORDINAL_FLAGS<bits>::IMAGE_ORDINAL_FLAG;
185 iid.name = strFilename; 185 iid.name = strFilename;
186 if (FileIter == m_vNewiid.end()) 186 if (FileIter == m_vNewiid.end())
187 { 187 {
188 iid.originalfirstthunk.push_back(td); 188 iid.originalfirstthunk.push_back(td);
189 iid.firstthunk.push_back(td); 189 iid.firstthunk.push_back(td);
190 m_vNewiid.push_back(iid); 190 m_vNewiid.push_back(iid);
191 } 191 }
192 else 192 else
193 { 193 {
194 FileIter->originalfirstthunk.push_back(td); 194 FileIter->originalfirstthunk.push_back(td);
195 FileIter->firstthunk.push_back(td); 195 FileIter->firstthunk.push_back(td);
196 } 196 }
197 197
198 return NO_ERROR; 198 return NO_ERROR;
199 } 199 }
200 200
201 /** 201 /**
202 * Add a function to the Import Directory. 202 * Add a function to the Import Directory.
203 * @param strFilename Name of the file which will be imported 203 * @param strFilename Name of the file which will be imported
204 * @param strFuncname Name of the function which will be imported. 204 * @param strFuncname Name of the function which will be imported.
205 **/ 205 **/
206 template<int bits> 206 template<int bits>
207 int ImportDirectory<bits>::addFunction(const std::string& strFilename, const std::string& strFuncname) 207 int ImportDirectory<bits>::addFunction(const std::string& strFilename, const std::string& strFuncname)
208 { 208 {
209 if (hasFunction(strFilename, strFuncname, &PELIB_THUNK_DATA<bits>::equalFunctionName)) 209 if (hasFunction(strFilename, strFuncname, &PELIB_THUNK_DATA<bits>::equalFunctionName))
210 { 210 {
211 return ERROR_DUPLICATE_ENTRY; 211 return ERROR_DUPLICATE_ENTRY;
212 } 212 }
213 213
214 // Find the imported file. 214 // Find the imported file.
215 ImpDirFileIterator FileIter = std::find_if(m_vNewiid.begin(), m_vNewiid.end(), std::bind2nd(std::mem_fun_ref(&PELIB_IMAGE_IMPORT_DIRECTORY<bits>::operator==), strFilename)); 215 ImpDirFileIterator FileIter = std::find_if(m_vNewiid.begin(), m_vNewiid.end(), std::bind2nd(std::mem_fun_ref(&PELIB_IMAGE_IMPORT_DIRECTORY<bits>::operator==), strFilename));
216 216
217 PELIB_IMAGE_IMPORT_DIRECTORY<bits> iid; 217 PELIB_IMAGE_IMPORT_DIRECTORY<bits> iid;
218 PELIB_THUNK_DATA<bits> td; 218 PELIB_THUNK_DATA<bits> td;
219 td.fname = strFuncname; 219 td.fname = strFuncname;
220 iid.name = strFilename; 220 iid.name = strFilename;
221 if (FileIter == m_vNewiid.end()) 221 if (FileIter == m_vNewiid.end())
222 { 222 {
223 iid.originalfirstthunk.push_back(td); 223 iid.originalfirstthunk.push_back(td);
224 iid.firstthunk.push_back(td); 224 iid.firstthunk.push_back(td);
225 m_vNewiid.push_back(iid); 225 m_vNewiid.push_back(iid);
226 } 226 }
227 else 227 else
228 { 228 {
229 FileIter->originalfirstthunk.push_back(td); 229 FileIter->originalfirstthunk.push_back(td);
230 FileIter->firstthunk.push_back(td); 230 FileIter->firstthunk.push_back(td);
231 } 231 }
232 232
233 return NO_ERROR; 233 return NO_ERROR;
234 } 234 }
235 235
236 /** 236 /**
237 * Searches through the import directory and returns the number of the import 237 * Searches through the import directory and returns the number of the import
238 * directory entry which belongs to the given filename. 238 * directory entry which belongs to the given filename.
239 * @param strFilename Name of the imported file. 239 * @param strFilename Name of the imported file.
240 * @param cdDir Flag to decide if the OLDDIR or new import directory is used. 240 * @param cdDir Flag to decide if the OLDDIR or new import directory is used.
241 * @return The ID of an imported file. 241 * @return The ID of an imported file.
242 **/ 242 **/
243 template<int bits> 243 template<int bits>
244 unsigned int ImportDirectory<bits>::getFileIndex(const std::string& strFilename, currdir cdDir) const 244 unsigned int ImportDirectory<bits>::getFileIndex(const std::string& strFilename, currdir cdDir) const
245 { 245 {
246 const std::vector<PELIB_IMAGE_IMPORT_DIRECTORY<bits> >* currDir; 246 const std::vector<PELIB_IMAGE_IMPORT_DIRECTORY<bits> >* currDir;
247 247
248 if (cdDir == OLDDIR) 248 if (cdDir == OLDDIR)
249 { 249 {
250 currDir = &m_vOldiid; 250 currDir = &m_vOldiid;
251 } 251 }
252 else 252 else
253 { 253 {
254 currDir = &m_vNewiid; 254 currDir = &m_vNewiid;
255 } 255 }
256 256
257 ConstImpDirFileIterator FileIter = std::find_if(currDir->begin(), currDir->end(), std::bind2nd(std::mem_fun_ref(&PELIB_IMAGE_IMPORT_DIRECTORY<bits>::operator==), strFilename)); 257 ConstImpDirFileIterator FileIter = std::find_if(currDir->begin(), currDir->end(), std::bind2nd(std::mem_fun_ref(&PELIB_IMAGE_IMPORT_DIRECTORY<bits>::operator==), strFilename));
258 258
259 if (FileIter != currDir->end()) 259 if (FileIter != currDir->end())
260 { 260 {
261 return static_cast<unsigned int>(std::distance(currDir->begin(), FileIter)); 261 return static_cast<unsigned int>(std::distance(currDir->begin(), FileIter));
262 } 262 }
263 else 263 else
264 { 264 {
265 return -1; 265 return -1;
266 // throw Exceptions::InvalidName(ImportDirectoryId, __LINE__); 266 // throw Exceptions::InvalidName(ImportDirectoryId, __LINE__);
267 } 267 }
268 268
269 return NO_ERROR; 269 return NO_ERROR;
270 } 270 }
271 271
272 /** 272 /**
273 * Searches through an imported file for a specific function. 273 * Searches through an imported file for a specific function.
274 * @param strFilename Name of the imported file. 274 * @param strFilename Name of the imported file.
275 * @param strFuncname Name of the imported function. 275 * @param strFuncname Name of the imported function.
276 * @param cdDir Flag to decide if the OLDDIR or new import directory is used. 276 * @param cdDir Flag to decide if the OLDDIR or new import directory is used.
277 * @return ID of the imported function. 277 * @return ID of the imported function.
278 **/ 278 **/
279 template<int bits> 279 template<int bits>
280 unsigned int ImportDirectory<bits>::getFunctionIndex(const std::string& strFilename, const std::string& strFuncname, currdir cdDir) const 280 unsigned int ImportDirectory<bits>::getFunctionIndex(const std::string& strFilename, const std::string& strFuncname, currdir cdDir) const
281 { 281 {
282 unsigned int uiFile = getFileIndex(strFilename, cdDir); 282 unsigned int uiFile = getFileIndex(strFilename, cdDir);
283 283
284 for (unsigned int i=0;i<getNumberOfFunctions(uiFile, cdDir);i++) 284 for (unsigned int i=0;i<getNumberOfFunctions(uiFile, cdDir);i++)
285 { 285 {
286 if (getFunctionName(uiFile, i, cdDir) == strFuncname) return i; 286 if (getFunctionName(uiFile, i, cdDir) == strFuncname) return i;
287 } 287 }
288 288
289 return -1; 289 return -1;
290 } 290 }
291 291
292 /** 292 /**
293 * Get the name of an imported file. 293 * Get the name of an imported file.
294 * @param dwFilenr Identifies which file should be checked. 294 * @param dwFilenr Identifies which file should be checked.
295 * @param cdDir Flag to decide if the OLDDIR or new import directory is used. 295 * @param cdDir Flag to decide if the OLDDIR or new import directory is used.
296 * @return Name of an imported file. 296 * @return Name of an imported file.
297 **/ 297 **/
298 template<int bits> 298 template<int bits>
299 std::string ImportDirectory<bits>::getFileName(dword dwFilenr, currdir cdDir) const 299 std::string ImportDirectory<bits>::getFileName(dword dwFilenr, currdir cdDir) const
300 { 300 {
301 if (cdDir == OLDDIR) return m_vOldiid[dwFilenr].name; 301 if (cdDir == OLDDIR) return m_vOldiid[dwFilenr].name;
302 else return m_vNewiid[dwFilenr].name; 302 else return m_vNewiid[dwFilenr].name;
303 } 303 }
304 304
305 template<int bits> 305 template<int bits>
306 void ImportDirectory<bits>::setFileName(dword filenr, currdir dir, const std::string& name) 306 void ImportDirectory<bits>::setFileName(dword filenr, currdir dir, const std::string& name)
307 { 307 {
308 if (dir == OLDDIR) m_vOldiid[filenr].name = name; 308 if (dir == OLDDIR) m_vOldiid[filenr].name = name;
309 else m_vNewiid[filenr].name = name; 309 else m_vNewiid[filenr].name = name;
310 } 310 }
311 311
312 /** 312 /**
313 * Get the name of an imported function. 313 * Get the name of an imported function.
314 * @param dwFilenr Identifies which file should be checked. 314 * @param dwFilenr Identifies which file should be checked.
315 * @param dwFuncnr Identifies which function should be checked. 315 * @param dwFuncnr Identifies which function should be checked.
316 * @param cdDir Flag to decide if the OLDDIR or new import directory is used. 316 * @param cdDir Flag to decide if the OLDDIR or new import directory is used.
317 * @return Name of an imported function. 317 * @return Name of an imported function.
318 * \todo Marked line is unsafe (function should be rewritten). 318 * \todo Marked line is unsafe (function should be rewritten).
319 **/ 319 **/
320 template<int bits> 320 template<int bits>
321 std::string ImportDirectory<bits>::getFunctionName(dword dwFilenr, dword dwFuncnr, currdir cdDir) const 321 std::string ImportDirectory<bits>::getFunctionName(dword dwFilenr, dword dwFuncnr, currdir cdDir) const
322 { 322 {
323 if (cdDir == OLDDIR) 323 if (cdDir == OLDDIR)
324 { 324 {
325 // Unsafe 325 // Unsafe
326 if (m_vOldiid[dwFilenr].impdesc.OriginalFirstThunk) 326 if (m_vOldiid[dwFilenr].impdesc.OriginalFirstThunk)
327 { 327 {
328 return m_vOldiid[dwFilenr].originalfirstthunk[dwFuncnr].fname; 328 return m_vOldiid[dwFilenr].originalfirstthunk[dwFuncnr].fname;
329 } 329 }
330 else 330 else
331 { 331 {
332 return m_vOldiid[dwFilenr].firstthunk[dwFuncnr].fname; 332 return m_vOldiid[dwFilenr].firstthunk[dwFuncnr].fname;
333 } 333 }
334 } 334 }
335 else 335 else
336 { 336 {
337 if (m_vNewiid[dwFilenr].impdesc.OriginalFirstThunk) 337 if (m_vNewiid[dwFilenr].impdesc.OriginalFirstThunk)
338 { 338 {
339 return m_vNewiid[dwFilenr].originalfirstthunk[dwFuncnr].fname; 339 return m_vNewiid[dwFilenr].originalfirstthunk[dwFuncnr].fname;
340 } 340 }
341 else 341 else
342 { 342 {
343 return m_vNewiid[dwFilenr].firstthunk[dwFuncnr].fname; 343 return m_vNewiid[dwFilenr].firstthunk[dwFuncnr].fname;
344 } 344 }
345 } 345 }
346 } 346 }
347 347
348 template<int bits> 348 template<int bits>
349 void ImportDirectory<bits>::setFunctionName(dword dwFilenr, dword dwFuncnr, currdir cdDir, const std::string& functionName) 349 void ImportDirectory<bits>::setFunctionName(dword dwFilenr, dword dwFuncnr, currdir cdDir, const std::string& functionName)
350 { 350 {
351 if (cdDir == OLDDIR) 351 if (cdDir == OLDDIR)
352 { 352 {
353 // Unsafe 353 // Unsafe
354 if (m_vOldiid[dwFilenr].impdesc.OriginalFirstThunk) 354 if (m_vOldiid[dwFilenr].impdesc.OriginalFirstThunk)
355 { 355 {
356 m_vOldiid[dwFilenr].originalfirstthunk[dwFuncnr].fname = functionName; 356 m_vOldiid[dwFilenr].originalfirstthunk[dwFuncnr].fname = functionName;
357 } 357 }
358 else 358 else
359 { 359 {
360 m_vOldiid[dwFilenr].firstthunk[dwFuncnr].fname = functionName; 360 m_vOldiid[dwFilenr].firstthunk[dwFuncnr].fname = functionName;
361 } 361 }
362 } 362 }
363 else 363 else
364 { 364 {
365 if (m_vNewiid[dwFilenr].impdesc.OriginalFirstThunk) 365 if (m_vNewiid[dwFilenr].impdesc.OriginalFirstThunk)
366 { 366 {
367 m_vNewiid[dwFilenr].originalfirstthunk[dwFuncnr].fname = functionName; 367 m_vNewiid[dwFilenr].originalfirstthunk[dwFuncnr].fname = functionName;
368 } 368 }
369 else 369 else
370 { 370 {
371 m_vNewiid[dwFilenr].firstthunk[dwFuncnr].fname = functionName; 371 m_vNewiid[dwFilenr].firstthunk[dwFuncnr].fname = functionName;
372 } 372 }
373 } 373 }
374 } 374 }
375 375
376 /** 376 /**
377 * Get the hint of an imported function. 377 * Get the hint of an imported function.
378 * @param dwFilenr Identifies which file should be checked. 378 * @param dwFilenr Identifies which file should be checked.
379 * @param dwFuncnr Identifies which function should be checked. 379 * @param dwFuncnr Identifies which function should be checked.
380 * @param cdDir Flag to decide if the OLDDIR or new import directory is used. 380 * @param cdDir Flag to decide if the OLDDIR or new import directory is used.
381 * @return Hint of an imported function. 381 * @return Hint of an imported function.
382 **/ 382 **/
383 template<int bits> 383 template<int bits>
384 word ImportDirectory<bits>::getFunctionHint(dword dwFilenr, dword dwFuncnr, currdir cdDir) const 384 word ImportDirectory<bits>::getFunctionHint(dword dwFilenr, dword dwFuncnr, currdir cdDir) const
385 { 385 {
386 if (cdDir == OLDDIR) 386 if (cdDir == OLDDIR)
387 { 387 {
388 if (m_vOldiid[dwFilenr].impdesc.OriginalFirstThunk) 388 if (m_vOldiid[dwFilenr].impdesc.OriginalFirstThunk)
389 { 389 {
390 return m_vOldiid[dwFilenr].originalfirstthunk[dwFuncnr].hint; 390 return m_vOldiid[dwFilenr].originalfirstthunk[dwFuncnr].hint;
391 } 391 }
392 else 392 else
393 { 393 {
394 return m_vOldiid[dwFilenr].firstthunk[dwFuncnr].hint; 394 return m_vOldiid[dwFilenr].firstthunk[dwFuncnr].hint;
395 } 395 }
396 } 396 }
397 else return m_vNewiid[dwFilenr].originalfirstthunk[dwFuncnr].hint; 397 else return m_vNewiid[dwFilenr].originalfirstthunk[dwFuncnr].hint;
398 } 398 }
399 399
400 template<int bits> 400 template<int bits>
401 void ImportDirectory<bits>::setFunctionHint(dword dwFilenr, dword dwFuncnr, currdir cdDir, word value) 401 void ImportDirectory<bits>::setFunctionHint(dword dwFilenr, dword dwFuncnr, currdir cdDir, word value)
402 { 402 {
403 if (cdDir == OLDDIR) 403 if (cdDir == OLDDIR)
404 { 404 {
405 if (m_vOldiid[dwFilenr].impdesc.OriginalFirstThunk) 405 if (m_vOldiid[dwFilenr].impdesc.OriginalFirstThunk)
406 { 406 {
407 m_vOldiid[dwFilenr].originalfirstthunk[dwFuncnr].hint = value; 407 m_vOldiid[dwFilenr].originalfirstthunk[dwFuncnr].hint = value;
408 } 408 }
409 else 409 else
410 { 410 {
411 m_vOldiid[dwFilenr].firstthunk[dwFuncnr].hint = value; 411 m_vOldiid[dwFilenr].firstthunk[dwFuncnr].hint = value;
412 } 412 }
413 } 413 }
414 else m_vNewiid[dwFilenr].originalfirstthunk[dwFuncnr].hint = value; 414 else m_vNewiid[dwFilenr].originalfirstthunk[dwFuncnr].hint = value;
415 } 415 }
416 416
417 /** 417 /**
418 * Get the number of files which are currently being imported. 418 * Get the number of files which are currently being imported.
419 * @param cdDir Flag to decide if the OLDDIR or new import directory is used. 419 * @param cdDir Flag to decide if the OLDDIR or new import directory is used.
420 * @return Number of files which are currently being imported. 420 * @return Number of files which are currently being imported.
421 **/ 421 **/
422 template<int bits> 422 template<int bits>
423 dword ImportDirectory<bits>::getNumberOfFiles(currdir cdDir) const 423 dword ImportDirectory<bits>::getNumberOfFiles(currdir cdDir) const
424 { 424 {
425 if (cdDir == OLDDIR) return static_cast<dword>(m_vOldiid.size()); 425 if (cdDir == OLDDIR) return static_cast<dword>(m_vOldiid.size());
426 else return static_cast<dword>(m_vNewiid.size()); 426 else return static_cast<dword>(m_vNewiid.size());
427 } 427 }
428 428
429 /** 429 /**
430 * Get the number of functions which are currently being imported from a specific file. 430 * Get the number of functions which are currently being imported from a specific file.
431 * @param dwFilenr Identifies which file should be checked. 431 * @param dwFilenr Identifies which file should be checked.
432 * @param cdDir Flag to decide if the OLDDIR or new import directory is used. 432 * @param cdDir Flag to decide if the OLDDIR or new import directory is used.
433 * @return Number of functions which are currently being imported from a specific file. 433 * @return Number of functions which are currently being imported from a specific file.
434 **/ 434 **/
435 template<int bits> 435 template<int bits>
436 dword ImportDirectory<bits>::getNumberOfFunctions(dword dwFilenr, currdir cdDir) const 436 dword ImportDirectory<bits>::getNumberOfFunctions(dword dwFilenr, currdir cdDir) const
437 { 437 {
438 if (cdDir == OLDDIR) return static_cast<unsigned int>(m_vOldiid[dwFilenr].firstthunk.size()); 438 if (cdDir == OLDDIR) return static_cast<unsigned int>(m_vOldiid[dwFilenr].firstthunk.size());
439 else return static_cast<unsigned int>(m_vNewiid[dwFilenr].firstthunk.size()); 439 else return static_cast<unsigned int>(m_vNewiid[dwFilenr].firstthunk.size());
440 } 440 }
441 441
442 /** 442 /**
443 * Read an import directory from a file. 443 * Read an import directory from a file.
444 * \todo Check if streams failed. 444 * \todo Check if streams failed.
445 * @param strFilename Name of the file which will be read. 445 * @param strFilename Name of the file which will be read.
446 * @param uiOffset Offset of the import directory (see #PeLib::PeHeader::getIDImportRVA). 446 * @param uiOffset Offset of the import directory (see #PeLib::PeHeader::getIDImportRVA).
447 * @param uiSize Size of the import directory (see #PeLib::PeHeader::getIDImportSize). 447 * @param uiSize Size of the import directory (see #PeLib::PeHeader::getIDImportSize).
448 * @param pehHeader A valid PE header. 448 * @param pehHeader A valid PE header.
449 **/ 449 **/
450 template<int bits> 450 template<int bits>
451 int ImportDirectory<bits>::read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize, const PeHeaderT<bits>& pehHeader) 451 int ImportDirectory<bits>::read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize, const PeHeaderT<bits>& pehHeader)
452 { 452 {
453 std::ifstream ifFile(strFilename.c_str(), std::ios_base::binary); 453 std::ifstream ifFile(strFilename.c_str(), std::ios_base::binary);
454 454
455 if (!ifFile) 455 if (!ifFile)
456 { 456 {
457 return ERROR_OPENING_FILE; 457 return ERROR_OPENING_FILE;
458 } 458 }
459 459
460 unsigned int uiFileSize = fileSize(ifFile); 460 unsigned int uiFileSize = fileSize(ifFile);
461 461
462 if (uiFileSize < uiOffset + uiSize) 462 if (uiFileSize < uiOffset + uiSize)
463 { 463 {
464 return ERROR_INVALID_FILE; 464 return ERROR_INVALID_FILE;
465 } 465 }
466 466
467 ifFile.seekg(uiOffset, std::ios_base::beg); 467 ifFile.seekg(uiOffset, std::ios_base::beg);
468 468
469 std::vector<unsigned char> vImportdirectory(uiSize); 469 std::vector<unsigned char> vImportdirectory(uiSize);
470 ifFile.read(reinterpret_cast<char*>(&vImportdirectory[0]), uiSize); 470 ifFile.read(reinterpret_cast<char*>(&vImportdirectory[0]), uiSize);
471 471
472 PELIB_IMAGE_IMPORT_DIRECTORY<bits> iidCurr; 472 PELIB_IMAGE_IMPORT_DIRECTORY<bits> iidCurr;
473 unsigned int uiDesccounter = 0; 473 unsigned int uiDesccounter = 0;
474 474
475 InputBuffer inpBuffer(vImportdirectory); 475 InputBuffer inpBuffer(vImportdirectory);
476 476
477 std::vector<PELIB_IMAGE_IMPORT_DIRECTORY<bits> > vOldIidCurr; 477 std::vector<PELIB_IMAGE_IMPORT_DIRECTORY<bits> > vOldIidCurr;
478 478
479 do // Read and store all descriptors 479 do // Read and store all descriptors
480 { 480 {
481 inpBuffer >> iidCurr.impdesc.OriginalFirstThunk; 481 inpBuffer >> iidCurr.impdesc.OriginalFirstThunk;
482 inpBuffer >> iidCurr.impdesc.TimeDateStamp; 482 inpBuffer >> iidCurr.impdesc.TimeDateStamp;
483 inpBuffer >> iidCurr.impdesc.ForwarderChain; 483 inpBuffer >> iidCurr.impdesc.ForwarderChain;
484 inpBuffer >> iidCurr.impdesc.Name; 484 inpBuffer >> iidCurr.impdesc.Name;
485 inpBuffer >> iidCurr.impdesc.FirstThunk; 485 inpBuffer >> iidCurr.impdesc.FirstThunk;
486 486
487 if (iidCurr.impdesc.OriginalFirstThunk != 0 || iidCurr.impdesc.TimeDateStamp != 0 || iidCurr.impdesc.ForwarderChain != 0 || 487 if (iidCurr.impdesc.OriginalFirstThunk != 0 || iidCurr.impdesc.TimeDateStamp != 0 || iidCurr.impdesc.ForwarderChain != 0 ||
488 iidCurr.impdesc.Name != 0 || iidCurr.impdesc.FirstThunk != 0) 488 iidCurr.impdesc.Name != 0 || iidCurr.impdesc.FirstThunk != 0)
489 { 489 {
490 vOldIidCurr.push_back(iidCurr); 490 vOldIidCurr.push_back(iidCurr);
491 } 491 }
492 492
493 uiDesccounter++; 493 uiDesccounter++;
494 494
495 if (uiSize < (uiDesccounter + 1) * PELIB_IMAGE_IMPORT_DESCRIPTOR::size()) break; 495 if (uiSize < (uiDesccounter + 1) * PELIB_IMAGE_IMPORT_DESCRIPTOR::size()) break;
496 } while (iidCurr.impdesc.OriginalFirstThunk != 0 || iidCurr.impdesc.TimeDateStamp != 0 || iidCurr.impdesc.ForwarderChain != 0 || 496 } while (iidCurr.impdesc.OriginalFirstThunk != 0 || iidCurr.impdesc.TimeDateStamp != 0 || iidCurr.impdesc.ForwarderChain != 0 ||
497 iidCurr.impdesc.Name != 0 || iidCurr.impdesc.FirstThunk != 0); 497 iidCurr.impdesc.Name != 0 || iidCurr.impdesc.FirstThunk != 0);
498 498
499 char namebuffer[2] = {0}; 499 char namebuffer[2] = {0};
500 500
501 // Name 501 // Name
502 for (unsigned int i=0;i<vOldIidCurr.size();i++) 502 for (unsigned int i=0;i<vOldIidCurr.size();i++)
503 { 503 {
504 ifFile.seekg(static_cast<unsigned int>(pehHeader.rvaToOffset(vOldIidCurr[i].impdesc.Name)), std::ios_base::beg); 504 ifFile.seekg(static_cast<unsigned int>(pehHeader.rvaToOffset(vOldIidCurr[i].impdesc.Name)), std::ios_base::beg);
505 505
506 std::string dllname = ""; 506 std::string dllname = "";
507 507
508 do 508 do
509 { 509 {
510 ifFile.read(namebuffer, 1); 510 ifFile.read(namebuffer, 1);
511 if (!ifFile || !namebuffer[0]) break; // reached end of file or 0-byte 511 if (!ifFile || !namebuffer[0]) break; // reached end of file or 0-byte
512 dllname += namebuffer; 512 dllname += namebuffer;
513 } while (true); 513 } while (true);
514 514
515 vOldIidCurr[i].name = dllname; 515 vOldIidCurr[i].name = dllname;
516 516
517 } 517 }
518 518
519 // OriginalFirstThunk 519 // OriginalFirstThunk
520 for (unsigned int i=0;i<vOldIidCurr.size();i++) 520 for (unsigned int i=0;i<vOldIidCurr.size();i++)
521 { 521 {
522 PELIB_THUNK_DATA<bits> tdCurr; 522 PELIB_THUNK_DATA<bits> tdCurr;
523 dword uiVaoft = vOldIidCurr[i].impdesc.OriginalFirstThunk; 523 dword uiVaoft = vOldIidCurr[i].impdesc.OriginalFirstThunk;
524 524
525 if (!uiVaoft) 525 if (!uiVaoft)
526 { 526 {
527 continue; 527 continue;
528 } 528 }
529 529
530 ifFile.seekg(static_cast<unsigned int>(pehHeader.rvaToOffset(uiVaoft)), std::ios_base::beg); 530 ifFile.seekg(static_cast<unsigned int>(pehHeader.rvaToOffset(uiVaoft)), std::ios_base::beg);
531 531
532 do 532 do
533 { 533 {
534 if (uiFileSize < pehHeader.rvaToOffset(uiVaoft) + sizeof(tdCurr.itd.Ordinal)) 534 if (uiFileSize < pehHeader.rvaToOffset(uiVaoft) + sizeof(tdCurr.itd.Ordinal))
535 { 535 {
536 return ERROR_INVALID_FILE; 536 return ERROR_INVALID_FILE;
537 } 537 }
538 uiVaoft += sizeof(tdCurr.itd.Ordinal); 538 uiVaoft += sizeof(tdCurr.itd.Ordinal);
539 539
540 ifFile.read(reinterpret_cast<char*>(&tdCurr.itd.Ordinal), sizeof(tdCurr.itd.Ordinal)); 540 ifFile.read(reinterpret_cast<char*>(&tdCurr.itd.Ordinal), sizeof(tdCurr.itd.Ordinal));
541 if (tdCurr.itd.Ordinal) vOldIidCurr[i].originalfirstthunk.push_back(tdCurr); 541 if (tdCurr.itd.Ordinal) vOldIidCurr[i].originalfirstthunk.push_back(tdCurr);
542 } while (tdCurr.itd.Ordinal); 542 } while (tdCurr.itd.Ordinal);
543 } 543 }
544 544
545 // FirstThunk 545 // FirstThunk
546 for (unsigned int i=0;i<vOldIidCurr.size();i++) 546 for (unsigned int i=0;i<vOldIidCurr.size();i++)
547 { 547 {
548 dword uiVaoft = vOldIidCurr[i].impdesc.FirstThunk; 548 dword uiVaoft = vOldIidCurr[i].impdesc.FirstThunk;
549 PELIB_THUNK_DATA<bits> tdCurr; 549 PELIB_THUNK_DATA<bits> tdCurr;
550 550
551 ifFile.seekg(static_cast<unsigned int>(pehHeader.rvaToOffset(uiVaoft)), std::ios_base::beg); 551 ifFile.seekg(static_cast<unsigned int>(pehHeader.rvaToOffset(uiVaoft)), std::ios_base::beg);
552 552
553 do 553 do
554 { 554 {
555 if (uiFileSize < pehHeader.rvaToOffset(uiVaoft) + sizeof(tdCurr.itd.Ordinal)) 555 if (uiFileSize < pehHeader.rvaToOffset(uiVaoft) + sizeof(tdCurr.itd.Ordinal))
556 { 556 {
557 return ERROR_INVALID_FILE; 557 return ERROR_INVALID_FILE;
558 } 558 }
559 559
560 uiVaoft += sizeof(tdCurr.itd.Ordinal); 560 uiVaoft += sizeof(tdCurr.itd.Ordinal);
561 561
562 ifFile.read(reinterpret_cast<char*>(&tdCurr.itd.Ordinal), sizeof(tdCurr.itd.Ordinal)); 562 ifFile.read(reinterpret_cast<char*>(&tdCurr.itd.Ordinal), sizeof(tdCurr.itd.Ordinal));
563 if (tdCurr.itd.Ordinal) vOldIidCurr[i].firstthunk.push_back(tdCurr); 563 if (tdCurr.itd.Ordinal) vOldIidCurr[i].firstthunk.push_back(tdCurr);
564 } while (tdCurr.itd.Ordinal); 564 } while (tdCurr.itd.Ordinal);
565 } 565 }
566 566
567 // Names 567 // Names
568 for (unsigned int i=0;i<vOldIidCurr.size();i++) 568 for (unsigned int i=0;i<vOldIidCurr.size();i++)
569 { 569 {
570 if (vOldIidCurr[i].impdesc.OriginalFirstThunk) 570 if (vOldIidCurr[i].impdesc.OriginalFirstThunk)
571 { 571 {
572 for (unsigned int j=0;j<vOldIidCurr[i].originalfirstthunk.size();j++) 572 for (unsigned int j=0;j<vOldIidCurr[i].originalfirstthunk.size();j++)
573 { 573 {
574 if (vOldIidCurr[i].originalfirstthunk[j].itd.Ordinal & PELIB_IMAGE_ORDINAL_FLAGS<bits>::IMAGE_ORDINAL_FLAG) 574 if (vOldIidCurr[i].originalfirstthunk[j].itd.Ordinal & PELIB_IMAGE_ORDINAL_FLAGS<bits>::IMAGE_ORDINAL_FLAG)
575 { 575 {
576 vOldIidCurr[i].originalfirstthunk[j].hint = 0; 576 vOldIidCurr[i].originalfirstthunk[j].hint = 0;
577 continue; 577 continue;
578 } 578 }
579 579
580 ifFile.seekg(static_cast<unsigned int>(pehHeader.rvaToOffset(vOldIidCurr[i].originalfirstthunk[j].itd.Ordinal)), std::ios_base::beg); 580 ifFile.seekg(static_cast<unsigned int>(pehHeader.rvaToOffset(vOldIidCurr[i].originalfirstthunk[j].itd.Ordinal)), std::ios_base::beg);
581 581
582 ifFile.read(reinterpret_cast<char*>(&vOldIidCurr[i].originalfirstthunk[j].hint), sizeof(vOldIidCurr[i].originalfirstthunk[j].hint)); 582 ifFile.read(reinterpret_cast<char*>(&vOldIidCurr[i].originalfirstthunk[j].hint), sizeof(vOldIidCurr[i].originalfirstthunk[j].hint));
583 583
584 if (!ifFile) 584 if (!ifFile)
585 return ERROR_INVALID_FILE; 585 return ERROR_INVALID_FILE;
586 586
587 std::string funcname = ""; 587 std::string funcname = "";
588 do 588 do
589 { 589 {
590 ifFile.read(namebuffer, 1); 590 ifFile.read(namebuffer, 1);
591 if (!ifFile || !namebuffer[0]) break; // reached end of file or 0-byte 591 if (!ifFile || !namebuffer[0]) break; // reached end of file or 0-byte
592 funcname += namebuffer; 592 funcname += namebuffer;
593 } while (true); 593 } while (true);
594 594
595 vOldIidCurr[i].originalfirstthunk[j].fname = funcname; 595 vOldIidCurr[i].originalfirstthunk[j].fname = funcname;
596 } 596 }
597 } 597 }
598 else 598 else
599 { 599 {
600 for (unsigned int j=0;j<vOldIidCurr[i].firstthunk.size();j++) 600 for (unsigned int j=0;j<vOldIidCurr[i].firstthunk.size();j++)
601 { 601 {
602 if (vOldIidCurr[i].firstthunk[j].itd.Ordinal & PELIB_IMAGE_ORDINAL_FLAGS<bits>::IMAGE_ORDINAL_FLAG) 602 if (vOldIidCurr[i].firstthunk[j].itd.Ordinal & PELIB_IMAGE_ORDINAL_FLAGS<bits>::IMAGE_ORDINAL_FLAG)
603 { 603 {
604 continue; 604 continue;
605 } 605 }
606 606
607 ifFile.seekg(static_cast<unsigned int>(pehHeader.rvaToOffset(vOldIidCurr[i].firstthunk[j].itd.Ordinal)), std::ios_base::beg); 607 ifFile.seekg(static_cast<unsigned int>(pehHeader.rvaToOffset(vOldIidCurr[i].firstthunk[j].itd.Ordinal)), std::ios_base::beg);
608 608
609 ifFile.read(reinterpret_cast<char*>(&vOldIidCurr[i].firstthunk[j].hint), sizeof(vOldIidCurr[i].firstthunk[j].hint)); 609 ifFile.read(reinterpret_cast<char*>(&vOldIidCurr[i].firstthunk[j].hint), sizeof(vOldIidCurr[i].firstthunk[j].hint));
610 610
611 if (!ifFile) 611 if (!ifFile)
612 return ERROR_INVALID_FILE; 612 return ERROR_INVALID_FILE;
613 613
614 std::string funcname = ""; 614 std::string funcname = "";
615 do 615 do
616 { 616 {
617 ifFile.read(namebuffer, 1); 617 ifFile.read(namebuffer, 1);
618 if (!ifFile || !namebuffer[0]) break; // reached end of file or 0-byte 618 if (!ifFile || !namebuffer[0]) break; // reached end of file or 0-byte
619 funcname += namebuffer; 619 funcname += namebuffer;
620 } while (true); 620 } while (true);
621 621
622 vOldIidCurr[i].firstthunk[j].fname = funcname; 622 vOldIidCurr[i].firstthunk[j].fname = funcname;
623 } 623 }
624 } 624 }
625 } 625 }
626 std::swap(vOldIidCurr, m_vOldiid); 626 std::swap(vOldIidCurr, m_vOldiid);
627 return NO_ERROR; 627 return NO_ERROR;
628 } 628 }
629 629
630 /** 630 /**
631 * Rebuilds the import directory. 631 * Rebuilds the import directory.
632 * @param vBuffer Buffer the rebuilt import directory will be written to. 632 * @param vBuffer Buffer the rebuilt import directory will be written to.
633 * @param dwRva The RVA of the ImportDirectory in the file. 633 * @param dwRva The RVA of the ImportDirectory in the file.
634 * \todo uiSizeoffuncnames is not used. 634 * \todo uiSizeoffuncnames is not used.
635 **/ 635 **/
636 template<int bits> 636 template<int bits>
637 void ImportDirectory<bits>::rebuild(std::vector<byte>& vBuffer, dword dwRva, bool fixEntries) const 637 void ImportDirectory<bits>::rebuild(std::vector<byte>& vBuffer, dword dwRva, bool fixEntries) const
638 { 638 {
639 unsigned int uiImprva = dwRva; 639 unsigned int uiImprva = dwRva;
640 unsigned int uiSizeofdescriptors = (static_cast<unsigned int>(m_vNewiid.size() + m_vOldiid.size()) + 1) * PELIB_IMAGE_IMPORT_DESCRIPTOR::size(); 640 unsigned int uiSizeofdescriptors = (static_cast<unsigned int>(m_vNewiid.size() + m_vOldiid.size()) + 1) * PELIB_IMAGE_IMPORT_DESCRIPTOR::size();
641 641
642 unsigned int uiSizeofdllnames = 0, uiSizeoffuncnames = 0; 642 unsigned int uiSizeofdllnames = 0, uiSizeoffuncnames = 0;
643 unsigned int uiSizeofoft = 0; 643 unsigned int uiSizeofoft = 0;
644 644
645 for (unsigned int i=0;i<m_vNewiid.size();i++) 645 for (unsigned int i=0;i<m_vNewiid.size();i++)
646 { 646 {
647 uiSizeofdllnames += static_cast<unsigned int>(m_vNewiid[i].name.size()) + 1; 647 uiSizeofdllnames += static_cast<unsigned int>(m_vNewiid[i].name.size()) + 1;
648 uiSizeofoft += (static_cast<unsigned int>(m_vNewiid[i].originalfirstthunk.size())+1) * PELIB_IMAGE_THUNK_DATA<bits>::size(); 648 uiSizeofoft += (static_cast<unsigned int>(m_vNewiid[i].originalfirstthunk.size())+1) * PELIB_IMAGE_THUNK_DATA<bits>::size();
649 649
650 for(unsigned int j=0;j<m_vNewiid[i].originalfirstthunk.size();j++) 650 for(unsigned int j=0;j<m_vNewiid[i].originalfirstthunk.size();j++)
651 { 651 {
652 // +3 for hint (word) and 00-byte 652 // +3 for hint (word) and 00-byte
653 uiSizeoffuncnames += (static_cast<unsigned int>(m_vNewiid[i].originalfirstthunk[j].fname.size()) + 3); 653 uiSizeoffuncnames += (static_cast<unsigned int>(m_vNewiid[i].originalfirstthunk[j].fname.size()) + 3);
654 } 654 }
655 } 655 }
656 656
657// for (unsigned int i=0;i<m_vNewiid.size();i++) 657// for (unsigned int i=0;i<m_vNewiid.size();i++)
658// { 658// {
659// uiSizeofoft += (static_cast<unsigned int>(m_vNewiid[i].originalfirstthunk.size())+1) * PELIB_IMAGE_THUNK_DATA<bits>::size(); 659// uiSizeofoft += (static_cast<unsigned int>(m_vNewiid[i].originalfirstthunk.size())+1) * PELIB_IMAGE_THUNK_DATA<bits>::size();
660// } 660// }
661 661
662 OutputBuffer obBuffer(vBuffer); 662 OutputBuffer obBuffer(vBuffer);
663 663
664 // Rebuild IMAGE_IMPORT_DESCRIPTORS 664 // Rebuild IMAGE_IMPORT_DESCRIPTORS
665 for (unsigned int i=0;i<m_vOldiid.size();i++) 665 for (unsigned int i=0;i<m_vOldiid.size();i++)
666 { 666 {
667 obBuffer << m_vOldiid[i].impdesc.OriginalFirstThunk; 667 obBuffer << m_vOldiid[i].impdesc.OriginalFirstThunk;
668 obBuffer << m_vOldiid[i].impdesc.TimeDateStamp; 668 obBuffer << m_vOldiid[i].impdesc.TimeDateStamp;
669 obBuffer << m_vOldiid[i].impdesc.ForwarderChain; 669 obBuffer << m_vOldiid[i].impdesc.ForwarderChain;
670 obBuffer << m_vOldiid[i].impdesc.Name; 670 obBuffer << m_vOldiid[i].impdesc.Name;
671 obBuffer << m_vOldiid[i].impdesc.FirstThunk; 671 obBuffer << m_vOldiid[i].impdesc.FirstThunk;
672 } 672 }
673 673
674 unsigned int dllsize = 0; 674 unsigned int dllsize = 0;
675 675
676 for (unsigned int i=0;i<m_vNewiid.size();i++) 676 for (unsigned int i=0;i<m_vNewiid.size();i++)
677 { 677 {
678 dword dwPoft = uiSizeofdescriptors + uiImprva; 678 dword dwPoft = uiSizeofdescriptors + uiImprva;
679 679
680 for (unsigned int j=1;j<=i;j++) 680 for (unsigned int j=1;j<=i;j++)
681 { 681 {
682 dwPoft += (static_cast<unsigned int>(m_vNewiid[j-1].originalfirstthunk.size()) + 1) * PELIB_IMAGE_THUNK_DATA<bits>::size(); 682 dwPoft += (static_cast<unsigned int>(m_vNewiid[j-1].originalfirstthunk.size()) + 1) * PELIB_IMAGE_THUNK_DATA<bits>::size();
683 } 683 }
684 684
685 obBuffer << (fixEntries ? dwPoft : m_vNewiid[i].impdesc.OriginalFirstThunk); 685 obBuffer << (fixEntries ? dwPoft : m_vNewiid[i].impdesc.OriginalFirstThunk);
686 obBuffer << m_vNewiid[i].impdesc.TimeDateStamp; 686 obBuffer << m_vNewiid[i].impdesc.TimeDateStamp;
687 obBuffer << m_vNewiid[i].impdesc.ForwarderChain; 687 obBuffer << m_vNewiid[i].impdesc.ForwarderChain;
688 dword dwPdll = uiSizeofdescriptors + uiSizeofoft + uiImprva + dllsize; 688 dword dwPdll = uiSizeofdescriptors + uiSizeofoft + uiImprva + dllsize;
689 obBuffer << (fixEntries ? dwPdll : m_vNewiid[i].impdesc.Name); 689 obBuffer << (fixEntries ? dwPdll : m_vNewiid[i].impdesc.Name);
690 obBuffer << (fixEntries ? dwPoft : m_vNewiid[i].impdesc.FirstThunk); 690 obBuffer << (fixEntries ? dwPoft : m_vNewiid[i].impdesc.FirstThunk);
691 691
692 dllsize += static_cast<unsigned int>(m_vNewiid[i].name.size()) + 1; 692 dllsize += static_cast<unsigned int>(m_vNewiid[i].name.size()) + 1;
693 } 693 }
694 694
695 obBuffer << (dword)0; 695 obBuffer << (dword)0;
696 obBuffer << (dword)0; 696 obBuffer << (dword)0;
697 obBuffer << (dword)0; 697 obBuffer << (dword)0;
698 obBuffer << (dword)0; 698 obBuffer << (dword)0;
699 obBuffer << (dword)0; 699 obBuffer << (dword)0;
700 700
701 unsigned int uiPfunc = uiSizeofdescriptors + uiSizeofoft + uiSizeofdllnames + uiImprva; 701 unsigned int uiPfunc = uiSizeofdescriptors + uiSizeofoft + uiSizeofdllnames + uiImprva;
702 702
703 // Rebuild original first thunk 703 // Rebuild original first thunk
704 for (unsigned int i=0;i<m_vNewiid.size();i++) 704 for (unsigned int i=0;i<m_vNewiid.size();i++)
705 { 705 {
706 for (unsigned int j=0;j<m_vNewiid[i].originalfirstthunk.size();j++) 706 for (unsigned int j=0;j<m_vNewiid[i].originalfirstthunk.size();j++)
707 { 707 {
708 if (m_vNewiid[i].originalfirstthunk[j].itd.Ordinal & PELIB_IMAGE_ORDINAL_FLAGS<bits>::IMAGE_ORDINAL_FLAG 708 if (m_vNewiid[i].originalfirstthunk[j].itd.Ordinal & PELIB_IMAGE_ORDINAL_FLAGS<bits>::IMAGE_ORDINAL_FLAG
709 || fixEntries == false) 709 || fixEntries == false)
710 { 710 {
711 obBuffer << m_vNewiid[i].originalfirstthunk[j].itd.Ordinal; 711 obBuffer << m_vNewiid[i].originalfirstthunk[j].itd.Ordinal;
712 } 712 }
713 else 713 else
714 { 714 {
715 obBuffer << uiPfunc; 715 obBuffer << uiPfunc;
716 } 716 }
717 uiPfunc += static_cast<unsigned int>(m_vNewiid[i].originalfirstthunk[j].fname.size()) + 3; 717 uiPfunc += static_cast<unsigned int>(m_vNewiid[i].originalfirstthunk[j].fname.size()) + 3;
718 } 718 }
719 obBuffer << (dword)0; 719 obBuffer << (dword)0;
720 } 720 }
721 721
722 // Write dllnames into import directory 722 // Write dllnames into import directory
723 for (unsigned int i=0;i<m_vNewiid.size();i++) 723 for (unsigned int i=0;i<m_vNewiid.size();i++)
724 { 724 {
725 obBuffer.add(m_vNewiid[i].name.c_str(), static_cast<unsigned int>(m_vNewiid[i].name.size())+1); 725 obBuffer.add(m_vNewiid[i].name.c_str(), static_cast<unsigned int>(m_vNewiid[i].name.size())+1);
726 } 726 }
727 727
728 // Write function names into directory 728 // Write function names into directory
729 for (unsigned int i=0;i<m_vNewiid.size();i++) 729 for (unsigned int i=0;i<m_vNewiid.size();i++)
730 { 730 {
731 for (unsigned int j=0;j<m_vNewiid[i].originalfirstthunk.size();j++) 731 for (unsigned int j=0;j<m_vNewiid[i].originalfirstthunk.size();j++)
732 { 732 {
733 obBuffer << m_vNewiid[i].originalfirstthunk[j].hint; 733 obBuffer << m_vNewiid[i].originalfirstthunk[j].hint;
734 obBuffer.add(m_vNewiid[i].originalfirstthunk[j].fname.c_str(), static_cast<unsigned int>(m_vNewiid[i].originalfirstthunk[j].fname.size()) + 1); 734 obBuffer.add(m_vNewiid[i].originalfirstthunk[j].fname.c_str(), static_cast<unsigned int>(m_vNewiid[i].originalfirstthunk[j].fname.size()) + 1);
735 } 735 }
736 } 736 }
737 } 737 }
738 738
739 /** 739 /**
740 * Removes a specific file and all functions of it from the import directory. 740 * Removes a specific file and all functions of it from the import directory.
741 * @param strFilename Name of the file which will be removed. 741 * @param strFilename Name of the file which will be removed.
742 **/ 742 **/
743 template<int bits> 743 template<int bits>
744 int ImportDirectory<bits>::removeFile(const std::string& strFilename) 744 int ImportDirectory<bits>::removeFile(const std::string& strFilename)
745 { 745 {
746 unsigned int oldSize = static_cast<unsigned int>(m_vNewiid.size()); 746 unsigned int oldSize = static_cast<unsigned int>(m_vNewiid.size());
747 747
748 m_vNewiid.erase(std::remove_if(m_vNewiid.begin(), m_vNewiid.end(), std::bind2nd(std::mem_fun_ref(&PELIB_IMAGE_IMPORT_DIRECTORY<bits>::operator==), strFilename)), m_vNewiid.end()); 748 m_vNewiid.erase(std::remove_if(m_vNewiid.begin(), m_vNewiid.end(), std::bind2nd(std::mem_fun_ref(&PELIB_IMAGE_IMPORT_DIRECTORY<bits>::operator==), strFilename)), m_vNewiid.end());
749 749
750 return oldSize == m_vNewiid.size() ? 1 : 0; 750 return oldSize == m_vNewiid.size() ? 1 : 0;
751 } 751 }
752 752
753 /** 753 /**
754 * Removes a specific function from the import directory. 754 * Removes a specific function from the import directory.
755 * @param strFilename Name of the file which exports the function. 755 * @param strFilename Name of the file which exports the function.
756 * @param strFuncname Name of the imported function. 756 * @param strFuncname Name of the imported function.
757 **/ 757 **/
758 template<int bits> 758 template<int bits>
759 int ImportDirectory<bits>::removeFunction(const std::string& strFilename, const std::string& strFuncname) 759 int ImportDirectory<bits>::removeFunction(const std::string& strFilename, const std::string& strFuncname)
760 { 760 {
761 ImpDirFileIterator viPos = m_vNewiid.begin(); 761 ImpDirFileIterator viPos = m_vNewiid.begin();
762 762
763 int notFound = 1; 763 int notFound = 1;
764 764
765 while (viPos != m_vNewiid.end()) 765 while (viPos != m_vNewiid.end())
766 { 766 {
767 if (isEqualNc(viPos->name, strFilename)) 767 if (isEqualNc(viPos->name, strFilename))
768 { 768 {
769 unsigned int oldSize = static_cast<unsigned int>(viPos->originalfirstthunk.size()); 769 unsigned int oldSize = static_cast<unsigned int>(viPos->originalfirstthunk.size());
770 viPos->originalfirstthunk.erase(std::remove_if(viPos->originalfirstthunk.begin(), viPos->originalfirstthunk.end(), std::bind2nd(std::mem_fun_ref(&PELIB_THUNK_DATA<bits>::equalFunctionName), strFuncname)), viPos->originalfirstthunk.end()); 770 viPos->originalfirstthunk.erase(std::remove_if(viPos->originalfirstthunk.begin(), viPos->originalfirstthunk.end(), std::bind2nd(std::mem_fun_ref(&PELIB_THUNK_DATA<bits>::equalFunctionName), strFuncname)), viPos->originalfirstthunk.end());
771 //viPos->originalfirstthunk.erase(std::remove_if(viPos->originalfirstthunk.begin(), viPos->originalfirstthunk.end(), std::bind2nd(CompPolicy<PELIB_THUNK_DATA, std::string>(), strFuncname))); 771 //viPos->originalfirstthunk.erase(std::remove_if(viPos->originalfirstthunk.begin(), viPos->originalfirstthunk.end(), std::bind2nd(CompPolicy<PELIB_THUNK_DATA, std::string>(), strFuncname)));
772 if (viPos->originalfirstthunk.size() != oldSize) notFound = 0; 772 if (viPos->originalfirstthunk.size() != oldSize) notFound = 0;
773 } 773 }
774 ++viPos; 774 ++viPos;
775 } 775 }
776 776
777 return notFound; 777 return notFound;
778 } 778 }
779 779
780 /** 780 /**
781 * Removes a specific function from the import directory. 781 * Removes a specific function from the import directory.
782 * @param strFilename Name of the file which exports the function. 782 * @param strFilename Name of the file which exports the function.
783 * @param wHint The hint of the function. 783 * @param wHint The hint of the function.
784 **/ 784 **/
785 template<int bits> 785 template<int bits>
786 int ImportDirectory<bits>::removeFunction(const std::string& strFilename, word wHint) 786 int ImportDirectory<bits>::removeFunction(const std::string& strFilename, word wHint)
787 { 787 {
788 ImpDirFileIterator viPos = m_vNewiid.begin(); 788 ImpDirFileIterator viPos = m_vNewiid.begin();
789 int notFound = 1; 789 int notFound = 1;
790 790
791 while (viPos != m_vNewiid.end()) 791 while (viPos != m_vNewiid.end())
792 { 792 {
793 if (isEqualNc(viPos->name, strFilename)) 793 if (isEqualNc(viPos->name, strFilename))
794 { 794 {
795 unsigned int oldSize = static_cast<unsigned int>(viPos->originalfirstthunk.size()); 795 unsigned int oldSize = static_cast<unsigned int>(viPos->originalfirstthunk.size());
796 viPos->originalfirstthunk.erase(std::remove_if(viPos->originalfirstthunk.begin(), viPos->originalfirstthunk.end(), std::bind2nd(std::mem_fun_ref(&PELIB_THUNK_DATA<bits>::equalHint), wHint)), viPos->originalfirstthunk.end()); 796 viPos->originalfirstthunk.erase(std::remove_if(viPos->originalfirstthunk.begin(), viPos->originalfirstthunk.end(), std::bind2nd(std::mem_fun_ref(&PELIB_THUNK_DATA<bits>::equalHint), wHint)), viPos->originalfirstthunk.end());
797 unsigned int newPos = static_cast<unsigned int>(viPos->originalfirstthunk.size()); 797 unsigned int newPos = static_cast<unsigned int>(viPos->originalfirstthunk.size());
798 if (viPos->originalfirstthunk.size() != oldSize) notFound = 0; 798 if (viPos->originalfirstthunk.size() != oldSize) notFound = 0;
799 } 799 }
800 ++viPos; 800 ++viPos;
801 } 801 }
802 802
803 return notFound; 803 return notFound;
804 } 804 }
805 805
806 /** 806 /**
807 * Writes the current import directory to a file. 807 * Writes the current import directory to a file.
808 * @param strFilename Name of the file. 808 * @param strFilename Name of the file.
809 * @param uiOffset File Offset of the new import directory. 809 * @param uiOffset File Offset of the new import directory.
810 * @param uiRva RVA which belongs to that file offset. 810 * @param uiRva RVA which belongs to that file offset.
811 **/ 811 **/
812 template<int bits> 812 template<int bits>
813 int ImportDirectory<bits>::write(const std::string& strFilename, unsigned int uiOffset, unsigned int uiRva) 813 int ImportDirectory<bits>::write(const std::string& strFilename, unsigned int uiOffset, unsigned int uiRva)
814 { 814 {
815 std::fstream ofFile(strFilename.c_str(), std::ios_base::in); 815 std::fstream ofFile(strFilename.c_str(), std::ios_base::in);
816 816
817 if (!ofFile) 817 if (!ofFile)
818 { 818 {
819 ofFile.clear(); 819 ofFile.clear();
820 ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary); 820 ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary);
821 } 821 }
822 else 822 else
823 { 823 {
824 ofFile.close(); 824 ofFile.close();
825 ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary); 825 ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary);
826 } 826 }
827 827
828 if (!ofFile) 828 if (!ofFile)
829 { 829 {
830 return ERROR_OPENING_FILE; 830 return ERROR_OPENING_FILE;
831 } 831 }
832 832
833 ofFile.seekp(uiOffset, std::ios_base::beg); 833 ofFile.seekp(uiOffset, std::ios_base::beg);
834 834
835 std::vector<byte> vBuffer; 835 std::vector<byte> vBuffer;
836 836
837 rebuild(vBuffer, uiRva); 837 rebuild(vBuffer, uiRva);
838 838
839 ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), vBuffer.size()); 839 ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), vBuffer.size());
840 ofFile.close(); 840 ofFile.close();
841 841
842 std::copy(m_vNewiid.begin(), m_vNewiid.end(), std::back_inserter(m_vOldiid)); 842 std::copy(m_vNewiid.begin(), m_vNewiid.end(), std::back_inserter(m_vOldiid));
843 m_vNewiid.clear(); 843 m_vNewiid.clear();
844 844
845 return NO_ERROR; 845 return NO_ERROR;
846 } 846 }
847 847
848 /** 848 /**
849 * Returns the size of the import directory. 849 * Returns the size of the import directory.
850 * @return Size of the import directory. 850 * @return Size of the import directory.
851 **/ 851 **/
852 template<int bits> 852 template<int bits>
853 unsigned int ImportDirectory<bits>::size() const 853 unsigned int ImportDirectory<bits>::size() const
854 { 854 {
855 // Only the descriptors of m_vOldiid must be rebuilt, not the data they point to. 855 // Only the descriptors of m_vOldiid must be rebuilt, not the data they point to.
856 return std::accumulate(m_vNewiid.begin(), m_vNewiid.end(), 0, accumulate<PELIB_IMAGE_IMPORT_DIRECTORY<bits> >) 856 return std::accumulate(m_vNewiid.begin(), m_vNewiid.end(), 0, accumulate<PELIB_IMAGE_IMPORT_DIRECTORY<bits> >)
857 + (m_vOldiid.size() + 1) * PELIB_IMAGE_IMPORT_DESCRIPTOR::size(); 857 + (m_vOldiid.size() + 1) * PELIB_IMAGE_IMPORT_DESCRIPTOR::size();
858 } 858 }
859 859
860 /** 860 /**
861 * @param strFilename Name of the imported file. 861 * @param strFilename Name of the imported file.
862 * @param cdDir Flag to decide if the OLDDIR or new import directory is used. 862 * @param cdDir Flag to decide if the OLDDIR or new import directory is used.
863 * @return FirstThunk value of an imported file. 863 * @return FirstThunk value of an imported file.
864 **/ 864 **/
865 template<int bits> 865 template<int bits>
866 dword ImportDirectory<bits>::getFirstThunk(const std::string& strFilename, currdir cdDir) const 866 dword ImportDirectory<bits>::getFirstThunk(const std::string& strFilename, currdir cdDir) const
867 { 867 {
868 if (cdDir == OLDDIR) 868 if (cdDir == OLDDIR)
869 { 869 {
870 return m_vOldiid[getFileIndex(strFilename, cdDir)].impdesc.FirstThunk; 870 return m_vOldiid[getFileIndex(strFilename, cdDir)].impdesc.FirstThunk;
871 } 871 }
872 else 872 else
873 { 873 {
874 return m_vNewiid[getFileIndex(strFilename, cdDir)].impdesc.FirstThunk; 874 return m_vNewiid[getFileIndex(strFilename, cdDir)].impdesc.FirstThunk;
875 } 875 }
876 } 876 }
877 877
878 /** 878 /**
879 * @param strFilename Name of the imported file. 879 * @param strFilename Name of the imported file.
880 * @param cdDir Flag to decide if the OLDDIR or new import directory is used. 880 * @param cdDir Flag to decide if the OLDDIR or new import directory is used.
881 * @return OriginalFirstThunk value of an imported file. 881 * @return OriginalFirstThunk value of an imported file.
882 **/ 882 **/
883 template<int bits> 883 template<int bits>
884 dword ImportDirectory<bits>::getOriginalFirstThunk(const std::string& strFilename, currdir cdDir) const 884 dword ImportDirectory<bits>::getOriginalFirstThunk(const std::string& strFilename, currdir cdDir) const
885 { 885 {
886 if (cdDir == OLDDIR) 886 if (cdDir == OLDDIR)
887 { 887 {
888 return m_vOldiid[getFileIndex(strFilename, cdDir)].impdesc.OriginalFirstThunk; 888 return m_vOldiid[getFileIndex(strFilename, cdDir)].impdesc.OriginalFirstThunk;
889 } 889 }
890 else 890 else
891 { 891 {
892 return m_vNewiid[getFileIndex(strFilename, cdDir)].impdesc.OriginalFirstThunk; 892 return m_vNewiid[getFileIndex(strFilename, cdDir)].impdesc.OriginalFirstThunk;
893 } 893 }
894 } 894 }
895 895
896 /** 896 /**
897 * @param strFilename Name of the imported file. 897 * @param strFilename Name of the imported file.
898 * @param cdDir Flag to decide if the OLDDIR or new import directory is used. 898 * @param cdDir Flag to decide if the OLDDIR or new import directory is used.
899 * @return ForwarderChain value of an imported file. 899 * @return ForwarderChain value of an imported file.
900 **/ 900 **/
901 template<int bits> 901 template<int bits>
902 dword ImportDirectory<bits>::getForwarderChain(const std::string& strFilename, currdir cdDir) const 902 dword ImportDirectory<bits>::getForwarderChain(const std::string& strFilename, currdir cdDir) const
903 { 903 {
904 if (cdDir == OLDDIR) 904 if (cdDir == OLDDIR)
905 { 905 {
906 return m_vOldiid[getFileIndex(strFilename, cdDir)].impdesc.ForwarderChain; 906 return m_vOldiid[getFileIndex(strFilename, cdDir)].impdesc.ForwarderChain;
907 } 907 }
908 else 908 else
909 { 909 {
910 return m_vNewiid[getFileIndex(strFilename, cdDir)].impdesc.ForwarderChain; 910 return m_vNewiid[getFileIndex(strFilename, cdDir)].impdesc.ForwarderChain;
911 } 911 }
912 } 912 }
913 913
914 /** 914 /**
915 * @param strFilename Name of the imported file. 915 * @param strFilename Name of the imported file.
916 * @param cdDir Flag to decide if the OLDDIR or new import directory is used. 916 * @param cdDir Flag to decide if the OLDDIR or new import directory is used.
917 * @return TimeDateStamp value of an imported file. 917 * @return TimeDateStamp value of an imported file.
918 **/ 918 **/
919 template<int bits> 919 template<int bits>
920 dword ImportDirectory<bits>::getTimeDateStamp(const std::string& strFilename, currdir cdDir) const 920 dword ImportDirectory<bits>::getTimeDateStamp(const std::string& strFilename, currdir cdDir) const
921 { 921 {
922 if (cdDir == OLDDIR) 922 if (cdDir == OLDDIR)
923 { 923 {
924 return m_vOldiid[getFileIndex(strFilename, cdDir)].impdesc.TimeDateStamp; 924 return m_vOldiid[getFileIndex(strFilename, cdDir)].impdesc.TimeDateStamp;
925 } 925 }
926 else 926 else
927 { 927 {
928 return m_vNewiid[getFileIndex(strFilename, cdDir)].impdesc.TimeDateStamp; 928 return m_vNewiid[getFileIndex(strFilename, cdDir)].impdesc.TimeDateStamp;
929 } 929 }
930 } 930 }
931 931
932 template<int bits> 932 template<int bits>
933 dword ImportDirectory<bits>::getRvaOfName(const std::string& strFilename, currdir cdDir) const 933 dword ImportDirectory<bits>::getRvaOfName(const std::string& strFilename, currdir cdDir) const
934 { 934 {
935 if (cdDir == OLDDIR) 935 if (cdDir == OLDDIR)
936 { 936 {
937 return m_vOldiid[getFileIndex(strFilename, cdDir)].impdesc.Name; 937 return m_vOldiid[getFileIndex(strFilename, cdDir)].impdesc.Name;
938 } 938 }
939 else 939 else
940 { 940 {
941 return m_vNewiid[getFileIndex(strFilename, cdDir)].impdesc.Name; 941 return m_vNewiid[getFileIndex(strFilename, cdDir)].impdesc.Name;
942 } 942 }
943 } 943 }
944 944
945 /** 945 /**
946 * @param strFilename Name of the imported file. 946 * @param strFilename Name of the imported file.
947 * @param cdDir Flag to decide if the OLDDIR or new import directory is used. 947 * @param cdDir Flag to decide if the OLDDIR or new import directory is used.
948 * @return FirstThunk value of an imported file. 948 * @return FirstThunk value of an imported file.
949 **/ 949 **/
950 template<int bits> 950 template<int bits>
951 dword ImportDirectory<bits>::getFirstThunk(dword dwFilenr, currdir cdDir) const 951 dword ImportDirectory<bits>::getFirstThunk(dword dwFilenr, currdir cdDir) const
952 { 952 {
953 if (cdDir == OLDDIR) 953 if (cdDir == OLDDIR)
954 { 954 {
955 return m_vOldiid[dwFilenr].impdesc.FirstThunk; 955 return m_vOldiid[dwFilenr].impdesc.FirstThunk;
956 } 956 }
957 else 957 else
958 { 958 {
959 return m_vNewiid[dwFilenr].impdesc.FirstThunk; 959 return m_vNewiid[dwFilenr].impdesc.FirstThunk;
960 } 960 }
961 } 961 }
962 962
963 template<int bits> 963 template<int bits>
964 void ImportDirectory<bits>::setFirstThunk(dword dwFilenr, currdir cdDir, dword value) 964 void ImportDirectory<bits>::setFirstThunk(dword dwFilenr, currdir cdDir, dword value)
965 { 965 {
966 if (cdDir == OLDDIR) 966 if (cdDir == OLDDIR)
967 { 967 {
968 m_vOldiid[dwFilenr].impdesc.FirstThunk = value; 968 m_vOldiid[dwFilenr].impdesc.FirstThunk = value;
969 } 969 }
970 else 970 else
971 { 971 {
972 m_vNewiid[dwFilenr].impdesc.FirstThunk = value; 972 m_vNewiid[dwFilenr].impdesc.FirstThunk = value;
973 } 973 }
974 } 974 }
975 975
976 /** 976 /**
977 * @param strFilename Name of the imported file. 977 * @param strFilename Name of the imported file.
978 * @param cdDir Flag to decide if the OLDDIR or new import directory is used. 978 * @param cdDir Flag to decide if the OLDDIR or new import directory is used.
979 * @return OriginalFirstThunk value of an imported file. 979 * @return OriginalFirstThunk value of an imported file.
980 **/ 980 **/
981 template<int bits> 981 template<int bits>
982 dword ImportDirectory<bits>::getOriginalFirstThunk(dword dwFilenr, currdir cdDir) const 982 dword ImportDirectory<bits>::getOriginalFirstThunk(dword dwFilenr, currdir cdDir) const
983 { 983 {
984 if (cdDir == OLDDIR) 984 if (cdDir == OLDDIR)
985 { 985 {
986 return m_vOldiid[dwFilenr].impdesc.OriginalFirstThunk; 986 return m_vOldiid[dwFilenr].impdesc.OriginalFirstThunk;
987 } 987 }
988 else 988 else
989 { 989 {
990 return m_vNewiid[dwFilenr].impdesc.OriginalFirstThunk; 990 return m_vNewiid[dwFilenr].impdesc.OriginalFirstThunk;
991 } 991 }
992 } 992 }
993 993
994 template<int bits> 994 template<int bits>
995 void ImportDirectory<bits>::setOriginalFirstThunk(dword dwFilenr, currdir cdDir, dword value) 995 void ImportDirectory<bits>::setOriginalFirstThunk(dword dwFilenr, currdir cdDir, dword value)
996 { 996 {
997 if (cdDir == OLDDIR) 997 if (cdDir == OLDDIR)
998 { 998 {
999 m_vOldiid[dwFilenr].impdesc.OriginalFirstThunk = value; 999 m_vOldiid[dwFilenr].impdesc.OriginalFirstThunk = value;
1000 } 1000 }
1001 else 1001 else
1002 { 1002 {
1003 m_vNewiid[dwFilenr].impdesc.OriginalFirstThunk = value; 1003 m_vNewiid[dwFilenr].impdesc.OriginalFirstThunk = value;
1004 } 1004 }
1005 } 1005 }
1006 1006
1007 /** 1007 /**
1008 * @param strFilename Name of the imported file. 1008 * @param strFilename Name of the imported file.
1009 * @param cdDir Flag to decide if the OLDDIR or new import directory is used. 1009 * @param cdDir Flag to decide if the OLDDIR or new import directory is used.
1010 * @return ForwarderChain value of an imported file. 1010 * @return ForwarderChain value of an imported file.
1011 **/ 1011 **/
1012 template<int bits> 1012 template<int bits>
1013 dword ImportDirectory<bits>::getForwarderChain(dword dwFilenr, currdir cdDir) const 1013 dword ImportDirectory<bits>::getForwarderChain(dword dwFilenr, currdir cdDir) const
1014 { 1014 {
1015 if (cdDir == OLDDIR) 1015 if (cdDir == OLDDIR)
1016 { 1016 {
1017 return m_vOldiid[dwFilenr].impdesc.ForwarderChain; 1017 return m_vOldiid[dwFilenr].impdesc.ForwarderChain;
1018 } 1018 }
1019 else 1019 else
1020 { 1020 {
1021 return m_vNewiid[dwFilenr].impdesc.ForwarderChain; 1021 return m_vNewiid[dwFilenr].impdesc.ForwarderChain;
1022 } 1022 }
1023 } 1023 }
1024 1024
1025 template<int bits> 1025 template<int bits>
1026 void ImportDirectory<bits>::setForwarderChain(dword dwFilenr, currdir cdDir, dword value) 1026 void ImportDirectory<bits>::setForwarderChain(dword dwFilenr, currdir cdDir, dword value)
1027 { 1027 {
1028 if (cdDir == OLDDIR) 1028 if (cdDir == OLDDIR)
1029 { 1029 {
1030 m_vOldiid[dwFilenr].impdesc.ForwarderChain = value; 1030 m_vOldiid[dwFilenr].impdesc.ForwarderChain = value;
1031 } 1031 }
1032 else 1032 else
1033 { 1033 {
1034 m_vNewiid[dwFilenr].impdesc.ForwarderChain = value; 1034 m_vNewiid[dwFilenr].impdesc.ForwarderChain = value;
1035 } 1035 }
1036 } 1036 }
1037 1037
1038 /** 1038 /**
1039 * @param strFilename Name of the imported file. 1039 * @param strFilename Name of the imported file.
1040 * @param cdDir Flag to decide if the OLDDIR or new import directory is used. 1040 * @param cdDir Flag to decide if the OLDDIR or new import directory is used.
1041 * @return TimeDateStamp value of an imported file. 1041 * @return TimeDateStamp value of an imported file.
1042 **/ 1042 **/
1043 template<int bits> 1043 template<int bits>
1044 dword ImportDirectory<bits>::getTimeDateStamp(dword dwFilenr, currdir cdDir) const 1044 dword ImportDirectory<bits>::getTimeDateStamp(dword dwFilenr, currdir cdDir) const
1045 { 1045 {
1046 if (cdDir == OLDDIR) 1046 if (cdDir == OLDDIR)
1047 { 1047 {
1048 return m_vOldiid[dwFilenr].impdesc.TimeDateStamp; 1048 return m_vOldiid[dwFilenr].impdesc.TimeDateStamp;
1049 } 1049 }
1050 else 1050 else
1051 { 1051 {
1052 return m_vNewiid[dwFilenr].impdesc.TimeDateStamp; 1052 return m_vNewiid[dwFilenr].impdesc.TimeDateStamp;
1053 } 1053 }
1054 } 1054 }
1055 1055
1056 template<int bits> 1056 template<int bits>
1057 void ImportDirectory<bits>::setTimeDateStamp(dword dwFilenr, currdir cdDir, dword value) 1057 void ImportDirectory<bits>::setTimeDateStamp(dword dwFilenr, currdir cdDir, dword value)
1058 { 1058 {
1059 if (cdDir == OLDDIR) 1059 if (cdDir == OLDDIR)
1060 { 1060 {
1061 m_vOldiid[dwFilenr].impdesc.TimeDateStamp = value; 1061 m_vOldiid[dwFilenr].impdesc.TimeDateStamp = value;
1062 } 1062 }
1063 else 1063 else
1064 { 1064 {
1065 m_vNewiid[dwFilenr].impdesc.TimeDateStamp = value; 1065 m_vNewiid[dwFilenr].impdesc.TimeDateStamp = value;
1066 } 1066 }
1067 } 1067 }
1068 1068
1069 template<int bits> 1069 template<int bits>
1070 dword ImportDirectory<bits>::getRvaOfName(dword dwFilenr, currdir cdDir) const 1070 dword ImportDirectory<bits>::getRvaOfName(dword dwFilenr, currdir cdDir) const
1071 { 1071 {
1072 if (cdDir == OLDDIR) 1072 if (cdDir == OLDDIR)
1073 { 1073 {
1074 return m_vOldiid[dwFilenr].impdesc.Name; 1074 return m_vOldiid[dwFilenr].impdesc.Name;
1075 } 1075 }
1076 else 1076 else
1077 { 1077 {
1078 return m_vNewiid[dwFilenr].impdesc.Name; 1078 return m_vNewiid[dwFilenr].impdesc.Name;
1079 } 1079 }
1080 } 1080 }
1081 1081
1082 template<int bits> 1082 template<int bits>
1083 void ImportDirectory<bits>::setRvaOfName(dword dwFilenr, currdir cdDir, dword value) 1083 void ImportDirectory<bits>::setRvaOfName(dword dwFilenr, currdir cdDir, dword value)
1084 { 1084 {
1085 if (cdDir == OLDDIR) 1085 if (cdDir == OLDDIR)
1086 { 1086 {
1087 m_vOldiid[dwFilenr].impdesc.Name = value; 1087 m_vOldiid[dwFilenr].impdesc.Name = value;
1088 } 1088 }
1089 else 1089 else
1090 { 1090 {
1091 m_vNewiid[dwFilenr].impdesc.Name = value; 1091 m_vNewiid[dwFilenr].impdesc.Name = value;
1092 } 1092 }
1093 } 1093 }
1094 1094
1095 /** 1095 /**
1096 * @param dwFilenr ID of the imported file. 1096 * @param dwFilenr ID of the imported file.
1097 * @param dwFuncnr ID of the imported function. 1097 * @param dwFuncnr ID of the imported function.
1098 * @param cdDir Flag to decide if the OLDDIR or new import directory is used. 1098 * @param cdDir Flag to decide if the OLDDIR or new import directory is used.
1099 * @return FirstThunk value of an imported function. 1099 * @return FirstThunk value of an imported function.
1100 **/ 1100 **/
1101 template<int bits> 1101 template<int bits>
1102 dword ImportDirectory<bits>::getFirstThunk(dword dwFilenr, dword dwFuncnr, currdir cdDir) const 1102 dword ImportDirectory<bits>::getFirstThunk(dword dwFilenr, dword dwFuncnr, currdir cdDir) const
1103 { 1103 {
1104 if (cdDir == OLDDIR) return m_vOldiid[dwFilenr].firstthunk[dwFuncnr].itd.Ordinal; 1104 if (cdDir == OLDDIR) return m_vOldiid[dwFilenr].firstthunk[dwFuncnr].itd.Ordinal;
1105 else return m_vNewiid[dwFilenr].firstthunk[dwFuncnr].itd.Ordinal; 1105 else return m_vNewiid[dwFilenr].firstthunk[dwFuncnr].itd.Ordinal;
1106 } 1106 }
1107 1107
1108 template<int bits> 1108 template<int bits>
1109 void ImportDirectory<bits>::setFirstThunk(dword dwFilenr, dword dwFuncnr, currdir cdDir, dword value) 1109 void ImportDirectory<bits>::setFirstThunk(dword dwFilenr, dword dwFuncnr, currdir cdDir, dword value)
1110 { 1110 {
1111 if (cdDir == OLDDIR) m_vOldiid[dwFilenr].firstthunk[dwFuncnr].itd.Ordinal = value; 1111 if (cdDir == OLDDIR) m_vOldiid[dwFilenr].firstthunk[dwFuncnr].itd.Ordinal = value;
1112 else m_vNewiid[dwFilenr].firstthunk[dwFuncnr].itd.Ordinal = value; 1112 else m_vNewiid[dwFilenr].firstthunk[dwFuncnr].itd.Ordinal = value;
1113 } 1113 }
1114 1114
1115 /** 1115 /**
1116 * @param dwFilenr ID of the imported file. 1116 * @param dwFilenr ID of the imported file.
1117 * @param dwFuncnr ID of the imported function. 1117 * @param dwFuncnr ID of the imported function.
1118 * @param cdDir Flag to decide if the OLDDIR or new import directory is used. 1118 * @param cdDir Flag to decide if the OLDDIR or new import directory is used.
1119 * @return OriginalFirstThunk value of an imported function. 1119 * @return OriginalFirstThunk value of an imported function.
1120 **/ 1120 **/
1121 template<int bits> 1121 template<int bits>
1122 dword ImportDirectory<bits>::getOriginalFirstThunk(dword dwFilenr, dword dwFuncnr, currdir cdDir) const 1122 dword ImportDirectory<bits>::getOriginalFirstThunk(dword dwFilenr, dword dwFuncnr, currdir cdDir) const
1123 { 1123 {
1124 if (cdDir == OLDDIR) return m_vOldiid[dwFilenr].originalfirstthunk[dwFuncnr].itd.Ordinal; 1124 if (cdDir == OLDDIR) return m_vOldiid[dwFilenr].originalfirstthunk[dwFuncnr].itd.Ordinal;
1125 else return m_vNewiid[dwFilenr].originalfirstthunk[dwFuncnr].itd.Ordinal; 1125 else return m_vNewiid[dwFilenr].originalfirstthunk[dwFuncnr].itd.Ordinal;
1126 } 1126 }
1127 1127
1128 template<int bits> 1128 template<int bits>
1129 void ImportDirectory<bits>::setOriginalFirstThunk(dword dwFilenr, dword dwFuncnr, currdir cdDir, dword value) 1129 void ImportDirectory<bits>::setOriginalFirstThunk(dword dwFilenr, dword dwFuncnr, currdir cdDir, dword value)
1130 { 1130 {
1131 if (cdDir == OLDDIR) m_vOldiid[dwFilenr].originalfirstthunk[dwFuncnr].itd.Ordinal = value; 1131 if (cdDir == OLDDIR) m_vOldiid[dwFilenr].originalfirstthunk[dwFuncnr].itd.Ordinal = value;
1132 else m_vNewiid[dwFilenr].originalfirstthunk[dwFuncnr].itd.Ordinal = value; 1132 else m_vNewiid[dwFilenr].originalfirstthunk[dwFuncnr].itd.Ordinal = value;
1133 } 1133 }
1134 1134
1135 typedef ImportDirectory<32> ImportDirectory32; 1135 typedef ImportDirectory<32> ImportDirectory32;
1136 typedef ImportDirectory<64> ImportDirectory64; 1136 typedef ImportDirectory<64> ImportDirectory64;
1137} 1137}
1138 1138
1139#endif 1139#endif
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/MzHeader.cpp b/utils/zenutils/libraries/pelib-0.9/pelib/MzHeader.cpp
index 39fe54d80d..3a2119b7ac 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/MzHeader.cpp
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/MzHeader.cpp
@@ -1,584 +1,584 @@
1/* 1/*
2* MzHeader.cpp - Part of the PeLib library. 2* MzHeader.cpp - Part of the PeLib library.
3* 3*
4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) 4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5* All rights reserved. 5* All rights reserved.
6* 6*
7* This software is licensed under the zlib/libpng License. 7* This software is licensed under the zlib/libpng License.
8* For more details see http://www.opensource.org/licenses/zlib-license.php 8* For more details see http://www.opensource.org/licenses/zlib-license.php
9* or the license information file (license.htm) in the root directory 9* or the license information file (license.htm) in the root directory
10* of PeLib. 10* of PeLib.
11*/ 11*/
12 12
13#include "MzHeader.h" 13#include "MzHeader.h"
14#include <iostream> 14#include <iostream>
15 15
16namespace PeLib 16namespace PeLib
17{ 17{
18 /** 18 /**
19 * Reads data from an InputBuffer into the struct that represents the MZ header. 19 * Reads data from an InputBuffer into the struct that represents the MZ header.
20 * It's required that the size of the input buffer is at least as big as the 20 * It's required that the size of the input buffer is at least as big as the
21 * size of a MZ header. Otherwise we get undefined behaviour. 21 * size of a MZ header. Otherwise we get undefined behaviour.
22 * @param ibBuffer InputBuffer that holds the data. 22 * @param ibBuffer InputBuffer that holds the data.
23 * @return A non-zero value is returned if a problem occured. 23 * @return A non-zero value is returned if a problem occured.
24 **/ 24 **/
25 void MzHeader::read(InputBuffer& ibBuffer) 25 void MzHeader::read(InputBuffer& ibBuffer)
26 { 26 {
27 ibBuffer >> m_idhHeader.e_magic; 27 ibBuffer >> m_idhHeader.e_magic;
28 ibBuffer >> m_idhHeader.e_cblp; 28 ibBuffer >> m_idhHeader.e_cblp;
29 ibBuffer >> m_idhHeader.e_cp; 29 ibBuffer >> m_idhHeader.e_cp;
30 ibBuffer >> m_idhHeader.e_crlc; 30 ibBuffer >> m_idhHeader.e_crlc;
31 ibBuffer >> m_idhHeader.e_cparhdr; 31 ibBuffer >> m_idhHeader.e_cparhdr;
32 ibBuffer >> m_idhHeader.e_minalloc; 32 ibBuffer >> m_idhHeader.e_minalloc;
33 ibBuffer >> m_idhHeader.e_maxalloc; 33 ibBuffer >> m_idhHeader.e_maxalloc;
34 ibBuffer >> m_idhHeader.e_ss; 34 ibBuffer >> m_idhHeader.e_ss;
35 ibBuffer >> m_idhHeader.e_sp; 35 ibBuffer >> m_idhHeader.e_sp;
36 ibBuffer >> m_idhHeader.e_csum; 36 ibBuffer >> m_idhHeader.e_csum;
37 ibBuffer >> m_idhHeader.e_ip; 37 ibBuffer >> m_idhHeader.e_ip;
38 ibBuffer >> m_idhHeader.e_cs; 38 ibBuffer >> m_idhHeader.e_cs;
39 ibBuffer >> m_idhHeader.e_lfarlc; 39 ibBuffer >> m_idhHeader.e_lfarlc;
40 ibBuffer >> m_idhHeader.e_ovno; 40 ibBuffer >> m_idhHeader.e_ovno;
41 41
42 for (unsigned int i=0;i<sizeof(m_idhHeader.e_res)/sizeof(m_idhHeader.e_res[0]);i++) 42 for (unsigned int i=0;i<sizeof(m_idhHeader.e_res)/sizeof(m_idhHeader.e_res[0]);i++)
43 { 43 {
44 ibBuffer >> m_idhHeader.e_res[i]; 44 ibBuffer >> m_idhHeader.e_res[i];
45 } 45 }
46 46
47 ibBuffer >> m_idhHeader.e_oemid; 47 ibBuffer >> m_idhHeader.e_oemid;
48 ibBuffer >> m_idhHeader.e_oeminfo; 48 ibBuffer >> m_idhHeader.e_oeminfo;
49 49
50 for (unsigned int i=0;i<sizeof(m_idhHeader.e_res2)/sizeof(m_idhHeader.e_res2[0]);i++) 50 for (unsigned int i=0;i<sizeof(m_idhHeader.e_res2)/sizeof(m_idhHeader.e_res2[0]);i++)
51 { 51 {
52 ibBuffer >> m_idhHeader.e_res2[i]; 52 ibBuffer >> m_idhHeader.e_res2[i];
53 } 53 }
54 54
55 ibBuffer >> m_idhHeader.e_lfanew; 55 ibBuffer >> m_idhHeader.e_lfanew;
56 } 56 }
57 57
58 /** 58 /**
59 * Tests if the currently loaded MZ header is a valid MZ header. 59 * Tests if the currently loaded MZ header is a valid MZ header.
60 * Note that this function does not check if the address to the PE header is valid as this is not possible. 60 * Note that this function does not check if the address to the PE header is valid as this is not possible.
61 * Actually, the only thing this function checks is if the e_magic value is set to 0x5A4D (IMAGE_DOS_SIGNATURE). 61 * Actually, the only thing this function checks is if the e_magic value is set to 0x5A4D (IMAGE_DOS_SIGNATURE).
62 * Everything else is not relevant for Windows 2000 and that's the system PeLib is focusing on for now. 62 * Everything else is not relevant for Windows 2000 and that's the system PeLib is focusing on for now.
63 * @return A boolean value that indicates if the MZ header is correct or not. 63 * @return A boolean value that indicates if the MZ header is correct or not.
64 **/ 64 **/
65 bool MzHeader::isValid() const 65 bool MzHeader::isValid() const
66 { 66 {
67 // The only thing that matters on Windows 2K is the e_magic value. The entire rest is for DOS compatibility. 67 // The only thing that matters on Windows 2K is the e_magic value. The entire rest is for DOS compatibility.
68 return isValid(e_magic); 68 return isValid(e_magic);
69 } 69 }
70 70
71 bool MzHeader::isValid(Field f) const 71 bool MzHeader::isValid(Field f) const
72 { 72 {
73 if (f == e_magic) 73 if (f == e_magic)
74 { 74 {
75 return m_idhHeader.e_magic == PELIB_IMAGE_DOS_SIGNATURE; 75 return m_idhHeader.e_magic == PELIB_IMAGE_DOS_SIGNATURE;
76 } 76 }
77 else 77 else
78 { 78 {
79 return true; 79 return true;
80 } 80 }
81 } 81 }
82 82
83 /** 83 /**
84 * Corrects all erroneous values of the current MZ header. Note that this function does not correct the 84 * Corrects all erroneous values of the current MZ header. Note that this function does not correct the
85 * pointer to the PE header. 85 * pointer to the PE header.
86 * Actually, the only thing this function corrects is the e_magic value. 86 * Actually, the only thing this function corrects is the e_magic value.
87 * Everything else is not relevant for Windows 2000 and that's the system PeLib is focusing on for now. 87 * Everything else is not relevant for Windows 2000 and that's the system PeLib is focusing on for now.
88 **/ 88 **/
89 void MzHeader::makeValid() 89 void MzHeader::makeValid()
90 { 90 {
91 // The only thing that matters on Windows is the e_magic value. The entire rest is for DOS compatibility. 91 // The only thing that matters on Windows is the e_magic value. The entire rest is for DOS compatibility.
92 setMagicNumber(PELIB_IMAGE_DOS_SIGNATURE); 92 setMagicNumber(PELIB_IMAGE_DOS_SIGNATURE);
93 } 93 }
94 94
95 void MzHeader::makeValid(Field f) 95 void MzHeader::makeValid(Field f)
96 { 96 {
97 if (f == e_magic) 97 if (f == e_magic)
98 { 98 {
99 setMagicNumber(PELIB_IMAGE_DOS_SIGNATURE); 99 setMagicNumber(PELIB_IMAGE_DOS_SIGNATURE);
100 } 100 }
101 } 101 }
102 102
103 /** 103 /**
104 * Reads the MZ header from a file. Note that this function does not verify if a file is actually a MZ file. 104 * Reads the MZ header from a file. Note that this function does not verify if a file is actually a MZ file.
105 * For this purpose see #PeFile::MzHeader::isValid. The reason for this is simple: Otherwise it might not 105 * For this purpose see #PeFile::MzHeader::isValid. The reason for this is simple: Otherwise it might not
106 * be possible to load damaged PE files to repair them. 106 * be possible to load damaged PE files to repair them.
107 * @param strFilename Name of the file which will be read. 107 * @param strFilename Name of the file which will be read.
108 * @return A non-zero value is returned if a problem occured. 108 * @return A non-zero value is returned if a problem occured.
109 **/ 109 **/
110 int MzHeader::read(const std::string& strFilename) 110 int MzHeader::read(const std::string& strFilename)
111 { 111 {
112 std::ifstream ifFile(strFilename.c_str(), std::ios::binary); 112 std::ifstream ifFile(strFilename.c_str(), std::ios::binary);
113 113
114 if (!ifFile) 114 if (!ifFile)
115 { 115 {
116 return ERROR_OPENING_FILE; 116 return ERROR_OPENING_FILE;
117 } 117 }
118 118
119 if (fileSize(ifFile) < PELIB_IMAGE_DOS_HEADER::size()) 119 if (fileSize(ifFile) < PELIB_IMAGE_DOS_HEADER::size())
120 { 120 {
121 return ERROR_INVALID_FILE; 121 return ERROR_INVALID_FILE;
122 } 122 }
123 123
124 ifFile.seekg(0, std::ios::beg); 124 ifFile.seekg(0, std::ios::beg);
125 125
126 originalOffset = 0; 126 originalOffset = 0;
127 127
128 std::vector<byte> vBuffer(PELIB_IMAGE_DOS_HEADER::size()); 128 std::vector<byte> vBuffer(PELIB_IMAGE_DOS_HEADER::size());
129 ifFile.read(reinterpret_cast<char*>(&vBuffer[0]), static_cast<unsigned int>(vBuffer.size())); 129 ifFile.read(reinterpret_cast<char*>(&vBuffer[0]), static_cast<unsigned int>(vBuffer.size()));
130 ifFile.close(); 130 ifFile.close();
131 131
132 InputBuffer ibBuffer(vBuffer); 132 InputBuffer ibBuffer(vBuffer);
133 read(ibBuffer); 133 read(ibBuffer);
134 return NO_ERROR; 134 return NO_ERROR;
135 } 135 }
136 136
137 /** 137 /**
138 * Reads the MZ header from memory. A pointer to a location in memory is passed and the data 138 * Reads the MZ header from memory. A pointer to a location in memory is passed and the data
139 * at this location is treated like a MZ header structure. The MZ header does not need to be valid. 139 * at this location is treated like a MZ header structure. The MZ header does not need to be valid.
140 * @param pcBuffer Pointer to a MZ header. 140 * @param pcBuffer Pointer to a MZ header.
141 * @param uiSize Length of the buffer. 141 * @param uiSize Length of the buffer.
142 * @return A non-zero value is returned if a problem occured. 142 * @return A non-zero value is returned if a problem occured.
143 **/ 143 **/
144 int MzHeader::read(unsigned char* pcBuffer, unsigned int uiSize, unsigned int originalOffs) 144 int MzHeader::read(unsigned char* pcBuffer, unsigned int uiSize, unsigned int originalOffs)
145 { 145 {
146 if (uiSize < PELIB_IMAGE_DOS_HEADER::size()) 146 if (uiSize < PELIB_IMAGE_DOS_HEADER::size())
147 { 147 {
148 return ERROR_INVALID_FILE; 148 return ERROR_INVALID_FILE;
149 } 149 }
150 150
151 std::vector<byte> vBuffer(pcBuffer, pcBuffer + uiSize); 151 std::vector<byte> vBuffer(pcBuffer, pcBuffer + uiSize);
152 for (int i=0;i<0x40;i++) std::cout << std::hex << (int)vBuffer[i] << " "; 152 for (int i=0;i<0x40;i++) std::cout << std::hex << (int)vBuffer[i] << " ";
153 153
154 originalOffset = originalOffs; 154 originalOffset = originalOffs;
155 155
156 InputBuffer ibBuffer(vBuffer); 156 InputBuffer ibBuffer(vBuffer);
157 read(ibBuffer); 157 read(ibBuffer);
158 return NO_ERROR; 158 return NO_ERROR;
159 } 159 }
160 160
161 /** 161 /**
162 * Rebuilds the MZ header so that it can be written to a file. It's not guaranteed that the 162 * Rebuilds the MZ header so that it can be written to a file. It's not guaranteed that the
163 * MZ header will be valid. If you want to make sure that the MZ header will be valid you 163 * MZ header will be valid. If you want to make sure that the MZ header will be valid you
164 * must call #PeLib::MzHeader::makeValid first. 164 * must call #PeLib::MzHeader::makeValid first.
165 * @param vBuffer Buffer where the rebuilt MZ header will be stored. 165 * @param vBuffer Buffer where the rebuilt MZ header will be stored.
166 **/ 166 **/
167 void MzHeader::rebuild(std::vector<byte>& vBuffer) const 167 void MzHeader::rebuild(std::vector<byte>& vBuffer) const
168 { 168 {
169 OutputBuffer obBuffer(vBuffer); 169 OutputBuffer obBuffer(vBuffer);
170 170
171 obBuffer << m_idhHeader.e_magic; 171 obBuffer << m_idhHeader.e_magic;
172 obBuffer << m_idhHeader.e_cblp; 172 obBuffer << m_idhHeader.e_cblp;
173 obBuffer << m_idhHeader.e_cp; 173 obBuffer << m_idhHeader.e_cp;
174 obBuffer << m_idhHeader.e_crlc; 174 obBuffer << m_idhHeader.e_crlc;
175 obBuffer << m_idhHeader.e_cparhdr; 175 obBuffer << m_idhHeader.e_cparhdr;
176 obBuffer << m_idhHeader.e_minalloc; 176 obBuffer << m_idhHeader.e_minalloc;
177 obBuffer << m_idhHeader.e_maxalloc; 177 obBuffer << m_idhHeader.e_maxalloc;
178 obBuffer << m_idhHeader.e_ss; 178 obBuffer << m_idhHeader.e_ss;
179 obBuffer << m_idhHeader.e_sp; 179 obBuffer << m_idhHeader.e_sp;
180 obBuffer << m_idhHeader.e_csum; 180 obBuffer << m_idhHeader.e_csum;
181 obBuffer << m_idhHeader.e_ip; 181 obBuffer << m_idhHeader.e_ip;
182 obBuffer << m_idhHeader.e_cs; 182 obBuffer << m_idhHeader.e_cs;
183 obBuffer << m_idhHeader.e_lfarlc; 183 obBuffer << m_idhHeader.e_lfarlc;
184 obBuffer << m_idhHeader.e_ovno; 184 obBuffer << m_idhHeader.e_ovno;
185 185
186 for (unsigned int i=0;i<sizeof(m_idhHeader.e_res)/sizeof(m_idhHeader.e_res[0]);i++) 186 for (unsigned int i=0;i<sizeof(m_idhHeader.e_res)/sizeof(m_idhHeader.e_res[0]);i++)
187 { 187 {
188 obBuffer << m_idhHeader.e_res[i]; 188 obBuffer << m_idhHeader.e_res[i];
189 } 189 }
190 190
191 obBuffer << m_idhHeader.e_oemid; 191 obBuffer << m_idhHeader.e_oemid;
192 obBuffer << m_idhHeader.e_oeminfo; 192 obBuffer << m_idhHeader.e_oeminfo;
193 193
194 for (unsigned int i=0;i<sizeof(m_idhHeader.e_res2)/sizeof(m_idhHeader.e_res2[0]);i++) 194 for (unsigned int i=0;i<sizeof(m_idhHeader.e_res2)/sizeof(m_idhHeader.e_res2[0]);i++)
195 { 195 {
196 obBuffer << m_idhHeader.e_res2[i]; 196 obBuffer << m_idhHeader.e_res2[i];
197 } 197 }
198 198
199 obBuffer << m_idhHeader.e_lfanew; 199 obBuffer << m_idhHeader.e_lfanew;
200 } 200 }
201 201
202 /** 202 /**
203 * Returns the size of the MZ header. This size is actually always sizeof(IMAGE_DOS_HEADER) (== 0x40) 203 * Returns the size of the MZ header. This size is actually always sizeof(IMAGE_DOS_HEADER) (== 0x40)
204 * because the MZ header is a header of constant size if you disregard the dos stub. If you want to know the 204 * because the MZ header is a header of constant size if you disregard the dos stub. If you want to know the
205 * size of the MZ header + the size of the dos stub check #PeLib::MzHeader::getAddressOfPeHeader. 205 * size of the MZ header + the size of the dos stub check #PeLib::MzHeader::getAddressOfPeHeader.
206 * @return Size of the MZ header. 206 * @return Size of the MZ header.
207 **/ 207 **/
208 unsigned int MzHeader::size() const 208 unsigned int MzHeader::size() const
209 { 209 {
210 return sizeof(m_idhHeader); 210 return sizeof(m_idhHeader);
211 } 211 }
212 212
213 /** 213 /**
214 * Writes the current MZ header to a file. The file does not have to exist. If it doesn't exist 214 * Writes the current MZ header to a file. The file does not have to exist. If it doesn't exist
215 * it will be created. 215 * it will be created.
216 * @param strFilename Name of the file the header will be written to. 216 * @param strFilename Name of the file the header will be written to.
217 * @param dwOffset Offset the header will be written to (defaults to 0). 217 * @param dwOffset Offset the header will be written to (defaults to 0).
218 * @return A non-zero value is returned if a problem occured. 218 * @return A non-zero value is returned if a problem occured.
219 **/ 219 **/
220 int MzHeader::write(const std::string& strFilename, dword dwOffset = 0) const 220 int MzHeader::write(const std::string& strFilename, dword dwOffset = 0) const
221 { 221 {
222 std::fstream ofFile(strFilename.c_str(), std::ios_base::in); 222 std::fstream ofFile(strFilename.c_str(), std::ios_base::in);
223 223
224 if (!ofFile) 224 if (!ofFile)
225 { 225 {
226 ofFile.clear(); 226 ofFile.clear();
227 ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary); 227 ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary);
228 } 228 }
229 else 229 else
230 { 230 {
231 ofFile.close(); 231 ofFile.close();
232 ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary); 232 ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary);
233 } 233 }
234 234
235 if (!ofFile) 235 if (!ofFile)
236 { 236 {
237 return ERROR_OPENING_FILE; 237 return ERROR_OPENING_FILE;
238 } 238 }
239 239
240 ofFile.seekp(dwOffset, std::ios::beg); 240 ofFile.seekp(dwOffset, std::ios::beg);
241 241
242 std::vector<unsigned char> vBuffer; 242 std::vector<unsigned char> vBuffer;
243 243
244 rebuild(vBuffer); 244 rebuild(vBuffer);
245 245
246 ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), static_cast<unsigned int>(vBuffer.size())); 246 ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), static_cast<unsigned int>(vBuffer.size()));
247 247
248 ofFile.close(); 248 ofFile.close();
249 249
250 return NO_ERROR; 250 return NO_ERROR;
251 } 251 }
252 252
253 /** 253 /**
254 * Returns the MZ header's e_magic value. 254 * Returns the MZ header's e_magic value.
255 **/ 255 **/
256 word MzHeader::getMagicNumber() const 256 word MzHeader::getMagicNumber() const
257 { 257 {
258 return m_idhHeader.e_magic; 258 return m_idhHeader.e_magic;
259 } 259 }
260 260
261 /** 261 /**
262 * Returns the MZ header's e_cblp value. 262 * Returns the MZ header's e_cblp value.
263 **/ 263 **/
264 word MzHeader::getBytesOnLastPage() const 264 word MzHeader::getBytesOnLastPage() const
265 { 265 {
266 return m_idhHeader.e_cblp; 266 return m_idhHeader.e_cblp;
267 } 267 }
268 268
269 /** 269 /**
270 * Returns the MZ header's e_cp value. 270 * Returns the MZ header's e_cp value.
271 **/ 271 **/
272 word MzHeader::getPagesInFile() const 272 word MzHeader::getPagesInFile() const
273 { 273 {
274 return m_idhHeader.e_cp; 274 return m_idhHeader.e_cp;
275 } 275 }
276 276
277 /** 277 /**
278 * Returns the MZ header's e_crlc value. 278 * Returns the MZ header's e_crlc value.
279 **/ 279 **/
280 word MzHeader::getRelocations() const 280 word MzHeader::getRelocations() const
281 { 281 {
282 return m_idhHeader.e_crlc; 282 return m_idhHeader.e_crlc;
283 } 283 }
284 284
285 /** 285 /**
286 * Returns the MZ header's e_cparhdr value. 286 * Returns the MZ header's e_cparhdr value.
287 **/ 287 **/
288 word MzHeader::getSizeOfHeader() const 288 word MzHeader::getSizeOfHeader() const
289 { 289 {
290 return m_idhHeader.e_cparhdr; 290 return m_idhHeader.e_cparhdr;
291 } 291 }
292 292
293 /** 293 /**
294 * Returns the MZ header's e_minalloc value. 294 * Returns the MZ header's e_minalloc value.
295 **/ 295 **/
296 word MzHeader::getMinExtraParagraphs() const 296 word MzHeader::getMinExtraParagraphs() const
297 { 297 {
298 return m_idhHeader.e_minalloc; 298 return m_idhHeader.e_minalloc;
299 } 299 }
300 300
301 /** 301 /**
302 * Returns the MZ header's e_maxalloc value. 302 * Returns the MZ header's e_maxalloc value.
303 **/ 303 **/
304 word MzHeader::getMaxExtraParagraphs() const 304 word MzHeader::getMaxExtraParagraphs() const
305 { 305 {
306 return m_idhHeader.e_maxalloc; 306 return m_idhHeader.e_maxalloc;
307 } 307 }
308 308
309 /** 309 /**
310 * Returns the MZ header's e_ss value. 310 * Returns the MZ header's e_ss value.
311 **/ 311 **/
312 word MzHeader::getSsValue() const 312 word MzHeader::getSsValue() const
313 { 313 {
314 return m_idhHeader.e_ss; 314 return m_idhHeader.e_ss;
315 } 315 }
316 316
317 /** 317 /**
318 * Returns the MZ header's e_sp value. 318 * Returns the MZ header's e_sp value.
319 **/ 319 **/
320 word MzHeader::getSpValue() const 320 word MzHeader::getSpValue() const
321 { 321 {
322 return m_idhHeader.e_sp; 322 return m_idhHeader.e_sp;
323 } 323 }
324 324
325 /** 325 /**
326 * Returns the MZ header's e_csum value. 326 * Returns the MZ header's e_csum value.
327 **/ 327 **/
328 word MzHeader::getChecksum() const 328 word MzHeader::getChecksum() const
329 { 329 {
330 return m_idhHeader.e_csum; 330 return m_idhHeader.e_csum;
331 } 331 }
332 332
333 /** 333 /**
334 * Returns the MZ header's e_ip value. 334 * Returns the MZ header's e_ip value.
335 **/ 335 **/
336 word MzHeader::getIpValue() const 336 word MzHeader::getIpValue() const
337 { 337 {
338 return m_idhHeader.e_ip; 338 return m_idhHeader.e_ip;
339 } 339 }
340 340
341 /** 341 /**
342 * Returns the MZ header's e_cs value. 342 * Returns the MZ header's e_cs value.
343 **/ 343 **/
344 word MzHeader::getCsValue() const 344 word MzHeader::getCsValue() const
345 { 345 {
346 return m_idhHeader.e_cs; 346 return m_idhHeader.e_cs;
347 } 347 }
348 348
349 /** 349 /**
350 * Returns the MZ header's e_lfarlc value. 350 * Returns the MZ header's e_lfarlc value.
351 **/ 351 **/
352 word MzHeader::getAddrOfRelocationTable() const 352 word MzHeader::getAddrOfRelocationTable() const
353 { 353 {
354 return m_idhHeader.e_lfarlc; 354 return m_idhHeader.e_lfarlc;
355 } 355 }
356 356
357 /** 357 /**
358 * Returns the MZ header's e_ovno value. 358 * Returns the MZ header's e_ovno value.
359 **/ 359 **/
360 word MzHeader::getOverlayNumber() const 360 word MzHeader::getOverlayNumber() const
361 { 361 {
362 return m_idhHeader.e_ovno; 362 return m_idhHeader.e_ovno;
363 } 363 }
364 364
365 /** 365 /**
366 * Returns the MZ header's e_oemid value. 366 * Returns the MZ header's e_oemid value.
367 **/ 367 **/
368 word MzHeader::getOemIdentifier() const 368 word MzHeader::getOemIdentifier() const
369 { 369 {
370 return m_idhHeader.e_oemid; 370 return m_idhHeader.e_oemid;
371 } 371 }
372 372
373 /** 373 /**
374 * Returns the MZ header's e_oeminfo value. 374 * Returns the MZ header's e_oeminfo value.
375 **/ 375 **/
376 word MzHeader::getOemInformation() const 376 word MzHeader::getOemInformation() const
377 { 377 {
378 return m_idhHeader.e_oeminfo; 378 return m_idhHeader.e_oeminfo;
379 } 379 }
380 380
381 /** 381 /**
382 * Returns the MZ header's e_lfanew value. 382 * Returns the MZ header's e_lfanew value.
383 **/ 383 **/
384 dword MzHeader::getAddressOfPeHeader() const 384 dword MzHeader::getAddressOfPeHeader() const
385 { 385 {
386 return m_idhHeader.e_lfanew; 386 return m_idhHeader.e_lfanew;
387 } 387 }
388 388
389 /** 389 /**
390 * Returns the MZ header's e_res[uiNr] value. If the parameter uiNr is out of range 390 * Returns the MZ header's e_res[uiNr] value. If the parameter uiNr is out of range
391 * you will get undefined behaviour. 391 * you will get undefined behaviour.
392 * @param uiNr The index of the word in the e_res array (valid range: 0-3) 392 * @param uiNr The index of the word in the e_res array (valid range: 0-3)
393 **/ 393 **/
394 word MzHeader::getReservedWords1(unsigned int uiNr) const 394 word MzHeader::getReservedWords1(unsigned int uiNr) const
395 { 395 {
396 return m_idhHeader.e_res[uiNr]; 396 return m_idhHeader.e_res[uiNr];
397 } 397 }
398 398
399 /** 399 /**
400 * Returns the MZ header's e_res2[uiNr] value. If the parameter uiNr is out of range 400 * Returns the MZ header's e_res2[uiNr] value. If the parameter uiNr is out of range
401 * you will get undefined behaviour. 401 * you will get undefined behaviour.
402 * @param uiNr The index of the word in the e_res array (valid range: 0-9) 402 * @param uiNr The index of the word in the e_res array (valid range: 0-9)
403 **/ 403 **/
404 word MzHeader::getReservedWords2(unsigned int uiNr) const 404 word MzHeader::getReservedWords2(unsigned int uiNr) const
405 { 405 {
406 return m_idhHeader.e_res2[uiNr]; 406 return m_idhHeader.e_res2[uiNr];
407 } 407 }
408 408
409 /** 409 /**
410 * Sets the MZ header's e_magic value. 410 * Sets the MZ header's e_magic value.
411 * @param wValue The new value of e_magic. 411 * @param wValue The new value of e_magic.
412 **/ 412 **/
413 void MzHeader::setMagicNumber(word wValue) 413 void MzHeader::setMagicNumber(word wValue)
414 { 414 {
415 m_idhHeader.e_magic = wValue; 415 m_idhHeader.e_magic = wValue;
416 } 416 }
417 417
418 /** 418 /**
419 * Sets the MZ header's e_cblp value. 419 * Sets the MZ header's e_cblp value.
420 * @param wValue The new value of e_cblp. 420 * @param wValue The new value of e_cblp.
421 **/ 421 **/
422 void MzHeader::setBytesOnLastPage(word wValue) 422 void MzHeader::setBytesOnLastPage(word wValue)
423 { 423 {
424 m_idhHeader.e_cblp = wValue; 424 m_idhHeader.e_cblp = wValue;
425 } 425 }
426 426
427 /** 427 /**
428 * Sets the MZ header's e_cp value. 428 * Sets the MZ header's e_cp value.
429 * @param wValue The new value of e_cp. 429 * @param wValue The new value of e_cp.
430 **/ 430 **/
431 void MzHeader::setPagesInFile(word wValue) 431 void MzHeader::setPagesInFile(word wValue)
432 { 432 {
433 m_idhHeader.e_cp = wValue; 433 m_idhHeader.e_cp = wValue;
434 } 434 }
435 435
436 /** 436 /**
437 * Sets the MZ header's e_crlc value. 437 * Sets the MZ header's e_crlc value.
438 * @param wValue The new value of e_crlc. 438 * @param wValue The new value of e_crlc.
439 **/ 439 **/
440 void MzHeader::setRelocations(word wValue) 440 void MzHeader::setRelocations(word wValue)
441 { 441 {
442 m_idhHeader.e_crlc = wValue; 442 m_idhHeader.e_crlc = wValue;
443 } 443 }
444 444
445 /** 445 /**
446 * Sets the MZ header's e_cparhdr value. 446 * Sets the MZ header's e_cparhdr value.
447 * @param wValue The new value of e_cparhdr. 447 * @param wValue The new value of e_cparhdr.
448 **/ 448 **/
449 void MzHeader::setSizeOfHeader(word wValue) 449 void MzHeader::setSizeOfHeader(word wValue)
450 { 450 {
451 m_idhHeader.e_cparhdr = wValue; 451 m_idhHeader.e_cparhdr = wValue;
452 } 452 }
453 453
454 /** 454 /**
455 * Sets the MZ header's e_minalloc value. 455 * Sets the MZ header's e_minalloc value.
456 * @param wValue The new value of e_minalloc. 456 * @param wValue The new value of e_minalloc.
457 **/ 457 **/
458 void MzHeader::setMinExtraParagraphs(word wValue) 458 void MzHeader::setMinExtraParagraphs(word wValue)
459 { 459 {
460 m_idhHeader.e_minalloc = wValue; 460 m_idhHeader.e_minalloc = wValue;
461 } 461 }
462 462
463 /** 463 /**
464 * Sets the MZ header's e_maxalloc value. 464 * Sets the MZ header's e_maxalloc value.
465 * @param wValue The new value of e_maxalloc. 465 * @param wValue The new value of e_maxalloc.
466 **/ 466 **/
467 void MzHeader::setMaxExtraParagraphs(word wValue) 467 void MzHeader::setMaxExtraParagraphs(word wValue)
468 { 468 {
469 m_idhHeader.e_maxalloc = wValue; 469 m_idhHeader.e_maxalloc = wValue;
470 } 470 }
471 471
472 /** 472 /**
473 * Sets the MZ header's e_ss value. 473 * Sets the MZ header's e_ss value.
474 * @param wValue The new value of e_ss. 474 * @param wValue The new value of e_ss.
475 **/ 475 **/
476 void MzHeader::setSsValue(word wValue) 476 void MzHeader::setSsValue(word wValue)
477 { 477 {
478 m_idhHeader.e_ss = wValue; 478 m_idhHeader.e_ss = wValue;
479 } 479 }
480 480
481 /** 481 /**
482 * Sets the MZ header's e_sp value. 482 * Sets the MZ header's e_sp value.
483 * @param wValue The new value of e_sp. 483 * @param wValue The new value of e_sp.
484 **/ 484 **/
485 void MzHeader::setSpValue(word wValue) 485 void MzHeader::setSpValue(word wValue)
486 { 486 {
487 m_idhHeader.e_sp = wValue; 487 m_idhHeader.e_sp = wValue;
488 } 488 }
489 489
490 /** 490 /**
491 * Sets the MZ header's e_csum value. 491 * Sets the MZ header's e_csum value.
492 * @param wValue The new value of e_csum. 492 * @param wValue The new value of e_csum.
493 **/ 493 **/
494 void MzHeader::setChecksum(word wValue) 494 void MzHeader::setChecksum(word wValue)
495 { 495 {
496 m_idhHeader.e_csum = wValue; 496 m_idhHeader.e_csum = wValue;
497 } 497 }
498 498
499 /** 499 /**
500 * Sets the MZ header's e_ip value. 500 * Sets the MZ header's e_ip value.
501 * @param wValue The new value of e_ip. 501 * @param wValue The new value of e_ip.
502 **/ 502 **/
503 void MzHeader::setIpValue(word wValue) 503 void MzHeader::setIpValue(word wValue)
504 { 504 {
505 m_idhHeader.e_ip = wValue; 505 m_idhHeader.e_ip = wValue;
506 } 506 }
507 507
508 /** 508 /**
509 * Sets the MZ header's e_cs value. 509 * Sets the MZ header's e_cs value.
510 * @param wValue The new value of e_cs. 510 * @param wValue The new value of e_cs.
511 **/ 511 **/
512 void MzHeader::setCsValue(word wValue) 512 void MzHeader::setCsValue(word wValue)
513 { 513 {
514 m_idhHeader.e_cs = wValue; 514 m_idhHeader.e_cs = wValue;
515 } 515 }
516 516
517 /** 517 /**
518 * Sets the MZ header's e_lfarlc value. 518 * Sets the MZ header's e_lfarlc value.
519 * @param wValue The new value of e_lfarlc. 519 * @param wValue The new value of e_lfarlc.
520 **/ 520 **/
521 void MzHeader::setAddrOfRelocationTable(word wValue) 521 void MzHeader::setAddrOfRelocationTable(word wValue)
522 { 522 {
523 m_idhHeader.e_lfarlc = wValue; 523 m_idhHeader.e_lfarlc = wValue;
524 } 524 }
525 525
526 /** 526 /**
527 * Sets the MZ header's e_ovno value. 527 * Sets the MZ header's e_ovno value.
528 * @param wValue The new value of e_ovno. 528 * @param wValue The new value of e_ovno.
529 **/ 529 **/
530 void MzHeader::setOverlayNumber(word wValue) 530 void MzHeader::setOverlayNumber(word wValue)
531 { 531 {
532 m_idhHeader.e_ovno = wValue; 532 m_idhHeader.e_ovno = wValue;
533 } 533 }
534 534
535 /** 535 /**
536 * Sets the MZ header's e_oemid value. 536 * Sets the MZ header's e_oemid value.
537 * @param wValue The new value of e_oemid. 537 * @param wValue The new value of e_oemid.
538 **/ 538 **/
539 void MzHeader::setOemIdentifier(word wValue) 539 void MzHeader::setOemIdentifier(word wValue)
540 { 540 {
541 m_idhHeader.e_oemid = wValue; 541 m_idhHeader.e_oemid = wValue;
542 } 542 }
543 543
544 /** 544 /**
545 * Sets the MZ header's e_oeminfo value. 545 * Sets the MZ header's e_oeminfo value.
546 * @param wValue The new value of e_oeminfo. 546 * @param wValue The new value of e_oeminfo.
547 **/ 547 **/
548 void MzHeader::setOemInformation(word wValue) 548 void MzHeader::setOemInformation(word wValue)
549 { 549 {
550 m_idhHeader.e_oeminfo = wValue; 550 m_idhHeader.e_oeminfo = wValue;
551 } 551 }
552 552
553 /** 553 /**
554 * Sets the MZ header's e_lfanew value. 554 * Sets the MZ header's e_lfanew value.
555 * @param lValue The new value of e_lfanew. 555 * @param lValue The new value of e_lfanew.
556 **/ 556 **/
557 void MzHeader::setAddressOfPeHeader(dword lValue) 557 void MzHeader::setAddressOfPeHeader(dword lValue)
558 { 558 {
559 m_idhHeader.e_lfanew = lValue; 559 m_idhHeader.e_lfanew = lValue;
560 } 560 }
561 561
562 /** 562 /**
563 * Sets the MZ header's e_res[uiNr] value. If the parameter uiNr is out of range 563 * Sets the MZ header's e_res[uiNr] value. If the parameter uiNr is out of range
564 * you will get undefined behaviour. 564 * you will get undefined behaviour.
565 * @param uiNr The index of the word in the e_res array (valid range: 0-3) 565 * @param uiNr The index of the word in the e_res array (valid range: 0-3)
566 * @param wValue The new value of e_res[nr]. 566 * @param wValue The new value of e_res[nr].
567 **/ 567 **/
568 void MzHeader::setReservedWords1(unsigned int uiNr, word wValue) 568 void MzHeader::setReservedWords1(unsigned int uiNr, word wValue)
569 { 569 {
570 m_idhHeader.e_res[uiNr] = wValue; 570 m_idhHeader.e_res[uiNr] = wValue;
571 } 571 }
572 572
573 /** 573 /**
574 * Sets the MZ header's e_res2[uiNr] value. If the parameter uiNr is out of range 574 * Sets the MZ header's e_res2[uiNr] value. If the parameter uiNr is out of range
575 * you will get undefined behaviour. 575 * you will get undefined behaviour.
576 * @param uiNr The index of the word in the e_res2 array (valid range: 0-9) 576 * @param uiNr The index of the word in the e_res2 array (valid range: 0-9)
577 * @param wValue The new value of e_res[nr]. 577 * @param wValue The new value of e_res[nr].
578 **/ 578 **/
579 void MzHeader::setReservedWords2(unsigned int uiNr, word wValue) 579 void MzHeader::setReservedWords2(unsigned int uiNr, word wValue)
580 { 580 {
581 m_idhHeader.e_res2[uiNr] = wValue; 581 m_idhHeader.e_res2[uiNr] = wValue;
582 } 582 }
583 583
584} 584}
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/MzHeader.h b/utils/zenutils/libraries/pelib-0.9/pelib/MzHeader.h
index 5aca6bfe59..4acb819727 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/MzHeader.h
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/MzHeader.h
@@ -1,148 +1,148 @@
1/* 1/*
2* MzHeader.h - Part of the PeLib library. 2* MzHeader.h - Part of the PeLib library.
3* 3*
4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) 4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5* All rights reserved. 5* All rights reserved.
6* 6*
7* This software is licensed under the zlib/libpng License. 7* This software is licensed under the zlib/libpng License.
8* For more details see http://www.opensource.org/licenses/zlib-license.php 8* For more details see http://www.opensource.org/licenses/zlib-license.php
9* or the license information file (license.htm) in the root directory 9* or the license information file (license.htm) in the root directory
10* of PeLib. 10* of PeLib.
11*/ 11*/
12 12
13#ifndef MZHEADER_H 13#ifndef MZHEADER_H
14#define MZHEADER_H 14#define MZHEADER_H
15 15
16#include "PeLibInc.h" 16#include "PeLibInc.h"
17 17
18namespace PeLib 18namespace PeLib
19{ 19{
20 /// Class that handles the MZ header of files. 20 /// Class that handles the MZ header of files.
21 /** 21 /**
22 * This class can read and modify MZ headers. It provides set- and get functions to access 22 * This class can read and modify MZ headers. It provides set- and get functions to access
23 * all individual members of a MZ header. Furthermore it's possible to validate and rebuild 23 * all individual members of a MZ header. Furthermore it's possible to validate and rebuild
24 * MZ headers. 24 * MZ headers.
25 **/ 25 **/
26 class MzHeader 26 class MzHeader
27 { 27 {
28 private: 28 private:
29 PELIB_IMAGE_DOS_HEADER m_idhHeader; ///< Stores all MZ header information. 29 PELIB_IMAGE_DOS_HEADER m_idhHeader; ///< Stores all MZ header information.
30 30
31 /// Reads data from an InputBuffer into a MZ header struct. 31 /// Reads data from an InputBuffer into a MZ header struct.
32 void read(InputBuffer& ibBuffer); 32 void read(InputBuffer& ibBuffer);
33 33
34 /// Offset of the MZ header in the original file. 34 /// Offset of the MZ header in the original file.
35 unsigned int originalOffset; 35 unsigned int originalOffset;
36 36
37 public: 37 public:
38 38
39 enum Field {e_magic, e_cblp, e_cp, e_crlc, e_cparhdr, e_minalloc, e_maxalloc, 39 enum Field {e_magic, e_cblp, e_cp, e_crlc, e_cparhdr, e_minalloc, e_maxalloc,
40 e_ss, e_sp, e_csum, e_ip, e_cs, e_lfarlc, e_ovno, e_res, e_oemid, 40 e_ss, e_sp, e_csum, e_ip, e_cs, e_lfarlc, e_ovno, e_res, e_oemid,
41 e_oeminfo, e_res2, e_lfanew}; 41 e_oeminfo, e_res2, e_lfanew};
42 42
43 /// Checks if the current MZ header is valid. 43 /// Checks if the current MZ header is valid.
44 bool isValid() const; // EXPORT 44 bool isValid() const; // EXPORT
45 45
46 bool isValid(Field field) const; // EXPORT _field 46 bool isValid(Field field) const; // EXPORT _field
47 47
48 /// Corrects the current MZ header. 48 /// Corrects the current MZ header.
49 void makeValid(); // EXPORT 49 void makeValid(); // EXPORT
50 50
51 void makeValid(Field field); // EXPORT _field 51 void makeValid(Field field); // EXPORT _field
52 52
53 /// Reads the MZ header of a file. 53 /// Reads the MZ header of a file.
54 int read(const std::string& strFilename); // EXPORT 54 int read(const std::string& strFilename); // EXPORT
55 55
56 /// Reads the MZ header from a memory location. 56 /// Reads the MZ header from a memory location.
57 int read(unsigned char* pcBuffer, unsigned int uiSize, unsigned int originalOffs = 0); // EXPORT _fromMemory 57 int read(unsigned char* pcBuffer, unsigned int uiSize, unsigned int originalOffs = 0); // EXPORT _fromMemory
58 58
59 /// Rebuild the MZ header. 59 /// Rebuild the MZ header.
60 void rebuild(std::vector<byte>& vBuffer) const; // EXPORT 60 void rebuild(std::vector<byte>& vBuffer) const; // EXPORT
61 61
62 /// Returns the size of the current MZ header. 62 /// Returns the size of the current MZ header.
63 unsigned int size() const; // EXPORT 63 unsigned int size() const; // EXPORT
64 64
65 /// Writes the current MZ header to offset 0 of a file. 65 /// Writes the current MZ header to offset 0 of a file.
66 int write(const std::string& strFilename, dword dwOffset) const; // EXPORT 66 int write(const std::string& strFilename, dword dwOffset) const; // EXPORT
67 67
68 /// Gets the e_magic value of the MZ header. 68 /// Gets the e_magic value of the MZ header.
69 word getMagicNumber() const; // EXPORT 69 word getMagicNumber() const; // EXPORT
70 /// Gets the e_cblp value of the MZ header. 70 /// Gets the e_cblp value of the MZ header.
71 word getBytesOnLastPage() const; // EXPORT 71 word getBytesOnLastPage() const; // EXPORT
72 /// Gets the e_cp value of the MZ header. 72 /// Gets the e_cp value of the MZ header.
73 word getPagesInFile() const; // EXPORT 73 word getPagesInFile() const; // EXPORT
74 /// Gets the e_crlc value of the MZ header. 74 /// Gets the e_crlc value of the MZ header.
75 word getRelocations() const; // EXPORT 75 word getRelocations() const; // EXPORT
76 /// Gets the e_cparhdr value of the MZ header. 76 /// Gets the e_cparhdr value of the MZ header.
77 word getSizeOfHeader() const; // EXPORT 77 word getSizeOfHeader() const; // EXPORT
78 /// Gets the e_minalloc value of the MZ header. 78 /// Gets the e_minalloc value of the MZ header.
79 word getMinExtraParagraphs() const; // EXPORT 79 word getMinExtraParagraphs() const; // EXPORT
80 /// Gets the e_maxalloc value of the MZ header. 80 /// Gets the e_maxalloc value of the MZ header.
81 word getMaxExtraParagraphs() const; // EXPORT 81 word getMaxExtraParagraphs() const; // EXPORT
82 /// Gets the e_ss value of the MZ header. 82 /// Gets the e_ss value of the MZ header.
83 word getSsValue() const; // EXPORT 83 word getSsValue() const; // EXPORT
84 /// Gets the e_sp value of the MZ header. 84 /// Gets the e_sp value of the MZ header.
85 word getSpValue() const; // EXPORT 85 word getSpValue() const; // EXPORT
86 /// Gets the e_csum value of the MZ header. 86 /// Gets the e_csum value of the MZ header.
87 word getChecksum() const; // EXPORT 87 word getChecksum() const; // EXPORT
88 /// Gets the e_ip value of the MZ header. 88 /// Gets the e_ip value of the MZ header.
89 word getIpValue() const; // EXPORT 89 word getIpValue() const; // EXPORT
90 /// Gets the e_cs value of the MZ header. 90 /// Gets the e_cs value of the MZ header.
91 word getCsValue() const; // EXPORT 91 word getCsValue() const; // EXPORT
92 /// Gets the e_lfarlc value of the MZ header. 92 /// Gets the e_lfarlc value of the MZ header.
93 word getAddrOfRelocationTable() const; // EXPORT 93 word getAddrOfRelocationTable() const; // EXPORT
94 /// Gets the e_ovnovalue of the MZ header. 94 /// Gets the e_ovnovalue of the MZ header.
95 word getOverlayNumber() const; // EXPORT 95 word getOverlayNumber() const; // EXPORT
96 /// Gets the e_oemid value of the MZ header. 96 /// Gets the e_oemid value of the MZ header.
97 word getOemIdentifier() const; // EXPORT 97 word getOemIdentifier() const; // EXPORT
98 /// Gets the e_oeminfo value of the MZ header. 98 /// Gets the e_oeminfo value of the MZ header.
99 word getOemInformation() const; // EXPORT 99 word getOemInformation() const; // EXPORT
100 /// Gets the e_lfanew value of the MZ header. 100 /// Gets the e_lfanew value of the MZ header.
101 dword getAddressOfPeHeader() const; // EXPORT 101 dword getAddressOfPeHeader() const; // EXPORT
102 /// Gets the e_res of the MZ header. 102 /// Gets the e_res of the MZ header.
103 word getReservedWords1(unsigned int uiNr) const; // EXPORT 103 word getReservedWords1(unsigned int uiNr) const; // EXPORT
104 /// Gets the e_res2 of the MZ header. 104 /// Gets the e_res2 of the MZ header.
105 word getReservedWords2(unsigned int uiNr) const; // EXPORT 105 word getReservedWords2(unsigned int uiNr) const; // EXPORT
106 106
107 /// Sets the e_magic value of the MZ header. 107 /// Sets the e_magic value of the MZ header.
108 void setMagicNumber(word wValue); // EXPORT 108 void setMagicNumber(word wValue); // EXPORT
109 /// Sets the e_cblp value of the MZ header. 109 /// Sets the e_cblp value of the MZ header.
110 void setBytesOnLastPage(word wValue); // EXPORT 110 void setBytesOnLastPage(word wValue); // EXPORT
111 /// Sets the e_cp value of the MZ header. 111 /// Sets the e_cp value of the MZ header.
112 void setPagesInFile(word wValue); // EXPORT 112 void setPagesInFile(word wValue); // EXPORT
113 /// Sets the e_crlc value of the MZ header. 113 /// Sets the e_crlc value of the MZ header.
114 void setRelocations(word wValue); // EXPORT 114 void setRelocations(word wValue); // EXPORT
115 /// Sets the e_cparhdr value of the MZ header. 115 /// Sets the e_cparhdr value of the MZ header.
116 void setSizeOfHeader(word wValue); // EXPORT 116 void setSizeOfHeader(word wValue); // EXPORT
117 /// Sets the e_minalloc value of the MZ header. 117 /// Sets the e_minalloc value of the MZ header.
118 void setMinExtraParagraphs(word wValue); // EXPORT 118 void setMinExtraParagraphs(word wValue); // EXPORT
119 /// Sets the e_maxalloc value of the MZ header. 119 /// Sets the e_maxalloc value of the MZ header.
120 void setMaxExtraParagraphs(word wValue); // EXPORT 120 void setMaxExtraParagraphs(word wValue); // EXPORT
121 /// Sets the e_ss value of the MZ header. 121 /// Sets the e_ss value of the MZ header.
122 void setSsValue(word wValue); // EXPORT 122 void setSsValue(word wValue); // EXPORT
123 /// Sets the e_sp value of the MZ header. 123 /// Sets the e_sp value of the MZ header.
124 void setSpValue(word wValue); // EXPORT 124 void setSpValue(word wValue); // EXPORT
125 /// Sets the e_csum value of the MZ header. 125 /// Sets the e_csum value of the MZ header.
126 void setChecksum(word wValue); // EXPORT 126 void setChecksum(word wValue); // EXPORT
127 /// Sets the e_ip value of the MZ header. 127 /// Sets the e_ip value of the MZ header.
128 void setIpValue(word wValue); // EXPORT 128 void setIpValue(word wValue); // EXPORT
129 /// Sets the e_cs value of the MZ header. 129 /// Sets the e_cs value of the MZ header.
130 void setCsValue(word wValue); // EXPORT 130 void setCsValue(word wValue); // EXPORT
131 /// Sets the e_lfarlc value of the MZ header. 131 /// Sets the e_lfarlc value of the MZ header.
132 void setAddrOfRelocationTable(word wValue); // EXPORT 132 void setAddrOfRelocationTable(word wValue); // EXPORT
133 /// Sets the e_ovno value of the MZ header. 133 /// Sets the e_ovno value of the MZ header.
134 void setOverlayNumber(word wValue); // EXPORT 134 void setOverlayNumber(word wValue); // EXPORT
135 /// Sets the e_oemid value of the MZ header. 135 /// Sets the e_oemid value of the MZ header.
136 void setOemIdentifier(word wValue); // EXPORT 136 void setOemIdentifier(word wValue); // EXPORT
137 /// Sets the e_oeminfo value of the MZ header. 137 /// Sets the e_oeminfo value of the MZ header.
138 void setOemInformation(word wValue); // EXPORT 138 void setOemInformation(word wValue); // EXPORT
139 /// Sets the e_lfanew value of the MZ header. 139 /// Sets the e_lfanew value of the MZ header.
140 void setAddressOfPeHeader(dword dwValue); // EXPORT 140 void setAddressOfPeHeader(dword dwValue); // EXPORT
141 /// Sets the e_res value of the MZ header. 141 /// Sets the e_res value of the MZ header.
142 void setReservedWords1(unsigned int uiNr, word wValue); // EXPORT 142 void setReservedWords1(unsigned int uiNr, word wValue); // EXPORT
143 /// Sets the e_res2 value of the MZ header. 143 /// Sets the e_res2 value of the MZ header.
144 void setReservedWords2(unsigned int uiNr, word wValue); // EXPORT 144 void setReservedWords2(unsigned int uiNr, word wValue); // EXPORT
145 }; 145 };
146} 146}
147 147
148#endif 148#endif
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/PeFile.cpp b/utils/zenutils/libraries/pelib-0.9/pelib/PeFile.cpp
index 39f2488b81..9e9f2d8691 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/PeFile.cpp
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/PeFile.cpp
@@ -1,169 +1,169 @@
1/* 1/*
2* PeLib.cpp - Part of the PeLib library. 2* PeLib.cpp - Part of the PeLib library.
3* 3*
4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) 4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5* All rights reserved. 5* All rights reserved.
6* 6*
7* This software is licensed under the zlib/libpng License. 7* This software is licensed under the zlib/libpng License.
8* For more details see http://www.opensource.org/licenses/zlib-license.php 8* For more details see http://www.opensource.org/licenses/zlib-license.php
9* or the license information file (license.htm) in the root directory 9* or the license information file (license.htm) in the root directory
10* of PeLib. 10* of PeLib.
11*/ 11*/
12 12
13#include "PeFile.h" 13#include "PeFile.h"
14 14
15namespace PeLib 15namespace PeLib
16{ 16{
17 PeFile::~PeFile() 17 PeFile::~PeFile()
18 { 18 {
19 } 19 }
20 20
21 PeFile32::PeFile32() : PeFileT<32>() 21 PeFile32::PeFile32() : PeFileT<32>()
22 { 22 {
23 } 23 }
24 24
25 PeFile32::PeFile32(const std::string& strFlename) : PeFileT<32>(strFlename) 25 PeFile32::PeFile32(const std::string& strFlename) : PeFileT<32>(strFlename)
26 { 26 {
27 } 27 }
28 28
29 PeFile64::PeFile64() : PeFileT<64>() 29 PeFile64::PeFile64() : PeFileT<64>()
30 { 30 {
31 } 31 }
32 32
33 PeFile64::PeFile64(const std::string& strFlename) : PeFileT<64>(strFlename) 33 PeFile64::PeFile64(const std::string& strFlename) : PeFileT<64>(strFlename)
34 { 34 {
35 } 35 }
36 36
37 /** 37 /**
38 * @return A reference to the file's MZ header. 38 * @return A reference to the file's MZ header.
39 **/ 39 **/
40 40
41 const MzHeader& PeFile::mzHeader() const 41 const MzHeader& PeFile::mzHeader() const
42 { 42 {
43 return m_mzh; 43 return m_mzh;
44 } 44 }
45 45
46 /** 46 /**
47 * @return A reference to the file's MZ header. 47 * @return A reference to the file's MZ header.
48 **/ 48 **/
49 49
50 MzHeader& PeFile::mzHeader() 50 MzHeader& PeFile::mzHeader()
51 { 51 {
52 return m_mzh; 52 return m_mzh;
53 } 53 }
54 54
55 /** 55 /**
56 * @return A reference to the file's export directory. 56 * @return A reference to the file's export directory.
57 **/ 57 **/
58 58
59 const ExportDirectory& PeFile::expDir() const 59 const ExportDirectory& PeFile::expDir() const
60 { 60 {
61 return m_expdir; 61 return m_expdir;
62 } 62 }
63 63
64 /** 64 /**
65 * @return A reference to the file's export directory. 65 * @return A reference to the file's export directory.
66 **/ 66 **/
67 67
68 ExportDirectory& PeFile::expDir() 68 ExportDirectory& PeFile::expDir()
69 { 69 {
70 return m_expdir; 70 return m_expdir;
71 } 71 }
72 72
73 /** 73 /**
74 * @return A reference to the file's bound import directory. 74 * @return A reference to the file's bound import directory.
75 **/ 75 **/
76 76
77 const BoundImportDirectory& PeFile::boundImpDir() const 77 const BoundImportDirectory& PeFile::boundImpDir() const
78 { 78 {
79 return m_boundimpdir; 79 return m_boundimpdir;
80 } 80 }
81 81
82 /** 82 /**
83 * @return A reference to the file's bound import directory. 83 * @return A reference to the file's bound import directory.
84 **/ 84 **/
85 85
86 BoundImportDirectory& PeFile::boundImpDir() 86 BoundImportDirectory& PeFile::boundImpDir()
87 { 87 {
88 return m_boundimpdir; 88 return m_boundimpdir;
89 } 89 }
90 90
91 /** 91 /**
92 * @return A reference to the file's resource directory. 92 * @return A reference to the file's resource directory.
93 **/ 93 **/
94 94
95 const ResourceDirectory& PeFile::resDir() const 95 const ResourceDirectory& PeFile::resDir() const
96 { 96 {
97 return m_resdir; 97 return m_resdir;
98 } 98 }
99 99
100 /** 100 /**
101 * @return A reference to the file's resource directory. 101 * @return A reference to the file's resource directory.
102 **/ 102 **/
103 103
104 ResourceDirectory& PeFile::resDir() 104 ResourceDirectory& PeFile::resDir()
105 { 105 {
106 return m_resdir; 106 return m_resdir;
107 } 107 }
108 108
109 /** 109 /**
110 * @return A reference to the file's relocations directory. 110 * @return A reference to the file's relocations directory.
111 **/ 111 **/
112 112
113 const RelocationsDirectory& PeFile::relocDir() const 113 const RelocationsDirectory& PeFile::relocDir() const
114 { 114 {
115 return m_relocs; 115 return m_relocs;
116 } 116 }
117 117
118 /** 118 /**
119 * @return A reference to the file's relocations directory. 119 * @return A reference to the file's relocations directory.
120 **/ 120 **/
121 121
122 RelocationsDirectory& PeFile::relocDir() 122 RelocationsDirectory& PeFile::relocDir()
123 { 123 {
124 return m_relocs; 124 return m_relocs;
125 } 125 }
126 126
127 /** 127 /**
128 * @return A reference to the file's COM+ descriptor directory. 128 * @return A reference to the file's COM+ descriptor directory.
129 **/ 129 **/
130 130
131 const ComHeaderDirectory& PeFile::comDir() const 131 const ComHeaderDirectory& PeFile::comDir() const
132 { 132 {
133 return m_comdesc; 133 return m_comdesc;
134 } 134 }
135 135
136 /** 136 /**
137 * @return A reference to the file's COM+ descriptor directory. 137 * @return A reference to the file's COM+ descriptor directory.
138 **/ 138 **/
139 139
140 ComHeaderDirectory & PeFile::comDir() 140 ComHeaderDirectory & PeFile::comDir()
141 { 141 {
142 return m_comdesc; 142 return m_comdesc;
143 } 143 }
144 144
145 145
146 const IatDirectory& PeFile::iatDir() const 146 const IatDirectory& PeFile::iatDir() const
147 { 147 {
148 return m_iat; 148 return m_iat;
149 } 149 }
150 150
151 151
152 IatDirectory& PeFile::iatDir() 152 IatDirectory& PeFile::iatDir()
153 { 153 {
154 return m_iat; 154 return m_iat;
155 } 155 }
156 156
157 157
158 const DebugDirectory& PeFile::debugDir() const 158 const DebugDirectory& PeFile::debugDir() const
159 { 159 {
160 return m_debugdir; 160 return m_debugdir;
161 } 161 }
162 162
163 163
164 DebugDirectory& PeFile::debugDir() 164 DebugDirectory& PeFile::debugDir()
165 { 165 {
166 return m_debugdir; 166 return m_debugdir;
167 } 167 }
168 168
169} 169}
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/PeFile.h b/utils/zenutils/libraries/pelib-0.9/pelib/PeFile.h
index a2b02cdfa8..e08d8da309 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/PeFile.h
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/PeFile.h
@@ -1,451 +1,451 @@
1/* 1/*
2* PeFile.h - Part of the PeLib library. 2* PeFile.h - Part of the PeLib library.
3* 3*
4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) 4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5* All rights reserved. 5* All rights reserved.
6* 6*
7* This software is licensed under the zlib/libpng License. 7* This software is licensed under the zlib/libpng License.
8* For more details see http://www.opensource.org/licenses/zlib-license.php 8* For more details see http://www.opensource.org/licenses/zlib-license.php
9* or the license information file (license.htm) in the root directory 9* or the license information file (license.htm) in the root directory
10* of PeLib. 10* of PeLib.
11*/ 11*/
12 12
13#ifndef PEFILE_H 13#ifndef PEFILE_H
14#define PEFILE_H 14#define PEFILE_H
15 15
16#include "PeLibInc.h" 16#include "PeLibInc.h"
17#include "MzHeader.h" 17#include "MzHeader.h"
18#include "PeHeader.h" 18#include "PeHeader.h"
19#include "ImportDirectory.h" 19#include "ImportDirectory.h"
20#include "ExportDirectory.h" 20#include "ExportDirectory.h"
21#include "BoundImportDirectory.h" 21#include "BoundImportDirectory.h"
22#include "ResourceDirectory.h" 22#include "ResourceDirectory.h"
23#include "RelocationsDirectory.h" 23#include "RelocationsDirectory.h"
24#include "ComHeaderDirectory.h" 24#include "ComHeaderDirectory.h"
25#include "IatDirectory.h" 25#include "IatDirectory.h"
26#include "DebugDirectory.h" 26#include "DebugDirectory.h"
27#include "TlsDirectory.h" 27#include "TlsDirectory.h"
28 28
29namespace PeLib 29namespace PeLib
30{ 30{
31 class PeFile32; 31 class PeFile32;
32 class PeFile64; 32 class PeFile64;
33 33
34 /** 34 /**
35 * Visitor base class for PeFiles. 35 * Visitor base class for PeFiles.
36 **/ 36 **/
37 class PeFileVisitor 37 class PeFileVisitor
38 { 38 {
39 public: 39 public:
40 virtual void callback(PeFile32 &file){} 40 virtual void callback(PeFile32 &file){}
41 virtual void callback(PeFile64 &file){} 41 virtual void callback(PeFile64 &file){}
42 virtual ~PeFileVisitor(){} 42 virtual ~PeFileVisitor(){}
43 }; 43 };
44 44
45 /** 45 /**
46 * Traits class that's used to decide of what type the PeHeader in a PeFile is. 46 * Traits class that's used to decide of what type the PeHeader in a PeFile is.
47 **/ 47 **/
48 template<int> 48 template<int>
49 struct PeFile_Traits; 49 struct PeFile_Traits;
50 50
51 template<> 51 template<>
52 struct PeFile_Traits<32> 52 struct PeFile_Traits<32>
53 { 53 {
54 typedef PeHeader32 PeHeader32_64; 54 typedef PeHeader32 PeHeader32_64;
55 }; 55 };
56 56
57 template<> 57 template<>
58 struct PeFile_Traits<64> 58 struct PeFile_Traits<64>
59 { 59 {
60 typedef PeHeader64 PeHeader32_64; 60 typedef PeHeader64 PeHeader32_64;
61 }; 61 };
62 62
63 /** 63 /**
64 * This class represents the common structures of PE and PE+ files. 64 * This class represents the common structures of PE and PE+ files.
65 **/ 65 **/
66 class PeFile 66 class PeFile
67 { 67 {
68 protected: 68 protected:
69 std::string m_filename; ///< Name of the current file. 69 std::string m_filename; ///< Name of the current file.
70 MzHeader m_mzh; ///< MZ header of the current file. 70 MzHeader m_mzh; ///< MZ header of the current file.
71 ExportDirectory m_expdir; ///< Export directory of the current file. 71 ExportDirectory m_expdir; ///< Export directory of the current file.
72 BoundImportDirectory m_boundimpdir; ///< BoundImportDirectory of the current file. 72 BoundImportDirectory m_boundimpdir; ///< BoundImportDirectory of the current file.
73 ResourceDirectory m_resdir; ///< ResourceDirectory of the current file. 73 ResourceDirectory m_resdir; ///< ResourceDirectory of the current file.
74 RelocationsDirectory m_relocs; ///< Relocations directory of the current file. 74 RelocationsDirectory m_relocs; ///< Relocations directory of the current file.
75 ComHeaderDirectory m_comdesc; ///< COM+ descriptor directory of the current file. 75 ComHeaderDirectory m_comdesc; ///< COM+ descriptor directory of the current file.
76 IatDirectory m_iat; ///< Import address table of the current file. 76 IatDirectory m_iat; ///< Import address table of the current file.
77 DebugDirectory m_debugdir; 77 DebugDirectory m_debugdir;
78 public: 78 public:
79 virtual ~PeFile(); 79 virtual ~PeFile();
80 80
81 /// Returns the name of the current file. 81 /// Returns the name of the current file.
82 virtual std::string getFileName() const = 0; // EXPORT 82 virtual std::string getFileName() const = 0; // EXPORT
83 /// Changes the name of the current file. 83 /// Changes the name of the current file.
84 virtual void setFileName(std::string strFilename) = 0; // EXPORT 84 virtual void setFileName(std::string strFilename) = 0; // EXPORT
85 85
86 virtual void visit(PeFileVisitor &v) = 0; 86 virtual void visit(PeFileVisitor &v) = 0;
87 87
88 /// Reads the MZ header of the current file from disc. 88 /// Reads the MZ header of the current file from disc.
89 virtual int readMzHeader() = 0; // EXPORT 89 virtual int readMzHeader() = 0; // EXPORT
90 /// Reads the export directory of the current file from disc. 90 /// Reads the export directory of the current file from disc.
91 virtual int readExportDirectory() = 0; // EXPORT 91 virtual int readExportDirectory() = 0; // EXPORT
92 /// Reads the PE header of the current file from disc. 92 /// Reads the PE header of the current file from disc.
93 virtual int readPeHeader() = 0; // EXPORT 93 virtual int readPeHeader() = 0; // EXPORT
94 /// Reads the import directory of the current file from disc. 94 /// Reads the import directory of the current file from disc.
95 virtual int readImportDirectory() = 0; // EXPORT 95 virtual int readImportDirectory() = 0; // EXPORT
96 /// Reads the bound import directory of the current file from disc. 96 /// Reads the bound import directory of the current file from disc.
97 virtual int readBoundImportDirectory() = 0; // EXPORT 97 virtual int readBoundImportDirectory() = 0; // EXPORT
98 /// Reads the resource directory of the current file from disc. 98 /// Reads the resource directory of the current file from disc.
99 virtual int readResourceDirectory() = 0; // EXPORT 99 virtual int readResourceDirectory() = 0; // EXPORT
100 /// Reads the relocations directory of the current file from disc. 100 /// Reads the relocations directory of the current file from disc.
101 virtual int readRelocationsDirectory() = 0; // EXPORT 101 virtual int readRelocationsDirectory() = 0; // EXPORT
102 /// Reads the COM+ descriptor directory of the current file from disc. 102 /// Reads the COM+ descriptor directory of the current file from disc.
103 virtual int readComHeaderDirectory() = 0; // EXPORT 103 virtual int readComHeaderDirectory() = 0; // EXPORT
104 /// Reads the IAT directory of the current file from disc. 104 /// Reads the IAT directory of the current file from disc.
105 virtual int readIatDirectory() = 0; // EXPORT 105 virtual int readIatDirectory() = 0; // EXPORT
106 /// Reads the Debug directory of the current file. 106 /// Reads the Debug directory of the current file.
107 virtual int readDebugDirectory() = 0; // EXPORT 107 virtual int readDebugDirectory() = 0; // EXPORT
108 virtual int readTlsDirectory() = 0; // EXPORT 108 virtual int readTlsDirectory() = 0; // EXPORT
109 109
110 virtual unsigned int getBits() const = 0; 110 virtual unsigned int getBits() const = 0;
111 111
112 /// Accessor function for the MZ header. 112 /// Accessor function for the MZ header.
113 const MzHeader& mzHeader() const; 113 const MzHeader& mzHeader() const;
114 /// Accessor function for the MZ header. 114 /// Accessor function for the MZ header.
115 MzHeader& mzHeader(); // EXPORT 115 MzHeader& mzHeader(); // EXPORT
116 116
117 /// Accessor function for the export directory. 117 /// Accessor function for the export directory.
118 const ExportDirectory& expDir() const; 118 const ExportDirectory& expDir() const;
119 /// Accessor function for the export directory. 119 /// Accessor function for the export directory.
120 ExportDirectory& expDir(); // EXPORT 120 ExportDirectory& expDir(); // EXPORT
121 121
122 /// Accessor function for the bound import directory. 122 /// Accessor function for the bound import directory.
123 const BoundImportDirectory& boundImpDir() const; 123 const BoundImportDirectory& boundImpDir() const;
124 /// Accessor function for the bound import directory. 124 /// Accessor function for the bound import directory.
125 BoundImportDirectory& boundImpDir(); // EXPORT 125 BoundImportDirectory& boundImpDir(); // EXPORT
126 126
127 /// Accessor function for the resource directory. 127 /// Accessor function for the resource directory.
128 const ResourceDirectory& resDir() const; 128 const ResourceDirectory& resDir() const;
129 /// Accessor function for the resource directory. 129 /// Accessor function for the resource directory.
130 ResourceDirectory& resDir(); // EXPORT 130 ResourceDirectory& resDir(); // EXPORT
131 131
132 /// Accessor function for the relocations directory. 132 /// Accessor function for the relocations directory.
133 const RelocationsDirectory& relocDir() const; 133 const RelocationsDirectory& relocDir() const;
134 /// Accessor function for the relocations directory. 134 /// Accessor function for the relocations directory.
135 RelocationsDirectory& relocDir(); // EXPORT 135 RelocationsDirectory& relocDir(); // EXPORT
136 136
137 /// Accessor function for the COM+ descriptor directory. 137 /// Accessor function for the COM+ descriptor directory.
138 const ComHeaderDirectory& comDir() const; 138 const ComHeaderDirectory& comDir() const;
139 /// Accessor function for the COM+ descriptor directory. 139 /// Accessor function for the COM+ descriptor directory.
140 ComHeaderDirectory& comDir(); // EXPORT 140 ComHeaderDirectory& comDir(); // EXPORT
141 141
142 /// Accessor function for the IAT directory. 142 /// Accessor function for the IAT directory.
143 const IatDirectory& iatDir() const; 143 const IatDirectory& iatDir() const;
144 /// Accessor function for the IAT directory. 144 /// Accessor function for the IAT directory.
145 IatDirectory& iatDir(); // EXPORT 145 IatDirectory& iatDir(); // EXPORT
146 146
147 /// Accessor function for the debug directory. 147 /// Accessor function for the debug directory.
148 const DebugDirectory& debugDir() const; 148 const DebugDirectory& debugDir() const;
149 /// Accessor function for the debug directory. 149 /// Accessor function for the debug directory.
150 DebugDirectory& debugDir(); // EXPORT 150 DebugDirectory& debugDir(); // EXPORT
151 151
152 }; 152 };
153 153
154 /** 154 /**
155 * This class implements the common structures of PE and PE+ files. 155 * This class implements the common structures of PE and PE+ files.
156 **/ 156 **/
157 template<int bits> 157 template<int bits>
158 class PeFileT : public PeFile 158 class PeFileT : public PeFile
159 { 159 {
160 typedef typename PeFile_Traits<bits>::PeHeader32_64 PeHeader32_64; 160 typedef typename PeFile_Traits<bits>::PeHeader32_64 PeHeader32_64;
161 161
162 private: 162 private:
163 PeHeader32_64 m_peh; ///< PE header of the current file. 163 PeHeader32_64 m_peh; ///< PE header of the current file.
164 ImportDirectory<bits> m_impdir; ///< Import directory of the current file. 164 ImportDirectory<bits> m_impdir; ///< Import directory of the current file.
165 TlsDirectory<bits> m_tlsdir; 165 TlsDirectory<bits> m_tlsdir;
166 166
167 public: 167 public:
168 /// Default constructor which exists only for the sake of allowing to construct files without filenames. 168 /// Default constructor which exists only for the sake of allowing to construct files without filenames.
169 PeFileT(); 169 PeFileT();
170 170
171 virtual ~PeFileT() {} 171 virtual ~PeFileT() {}
172 172
173 /// Initializes a PeFile with a filename 173 /// Initializes a PeFile with a filename
174 explicit PeFileT(const std::string& strFilename); 174 explicit PeFileT(const std::string& strFilename);
175 175
176 /// Returns the name of the current file. 176 /// Returns the name of the current file.
177 std::string getFileName() const; 177 std::string getFileName() const;
178 /// Changes the name of the current file. 178 /// Changes the name of the current file.
179 void setFileName(std::string strFilename); 179 void setFileName(std::string strFilename);
180 180
181 /// Reads the MZ header of the current file from disc. 181 /// Reads the MZ header of the current file from disc.
182 int readMzHeader() ; 182 int readMzHeader() ;
183 /// Reads the export directory of the current file from disc. 183 /// Reads the export directory of the current file from disc.
184 int readExportDirectory() ; 184 int readExportDirectory() ;
185 /// Reads the PE header of the current file from disc. 185 /// Reads the PE header of the current file from disc.
186 int readPeHeader() ; 186 int readPeHeader() ;
187 /// Reads the import directory of the current file from disc. 187 /// Reads the import directory of the current file from disc.
188 int readImportDirectory() ; 188 int readImportDirectory() ;
189 /// Reads the bound import directory of the current file from disc. 189 /// Reads the bound import directory of the current file from disc.
190 int readBoundImportDirectory() ; 190 int readBoundImportDirectory() ;
191 /// Reads the resource directory of the current file from disc. 191 /// Reads the resource directory of the current file from disc.
192 int readResourceDirectory() ; 192 int readResourceDirectory() ;
193 /// Reads the relocations directory of the current file from disc. 193 /// Reads the relocations directory of the current file from disc.
194 int readRelocationsDirectory() ; 194 int readRelocationsDirectory() ;
195 /// Reads the COM+ descriptor directory of the current file from disc. 195 /// Reads the COM+ descriptor directory of the current file from disc.
196 int readComHeaderDirectory() ; 196 int readComHeaderDirectory() ;
197 /// Reads the IAT directory of the current file from disc. 197 /// Reads the IAT directory of the current file from disc.
198 int readIatDirectory() ; 198 int readIatDirectory() ;
199 /// Reads the Debug directory of the current file. 199 /// Reads the Debug directory of the current file.
200 int readDebugDirectory() ; 200 int readDebugDirectory() ;
201 int readTlsDirectory() ; 201 int readTlsDirectory() ;
202 202
203 unsigned int getBits() const 203 unsigned int getBits() const
204 { 204 {
205 return bits; 205 return bits;
206 } 206 }
207 207
208 /// Accessor function for the PE header. 208 /// Accessor function for the PE header.
209 const PeHeader32_64& peHeader() const; 209 const PeHeader32_64& peHeader() const;
210 /// Accessor function for the PE header. 210 /// Accessor function for the PE header.
211 PeHeader32_64& peHeader(); 211 PeHeader32_64& peHeader();
212 212
213 /// Accessor function for the import directory. 213 /// Accessor function for the import directory.
214 const ImportDirectory<bits>& impDir() const; 214 const ImportDirectory<bits>& impDir() const;
215 /// Accessor function for the import directory. 215 /// Accessor function for the import directory.
216 ImportDirectory<bits>& impDir(); 216 ImportDirectory<bits>& impDir();
217 217
218 const TlsDirectory<bits>& tlsDir() const; 218 const TlsDirectory<bits>& tlsDir() const;
219 TlsDirectory<bits>& tlsDir(); 219 TlsDirectory<bits>& tlsDir();
220 }; 220 };
221 221
222 /** 222 /**
223 * This class is the main class for handling PE files. 223 * This class is the main class for handling PE files.
224 **/ 224 **/
225 class PeFile32 : public PeFileT<32> 225 class PeFile32 : public PeFileT<32>
226 { 226 {
227 public: 227 public:
228 /// Default constructor which exists only for the sake of allowing to construct files without filenames. 228 /// Default constructor which exists only for the sake of allowing to construct files without filenames.
229 PeFile32(); 229 PeFile32();
230 230
231 /// Initializes a PeFile with a filename 231 /// Initializes a PeFile with a filename
232 explicit PeFile32(const std::string& strFlename); 232 explicit PeFile32(const std::string& strFlename);
233 virtual void visit(PeFileVisitor &v) { v.callback( *this ); } 233 virtual void visit(PeFileVisitor &v) { v.callback( *this ); }
234 }; 234 };
235 235
236 /** 236 /**
237 * This class is the main class for handling PE+ files. 237 * This class is the main class for handling PE+ files.
238 **/ 238 **/
239 class PeFile64 : public PeFileT<64> 239 class PeFile64 : public PeFileT<64>
240 { 240 {
241 public: 241 public:
242 /// Default constructor which exists only for the sake of allowing to construct files without filenames. 242 /// Default constructor which exists only for the sake of allowing to construct files without filenames.
243 PeFile64(); 243 PeFile64();
244 244
245 /// Initializes a PeFile with a filename 245 /// Initializes a PeFile with a filename
246 explicit PeFile64(const std::string& strFlename); 246 explicit PeFile64(const std::string& strFlename);
247 virtual void visit(PeFileVisitor &v) { v.callback( *this ); } 247 virtual void visit(PeFileVisitor &v) { v.callback( *this ); }
248 }; 248 };
249 249
250 //typedef PeFileT<32> PeFile32; 250 //typedef PeFileT<32> PeFile32;
251 //typedef PeFileT<64> PeFile64; 251 //typedef PeFileT<64> PeFile64;
252 252
253 /** 253 /**
254 * @param strFilename Name of the current file. 254 * @param strFilename Name of the current file.
255 **/ 255 **/
256 template<int bits> 256 template<int bits>
257 PeFileT<bits>::PeFileT(const std::string& strFilename) 257 PeFileT<bits>::PeFileT(const std::string& strFilename)
258 { 258 {
259 m_filename = strFilename; 259 m_filename = strFilename;
260 } 260 }
261 261
262 template<int bits> 262 template<int bits>
263 PeFileT<bits>::PeFileT() 263 PeFileT<bits>::PeFileT()
264 { 264 {
265 } 265 }
266 266
267 template<int bits> 267 template<int bits>
268 int PeFileT<bits>::readPeHeader() 268 int PeFileT<bits>::readPeHeader()
269 { 269 {
270 return peHeader().read(getFileName(), mzHeader().getAddressOfPeHeader()); 270 return peHeader().read(getFileName(), mzHeader().getAddressOfPeHeader());
271 } 271 }
272 272
273 273
274 template<int bits> 274 template<int bits>
275 int PeFileT<bits>::readImportDirectory() 275 int PeFileT<bits>::readImportDirectory()
276 { 276 {
277 if (peHeader().calcNumberOfRvaAndSizes() >= 2 277 if (peHeader().calcNumberOfRvaAndSizes() >= 2
278 && peHeader().getIddImportRva() 278 && peHeader().getIddImportRva()
279 && peHeader().getIddImportSize()) 279 && peHeader().getIddImportSize())
280 { 280 {
281 return impDir().read(getFileName(), static_cast<unsigned int>(peHeader().rvaToOffset(peHeader().getIddImportRva())), peHeader().getIddImportSize(), peHeader()); 281 return impDir().read(getFileName(), static_cast<unsigned int>(peHeader().rvaToOffset(peHeader().getIddImportRva())), peHeader().getIddImportSize(), peHeader());
282 } 282 }
283 return ERROR_DIRECTORY_DOES_NOT_EXIST; 283 return ERROR_DIRECTORY_DOES_NOT_EXIST;
284 } 284 }
285 285
286 /** 286 /**
287 * @return A reference to the file's PE header. 287 * @return A reference to the file's PE header.
288 **/ 288 **/
289 template<int bits> 289 template<int bits>
290 const typename PeFile_Traits<bits>::PeHeader32_64& PeFileT<bits>::peHeader() const 290 const typename PeFile_Traits<bits>::PeHeader32_64& PeFileT<bits>::peHeader() const
291 { 291 {
292 return m_peh; 292 return m_peh;
293 } 293 }
294 294
295 /** 295 /**
296 * @return A reference to the file's PE header. 296 * @return A reference to the file's PE header.
297 **/ 297 **/
298 template<int bits> 298 template<int bits>
299 typename PeFile_Traits<bits>::PeHeader32_64& PeFileT<bits>::peHeader() 299 typename PeFile_Traits<bits>::PeHeader32_64& PeFileT<bits>::peHeader()
300 { 300 {
301 return m_peh; 301 return m_peh;
302 } 302 }
303 303
304 /** 304 /**
305 * @return A reference to the file's import directory. 305 * @return A reference to the file's import directory.
306 **/ 306 **/
307 template<int bits> 307 template<int bits>
308 const ImportDirectory<bits>& PeFileT<bits>::impDir() const 308 const ImportDirectory<bits>& PeFileT<bits>::impDir() const
309 { 309 {
310 return m_impdir; 310 return m_impdir;
311 } 311 }
312 312
313 /** 313 /**
314 * @return A reference to the file's import directory. 314 * @return A reference to the file's import directory.
315 **/ 315 **/
316 template<int bits> 316 template<int bits>
317 ImportDirectory<bits>& PeFileT<bits>::impDir() 317 ImportDirectory<bits>& PeFileT<bits>::impDir()
318 { 318 {
319 return m_impdir; 319 return m_impdir;
320 } 320 }
321 321
322 template<int bits> 322 template<int bits>
323 const TlsDirectory<bits>& PeFileT<bits>::tlsDir() const 323 const TlsDirectory<bits>& PeFileT<bits>::tlsDir() const
324 { 324 {
325 return m_tlsdir; 325 return m_tlsdir;
326 } 326 }
327 327
328 template<int bits> 328 template<int bits>
329 TlsDirectory<bits>& PeFileT<bits>::tlsDir() 329 TlsDirectory<bits>& PeFileT<bits>::tlsDir()
330 { 330 {
331 return m_tlsdir; 331 return m_tlsdir;
332 } 332 }
333 333
334 /** 334 /**
335 * @return Filename of the current file. 335 * @return Filename of the current file.
336 **/ 336 **/
337 template<int bits> 337 template<int bits>
338 std::string PeFileT<bits>::getFileName() const 338 std::string PeFileT<bits>::getFileName() const
339 { 339 {
340 return m_filename; 340 return m_filename;
341 } 341 }
342 342
343 /** 343 /**
344 * @param strFilename New filename. 344 * @param strFilename New filename.
345 **/ 345 **/
346 template<int bits> 346 template<int bits>
347 void PeFileT<bits>::setFileName(std::string strFilename) 347 void PeFileT<bits>::setFileName(std::string strFilename)
348 { 348 {
349 m_filename = strFilename; 349 m_filename = strFilename;
350 } 350 }
351 351
352 template<int bits> 352 template<int bits>
353 int PeFileT<bits>::readMzHeader() 353 int PeFileT<bits>::readMzHeader()
354 { 354 {
355 return mzHeader().read(getFileName()); 355 return mzHeader().read(getFileName());
356 } 356 }
357 357
358 template<int bits> 358 template<int bits>
359 int PeFileT<bits>::readExportDirectory() 359 int PeFileT<bits>::readExportDirectory()
360 { 360 {
361 if (peHeader().calcNumberOfRvaAndSizes() >= 1 361 if (peHeader().calcNumberOfRvaAndSizes() >= 1
362 && peHeader().getIddExportRva() && peHeader().getIddExportSize()) 362 && peHeader().getIddExportRva() && peHeader().getIddExportSize())
363 { 363 {
364 return expDir().read(getFileName(), static_cast<unsigned int>(peHeader().rvaToOffset(peHeader().getIddExportRva())), peHeader().getIddExportSize(), peHeader()); 364 return expDir().read(getFileName(), static_cast<unsigned int>(peHeader().rvaToOffset(peHeader().getIddExportRva())), peHeader().getIddExportSize(), peHeader());
365 } 365 }
366 return ERROR_DIRECTORY_DOES_NOT_EXIST; 366 return ERROR_DIRECTORY_DOES_NOT_EXIST;
367 } 367 }
368 368
369 369
370 template<int bits> 370 template<int bits>
371 int PeFileT<bits>::readBoundImportDirectory() 371 int PeFileT<bits>::readBoundImportDirectory()
372 { 372 {
373 if (peHeader().calcNumberOfRvaAndSizes() >= 12 373 if (peHeader().calcNumberOfRvaAndSizes() >= 12
374 && peHeader().getIddBoundImportRva() && peHeader().getIddBoundImportSize()) 374 && peHeader().getIddBoundImportRva() && peHeader().getIddBoundImportSize())
375 { 375 {
376 return boundImpDir().read(getFileName(), static_cast<unsigned int>(peHeader().rvaToOffset(peHeader().getIddBoundImportRva())), peHeader().getIddBoundImportSize()); 376 return boundImpDir().read(getFileName(), static_cast<unsigned int>(peHeader().rvaToOffset(peHeader().getIddBoundImportRva())), peHeader().getIddBoundImportSize());
377 } 377 }
378 return ERROR_DIRECTORY_DOES_NOT_EXIST; 378 return ERROR_DIRECTORY_DOES_NOT_EXIST;
379 } 379 }
380 380
381 template<int bits> 381 template<int bits>
382 int PeFileT<bits>::readResourceDirectory() 382 int PeFileT<bits>::readResourceDirectory()
383 { 383 {
384 if (peHeader().calcNumberOfRvaAndSizes() >= 3 384 if (peHeader().calcNumberOfRvaAndSizes() >= 3
385 && peHeader().getIddResourceRva() && peHeader().getIddResourceSize()) 385 && peHeader().getIddResourceRva() && peHeader().getIddResourceSize())
386 { 386 {
387 return resDir().read(getFileName(), static_cast<unsigned int>(peHeader().rvaToOffset(peHeader().getIddResourceRva())), peHeader().getIddResourceSize(), peHeader().getIddResourceRva()); 387 return resDir().read(getFileName(), static_cast<unsigned int>(peHeader().rvaToOffset(peHeader().getIddResourceRva())), peHeader().getIddResourceSize(), peHeader().getIddResourceRva());
388 } 388 }
389 return ERROR_DIRECTORY_DOES_NOT_EXIST; 389 return ERROR_DIRECTORY_DOES_NOT_EXIST;
390 } 390 }
391 391
392 template<int bits> 392 template<int bits>
393 int PeFileT<bits>::readRelocationsDirectory() 393 int PeFileT<bits>::readRelocationsDirectory()
394 { 394 {
395 if (peHeader().calcNumberOfRvaAndSizes() >= 6 395 if (peHeader().calcNumberOfRvaAndSizes() >= 6
396 && peHeader().getIddBaseRelocRva() && peHeader().getIddBaseRelocSize()) 396 && peHeader().getIddBaseRelocRva() && peHeader().getIddBaseRelocSize())
397 { 397 {
398 return relocDir().read(getFileName(), static_cast<unsigned int>(peHeader().rvaToOffset(peHeader().getIddBaseRelocRva())), peHeader().getIddBaseRelocSize()); 398 return relocDir().read(getFileName(), static_cast<unsigned int>(peHeader().rvaToOffset(peHeader().getIddBaseRelocRva())), peHeader().getIddBaseRelocSize());
399 } 399 }
400 return ERROR_DIRECTORY_DOES_NOT_EXIST; 400 return ERROR_DIRECTORY_DOES_NOT_EXIST;
401 } 401 }
402 402
403 template<int bits> 403 template<int bits>
404 int PeFileT<bits>::readComHeaderDirectory() 404 int PeFileT<bits>::readComHeaderDirectory()
405 { 405 {
406 if (peHeader().calcNumberOfRvaAndSizes() >= 15 406 if (peHeader().calcNumberOfRvaAndSizes() >= 15
407 && peHeader().getIddComHeaderRva() && peHeader().getIddComHeaderSize()) 407 && peHeader().getIddComHeaderRva() && peHeader().getIddComHeaderSize())
408 { 408 {
409 return comDir().read(getFileName(), static_cast<unsigned int>(peHeader().rvaToOffset(peHeader().getIddComHeaderRva())), peHeader().getIddComHeaderSize()); 409 return comDir().read(getFileName(), static_cast<unsigned int>(peHeader().rvaToOffset(peHeader().getIddComHeaderRva())), peHeader().getIddComHeaderSize());
410 } 410 }
411 std::cout << peHeader().getIddComHeaderRva() << std::endl; 411 std::cout << peHeader().getIddComHeaderRva() << std::endl;
412 std::exit(0); 412 std::exit(0);
413 return ERROR_DIRECTORY_DOES_NOT_EXIST; 413 return ERROR_DIRECTORY_DOES_NOT_EXIST;
414 } 414 }
415 415
416 template<int bits> 416 template<int bits>
417 int PeFileT<bits>::readIatDirectory() 417 int PeFileT<bits>::readIatDirectory()
418 { 418 {
419 if (peHeader().calcNumberOfRvaAndSizes() >= 13 419 if (peHeader().calcNumberOfRvaAndSizes() >= 13
420 && peHeader().getIddIatRva() && peHeader().getIddIatSize()) 420 && peHeader().getIddIatRva() && peHeader().getIddIatSize())
421 { 421 {
422 return iatDir().read(getFileName(), static_cast<unsigned int>(peHeader().rvaToOffset(peHeader().getIddIatRva())), peHeader().getIddIatSize()); 422 return iatDir().read(getFileName(), static_cast<unsigned int>(peHeader().rvaToOffset(peHeader().getIddIatRva())), peHeader().getIddIatSize());
423 } 423 }
424 return ERROR_DIRECTORY_DOES_NOT_EXIST; 424 return ERROR_DIRECTORY_DOES_NOT_EXIST;
425 } 425 }
426 426
427 template<int bits> 427 template<int bits>
428 int PeFileT<bits>::readDebugDirectory() 428 int PeFileT<bits>::readDebugDirectory()
429 { 429 {
430 if (peHeader().calcNumberOfRvaAndSizes() >= 7 430 if (peHeader().calcNumberOfRvaAndSizes() >= 7
431 && peHeader().getIddDebugRva() && peHeader().getIddDebugSize()) 431 && peHeader().getIddDebugRva() && peHeader().getIddDebugSize())
432 { 432 {
433 return debugDir().read(getFileName(), static_cast<unsigned int>(peHeader().rvaToOffset(peHeader().getIddDebugRva())), peHeader().getIddDebugSize()); 433 return debugDir().read(getFileName(), static_cast<unsigned int>(peHeader().rvaToOffset(peHeader().getIddDebugRva())), peHeader().getIddDebugSize());
434 } 434 }
435 return ERROR_DIRECTORY_DOES_NOT_EXIST; 435 return ERROR_DIRECTORY_DOES_NOT_EXIST;
436 } 436 }
437 437
438 template<int bits> 438 template<int bits>
439 int PeFileT<bits>::readTlsDirectory() 439 int PeFileT<bits>::readTlsDirectory()
440 { 440 {
441 if (peHeader().calcNumberOfRvaAndSizes() >= 10 441 if (peHeader().calcNumberOfRvaAndSizes() >= 10
442 && peHeader().getIddTlsRva() && peHeader().getIddTlsSize()) 442 && peHeader().getIddTlsRva() && peHeader().getIddTlsSize())
443 { 443 {
444 return tlsDir().read(getFileName(), static_cast<unsigned int>(peHeader().rvaToOffset(peHeader().getIddTlsRva())), peHeader().getIddTlsSize()); 444 return tlsDir().read(getFileName(), static_cast<unsigned int>(peHeader().rvaToOffset(peHeader().getIddTlsRva())), peHeader().getIddTlsSize());
445 } 445 }
446 return ERROR_DIRECTORY_DOES_NOT_EXIST; 446 return ERROR_DIRECTORY_DOES_NOT_EXIST;
447 } 447 }
448 448
449} 449}
450 450
451#endif 451#endif
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/PeHeader.cpp b/utils/zenutils/libraries/pelib-0.9/pelib/PeHeader.cpp
index fe7011072c..1199e6bdd1 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/PeHeader.cpp
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/PeHeader.cpp
@@ -1,90 +1,90 @@
1/* 1/*
2* PeHeader.cpp - Part of the PeLib library. 2* PeHeader.cpp - Part of the PeLib library.
3* 3*
4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) 4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5* All rights reserved. 5* All rights reserved.
6* 6*
7* This software is licensed under the zlib/libpng License. 7* This software is licensed under the zlib/libpng License.
8* For more details see http://www.opensource.org/licenses/zlib-license.php 8* For more details see http://www.opensource.org/licenses/zlib-license.php
9* or the license information file (license.htm) in the root directory 9* or the license information file (license.htm) in the root directory
10* of PeLib. 10* of PeLib.
11*/ 11*/
12 12
13#include "PeLibInc.h" 13#include "PeLibInc.h"
14#include "PeHeader.h" 14#include "PeHeader.h"
15 15
16namespace PeLib 16namespace PeLib
17{ 17{
18 template<> 18 template<>
19 void PeHeaderT<32>::readBaseOfData(InputBuffer& ibBuffer, PELIB_IMAGE_NT_HEADERS<32>& header) const 19 void PeHeaderT<32>::readBaseOfData(InputBuffer& ibBuffer, PELIB_IMAGE_NT_HEADERS<32>& header) const
20 { 20 {
21 ibBuffer >> header.OptionalHeader.BaseOfData; 21 ibBuffer >> header.OptionalHeader.BaseOfData;
22 } 22 }
23 23
24 template<> 24 template<>
25 void PeHeaderT<64>::readBaseOfData(InputBuffer&, PELIB_IMAGE_NT_HEADERS<64>&) const 25 void PeHeaderT<64>::readBaseOfData(InputBuffer&, PELIB_IMAGE_NT_HEADERS<64>&) const
26 { 26 {
27 } 27 }
28 28
29 template<> 29 template<>
30 void PeHeaderT<32>::rebuildBaseOfData(OutputBuffer& obBuffer) const 30 void PeHeaderT<32>::rebuildBaseOfData(OutputBuffer& obBuffer) const
31 { 31 {
32 obBuffer << m_inthHeader.OptionalHeader.BaseOfData; 32 obBuffer << m_inthHeader.OptionalHeader.BaseOfData;
33 } 33 }
34 34
35 template<> 35 template<>
36 void PeHeaderT<64>::rebuildBaseOfData(OutputBuffer&) const 36 void PeHeaderT<64>::rebuildBaseOfData(OutputBuffer&) const
37 { 37 {
38 } 38 }
39 39
40 template<> 40 template<>
41 bool PeHeaderT<32>::isValid() const 41 bool PeHeaderT<32>::isValid() const
42 { 42 {
43 return true; 43 return true;
44 } 44 }
45 45
46 template<> 46 template<>
47 bool PeHeaderT<64>::isValid() const 47 bool PeHeaderT<64>::isValid() const
48 { 48 {
49 return true; 49 return true;
50 } 50 }
51 51
52 template<> 52 template<>
53 bool PeHeaderT<32>::isValid(unsigned int pehf) const 53 bool PeHeaderT<32>::isValid(unsigned int pehf) const
54 { 54 {
55 /* 55 /*
56 if (pehf == NtSignature) 56 if (pehf == NtSignature)
57 { 57 {
58 return m_inthHeader.Signature == IMAGE_NT_SIGNATURE; 58 return m_inthHeader.Signature == IMAGE_NT_SIGNATURE;
59 } 59 }
60 else if (pehf == NumberOfSections) 60 else if (pehf == NumberOfSections)
61 { 61 {
62 return getNumberOfSections() == calcNumberOfSections(); 62 return getNumberOfSections() == calcNumberOfSections();
63 } */ 63 } */
64 return false; 64 return false;
65 } 65 }
66 66
67 template<> 67 template<>
68 bool PeHeaderT<64>::isValid(unsigned int pehf) const 68 bool PeHeaderT<64>::isValid(unsigned int pehf) const
69 { 69 {
70 return false; 70 return false;
71 } 71 }
72 72
73 /** 73 /**
74 * @return The BaseOfData value from the PE header. 74 * @return The BaseOfData value from the PE header.
75 **/ 75 **/
76 dword PeHeader32::getBaseOfData() const 76 dword PeHeader32::getBaseOfData() const
77 { 77 {
78 return m_inthHeader.OptionalHeader.BaseOfData; 78 return m_inthHeader.OptionalHeader.BaseOfData;
79 } 79 }
80 80
81 /** 81 /**
82 * Changes the file's BaseOfData. 82 * Changes the file's BaseOfData.
83 * @param dwValue New value. 83 * @param dwValue New value.
84 **/ 84 **/
85 void PeHeader32::setBaseOfData(dword dwValue) 85 void PeHeader32::setBaseOfData(dword dwValue)
86 { 86 {
87 m_inthHeader.OptionalHeader.BaseOfData = dwValue; 87 m_inthHeader.OptionalHeader.BaseOfData = dwValue;
88 } 88 }
89 89
90} 90}
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/PeHeader.h b/utils/zenutils/libraries/pelib-0.9/pelib/PeHeader.h
index 08eaca4072..d5c1748233 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/PeHeader.h
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/PeHeader.h
@@ -1,2685 +1,2685 @@
1/* 1/*
2* PeHeader.h - Part of the PeLib library. 2* PeHeader.h - Part of the PeLib library.
3* 3*
4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) 4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5* All rights reserved. 5* All rights reserved.
6* 6*
7* This software is licensed under the zlib/libpng License. 7* This software is licensed under the zlib/libpng License.
8* For more details see http://www.opensource.org/licenses/zlib-license.php 8* For more details see http://www.opensource.org/licenses/zlib-license.php
9* or the license information file (license.htm) in the root directory 9* or the license information file (license.htm) in the root directory
10* of PeLib. 10* of PeLib.
11*/ 11*/
12 12
13#ifndef PEHEADER_H 13#ifndef PEHEADER_H
14#define PEHEADER_H 14#define PEHEADER_H
15 15
16#include "PeLibAux.h" 16#include "PeLibAux.h"
17 17
18namespace PeLib 18namespace PeLib
19{ 19{
20 class PeHeader 20 class PeHeader
21 { 21 {
22// protected: 22// protected:
23// virtual void readBaseOfData(InputBuffer& ibBuffer) = 0; 23// virtual void readBaseOfData(InputBuffer& ibBuffer) = 0;
24// virtual void rebuildBaseOfData(OutputBuffer& obBuffer) const = 0; 24// virtual void rebuildBaseOfData(OutputBuffer& obBuffer) const = 0;
25 25
26 public: 26 public:
27 virtual ~PeHeader(){}; 27 virtual ~PeHeader(){};
28 }; 28 };
29 29
30 /// Class that handles the PE header of files. 30 /// Class that handles the PE header of files.
31 /** 31 /**
32 * This class can read and modify PE headers. It provides set- and get functions to access 32 * This class can read and modify PE headers. It provides set- and get functions to access
33 * all individual members of a PE header. Furthermore it's possible to validate and rebuild 33 * all individual members of a PE header. Furthermore it's possible to validate and rebuild
34 * PE headers. A PE header includes the IMAGE_Nt_HEADERS and the section definitions of a PE file. 34 * PE headers. A PE header includes the IMAGE_Nt_HEADERS and the section definitions of a PE file.
35 * \todo getIdReservedRva 35 * \todo getIdReservedRva
36 **/ 36 **/
37 template<int x> 37 template<int x>
38 class PeHeaderT : public PeHeader 38 class PeHeaderT : public PeHeader
39 { 39 {
40 private: 40 private:
41 void readBaseOfData(InputBuffer& ibBuffer, PELIB_IMAGE_NT_HEADERS<x>& header) const; 41 void readBaseOfData(InputBuffer& ibBuffer, PELIB_IMAGE_NT_HEADERS<x>& header) const;
42 void rebuildBaseOfData(OutputBuffer& obBuffer) const; 42 void rebuildBaseOfData(OutputBuffer& obBuffer) const;
43 43
44 protected: 44 protected:
45 std::vector<PELIB_IMAGE_SECTION_HEADER> m_vIsh; ///< Stores section header information. 45 std::vector<PELIB_IMAGE_SECTION_HEADER> m_vIsh; ///< Stores section header information.
46 PELIB_IMAGE_NT_HEADERS<x> m_inthHeader; ///< Stores Nt header information. 46 PELIB_IMAGE_NT_HEADERS<x> m_inthHeader; ///< Stores Nt header information.
47 dword m_uiOffset; ///< Equivalent to the value returned by #PeLib::MzHeader::getAddressOfPeFile 47 dword m_uiOffset; ///< Equivalent to the value returned by #PeLib::MzHeader::getAddressOfPeFile
48 48
49 public: 49 public:
50 typedef typename FieldSizes<x>::VAR4_8 VAR4_8; 50 typedef typename FieldSizes<x>::VAR4_8 VAR4_8;
51 51
52 PeHeaderT() : m_uiOffset(0) 52 PeHeaderT() : m_uiOffset(0)
53 { 53 {
54 } 54 }
55 55
56 /// Add a section to the header. 56 /// Add a section to the header.
57 int addSection(const std::string& strName, dword dwSize); // EXPORT 57 int addSection(const std::string& strName, dword dwSize); // EXPORT
58 58
59 unsigned int calcSizeOfImage() const; // EXPORT 59 unsigned int calcSizeOfImage() const; // EXPORT
60 60
61 /// Returns the unused space after the header. 61 /// Returns the unused space after the header.
62 unsigned int calcSpaceAfterHeader() const; // EXPORT 62 unsigned int calcSpaceAfterHeader() const; // EXPORT
63 63
64 /// Returns the address of the physically first section (not the first defined section). 64 /// Returns the address of the physically first section (not the first defined section).
65 unsigned int calcStartOfCode() const; // EXPORT 65 unsigned int calcStartOfCode() const; // EXPORT
66 66
67 /// Calculates the offset for a new section of size uiSize. 67 /// Calculates the offset for a new section of size uiSize.
68 unsigned int calcOffset() const; // EXPORT 68 unsigned int calcOffset() const; // EXPORT
69 69
70 /// Calculates the Rva for a new section of size uiSize. 70 /// Calculates the Rva for a new section of size uiSize.
71 unsigned int calcRva() const; // EXPORT 71 unsigned int calcRva() const; // EXPORT
72 72
73 /// Returns the number of sections in the current file. 73 /// Returns the number of sections in the current file.
74 word calcNumberOfSections() const; // EXPORT 74 word calcNumberOfSections() const; // EXPORT
75 75
76 void enlargeLastSection(unsigned int uiSize); // EXPORT 76 void enlargeLastSection(unsigned int uiSize); // EXPORT
77 77
78 /// Returns the section Id of the section that contains the offset. 78 /// Returns the section Id of the section that contains the offset.
79 word getSectionWithOffset(VAR4_8 dwOffset) const; // EXPORT 79 word getSectionWithOffset(VAR4_8 dwOffset) const; // EXPORT
80 80
81 /// Returns the number of the section which the given relative address points to. 81 /// Returns the number of the section which the given relative address points to.
82 word getSectionWithRva(VAR4_8 rva) const; // EXPORT 82 word getSectionWithRva(VAR4_8 rva) const; // EXPORT
83 83
84 bool isValid() const; // EXPORT 84 bool isValid() const; // EXPORT
85 bool isValid(unsigned int foo) const; // EXPORT 85 bool isValid(unsigned int foo) const; // EXPORT
86 86
87 /// Corrects the current PE header. 87 /// Corrects the current PE header.
88 void makeValid(dword dwOffset); // EXPORT 88 void makeValid(dword dwOffset); // EXPORT
89 89
90 /// Converts a file offset to a relative virtual offset. 90 /// Converts a file offset to a relative virtual offset.
91 unsigned int offsetToRva(VAR4_8 dwOffset) const; // EXPORT 91 unsigned int offsetToRva(VAR4_8 dwOffset) const; // EXPORT
92 92
93 /// Converts a file offset to a virtual address. 93 /// Converts a file offset to a virtual address.
94 unsigned int offsetToVa(VAR4_8 dwOffset) const; // EXPORT 94 unsigned int offsetToVa(VAR4_8 dwOffset) const; // EXPORT
95 95
96 /// Reads the PE header of a file. 96 /// Reads the PE header of a file.
97 int read(std::string strFilename, unsigned int uiOffset); // EXPORT 97 int read(std::string strFilename, unsigned int uiOffset); // EXPORT
98 98
99 int read(const unsigned char* pcBuffer, unsigned int uiSize, unsigned int uiOffset); // EXPORT 99 int read(const unsigned char* pcBuffer, unsigned int uiSize, unsigned int uiOffset); // EXPORT
100 100
101 void readHeader(InputBuffer& ibBuffer, PELIB_IMAGE_NT_HEADERS<x>& header) const; 101 void readHeader(InputBuffer& ibBuffer, PELIB_IMAGE_NT_HEADERS<x>& header) const;
102 void readDataDirectories(InputBuffer& ibBuffer, PELIB_IMAGE_NT_HEADERS<x>& header) const; 102 void readDataDirectories(InputBuffer& ibBuffer, PELIB_IMAGE_NT_HEADERS<x>& header) const;
103 std::vector<PELIB_IMAGE_SECTION_HEADER> readSections(InputBuffer& ibBuffer, PELIB_IMAGE_NT_HEADERS<x>& header) const; 103 std::vector<PELIB_IMAGE_SECTION_HEADER> readSections(InputBuffer& ibBuffer, PELIB_IMAGE_NT_HEADERS<x>& header) const;
104 104
105 /// Rebuilds the current PE header. 105 /// Rebuilds the current PE header.
106 void rebuild(std::vector<byte>& vBuffer) const; // EXPORT 106 void rebuild(std::vector<byte>& vBuffer) const; // EXPORT
107 107
108 /// Converts a relative virtual address to a file offset. 108 /// Converts a relative virtual address to a file offset.
109 VAR4_8 rvaToOffset(VAR4_8 dwRva) const; // EXPORT 109 VAR4_8 rvaToOffset(VAR4_8 dwRva) const; // EXPORT
110 110
111 /// Converts a relative virtual address to a virtual address. 111 /// Converts a relative virtual address to a virtual address.
112 VAR4_8 rvaToVa(VAR4_8 dwRva) const; // EXPORT 112 VAR4_8 rvaToVa(VAR4_8 dwRva) const; // EXPORT
113 113
114 /// Calculates the size for the current PE header including all section definitions. 114 /// Calculates the size for the current PE header including all section definitions.
115 unsigned int size() const; 115 unsigned int size() const;
116 116
117 VAR4_8 vaToRva(VAR4_8 dwRva) const; // EXPORT 117 VAR4_8 vaToRva(VAR4_8 dwRva) const; // EXPORT
118 VAR4_8 vaToOffset(VAR4_8 dwRva) const; // EXPORT 118 VAR4_8 vaToOffset(VAR4_8 dwRva) const; // EXPORT
119 119
120 /// Save the PE header to a file. 120 /// Save the PE header to a file.
121 int write(std::string strFilename, unsigned int uiOffset) const; // EXPORT 121 int write(std::string strFilename, unsigned int uiOffset) const; // EXPORT
122 122
123 /// Writes sections to a file. 123 /// Writes sections to a file.
124 int writeSections(const std::string& strFilename) const; // EXPORT 124 int writeSections(const std::string& strFilename) const; // EXPORT
125 /// Overwrites a section with new data. 125 /// Overwrites a section with new data.
126 int writeSectionData(const std::string& strFilename, word wSecnr, const std::vector<byte>& vBuffer) const; // EXPORT 126 int writeSectionData(const std::string& strFilename, word wSecnr, const std::vector<byte>& vBuffer) const; // EXPORT
127 127
128// header getters 128// header getters
129 /// Returns the Signature value of the header. 129 /// Returns the Signature value of the header.
130 dword getNtSignature() const; // EXPORT 130 dword getNtSignature() const; // EXPORT
131 /// Returns the Machine value of the header. 131 /// Returns the Machine value of the header.
132 word getMachine() const; // EXPORT 132 word getMachine() const; // EXPORT
133 /// Returns the Sections value of the header. 133 /// Returns the Sections value of the header.
134 word getNumberOfSections() const; // EXPORT 134 word getNumberOfSections() const; // EXPORT
135 /// Returns the TimeDateStamp value of the header. 135 /// Returns the TimeDateStamp value of the header.
136 dword getTimeDateStamp() const; // EXPORT 136 dword getTimeDateStamp() const; // EXPORT
137 /// Returns the PointerToSymbolTable value of the header. 137 /// Returns the PointerToSymbolTable value of the header.
138 dword getPointerToSymbolTable() const; // EXPORT 138 dword getPointerToSymbolTable() const; // EXPORT
139 /// Returns the NumberOfSymbols value of the header. 139 /// Returns the NumberOfSymbols value of the header.
140 dword getNumberOfSymbols() const; // EXPORT 140 dword getNumberOfSymbols() const; // EXPORT
141 /// Returns the SizeOfOptionalHeader value of the header. 141 /// Returns the SizeOfOptionalHeader value of the header.
142 word getSizeOfOptionalHeader() const; // EXPORT 142 word getSizeOfOptionalHeader() const; // EXPORT
143 /// Returns the Characteristics value of the header. 143 /// Returns the Characteristics value of the header.
144 word getCharacteristics() const; // EXPORT 144 word getCharacteristics() const; // EXPORT
145 145
146 /// Returns the Magic value of the header. 146 /// Returns the Magic value of the header.
147 word getMagic() const; // EXPORT 147 word getMagic() const; // EXPORT
148 /// Returns the MajorLinkerVersion value of the header. 148 /// Returns the MajorLinkerVersion value of the header.
149 byte getMajorLinkerVersion() const; // EXPORT 149 byte getMajorLinkerVersion() const; // EXPORT
150 /// Returns the MinorLinkerVersion value of the header. 150 /// Returns the MinorLinkerVersion value of the header.
151 byte getMinorLinkerVersion() const; // EXPORT 151 byte getMinorLinkerVersion() const; // EXPORT
152 /// Returns the SizeOfCode value of the header. 152 /// Returns the SizeOfCode value of the header.
153 dword getSizeOfCode() const; // EXPORT 153 dword getSizeOfCode() const; // EXPORT
154 /// Returns the SizeOfInitializedData value of the header. 154 /// Returns the SizeOfInitializedData value of the header.
155 dword getSizeOfInitializedData() const; // EXPORT 155 dword getSizeOfInitializedData() const; // EXPORT
156 /// Returns the SizeOfUninitializedData value of the header. 156 /// Returns the SizeOfUninitializedData value of the header.
157 dword getSizeOfUninitializedData() const; // EXPORT 157 dword getSizeOfUninitializedData() const; // EXPORT
158 /// Returns the AddressOfEntryPoint value of the header. 158 /// Returns the AddressOfEntryPoint value of the header.
159 dword getAddressOfEntryPoint() const; // EXPORT 159 dword getAddressOfEntryPoint() const; // EXPORT
160 /// Returns the BaseOfCode value of the header. 160 /// Returns the BaseOfCode value of the header.
161 dword getBaseOfCode() const; // EXPORT 161 dword getBaseOfCode() const; // EXPORT
162 /// Returns the ImageBase value of the header. 162 /// Returns the ImageBase value of the header.
163 VAR4_8 getImageBase() const; // EXPORT 163 VAR4_8 getImageBase() const; // EXPORT
164 /// Returns the SectionAlignment value of the header. 164 /// Returns the SectionAlignment value of the header.
165 dword getSectionAlignment() const; // EXPORT 165 dword getSectionAlignment() const; // EXPORT
166 /// Returns the FileAlignment value of the header. 166 /// Returns the FileAlignment value of the header.
167 dword getFileAlignment() const; // EXPORT 167 dword getFileAlignment() const; // EXPORT
168 /// Returns the MajorOperatingSystemVersion value of the header. 168 /// Returns the MajorOperatingSystemVersion value of the header.
169 word getMajorOperatingSystemVersion() const; // EXPORT 169 word getMajorOperatingSystemVersion() const; // EXPORT
170 /// Returns the MinorOperatingSystemVersion value of the header. 170 /// Returns the MinorOperatingSystemVersion value of the header.
171 word getMinorOperatingSystemVersion() const; // EXPORT 171 word getMinorOperatingSystemVersion() const; // EXPORT
172 /// Returns the MajorImageVersion value of the header. 172 /// Returns the MajorImageVersion value of the header.
173 word getMajorImageVersion() const; // EXPORT 173 word getMajorImageVersion() const; // EXPORT
174 /// Returns the MinorImageVersion value of the header. 174 /// Returns the MinorImageVersion value of the header.
175 word getMinorImageVersion() const; // EXPORT 175 word getMinorImageVersion() const; // EXPORT
176 /// Returns the MajorSubsystemVersion value of the header. 176 /// Returns the MajorSubsystemVersion value of the header.
177 word getMajorSubsystemVersion() const; // EXPORT 177 word getMajorSubsystemVersion() const; // EXPORT
178 /// Returns the MinorSubsystemVersion value of the header. 178 /// Returns the MinorSubsystemVersion value of the header.
179 word getMinorSubsystemVersion() const; // EXPORT 179 word getMinorSubsystemVersion() const; // EXPORT
180 /// Returns the Reserved1 value of the header. 180 /// Returns the Reserved1 value of the header.
181 dword getWin32VersionValue() const; // EXPORT 181 dword getWin32VersionValue() const; // EXPORT
182 /// Returns the SizeOfImage value of the header. 182 /// Returns the SizeOfImage value of the header.
183 dword getSizeOfImage() const; // EXPORT 183 dword getSizeOfImage() const; // EXPORT
184 /// Returns the SizeOfHeaders value of the header. 184 /// Returns the SizeOfHeaders value of the header.
185 dword getSizeOfHeaders() const; // EXPORT 185 dword getSizeOfHeaders() const; // EXPORT
186 /// Returns the CheckSum value of the header. 186 /// Returns the CheckSum value of the header.
187 dword getCheckSum() const; // EXPORT 187 dword getCheckSum() const; // EXPORT
188 /// Returns the Subsystem value of the header. 188 /// Returns the Subsystem value of the header.
189 word getSubsystem() const; // EXPORT 189 word getSubsystem() const; // EXPORT
190 /// Returns the DllCharacteristics value of the header. 190 /// Returns the DllCharacteristics value of the header.
191 word getDllCharacteristics() const; // EXPORT 191 word getDllCharacteristics() const; // EXPORT
192 /// Returns the SizeOfStackReserve value of the header. 192 /// Returns the SizeOfStackReserve value of the header.
193 VAR4_8 getSizeOfStackReserve() const; // EXPORT 193 VAR4_8 getSizeOfStackReserve() const; // EXPORT
194 /// Returns the SizeOfStackCommit value of the header. 194 /// Returns the SizeOfStackCommit value of the header.
195 VAR4_8 getSizeOfStackCommit() const; // EXPORT 195 VAR4_8 getSizeOfStackCommit() const; // EXPORT
196 /// Returns the SizeOfHeapReserve value of the header. 196 /// Returns the SizeOfHeapReserve value of the header.
197 VAR4_8 getSizeOfHeapReserve() const; // EXPORT 197 VAR4_8 getSizeOfHeapReserve() const; // EXPORT
198 /// Returns the SizeOfHeapCommit value of the header. 198 /// Returns the SizeOfHeapCommit value of the header.
199 VAR4_8 getSizeOfHeapCommit() const; // EXPORT 199 VAR4_8 getSizeOfHeapCommit() const; // EXPORT
200 /// Returns the LoaderFlags value of the header. 200 /// Returns the LoaderFlags value of the header.
201 dword getLoaderFlags() const; // EXPORT 201 dword getLoaderFlags() const; // EXPORT
202 /// Returns the NumberOfRvaAndSizes value of the header. 202 /// Returns the NumberOfRvaAndSizes value of the header.
203 dword getNumberOfRvaAndSizes() const; // EXPORT 203 dword getNumberOfRvaAndSizes() const; // EXPORT
204 dword calcNumberOfRvaAndSizes() const; // EXPORT 204 dword calcNumberOfRvaAndSizes() const; // EXPORT
205 205
206 void addDataDirectory(); // EXPORT 206 void addDataDirectory(); // EXPORT
207 void removeDataDirectory(dword index); // EXPORT 207 void removeDataDirectory(dword index); // EXPORT
208 208
209// image directory getters 209// image directory getters
210 /// Returns the relative virtual address of the image directory Export. 210 /// Returns the relative virtual address of the image directory Export.
211 dword getIddExportRva() const; // EXPORT 211 dword getIddExportRva() const; // EXPORT
212 /// Returns the size of the image directory Export. 212 /// Returns the size of the image directory Export.
213 dword getIddExportSize() const; // EXPORT 213 dword getIddExportSize() const; // EXPORT
214 /// Returns the relative virtual address of the image directory Import. 214 /// Returns the relative virtual address of the image directory Import.
215 dword getIddImportRva() const; // EXPORT 215 dword getIddImportRva() const; // EXPORT
216 /// Returns the size of the image directory Import. 216 /// Returns the size of the image directory Import.
217 dword getIddImportSize() const; // EXPORT 217 dword getIddImportSize() const; // EXPORT
218 /// Returns the relative virtual address of the image directory Resource. 218 /// Returns the relative virtual address of the image directory Resource.
219 dword getIddResourceRva() const; // EXPORT 219 dword getIddResourceRva() const; // EXPORT
220 /// Returns the size of the image directory Resource. 220 /// Returns the size of the image directory Resource.
221 dword getIddResourceSize() const; // EXPORT 221 dword getIddResourceSize() const; // EXPORT
222 /// Returns the relative virtual address of the image directory Exception. 222 /// Returns the relative virtual address of the image directory Exception.
223 dword getIddExceptionRva() const; // EXPORT 223 dword getIddExceptionRva() const; // EXPORT
224 /// Returns the size of the image directory Exception. 224 /// Returns the size of the image directory Exception.
225 dword getIddExceptionSize() const; // EXPORT 225 dword getIddExceptionSize() const; // EXPORT
226 /// Returns the relative virtual address of the image directory Security. 226 /// Returns the relative virtual address of the image directory Security.
227 dword getIddSecurityRva() const; // EXPORT 227 dword getIddSecurityRva() const; // EXPORT
228 /// Returns the size of the image directory Security. 228 /// Returns the size of the image directory Security.
229 dword getIddSecuritySize() const; // EXPORT 229 dword getIddSecuritySize() const; // EXPORT
230 /// Returns the relative virtual address of the image directory Base Reloc. 230 /// Returns the relative virtual address of the image directory Base Reloc.
231 dword getIddBaseRelocRva() const; // EXPORT 231 dword getIddBaseRelocRva() const; // EXPORT
232 /// Returns the size of the image directory Base Reloc. 232 /// Returns the size of the image directory Base Reloc.
233 dword getIddBaseRelocSize() const; // EXPORT 233 dword getIddBaseRelocSize() const; // EXPORT
234 /// Returns the relative virtual address of the image directory Debug. 234 /// Returns the relative virtual address of the image directory Debug.
235 dword getIddDebugRva() const; // EXPORT 235 dword getIddDebugRva() const; // EXPORT
236 /// Returns the size of the image directory Debug. 236 /// Returns the size of the image directory Debug.
237 dword getIddDebugSize() const; // EXPORT 237 dword getIddDebugSize() const; // EXPORT
238 /// Returns the relative virtual address of the image directory Architecture. 238 /// Returns the relative virtual address of the image directory Architecture.
239 dword getIddArchitectureRva() const; // EXPORT 239 dword getIddArchitectureRva() const; // EXPORT
240 /// Returns the size of the image directory Architecture. 240 /// Returns the size of the image directory Architecture.
241 dword getIddArchitectureSize() const; // EXPORT 241 dword getIddArchitectureSize() const; // EXPORT
242 /// Returns the relative virtual address of the image directory GlobalPtr. 242 /// Returns the relative virtual address of the image directory GlobalPtr.
243 dword getIddGlobalPtrRva() const; // EXPORT 243 dword getIddGlobalPtrRva() const; // EXPORT
244 /// Returns the size of the image directory GlobalPtr. 244 /// Returns the size of the image directory GlobalPtr.
245 dword getIddGlobalPtrSize() const; // EXPORT 245 dword getIddGlobalPtrSize() const; // EXPORT
246 /// Returns the relative virtual address of the image directory Tls. 246 /// Returns the relative virtual address of the image directory Tls.
247 dword getIddTlsRva() const; // EXPORT 247 dword getIddTlsRva() const; // EXPORT
248 /// Returns the size of the image directory Tls. 248 /// Returns the size of the image directory Tls.
249 dword getIddTlsSize() const; // EXPORT 249 dword getIddTlsSize() const; // EXPORT
250 /// Returns the relative virtual address of the image directory LoadConfig. 250 /// Returns the relative virtual address of the image directory LoadConfig.
251 dword getIddLoadConfigRva() const; // EXPORT 251 dword getIddLoadConfigRva() const; // EXPORT
252 /// Returns the size of the image directory LoadConfig. 252 /// Returns the size of the image directory LoadConfig.
253 dword getIddLoadConfigSize() const; // EXPORT 253 dword getIddLoadConfigSize() const; // EXPORT
254 /// Returns the relative virtual address of the image directory BoundImport. 254 /// Returns the relative virtual address of the image directory BoundImport.
255 dword getIddBoundImportRva() const; // EXPORT 255 dword getIddBoundImportRva() const; // EXPORT
256 /// Returns the size of the image directory BoundImport. 256 /// Returns the size of the image directory BoundImport.
257 dword getIddBoundImportSize() const; // EXPORT 257 dword getIddBoundImportSize() const; // EXPORT
258 /// Returns the relative virtual address of the image directory Iat. 258 /// Returns the relative virtual address of the image directory Iat.
259 dword getIddIatRva() const; // EXPORT 259 dword getIddIatRva() const; // EXPORT
260 /// Returns the size of the image directory Iat. 260 /// Returns the size of the image directory Iat.
261 dword getIddIatSize() const; // EXPORT 261 dword getIddIatSize() const; // EXPORT
262 /// Returns the relative virtual address of the image directory DelayImport. 262 /// Returns the relative virtual address of the image directory DelayImport.
263 dword getIddDelayImportRva() const; // EXPORT 263 dword getIddDelayImportRva() const; // EXPORT
264 /// Returns the size of the image directory DelayImport. 264 /// Returns the size of the image directory DelayImport.
265 dword getIddDelayImportSize() const; // EXPORT 265 dword getIddDelayImportSize() const; // EXPORT
266 /// Returns the relative virtual address of the image directory COM Descriptor. 266 /// Returns the relative virtual address of the image directory COM Descriptor.
267 dword getIddComHeaderRva() const; // EXPORT 267 dword getIddComHeaderRva() const; // EXPORT
268 /// Returns the size of the image directory COM Descriptor. 268 /// Returns the size of the image directory COM Descriptor.
269 dword getIddComHeaderSize() const; // EXPORT 269 dword getIddComHeaderSize() const; // EXPORT
270 270
271 /// Returns the relative virtual address of an image directory. 271 /// Returns the relative virtual address of an image directory.
272 dword getImageDataDirectoryRva(dword dwDirectory) const; // EXPORT 272 dword getImageDataDirectoryRva(dword dwDirectory) const; // EXPORT
273 /// Returns the size of an image directory. 273 /// Returns the size of an image directory.
274 dword getImageDataDirectorySize(dword dwDirectory) const; // EXPORT 274 dword getImageDataDirectorySize(dword dwDirectory) const; // EXPORT
275 275
276 void setImageDataDirectoryRva(dword dwDirectory, dword value); // EXPORT 276 void setImageDataDirectoryRva(dword dwDirectory, dword value); // EXPORT
277 void setImageDataDirectorySize(dword dwDirectory, dword value); // EXPORT 277 void setImageDataDirectorySize(dword dwDirectory, dword value); // EXPORT
278 278
279// section getters 279// section getters
280 /// Returns the name of a section. 280 /// Returns the name of a section.
281 std::string getSectionName(word uiSectionnr) const; // EXPORT 281 std::string getSectionName(word uiSectionnr) const; // EXPORT
282 /// Returns the virtual size of a section. 282 /// Returns the virtual size of a section.
283 dword getVirtualSize(word uiSectionnr) const; // EXPORT 283 dword getVirtualSize(word uiSectionnr) const; // EXPORT
284 /// Returns the virtual address of a section. 284 /// Returns the virtual address of a section.
285 dword getVirtualAddress(word uiSectionnr) const; // EXPORT 285 dword getVirtualAddress(word uiSectionnr) const; // EXPORT
286 /// Returns the size of a section's raw data. 286 /// Returns the size of a section's raw data.
287 dword getSizeOfRawData(word uiSectionnr) const; // EXPORT 287 dword getSizeOfRawData(word uiSectionnr) const; // EXPORT
288 /// Returns file offset of the data of a section. 288 /// Returns file offset of the data of a section.
289 dword getPointerToRawData(word uiSectionnr) const; // EXPORT 289 dword getPointerToRawData(word uiSectionnr) const; // EXPORT
290 /// Returns the rva of the relocations of a section. 290 /// Returns the rva of the relocations of a section.
291 dword getPointerToRelocations(word uiSectionnr) const; // EXPORT 291 dword getPointerToRelocations(word uiSectionnr) const; // EXPORT
292 /// Returns the rva of the line numbers of a section. 292 /// Returns the rva of the line numbers of a section.
293 dword getPointerToLinenumbers(word uiSectionnr) const; // EXPORT 293 dword getPointerToLinenumbers(word uiSectionnr) const; // EXPORT
294 /// Returns the number of relocations of a section. 294 /// Returns the number of relocations of a section.
295 dword getNumberOfRelocations(word uiSectionnr) const; // EXPORT 295 dword getNumberOfRelocations(word uiSectionnr) const; // EXPORT
296 /// Returns the number of line numbers of a section. 296 /// Returns the number of line numbers of a section.
297 dword getNumberOfLinenumbers(word uiSectionnr) const; // EXPORT 297 dword getNumberOfLinenumbers(word uiSectionnr) const; // EXPORT
298 /// Returns the characteristics of a section. 298 /// Returns the characteristics of a section.
299 dword getCharacteristics(word uiSectionnr) const; // EXPORT _section 299 dword getCharacteristics(word uiSectionnr) const; // EXPORT _section
300 300
301// header setters 301// header setters
302 /// Sets the Signature value of the header. 302 /// Sets the Signature value of the header.
303 void setNtSignature(dword value); // EXPORT 303 void setNtSignature(dword value); // EXPORT
304 /// Sets the Machine value of the header. 304 /// Sets the Machine value of the header.
305 void setMachine(word value); // EXPORT 305 void setMachine(word value); // EXPORT
306 /// Sets the Sections value of the header. 306 /// Sets the Sections value of the header.
307 void setNumberOfSections(word value); // EXPORT 307 void setNumberOfSections(word value); // EXPORT
308 /// Sets the TimeDateStamp value of the header. 308 /// Sets the TimeDateStamp value of the header.
309 void setTimeDateStamp(dword value); // EXPORT 309 void setTimeDateStamp(dword value); // EXPORT
310 /// Sets the PointerToSymbolTable value of the header. 310 /// Sets the PointerToSymbolTable value of the header.
311 void setPointerToSymbolTable(dword value); // EXPORT 311 void setPointerToSymbolTable(dword value); // EXPORT
312 /// Sets the NumberOfSymbols value of the header. 312 /// Sets the NumberOfSymbols value of the header.
313 void setNumberOfSymbols(dword value); // EXPORT 313 void setNumberOfSymbols(dword value); // EXPORT
314 /// Sets the SizeOfOptionalHeader value of the header. 314 /// Sets the SizeOfOptionalHeader value of the header.
315 void setSizeOfOptionalHeader(word value); // EXPORT 315 void setSizeOfOptionalHeader(word value); // EXPORT
316 /// Sets the Characteristics value of the header. 316 /// Sets the Characteristics value of the header.
317 void setCharacteristics(word value); // EXPORT _section 317 void setCharacteristics(word value); // EXPORT _section
318 318
319 /// Sets the Magic value of the header. 319 /// Sets the Magic value of the header.
320 void setMagic(word value); // EXPORT 320 void setMagic(word value); // EXPORT
321 /// Sets the MajorLinkerVersion value of the header. 321 /// Sets the MajorLinkerVersion value of the header.
322 void setMajorLinkerVersion(byte value); // EXPORT 322 void setMajorLinkerVersion(byte value); // EXPORT
323 /// Sets the MinorLinkerVersion value of the header. 323 /// Sets the MinorLinkerVersion value of the header.
324 void setMinorLinkerVersion(byte value); // EXPORT 324 void setMinorLinkerVersion(byte value); // EXPORT
325 /// Sets the SizeOfCode value of the header. 325 /// Sets the SizeOfCode value of the header.
326 void setSizeOfCode(dword value); // EXPORT 326 void setSizeOfCode(dword value); // EXPORT
327 /// Sets the SizeOfInitializedData value of the header. 327 /// Sets the SizeOfInitializedData value of the header.
328 void setSizeOfInitializedData(dword value); // EXPORT 328 void setSizeOfInitializedData(dword value); // EXPORT
329 /// Sets the SizeOfUninitializedData value of the header. 329 /// Sets the SizeOfUninitializedData value of the header.
330 void setSizeOfUninitializedData(dword value); // EXPORT 330 void setSizeOfUninitializedData(dword value); // EXPORT
331 /// Sets the AddressOfEntryPoint value of the header. 331 /// Sets the AddressOfEntryPoint value of the header.
332 void setAddressOfEntryPoint(dword value); // EXPORT 332 void setAddressOfEntryPoint(dword value); // EXPORT
333 /// Sets the BaseOfCode value of the header. 333 /// Sets the BaseOfCode value of the header.
334 void setBaseOfCode(dword value); // EXPORT 334 void setBaseOfCode(dword value); // EXPORT
335 /// Sets the ImageBase value of the header. 335 /// Sets the ImageBase value of the header.
336 void setImageBase(VAR4_8 value); // EXPORT 336 void setImageBase(VAR4_8 value); // EXPORT
337 /// Sets the SectionAlignment value of the header. 337 /// Sets the SectionAlignment value of the header.
338 void setSectionAlignment(dword value); // EXPORT 338 void setSectionAlignment(dword value); // EXPORT
339 /// Sets the FileAlignment value of the header. 339 /// Sets the FileAlignment value of the header.
340 void setFileAlignment(dword value); // EXPORT 340 void setFileAlignment(dword value); // EXPORT
341 /// Sets the MajorOperatingSystemVersion value of the header. 341 /// Sets the MajorOperatingSystemVersion value of the header.
342 void setMajorOperatingSystemVersion(word value); // EXPORT 342 void setMajorOperatingSystemVersion(word value); // EXPORT
343 /// Sets the MinorOperatingSystemVersion value of the header. 343 /// Sets the MinorOperatingSystemVersion value of the header.
344 void setMinorOperatingSystemVersion(word value); // EXPORT 344 void setMinorOperatingSystemVersion(word value); // EXPORT
345 /// Sets the MajorImageVersion value of the header. 345 /// Sets the MajorImageVersion value of the header.
346 void setMajorImageVersion(word value); // EXPORT 346 void setMajorImageVersion(word value); // EXPORT
347 /// Sets the MinorImageVersion value of the header. 347 /// Sets the MinorImageVersion value of the header.
348 void setMinorImageVersion(word value); // EXPORT 348 void setMinorImageVersion(word value); // EXPORT
349 /// Sets the MajorSubsystemVersion value of the header. 349 /// Sets the MajorSubsystemVersion value of the header.
350 void setMajorSubsystemVersion(word value); // EXPORT 350 void setMajorSubsystemVersion(word value); // EXPORT
351 /// Sets the MinorSubsystemVersion value of the header. 351 /// Sets the MinorSubsystemVersion value of the header.
352 void setMinorSubsystemVersion(word value); // EXPORT 352 void setMinorSubsystemVersion(word value); // EXPORT
353 /// Sets the Reserved1 value of the header. 353 /// Sets the Reserved1 value of the header.
354 void setWin32VersionValue(dword value); // EXPORT 354 void setWin32VersionValue(dword value); // EXPORT
355 /// Sets the SizeOfImage value of the header. 355 /// Sets the SizeOfImage value of the header.
356 void setSizeOfImage(dword value); // EXPORT 356 void setSizeOfImage(dword value); // EXPORT
357 /// Sets the SizeOfHeaders value of the header. 357 /// Sets the SizeOfHeaders value of the header.
358 void setSizeOfHeaders(dword value); // EXPORT 358 void setSizeOfHeaders(dword value); // EXPORT
359 /// Sets the CheckSum value of the header. 359 /// Sets the CheckSum value of the header.
360 void setCheckSum(dword value); // EXPORT 360 void setCheckSum(dword value); // EXPORT
361 /// Sets the Subsystem value of the header. 361 /// Sets the Subsystem value of the header.
362 void setSubsystem(word value); // EXPORT 362 void setSubsystem(word value); // EXPORT
363 /// Sets the DllCharacteristics value of the header. 363 /// Sets the DllCharacteristics value of the header.
364 void setDllCharacteristics(word value); // EXPORT 364 void setDllCharacteristics(word value); // EXPORT
365 /// Sets the SizeOfStackReserve value of the header. 365 /// Sets the SizeOfStackReserve value of the header.
366 void setSizeOfStackReserve(VAR4_8 value); // EXPORT 366 void setSizeOfStackReserve(VAR4_8 value); // EXPORT
367 /// Sets the SizeOfStackCommit value of the header. 367 /// Sets the SizeOfStackCommit value of the header.
368 void setSizeOfStackCommit(VAR4_8 value); // EXPORT 368 void setSizeOfStackCommit(VAR4_8 value); // EXPORT
369 /// Sets the SizeOfHeapReserve value of the header. 369 /// Sets the SizeOfHeapReserve value of the header.
370 void setSizeOfHeapReserve(VAR4_8 value); // EXPORT 370 void setSizeOfHeapReserve(VAR4_8 value); // EXPORT
371 /// Sets the SizeOfHeapCommit value of the header. 371 /// Sets the SizeOfHeapCommit value of the header.
372 void setSizeOfHeapCommit(VAR4_8 value); // EXPORT 372 void setSizeOfHeapCommit(VAR4_8 value); // EXPORT
373 /// Sets the LoaderFlags value of the header. 373 /// Sets the LoaderFlags value of the header.
374 void setLoaderFlags(dword value); // EXPORT 374 void setLoaderFlags(dword value); // EXPORT
375 /// Sets the NumberOfRvaAndSizes value of the header. 375 /// Sets the NumberOfRvaAndSizes value of the header.
376 void setNumberOfRvaAndSizes(dword value); // EXPORT 376 void setNumberOfRvaAndSizes(dword value); // EXPORT
377 377
378// image directory getters 378// image directory getters
379 void setIddDebugRva(dword dwValue); // EXPORT 379 void setIddDebugRva(dword dwValue); // EXPORT
380 void setIddDebugSize(dword dwValue); // EXPORT 380 void setIddDebugSize(dword dwValue); // EXPORT
381 void setIddDelayImportRva(dword dwValue); // EXPORT 381 void setIddDelayImportRva(dword dwValue); // EXPORT
382 void setIddDelayImportSize(dword dwValue); // EXPORT 382 void setIddDelayImportSize(dword dwValue); // EXPORT
383 void setIddExceptionRva(dword dwValue); // EXPORT 383 void setIddExceptionRva(dword dwValue); // EXPORT
384 void setIddExceptionSize(dword dwValue); // EXPORT 384 void setIddExceptionSize(dword dwValue); // EXPORT
385 void setIddGlobalPtrRva(dword dwValue); // EXPORT 385 void setIddGlobalPtrRva(dword dwValue); // EXPORT
386 void setIddGlobalPtrSize(dword dwValue); // EXPORT 386 void setIddGlobalPtrSize(dword dwValue); // EXPORT
387 void setIddIatRva(dword dwValue); // EXPORT 387 void setIddIatRva(dword dwValue); // EXPORT
388 void setIddIatSize(dword dwValue); // EXPORT 388 void setIddIatSize(dword dwValue); // EXPORT
389 void setIddLoadConfigRva(dword dwValue); // EXPORT 389 void setIddLoadConfigRva(dword dwValue); // EXPORT
390 void setIddLoadConfigSize(dword dwValue); // EXPORT 390 void setIddLoadConfigSize(dword dwValue); // EXPORT
391 void setIddResourceRva(dword dwValue); // EXPORT 391 void setIddResourceRva(dword dwValue); // EXPORT
392 void setIddResourceSize(dword dwValue); // EXPORT 392 void setIddResourceSize(dword dwValue); // EXPORT
393 void setIddSecurityRva(dword dwValue); // EXPORT 393 void setIddSecurityRva(dword dwValue); // EXPORT
394 void setIddSecuritySize(dword dwValue); // EXPORT 394 void setIddSecuritySize(dword dwValue); // EXPORT
395 void setIddTlsRva(dword dwValue); // EXPORT 395 void setIddTlsRva(dword dwValue); // EXPORT
396 void setIddTlsSize(dword dwValue); // EXPORT 396 void setIddTlsSize(dword dwValue); // EXPORT
397 397
398 void setIddImportRva(dword dwValue); // EXPORT 398 void setIddImportRva(dword dwValue); // EXPORT
399 void setIddImportSize(dword dwValue); // EXPORT 399 void setIddImportSize(dword dwValue); // EXPORT
400 void setIddExportRva(dword dwValue); // EXPORT 400 void setIddExportRva(dword dwValue); // EXPORT
401 void setIddExportSize(dword dwValue); // EXPORT 401 void setIddExportSize(dword dwValue); // EXPORT
402 402
403 void setIddBaseRelocRva(dword value); // EXPORT 403 void setIddBaseRelocRva(dword value); // EXPORT
404 void setIddBaseRelocSize(dword value); // EXPORT 404 void setIddBaseRelocSize(dword value); // EXPORT
405 void setIddArchitectureRva(dword value); // EXPORT 405 void setIddArchitectureRva(dword value); // EXPORT
406 void setIddArchitectureSize(dword value); // EXPORT 406 void setIddArchitectureSize(dword value); // EXPORT
407 void setIddComHeaderRva(dword value); // EXPORT 407 void setIddComHeaderRva(dword value); // EXPORT
408 void setIddComHeaderSize(dword value); // EXPORT 408 void setIddComHeaderSize(dword value); // EXPORT
409 409
410 /// Set the name of a section. 410 /// Set the name of a section.
411 void setSectionName(word uiSectionnr, std::string strName); // EXPORT 411 void setSectionName(word uiSectionnr, std::string strName); // EXPORT
412 /// Set the virtual size of a section. 412 /// Set the virtual size of a section.
413 void setVirtualSize(word uiSectionnr, dword dwValue); // EXPORT 413 void setVirtualSize(word uiSectionnr, dword dwValue); // EXPORT
414 /// Set the virtual address of a section. 414 /// Set the virtual address of a section.
415 void setVirtualAddress(word uiSectionnr, dword dwValue); // EXPORT 415 void setVirtualAddress(word uiSectionnr, dword dwValue); // EXPORT
416 /// Set the size of raw data of a section. 416 /// Set the size of raw data of a section.
417 void setSizeOfRawData(word uiSectionnr, dword dwValue); // EXPORT 417 void setSizeOfRawData(word uiSectionnr, dword dwValue); // EXPORT
418 /// Set the file offset of a section. 418 /// Set the file offset of a section.
419 void setPointerToRawData(word uiSectionnr, dword dwValue); // EXPORT 419 void setPointerToRawData(word uiSectionnr, dword dwValue); // EXPORT
420 /// Set the pointer to relocations of a section. 420 /// Set the pointer to relocations of a section.
421 void setPointerToRelocations(word uiSectionnr, dword dwValue); // EXPORT 421 void setPointerToRelocations(word uiSectionnr, dword dwValue); // EXPORT
422 /// Set the pointer to linenumbers of a section. 422 /// Set the pointer to linenumbers of a section.
423 void setPointerToLinenumbers(word uiSectionnr, dword dwValue); // EXPORT 423 void setPointerToLinenumbers(word uiSectionnr, dword dwValue); // EXPORT
424 /// Set the number of relocations a section. 424 /// Set the number of relocations a section.
425 void setNumberOfRelocations(word uiSectionnr, dword dwValue); // EXPORT 425 void setNumberOfRelocations(word uiSectionnr, dword dwValue); // EXPORT
426 /// Set the number of linenumbers section. 426 /// Set the number of linenumbers section.
427 void setNumberOfLinenumbers(word uiSectionnr, dword dwValue); // EXPORT 427 void setNumberOfLinenumbers(word uiSectionnr, dword dwValue); // EXPORT
428 /// Set the characteristics of a section. 428 /// Set the characteristics of a section.
429 void setCharacteristics(word uiSectionnr, dword dwValue); // EXPORT 429 void setCharacteristics(word uiSectionnr, dword dwValue); // EXPORT
430 }; 430 };
431 431
432 class PeHeader32 : public PeHeaderT<32> 432 class PeHeader32 : public PeHeaderT<32>
433 { 433 {
434 public: 434 public:
435 /// Returns the BaseOfData value of the header. 435 /// Returns the BaseOfData value of the header.
436 dword getBaseOfData() const; // EXPORT 436 dword getBaseOfData() const; // EXPORT
437 /// Sets the BaseOfData value of the header. 437 /// Sets the BaseOfData value of the header.
438 void setBaseOfData(dword value); // EXPORT 438 void setBaseOfData(dword value); // EXPORT
439 }; 439 };
440 440
441 class PeHeader64 : public PeHeaderT<64> 441 class PeHeader64 : public PeHeaderT<64>
442 { 442 {
443 }; 443 };
444 444
445 template<int x> 445 template<int x>
446 void PeHeaderT<x>::addDataDirectory() 446 void PeHeaderT<x>::addDataDirectory()
447 { 447 {
448 m_inthHeader.dataDirectories.push_back(PELIB_IMAGE_DATA_DIRECTORY()); 448 m_inthHeader.dataDirectories.push_back(PELIB_IMAGE_DATA_DIRECTORY());
449 } 449 }
450 450
451 template<int x> 451 template<int x>
452 void PeHeaderT<x>::removeDataDirectory(dword index) 452 void PeHeaderT<x>::removeDataDirectory(dword index)
453 { 453 {
454 m_inthHeader.dataDirectories.erase(m_inthHeader.dataDirectories.begin() + index); 454 m_inthHeader.dataDirectories.erase(m_inthHeader.dataDirectories.begin() + index);
455 } 455 }
456 456
457 /** 457 /**
458 * Adds a new section to the header. The physical and virtual address as well as the virtual 458 * Adds a new section to the header. The physical and virtual address as well as the virtual
459 * size of the section will be determined automatically from the raw size. The section 459 * size of the section will be determined automatically from the raw size. The section
460 * characteristics will be set to IMAGE_SCN_MEM_WRITE | IMAGE_SCN_MEM_READ | 460 * characteristics will be set to IMAGE_SCN_MEM_WRITE | IMAGE_SCN_MEM_READ |
461 * IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_CNT_CODE. All other values will be set to 0. 461 * IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_CNT_CODE. All other values will be set to 0.
462 * Note: It's important that if the current header's FileAlignment and/or SectionAlignment values are 462 * Note: It's important that if the current header's FileAlignment and/or SectionAlignment values are
463 * 0 this function will fail. 463 * 0 this function will fail.
464 * @param strName Name of the new section. If this name is longer than 8 bytes only the first 8 bytes will be used. 464 * @param strName Name of the new section. If this name is longer than 8 bytes only the first 8 bytes will be used.
465 * @param dwSize Physical size of the new section in bytes. 465 * @param dwSize Physical size of the new section in bytes.
466 * \todo Better code that handles files with 0 sections. 466 * \todo Better code that handles files with 0 sections.
467 **/ 467 **/
468 template<int x> 468 template<int x>
469 int PeHeaderT<x>::addSection(const std::string& strName, dword dwSize) 469 int PeHeaderT<x>::addSection(const std::string& strName, dword dwSize)
470 { 470 {
471 unsigned int uiSecnr = calcNumberOfSections(); 471 unsigned int uiSecnr = calcNumberOfSections();
472 472
473 if (!getFileAlignment()) 473 if (!getFileAlignment())
474 { 474 {
475 return ERROR_NO_FILE_ALIGNMENT; 475 return ERROR_NO_FILE_ALIGNMENT;
476 } 476 }
477 else if (!getSectionAlignment()) 477 else if (!getSectionAlignment())
478 { 478 {
479 return ERROR_NO_SECTION_ALIGNMENT; 479 return ERROR_NO_SECTION_ALIGNMENT;
480 } 480 }
481 481
482 if (uiSecnr) // Always allow 1 section. 482 if (uiSecnr) // Always allow 1 section.
483 { 483 {
484 if (uiSecnr == 0xFFFF) 484 if (uiSecnr == 0xFFFF)
485 { 485 {
486 return ERROR_TOO_MANY_SECTIONS; 486 return ERROR_TOO_MANY_SECTIONS;
487 } 487 }
488 else if (calcSpaceAfterHeader() < PELIB_IMAGE_SECTION_HEADER::size()) 488 else if (calcSpaceAfterHeader() < PELIB_IMAGE_SECTION_HEADER::size())
489 { 489 {
490 return ERROR_NOT_ENOUGH_SPACE; 490 return ERROR_NOT_ENOUGH_SPACE;
491 } 491 }
492 } 492 }
493 493
494 dword dwOffset = calcOffset(/*dwSize*/); 494 dword dwOffset = calcOffset(/*dwSize*/);
495 dword dwRva = calcRva(/*dwSize*/); 495 dword dwRva = calcRva(/*dwSize*/);
496 496
497 PELIB_IMAGE_SECTION_HEADER ishdCurr; 497 PELIB_IMAGE_SECTION_HEADER ishdCurr;
498 m_vIsh.push_back(ishdCurr); 498 m_vIsh.push_back(ishdCurr);
499 499
500 setSectionName(uiSecnr, strName); 500 setSectionName(uiSecnr, strName);
501 setSizeOfRawData(uiSecnr, alignOffset(dwSize, getFileAlignment())); 501 setSizeOfRawData(uiSecnr, alignOffset(dwSize, getFileAlignment()));
502 setPointerToRawData(uiSecnr, dwOffset); 502 setPointerToRawData(uiSecnr, dwOffset);
503 setVirtualSize(uiSecnr, alignOffset(dwSize, getSectionAlignment())); 503 setVirtualSize(uiSecnr, alignOffset(dwSize, getSectionAlignment()));
504 setVirtualAddress(uiSecnr, dwRva); 504 setVirtualAddress(uiSecnr, dwRva);
505 setCharacteristics(uiSecnr, PELIB_IMAGE_SCN_MEM_WRITE | PELIB_IMAGE_SCN_MEM_READ | PELIB_IMAGE_SCN_CNT_INITIALIZED_DATA | PELIB_IMAGE_SCN_CNT_CODE); 505 setCharacteristics(uiSecnr, PELIB_IMAGE_SCN_MEM_WRITE | PELIB_IMAGE_SCN_MEM_READ | PELIB_IMAGE_SCN_CNT_INITIALIZED_DATA | PELIB_IMAGE_SCN_CNT_CODE);
506 506
507 return NO_ERROR; 507 return NO_ERROR;
508 } 508 }
509 509
510 /** 510 /**
511 * Calculates a valid SizeOfImage value given the information from the current PE header. 511 * Calculates a valid SizeOfImage value given the information from the current PE header.
512 * Note that this calculation works in Win2K but probably does not work in Win9X. I didn't test that though. 512 * Note that this calculation works in Win2K but probably does not work in Win9X. I didn't test that though.
513 * @return Valid SizeOfImage value. 513 * @return Valid SizeOfImage value.
514 **/ 514 **/
515 template<int x> 515 template<int x>
516 unsigned int PeHeaderT<x>::calcSizeOfImage() const 516 unsigned int PeHeaderT<x>::calcSizeOfImage() const
517 { 517 {
518 // Major note here: It's possible for sections to exist with a Virtual Size of 0. 518 // Major note here: It's possible for sections to exist with a Virtual Size of 0.
519 // That's why it's necessary to use std::max(Vsize, RawSize) here. 519 // That's why it's necessary to use std::max(Vsize, RawSize) here.
520 // An example for such a file is dbeng6.exe (made by Sybase). 520 // An example for such a file is dbeng6.exe (made by Sybase).
521 // In this file each and every section has a VSize of 0 but it still runs. 521 // In this file each and every section has a VSize of 0 but it still runs.
522 522
523 std::vector<PELIB_IMAGE_SECTION_HEADER>::const_iterator ishLastSection = std::max_element(m_vIsh.begin(), m_vIsh.end(), std::mem_fun_ref(&PELIB_IMAGE_SECTION_HEADER::biggerVirtualAddress)); 523 std::vector<PELIB_IMAGE_SECTION_HEADER>::const_iterator ishLastSection = std::max_element(m_vIsh.begin(), m_vIsh.end(), std::mem_fun_ref(&PELIB_IMAGE_SECTION_HEADER::biggerVirtualAddress));
524 if (ishLastSection->VirtualSize != 0) return ishLastSection->VirtualAddress + ishLastSection->VirtualSize; 524 if (ishLastSection->VirtualSize != 0) return ishLastSection->VirtualAddress + ishLastSection->VirtualSize;
525 return ishLastSection->VirtualAddress + std::max(ishLastSection->VirtualSize, ishLastSection->SizeOfRawData); 525 return ishLastSection->VirtualAddress + std::max(ishLastSection->VirtualSize, ishLastSection->SizeOfRawData);
526 } 526 }
527 527
528 /** 528 /**
529 * Calculates the space between the last byte of the header and the first byte that's used for something 529 * Calculates the space between the last byte of the header and the first byte that's used for something
530 * else (that's either the first section or an image directory). 530 * else (that's either the first section or an image directory).
531 * @return Unused space after the header. 531 * @return Unused space after the header.
532 * \todo There are PE files with sections beginning at offset 0. They 532 * \todo There are PE files with sections beginning at offset 0. They
533 * need to be considered. 533 * need to be considered.
534 **/ 534 **/
535 template<int x> 535 template<int x>
536 unsigned int PeHeaderT<x>::calcSpaceAfterHeader() const 536 unsigned int PeHeaderT<x>::calcSpaceAfterHeader() const
537 { 537 {
538 return (calcStartOfCode() > size() + m_uiOffset) ? calcStartOfCode() - (size() + m_uiOffset) : 0; 538 return (calcStartOfCode() > size() + m_uiOffset) ? calcStartOfCode() - (size() + m_uiOffset) : 0;
539 } 539 }
540 540
541 /** 541 /**
542 * Returns the first offset of the file that's actually used for something different than the header. 542 * Returns the first offset of the file that's actually used for something different than the header.
543 * That something is not necessarily code, it can be a data directory too. 543 * That something is not necessarily code, it can be a data directory too.
544 * This offset can be the beginning of a section or the beginning of a directory. 544 * This offset can be the beginning of a section or the beginning of a directory.
545 * \todo Some optimizization is surely possible here. 545 * \todo Some optimizization is surely possible here.
546 * \todo There are PE files with sections beginning at offset 0. They 546 * \todo There are PE files with sections beginning at offset 0. They
547 * need to be considered. Returning 0 for these files doesn't really make sense. 547 * need to be considered. Returning 0 for these files doesn't really make sense.
548 * So far these sections are disregarded. 548 * So far these sections are disregarded.
549 **/ 549 **/
550 template<int x> 550 template<int x>
551 unsigned int PeHeaderT<x>::calcStartOfCode() const 551 unsigned int PeHeaderT<x>::calcStartOfCode() const
552 { 552 {
553 unsigned int directories = calcNumberOfRvaAndSizes(); 553 unsigned int directories = calcNumberOfRvaAndSizes();
554 dword dwMinOffset = 0xFFFFFFFF; 554 dword dwMinOffset = 0xFFFFFFFF;
555 if (directories >= 1 && getIddExportRva() && rvaToOffset(getIddExportRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddExportRva()); 555 if (directories >= 1 && getIddExportRva() && rvaToOffset(getIddExportRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddExportRva());
556 if (directories >= 2 && getIddImportRva() && rvaToOffset(getIddImportRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddImportRva()); 556 if (directories >= 2 && getIddImportRva() && rvaToOffset(getIddImportRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddImportRva());
557 if (directories >= 3 && getIddResourceRva() && rvaToOffset(getIddResourceRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddResourceRva()); 557 if (directories >= 3 && getIddResourceRva() && rvaToOffset(getIddResourceRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddResourceRva());
558 if (directories >= 4 && getIddExceptionRva() && rvaToOffset(getIddExceptionRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddExceptionRva()); 558 if (directories >= 4 && getIddExceptionRva() && rvaToOffset(getIddExceptionRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddExceptionRva());
559 if (directories >= 5 && getIddSecurityRva() && rvaToOffset(getIddSecurityRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddSecurityRva()); 559 if (directories >= 5 && getIddSecurityRva() && rvaToOffset(getIddSecurityRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddSecurityRva());
560 if (directories >= 6 && getIddBaseRelocRva() && rvaToOffset(getIddBaseRelocRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddBaseRelocRva()); 560 if (directories >= 6 && getIddBaseRelocRva() && rvaToOffset(getIddBaseRelocRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddBaseRelocRva());
561 if (directories >= 7 && getIddDebugRva() && rvaToOffset(getIddDebugRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddDebugRva()); 561 if (directories >= 7 && getIddDebugRva() && rvaToOffset(getIddDebugRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddDebugRva());
562 if (directories >= 8 && getIddArchitectureRva() && rvaToOffset(getIddArchitectureRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddArchitectureRva()); 562 if (directories >= 8 && getIddArchitectureRva() && rvaToOffset(getIddArchitectureRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddArchitectureRva());
563 if (directories >= 9 && getIddGlobalPtrRva() && rvaToOffset(getIddGlobalPtrRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddGlobalPtrRva()); 563 if (directories >= 9 && getIddGlobalPtrRva() && rvaToOffset(getIddGlobalPtrRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddGlobalPtrRva());
564 if (directories >= 10 && getIddTlsRva() && rvaToOffset(getIddTlsRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddTlsRva()); 564 if (directories >= 10 && getIddTlsRva() && rvaToOffset(getIddTlsRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddTlsRva());
565 if (directories >= 11 && getIddLoadConfigRva() && rvaToOffset(getIddLoadConfigRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddLoadConfigRva()); 565 if (directories >= 11 && getIddLoadConfigRva() && rvaToOffset(getIddLoadConfigRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddLoadConfigRva());
566 if (directories >= 12 && getIddBoundImportRva() && rvaToOffset(getIddBoundImportRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddBoundImportRva()); 566 if (directories >= 12 && getIddBoundImportRva() && rvaToOffset(getIddBoundImportRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddBoundImportRva());
567 if (directories >= 13 && getIddIatRva() && rvaToOffset(getIddIatRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddIatRva()); 567 if (directories >= 13 && getIddIatRva() && rvaToOffset(getIddIatRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddIatRva());
568 if (directories >= 14 && getIddDelayImportRva() && rvaToOffset(getIddDelayImportRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddDelayImportRva()); 568 if (directories >= 14 && getIddDelayImportRva() && rvaToOffset(getIddDelayImportRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddDelayImportRva());
569 if (directories >= 15 && getIddComHeaderRva() && rvaToOffset(getIddComHeaderRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddComHeaderRva()); 569 if (directories >= 15 && getIddComHeaderRva() && rvaToOffset(getIddComHeaderRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddComHeaderRva());
570 570
571 for (word i=0;i<calcNumberOfSections();i++) 571 for (word i=0;i<calcNumberOfSections();i++)
572 { 572 {
573 if ((getPointerToRawData(i) < dwMinOffset || dwMinOffset == 0xFFFFFFFF) && getSizeOfRawData(i)) 573 if ((getPointerToRawData(i) < dwMinOffset || dwMinOffset == 0xFFFFFFFF) && getSizeOfRawData(i))
574 { 574 {
575 if (getPointerToRawData(i)) dwMinOffset = getPointerToRawData(i); 575 if (getPointerToRawData(i)) dwMinOffset = getPointerToRawData(i);
576 } 576 }
577 } 577 }
578 return dwMinOffset; 578 return dwMinOffset;
579 } 579 }
580 580
581 /** 581 /**
582 * Calculates the file offset for a new section. The file offset will already be aligned to the file's FileAlignment. 582 * Calculates the file offset for a new section. The file offset will already be aligned to the file's FileAlignment.
583 * @return Aligned file offset. 583 * @return Aligned file offset.
584 * \todo uiSize isn't used yet. Will be used later on to search for caves. 584 * \todo uiSize isn't used yet. Will be used later on to search for caves.
585 **/ 585 **/
586 template<int x> 586 template<int x>
587 unsigned int PeHeaderT<x>::calcOffset(/*unsigned int uiSize*/) const 587 unsigned int PeHeaderT<x>::calcOffset(/*unsigned int uiSize*/) const
588 { 588 {
589 unsigned int maxoffset = size(); 589 unsigned int maxoffset = size();
590 590
591 for (word i=0;i<calcNumberOfSections();i++) 591 for (word i=0;i<calcNumberOfSections();i++)
592 { 592 {
593 if (getPointerToRawData(i) + getSizeOfRawData(i) > maxoffset) maxoffset = getPointerToRawData(i) + getSizeOfRawData(i); 593 if (getPointerToRawData(i) + getSizeOfRawData(i) > maxoffset) maxoffset = getPointerToRawData(i) + getSizeOfRawData(i);
594 } 594 }
595 595
596 return alignOffset(maxoffset, getFileAlignment()); 596 return alignOffset(maxoffset, getFileAlignment());
597 } 597 }
598 598
599 /** 599 /**
600 * Calculates the Rva for a new section. The Rva will already be aligned to the file's SectionAlignment. 600 * Calculates the Rva for a new section. The Rva will already be aligned to the file's SectionAlignment.
601 * \todo uiSize isn't used yet. Will be used later on to search for caves. 601 * \todo uiSize isn't used yet. Will be used later on to search for caves.
602 * @return Aligned Rva. 602 * @return Aligned Rva.
603 **/ 603 **/
604 template<int x> 604 template<int x>
605 unsigned int PeHeaderT<x>::calcRva(/*unsigned int uiSize*/) const 605 unsigned int PeHeaderT<x>::calcRva(/*unsigned int uiSize*/) const
606 { 606 {
607 // Major note here: It's possible for sections to exist with a Virtual Size of 0. 607 // Major note here: It's possible for sections to exist with a Virtual Size of 0.
608 // That's why it's necessary to use std::max(Vsize, RawSize) here. 608 // That's why it's necessary to use std::max(Vsize, RawSize) here.
609 // An example for such a file is dbeng6.exe (made by Sybase). 609 // An example for such a file is dbeng6.exe (made by Sybase).
610 // In this file each and every section has a VSize of 0 but it still runs. 610 // In this file each and every section has a VSize of 0 but it still runs.
611 611
612 unsigned int maxoffset = size(); 612 unsigned int maxoffset = size();
613 for (word i=0;i<calcNumberOfSections();i++) 613 for (word i=0;i<calcNumberOfSections();i++)
614 { 614 {
615 if (getVirtualAddress(i) + std::max(getVirtualSize(i), getSizeOfRawData(i)) > maxoffset) maxoffset = getVirtualAddress(i) + std::max(getVirtualSize(i), getSizeOfRawData(i)); 615 if (getVirtualAddress(i) + std::max(getVirtualSize(i), getSizeOfRawData(i)) > maxoffset) maxoffset = getVirtualAddress(i) + std::max(getVirtualSize(i), getSizeOfRawData(i));
616 } 616 }
617 617
618 return alignOffset(maxoffset, getSectionAlignment()); 618 return alignOffset(maxoffset, getSectionAlignment());
619 } 619 }
620 620
621 /** 621 /**
622 * Returns the number of currently defined sections. Note that this value can be different from the number 622 * Returns the number of currently defined sections. Note that this value can be different from the number
623 * of sections according to the header (see #PeLib::PeHeaderT<x>::getNumberOfSections). 623 * of sections according to the header (see #PeLib::PeHeaderT<x>::getNumberOfSections).
624 * @return Number of currently defined sections. 624 * @return Number of currently defined sections.
625 **/ 625 **/
626 template<int x> 626 template<int x>
627 word PeHeaderT<x>::calcNumberOfSections() const 627 word PeHeaderT<x>::calcNumberOfSections() const
628 { 628 {
629 return static_cast<PeLib::word>(m_vIsh.size()); 629 return static_cast<PeLib::word>(m_vIsh.size());
630 } 630 }
631 631
632 /** 632 /**
633 * Enlarges the physically last section in the file. 633 * Enlarges the physically last section in the file.
634 * @param uiSize Additional size that's added to the section's size. 634 * @param uiSize Additional size that's added to the section's size.
635 **/ 635 **/
636 template<int x> 636 template<int x>
637 void PeHeaderT<x>::enlargeLastSection(unsigned int uiSize) 637 void PeHeaderT<x>::enlargeLastSection(unsigned int uiSize)
638 { 638 {
639 std::vector<PELIB_IMAGE_SECTION_HEADER>::iterator ishLastSection = std::max_element(m_vIsh.begin(), m_vIsh.end(), std::mem_fun_ref(&PELIB_IMAGE_SECTION_HEADER::biggerFileOffset)); 639 std::vector<PELIB_IMAGE_SECTION_HEADER>::iterator ishLastSection = std::max_element(m_vIsh.begin(), m_vIsh.end(), std::mem_fun_ref(&PELIB_IMAGE_SECTION_HEADER::biggerFileOffset));
640 unsigned int uiRawDataSize = alignOffset(ishLastSection->SizeOfRawData + uiSize, getFileAlignment()); 640 unsigned int uiRawDataSize = alignOffset(ishLastSection->SizeOfRawData + uiSize, getFileAlignment());
641 641
642 ishLastSection->SizeOfRawData = uiRawDataSize; 642 ishLastSection->SizeOfRawData = uiRawDataSize;
643 ishLastSection->VirtualSize = ishLastSection->SizeOfRawData; 643 ishLastSection->VirtualSize = ishLastSection->SizeOfRawData;
644 644
645 setSizeOfImage(calcSizeOfImage()); 645 setSizeOfImage(calcSizeOfImage());
646 } 646 }
647 647
648 /** 648 /**
649 * Determines the section which contains the file offset. 649 * Determines the section which contains the file offset.
650 * @param dwOffset File offset. 650 * @param dwOffset File offset.
651 * @return Section Id of the section which contains the offset. 651 * @return Section Id of the section which contains the offset.
652 **/ 652 **/
653 template<int x> 653 template<int x>
654 word PeHeaderT<x>::getSectionWithOffset(VAR4_8 dwOffset) const 654 word PeHeaderT<x>::getSectionWithOffset(VAR4_8 dwOffset) const
655 { 655 {
656 // Offset = 0 must be handled explicitly as there are files 656 // Offset = 0 must be handled explicitly as there are files
657 // with sections that begin at offset 0, that means the section 657 // with sections that begin at offset 0, that means the section
658 // only exists in memory. 658 // only exists in memory.
659 659
660 if (!dwOffset) return std::numeric_limits<word>::max(); 660 if (!dwOffset) return std::numeric_limits<word>::max();
661 661
662 for (word i=0;i<calcNumberOfSections();i++) 662 for (word i=0;i<calcNumberOfSections();i++)
663 { 663 {
664 // Explicity exclude sections with raw pointer = 0. 664 // Explicity exclude sections with raw pointer = 0.
665 dword rawptr = getPointerToRawData(i); 665 dword rawptr = getPointerToRawData(i);
666 if (rawptr && rawptr <= dwOffset && rawptr + getSizeOfRawData(i) > dwOffset) return i; 666 if (rawptr && rawptr <= dwOffset && rawptr + getSizeOfRawData(i) > dwOffset) return i;
667 } 667 }
668 668
669 return std::numeric_limits<word>::max(); 669 return std::numeric_limits<word>::max();
670 } 670 }
671 671
672 /** 672 /**
673 * Determines the section which contains the Rva. 673 * Determines the section which contains the Rva.
674 * @param dwRva A relative virtual address. 674 * @param dwRva A relative virtual address.
675 * @return Section Id of the section which contains the Rva. 675 * @return Section Id of the section which contains the Rva.
676 **/ 676 **/
677 template<int x> 677 template<int x>
678 word PeHeaderT<x>::getSectionWithRva(VAR4_8 dwRva) const 678 word PeHeaderT<x>::getSectionWithRva(VAR4_8 dwRva) const
679 { 679 {
680 // Major note here: It's possible for sections to exist with a Virtual Size of 0. 680 // Major note here: It's possible for sections to exist with a Virtual Size of 0.
681 // That's why it's necessary to use std::max(Vsize, RawSize) here. 681 // That's why it's necessary to use std::max(Vsize, RawSize) here.
682 // An example for such a file is dbeng6.exe (made by Sybase). 682 // An example for such a file is dbeng6.exe (made by Sybase).
683 // In this file each and every section has a VSize of 0 but it still runs. 683 // In this file each and every section has a VSize of 0 but it still runs.
684 684
685 for (word i=0;i<calcNumberOfSections();i++) 685 for (word i=0;i<calcNumberOfSections();i++)
686 { 686 {
687 // Weird VC++7 error doesn't allow me to use std::max here. 687 // Weird VC++7 error doesn't allow me to use std::max here.
688 dword max = getVirtualSize(i) >= getSizeOfRawData(i) ? getVirtualSize(i) : getSizeOfRawData(i); 688 dword max = getVirtualSize(i) >= getSizeOfRawData(i) ? getVirtualSize(i) : getSizeOfRawData(i);
689 if (getVirtualAddress(i) <= dwRva && getVirtualAddress(i) + max > dwRva) return i; 689 if (getVirtualAddress(i) <= dwRva && getVirtualAddress(i) + max > dwRva) return i;
690 } 690 }
691 691
692 return -1; 692 return -1;
693 } 693 }
694 694
695 /** 695 /**
696 * Corrects all faulty values of the current PE header. The following values will be corrected: NtSignature, 696 * Corrects all faulty values of the current PE header. The following values will be corrected: NtSignature,
697 * NumberOfSections, SizeOfOptionalHeader, FileAlignment (will be aligned to n*0x200), 697 * NumberOfSections, SizeOfOptionalHeader, FileAlignment (will be aligned to n*0x200),
698 * SectionAlignment (will be aligned to n*0x1000), NumberOfRvaAndSizes, SizeOfHeaders, SizeOfImage, 698 * SectionAlignment (will be aligned to n*0x1000), NumberOfRvaAndSizes, SizeOfHeaders, SizeOfImage,
699 * Magic, Characteristics. 699 * Magic, Characteristics.
700 * @param dwOffset Beginning of PeHeader (see #PeLib::MzHeader::getAddressOfPeHeader). 700 * @param dwOffset Beginning of PeHeader (see #PeLib::MzHeader::getAddressOfPeHeader).
701 * \todo 32bit and 64bit versions. 701 * \todo 32bit and 64bit versions.
702 **/ 702 **/
703 template<int x> 703 template<int x>
704 void PeHeaderT<x>::makeValid(dword dwOffset) 704 void PeHeaderT<x>::makeValid(dword dwOffset)
705 { 705 {
706 setNtSignature(PELIB_IMAGE_NT_SIGNATURE); // 'PE' 706 setNtSignature(PELIB_IMAGE_NT_SIGNATURE); // 'PE'
707 setMachine(PELIB_IMAGE_FILE_MACHINE_I386); 707 setMachine(PELIB_IMAGE_FILE_MACHINE_I386);
708 setNumberOfSections(calcNumberOfSections()); 708 setNumberOfSections(calcNumberOfSections());
709 709
710 // Check if 64 bits. 710 // Check if 64 bits.
711 setSizeOfOptionalHeader(PELIB_IMAGE_OPTIONAL_HEADER<x>::size() + calcNumberOfRvaAndSizes() * 8); 711 setSizeOfOptionalHeader(PELIB_IMAGE_OPTIONAL_HEADER<x>::size() + calcNumberOfRvaAndSizes() * 8);
712 712
713 // Check if 64 bits. 713 // Check if 64 bits.
714 dword dwCharacteristics = PELIB_IMAGE_FILE_EXECUTABLE_IMAGE | PELIB_IMAGE_FILE_32BIT_MACHINE; 714 dword dwCharacteristics = PELIB_IMAGE_FILE_EXECUTABLE_IMAGE | PELIB_IMAGE_FILE_32BIT_MACHINE;
715 setCharacteristics(dwCharacteristics); 715 setCharacteristics(dwCharacteristics);
716 716
717 // Check if 64 bits. 717 // Check if 64 bits.
718 setMagic(PELIB_IMAGE_NT_OPTIONAL_HDR32_MAGIC); 718 setMagic(PELIB_IMAGE_NT_OPTIONAL_HDR32_MAGIC);
719 719
720 // setImageBase(0x01000000); 720 // setImageBase(0x01000000);
721 721
722 // Align file and section alignment values 722 // Align file and section alignment values
723 unsigned int dwAlignedOffset = alignOffset(getSectionAlignment(), 0x1000); 723 unsigned int dwAlignedOffset = alignOffset(getSectionAlignment(), 0x1000);
724 setSectionAlignment(dwAlignedOffset ? dwAlignedOffset : 0x1000); 724 setSectionAlignment(dwAlignedOffset ? dwAlignedOffset : 0x1000);
725 725
726 dwAlignedOffset = alignOffset(getFileAlignment(), 0x200); 726 dwAlignedOffset = alignOffset(getFileAlignment(), 0x200);
727 setFileAlignment(dwAlignedOffset ? dwAlignedOffset : 0x200); 727 setFileAlignment(dwAlignedOffset ? dwAlignedOffset : 0x200);
728 728
729// setMajorSubsystemVersion(4); 729// setMajorSubsystemVersion(4);
730// setSubsystem(IMAGE_SUBSYSTEM_WINDOWS_GUI); 730// setSubsystem(IMAGE_SUBSYSTEM_WINDOWS_GUI);
731 setNumberOfRvaAndSizes(calcNumberOfRvaAndSizes()); 731 setNumberOfRvaAndSizes(calcNumberOfRvaAndSizes());
732 732
733 // Code below depends on code above. Don't change the order. 733 // Code below depends on code above. Don't change the order.
734 dword dwSizeOfHeaders = alignOffset(dwOffset + size(), getFileAlignment()); 734 dword dwSizeOfHeaders = alignOffset(dwOffset + size(), getFileAlignment());
735 setSizeOfHeaders(dwSizeOfHeaders); 735 setSizeOfHeaders(dwSizeOfHeaders);
736 736
737 dword dwSizeOfImage = alignOffset(dwSizeOfHeaders, getSectionAlignment()); 737 dword dwSizeOfImage = alignOffset(dwSizeOfHeaders, getSectionAlignment());
738 738
739 for (int i=0;i<calcNumberOfSections();i++) 739 for (int i=0;i<calcNumberOfSections();i++)
740 { 740 {
741 dwSizeOfImage += alignOffset(getVirtualSize(i), getSectionAlignment()); 741 dwSizeOfImage += alignOffset(getVirtualSize(i), getSectionAlignment());
742 } 742 }
743 743
744 dwSizeOfImage = alignOffset(dwSizeOfImage, getSectionAlignment()); 744 dwSizeOfImage = alignOffset(dwSizeOfImage, getSectionAlignment());
745 setSizeOfImage(dwSizeOfImage); 745 setSizeOfImage(dwSizeOfImage);
746 } 746 }
747 747
748 template<int x> 748 template<int x>
749 unsigned int PeHeaderT<x>::offsetToRva(VAR4_8 dwOffset) const 749 unsigned int PeHeaderT<x>::offsetToRva(VAR4_8 dwOffset) const
750 { 750 {
751 if (dwOffset < calcStartOfCode()) return dwOffset; 751 if (dwOffset < calcStartOfCode()) return dwOffset;
752 752
753 PeLib::word uiSecnr = getSectionWithOffset(dwOffset); 753 PeLib::word uiSecnr = getSectionWithOffset(dwOffset);
754 754
755 if (uiSecnr == 0xFFFF) return -1; 755 if (uiSecnr == 0xFFFF) return -1;
756 756
757 return getVirtualAddress(uiSecnr) + dwOffset - getPointerToRawData(uiSecnr); 757 return getVirtualAddress(uiSecnr) + dwOffset - getPointerToRawData(uiSecnr);
758 } 758 }
759 759
760 /** 760 /**
761 * Converts a file offset to a virtual address. 761 * Converts a file offset to a virtual address.
762 * @param dwOffset File offset. 762 * @param dwOffset File offset.
763 * @return Virtual Address. 763 * @return Virtual Address.
764 **/ 764 **/
765 template<int x> 765 template<int x>
766 unsigned int PeHeaderT<x>::offsetToVa(VAR4_8 dwOffset) const 766 unsigned int PeHeaderT<x>::offsetToVa(VAR4_8 dwOffset) const
767 { 767 {
768 if (dwOffset < calcStartOfCode()) return getImageBase() + dwOffset; 768 if (dwOffset < calcStartOfCode()) return getImageBase() + dwOffset;
769 769
770 PeLib::word uiSecnr = getSectionWithOffset(dwOffset); 770 PeLib::word uiSecnr = getSectionWithOffset(dwOffset);
771 771
772 if (uiSecnr == 0xFFFF) return -1; 772 if (uiSecnr == 0xFFFF) return -1;
773 773
774 return getImageBase() + getVirtualAddress(uiSecnr) + dwOffset - getPointerToRawData(uiSecnr); 774 return getImageBase() + getVirtualAddress(uiSecnr) + dwOffset - getPointerToRawData(uiSecnr);
775 } 775 }
776 776
777 template<int x> 777 template<int x>
778 void PeHeaderT<x>::readHeader(InputBuffer& ibBuffer, PELIB_IMAGE_NT_HEADERS<x>& header) const 778 void PeHeaderT<x>::readHeader(InputBuffer& ibBuffer, PELIB_IMAGE_NT_HEADERS<x>& header) const
779 { 779 {
780 ibBuffer >> header.Signature; 780 ibBuffer >> header.Signature;
781 781
782 ibBuffer >> header.FileHeader.Machine; 782 ibBuffer >> header.FileHeader.Machine;
783 ibBuffer >> header.FileHeader.NumberOfSections; 783 ibBuffer >> header.FileHeader.NumberOfSections;
784 ibBuffer >> header.FileHeader.TimeDateStamp; 784 ibBuffer >> header.FileHeader.TimeDateStamp;
785 ibBuffer >> header.FileHeader.PointerToSymbolTable; 785 ibBuffer >> header.FileHeader.PointerToSymbolTable;
786 ibBuffer >> header.FileHeader.NumberOfSymbols; 786 ibBuffer >> header.FileHeader.NumberOfSymbols;
787 ibBuffer >> header.FileHeader.SizeOfOptionalHeader; 787 ibBuffer >> header.FileHeader.SizeOfOptionalHeader;
788 ibBuffer >> header.FileHeader.Characteristics; 788 ibBuffer >> header.FileHeader.Characteristics;
789 ibBuffer >> header.OptionalHeader.Magic; 789 ibBuffer >> header.OptionalHeader.Magic;
790 790
791 ibBuffer >> header.OptionalHeader.MajorLinkerVersion; 791 ibBuffer >> header.OptionalHeader.MajorLinkerVersion;
792 ibBuffer >> header.OptionalHeader.MinorLinkerVersion; 792 ibBuffer >> header.OptionalHeader.MinorLinkerVersion;
793 ibBuffer >> header.OptionalHeader.SizeOfCode; 793 ibBuffer >> header.OptionalHeader.SizeOfCode;
794 ibBuffer >> header.OptionalHeader.SizeOfInitializedData; 794 ibBuffer >> header.OptionalHeader.SizeOfInitializedData;
795 ibBuffer >> header.OptionalHeader.SizeOfUninitializedData; 795 ibBuffer >> header.OptionalHeader.SizeOfUninitializedData;
796 ibBuffer >> header.OptionalHeader.AddressOfEntryPoint; 796 ibBuffer >> header.OptionalHeader.AddressOfEntryPoint;
797 ibBuffer >> header.OptionalHeader.BaseOfCode; 797 ibBuffer >> header.OptionalHeader.BaseOfCode;
798 readBaseOfData(ibBuffer, header); 798 readBaseOfData(ibBuffer, header);
799 ibBuffer >> header.OptionalHeader.ImageBase; 799 ibBuffer >> header.OptionalHeader.ImageBase;
800 ibBuffer >> header.OptionalHeader.SectionAlignment; 800 ibBuffer >> header.OptionalHeader.SectionAlignment;
801 ibBuffer >> header.OptionalHeader.FileAlignment; 801 ibBuffer >> header.OptionalHeader.FileAlignment;
802 ibBuffer >> header.OptionalHeader.MajorOperatingSystemVersion; 802 ibBuffer >> header.OptionalHeader.MajorOperatingSystemVersion;
803 ibBuffer >> header.OptionalHeader.MinorOperatingSystemVersion; 803 ibBuffer >> header.OptionalHeader.MinorOperatingSystemVersion;
804 ibBuffer >> header.OptionalHeader.MajorImageVersion; 804 ibBuffer >> header.OptionalHeader.MajorImageVersion;
805 ibBuffer >> header.OptionalHeader.MinorImageVersion; 805 ibBuffer >> header.OptionalHeader.MinorImageVersion;
806 ibBuffer >> header.OptionalHeader.MajorSubsystemVersion; 806 ibBuffer >> header.OptionalHeader.MajorSubsystemVersion;
807 ibBuffer >> header.OptionalHeader.MinorSubsystemVersion; 807 ibBuffer >> header.OptionalHeader.MinorSubsystemVersion;
808 ibBuffer >> header.OptionalHeader.Win32VersionValue; 808 ibBuffer >> header.OptionalHeader.Win32VersionValue;
809 ibBuffer >> header.OptionalHeader.SizeOfImage; 809 ibBuffer >> header.OptionalHeader.SizeOfImage;
810 ibBuffer >> header.OptionalHeader.SizeOfHeaders; 810 ibBuffer >> header.OptionalHeader.SizeOfHeaders;
811 ibBuffer >> header.OptionalHeader.CheckSum; 811 ibBuffer >> header.OptionalHeader.CheckSum;
812 ibBuffer >> header.OptionalHeader.Subsystem; 812 ibBuffer >> header.OptionalHeader.Subsystem;
813 ibBuffer >> header.OptionalHeader.DllCharacteristics; 813 ibBuffer >> header.OptionalHeader.DllCharacteristics;
814 ibBuffer >> header.OptionalHeader.SizeOfStackReserve; 814 ibBuffer >> header.OptionalHeader.SizeOfStackReserve;
815 ibBuffer >> header.OptionalHeader.SizeOfStackCommit; 815 ibBuffer >> header.OptionalHeader.SizeOfStackCommit;
816 ibBuffer >> header.OptionalHeader.SizeOfHeapReserve; 816 ibBuffer >> header.OptionalHeader.SizeOfHeapReserve;
817 ibBuffer >> header.OptionalHeader.SizeOfHeapCommit; 817 ibBuffer >> header.OptionalHeader.SizeOfHeapCommit;
818 ibBuffer >> header.OptionalHeader.LoaderFlags; 818 ibBuffer >> header.OptionalHeader.LoaderFlags;
819 ibBuffer >> header.OptionalHeader.NumberOfRvaAndSizes; 819 ibBuffer >> header.OptionalHeader.NumberOfRvaAndSizes;
820 } 820 }
821 821
822 template<int x> 822 template<int x>
823 void PeHeaderT<x>::readDataDirectories(InputBuffer& ibBuffer, PELIB_IMAGE_NT_HEADERS<x>& header) const 823 void PeHeaderT<x>::readDataDirectories(InputBuffer& ibBuffer, PELIB_IMAGE_NT_HEADERS<x>& header) const
824 { 824 {
825 PELIB_IMAGE_DATA_DIRECTORY idd; 825 PELIB_IMAGE_DATA_DIRECTORY idd;
826 826
827 for (unsigned int i=0;i<header.OptionalHeader.NumberOfRvaAndSizes;i++) 827 for (unsigned int i=0;i<header.OptionalHeader.NumberOfRvaAndSizes;i++)
828 { 828 {
829 ibBuffer >> idd.VirtualAddress; 829 ibBuffer >> idd.VirtualAddress;
830 ibBuffer >> idd.Size; 830 ibBuffer >> idd.Size;
831 header.dataDirectories.push_back(idd); 831 header.dataDirectories.push_back(idd);
832 } 832 }
833 } 833 }
834 834
835 template<int x> 835 template<int x>
836 std::vector<PELIB_IMAGE_SECTION_HEADER> PeHeaderT<x>::readSections(InputBuffer& ibBuffer, PELIB_IMAGE_NT_HEADERS<x>& header) const 836 std::vector<PELIB_IMAGE_SECTION_HEADER> PeHeaderT<x>::readSections(InputBuffer& ibBuffer, PELIB_IMAGE_NT_HEADERS<x>& header) const
837 { 837 {
838 const unsigned int nrSections = header.FileHeader.NumberOfSections; 838 const unsigned int nrSections = header.FileHeader.NumberOfSections;
839 PELIB_IMAGE_SECTION_HEADER ishCurr; 839 PELIB_IMAGE_SECTION_HEADER ishCurr;
840 840
841 std::vector<PELIB_IMAGE_SECTION_HEADER> vIshdCurr; 841 std::vector<PELIB_IMAGE_SECTION_HEADER> vIshdCurr;
842 842
843 for (unsigned int i=0;i<nrSections;i++) 843 for (unsigned int i=0;i<nrSections;i++)
844 { 844 {
845 ibBuffer.read(reinterpret_cast<char*>(ishCurr.Name), 8); 845 ibBuffer.read(reinterpret_cast<char*>(ishCurr.Name), 8);
846 ibBuffer >> ishCurr.VirtualSize; 846 ibBuffer >> ishCurr.VirtualSize;
847 ibBuffer >> ishCurr.VirtualAddress; 847 ibBuffer >> ishCurr.VirtualAddress;
848 ibBuffer >> ishCurr.SizeOfRawData; 848 ibBuffer >> ishCurr.SizeOfRawData;
849 ibBuffer >> ishCurr.PointerToRawData; 849 ibBuffer >> ishCurr.PointerToRawData;
850 ibBuffer >> ishCurr.PointerToRelocations; 850 ibBuffer >> ishCurr.PointerToRelocations;
851 ibBuffer >> ishCurr.PointerToLinenumbers; 851 ibBuffer >> ishCurr.PointerToLinenumbers;
852 ibBuffer >> ishCurr.NumberOfRelocations; 852 ibBuffer >> ishCurr.NumberOfRelocations;
853 ibBuffer >> ishCurr.NumberOfLinenumbers; 853 ibBuffer >> ishCurr.NumberOfLinenumbers;
854 ibBuffer >> ishCurr.Characteristics; 854 ibBuffer >> ishCurr.Characteristics;
855 vIshdCurr.push_back(ishCurr); 855 vIshdCurr.push_back(ishCurr);
856 } 856 }
857 857
858 return vIshdCurr; 858 return vIshdCurr;
859 } 859 }
860 860
861 template<int x> 861 template<int x>
862 int PeHeaderT<x>::read(const unsigned char* pcBuffer, unsigned int uiSize, unsigned int uiOffset) 862 int PeHeaderT<x>::read(const unsigned char* pcBuffer, unsigned int uiSize, unsigned int uiOffset)
863 { 863 {
864 if (uiSize < m_inthHeader.size()) 864 if (uiSize < m_inthHeader.size())
865 { 865 {
866 return ERROR_INVALID_FILE; 866 return ERROR_INVALID_FILE;
867 } 867 }
868 868
869 std::vector<unsigned char> vBuffer(pcBuffer, pcBuffer + m_inthHeader.size()); 869 std::vector<unsigned char> vBuffer(pcBuffer, pcBuffer + m_inthHeader.size());
870 870
871 InputBuffer ibBuffer(vBuffer); 871 InputBuffer ibBuffer(vBuffer);
872 PELIB_IMAGE_NT_HEADERS<x> header; 872 PELIB_IMAGE_NT_HEADERS<x> header;
873 873
874 readHeader(ibBuffer, header); 874 readHeader(ibBuffer, header);
875 875
876 if (uiSize < m_inthHeader.size() + header.OptionalHeader.NumberOfRvaAndSizes * 8 + header.FileHeader.NumberOfSections * 0x28) 876 if (uiSize < m_inthHeader.size() + header.OptionalHeader.NumberOfRvaAndSizes * 8 + header.FileHeader.NumberOfSections * 0x28)
877 { 877 {
878 return ERROR_INVALID_FILE; 878 return ERROR_INVALID_FILE;
879 } 879 }
880 880
881 vBuffer.resize(header.OptionalHeader.NumberOfRvaAndSizes * 8 + header.FileHeader.NumberOfSections * 0x28); 881 vBuffer.resize(header.OptionalHeader.NumberOfRvaAndSizes * 8 + header.FileHeader.NumberOfSections * 0x28);
882 vBuffer.assign(pcBuffer + m_inthHeader.size(), pcBuffer + m_inthHeader.size() + header.OptionalHeader.NumberOfRvaAndSizes * 8 + header.FileHeader.NumberOfSections * 0x28); 882 vBuffer.assign(pcBuffer + m_inthHeader.size(), pcBuffer + m_inthHeader.size() + header.OptionalHeader.NumberOfRvaAndSizes * 8 + header.FileHeader.NumberOfSections * 0x28);
883 883
884 ibBuffer.setBuffer(vBuffer); 884 ibBuffer.setBuffer(vBuffer);
885 885
886 readDataDirectories(ibBuffer, header); 886 readDataDirectories(ibBuffer, header);
887 887
888 m_vIsh = readSections(ibBuffer, header); 888 m_vIsh = readSections(ibBuffer, header);
889 889
890 std::swap(m_inthHeader, header); 890 std::swap(m_inthHeader, header);
891 891
892 m_uiOffset = uiOffset; 892 m_uiOffset = uiOffset;
893 893
894 return NO_ERROR; 894 return NO_ERROR;
895 } 895 }
896 896
897 /** 897 /**
898 * Reads the PE header from a file Note that this function does not verify if a file is actually a MZ file. 898 * Reads the PE header from a file Note that this function does not verify if a file is actually a MZ file.
899 * For this purpose see #PeLib::PeHeaderT<x>::isValid. The only check this function makes is a check to see if 899 * For this purpose see #PeLib::PeHeaderT<x>::isValid. The only check this function makes is a check to see if
900 * the file is large enough to be a PE header. If the data is valid doesn't matter. 900 * the file is large enough to be a PE header. If the data is valid doesn't matter.
901 * @param strFilename Name of the file which will be read. 901 * @param strFilename Name of the file which will be read.
902 * @param uiOffset File offset of PE header (see #PeLib::MzHeader::getAddressOfPeHeader). 902 * @param uiOffset File offset of PE header (see #PeLib::MzHeader::getAddressOfPeHeader).
903 **/ 903 **/
904 template<int x> 904 template<int x>
905 int PeHeaderT<x>::read(std::string strFilename, unsigned int uiOffset) 905 int PeHeaderT<x>::read(std::string strFilename, unsigned int uiOffset)
906 { 906 {
907 std::ifstream ifFile(strFilename.c_str(), std::ios::binary); 907 std::ifstream ifFile(strFilename.c_str(), std::ios::binary);
908 908
909 if (!ifFile) 909 if (!ifFile)
910 { 910 {
911 return ERROR_OPENING_FILE; 911 return ERROR_OPENING_FILE;
912 } 912 }
913 913
914 // File too small 914 // File too small
915 if (fileSize(ifFile) < uiOffset + m_inthHeader.size()) 915 if (fileSize(ifFile) < uiOffset + m_inthHeader.size())
916 { 916 {
917 return ERROR_INVALID_FILE; 917 return ERROR_INVALID_FILE;
918 } 918 }
919 919
920 std::vector<unsigned char> vBuffer(m_inthHeader.size()); 920 std::vector<unsigned char> vBuffer(m_inthHeader.size());
921 921
922 ifFile.seekg(uiOffset, std::ios::beg); 922 ifFile.seekg(uiOffset, std::ios::beg);
923 ifFile.read(reinterpret_cast<char*>(&vBuffer[0]), static_cast<std::streamsize>(vBuffer.size())); 923 ifFile.read(reinterpret_cast<char*>(&vBuffer[0]), static_cast<std::streamsize>(vBuffer.size()));
924 924
925 InputBuffer ibBuffer(vBuffer); 925 InputBuffer ibBuffer(vBuffer);
926 PELIB_IMAGE_NT_HEADERS<x> header; 926 PELIB_IMAGE_NT_HEADERS<x> header;
927 927
928 readHeader(ibBuffer, header); 928 readHeader(ibBuffer, header);
929 929
930 vBuffer.resize(header.OptionalHeader.NumberOfRvaAndSizes * 8 + header.FileHeader.NumberOfSections * 0x28); 930 vBuffer.resize(header.OptionalHeader.NumberOfRvaAndSizes * 8 + header.FileHeader.NumberOfSections * 0x28);
931 931
932 ifFile.read(reinterpret_cast<char*>(&vBuffer[0]), static_cast<std::streamsize>(vBuffer.size())); 932 ifFile.read(reinterpret_cast<char*>(&vBuffer[0]), static_cast<std::streamsize>(vBuffer.size()));
933 if (!ifFile) 933 if (!ifFile)
934 { 934 {
935 return ERROR_INVALID_FILE; 935 return ERROR_INVALID_FILE;
936 } 936 }
937 937
938 ibBuffer.setBuffer(vBuffer); 938 ibBuffer.setBuffer(vBuffer);
939 939
940 readDataDirectories(ibBuffer, header); 940 readDataDirectories(ibBuffer, header);
941 941
942 // Sections 942 // Sections
943// const unsigned int nrSections = header.FileHeader.NumberOfSections; 943// const unsigned int nrSections = header.FileHeader.NumberOfSections;
944// if (fileSize(ifFile) < uiOffset + m_inthHeader.size() + nrSections * PELIB_IMAGE_SECTION_HEADER::size()) 944// if (fileSize(ifFile) < uiOffset + m_inthHeader.size() + nrSections * PELIB_IMAGE_SECTION_HEADER::size())
945// { 945// {
946// return ERROR_INVALID_FILE; 946// return ERROR_INVALID_FILE;
947// } 947// }
948 948
949 m_vIsh = readSections(ibBuffer, header); 949 m_vIsh = readSections(ibBuffer, header);
950 950
951 std::swap(m_inthHeader, header); 951 std::swap(m_inthHeader, header);
952 952
953 m_uiOffset = uiOffset; 953 m_uiOffset = uiOffset;
954 954
955 ifFile.close(); 955 ifFile.close();
956 956
957 return NO_ERROR; 957 return NO_ERROR;
958 } 958 }
959 959
960 /** 960 /**
961 * Rebuilds the PE header so that it can be written to a file. It's not guaranteed that the 961 * Rebuilds the PE header so that it can be written to a file. It's not guaranteed that the
962 * header will be valid. If you want to make sure that the header will be valid you 962 * header will be valid. If you want to make sure that the header will be valid you
963 * must call #PeLib::PeHeaderT<x>::makeValid first. 963 * must call #PeLib::PeHeaderT<x>::makeValid first.
964 * @param vBuffer Buffer where the rebuilt header will be stored. 964 * @param vBuffer Buffer where the rebuilt header will be stored.
965 **/ 965 **/
966 template<int x> 966 template<int x>
967 void PeHeaderT<x>::rebuild(std::vector<byte>& vBuffer) const 967 void PeHeaderT<x>::rebuild(std::vector<byte>& vBuffer) const
968 { 968 {
969 OutputBuffer obBuffer(vBuffer); 969 OutputBuffer obBuffer(vBuffer);
970 970
971 obBuffer << m_inthHeader.Signature; 971 obBuffer << m_inthHeader.Signature;
972 972
973 obBuffer << m_inthHeader.FileHeader.Machine; 973 obBuffer << m_inthHeader.FileHeader.Machine;
974 obBuffer << m_inthHeader.FileHeader.NumberOfSections; 974 obBuffer << m_inthHeader.FileHeader.NumberOfSections;
975 obBuffer << m_inthHeader.FileHeader.TimeDateStamp; 975 obBuffer << m_inthHeader.FileHeader.TimeDateStamp;
976 obBuffer << m_inthHeader.FileHeader.PointerToSymbolTable; 976 obBuffer << m_inthHeader.FileHeader.PointerToSymbolTable;
977 obBuffer << m_inthHeader.FileHeader.NumberOfSymbols; 977 obBuffer << m_inthHeader.FileHeader.NumberOfSymbols;
978 obBuffer << m_inthHeader.FileHeader.SizeOfOptionalHeader; 978 obBuffer << m_inthHeader.FileHeader.SizeOfOptionalHeader;
979 obBuffer << m_inthHeader.FileHeader.Characteristics; 979 obBuffer << m_inthHeader.FileHeader.Characteristics;
980 obBuffer << m_inthHeader.OptionalHeader.Magic; 980 obBuffer << m_inthHeader.OptionalHeader.Magic;
981 obBuffer << m_inthHeader.OptionalHeader.MajorLinkerVersion; 981 obBuffer << m_inthHeader.OptionalHeader.MajorLinkerVersion;
982 obBuffer << m_inthHeader.OptionalHeader.MinorLinkerVersion; 982 obBuffer << m_inthHeader.OptionalHeader.MinorLinkerVersion;
983 obBuffer << m_inthHeader.OptionalHeader.SizeOfCode; 983 obBuffer << m_inthHeader.OptionalHeader.SizeOfCode;
984 obBuffer << m_inthHeader.OptionalHeader.SizeOfInitializedData; 984 obBuffer << m_inthHeader.OptionalHeader.SizeOfInitializedData;
985 obBuffer << m_inthHeader.OptionalHeader.SizeOfUninitializedData; 985 obBuffer << m_inthHeader.OptionalHeader.SizeOfUninitializedData;
986 obBuffer << m_inthHeader.OptionalHeader.AddressOfEntryPoint; 986 obBuffer << m_inthHeader.OptionalHeader.AddressOfEntryPoint;
987 obBuffer << m_inthHeader.OptionalHeader.BaseOfCode; 987 obBuffer << m_inthHeader.OptionalHeader.BaseOfCode;
988 rebuildBaseOfData(obBuffer); 988 rebuildBaseOfData(obBuffer);
989// obBuffer << m_inthHeader.OptionalHeader.BaseOfData; 989// obBuffer << m_inthHeader.OptionalHeader.BaseOfData;
990 obBuffer << m_inthHeader.OptionalHeader.ImageBase; 990 obBuffer << m_inthHeader.OptionalHeader.ImageBase;
991 obBuffer << m_inthHeader.OptionalHeader.SectionAlignment; 991 obBuffer << m_inthHeader.OptionalHeader.SectionAlignment;
992 obBuffer << m_inthHeader.OptionalHeader.FileAlignment; 992 obBuffer << m_inthHeader.OptionalHeader.FileAlignment;
993 obBuffer << m_inthHeader.OptionalHeader.MajorOperatingSystemVersion; 993 obBuffer << m_inthHeader.OptionalHeader.MajorOperatingSystemVersion;
994 obBuffer << m_inthHeader.OptionalHeader.MinorOperatingSystemVersion; 994 obBuffer << m_inthHeader.OptionalHeader.MinorOperatingSystemVersion;
995 obBuffer << m_inthHeader.OptionalHeader.MajorImageVersion; 995 obBuffer << m_inthHeader.OptionalHeader.MajorImageVersion;
996 obBuffer << m_inthHeader.OptionalHeader.MinorImageVersion; 996 obBuffer << m_inthHeader.OptionalHeader.MinorImageVersion;
997 obBuffer << m_inthHeader.OptionalHeader.MajorSubsystemVersion; 997 obBuffer << m_inthHeader.OptionalHeader.MajorSubsystemVersion;
998 obBuffer << m_inthHeader.OptionalHeader.MinorSubsystemVersion; 998 obBuffer << m_inthHeader.OptionalHeader.MinorSubsystemVersion;
999 obBuffer << m_inthHeader.OptionalHeader.Win32VersionValue; 999 obBuffer << m_inthHeader.OptionalHeader.Win32VersionValue;
1000 obBuffer << m_inthHeader.OptionalHeader.SizeOfImage; 1000 obBuffer << m_inthHeader.OptionalHeader.SizeOfImage;
1001 obBuffer << m_inthHeader.OptionalHeader.SizeOfHeaders; 1001 obBuffer << m_inthHeader.OptionalHeader.SizeOfHeaders;
1002 obBuffer << m_inthHeader.OptionalHeader.CheckSum; 1002 obBuffer << m_inthHeader.OptionalHeader.CheckSum;
1003 obBuffer << m_inthHeader.OptionalHeader.Subsystem; 1003 obBuffer << m_inthHeader.OptionalHeader.Subsystem;
1004 obBuffer << m_inthHeader.OptionalHeader.DllCharacteristics; 1004 obBuffer << m_inthHeader.OptionalHeader.DllCharacteristics;
1005 obBuffer << m_inthHeader.OptionalHeader.SizeOfStackReserve; 1005 obBuffer << m_inthHeader.OptionalHeader.SizeOfStackReserve;
1006 obBuffer << m_inthHeader.OptionalHeader.SizeOfStackCommit; 1006 obBuffer << m_inthHeader.OptionalHeader.SizeOfStackCommit;
1007 obBuffer << m_inthHeader.OptionalHeader.SizeOfHeapReserve; 1007 obBuffer << m_inthHeader.OptionalHeader.SizeOfHeapReserve;
1008 obBuffer << m_inthHeader.OptionalHeader.SizeOfHeapCommit; 1008 obBuffer << m_inthHeader.OptionalHeader.SizeOfHeapCommit;
1009 obBuffer << m_inthHeader.OptionalHeader.LoaderFlags; 1009 obBuffer << m_inthHeader.OptionalHeader.LoaderFlags;
1010 obBuffer << m_inthHeader.OptionalHeader.NumberOfRvaAndSizes; 1010 obBuffer << m_inthHeader.OptionalHeader.NumberOfRvaAndSizes;
1011 1011
1012 // The 0x10 data directories 1012 // The 0x10 data directories
1013 for (unsigned int i=0;i<calcNumberOfRvaAndSizes();i++) 1013 for (unsigned int i=0;i<calcNumberOfRvaAndSizes();i++)
1014 { 1014 {
1015 obBuffer << m_inthHeader.dataDirectories[i].VirtualAddress; 1015 obBuffer << m_inthHeader.dataDirectories[i].VirtualAddress;
1016 obBuffer << m_inthHeader.dataDirectories[i].Size; 1016 obBuffer << m_inthHeader.dataDirectories[i].Size;
1017 } 1017 }
1018 1018
1019 // The section definitions 1019 // The section definitions
1020 const unsigned int nrSections = calcNumberOfSections(); 1020 const unsigned int nrSections = calcNumberOfSections();
1021 for (unsigned int i=0;i<nrSections;i++) 1021 for (unsigned int i=0;i<nrSections;i++)
1022 { 1022 {
1023 char temp[9] = {0}; 1023 char temp[9] = {0};
1024 strcpy(temp, getSectionName(i).c_str()); 1024 strcpy(temp, getSectionName(i).c_str());
1025 obBuffer.add(temp, 8); 1025 obBuffer.add(temp, 8);
1026 obBuffer << m_vIsh[i].VirtualSize; 1026 obBuffer << m_vIsh[i].VirtualSize;
1027 obBuffer << m_vIsh[i].VirtualAddress; 1027 obBuffer << m_vIsh[i].VirtualAddress;
1028 obBuffer << m_vIsh[i].SizeOfRawData; 1028 obBuffer << m_vIsh[i].SizeOfRawData;
1029 obBuffer << m_vIsh[i].PointerToRawData; 1029 obBuffer << m_vIsh[i].PointerToRawData;
1030 obBuffer << m_vIsh[i].PointerToRelocations; 1030 obBuffer << m_vIsh[i].PointerToRelocations;
1031 obBuffer << m_vIsh[i].PointerToLinenumbers; 1031 obBuffer << m_vIsh[i].PointerToLinenumbers;
1032 obBuffer << m_vIsh[i].NumberOfRelocations; 1032 obBuffer << m_vIsh[i].NumberOfRelocations;
1033 obBuffer << m_vIsh[i].NumberOfLinenumbers; 1033 obBuffer << m_vIsh[i].NumberOfLinenumbers;
1034 obBuffer << m_vIsh[i].Characteristics; 1034 obBuffer << m_vIsh[i].Characteristics;
1035 } 1035 }
1036 } 1036 }
1037 1037
1038 /** 1038 /**
1039 * Converts a relative virtual offset to a file offset. 1039 * Converts a relative virtual offset to a file offset.
1040 * @param dwRva A relative virtual offset. 1040 * @param dwRva A relative virtual offset.
1041 * @return A file offset. 1041 * @return A file offset.
1042 * \todo It's not always 0x1000. 1042 * \todo It's not always 0x1000.
1043 **/ 1043 **/
1044 template<int x> 1044 template<int x>
1045 typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::rvaToOffset(VAR4_8 dwRva) const 1045 typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::rvaToOffset(VAR4_8 dwRva) const
1046 { 1046 {
1047 // XXX: Not correct 1047 // XXX: Not correct
1048 if (dwRva < 0x1000) return dwRva; 1048 if (dwRva < 0x1000) return dwRva;
1049 1049
1050 PeLib::word uiSecnr = getSectionWithRva(dwRva); 1050 PeLib::word uiSecnr = getSectionWithRva(dwRva);
1051 if (uiSecnr == 0xFFFF || dwRva > getVirtualAddress(uiSecnr) + getSizeOfRawData(uiSecnr)) 1051 if (uiSecnr == 0xFFFF || dwRva > getVirtualAddress(uiSecnr) + getSizeOfRawData(uiSecnr))
1052 { 1052 {
1053 return std::numeric_limits<VAR4_8>::max(); 1053 return std::numeric_limits<VAR4_8>::max();
1054 } 1054 }
1055 1055
1056 return getPointerToRawData(uiSecnr) + dwRva - getVirtualAddress(uiSecnr); 1056 return getPointerToRawData(uiSecnr) + dwRva - getVirtualAddress(uiSecnr);
1057 } 1057 }
1058 1058
1059 /** 1059 /**
1060 * Converts a relative virtual offset to a virtual offset. 1060 * Converts a relative virtual offset to a virtual offset.
1061 * @param dwRva A relative virtual offset. 1061 * @param dwRva A relative virtual offset.
1062 * @return A virtual offset. 1062 * @return A virtual offset.
1063 **/ 1063 **/
1064 template<int x> 1064 template<int x>
1065 typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::rvaToVa(VAR4_8 dwRva) const 1065 typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::rvaToVa(VAR4_8 dwRva) const
1066 { 1066 {
1067 return getImageBase() + dwRva; 1067 return getImageBase() + dwRva;
1068 } 1068 }
1069 1069
1070 /** 1070 /**
1071 * Calculates the size of the current PE header. This includes the actual header and the section definitions. 1071 * Calculates the size of the current PE header. This includes the actual header and the section definitions.
1072 * @return Size of the current PE header. 1072 * @return Size of the current PE header.
1073 * \todo Better handling of files with less than 0x10 directories. 1073 * \todo Better handling of files with less than 0x10 directories.
1074 **/ 1074 **/
1075 template<int x> 1075 template<int x>
1076 unsigned int PeHeaderT<x>::size() const 1076 unsigned int PeHeaderT<x>::size() const
1077 { 1077 {
1078 return m_inthHeader.size() + getNumberOfSections() * PELIB_IMAGE_SECTION_HEADER::size(); 1078 return m_inthHeader.size() + getNumberOfSections() * PELIB_IMAGE_SECTION_HEADER::size();
1079 } 1079 }
1080 1080
1081 // \todo Not sure if this works. 1081 // \todo Not sure if this works.
1082 template<int x> 1082 template<int x>
1083 typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::vaToRva(VAR4_8 dwRva) const 1083 typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::vaToRva(VAR4_8 dwRva) const
1084 { 1084 {
1085 if (dwRva - getImageBase() < calcStartOfCode()) return dwRva - getImageBase(); 1085 if (dwRva - getImageBase() < calcStartOfCode()) return dwRva - getImageBase();
1086 1086
1087 if (getSectionWithRva(dwRva - getImageBase()) == 0xFFFF) return -1; 1087 if (getSectionWithRva(dwRva - getImageBase()) == 0xFFFF) return -1;
1088 1088
1089 return dwRva - getImageBase(); 1089 return dwRva - getImageBase();
1090 } 1090 }
1091 1091
1092 template<int x> 1092 template<int x>
1093 typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::vaToOffset(VAR4_8 dwRva) const 1093 typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::vaToOffset(VAR4_8 dwRva) const
1094 { 1094 {
1095 return rvaToOffset(dwRva - getImageBase()); 1095 return rvaToOffset(dwRva - getImageBase());
1096 } 1096 }
1097 1097
1098 /** 1098 /**
1099 * Saves the PE header to a file. Note that this only saves the header information, if you have added sections 1099 * Saves the PE header to a file. Note that this only saves the header information, if you have added sections
1100 * and want to save these to the file you have to call #PeLib::PeHeaderT<x>::saveSections too. This function also 1100 * and want to save these to the file you have to call #PeLib::PeHeaderT<x>::saveSections too. This function also
1101 * does not verify if the PE header is correct. If you want to make sure that the current PE header is valid, 1101 * does not verify if the PE header is correct. If you want to make sure that the current PE header is valid,
1102 * call #PeLib::PeHeaderT<x>::isValid and #PeLib::PeHeaderT<x>::makeValid first. 1102 * call #PeLib::PeHeaderT<x>::isValid and #PeLib::PeHeaderT<x>::makeValid first.
1103 * @param strFilename Filename of the file the header will be written to. 1103 * @param strFilename Filename of the file the header will be written to.
1104 * @param uiOffset File offset the header will be written to. 1104 * @param uiOffset File offset the header will be written to.
1105 **/ 1105 **/
1106 template<int x> 1106 template<int x>
1107 int PeHeaderT<x>::write(std::string strFilename, unsigned int uiOffset) const 1107 int PeHeaderT<x>::write(std::string strFilename, unsigned int uiOffset) const
1108 { 1108 {
1109 std::fstream ofFile(strFilename.c_str(), std::ios_base::in); 1109 std::fstream ofFile(strFilename.c_str(), std::ios_base::in);
1110 1110
1111 if (!ofFile) 1111 if (!ofFile)
1112 { 1112 {
1113 ofFile.clear(); 1113 ofFile.clear();
1114 ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary); 1114 ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary);
1115 } 1115 }
1116 else 1116 else
1117 { 1117 {
1118 ofFile.close(); 1118 ofFile.close();
1119 ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary); 1119 ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary);
1120 } 1120 }
1121 1121
1122 if (!ofFile) 1122 if (!ofFile)
1123 { 1123 {
1124 return ERROR_OPENING_FILE; 1124 return ERROR_OPENING_FILE;
1125 } 1125 }
1126 1126
1127 ofFile.seekp(uiOffset, std::ios::beg); 1127 ofFile.seekp(uiOffset, std::ios::beg);
1128 1128
1129 std::vector<unsigned char> vBuffer; 1129 std::vector<unsigned char> vBuffer;
1130 1130
1131 rebuild(vBuffer); 1131 rebuild(vBuffer);
1132 1132
1133 ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), static_cast<unsigned int>(vBuffer.size())); 1133 ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), static_cast<unsigned int>(vBuffer.size()));
1134 1134
1135 ofFile.close(); 1135 ofFile.close();
1136 1136
1137 return NO_ERROR; 1137 return NO_ERROR;
1138 } 1138 }
1139 1139
1140 1140
1141 /** 1141 /**
1142 * Overwrites a section's data. 1142 * Overwrites a section's data.
1143 * @param wSecnr Number of the section which will be overwritten. 1143 * @param wSecnr Number of the section which will be overwritten.
1144 * @param strFilename Name of the file where the section will be written to. 1144 * @param strFilename Name of the file where the section will be written to.
1145 * @param wSecnr Number of the section that will be written. 1145 * @param wSecnr Number of the section that will be written.
1146 * @param vBuffer New data of the section. 1146 * @param vBuffer New data of the section.
1147 **/ 1147 **/
1148 template<int x> 1148 template<int x>
1149 int PeHeaderT<x>::writeSectionData(const std::string& strFilename, word wSecnr, const std::vector<byte>& vBuffer) const 1149 int PeHeaderT<x>::writeSectionData(const std::string& strFilename, word wSecnr, const std::vector<byte>& vBuffer) const
1150 { 1150 {
1151 std::fstream ofFile(strFilename.c_str(), std::ios_base::in); 1151 std::fstream ofFile(strFilename.c_str(), std::ios_base::in);
1152 1152
1153 if (!ofFile) 1153 if (!ofFile)
1154 { 1154 {
1155 ofFile.clear(); 1155 ofFile.clear();
1156 ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary); 1156 ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary);
1157 } 1157 }
1158 else 1158 else
1159 { 1159 {
1160 ofFile.close(); 1160 ofFile.close();
1161 ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary); 1161 ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary);
1162 } 1162 }
1163 1163
1164 if (!ofFile) 1164 if (!ofFile)
1165 { 1165 {
1166 ofFile.clear(); 1166 ofFile.clear();
1167 1167
1168 return ERROR_OPENING_FILE; 1168 return ERROR_OPENING_FILE;
1169 } 1169 }
1170 1170
1171 ofFile.seekp(getPointerToRawData(wSecnr), std::ios::beg); 1171 ofFile.seekp(getPointerToRawData(wSecnr), std::ios::beg);
1172 1172
1173 ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), std::min(static_cast<unsigned int>(vBuffer.size()), getSizeOfRawData(wSecnr))); 1173 ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), std::min(static_cast<unsigned int>(vBuffer.size()), getSizeOfRawData(wSecnr)));
1174 1174
1175 ofFile.close(); 1175 ofFile.close();
1176 1176
1177 return NO_ERROR; 1177 return NO_ERROR;
1178 } 1178 }
1179 1179
1180 template<int x> 1180 template<int x>
1181 int PeHeaderT<x>::writeSections(const std::string& strFilename) const 1181 int PeHeaderT<x>::writeSections(const std::string& strFilename) const
1182 { 1182 {
1183 std::fstream ofFile(strFilename.c_str(), std::ios_base::in); 1183 std::fstream ofFile(strFilename.c_str(), std::ios_base::in);
1184 1184
1185 if (!ofFile) 1185 if (!ofFile)
1186 { 1186 {
1187 ofFile.clear(); 1187 ofFile.clear();
1188 ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary); 1188 ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary);
1189 } 1189 }
1190 else 1190 else
1191 { 1191 {
1192 ofFile.close(); 1192 ofFile.close();
1193 ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary); 1193 ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary);
1194 } 1194 }
1195 1195
1196 if (!ofFile) 1196 if (!ofFile)
1197 { 1197 {
1198 return ERROR_OPENING_FILE; 1198 return ERROR_OPENING_FILE;
1199 } 1199 }
1200 1200
1201 unsigned int uiFilesize = fileSize(ofFile); 1201 unsigned int uiFilesize = fileSize(ofFile);
1202 1202
1203 for (int i=0;i<calcNumberOfSections();i++) 1203 for (int i=0;i<calcNumberOfSections();i++)
1204 { 1204 {
1205 if (uiFilesize < getPointerToRawData(i) + getSizeOfRawData(i)) 1205 if (uiFilesize < getPointerToRawData(i) + getSizeOfRawData(i))
1206 { 1206 {
1207 unsigned int uiToWrite = getPointerToRawData(i) + getSizeOfRawData(i) - uiFilesize; 1207 unsigned int uiToWrite = getPointerToRawData(i) + getSizeOfRawData(i) - uiFilesize;
1208 std::vector<char> vBuffer(uiToWrite); 1208 std::vector<char> vBuffer(uiToWrite);
1209 ofFile.seekp(0, std::ios::end); 1209 ofFile.seekp(0, std::ios::end);
1210 ofFile.write(&vBuffer[0], static_cast<unsigned int>(vBuffer.size())); 1210 ofFile.write(&vBuffer[0], static_cast<unsigned int>(vBuffer.size()));
1211 uiFilesize = getPointerToRawData(i) + getSizeOfRawData(i); 1211 uiFilesize = getPointerToRawData(i) + getSizeOfRawData(i);
1212 } 1212 }
1213 } 1213 }
1214 1214
1215 ofFile.close(); 1215 ofFile.close();
1216 1216
1217 return NO_ERROR; 1217 return NO_ERROR;
1218 } 1218 }
1219 1219
1220 /** 1220 /**
1221 * Returns the file's Nt signature. 1221 * Returns the file's Nt signature.
1222 * @return The Nt signature value from the PE header. 1222 * @return The Nt signature value from the PE header.
1223 **/ 1223 **/
1224 template<int x> 1224 template<int x>
1225 dword PeHeaderT<x>::getNtSignature() const 1225 dword PeHeaderT<x>::getNtSignature() const
1226 { 1226 {
1227 return m_inthHeader.Signature; 1227 return m_inthHeader.Signature;
1228 } 1228 }
1229 1229
1230 /** 1230 /**
1231 * Returns the file's machine. 1231 * Returns the file's machine.
1232 * @return The Machine value from the PE header. 1232 * @return The Machine value from the PE header.
1233 **/ 1233 **/
1234 template<int x> 1234 template<int x>
1235 word PeHeaderT<x>::getMachine() const 1235 word PeHeaderT<x>::getMachine() const
1236 { 1236 {
1237 return m_inthHeader.FileHeader.Machine; 1237 return m_inthHeader.FileHeader.Machine;
1238 } 1238 }
1239 1239
1240 1240
1241 /** 1241 /**
1242 * Returns the file's number of sections as defined in the header. Note that this value can be different 1242 * Returns the file's number of sections as defined in the header. Note that this value can be different
1243 * from the number of defined sections (#see PeLib::PeHeaderT<x>::getNumberOfSections). 1243 * from the number of defined sections (#see PeLib::PeHeaderT<x>::getNumberOfSections).
1244 * @return The NumberOfSections value from the PE header. 1244 * @return The NumberOfSections value from the PE header.
1245 **/ 1245 **/
1246 template<int x> 1246 template<int x>
1247 word PeHeaderT<x>::getNumberOfSections() const 1247 word PeHeaderT<x>::getNumberOfSections() const
1248 { 1248 {
1249 return m_inthHeader.FileHeader.NumberOfSections; 1249 return m_inthHeader.FileHeader.NumberOfSections;
1250 } 1250 }
1251 1251
1252 /** 1252 /**
1253 * Returns the file's TimeDateStamp. 1253 * Returns the file's TimeDateStamp.
1254 * @return The TimeDateStamp value from the PE header. 1254 * @return The TimeDateStamp value from the PE header.
1255 **/ 1255 **/
1256 template<int x> 1256 template<int x>
1257 dword PeHeaderT<x>::getTimeDateStamp() const 1257 dword PeHeaderT<x>::getTimeDateStamp() const
1258 { 1258 {
1259 return m_inthHeader.FileHeader.TimeDateStamp; 1259 return m_inthHeader.FileHeader.TimeDateStamp;
1260 } 1260 }
1261 1261
1262 /** 1262 /**
1263 * Returns the relative virtual address of the file's symbol table. 1263 * Returns the relative virtual address of the file's symbol table.
1264 * @return The PointerToSymbolTable value from the PE header. 1264 * @return The PointerToSymbolTable value from the PE header.
1265 **/ 1265 **/
1266 template<int x> 1266 template<int x>
1267 dword PeHeaderT<x>::getPointerToSymbolTable() const 1267 dword PeHeaderT<x>::getPointerToSymbolTable() const
1268 { 1268 {
1269 return m_inthHeader.FileHeader.PointerToSymbolTable; 1269 return m_inthHeader.FileHeader.PointerToSymbolTable;
1270 } 1270 }
1271 1271
1272 /** 1272 /**
1273 * Returns the number of symbols of the file's symbol table. 1273 * Returns the number of symbols of the file's symbol table.
1274 * @return The NumberOfSymbols value from the PE header. 1274 * @return The NumberOfSymbols value from the PE header.
1275 **/ 1275 **/
1276 template<int x> 1276 template<int x>
1277 dword PeHeaderT<x>::getNumberOfSymbols() const 1277 dword PeHeaderT<x>::getNumberOfSymbols() const
1278 { 1278 {
1279 return m_inthHeader.FileHeader.NumberOfSymbols; 1279 return m_inthHeader.FileHeader.NumberOfSymbols;
1280 } 1280 }
1281 1281
1282 /** 1282 /**
1283 * Returns the size of optional header of the file. 1283 * Returns the size of optional header of the file.
1284 * @return The SizeOfOptionalHeader value from the PE header. 1284 * @return The SizeOfOptionalHeader value from the PE header.
1285 **/ 1285 **/
1286 template<int x> 1286 template<int x>
1287 word PeHeaderT<x>::getSizeOfOptionalHeader() const 1287 word PeHeaderT<x>::getSizeOfOptionalHeader() const
1288 { 1288 {
1289 return m_inthHeader.FileHeader.SizeOfOptionalHeader; 1289 return m_inthHeader.FileHeader.SizeOfOptionalHeader;
1290 } 1290 }
1291 1291
1292 /** 1292 /**
1293 * @return The Characteristics value from the PE header. 1293 * @return The Characteristics value from the PE header.
1294 **/ 1294 **/
1295 template<int x> 1295 template<int x>
1296 word PeHeaderT<x>::getCharacteristics() const 1296 word PeHeaderT<x>::getCharacteristics() const
1297 { 1297 {
1298 return m_inthHeader.FileHeader.Characteristics; 1298 return m_inthHeader.FileHeader.Characteristics;
1299 } 1299 }
1300 1300
1301 /** 1301 /**
1302 * @return The Magic value from the PE header. 1302 * @return The Magic value from the PE header.
1303 **/ 1303 **/
1304 template<int x> 1304 template<int x>
1305 word PeHeaderT<x>::getMagic() const 1305 word PeHeaderT<x>::getMagic() const
1306 { 1306 {
1307 return m_inthHeader.OptionalHeader.Magic; 1307 return m_inthHeader.OptionalHeader.Magic;
1308 } 1308 }
1309 1309
1310 /** 1310 /**
1311 * @return The MajorLinkerVersion value from the PE header. 1311 * @return The MajorLinkerVersion value from the PE header.
1312 **/ 1312 **/
1313 template<int x> 1313 template<int x>
1314 byte PeHeaderT<x>::getMajorLinkerVersion() const 1314 byte PeHeaderT<x>::getMajorLinkerVersion() const
1315 { 1315 {
1316 return m_inthHeader.OptionalHeader.MajorLinkerVersion; 1316 return m_inthHeader.OptionalHeader.MajorLinkerVersion;
1317 } 1317 }
1318 1318
1319 /** 1319 /**
1320 * @return The MinorLinkerVersion value from the PE header. 1320 * @return The MinorLinkerVersion value from the PE header.
1321 **/ 1321 **/
1322 template<int x> 1322 template<int x>
1323 byte PeHeaderT<x>::getMinorLinkerVersion() const 1323 byte PeHeaderT<x>::getMinorLinkerVersion() const
1324 { 1324 {
1325 return m_inthHeader.OptionalHeader.MinorLinkerVersion; 1325 return m_inthHeader.OptionalHeader.MinorLinkerVersion;
1326 } 1326 }
1327 1327
1328 /** 1328 /**
1329 * @return The SizeOfCode value from the PE header. 1329 * @return The SizeOfCode value from the PE header.
1330 **/ 1330 **/
1331 template<int x> 1331 template<int x>
1332 dword PeHeaderT<x>::getSizeOfCode() const 1332 dword PeHeaderT<x>::getSizeOfCode() const
1333 { 1333 {
1334 return m_inthHeader.OptionalHeader.SizeOfCode; 1334 return m_inthHeader.OptionalHeader.SizeOfCode;
1335 } 1335 }
1336 1336
1337 /** 1337 /**
1338 * @return The SizeOfInitializedData value from the PE header. 1338 * @return The SizeOfInitializedData value from the PE header.
1339 **/ 1339 **/
1340 template<int x> 1340 template<int x>
1341 dword PeHeaderT<x>::getSizeOfInitializedData() const 1341 dword PeHeaderT<x>::getSizeOfInitializedData() const
1342 { 1342 {
1343 return m_inthHeader.OptionalHeader.SizeOfInitializedData; 1343 return m_inthHeader.OptionalHeader.SizeOfInitializedData;
1344 } 1344 }
1345 1345
1346 /** 1346 /**
1347 * @return The SizeOfUninitializedData value from the PE header. 1347 * @return The SizeOfUninitializedData value from the PE header.
1348 **/ 1348 **/
1349 template<int x> 1349 template<int x>
1350 dword PeHeaderT<x>::getSizeOfUninitializedData() const 1350 dword PeHeaderT<x>::getSizeOfUninitializedData() const
1351 { 1351 {
1352 return m_inthHeader.OptionalHeader.SizeOfUninitializedData; 1352 return m_inthHeader.OptionalHeader.SizeOfUninitializedData;
1353 } 1353 }
1354 1354
1355 /** 1355 /**
1356 * @return The AddressOfEntryPoint value from the PE header. 1356 * @return The AddressOfEntryPoint value from the PE header.
1357 **/ 1357 **/
1358 template<int x> 1358 template<int x>
1359 dword PeHeaderT<x>::getAddressOfEntryPoint() const 1359 dword PeHeaderT<x>::getAddressOfEntryPoint() const
1360 { 1360 {
1361 return m_inthHeader.OptionalHeader.AddressOfEntryPoint; 1361 return m_inthHeader.OptionalHeader.AddressOfEntryPoint;
1362 } 1362 }
1363 1363
1364 /** 1364 /**
1365 * @return The BaseOfCode value from the PE header. 1365 * @return The BaseOfCode value from the PE header.
1366 **/ 1366 **/
1367 template<int x> 1367 template<int x>
1368 dword PeHeaderT<x>::getBaseOfCode() const 1368 dword PeHeaderT<x>::getBaseOfCode() const
1369 { 1369 {
1370 return m_inthHeader.OptionalHeader.BaseOfCode; 1370 return m_inthHeader.OptionalHeader.BaseOfCode;
1371 } 1371 }
1372 1372
1373 /** 1373 /**
1374 * @return The ImageBase value from the PE header. 1374 * @return The ImageBase value from the PE header.
1375 **/ 1375 **/
1376 template<int x> 1376 template<int x>
1377 typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::getImageBase() const 1377 typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::getImageBase() const
1378 { 1378 {
1379 return m_inthHeader.OptionalHeader.ImageBase; 1379 return m_inthHeader.OptionalHeader.ImageBase;
1380 } 1380 }
1381 1381
1382 /** 1382 /**
1383 * @return The SectionAlignment value from the PE header. 1383 * @return The SectionAlignment value from the PE header.
1384 **/ 1384 **/
1385 template<int x> 1385 template<int x>
1386 dword PeHeaderT<x>::getSectionAlignment() const 1386 dword PeHeaderT<x>::getSectionAlignment() const
1387 { 1387 {
1388 return m_inthHeader.OptionalHeader.SectionAlignment; 1388 return m_inthHeader.OptionalHeader.SectionAlignment;
1389 } 1389 }
1390 1390
1391 /** 1391 /**
1392 * @return The FileAlignment value from the PE header. 1392 * @return The FileAlignment value from the PE header.
1393 **/ 1393 **/
1394 template<int x> 1394 template<int x>
1395 dword PeHeaderT<x>::getFileAlignment() const 1395 dword PeHeaderT<x>::getFileAlignment() const
1396 { 1396 {
1397 return m_inthHeader.OptionalHeader.FileAlignment; 1397 return m_inthHeader.OptionalHeader.FileAlignment;
1398 } 1398 }
1399 1399
1400 /** 1400 /**
1401 * @return The MajorOperatingSystemVersion value from the PE header. 1401 * @return The MajorOperatingSystemVersion value from the PE header.
1402 **/ 1402 **/
1403 template<int x> 1403 template<int x>
1404 word PeHeaderT<x>::getMajorOperatingSystemVersion() const 1404 word PeHeaderT<x>::getMajorOperatingSystemVersion() const
1405 { 1405 {
1406 return m_inthHeader.OptionalHeader.MajorOperatingSystemVersion; 1406 return m_inthHeader.OptionalHeader.MajorOperatingSystemVersion;
1407 } 1407 }
1408 1408
1409 /** 1409 /**
1410 * @return The MinorOperatingSystemVersion value from the PE header. 1410 * @return The MinorOperatingSystemVersion value from the PE header.
1411 **/ 1411 **/
1412 template<int x> 1412 template<int x>
1413 word PeHeaderT<x>::getMinorOperatingSystemVersion() const 1413 word PeHeaderT<x>::getMinorOperatingSystemVersion() const
1414 { 1414 {
1415 return m_inthHeader.OptionalHeader.MinorOperatingSystemVersion; 1415 return m_inthHeader.OptionalHeader.MinorOperatingSystemVersion;
1416 } 1416 }
1417 1417
1418 /** 1418 /**
1419 * @return The MajorImageVersion value from the PE header. 1419 * @return The MajorImageVersion value from the PE header.
1420 **/ 1420 **/
1421 template<int x> 1421 template<int x>
1422 word PeHeaderT<x>::getMajorImageVersion() const 1422 word PeHeaderT<x>::getMajorImageVersion() const
1423 { 1423 {
1424 return m_inthHeader.OptionalHeader.MajorImageVersion; 1424 return m_inthHeader.OptionalHeader.MajorImageVersion;
1425 } 1425 }
1426 1426
1427 /** 1427 /**
1428 * @return The MinorImageVersion value from the PE header. 1428 * @return The MinorImageVersion value from the PE header.
1429 **/ 1429 **/
1430 template<int x> 1430 template<int x>
1431 word PeHeaderT<x>::getMinorImageVersion() const 1431 word PeHeaderT<x>::getMinorImageVersion() const
1432 { 1432 {
1433 return m_inthHeader.OptionalHeader.MinorImageVersion; 1433 return m_inthHeader.OptionalHeader.MinorImageVersion;
1434 } 1434 }
1435 1435
1436 /** 1436 /**
1437 * @return The MajorSubsystemVersion value from the PE header. 1437 * @return The MajorSubsystemVersion value from the PE header.
1438 **/ 1438 **/
1439 template<int x> 1439 template<int x>
1440 word PeHeaderT<x>::getMajorSubsystemVersion() const 1440 word PeHeaderT<x>::getMajorSubsystemVersion() const
1441 { 1441 {
1442 return m_inthHeader.OptionalHeader.MajorSubsystemVersion; 1442 return m_inthHeader.OptionalHeader.MajorSubsystemVersion;
1443 } 1443 }
1444 1444
1445 /** 1445 /**
1446 * @return The MinorSubsystemVersion value from the PE header. 1446 * @return The MinorSubsystemVersion value from the PE header.
1447 **/ 1447 **/
1448 template<int x> 1448 template<int x>
1449 word PeHeaderT<x>::getMinorSubsystemVersion() const 1449 word PeHeaderT<x>::getMinorSubsystemVersion() const
1450 { 1450 {
1451 return m_inthHeader.OptionalHeader.MinorSubsystemVersion; 1451 return m_inthHeader.OptionalHeader.MinorSubsystemVersion;
1452 } 1452 }
1453 1453
1454 /** 1454 /**
1455 * @return The WinVersionValue value from the PE header. 1455 * @return The WinVersionValue value from the PE header.
1456 **/ 1456 **/
1457 template<int x> 1457 template<int x>
1458 dword PeHeaderT<x>::getWin32VersionValue() const 1458 dword PeHeaderT<x>::getWin32VersionValue() const
1459 { 1459 {
1460 return m_inthHeader.OptionalHeader.Win32VersionValue; 1460 return m_inthHeader.OptionalHeader.Win32VersionValue;
1461 } 1461 }
1462 1462
1463 /** 1463 /**
1464 * @return The SizeOfImage value from the PE header. 1464 * @return The SizeOfImage value from the PE header.
1465 **/ 1465 **/
1466 template<int x> 1466 template<int x>
1467 dword PeHeaderT<x>::getSizeOfImage() const 1467 dword PeHeaderT<x>::getSizeOfImage() const
1468 { 1468 {
1469 return m_inthHeader.OptionalHeader.SizeOfImage; 1469 return m_inthHeader.OptionalHeader.SizeOfImage;
1470 } 1470 }
1471 1471
1472 /** 1472 /**
1473 * @return The SizeOfHeaders value from the PE header. 1473 * @return The SizeOfHeaders value from the PE header.
1474 **/ 1474 **/
1475 template<int x> 1475 template<int x>
1476 dword PeHeaderT<x>::getSizeOfHeaders() const 1476 dword PeHeaderT<x>::getSizeOfHeaders() const
1477 { 1477 {
1478 return m_inthHeader.OptionalHeader.SizeOfHeaders; 1478 return m_inthHeader.OptionalHeader.SizeOfHeaders;
1479 } 1479 }
1480 1480
1481 /** 1481 /**
1482 * @return The CheckSums value from the PE header. 1482 * @return The CheckSums value from the PE header.
1483 **/ 1483 **/
1484 template<int x> 1484 template<int x>
1485 dword PeHeaderT<x>::getCheckSum() const 1485 dword PeHeaderT<x>::getCheckSum() const
1486 { 1486 {
1487 return m_inthHeader.OptionalHeader.CheckSum; 1487 return m_inthHeader.OptionalHeader.CheckSum;
1488 } 1488 }
1489 1489
1490 /** 1490 /**
1491 * @return The Subsystem value from the PE header. 1491 * @return The Subsystem value from the PE header.
1492 **/ 1492 **/
1493 template<int x> 1493 template<int x>
1494 word PeHeaderT<x>::getSubsystem() const 1494 word PeHeaderT<x>::getSubsystem() const
1495 { 1495 {
1496 return m_inthHeader.OptionalHeader.Subsystem; 1496 return m_inthHeader.OptionalHeader.Subsystem;
1497 } 1497 }
1498 1498
1499 /** 1499 /**
1500 * @return The DllCharacteristics value from the PE header. 1500 * @return The DllCharacteristics value from the PE header.
1501 **/ 1501 **/
1502 template<int x> 1502 template<int x>
1503 word PeHeaderT<x>::getDllCharacteristics() const 1503 word PeHeaderT<x>::getDllCharacteristics() const
1504 { 1504 {
1505 return m_inthHeader.OptionalHeader.DllCharacteristics; 1505 return m_inthHeader.OptionalHeader.DllCharacteristics;
1506 } 1506 }
1507 1507
1508 /** 1508 /**
1509 * @return The SizeOfStackReserve value from the PE header. 1509 * @return The SizeOfStackReserve value from the PE header.
1510 **/ 1510 **/
1511 template<int x> 1511 template<int x>
1512 typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::getSizeOfStackReserve() const 1512 typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::getSizeOfStackReserve() const
1513 { 1513 {
1514 return m_inthHeader.OptionalHeader.SizeOfStackReserve; 1514 return m_inthHeader.OptionalHeader.SizeOfStackReserve;
1515 } 1515 }
1516 1516
1517 /** 1517 /**
1518 * @return The SizeOfStackCommit value from the PE header. 1518 * @return The SizeOfStackCommit value from the PE header.
1519 **/ 1519 **/
1520 template<int x> 1520 template<int x>
1521 typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::getSizeOfStackCommit() const 1521 typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::getSizeOfStackCommit() const
1522 { 1522 {
1523 return m_inthHeader.OptionalHeader.SizeOfStackCommit; 1523 return m_inthHeader.OptionalHeader.SizeOfStackCommit;
1524 } 1524 }
1525 1525
1526 /** 1526 /**
1527 * @return The SizeOfHeapReserve value from the PE header. 1527 * @return The SizeOfHeapReserve value from the PE header.
1528 **/ 1528 **/
1529 template<int x> 1529 template<int x>
1530 typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::getSizeOfHeapReserve() const 1530 typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::getSizeOfHeapReserve() const
1531 { 1531 {
1532 return m_inthHeader.OptionalHeader.SizeOfHeapReserve; 1532 return m_inthHeader.OptionalHeader.SizeOfHeapReserve;
1533 } 1533 }
1534 1534
1535 /** 1535 /**
1536 * @return The SizeOfHeapCommit value from the PE header. 1536 * @return The SizeOfHeapCommit value from the PE header.
1537 **/ 1537 **/
1538 template<int x> 1538 template<int x>
1539 typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::getSizeOfHeapCommit() const 1539 typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::getSizeOfHeapCommit() const
1540 { 1540 {
1541 return m_inthHeader.OptionalHeader.SizeOfHeapCommit; 1541 return m_inthHeader.OptionalHeader.SizeOfHeapCommit;
1542 } 1542 }
1543 1543
1544 /** 1544 /**
1545 * @return The LoaderFlags value from the PE header. 1545 * @return The LoaderFlags value from the PE header.
1546 **/ 1546 **/
1547 template<int x> 1547 template<int x>
1548 dword PeHeaderT<x>::getLoaderFlags() const 1548 dword PeHeaderT<x>::getLoaderFlags() const
1549 { 1549 {
1550 return m_inthHeader.OptionalHeader.LoaderFlags; 1550 return m_inthHeader.OptionalHeader.LoaderFlags;
1551 } 1551 }
1552 1552
1553 /** 1553 /**
1554 * @return The NumberOfRvaAndSizes value from the PE header. 1554 * @return The NumberOfRvaAndSizes value from the PE header.
1555 **/ 1555 **/
1556 template<int x> 1556 template<int x>
1557 dword PeHeaderT<x>::getNumberOfRvaAndSizes() const 1557 dword PeHeaderT<x>::getNumberOfRvaAndSizes() const
1558 { 1558 {
1559 return m_inthHeader.OptionalHeader.NumberOfRvaAndSizes; 1559 return m_inthHeader.OptionalHeader.NumberOfRvaAndSizes;
1560 } 1560 }
1561 1561
1562 template<int x> 1562 template<int x>
1563 dword PeHeaderT<x>::calcNumberOfRvaAndSizes() const 1563 dword PeHeaderT<x>::calcNumberOfRvaAndSizes() const
1564 { 1564 {
1565 return static_cast<dword>(m_inthHeader.dataDirectories.size()); 1565 return static_cast<dword>(m_inthHeader.dataDirectories.size());
1566 } 1566 }
1567 1567
1568 /** 1568 /**
1569 * Returns the relative virtual address of the current file's export directory. 1569 * Returns the relative virtual address of the current file's export directory.
1570 * @return The Rva of the Export directory. 1570 * @return The Rva of the Export directory.
1571 **/ 1571 **/
1572 template<int x> 1572 template<int x>
1573 dword PeHeaderT<x>::getIddExportRva() const 1573 dword PeHeaderT<x>::getIddExportRva() const
1574 { 1574 {
1575 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress; 1575 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
1576 } 1576 }
1577 1577
1578 /** 1578 /**
1579 * Returns the size of the current file's export directory. 1579 * Returns the size of the current file's export directory.
1580 * @return The sizeof the Export directory. 1580 * @return The sizeof the Export directory.
1581 **/ 1581 **/
1582 template<int x> 1582 template<int x>
1583 dword PeHeaderT<x>::getIddExportSize() const 1583 dword PeHeaderT<x>::getIddExportSize() const
1584 { 1584 {
1585 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_EXPORT].Size; 1585 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_EXPORT].Size;
1586 } 1586 }
1587 1587
1588 /** 1588 /**
1589 * Returns the relative virtual address of the current file's import directory. 1589 * Returns the relative virtual address of the current file's import directory.
1590 * @return The Rva of the Import directory. 1590 * @return The Rva of the Import directory.
1591 **/ 1591 **/
1592 template<int x> 1592 template<int x>
1593 dword PeHeaderT<x>::getIddImportRva() const 1593 dword PeHeaderT<x>::getIddImportRva() const
1594 { 1594 {
1595 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress; 1595 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress;
1596 } 1596 }
1597 1597
1598 /** 1598 /**
1599 * Returns the size of the current file's import directory. 1599 * Returns the size of the current file's import directory.
1600 * @return The size of the Import directory. 1600 * @return The size of the Import directory.
1601 **/ 1601 **/
1602 template<int x> 1602 template<int x>
1603 dword PeHeaderT<x>::getIddImportSize() const 1603 dword PeHeaderT<x>::getIddImportSize() const
1604 { 1604 {
1605 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_IMPORT].Size; 1605 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_IMPORT].Size;
1606 } 1606 }
1607 1607
1608 /** 1608 /**
1609 * Returns the relative virtual address of the current file's resource directory. 1609 * Returns the relative virtual address of the current file's resource directory.
1610 * @return The Rva of the Resource directory. 1610 * @return The Rva of the Resource directory.
1611 **/ 1611 **/
1612 template<int x> 1612 template<int x>
1613 dword PeHeaderT<x>::getIddResourceRva() const 1613 dword PeHeaderT<x>::getIddResourceRva() const
1614 { 1614 {
1615 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress; 1615 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress;
1616 } 1616 }
1617 1617
1618 /** 1618 /**
1619 * Returns the size of the current file'resource resource directory. 1619 * Returns the size of the current file'resource resource directory.
1620 * @return The size of the Resource directory. 1620 * @return The size of the Resource directory.
1621 **/ 1621 **/
1622 template<int x> 1622 template<int x>
1623 dword PeHeaderT<x>::getIddResourceSize() const 1623 dword PeHeaderT<x>::getIddResourceSize() const
1624 { 1624 {
1625 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_RESOURCE].Size; 1625 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_RESOURCE].Size;
1626 } 1626 }
1627 1627
1628 /** 1628 /**
1629 * Returns the relative virtual address of the current file's exception directory. 1629 * Returns the relative virtual address of the current file's exception directory.
1630 * @return The Rva of the Exception directory. 1630 * @return The Rva of the Exception directory.
1631 **/ 1631 **/
1632 template<int x> 1632 template<int x>
1633 dword PeHeaderT<x>::getIddExceptionRva() const 1633 dword PeHeaderT<x>::getIddExceptionRva() const
1634 { 1634 {
1635 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_EXCEPTION].VirtualAddress; 1635 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_EXCEPTION].VirtualAddress;
1636 } 1636 }
1637 1637
1638 /** 1638 /**
1639 * Returns the size of the current file's exception directory. 1639 * Returns the size of the current file's exception directory.
1640 * @return The size of the Exception directory. 1640 * @return The size of the Exception directory.
1641 **/ 1641 **/
1642 template<int x> 1642 template<int x>
1643 dword PeHeaderT<x>::getIddExceptionSize() const 1643 dword PeHeaderT<x>::getIddExceptionSize() const
1644 { 1644 {
1645 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_EXCEPTION].Size; 1645 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_EXCEPTION].Size;
1646 } 1646 }
1647 1647
1648 /** 1648 /**
1649 * Returns the relative virtual address of the current file's security directory. 1649 * Returns the relative virtual address of the current file's security directory.
1650 * @return The Rva of the Security directory. 1650 * @return The Rva of the Security directory.
1651 **/ 1651 **/
1652 template<int x> 1652 template<int x>
1653 dword PeHeaderT<x>::getIddSecurityRva() const 1653 dword PeHeaderT<x>::getIddSecurityRva() const
1654 { 1654 {
1655 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_SECURITY].VirtualAddress; 1655 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_SECURITY].VirtualAddress;
1656 } 1656 }
1657 1657
1658 /** 1658 /**
1659 * Returns the size of the current file's security directory. 1659 * Returns the size of the current file's security directory.
1660 * @return The size of the Security directory. 1660 * @return The size of the Security directory.
1661 **/ 1661 **/
1662 template<int x> 1662 template<int x>
1663 dword PeHeaderT<x>::getIddSecuritySize() const 1663 dword PeHeaderT<x>::getIddSecuritySize() const
1664 { 1664 {
1665 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_SECURITY].Size; 1665 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_SECURITY].Size;
1666 } 1666 }
1667 1667
1668 /** 1668 /**
1669 * Returns the relative virtual address of the current file's base reloc directory. 1669 * Returns the relative virtual address of the current file's base reloc directory.
1670 * @return The Rva of the Base Reloc directory. 1670 * @return The Rva of the Base Reloc directory.
1671 **/ 1671 **/
1672 template<int x> 1672 template<int x>
1673 dword PeHeaderT<x>::getIddBaseRelocRva() const 1673 dword PeHeaderT<x>::getIddBaseRelocRva() const
1674 { 1674 {
1675 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress; 1675 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress;
1676 } 1676 }
1677 1677
1678 /** 1678 /**
1679 * Returns the size of the current file's base reloc directory. 1679 * Returns the size of the current file's base reloc directory.
1680 * @return The size of the Base Reloc directory. 1680 * @return The size of the Base Reloc directory.
1681 **/ 1681 **/
1682 template<int x> 1682 template<int x>
1683 dword PeHeaderT<x>::getIddBaseRelocSize() const 1683 dword PeHeaderT<x>::getIddBaseRelocSize() const
1684 { 1684 {
1685 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_BASERELOC].Size; 1685 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_BASERELOC].Size;
1686 } 1686 }
1687 1687
1688 /** 1688 /**
1689 * Returns the relative virtual address of the current file's debug directory. 1689 * Returns the relative virtual address of the current file's debug directory.
1690 * @return The Rva of the Debug directory. 1690 * @return The Rva of the Debug directory.
1691 **/ 1691 **/
1692 template<int x> 1692 template<int x>
1693 dword PeHeaderT<x>::getIddDebugRva() const 1693 dword PeHeaderT<x>::getIddDebugRva() const
1694 { 1694 {
1695 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress; 1695 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress;
1696 } 1696 }
1697 1697
1698 /** 1698 /**
1699 * Returns the size of the current file's debug directory. 1699 * Returns the size of the current file's debug directory.
1700 * @return The size of the Debug directory. 1700 * @return The size of the Debug directory.
1701 **/ 1701 **/
1702 template<int x> 1702 template<int x>
1703 dword PeHeaderT<x>::getIddDebugSize() const 1703 dword PeHeaderT<x>::getIddDebugSize() const
1704 { 1704 {
1705 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_DEBUG].Size; 1705 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_DEBUG].Size;
1706 } 1706 }
1707 1707
1708 /** 1708 /**
1709 * Returns the relative virtual address of the current file's Architecture directory. 1709 * Returns the relative virtual address of the current file's Architecture directory.
1710 * @return The Rva of the Architecture directory. 1710 * @return The Rva of the Architecture directory.
1711 **/ 1711 **/
1712 template<int x> 1712 template<int x>
1713 dword PeHeaderT<x>::getIddArchitectureRva() const 1713 dword PeHeaderT<x>::getIddArchitectureRva() const
1714 { 1714 {
1715 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_ARCHITECTURE].VirtualAddress; 1715 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_ARCHITECTURE].VirtualAddress;
1716 } 1716 }
1717 1717
1718 /** 1718 /**
1719 * Returns the size of the current file's Architecture directory. 1719 * Returns the size of the current file's Architecture directory.
1720 * @return The size of the Architecture directory. 1720 * @return The size of the Architecture directory.
1721 **/ 1721 **/
1722 template<int x> 1722 template<int x>
1723 dword PeHeaderT<x>::getIddArchitectureSize() const 1723 dword PeHeaderT<x>::getIddArchitectureSize() const
1724 { 1724 {
1725 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_ARCHITECTURE].Size; 1725 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_ARCHITECTURE].Size;
1726 } 1726 }
1727 1727
1728 /** 1728 /**
1729 * Returns the relative virtual address of the current file's global ptr directory. 1729 * Returns the relative virtual address of the current file's global ptr directory.
1730 * @return The Rva of the GlobalPtr directory. 1730 * @return The Rva of the GlobalPtr directory.
1731 **/ 1731 **/
1732 template<int x> 1732 template<int x>
1733 dword PeHeaderT<x>::getIddGlobalPtrRva() const 1733 dword PeHeaderT<x>::getIddGlobalPtrRva() const
1734 { 1734 {
1735 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_GLOBALPTR].VirtualAddress; 1735 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_GLOBALPTR].VirtualAddress;
1736 } 1736 }
1737 1737
1738 /** 1738 /**
1739 * Returns the size of the current file's global ptr directory. 1739 * Returns the size of the current file's global ptr directory.
1740 * @return The size of the GlobalPtr directory. 1740 * @return The size of the GlobalPtr directory.
1741 **/ 1741 **/
1742 template<int x> 1742 template<int x>
1743 dword PeHeaderT<x>::getIddGlobalPtrSize() const 1743 dword PeHeaderT<x>::getIddGlobalPtrSize() const
1744 { 1744 {
1745 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_GLOBALPTR].Size; 1745 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_GLOBALPTR].Size;
1746 } 1746 }
1747 1747
1748 /** 1748 /**
1749 * Returns the relative virtual address of the current file's TLS directory. 1749 * Returns the relative virtual address of the current file's TLS directory.
1750 * @return The Rva of the Tls directory. 1750 * @return The Rva of the Tls directory.
1751 **/ 1751 **/
1752 template<int x> 1752 template<int x>
1753 dword PeHeaderT<x>::getIddTlsRva() const 1753 dword PeHeaderT<x>::getIddTlsRva() const
1754 { 1754 {
1755 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_TLS].VirtualAddress; 1755 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_TLS].VirtualAddress;
1756 } 1756 }
1757 1757
1758 /** 1758 /**
1759 * Returns the size of the current file's TLS directory. 1759 * Returns the size of the current file's TLS directory.
1760 * @return The size of the Tls directory. 1760 * @return The size of the Tls directory.
1761 **/ 1761 **/
1762 template<int x> 1762 template<int x>
1763 dword PeHeaderT<x>::getIddTlsSize() const 1763 dword PeHeaderT<x>::getIddTlsSize() const
1764 { 1764 {
1765 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_TLS].Size; 1765 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_TLS].Size;
1766 } 1766 }
1767 1767
1768 /** 1768 /**
1769 * Returns the relative virtual address of the current file's load config directory. 1769 * Returns the relative virtual address of the current file's load config directory.
1770 * @return The Rva of the LoadConfig directory. 1770 * @return The Rva of the LoadConfig directory.
1771 **/ 1771 **/
1772 template<int x> 1772 template<int x>
1773 dword PeHeaderT<x>::getIddLoadConfigRva() const 1773 dword PeHeaderT<x>::getIddLoadConfigRva() const
1774 { 1774 {
1775 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG].VirtualAddress; 1775 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG].VirtualAddress;
1776 } 1776 }
1777 1777
1778 /** 1778 /**
1779 * Returns the size of the current file's load config directory. 1779 * Returns the size of the current file's load config directory.
1780 * @return The size of the LoadConfig directory. 1780 * @return The size of the LoadConfig directory.
1781 **/ 1781 **/
1782 template<int x> 1782 template<int x>
1783 dword PeHeaderT<x>::getIddLoadConfigSize() const 1783 dword PeHeaderT<x>::getIddLoadConfigSize() const
1784 { 1784 {
1785 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG].Size; 1785 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG].Size;
1786 } 1786 }
1787 1787
1788 /** 1788 /**
1789 * Returns the relative virtual address of the current file's bound import directory. 1789 * Returns the relative virtual address of the current file's bound import directory.
1790 * @return The Rva of the BoundImport directory. 1790 * @return The Rva of the BoundImport directory.
1791 **/ 1791 **/
1792 template<int x> 1792 template<int x>
1793 dword PeHeaderT<x>::getIddBoundImportRva() const 1793 dword PeHeaderT<x>::getIddBoundImportRva() const
1794 { 1794 {
1795 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT].VirtualAddress; 1795 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT].VirtualAddress;
1796 } 1796 }
1797 1797
1798 /** 1798 /**
1799 * Returns the size of the current file's bound import directory. 1799 * Returns the size of the current file's bound import directory.
1800 * @return The size of the BoundImport directory. 1800 * @return The size of the BoundImport directory.
1801 **/ 1801 **/
1802 template<int x> 1802 template<int x>
1803 dword PeHeaderT<x>::getIddBoundImportSize() const 1803 dword PeHeaderT<x>::getIddBoundImportSize() const
1804 { 1804 {
1805 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT].Size; 1805 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT].Size;
1806 } 1806 }
1807 1807
1808 /** 1808 /**
1809 * Returns the relative virtual address of the current file's IAT directory. 1809 * Returns the relative virtual address of the current file's IAT directory.
1810 * @return The Rva of the IAT directory. 1810 * @return The Rva of the IAT directory.
1811 **/ 1811 **/
1812 template<int x> 1812 template<int x>
1813 dword PeHeaderT<x>::getIddIatRva() const 1813 dword PeHeaderT<x>::getIddIatRva() const
1814 { 1814 {
1815 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_IAT].VirtualAddress; 1815 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_IAT].VirtualAddress;
1816 } 1816 }
1817 1817
1818 /** 1818 /**
1819 * Returns the size of the current file's IAT directory. 1819 * Returns the size of the current file's IAT directory.
1820 * @return The size of the IAT directory. 1820 * @return The size of the IAT directory.
1821 **/ 1821 **/
1822 template<int x> 1822 template<int x>
1823 dword PeHeaderT<x>::getIddIatSize() const 1823 dword PeHeaderT<x>::getIddIatSize() const
1824 { 1824 {
1825 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_IAT].Size; 1825 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_IAT].Size;
1826 } 1826 }
1827 1827
1828 /** 1828 /**
1829 * Returns the relative virtual address of the current file's Delay Import directory. 1829 * Returns the relative virtual address of the current file's Delay Import directory.
1830 * @return The Rva of the DelayImport directory. 1830 * @return The Rva of the DelayImport directory.
1831 **/ 1831 **/
1832 template<int x> 1832 template<int x>
1833 dword PeHeaderT<x>::getIddDelayImportRva() const 1833 dword PeHeaderT<x>::getIddDelayImportRva() const
1834 { 1834 {
1835 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT].VirtualAddress; 1835 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT].VirtualAddress;
1836 } 1836 }
1837 1837
1838 /** 1838 /**
1839 * Returns the size of the current file's Delay Import directory. 1839 * Returns the size of the current file's Delay Import directory.
1840 * @return The size of the DelayImport directory. 1840 * @return The size of the DelayImport directory.
1841 **/ 1841 **/
1842 template<int x> 1842 template<int x>
1843 dword PeHeaderT<x>::getIddDelayImportSize() const 1843 dword PeHeaderT<x>::getIddDelayImportSize() const
1844 { 1844 {
1845 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT].Size; 1845 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT].Size;
1846 } 1846 }
1847 1847
1848 /** 1848 /**
1849 * Returns the relative virtual address of the current file's COM Descriptor directory. 1849 * Returns the relative virtual address of the current file's COM Descriptor directory.
1850 * @return The Rva of the COM Descriptor directory. 1850 * @return The Rva of the COM Descriptor directory.
1851 **/ 1851 **/
1852 template<int x> 1852 template<int x>
1853 dword PeHeaderT<x>::getIddComHeaderRva() const 1853 dword PeHeaderT<x>::getIddComHeaderRva() const
1854 { 1854 {
1855 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress; 1855 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress;
1856 } 1856 }
1857 1857
1858 /** 1858 /**
1859 * Returns the size of the current file's COM Descriptor directory. 1859 * Returns the size of the current file's COM Descriptor directory.
1860 * @return The Rva of the COM Descriptor directory. 1860 * @return The Rva of the COM Descriptor directory.
1861 **/ 1861 **/
1862 template<int x> 1862 template<int x>
1863 dword PeHeaderT<x>::getIddComHeaderSize() const 1863 dword PeHeaderT<x>::getIddComHeaderSize() const
1864 { 1864 {
1865 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].Size; 1865 return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].Size;
1866 } 1866 }
1867 1867
1868 /** 1868 /**
1869 * Returns the relative virtual address of an image directory. 1869 * Returns the relative virtual address of an image directory.
1870 * @param dwDirectory The identifier of an image directory. 1870 * @param dwDirectory The identifier of an image directory.
1871 * @return The Rva of the image directory. 1871 * @return The Rva of the image directory.
1872 **/ 1872 **/
1873 template<int x> 1873 template<int x>
1874 dword PeHeaderT<x>::getImageDataDirectoryRva(dword dwDirectory) const 1874 dword PeHeaderT<x>::getImageDataDirectoryRva(dword dwDirectory) const
1875 { 1875 {
1876 return m_inthHeader.dataDirectories[dwDirectory].VirtualAddress; 1876 return m_inthHeader.dataDirectories[dwDirectory].VirtualAddress;
1877 } 1877 }
1878 1878
1879 template<int x> 1879 template<int x>
1880 void PeHeaderT<x>::setImageDataDirectoryRva(dword dwDirectory, dword value) 1880 void PeHeaderT<x>::setImageDataDirectoryRva(dword dwDirectory, dword value)
1881 { 1881 {
1882 m_inthHeader.dataDirectories[dwDirectory].VirtualAddress = value; 1882 m_inthHeader.dataDirectories[dwDirectory].VirtualAddress = value;
1883 } 1883 }
1884 1884
1885 /** 1885 /**
1886 * Returns the size of an image directory. 1886 * Returns the size of an image directory.
1887 * @param dwDirectory The identifier of an image directory. 1887 * @param dwDirectory The identifier of an image directory.
1888 * @return The size of the image directory. 1888 * @return The size of the image directory.
1889 **/ 1889 **/
1890 template<int x> 1890 template<int x>
1891 dword PeHeaderT<x>::getImageDataDirectorySize(dword dwDirectory) const 1891 dword PeHeaderT<x>::getImageDataDirectorySize(dword dwDirectory) const
1892 { 1892 {
1893 return m_inthHeader.dataDirectories[dwDirectory].Size; 1893 return m_inthHeader.dataDirectories[dwDirectory].Size;
1894 } 1894 }
1895 1895
1896 template<int x> 1896 template<int x>
1897 void PeHeaderT<x>::setImageDataDirectorySize(dword dwDirectory, dword value) 1897 void PeHeaderT<x>::setImageDataDirectorySize(dword dwDirectory, dword value)
1898 { 1898 {
1899 m_inthHeader.dataDirectories[dwDirectory].Size = value; 1899 m_inthHeader.dataDirectories[dwDirectory].Size = value;
1900 } 1900 }
1901 1901
1902 /** 1902 /**
1903 * Returns the name of the section which is specified by the parameter wSectionnr. 1903 * Returns the name of the section which is specified by the parameter wSectionnr.
1904 * @param wSectionnr Index of the section. 1904 * @param wSectionnr Index of the section.
1905 * @return The name of the section. 1905 * @return The name of the section.
1906 **/ 1906 **/
1907 template<int x> 1907 template<int x>
1908 std::string PeHeaderT<x>::getSectionName(word wSectionnr) const 1908 std::string PeHeaderT<x>::getSectionName(word wSectionnr) const
1909 { 1909 {
1910 std::string sectionName = ""; 1910 std::string sectionName = "";
1911 1911
1912 for (unsigned int i=0;i<sizeof(m_vIsh[wSectionnr].Name);i++) 1912 for (unsigned int i=0;i<sizeof(m_vIsh[wSectionnr].Name);i++)
1913 { 1913 {
1914 if (m_vIsh[wSectionnr].Name[i]) sectionName += m_vIsh[wSectionnr].Name[i]; 1914 if (m_vIsh[wSectionnr].Name[i]) sectionName += m_vIsh[wSectionnr].Name[i];
1915 } 1915 }
1916 1916
1917 return sectionName; 1917 return sectionName;
1918 } 1918 }
1919 1919
1920 /** 1920 /**
1921 * Returns the virtual size of the section which is specified by the parameter wSectionnr. 1921 * Returns the virtual size of the section which is specified by the parameter wSectionnr.
1922 * @param wSectionnr Index of the section. 1922 * @param wSectionnr Index of the section.
1923 * @return The virtual size of the section. 1923 * @return The virtual size of the section.
1924 **/ 1924 **/
1925 template<int x> 1925 template<int x>
1926 dword PeHeaderT<x>::getVirtualSize(word wSectionnr) const 1926 dword PeHeaderT<x>::getVirtualSize(word wSectionnr) const
1927 { 1927 {
1928 return m_vIsh[wSectionnr].VirtualSize; 1928 return m_vIsh[wSectionnr].VirtualSize;
1929 } 1929 }
1930 1930
1931 /** 1931 /**
1932 * Returns the relative virtual address of the section which is specified by the parameter wSectionnr. 1932 * Returns the relative virtual address of the section which is specified by the parameter wSectionnr.
1933 * @param wSectionnr Index of the section. 1933 * @param wSectionnr Index of the section.
1934 * @return The Rva of the section. 1934 * @return The Rva of the section.
1935 **/ 1935 **/
1936 template<int x> 1936 template<int x>
1937 dword PeHeaderT<x>::getVirtualAddress(word wSectionnr) const 1937 dword PeHeaderT<x>::getVirtualAddress(word wSectionnr) const
1938 { 1938 {
1939 return m_vIsh[wSectionnr].VirtualAddress; 1939 return m_vIsh[wSectionnr].VirtualAddress;
1940 } 1940 }
1941 1941
1942 /** 1942 /**
1943 * Returns the size of raw data of the section which is specified by the parameter wSectionnr. 1943 * Returns the size of raw data of the section which is specified by the parameter wSectionnr.
1944 * @param wSectionnr Index of the section. 1944 * @param wSectionnr Index of the section.
1945 * @return The size of raw data of the section. 1945 * @return The size of raw data of the section.
1946 **/ 1946 **/
1947 template<int x> 1947 template<int x>
1948 dword PeHeaderT<x>::getSizeOfRawData(word wSectionnr) const 1948 dword PeHeaderT<x>::getSizeOfRawData(word wSectionnr) const
1949 { 1949 {
1950 return m_vIsh[wSectionnr].SizeOfRawData; 1950 return m_vIsh[wSectionnr].SizeOfRawData;
1951 } 1951 }
1952 1952
1953 /** 1953 /**
1954 * Returns the file offset of the section which is specified by the parameter wSectionnr. 1954 * Returns the file offset of the section which is specified by the parameter wSectionnr.
1955 * @param wSectionnr Index of the section. 1955 * @param wSectionnr Index of the section.
1956 * @return The file offset of the section. 1956 * @return The file offset of the section.
1957 **/ 1957 **/
1958 template<int x> 1958 template<int x>
1959 dword PeHeaderT<x>::getPointerToRawData(word wSectionnr) const 1959 dword PeHeaderT<x>::getPointerToRawData(word wSectionnr) const
1960 { 1960 {
1961 return m_vIsh[wSectionnr].PointerToRawData; 1961 return m_vIsh[wSectionnr].PointerToRawData;
1962 } 1962 }
1963 1963
1964 /** 1964 /**
1965 * Returns the pointer to relocations of the section which is specified by the parameter wSectionnr. 1965 * Returns the pointer to relocations of the section which is specified by the parameter wSectionnr.
1966 * @param wSectionnr Index of the section. 1966 * @param wSectionnr Index of the section.
1967 * @return The pointer to relocations of the section. 1967 * @return The pointer to relocations of the section.
1968 **/ 1968 **/
1969 template<int x> 1969 template<int x>
1970 dword PeHeaderT<x>::getPointerToRelocations(word wSectionnr) const 1970 dword PeHeaderT<x>::getPointerToRelocations(word wSectionnr) const
1971 { 1971 {
1972 return m_vIsh[wSectionnr].PointerToRelocations; 1972 return m_vIsh[wSectionnr].PointerToRelocations;
1973 } 1973 }
1974 1974
1975 /** 1975 /**
1976 * Returns the poiner to line numbers of the section which is specified by the parameter wSectionnr. 1976 * Returns the poiner to line numbers of the section which is specified by the parameter wSectionnr.
1977 * @param wSectionnr Index of the section. 1977 * @param wSectionnr Index of the section.
1978 * @return The pointer to line numbers of the section. 1978 * @return The pointer to line numbers of the section.
1979 **/ 1979 **/
1980 template<int x> 1980 template<int x>
1981 dword PeHeaderT<x>::getPointerToLinenumbers(word wSectionnr) const 1981 dword PeHeaderT<x>::getPointerToLinenumbers(word wSectionnr) const
1982 { 1982 {
1983 return m_vIsh[wSectionnr].PointerToLinenumbers; 1983 return m_vIsh[wSectionnr].PointerToLinenumbers;
1984 } 1984 }
1985 1985
1986 /** 1986 /**
1987 * Returns the number of relocations of the section which is specified by the parameter wSectionnr. 1987 * Returns the number of relocations of the section which is specified by the parameter wSectionnr.
1988 * @param wSectionnr Index of the section. 1988 * @param wSectionnr Index of the section.
1989 * @return The number of relocations of the section. 1989 * @return The number of relocations of the section.
1990 **/ 1990 **/
1991 template<int x> 1991 template<int x>
1992 dword PeHeaderT<x>::getNumberOfRelocations(word wSectionnr) const 1992 dword PeHeaderT<x>::getNumberOfRelocations(word wSectionnr) const
1993 { 1993 {
1994 return m_vIsh[wSectionnr].NumberOfRelocations; 1994 return m_vIsh[wSectionnr].NumberOfRelocations;
1995 } 1995 }
1996 1996
1997 /** 1997 /**
1998 * Returns the number of line numbers of the section which is specified by the parameter wSectionnr. 1998 * Returns the number of line numbers of the section which is specified by the parameter wSectionnr.
1999 * @param wSectionnr Index of the section. 1999 * @param wSectionnr Index of the section.
2000 * @return The number of line numbers of the section. 2000 * @return The number of line numbers of the section.
2001 **/ 2001 **/
2002 template<int x> 2002 template<int x>
2003 dword PeHeaderT<x>::getNumberOfLinenumbers(word wSectionnr) const 2003 dword PeHeaderT<x>::getNumberOfLinenumbers(word wSectionnr) const
2004 { 2004 {
2005 return m_vIsh[wSectionnr].NumberOfLinenumbers; 2005 return m_vIsh[wSectionnr].NumberOfLinenumbers;
2006 } 2006 }
2007 2007
2008 /** 2008 /**
2009 * Returns the characteristics of the section which is specified by the parameter wSectionnr. 2009 * Returns the characteristics of the section which is specified by the parameter wSectionnr.
2010 * @param wSectionnr Index of the section. 2010 * @param wSectionnr Index of the section.
2011 * @return The characteristics of the section. 2011 * @return The characteristics of the section.
2012 **/ 2012 **/
2013 template<int x> 2013 template<int x>
2014 dword PeHeaderT<x>::getCharacteristics(word wSectionnr) const 2014 dword PeHeaderT<x>::getCharacteristics(word wSectionnr) const
2015 { 2015 {
2016 return m_vIsh[wSectionnr].Characteristics; 2016 return m_vIsh[wSectionnr].Characteristics;
2017 } 2017 }
2018 2018
2019 /** 2019 /**
2020 * Changes the file's Nt signature. 2020 * Changes the file's Nt signature.
2021 * @param dwValue New value. 2021 * @param dwValue New value.
2022 **/ 2022 **/
2023 template<int x> 2023 template<int x>
2024 void PeHeaderT<x>::setNtSignature(dword dwValue) 2024 void PeHeaderT<x>::setNtSignature(dword dwValue)
2025 { 2025 {
2026 m_inthHeader.Signature = dwValue; 2026 m_inthHeader.Signature = dwValue;
2027 } 2027 }
2028 2028
2029 /** 2029 /**
2030 * Changes the file's Machine. 2030 * Changes the file's Machine.
2031 * @param wValue New value. 2031 * @param wValue New value.
2032 **/ 2032 **/
2033 template<int x> 2033 template<int x>
2034 void PeHeaderT<x>::setMachine(word wValue) 2034 void PeHeaderT<x>::setMachine(word wValue)
2035 { 2035 {
2036 m_inthHeader.FileHeader.Machine = wValue; 2036 m_inthHeader.FileHeader.Machine = wValue;
2037 } 2037 }
2038 2038
2039 /** 2039 /**
2040 * Changes the number of sections. 2040 * Changes the number of sections.
2041 * @param wValue New value. 2041 * @param wValue New value.
2042 **/ 2042 **/
2043 template<int x> 2043 template<int x>
2044 void PeHeaderT<x>::setNumberOfSections(word wValue) 2044 void PeHeaderT<x>::setNumberOfSections(word wValue)
2045 { 2045 {
2046 m_inthHeader.FileHeader.NumberOfSections = wValue; 2046 m_inthHeader.FileHeader.NumberOfSections = wValue;
2047 } 2047 }
2048 2048
2049 /** 2049 /**
2050 * Changes the file's TimeDateStamp. 2050 * Changes the file's TimeDateStamp.
2051 * @param dwValue New value. 2051 * @param dwValue New value.
2052 **/ 2052 **/
2053 template<int x> 2053 template<int x>
2054 void PeHeaderT<x>::setTimeDateStamp(dword dwValue) 2054 void PeHeaderT<x>::setTimeDateStamp(dword dwValue)
2055 { 2055 {
2056 m_inthHeader.FileHeader.TimeDateStamp = dwValue; 2056 m_inthHeader.FileHeader.TimeDateStamp = dwValue;
2057 } 2057 }
2058 2058
2059 /** 2059 /**
2060 * Changes the file's PointerToSymbolTable. 2060 * Changes the file's PointerToSymbolTable.
2061 * @param dwValue New value. 2061 * @param dwValue New value.
2062 **/ 2062 **/
2063 template<int x> 2063 template<int x>
2064 void PeHeaderT<x>::setPointerToSymbolTable(dword dwValue) 2064 void PeHeaderT<x>::setPointerToSymbolTable(dword dwValue)
2065 { 2065 {
2066 m_inthHeader.FileHeader.PointerToSymbolTable = dwValue; 2066 m_inthHeader.FileHeader.PointerToSymbolTable = dwValue;
2067 } 2067 }
2068 2068
2069 /** 2069 /**
2070 * Changes the file's NumberOfSymbols. 2070 * Changes the file's NumberOfSymbols.
2071 * @param dwValue New value. 2071 * @param dwValue New value.
2072 **/ 2072 **/
2073 template<int x> 2073 template<int x>
2074 void PeHeaderT<x>::setNumberOfSymbols(dword dwValue) 2074 void PeHeaderT<x>::setNumberOfSymbols(dword dwValue)
2075 { 2075 {
2076 m_inthHeader.FileHeader.NumberOfSymbols = dwValue; 2076 m_inthHeader.FileHeader.NumberOfSymbols = dwValue;
2077 } 2077 }
2078 2078
2079 /** 2079 /**
2080 * Changes the file's SizeOfOptionalHeader. 2080 * Changes the file's SizeOfOptionalHeader.
2081 * @param wValue New value. 2081 * @param wValue New value.
2082 **/ 2082 **/
2083 template<int x> 2083 template<int x>
2084 void PeHeaderT<x>::setSizeOfOptionalHeader(word wValue) 2084 void PeHeaderT<x>::setSizeOfOptionalHeader(word wValue)
2085 { 2085 {
2086 m_inthHeader.FileHeader.SizeOfOptionalHeader = wValue; 2086 m_inthHeader.FileHeader.SizeOfOptionalHeader = wValue;
2087 } 2087 }
2088 2088
2089 /** 2089 /**
2090 * Changes the file's Characteristics. 2090 * Changes the file's Characteristics.
2091 * @param wValue New value. 2091 * @param wValue New value.
2092 **/ 2092 **/
2093 template<int x> 2093 template<int x>
2094 void PeHeaderT<x>::setCharacteristics(word wValue) 2094 void PeHeaderT<x>::setCharacteristics(word wValue)
2095 { 2095 {
2096 m_inthHeader.FileHeader.Characteristics = wValue; 2096 m_inthHeader.FileHeader.Characteristics = wValue;
2097 } 2097 }
2098 2098
2099 /** 2099 /**
2100 * Changes the file's Magic. 2100 * Changes the file's Magic.
2101 * @param wValue New value. 2101 * @param wValue New value.
2102 **/ 2102 **/
2103 template<int x> 2103 template<int x>
2104 void PeHeaderT<x>::setMagic(word wValue) 2104 void PeHeaderT<x>::setMagic(word wValue)
2105 { 2105 {
2106 m_inthHeader.OptionalHeader.Magic = wValue; 2106 m_inthHeader.OptionalHeader.Magic = wValue;
2107 } 2107 }
2108 2108
2109 /** 2109 /**
2110 * Changes the file's MajorLinkerVersion. 2110 * Changes the file's MajorLinkerVersion.
2111 * @param bValue New value. 2111 * @param bValue New value.
2112 **/ 2112 **/
2113 template<int x> 2113 template<int x>
2114 void PeHeaderT<x>::setMajorLinkerVersion(byte bValue) 2114 void PeHeaderT<x>::setMajorLinkerVersion(byte bValue)
2115 { 2115 {
2116 m_inthHeader.OptionalHeader.MajorLinkerVersion = bValue; 2116 m_inthHeader.OptionalHeader.MajorLinkerVersion = bValue;
2117 } 2117 }
2118 2118
2119 /** 2119 /**
2120 * Changes the file's MinorLinkerVersion. 2120 * Changes the file's MinorLinkerVersion.
2121 * @param bValue New value. 2121 * @param bValue New value.
2122 **/ 2122 **/
2123 template<int x> 2123 template<int x>
2124 void PeHeaderT<x>::setMinorLinkerVersion(byte bValue) 2124 void PeHeaderT<x>::setMinorLinkerVersion(byte bValue)
2125 { 2125 {
2126 m_inthHeader.OptionalHeader.MinorLinkerVersion = bValue; 2126 m_inthHeader.OptionalHeader.MinorLinkerVersion = bValue;
2127 } 2127 }
2128 2128
2129 /** 2129 /**
2130 * Changes the file's SizeOfCode. 2130 * Changes the file's SizeOfCode.
2131 * @param dwValue New value. 2131 * @param dwValue New value.
2132 **/ 2132 **/
2133 template<int x> 2133 template<int x>
2134 void PeHeaderT<x>::setSizeOfCode(dword dwValue) 2134 void PeHeaderT<x>::setSizeOfCode(dword dwValue)
2135 { 2135 {
2136 m_inthHeader.OptionalHeader.SizeOfCode = dwValue; 2136 m_inthHeader.OptionalHeader.SizeOfCode = dwValue;
2137 } 2137 }
2138 2138
2139 /** 2139 /**
2140 * Changes the file's SizeOfInitializedData. 2140 * Changes the file's SizeOfInitializedData.
2141 * @param dwValue New value. 2141 * @param dwValue New value.
2142 **/ 2142 **/
2143 template<int x> 2143 template<int x>
2144 void PeHeaderT<x>::setSizeOfInitializedData(dword dwValue) 2144 void PeHeaderT<x>::setSizeOfInitializedData(dword dwValue)
2145 { 2145 {
2146 m_inthHeader.OptionalHeader.SizeOfInitializedData = dwValue; 2146 m_inthHeader.OptionalHeader.SizeOfInitializedData = dwValue;
2147 } 2147 }
2148 2148
2149 /** 2149 /**
2150 * Changes the file's SizeOfUninitializedData. 2150 * Changes the file's SizeOfUninitializedData.
2151 * @param dwValue New value. 2151 * @param dwValue New value.
2152 **/ 2152 **/
2153 template<int x> 2153 template<int x>
2154 void PeHeaderT<x>::setSizeOfUninitializedData(dword dwValue) 2154 void PeHeaderT<x>::setSizeOfUninitializedData(dword dwValue)
2155 { 2155 {
2156 m_inthHeader.OptionalHeader.SizeOfUninitializedData = dwValue; 2156 m_inthHeader.OptionalHeader.SizeOfUninitializedData = dwValue;
2157 } 2157 }
2158 2158
2159 /** 2159 /**
2160 * Changes the file's AddressOfEntryPoint. 2160 * Changes the file's AddressOfEntryPoint.
2161 * @param dwValue New value. 2161 * @param dwValue New value.
2162 **/ 2162 **/
2163 template<int x> 2163 template<int x>
2164 void PeHeaderT<x>::setAddressOfEntryPoint(dword dwValue) 2164 void PeHeaderT<x>::setAddressOfEntryPoint(dword dwValue)
2165 { 2165 {
2166 m_inthHeader.OptionalHeader.AddressOfEntryPoint = dwValue; 2166 m_inthHeader.OptionalHeader.AddressOfEntryPoint = dwValue;
2167 } 2167 }
2168 2168
2169 /** 2169 /**
2170 * Changes the file's BaseOfCode. 2170 * Changes the file's BaseOfCode.
2171 * @param dwValue New value. 2171 * @param dwValue New value.
2172 **/ 2172 **/
2173 template<int x> 2173 template<int x>
2174 void PeHeaderT<x>::setBaseOfCode(dword dwValue) 2174 void PeHeaderT<x>::setBaseOfCode(dword dwValue)
2175 { 2175 {
2176 m_inthHeader.OptionalHeader.BaseOfCode = dwValue; 2176 m_inthHeader.OptionalHeader.BaseOfCode = dwValue;
2177 } 2177 }
2178 2178
2179 /** 2179 /**
2180 * Changes the file's ImageBase. 2180 * Changes the file's ImageBase.
2181 * @param dwValue New value. 2181 * @param dwValue New value.
2182 **/ 2182 **/
2183 template<int x> 2183 template<int x>
2184 void PeHeaderT<x>::setImageBase(typename FieldSizes<x>::VAR4_8 dwValue) 2184 void PeHeaderT<x>::setImageBase(typename FieldSizes<x>::VAR4_8 dwValue)
2185 { 2185 {
2186 m_inthHeader.OptionalHeader.ImageBase = dwValue; 2186 m_inthHeader.OptionalHeader.ImageBase = dwValue;
2187 } 2187 }
2188 2188
2189 /** 2189 /**
2190 * Changes the file's SectionAlignment. 2190 * Changes the file's SectionAlignment.
2191 * @param dwValue New value. 2191 * @param dwValue New value.
2192 **/ 2192 **/
2193 template<int x> 2193 template<int x>
2194 void PeHeaderT<x>::setSectionAlignment(dword dwValue) 2194 void PeHeaderT<x>::setSectionAlignment(dword dwValue)
2195 { 2195 {
2196 m_inthHeader.OptionalHeader.SectionAlignment = dwValue; 2196 m_inthHeader.OptionalHeader.SectionAlignment = dwValue;
2197 } 2197 }
2198 2198
2199 /** 2199 /**
2200 * Changes the file's FileAlignment. 2200 * Changes the file's FileAlignment.
2201 * @param dwValue New value. 2201 * @param dwValue New value.
2202 **/ 2202 **/
2203 template<int x> 2203 template<int x>
2204 void PeHeaderT<x>::setFileAlignment(dword dwValue) 2204 void PeHeaderT<x>::setFileAlignment(dword dwValue)
2205 { 2205 {
2206 m_inthHeader.OptionalHeader.FileAlignment = dwValue; 2206 m_inthHeader.OptionalHeader.FileAlignment = dwValue;
2207 } 2207 }
2208 2208
2209 /** 2209 /**
2210 * Changes the file's MajorOperatingSystemVersion. 2210 * Changes the file's MajorOperatingSystemVersion.
2211 * @param wValue New value. 2211 * @param wValue New value.
2212 **/ 2212 **/
2213 template<int x> 2213 template<int x>
2214 void PeHeaderT<x>::setMajorOperatingSystemVersion(word wValue) 2214 void PeHeaderT<x>::setMajorOperatingSystemVersion(word wValue)
2215 { 2215 {
2216 m_inthHeader.OptionalHeader.MajorOperatingSystemVersion = wValue; 2216 m_inthHeader.OptionalHeader.MajorOperatingSystemVersion = wValue;
2217 } 2217 }
2218 2218
2219 /** 2219 /**
2220 * Changes the file's MinorOperatingSystemVersion. 2220 * Changes the file's MinorOperatingSystemVersion.
2221 * @param wValue New value. 2221 * @param wValue New value.
2222 **/ 2222 **/
2223 template<int x> 2223 template<int x>
2224 void PeHeaderT<x>::setMinorOperatingSystemVersion(word wValue) 2224 void PeHeaderT<x>::setMinorOperatingSystemVersion(word wValue)
2225 { 2225 {
2226 m_inthHeader.OptionalHeader.MinorOperatingSystemVersion = wValue; 2226 m_inthHeader.OptionalHeader.MinorOperatingSystemVersion = wValue;
2227 } 2227 }
2228 2228
2229 /** 2229 /**
2230 * Changes the file's MajorImageVersion. 2230 * Changes the file's MajorImageVersion.
2231 * @param wValue New value. 2231 * @param wValue New value.
2232 **/ 2232 **/
2233 template<int x> 2233 template<int x>
2234 void PeHeaderT<x>::setMajorImageVersion(word wValue) 2234 void PeHeaderT<x>::setMajorImageVersion(word wValue)
2235 { 2235 {
2236 m_inthHeader.OptionalHeader.MajorImageVersion = wValue; 2236 m_inthHeader.OptionalHeader.MajorImageVersion = wValue;
2237 } 2237 }
2238 2238
2239 /** 2239 /**
2240 * Changes the file's MinorImageVersion. 2240 * Changes the file's MinorImageVersion.
2241 * @param wValue New value. 2241 * @param wValue New value.
2242 **/ 2242 **/
2243 template<int x> 2243 template<int x>
2244 void PeHeaderT<x>::setMinorImageVersion(word wValue) 2244 void PeHeaderT<x>::setMinorImageVersion(word wValue)
2245 { 2245 {
2246 m_inthHeader.OptionalHeader.MinorImageVersion = wValue; 2246 m_inthHeader.OptionalHeader.MinorImageVersion = wValue;
2247 } 2247 }
2248 2248
2249 /** 2249 /**
2250 * Changes the file's MajorSubsystemVersion. 2250 * Changes the file's MajorSubsystemVersion.
2251 * @param wValue New value. 2251 * @param wValue New value.
2252 **/ 2252 **/
2253 template<int x> 2253 template<int x>
2254 void PeHeaderT<x>::setMajorSubsystemVersion(word wValue) 2254 void PeHeaderT<x>::setMajorSubsystemVersion(word wValue)
2255 { 2255 {
2256 m_inthHeader.OptionalHeader.MajorSubsystemVersion = wValue; 2256 m_inthHeader.OptionalHeader.MajorSubsystemVersion = wValue;
2257 } 2257 }
2258 2258
2259 /** 2259 /**
2260 * Changes the file's MinorSubsystemVersion. 2260 * Changes the file's MinorSubsystemVersion.
2261 * @param wValue New value. 2261 * @param wValue New value.
2262 **/ 2262 **/
2263 template<int x> 2263 template<int x>
2264 void PeHeaderT<x>::setMinorSubsystemVersion(word wValue) 2264 void PeHeaderT<x>::setMinorSubsystemVersion(word wValue)
2265 { 2265 {
2266 m_inthHeader.OptionalHeader.MinorSubsystemVersion = wValue; 2266 m_inthHeader.OptionalHeader.MinorSubsystemVersion = wValue;
2267 } 2267 }
2268 2268
2269 /** 2269 /**
2270 * Changes the file's Win32VersionValue. 2270 * Changes the file's Win32VersionValue.
2271 * @param dwValue New value. 2271 * @param dwValue New value.
2272 **/ 2272 **/
2273 template<int x> 2273 template<int x>
2274 void PeHeaderT<x>::setWin32VersionValue(dword dwValue) 2274 void PeHeaderT<x>::setWin32VersionValue(dword dwValue)
2275 { 2275 {
2276 m_inthHeader.OptionalHeader.Win32VersionValue = dwValue; 2276 m_inthHeader.OptionalHeader.Win32VersionValue = dwValue;
2277 } 2277 }
2278 2278
2279 /** 2279 /**
2280 * Changes the file's SizeOfImage. 2280 * Changes the file's SizeOfImage.
2281 * @param dwValue New value. 2281 * @param dwValue New value.
2282 **/ 2282 **/
2283 template<int x> 2283 template<int x>
2284 void PeHeaderT<x>::setSizeOfImage(dword dwValue) 2284 void PeHeaderT<x>::setSizeOfImage(dword dwValue)
2285 { 2285 {
2286 m_inthHeader.OptionalHeader.SizeOfImage = dwValue; 2286 m_inthHeader.OptionalHeader.SizeOfImage = dwValue;
2287 } 2287 }
2288 2288
2289 /** 2289 /**
2290 * Changes the file's SizeOfHeaders. 2290 * Changes the file's SizeOfHeaders.
2291 * @param dwValue New value. 2291 * @param dwValue New value.
2292 **/ 2292 **/
2293 template<int x> 2293 template<int x>
2294 void PeHeaderT<x>::setSizeOfHeaders(dword dwValue) 2294 void PeHeaderT<x>::setSizeOfHeaders(dword dwValue)
2295 { 2295 {
2296 m_inthHeader.OptionalHeader.SizeOfHeaders = dwValue; 2296 m_inthHeader.OptionalHeader.SizeOfHeaders = dwValue;
2297 } 2297 }
2298 2298
2299 /** 2299 /**
2300 * Changes the file's CheckSum. 2300 * Changes the file's CheckSum.
2301 * @param dwValue New value. 2301 * @param dwValue New value.
2302 **/ 2302 **/
2303 template<int x> 2303 template<int x>
2304 void PeHeaderT<x>::setCheckSum(dword dwValue) 2304 void PeHeaderT<x>::setCheckSum(dword dwValue)
2305 { 2305 {
2306 m_inthHeader.OptionalHeader.CheckSum = dwValue; 2306 m_inthHeader.OptionalHeader.CheckSum = dwValue;
2307 } 2307 }
2308 2308
2309 /** 2309 /**
2310 * Changes the file's Subsystem. 2310 * Changes the file's Subsystem.
2311 * @param wValue New value. 2311 * @param wValue New value.
2312 **/ 2312 **/
2313 template<int x> 2313 template<int x>
2314 void PeHeaderT<x>::setSubsystem(word wValue) 2314 void PeHeaderT<x>::setSubsystem(word wValue)
2315 { 2315 {
2316 m_inthHeader.OptionalHeader.Subsystem = wValue; 2316 m_inthHeader.OptionalHeader.Subsystem = wValue;
2317 } 2317 }
2318 2318
2319 /** 2319 /**
2320 * Changes the file's DllCharacteristics. 2320 * Changes the file's DllCharacteristics.
2321 * @param wValue New value. 2321 * @param wValue New value.
2322 **/ 2322 **/
2323 template<int x> 2323 template<int x>
2324 void PeHeaderT<x>::setDllCharacteristics(word wValue) 2324 void PeHeaderT<x>::setDllCharacteristics(word wValue)
2325 { 2325 {
2326 m_inthHeader.OptionalHeader.DllCharacteristics = wValue; 2326 m_inthHeader.OptionalHeader.DllCharacteristics = wValue;
2327 } 2327 }
2328 2328
2329 /** 2329 /**
2330 * Changes the file's SizeOfStackReserve. 2330 * Changes the file's SizeOfStackReserve.
2331 * @param dwValue New value. 2331 * @param dwValue New value.
2332 **/ 2332 **/
2333 template<int x> 2333 template<int x>
2334 void PeHeaderT<x>::setSizeOfStackReserve(typename FieldSizes<x>::VAR4_8 dwValue) 2334 void PeHeaderT<x>::setSizeOfStackReserve(typename FieldSizes<x>::VAR4_8 dwValue)
2335 { 2335 {
2336 m_inthHeader.OptionalHeader.SizeOfStackReserve = dwValue; 2336 m_inthHeader.OptionalHeader.SizeOfStackReserve = dwValue;
2337 } 2337 }
2338 2338
2339 /** 2339 /**
2340 * Changes the file's SizeOfStackCommit. 2340 * Changes the file's SizeOfStackCommit.
2341 * @param dwValue New value. 2341 * @param dwValue New value.
2342 **/ 2342 **/
2343 template<int x> 2343 template<int x>
2344 void PeHeaderT<x>::setSizeOfStackCommit(typename FieldSizes<x>::VAR4_8 dwValue) 2344 void PeHeaderT<x>::setSizeOfStackCommit(typename FieldSizes<x>::VAR4_8 dwValue)
2345 { 2345 {
2346 m_inthHeader.OptionalHeader.SizeOfStackCommit = dwValue; 2346 m_inthHeader.OptionalHeader.SizeOfStackCommit = dwValue;
2347 } 2347 }
2348 2348
2349 /** 2349 /**
2350 * Changes the file's SizeOfHeapReserve. 2350 * Changes the file's SizeOfHeapReserve.
2351 * @param dwValue New value. 2351 * @param dwValue New value.
2352 **/ 2352 **/
2353 template<int x> 2353 template<int x>
2354 void PeHeaderT<x>::setSizeOfHeapReserve(typename FieldSizes<x>::VAR4_8 dwValue) 2354 void PeHeaderT<x>::setSizeOfHeapReserve(typename FieldSizes<x>::VAR4_8 dwValue)
2355 { 2355 {
2356 m_inthHeader.OptionalHeader.SizeOfHeapReserve = dwValue; 2356 m_inthHeader.OptionalHeader.SizeOfHeapReserve = dwValue;
2357 } 2357 }
2358 2358
2359 /** 2359 /**
2360 * Changes the file's SizeOfHeapCommit. 2360 * Changes the file's SizeOfHeapCommit.
2361 * @param dwValue New value. 2361 * @param dwValue New value.
2362 **/ 2362 **/
2363 template<int x> 2363 template<int x>
2364 void PeHeaderT<x>::setSizeOfHeapCommit(typename FieldSizes<x>::VAR4_8 dwValue) 2364 void PeHeaderT<x>::setSizeOfHeapCommit(typename FieldSizes<x>::VAR4_8 dwValue)
2365 { 2365 {
2366 m_inthHeader.OptionalHeader.SizeOfHeapCommit = dwValue; 2366 m_inthHeader.OptionalHeader.SizeOfHeapCommit = dwValue;
2367 } 2367 }
2368 2368
2369 /** 2369 /**
2370 * Changes the file's LoaderFlags. 2370 * Changes the file's LoaderFlags.
2371 * @param dwValue New value. 2371 * @param dwValue New value.
2372 **/ 2372 **/
2373 template<int x> 2373 template<int x>
2374 void PeHeaderT<x>::setLoaderFlags(dword dwValue) 2374 void PeHeaderT<x>::setLoaderFlags(dword dwValue)
2375 { 2375 {
2376 m_inthHeader.OptionalHeader.LoaderFlags = dwValue; 2376 m_inthHeader.OptionalHeader.LoaderFlags = dwValue;
2377 } 2377 }
2378 2378
2379 /** 2379 /**
2380 * Changes the file's NumberOfRvaAndSizes. 2380 * Changes the file's NumberOfRvaAndSizes.
2381 * @param dwValue New value. 2381 * @param dwValue New value.
2382 **/ 2382 **/
2383 template<int x> 2383 template<int x>
2384 void PeHeaderT<x>::setNumberOfRvaAndSizes(dword dwValue) 2384 void PeHeaderT<x>::setNumberOfRvaAndSizes(dword dwValue)
2385 { 2385 {
2386 m_inthHeader.OptionalHeader.NumberOfRvaAndSizes = dwValue; 2386 m_inthHeader.OptionalHeader.NumberOfRvaAndSizes = dwValue;
2387 } 2387 }
2388 2388
2389 template<int x> 2389 template<int x>
2390 void PeHeaderT<x>::setIddDebugRva(dword dwValue) 2390 void PeHeaderT<x>::setIddDebugRva(dword dwValue)
2391 { 2391 {
2392 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress = dwValue; 2392 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress = dwValue;
2393 } 2393 }
2394 2394
2395 template<int x> 2395 template<int x>
2396 void PeHeaderT<x>::setIddDebugSize(dword dwValue) 2396 void PeHeaderT<x>::setIddDebugSize(dword dwValue)
2397 { 2397 {
2398 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_DEBUG].Size = dwValue; 2398 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_DEBUG].Size = dwValue;
2399 } 2399 }
2400 2400
2401 template<int x> 2401 template<int x>
2402 void PeHeaderT<x>::setIddDelayImportRva(dword dwValue) 2402 void PeHeaderT<x>::setIddDelayImportRva(dword dwValue)
2403 { 2403 {
2404 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT].VirtualAddress = dwValue; 2404 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT].VirtualAddress = dwValue;
2405 } 2405 }
2406 2406
2407 template<int x> 2407 template<int x>
2408 void PeHeaderT<x>::setIddDelayImportSize(dword dwValue) 2408 void PeHeaderT<x>::setIddDelayImportSize(dword dwValue)
2409 { 2409 {
2410 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT].Size = dwValue; 2410 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT].Size = dwValue;
2411 } 2411 }
2412 2412
2413 template<int x> 2413 template<int x>
2414 void PeHeaderT<x>::setIddExceptionRva(dword dwValue) 2414 void PeHeaderT<x>::setIddExceptionRva(dword dwValue)
2415 { 2415 {
2416 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_EXCEPTION].VirtualAddress = dwValue; 2416 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_EXCEPTION].VirtualAddress = dwValue;
2417 } 2417 }
2418 2418
2419 template<int x> 2419 template<int x>
2420 void PeHeaderT<x>::setIddExceptionSize(dword dwValue) 2420 void PeHeaderT<x>::setIddExceptionSize(dword dwValue)
2421 { 2421 {
2422 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_EXCEPTION].Size = dwValue; 2422 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_EXCEPTION].Size = dwValue;
2423 } 2423 }
2424 2424
2425 template<int x> 2425 template<int x>
2426 void PeHeaderT<x>::setIddGlobalPtrRva(dword dwValue) 2426 void PeHeaderT<x>::setIddGlobalPtrRva(dword dwValue)
2427 { 2427 {
2428 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_GLOBALPTR].VirtualAddress = dwValue; 2428 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_GLOBALPTR].VirtualAddress = dwValue;
2429 } 2429 }
2430 2430
2431 template<int x> 2431 template<int x>
2432 void PeHeaderT<x>::setIddGlobalPtrSize(dword dwValue) 2432 void PeHeaderT<x>::setIddGlobalPtrSize(dword dwValue)
2433 { 2433 {
2434 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_GLOBALPTR].Size = dwValue; 2434 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_GLOBALPTR].Size = dwValue;
2435 } 2435 }
2436 2436
2437 template<int x> 2437 template<int x>
2438 void PeHeaderT<x>::setIddIatRva(dword dwValue) 2438 void PeHeaderT<x>::setIddIatRva(dword dwValue)
2439 { 2439 {
2440 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_IAT].VirtualAddress = dwValue; 2440 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_IAT].VirtualAddress = dwValue;
2441 } 2441 }
2442 2442
2443 template<int x> 2443 template<int x>
2444 void PeHeaderT<x>::setIddIatSize(dword dwValue) 2444 void PeHeaderT<x>::setIddIatSize(dword dwValue)
2445 { 2445 {
2446 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_IAT].Size = dwValue; 2446 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_IAT].Size = dwValue;
2447 } 2447 }
2448 2448
2449 template<int x> 2449 template<int x>
2450 void PeHeaderT<x>::setIddLoadConfigRva(dword dwValue) 2450 void PeHeaderT<x>::setIddLoadConfigRva(dword dwValue)
2451 { 2451 {
2452 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG].VirtualAddress = dwValue; 2452 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG].VirtualAddress = dwValue;
2453 } 2453 }
2454 2454
2455 template<int x> 2455 template<int x>
2456 void PeHeaderT<x>::setIddLoadConfigSize(dword dwValue) 2456 void PeHeaderT<x>::setIddLoadConfigSize(dword dwValue)
2457 { 2457 {
2458 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG].Size = dwValue; 2458 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG].Size = dwValue;
2459 } 2459 }
2460 2460
2461 template<int x> 2461 template<int x>
2462 void PeHeaderT<x>::setIddResourceRva(dword dwValue) 2462 void PeHeaderT<x>::setIddResourceRva(dword dwValue)
2463 { 2463 {
2464 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress = dwValue; 2464 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress = dwValue;
2465 } 2465 }
2466 2466
2467 template<int x> 2467 template<int x>
2468 void PeHeaderT<x>::setIddResourceSize(dword dwValue) 2468 void PeHeaderT<x>::setIddResourceSize(dword dwValue)
2469 { 2469 {
2470 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_RESOURCE].Size = dwValue; 2470 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_RESOURCE].Size = dwValue;
2471 } 2471 }
2472 2472
2473 template<int x> 2473 template<int x>
2474 void PeHeaderT<x>::setIddSecurityRva(dword dwValue) 2474 void PeHeaderT<x>::setIddSecurityRva(dword dwValue)
2475 { 2475 {
2476 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_SECURITY].VirtualAddress = dwValue; 2476 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_SECURITY].VirtualAddress = dwValue;
2477 } 2477 }
2478 2478
2479 template<int x> 2479 template<int x>
2480 void PeHeaderT<x>::setIddSecuritySize(dword dwValue) 2480 void PeHeaderT<x>::setIddSecuritySize(dword dwValue)
2481 { 2481 {
2482 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_SECURITY].Size = dwValue; 2482 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_SECURITY].Size = dwValue;
2483 } 2483 }
2484 2484
2485 template<int x> 2485 template<int x>
2486 void PeHeaderT<x>::setIddTlsRva(dword dwValue) 2486 void PeHeaderT<x>::setIddTlsRva(dword dwValue)
2487 { 2487 {
2488 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_TLS].VirtualAddress = dwValue; 2488 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_TLS].VirtualAddress = dwValue;
2489 } 2489 }
2490 2490
2491 template<int x> 2491 template<int x>
2492 void PeHeaderT<x>::setIddTlsSize(dword dwValue) 2492 void PeHeaderT<x>::setIddTlsSize(dword dwValue)
2493 { 2493 {
2494 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_TLS].Size = dwValue; 2494 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_TLS].Size = dwValue;
2495 } 2495 }
2496 2496
2497 /** 2497 /**
2498 * Changes the rva of the file's export directory. 2498 * Changes the rva of the file's export directory.
2499 * @param dwValue New value. 2499 * @param dwValue New value.
2500 **/ 2500 **/
2501 template<int x> 2501 template<int x>
2502 void PeHeaderT<x>::setIddExportRva(dword dwValue) 2502 void PeHeaderT<x>::setIddExportRva(dword dwValue)
2503 { 2503 {
2504 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress = dwValue; 2504 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress = dwValue;
2505 } 2505 }
2506 2506
2507 /** 2507 /**
2508 * Changes the size of the file's export directory. 2508 * Changes the size of the file's export directory.
2509 * @param dwValue New value. 2509 * @param dwValue New value.
2510 **/ 2510 **/
2511 template<int x> 2511 template<int x>
2512 void PeHeaderT<x>::setIddExportSize(dword dwValue) 2512 void PeHeaderT<x>::setIddExportSize(dword dwValue)
2513 { 2513 {
2514 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_EXPORT].Size = dwValue; 2514 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_EXPORT].Size = dwValue;
2515 } 2515 }
2516 2516
2517 template<int x> 2517 template<int x>
2518 void PeHeaderT<x>::setIddBaseRelocRva(dword value) 2518 void PeHeaderT<x>::setIddBaseRelocRva(dword value)
2519 { 2519 {
2520 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress = value; 2520 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress = value;
2521 } 2521 }
2522 2522
2523 template<int x> 2523 template<int x>
2524 void PeHeaderT<x>::setIddBaseRelocSize(dword value) 2524 void PeHeaderT<x>::setIddBaseRelocSize(dword value)
2525 { 2525 {
2526 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_BASERELOC].Size = value; 2526 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_BASERELOC].Size = value;
2527 } 2527 }
2528 2528
2529 template<int x> 2529 template<int x>
2530 void PeHeaderT<x>::setIddArchitectureRva(dword value) 2530 void PeHeaderT<x>::setIddArchitectureRva(dword value)
2531 { 2531 {
2532 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_ARCHITECTURE].VirtualAddress = value; 2532 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_ARCHITECTURE].VirtualAddress = value;
2533 } 2533 }
2534 2534
2535 template<int x> 2535 template<int x>
2536 void PeHeaderT<x>::setIddArchitectureSize(dword value) 2536 void PeHeaderT<x>::setIddArchitectureSize(dword value)
2537 { 2537 {
2538 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_ARCHITECTURE].Size = value; 2538 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_ARCHITECTURE].Size = value;
2539 } 2539 }
2540 2540
2541 template<int x> 2541 template<int x>
2542 void PeHeaderT<x>::setIddComHeaderRva(dword value) 2542 void PeHeaderT<x>::setIddComHeaderRva(dword value)
2543 { 2543 {
2544 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress = value; 2544 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress = value;
2545 } 2545 }
2546 2546
2547 template<int x> 2547 template<int x>
2548 void PeHeaderT<x>::setIddComHeaderSize(dword value) 2548 void PeHeaderT<x>::setIddComHeaderSize(dword value)
2549 { 2549 {
2550 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].Size = value; 2550 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].Size = value;
2551 } 2551 }
2552 2552
2553 /** 2553 /**
2554 * Changes the rva of the file's import directory. 2554 * Changes the rva of the file's import directory.
2555 * @param dwValue New value. 2555 * @param dwValue New value.
2556 **/ 2556 **/
2557 template<int x> 2557 template<int x>
2558 void PeHeaderT<x>::setIddImportRva(dword dwValue) 2558 void PeHeaderT<x>::setIddImportRva(dword dwValue)
2559 { 2559 {
2560 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress = dwValue; 2560 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress = dwValue;
2561 } 2561 }
2562 2562
2563 /** 2563 /**
2564 * Changes the size of the file's import directory. 2564 * Changes the size of the file's import directory.
2565 * @param dwValue New value. 2565 * @param dwValue New value.
2566 **/ 2566 **/
2567 template<int x> 2567 template<int x>
2568 void PeHeaderT<x>::setIddImportSize(dword dwValue) 2568 void PeHeaderT<x>::setIddImportSize(dword dwValue)
2569 { 2569 {
2570 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_IMPORT].Size = dwValue; 2570 m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_IMPORT].Size = dwValue;
2571 } 2571 }
2572 2572
2573 /** 2573 /**
2574 * Changes the name of a section. 2574 * Changes the name of a section.
2575 * @param wSectionnr Identifier of the section 2575 * @param wSectionnr Identifier of the section
2576 * @param strName New name. 2576 * @param strName New name.
2577 **/ 2577 **/
2578 template<int x> 2578 template<int x>
2579 void PeHeaderT<x>::setSectionName(word wSectionnr, std::string strName) 2579 void PeHeaderT<x>::setSectionName(word wSectionnr, std::string strName)
2580 { 2580 {
2581 strncpy(reinterpret_cast<char*>(m_vIsh[wSectionnr].Name), strName.c_str(), sizeof(m_vIsh[wSectionnr].Name)); 2581 strncpy(reinterpret_cast<char*>(m_vIsh[wSectionnr].Name), strName.c_str(), sizeof(m_vIsh[wSectionnr].Name));
2582 } 2582 }
2583 2583
2584 /** 2584 /**
2585 * Changes the virtual size of a section. 2585 * Changes the virtual size of a section.
2586 * @param wSectionnr Identifier of the section 2586 * @param wSectionnr Identifier of the section
2587 * @param dwValue New value. 2587 * @param dwValue New value.
2588 **/ 2588 **/
2589 template<int x> 2589 template<int x>
2590 void PeHeaderT<x>::setVirtualSize(word wSectionnr, dword dwValue) 2590 void PeHeaderT<x>::setVirtualSize(word wSectionnr, dword dwValue)
2591 { 2591 {
2592 m_vIsh[wSectionnr].VirtualSize = dwValue; 2592 m_vIsh[wSectionnr].VirtualSize = dwValue;
2593 } 2593 }
2594 2594
2595 /** 2595 /**
2596 * Changes the virtual address of a section. 2596 * Changes the virtual address of a section.
2597 * @param wSectionnr Identifier of the section 2597 * @param wSectionnr Identifier of the section
2598 * @param dwValue New value. 2598 * @param dwValue New value.
2599 **/ 2599 **/
2600 template<int x> 2600 template<int x>
2601 void PeHeaderT<x>::setVirtualAddress(word wSectionnr, dword dwValue) 2601 void PeHeaderT<x>::setVirtualAddress(word wSectionnr, dword dwValue)
2602 { 2602 {
2603 m_vIsh[wSectionnr].VirtualAddress = dwValue; 2603 m_vIsh[wSectionnr].VirtualAddress = dwValue;
2604 } 2604 }
2605 2605
2606 /** 2606 /**
2607 * Changes the size of raw data of a section. 2607 * Changes the size of raw data of a section.
2608 * @param wSectionnr Identifier of the section 2608 * @param wSectionnr Identifier of the section
2609 * @param dwValue New value. 2609 * @param dwValue New value.
2610 **/ 2610 **/
2611 template<int x> 2611 template<int x>
2612 void PeHeaderT<x>::setSizeOfRawData(word wSectionnr, dword dwValue) 2612 void PeHeaderT<x>::setSizeOfRawData(word wSectionnr, dword dwValue)
2613 { 2613 {
2614 m_vIsh[wSectionnr].SizeOfRawData = dwValue; 2614 m_vIsh[wSectionnr].SizeOfRawData = dwValue;
2615 } 2615 }
2616 2616
2617 /** 2617 /**
2618 * Changes the size of raw data of a section. 2618 * Changes the size of raw data of a section.
2619 * @param wSectionnr Identifier of the section 2619 * @param wSectionnr Identifier of the section
2620 * @param dwValue New value. 2620 * @param dwValue New value.
2621 **/ 2621 **/
2622 template<int x> 2622 template<int x>
2623 void PeHeaderT<x>::setPointerToRawData(word wSectionnr, dword dwValue) 2623 void PeHeaderT<x>::setPointerToRawData(word wSectionnr, dword dwValue)
2624 { 2624 {
2625 m_vIsh[wSectionnr].PointerToRawData = dwValue; 2625 m_vIsh[wSectionnr].PointerToRawData = dwValue;
2626 } 2626 }
2627 2627
2628 /** 2628 /**
2629 * Changes the pointer to relocations of a section. 2629 * Changes the pointer to relocations of a section.
2630 * @param wSectionnr Identifier of the section 2630 * @param wSectionnr Identifier of the section
2631 * @param dwValue New value. 2631 * @param dwValue New value.
2632 **/ 2632 **/
2633 template<int x> 2633 template<int x>
2634 void PeHeaderT<x>::setPointerToRelocations(word wSectionnr, dword dwValue) 2634 void PeHeaderT<x>::setPointerToRelocations(word wSectionnr, dword dwValue)
2635 { 2635 {
2636 m_vIsh[wSectionnr].PointerToRelocations = dwValue; 2636 m_vIsh[wSectionnr].PointerToRelocations = dwValue;
2637 } 2637 }
2638 2638
2639 /** 2639 /**
2640 * Changes the pointer to line numbers of a section. 2640 * Changes the pointer to line numbers of a section.
2641 * @param wSectionnr Identifier of the section 2641 * @param wSectionnr Identifier of the section
2642 * @param dwValue New value. 2642 * @param dwValue New value.
2643 **/ 2643 **/
2644 template<int x> 2644 template<int x>
2645 void PeHeaderT<x>::setPointerToLinenumbers(word wSectionnr, dword dwValue) 2645 void PeHeaderT<x>::setPointerToLinenumbers(word wSectionnr, dword dwValue)
2646 { 2646 {
2647 m_vIsh[wSectionnr].PointerToLinenumbers = dwValue; 2647 m_vIsh[wSectionnr].PointerToLinenumbers = dwValue;
2648 } 2648 }
2649 2649
2650 /** 2650 /**
2651 * Changes the number of relocations of a section. 2651 * Changes the number of relocations of a section.
2652 * @param wSectionnr Identifier of the section 2652 * @param wSectionnr Identifier of the section
2653 * @param dwValue New value. 2653 * @param dwValue New value.
2654 **/ 2654 **/
2655 template<int x> 2655 template<int x>
2656 void PeHeaderT<x>::setNumberOfRelocations(word wSectionnr, dword dwValue) 2656 void PeHeaderT<x>::setNumberOfRelocations(word wSectionnr, dword dwValue)
2657 { 2657 {
2658 m_vIsh[wSectionnr].NumberOfRelocations = dwValue; 2658 m_vIsh[wSectionnr].NumberOfRelocations = dwValue;
2659 } 2659 }
2660 2660
2661 /** 2661 /**
2662 * Changes the number of line numbers of a section. 2662 * Changes the number of line numbers of a section.
2663 * @param wSectionnr Identifier of the section 2663 * @param wSectionnr Identifier of the section
2664 * @param dwValue New value. 2664 * @param dwValue New value.
2665 **/ 2665 **/
2666 template<int x> 2666 template<int x>
2667 void PeHeaderT<x>::setNumberOfLinenumbers(word wSectionnr, dword dwValue) 2667 void PeHeaderT<x>::setNumberOfLinenumbers(word wSectionnr, dword dwValue)
2668 { 2668 {
2669 m_vIsh[wSectionnr].NumberOfLinenumbers = dwValue; 2669 m_vIsh[wSectionnr].NumberOfLinenumbers = dwValue;
2670 } 2670 }
2671 2671
2672 /** 2672 /**
2673 * Changes the characteristics of a section. 2673 * Changes the characteristics of a section.
2674 * @param wSectionnr Identifier of the section 2674 * @param wSectionnr Identifier of the section
2675 * @param dwValue New value. 2675 * @param dwValue New value.
2676 **/ 2676 **/
2677 template<int x> 2677 template<int x>
2678 void PeHeaderT<x>::setCharacteristics(word wSectionnr, dword dwValue) 2678 void PeHeaderT<x>::setCharacteristics(word wSectionnr, dword dwValue)
2679 { 2679 {
2680 m_vIsh[wSectionnr].Characteristics = dwValue; 2680 m_vIsh[wSectionnr].Characteristics = dwValue;
2681 } 2681 }
2682 2682
2683} 2683}
2684 2684
2685#endif 2685#endif
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/PeLib.h b/utils/zenutils/libraries/pelib-0.9/pelib/PeLib.h
index 870c873606..12f9693dda 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/PeLib.h
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/PeLib.h
@@ -1,27 +1,27 @@
1/* 1/*
2* PeLib.h - Part of the PeLib library. 2* PeLib.h - Part of the PeLib library.
3* 3*
4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) 4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5* All rights reserved. 5* All rights reserved.
6* 6*
7* This software is licensed under the zlib/libpng License. 7* This software is licensed under the zlib/libpng License.
8* For more details see http://www.opensource.org/licenses/zlib-license.php 8* For more details see http://www.opensource.org/licenses/zlib-license.php
9* or the license information file (license.htm) in the root directory 9* or the license information file (license.htm) in the root directory
10* of PeLib. 10* of PeLib.
11*/ 11*/
12 12
13 13
14/** \mainpage PeLib - An open-source C++ library to modify PE files. 14/** \mainpage PeLib - An open-source C++ library to modify PE files.
15* 15*
16* \section intro Introduction 16* \section intro Introduction
17* 17*
18* <b>What is PeLib?</b><br> 18* <b>What is PeLib?</b><br>
19* PeLib is an open source C++ library with the purpose to ease the access and modification of PE (Portable executable) files. This is done through a multitude of classes which represent all important PE header and directory structures and which provide the necessary functions to read, modify and write these structures. As this library is fully ISO C++ compliant it should compile with all popular compilers for the Windows platform. For people who don't use C++ in their projects a dynamic link library is provided which encapsulates all of PeLib's functionality so that projects using programming languages as diverse as Win32 assembler, C# or Delphi can still benefit from PeLib's power 19* PeLib is an open source C++ library with the purpose to ease the access and modification of PE (Portable executable) files. This is done through a multitude of classes which represent all important PE header and directory structures and which provide the necessary functions to read, modify and write these structures. As this library is fully ISO C++ compliant it should compile with all popular compilers for the Windows platform. For people who don't use C++ in their projects a dynamic link library is provided which encapsulates all of PeLib's functionality so that projects using programming languages as diverse as Win32 assembler, C# or Delphi can still benefit from PeLib's power
20*/ 20*/
21 21
22#ifndef PELIB_H 22#ifndef PELIB_H
23#define PELIB_H 23#define PELIB_H
24 24
25#include "PeFile.h" 25#include "PeFile.h"
26 26
27#endif 27#endif
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/PeLibAux.cpp b/utils/zenutils/libraries/pelib-0.9/pelib/PeLibAux.cpp
index 1e06bae620..0a420ebecf 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/PeLibAux.cpp
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/PeLibAux.cpp
@@ -1,275 +1,275 @@
1/* 1/*
2* PeLibAux.cpp - Part of the PeLib library. 2* PeLibAux.cpp - Part of the PeLib library.
3* 3*
4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) 4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5* All rights reserved. 5* All rights reserved.
6* 6*
7* This software is licensed under the zlib/libpng License. 7* This software is licensed under the zlib/libpng License.
8* For more details see http://www.opensource.org/licenses/zlib-license.php 8* For more details see http://www.opensource.org/licenses/zlib-license.php
9* or the license information file (license.htm) in the root directory 9* or the license information file (license.htm) in the root directory
10* of PeLib. 10* of PeLib.
11*/ 11*/
12 12
13#include "PeLibInc.h" 13#include "PeLibInc.h"
14#include "PeLibAux.h" 14#include "PeLibAux.h"
15#include "PeFile.h" 15#include "PeFile.h"
16 16
17#ifdef _MSC_VER 17#ifdef _MSC_VER
18 #include <ctype.h> 18 #include <ctype.h>
19#endif 19#endif
20 20
21namespace PeLib 21namespace PeLib
22{ 22{
23 const qword PELIB_IMAGE_ORDINAL_FLAGS<64>::IMAGE_ORDINAL_FLAG = 0x8000000000000000ULL; 23 const qword PELIB_IMAGE_ORDINAL_FLAGS<64>::IMAGE_ORDINAL_FLAG = 0x8000000000000000ULL;
24 24
25 bool PELIB_IMAGE_SECTION_HEADER::biggerFileOffset(const PELIB_IMAGE_SECTION_HEADER& ish) const 25 bool PELIB_IMAGE_SECTION_HEADER::biggerFileOffset(const PELIB_IMAGE_SECTION_HEADER& ish) const
26 { 26 {
27 return PointerToRawData < ish.PointerToRawData; 27 return PointerToRawData < ish.PointerToRawData;
28 } 28 }
29 29
30 bool PELIB_IMAGE_SECTION_HEADER::biggerVirtualAddress(const PELIB_IMAGE_SECTION_HEADER& ish) const 30 bool PELIB_IMAGE_SECTION_HEADER::biggerVirtualAddress(const PELIB_IMAGE_SECTION_HEADER& ish) const
31 { 31 {
32 return VirtualAddress < ish.VirtualAddress; 32 return VirtualAddress < ish.VirtualAddress;
33 } 33 }
34 34
35 unsigned int alignOffset(unsigned int uiOffset, unsigned int uiAlignment) 35 unsigned int alignOffset(unsigned int uiOffset, unsigned int uiAlignment)
36 { 36 {
37 if (!uiAlignment) return uiAlignment; 37 if (!uiAlignment) return uiAlignment;
38 return (uiOffset % uiAlignment) ? uiOffset + (uiAlignment - uiOffset % uiAlignment) : uiOffset; 38 return (uiOffset % uiAlignment) ? uiOffset + (uiAlignment - uiOffset % uiAlignment) : uiOffset;
39 } 39 }
40 40
41 unsigned int fileSize(const std::string& filename) 41 unsigned int fileSize(const std::string& filename)
42 { 42 {
43 std::fstream file(filename.c_str()); 43 std::fstream file(filename.c_str());
44 file.seekg(0, std::ios::end); 44 file.seekg(0, std::ios::end);
45 return file.tellg(); 45 return file.tellg();
46 } 46 }
47 47
48 unsigned int fileSize(std::ifstream& file) 48 unsigned int fileSize(std::ifstream& file)
49 { 49 {
50 unsigned int oldpos = file.tellg(); 50 unsigned int oldpos = file.tellg();
51 file.seekg(0, std::ios::end); 51 file.seekg(0, std::ios::end);
52 unsigned int filesize = file.tellg(); 52 unsigned int filesize = file.tellg();
53 file.seekg(oldpos, std::ios::beg); 53 file.seekg(oldpos, std::ios::beg);
54 return filesize; 54 return filesize;
55 } 55 }
56 56
57 unsigned int fileSize(std::fstream& file) 57 unsigned int fileSize(std::fstream& file)
58 { 58 {
59 unsigned int oldpos = file.tellg(); 59 unsigned int oldpos = file.tellg();
60 file.seekg(0, std::ios::end); 60 file.seekg(0, std::ios::end);
61 unsigned int filesize = file.tellg(); 61 unsigned int filesize = file.tellg();
62 file.seekg(oldpos, std::ios::beg); 62 file.seekg(oldpos, std::ios::beg);
63 return filesize; 63 return filesize;
64 } 64 }
65 65
66 unsigned int fileSize(std::ofstream& file) 66 unsigned int fileSize(std::ofstream& file)
67 { 67 {
68 unsigned int oldpos = file.tellp(); 68 unsigned int oldpos = file.tellp();
69 file.seekp(0, std::ios::end); 69 file.seekp(0, std::ios::end);
70 unsigned int filesize = file.tellp(); 70 unsigned int filesize = file.tellp();
71 file.seekp(oldpos, std::ios::beg); 71 file.seekp(oldpos, std::ios::beg);
72 return filesize; 72 return filesize;
73 } 73 }
74 74
75 bool isEqualNc(const std::string& s1, const std::string& s2) 75 bool isEqualNc(const std::string& s1, const std::string& s2)
76 { 76 {
77 std::string t1 = s1; 77 std::string t1 = s1;
78 std::string t2 = s2; 78 std::string t2 = s2;
79 79
80 // No std:: to make VC++ happy 80 // No std:: to make VC++ happy
81 #ifdef _MSC_VER 81 #ifdef _MSC_VER
82 std::transform(t1.begin(), t1.end(), t1.begin(), toupper); 82 std::transform(t1.begin(), t1.end(), t1.begin(), toupper);
83 std::transform(t2.begin(), t2.end(), t2.begin(), toupper); 83 std::transform(t2.begin(), t2.end(), t2.begin(), toupper);
84 #else 84 #else
85 // Weird syntax to make Borland C++ happy 85 // Weird syntax to make Borland C++ happy
86 std::transform(t1.begin(), t1.end(), t1.begin(), (int(*)(int))std::toupper); 86 std::transform(t1.begin(), t1.end(), t1.begin(), (int(*)(int))std::toupper);
87 std::transform(t2.begin(), t2.end(), t2.begin(), (int(*)(int))std::toupper); 87 std::transform(t2.begin(), t2.end(), t2.begin(), (int(*)(int))std::toupper);
88 #endif 88 #endif
89 return t1 == t2; 89 return t1 == t2;
90 } 90 }
91 91
92 PELIB_IMAGE_DOS_HEADER::PELIB_IMAGE_DOS_HEADER() 92 PELIB_IMAGE_DOS_HEADER::PELIB_IMAGE_DOS_HEADER()
93 { 93 {
94 e_magic = 0; 94 e_magic = 0;
95 e_cblp = 0; 95 e_cblp = 0;
96 e_cp = 0; 96 e_cp = 0;
97 e_crlc = 0; 97 e_crlc = 0;
98 e_cparhdr = 0; 98 e_cparhdr = 0;
99 e_minalloc = 0; 99 e_minalloc = 0;
100 e_maxalloc = 0; 100 e_maxalloc = 0;
101 e_ss = 0; 101 e_ss = 0;
102 e_sp = 0; 102 e_sp = 0;
103 e_csum = 0; 103 e_csum = 0;
104 e_ip = 0; 104 e_ip = 0;
105 e_cs = 0; 105 e_cs = 0;
106 e_lfarlc = 0; 106 e_lfarlc = 0;
107 e_ovno = 0; 107 e_ovno = 0;
108 108
109 for (unsigned int i=0;i<sizeof(e_res)/sizeof(e_res[0]);i++) 109 for (unsigned int i=0;i<sizeof(e_res)/sizeof(e_res[0]);i++)
110 { 110 {
111 e_res[i] = 0; 111 e_res[i] = 0;
112 } 112 }
113 113
114 e_oemid = 0; 114 e_oemid = 0;
115 e_oeminfo = 0; 115 e_oeminfo = 0;
116 116
117 for (unsigned int i=0;i<sizeof(e_res2)/sizeof(e_res2[0]);i++) 117 for (unsigned int i=0;i<sizeof(e_res2)/sizeof(e_res2[0]);i++)
118 { 118 {
119 e_res2[i] = 0; 119 e_res2[i] = 0;
120 } 120 }
121 121
122 e_lfanew = 0; 122 e_lfanew = 0;
123 } 123 }
124 124
125 PELIB_EXP_FUNC_INFORMATION::PELIB_EXP_FUNC_INFORMATION() 125 PELIB_EXP_FUNC_INFORMATION::PELIB_EXP_FUNC_INFORMATION()
126 { 126 {
127 addroffunc = 0; 127 addroffunc = 0;
128 addrofname = 0; 128 addrofname = 0;
129 ordinal = 0; 129 ordinal = 0;
130 } 130 }
131 131
132 PELIB_IMAGE_RESOURCE_DIRECTORY::PELIB_IMAGE_RESOURCE_DIRECTORY() 132 PELIB_IMAGE_RESOURCE_DIRECTORY::PELIB_IMAGE_RESOURCE_DIRECTORY()
133 { 133 {
134 Characteristics = 0; 134 Characteristics = 0;
135 TimeDateStamp = 0; 135 TimeDateStamp = 0;
136 MajorVersion = 0; 136 MajorVersion = 0;
137 MinorVersion = 0; 137 MinorVersion = 0;
138 NumberOfNamedEntries = 0; 138 NumberOfNamedEntries = 0;
139 NumberOfIdEntries = 0; 139 NumberOfIdEntries = 0;
140 } 140 }
141 141
142 PELIB_IMAGE_RESOURCE_DIRECTORY_ENTRY::PELIB_IMAGE_RESOURCE_DIRECTORY_ENTRY() 142 PELIB_IMAGE_RESOURCE_DIRECTORY_ENTRY::PELIB_IMAGE_RESOURCE_DIRECTORY_ENTRY()
143 { 143 {
144 Name = 0; 144 Name = 0;
145 OffsetToData = 0; 145 OffsetToData = 0;
146 } 146 }
147 147
148 bool PELIB_IMG_RES_DIR_ENTRY::operator<(const PELIB_IMG_RES_DIR_ENTRY& first) const 148 bool PELIB_IMG_RES_DIR_ENTRY::operator<(const PELIB_IMG_RES_DIR_ENTRY& first) const
149 { 149 {
150 if (irde.Name & PELIB_IMAGE_RESOURCE_NAME_IS_STRING && first.irde.Name & PELIB_IMAGE_RESOURCE_NAME_IS_STRING) 150 if (irde.Name & PELIB_IMAGE_RESOURCE_NAME_IS_STRING && first.irde.Name & PELIB_IMAGE_RESOURCE_NAME_IS_STRING)
151 { 151 {
152 return wstrName < first.wstrName; 152 return wstrName < first.wstrName;
153 } 153 }
154 else if (irde.Name & PELIB_IMAGE_RESOURCE_NAME_IS_STRING) 154 else if (irde.Name & PELIB_IMAGE_RESOURCE_NAME_IS_STRING)
155 { 155 {
156 return true; 156 return true;
157 } 157 }
158 else if (first.irde.Name & PELIB_IMAGE_RESOURCE_NAME_IS_STRING) 158 else if (first.irde.Name & PELIB_IMAGE_RESOURCE_NAME_IS_STRING)
159 { 159 {
160 return false; 160 return false;
161 } 161 }
162 else 162 else
163 { 163 {
164 return irde.Name < first.irde.Name; 164 return irde.Name < first.irde.Name;
165 } 165 }
166 } 166 }
167 167
168 PELIB_IMAGE_BASE_RELOCATION::PELIB_IMAGE_BASE_RELOCATION() 168 PELIB_IMAGE_BASE_RELOCATION::PELIB_IMAGE_BASE_RELOCATION()
169 { 169 {
170 VirtualAddress = 0; 170 VirtualAddress = 0;
171 SizeOfBlock = 0; 171 SizeOfBlock = 0;
172 } 172 }
173 173
174 PELIB_IMAGE_COR20_HEADER::PELIB_IMAGE_COR20_HEADER() 174 PELIB_IMAGE_COR20_HEADER::PELIB_IMAGE_COR20_HEADER()
175 { 175 {
176 cb = 0; 176 cb = 0;
177 MajorRuntimeVersion = 0; 177 MajorRuntimeVersion = 0;
178 MinorRuntimeVersion = 0; 178 MinorRuntimeVersion = 0;
179 MetaData.VirtualAddress = 0; 179 MetaData.VirtualAddress = 0;
180 MetaData.Size = 0; 180 MetaData.Size = 0;
181 Flags = 0; 181 Flags = 0;
182 EntryPointToken = 0; 182 EntryPointToken = 0;
183 Resources.VirtualAddress = 0; 183 Resources.VirtualAddress = 0;
184 Resources.Size = 0; 184 Resources.Size = 0;
185 StrongNameSignature.VirtualAddress = 0; 185 StrongNameSignature.VirtualAddress = 0;
186 StrongNameSignature.Size = 0; 186 StrongNameSignature.Size = 0;
187 CodeManagerTable.VirtualAddress = 0; 187 CodeManagerTable.VirtualAddress = 0;
188 CodeManagerTable.Size = 0; 188 CodeManagerTable.Size = 0;
189 VTableFixups.VirtualAddress = 0; 189 VTableFixups.VirtualAddress = 0;
190 VTableFixups.Size = 0; 190 VTableFixups.Size = 0;
191 ExportAddressTableJumps.VirtualAddress = 0; 191 ExportAddressTableJumps.VirtualAddress = 0;
192 ExportAddressTableJumps.Size = 0; 192 ExportAddressTableJumps.Size = 0;
193 ManagedNativeHeader.VirtualAddress = 0; 193 ManagedNativeHeader.VirtualAddress = 0;
194 ManagedNativeHeader.Size = 0; 194 ManagedNativeHeader.Size = 0;
195 } 195 }
196 196
197 /** Compares the passed filename to the struct's filename. 197 /** Compares the passed filename to the struct's filename.
198 * @param strModuleName A filename. 198 * @param strModuleName A filename.
199 * @return True, if the passed filename equals the struct's filename. The comparison is case-sensitive. 199 * @return True, if the passed filename equals the struct's filename. The comparison is case-sensitive.
200 **/ 200 **/
201 bool PELIB_IMAGE_BOUND_DIRECTORY::equal(const std::string strModuleName) const 201 bool PELIB_IMAGE_BOUND_DIRECTORY::equal(const std::string strModuleName) const
202 { 202 {
203 return this->strModuleName == strModuleName; 203 return this->strModuleName == strModuleName;
204 } 204 }
205 205
206 bool PELIB_EXP_FUNC_INFORMATION::equal(const std::string strFunctionName) const 206 bool PELIB_EXP_FUNC_INFORMATION::equal(const std::string strFunctionName) const
207 { 207 {
208 return isEqualNc(this->funcname, strFunctionName); 208 return isEqualNc(this->funcname, strFunctionName);
209 } 209 }
210 210
211 /** 211 /**
212 * @param strFilename Name of a file. 212 * @param strFilename Name of a file.
213 * @return Either PEFILE32, PEFILE64 or PEFILE_UNKNOWN 213 * @return Either PEFILE32, PEFILE64 or PEFILE_UNKNOWN
214 **/ 214 **/
215 unsigned int getFileType(const std::string strFilename) 215 unsigned int getFileType(const std::string strFilename)
216 { 216 {
217 word machine, magic; 217 word machine, magic;
218 218
219 PeFile32 pef(strFilename); 219 PeFile32 pef(strFilename);
220 if (pef.readMzHeader() != NO_ERROR) return PEFILE_UNKNOWN; 220 if (pef.readMzHeader() != NO_ERROR) return PEFILE_UNKNOWN;
221 if (pef.readPeHeader() != NO_ERROR) return PEFILE_UNKNOWN; 221 if (pef.readPeHeader() != NO_ERROR) return PEFILE_UNKNOWN;
222 222
223 machine = pef.peHeader().getMachine(); 223 machine = pef.peHeader().getMachine();
224 magic = pef.peHeader().getMagic(); 224 magic = pef.peHeader().getMagic();
225 225
226 if (machine == PELIB_IMAGE_FILE_MACHINE_I386 && magic == PELIB_IMAGE_NT_OPTIONAL_HDR32_MAGIC) 226 if (machine == PELIB_IMAGE_FILE_MACHINE_I386 && magic == PELIB_IMAGE_NT_OPTIONAL_HDR32_MAGIC)
227 { 227 {
228 return PEFILE32; 228 return PEFILE32;
229 } 229 }
230 // 0x8664 == AMD64; no named constant yet 230 // 0x8664 == AMD64; no named constant yet
231 else if ((machine == 0x8664 || machine == PELIB_IMAGE_FILE_MACHINE_IA64) && magic == PELIB_IMAGE_NT_OPTIONAL_HDR64_MAGIC) 231 else if ((machine == 0x8664 || machine == PELIB_IMAGE_FILE_MACHINE_IA64) && magic == PELIB_IMAGE_NT_OPTIONAL_HDR64_MAGIC)
232 { 232 {
233 return PEFILE64; 233 return PEFILE64;
234 } 234 }
235 else 235 else
236 { 236 {
237 return PEFILE_UNKNOWN; 237 return PEFILE_UNKNOWN;
238 } 238 }
239 } 239 }
240 240
241 /** 241 /**
242 * Opens a PE file. The return type is either PeFile32 or PeFile64 object. If an error occurs the return 242 * Opens a PE file. The return type is either PeFile32 or PeFile64 object. If an error occurs the return
243 * value is 0. 243 * value is 0.
244 * @param strFilename Name of a file. 244 * @param strFilename Name of a file.
245 * @return Either a PeFile32 object, a PeFil64 object or 0. 245 * @return Either a PeFile32 object, a PeFil64 object or 0.
246 **/ 246 **/
247 PeFile* openPeFile(const std::string& strFilename) 247 PeFile* openPeFile(const std::string& strFilename)
248 { 248 {
249 unsigned int type = getFileType(strFilename); 249 unsigned int type = getFileType(strFilename);
250 250
251 if (type == PEFILE32) 251 if (type == PEFILE32)
252 { 252 {
253 return new PeFile32(strFilename); 253 return new PeFile32(strFilename);
254 } 254 }
255 else if (type == PEFILE64) 255 else if (type == PEFILE64)
256 { 256 {
257 return new PeFile64(strFilename); 257 return new PeFile64(strFilename);
258 } 258 }
259 else 259 else
260 { 260 {
261 return 0; 261 return 0;
262 } 262 }
263 } 263 }
264 264
265 unsigned int PELIB_IMAGE_BOUND_DIRECTORY::size() const 265 unsigned int PELIB_IMAGE_BOUND_DIRECTORY::size() const
266 { 266 {
267 unsigned int size = 0; 267 unsigned int size = 0;
268 for (unsigned int i=0;i<moduleForwarders.size();i++) 268 for (unsigned int i=0;i<moduleForwarders.size();i++)
269 { 269 {
270 size += moduleForwarders[i].size(); 270 size += moduleForwarders[i].size();
271 } 271 }
272 272
273 return size + PELIB_IMAGE_BOUND_IMPORT_DESCRIPTOR::size() + strModuleName.size() + 1; 273 return size + PELIB_IMAGE_BOUND_IMPORT_DESCRIPTOR::size() + strModuleName.size() + 1;
274 } 274 }
275} 275}
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/PeLibAux.h b/utils/zenutils/libraries/pelib-0.9/pelib/PeLibAux.h
index 4aed866a7d..cfce60796f 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/PeLibAux.h
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/PeLibAux.h
@@ -1,884 +1,884 @@
1/* 1/*
2* PeLibAux.cpp - Part of the PeLib library. 2* PeLibAux.cpp - Part of the PeLib library.
3* 3*
4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) 4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5* All rights reserved. 5* All rights reserved.
6* 6*
7* This software is licensed under the zlib/libpng License. 7* This software is licensed under the zlib/libpng License.
8* For more details see http://www.opensource.org/licenses/zlib-license.php 8* For more details see http://www.opensource.org/licenses/zlib-license.php
9* or the license information file (license.htm) in the root directory 9* or the license information file (license.htm) in the root directory
10* of PeLib. 10* of PeLib.
11*/ 11*/
12 12
13#ifndef PELIBAUX_H 13#ifndef PELIBAUX_H
14#define PELIBAUX_H 14#define PELIBAUX_H
15 15
16//#include "PeLibInc.h" 16//#include "PeLibInc.h"
17//#include "PeHeader.h" 17//#include "PeHeader.h"
18#include "buffer/OutputBuffer.h" 18#include "buffer/OutputBuffer.h"
19#include "buffer/InputBuffer.h" 19#include "buffer/InputBuffer.h"
20//#include "buffer/ResTree.h" 20//#include "buffer/ResTree.h"
21#include <numeric> 21#include <numeric>
22#include <limits> 22#include <limits>
23 23
24namespace PeLib 24namespace PeLib
25{ 25{
26 enum errorCodes 26 enum errorCodes
27 { 27 {
28 NO_ERROR = 0, 28 NO_ERROR = 0,
29 ERROR_OPENING_FILE = -1, 29 ERROR_OPENING_FILE = -1,
30 ERROR_INVALID_FILE = -2, 30 ERROR_INVALID_FILE = -2,
31 ERROR_TOO_MANY_SECTIONS = -3, 31 ERROR_TOO_MANY_SECTIONS = -3,
32 ERROR_NOT_ENOUGH_SPACE = -4, 32 ERROR_NOT_ENOUGH_SPACE = -4,
33 ERROR_NO_FILE_ALIGNMENT = -5, 33 ERROR_NO_FILE_ALIGNMENT = -5,
34 ERROR_NO_SECTION_ALIGNMENT = -6, 34 ERROR_NO_SECTION_ALIGNMENT = -6,
35 ERROR_ENTRY_NOT_FOUND = -7, 35 ERROR_ENTRY_NOT_FOUND = -7,
36 ERROR_DUPLICATE_ENTRY = -8, 36 ERROR_DUPLICATE_ENTRY = -8,
37 ERROR_DIRECTORY_DOES_NOT_EXIST = -9 37 ERROR_DIRECTORY_DOES_NOT_EXIST = -9
38 }; 38 };
39 39
40 class PeFile; 40 class PeFile;
41 bool isEqualNc(const std::string& s1, const std::string& s2); 41 bool isEqualNc(const std::string& s1, const std::string& s2);
42 42
43// It's necessary to make sure that a byte has 8 bits and that the platform has a 8 bit type, 43// It's necessary to make sure that a byte has 8 bits and that the platform has a 8 bit type,
44// a 16bit type and a bit type. That's because binary PE files are pretty picky about their 44// a 16bit type and a bit type. That's because binary PE files are pretty picky about their
45// structure. 45// structure.
46 46
47 #if CHAR_BIT == 8 47 #if CHAR_BIT == 8
48 #if UCHAR_MAX == 255 48 #if UCHAR_MAX == 255
49 typedef unsigned char byte; 49 typedef unsigned char byte;
50 // typedef std::bitset<8> byte; 50 // typedef std::bitset<8> byte;
51 #else 51 #else
52 #error You need to change some typedefs (Code: 8). Please read the PeLib documentation. 52 #error You need to change some typedefs (Code: 8). Please read the PeLib documentation.
53 #endif 53 #endif
54 54
55 #if USHRT_MAX == 65535U 55 #if USHRT_MAX == 65535U
56 typedef unsigned short word; 56 typedef unsigned short word;
57 // typedef std::bitset<16> word; 57 // typedef std::bitset<16> word;
58 #else 58 #else
59 #error You need to change some typedefs (Code: 16). Please read the PeLib documentation. 59 #error You need to change some typedefs (Code: 16). Please read the PeLib documentation.
60 #endif 60 #endif
61 61
62 #if UINT_MAX == 4294967295UL 62 #if UINT_MAX == 4294967295UL
63 typedef unsigned int dword; 63 typedef unsigned int dword;
64 // typedef std::bitset<32> dword; 64 // typedef std::bitset<32> dword;
65 #else 65 #else
66 #error You need to change some typedefs (Code: 32). Please read the PeLib documentation. 66 #error You need to change some typedefs (Code: 32). Please read the PeLib documentation.
67 #endif 67 #endif
68 68
69 typedef unsigned long long qword; 69 typedef unsigned long long qword;
70 70
71// #if ULLONG_MAX == 18446744073709551615 71// #if ULLONG_MAX == 18446744073709551615
72// typedef unsigned long long qword; 72// typedef unsigned long long qword;
73// #else 73// #else
74// #error You need to change some typedefs (Code: 32). Please read the PeLib documentation. 74// #error You need to change some typedefs (Code: 32). Please read the PeLib documentation.
75// #endif 75// #endif
76 #else 76 #else
77 #error You need to change some typedefs. Please read the PeLib documentation. 77 #error You need to change some typedefs. Please read the PeLib documentation.
78 #endif 78 #endif
79 79
80 80
81/* enum bits {BITS_BYTE = 8, BITS_WORD = 16, BITS_DWORD = 32}; 81/* enum bits {BITS_BYTE = 8, BITS_WORD = 16, BITS_DWORD = 32};
82 82
83 template<bits value> 83 template<bits value>
84 class DataType 84 class DataType
85 { 85 {
86 private: 86 private:
87 std::bitset<value> bsValue; 87 std::bitset<value> bsValue;
88 unsigned long ulValue; 88 unsigned long ulValue;
89 89
90 public: 90 public:
91 void operator=(unsigned long ulValue) 91 void operator=(unsigned long ulValue)
92 { 92 {
93 bsValue = ulValue; 93 bsValue = ulValue;
94 } 94 }
95 95
96 operator unsigned long() const 96 operator unsigned long() const
97 { 97 {
98 return bsValue.to_ulong(); 98 return bsValue.to_ulong();
99 } 99 }
100 100
101 const int operator&() 101 const int operator&()
102 { 102 {
103 ulValue = bsValue; 103 ulValue = bsValue;
104 return ulValue; 104 return ulValue;
105 } 105 }
106 106
107 }; 107 };
108 108
109 typedef DataType<BITS_BYTE> byte; 109 typedef DataType<BITS_BYTE> byte;
110 typedef DataType<BITS_WORD> word; 110 typedef DataType<BITS_WORD> word;
111 typedef DataType<BITS_DWORD> dword; 111 typedef DataType<BITS_DWORD> dword;
112*/ 112*/
113 113
114 enum {PEFILE32 = 32, 114 enum {PEFILE32 = 32,
115 PEFILE64 = 64, 115 PEFILE64 = 64,
116 PEFILE_UNKNOWN = 0}; 116 PEFILE_UNKNOWN = 0};
117 117
118 enum {BoundImportDirectoryId = 1, 118 enum {BoundImportDirectoryId = 1,
119 ComHeaderDirectoryId, 119 ComHeaderDirectoryId,
120 ExportDirectoryId, 120 ExportDirectoryId,
121 IatDirectoryId, 121 IatDirectoryId,
122 ImportDirectoryId, 122 ImportDirectoryId,
123 MzHeaderId, 123 MzHeaderId,
124 PeHeaderId, 124 PeHeaderId,
125 RelocationsId, 125 RelocationsId,
126 PeFileId, 126 PeFileId,
127 ResourceDirectoryId, 127 ResourceDirectoryId,
128 DebugDirectoryId, 128 DebugDirectoryId,
129 TlsDirectoryId 129 TlsDirectoryId
130 }; 130 };
131 131
132 const word PELIB_IMAGE_DOS_SIGNATURE = 0x5A4D; 132 const word PELIB_IMAGE_DOS_SIGNATURE = 0x5A4D;
133 133
134 const dword PELIB_IMAGE_NT_SIGNATURE = 0x00004550; 134 const dword PELIB_IMAGE_NT_SIGNATURE = 0x00004550;
135 135
136 template<int bits> 136 template<int bits>
137 struct PELIB_IMAGE_ORDINAL_FLAGS; 137 struct PELIB_IMAGE_ORDINAL_FLAGS;
138 138
139 template<> 139 template<>
140 struct PELIB_IMAGE_ORDINAL_FLAGS<32> 140 struct PELIB_IMAGE_ORDINAL_FLAGS<32>
141 { 141 {
142 static const dword IMAGE_ORDINAL_FLAG = 0x80000000; 142 static const dword IMAGE_ORDINAL_FLAG = 0x80000000;
143 }; 143 };
144 144
145 template<> 145 template<>
146 struct PELIB_IMAGE_ORDINAL_FLAGS<64> 146 struct PELIB_IMAGE_ORDINAL_FLAGS<64>
147 { 147 {
148 static const qword IMAGE_ORDINAL_FLAG; 148 static const qword IMAGE_ORDINAL_FLAG;
149 }; 149 };
150 150
151 const unsigned long PELIB_IMAGE_NUMBEROF_DIRECTORY_ENTRIES = 16; 151 const unsigned long PELIB_IMAGE_NUMBEROF_DIRECTORY_ENTRIES = 16;
152 152
153 const unsigned long PELIB_IMAGE_RESOURCE_NAME_IS_STRING = 0x80000000; 153 const unsigned long PELIB_IMAGE_RESOURCE_NAME_IS_STRING = 0x80000000;
154 154
155 const unsigned long PELIB_IMAGE_RESOURCE_DATA_IS_DIRECTORY = 0x80000000; 155 const unsigned long PELIB_IMAGE_RESOURCE_DATA_IS_DIRECTORY = 0x80000000;
156 156
157 enum 157 enum
158 { 158 {
159 PELIB_IMAGE_DIRECTORY_ENTRY_EXPORT, // OK 159 PELIB_IMAGE_DIRECTORY_ENTRY_EXPORT, // OK
160 PELIB_IMAGE_DIRECTORY_ENTRY_IMPORT, // OK 160 PELIB_IMAGE_DIRECTORY_ENTRY_IMPORT, // OK
161 PELIB_IMAGE_DIRECTORY_ENTRY_RESOURCE, // OK 161 PELIB_IMAGE_DIRECTORY_ENTRY_RESOURCE, // OK
162 PELIB_IMAGE_DIRECTORY_ENTRY_EXCEPTION, 162 PELIB_IMAGE_DIRECTORY_ENTRY_EXCEPTION,
163 PELIB_IMAGE_DIRECTORY_ENTRY_SECURITY, 163 PELIB_IMAGE_DIRECTORY_ENTRY_SECURITY,
164 PELIB_IMAGE_DIRECTORY_ENTRY_BASERELOC, // OK 164 PELIB_IMAGE_DIRECTORY_ENTRY_BASERELOC, // OK
165 PELIB_IMAGE_DIRECTORY_ENTRY_DEBUG, 165 PELIB_IMAGE_DIRECTORY_ENTRY_DEBUG,
166 PELIB_IMAGE_DIRECTORY_ENTRY_ARCHITECTURE, 166 PELIB_IMAGE_DIRECTORY_ENTRY_ARCHITECTURE,
167 PELIB_IMAGE_DIRECTORY_ENTRY_GLOBALPTR, 167 PELIB_IMAGE_DIRECTORY_ENTRY_GLOBALPTR,
168 PELIB_IMAGE_DIRECTORY_ENTRY_TLS, 168 PELIB_IMAGE_DIRECTORY_ENTRY_TLS,
169 PELIB_IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG, 169 PELIB_IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG,
170 PELIB_IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT, // OK 170 PELIB_IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT, // OK
171 PELIB_IMAGE_DIRECTORY_ENTRY_IAT, // OK 171 PELIB_IMAGE_DIRECTORY_ENTRY_IAT, // OK
172 PELIB_IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT, 172 PELIB_IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT,
173 PELIB_IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR 173 PELIB_IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR
174 }; 174 };
175 175
176 enum 176 enum
177 { 177 {
178 PELIB_IMAGE_SCN_TYPE_NO_PAD = 0x00000008, 178 PELIB_IMAGE_SCN_TYPE_NO_PAD = 0x00000008,
179 PELIB_IMAGE_SCN_CNT_CODE = 0x00000020, 179 PELIB_IMAGE_SCN_CNT_CODE = 0x00000020,
180 PELIB_IMAGE_SCN_CNT_INITIALIZED_DATA = 0x00000040, 180 PELIB_IMAGE_SCN_CNT_INITIALIZED_DATA = 0x00000040,
181 PELIB_IMAGE_SCN_CNT_UNINITIALIZED_DATA = 0x00000080, 181 PELIB_IMAGE_SCN_CNT_UNINITIALIZED_DATA = 0x00000080,
182 PELIB_IMAGE_SCN_LNK_OTHER = 0x00000100, 182 PELIB_IMAGE_SCN_LNK_OTHER = 0x00000100,
183 PELIB_IMAGE_SCN_LNK_INFO = 0x00000200, 183 PELIB_IMAGE_SCN_LNK_INFO = 0x00000200,
184 PELIB_IMAGE_SCN_LNK_REMOVE = 0x00000800, 184 PELIB_IMAGE_SCN_LNK_REMOVE = 0x00000800,
185 PELIB_IMAGE_SCN_LNK_COMDAT = 0x00001000, 185 PELIB_IMAGE_SCN_LNK_COMDAT = 0x00001000,
186 PELIB_IMAGE_SCN_NO_DEFER_SPEC_EXC = 0x00004000, 186 PELIB_IMAGE_SCN_NO_DEFER_SPEC_EXC = 0x00004000,
187 PELIB_IMAGE_SCN_GPREL = 0x00008000, 187 PELIB_IMAGE_SCN_GPREL = 0x00008000,
188 PELIB_IMAGE_SCN_MEM_FARDATA = 0x00008000, 188 PELIB_IMAGE_SCN_MEM_FARDATA = 0x00008000,
189 PELIB_IMAGE_SCN_MEM_PURGEABLE = 0x00020000, 189 PELIB_IMAGE_SCN_MEM_PURGEABLE = 0x00020000,
190 PELIB_IMAGE_SCN_MEM_16BIT = 0x00020000, 190 PELIB_IMAGE_SCN_MEM_16BIT = 0x00020000,
191 PELIB_IMAGE_SCN_MEM_LOCKED = 0x00040000, 191 PELIB_IMAGE_SCN_MEM_LOCKED = 0x00040000,
192 PELIB_IMAGE_SCN_MEM_PRELOAD = 0x00080000, 192 PELIB_IMAGE_SCN_MEM_PRELOAD = 0x00080000,
193 PELIB_IMAGE_SCN_ALIGN_1BYTES = 0x00100000, 193 PELIB_IMAGE_SCN_ALIGN_1BYTES = 0x00100000,
194 PELIB_IMAGE_SCN_ALIGN_2BYTES = 0x00200000, 194 PELIB_IMAGE_SCN_ALIGN_2BYTES = 0x00200000,
195 PELIB_IMAGE_SCN_ALIGN_4BYTES = 0x00300000, 195 PELIB_IMAGE_SCN_ALIGN_4BYTES = 0x00300000,
196 PELIB_IMAGE_SCN_ALIGN_8BYTES = 0x00400000, 196 PELIB_IMAGE_SCN_ALIGN_8BYTES = 0x00400000,
197 PELIB_IMAGE_SCN_ALIGN_16BYTES = 0x00500000, 197 PELIB_IMAGE_SCN_ALIGN_16BYTES = 0x00500000,
198 PELIB_IMAGE_SCN_ALIGN_BYTES = 0x00600000, 198 PELIB_IMAGE_SCN_ALIGN_BYTES = 0x00600000,
199 PELIB_IMAGE_SCN_ALIGN_64BYTES = 0x00700000, 199 PELIB_IMAGE_SCN_ALIGN_64BYTES = 0x00700000,
200 PELIB_IMAGE_SCN_ALIGN_128BYTES = 0x00800000, 200 PELIB_IMAGE_SCN_ALIGN_128BYTES = 0x00800000,
201 PELIB_IMAGE_SCN_ALIGN_256BYTES = 0x00900000, 201 PELIB_IMAGE_SCN_ALIGN_256BYTES = 0x00900000,
202 PELIB_IMAGE_SCN_ALIGN_512BYTES = 0x00A00000, 202 PELIB_IMAGE_SCN_ALIGN_512BYTES = 0x00A00000,
203 PELIB_IMAGE_SCN_ALIGN_1024BYTES = 0x00B00000, 203 PELIB_IMAGE_SCN_ALIGN_1024BYTES = 0x00B00000,
204 PELIB_IMAGE_SCN_ALIGN_2048BYTES = 0x00C00000, 204 PELIB_IMAGE_SCN_ALIGN_2048BYTES = 0x00C00000,
205 PELIB_IMAGE_SCN_ALIGN_4096BYTES = 0x00D00000, 205 PELIB_IMAGE_SCN_ALIGN_4096BYTES = 0x00D00000,
206 PELIB_IMAGE_SCN_ALIGN_8192BYTES = 0x00E00000, 206 PELIB_IMAGE_SCN_ALIGN_8192BYTES = 0x00E00000,
207 PELIB_IMAGE_SCN_LNK_NRELOC_OVFL = 0x01000000, 207 PELIB_IMAGE_SCN_LNK_NRELOC_OVFL = 0x01000000,
208 PELIB_IMAGE_SCN_MEM_DISCARDABLE = 0x02000000, 208 PELIB_IMAGE_SCN_MEM_DISCARDABLE = 0x02000000,
209 PELIB_IMAGE_SCN_MEM_NOT_CACHED = 0x04000000, 209 PELIB_IMAGE_SCN_MEM_NOT_CACHED = 0x04000000,
210 PELIB_IMAGE_SCN_MEM_NOT_PAGED = 0x08000000, 210 PELIB_IMAGE_SCN_MEM_NOT_PAGED = 0x08000000,
211 PELIB_IMAGE_SCN_MEM_SHARED = 0x10000000, 211 PELIB_IMAGE_SCN_MEM_SHARED = 0x10000000,
212 PELIB_IMAGE_SCN_MEM_EXECUTE = 0x20000000, 212 PELIB_IMAGE_SCN_MEM_EXECUTE = 0x20000000,
213 PELIB_IMAGE_SCN_MEM_READ = 0x40000000, 213 PELIB_IMAGE_SCN_MEM_READ = 0x40000000,
214 PELIB_IMAGE_SCN_MEM_WRITE = 0x80000000 214 PELIB_IMAGE_SCN_MEM_WRITE = 0x80000000
215 }; 215 };
216 216
217 enum 217 enum
218 { 218 {
219 PELIB_IMAGE_FILE_MACHINE_UNKNOWN = 0, 219 PELIB_IMAGE_FILE_MACHINE_UNKNOWN = 0,
220 PELIB_IMAGE_FILE_MACHINE_I386 = 0x014c, 220 PELIB_IMAGE_FILE_MACHINE_I386 = 0x014c,
221 PELIB_IMAGE_FILE_MACHINE_R3000 = 0x0162, 221 PELIB_IMAGE_FILE_MACHINE_R3000 = 0x0162,
222 PELIB_IMAGE_FILE_MACHINE_R4000 = 0x0166, 222 PELIB_IMAGE_FILE_MACHINE_R4000 = 0x0166,
223 PELIB_IMAGE_FILE_MACHINE_R10000 = 0x0168, 223 PELIB_IMAGE_FILE_MACHINE_R10000 = 0x0168,
224 PELIB_IMAGE_FILE_MACHINE_WCEMIPSV2 = 0x0169, 224 PELIB_IMAGE_FILE_MACHINE_WCEMIPSV2 = 0x0169,
225 PELIB_IMAGE_FILE_MACHINE_ALPHA = 0x0184, 225 PELIB_IMAGE_FILE_MACHINE_ALPHA = 0x0184,
226 PELIB_IMAGE_FILE_MACHINE_POWERPC = 0x01F0, 226 PELIB_IMAGE_FILE_MACHINE_POWERPC = 0x01F0,
227 PELIB_IMAGE_FILE_MACHINE_SH3 = 0x01a2, 227 PELIB_IMAGE_FILE_MACHINE_SH3 = 0x01a2,
228 PELIB_IMAGE_FILE_MACHINE_SH3E = 0x01a4, 228 PELIB_IMAGE_FILE_MACHINE_SH3E = 0x01a4,
229 PELIB_IMAGE_FILE_MACHINE_SH4 = 0x01a6, 229 PELIB_IMAGE_FILE_MACHINE_SH4 = 0x01a6,
230 PELIB_IMAGE_FILE_MACHINE_ARM = 0x01c0, 230 PELIB_IMAGE_FILE_MACHINE_ARM = 0x01c0,
231 PELIB_IMAGE_FILE_MACHINE_THUMB = 0x01c2, 231 PELIB_IMAGE_FILE_MACHINE_THUMB = 0x01c2,
232 PELIB_IMAGE_FILE_MACHINE_IA64 = 0x0200, 232 PELIB_IMAGE_FILE_MACHINE_IA64 = 0x0200,
233 PELIB_IMAGE_FILE_MACHINE_MIPS16 = 0x0266, 233 PELIB_IMAGE_FILE_MACHINE_MIPS16 = 0x0266,
234 PELIB_IMAGE_FILE_MACHINE_MIPSFPU = 0x0366, 234 PELIB_IMAGE_FILE_MACHINE_MIPSFPU = 0x0366,
235 PELIB_IMAGE_FILE_MACHINE_MIPSFPU16 = 0x0466, 235 PELIB_IMAGE_FILE_MACHINE_MIPSFPU16 = 0x0466,
236 PELIB_IMAGE_FILE_MACHINE_ALPHA64 = 0x0284, 236 PELIB_IMAGE_FILE_MACHINE_ALPHA64 = 0x0284,
237 PELIB_IMAGE_FILE_MACHINE_AXP64 = PELIB_IMAGE_FILE_MACHINE_ALPHA64 237 PELIB_IMAGE_FILE_MACHINE_AXP64 = PELIB_IMAGE_FILE_MACHINE_ALPHA64
238 }; 238 };
239 239
240 enum 240 enum
241 { 241 {
242 PELIB_IMAGE_FILE_RELOCS_STRIPPED = 0x0001, 242 PELIB_IMAGE_FILE_RELOCS_STRIPPED = 0x0001,
243 PELIB_IMAGE_FILE_EXECUTABLE_IMAGE = 0x0002, 243 PELIB_IMAGE_FILE_EXECUTABLE_IMAGE = 0x0002,
244 PELIB_IMAGE_FILE_LINE_NUMS_STRIPPED = 0x0004, 244 PELIB_IMAGE_FILE_LINE_NUMS_STRIPPED = 0x0004,
245 PELIB_IMAGE_FILE_LOCAL_SYMS_STRIPPED = 0x0008, 245 PELIB_IMAGE_FILE_LOCAL_SYMS_STRIPPED = 0x0008,
246 PELIB_IMAGE_FILE_AGGRESIVE_WS_TRIM = 0x0010, 246 PELIB_IMAGE_FILE_AGGRESIVE_WS_TRIM = 0x0010,
247 PELIB_IMAGE_FILE_LARGE_ADDRESS_AWARE = 0x0020, 247 PELIB_IMAGE_FILE_LARGE_ADDRESS_AWARE = 0x0020,
248 PELIB_IMAGE_FILE_BYTES_REVERSED_LO = 0x0080, 248 PELIB_IMAGE_FILE_BYTES_REVERSED_LO = 0x0080,
249 PELIB_IMAGE_FILE_32BIT_MACHINE = 0x0100, 249 PELIB_IMAGE_FILE_32BIT_MACHINE = 0x0100,
250 PELIB_IMAGE_FILE_DEBUG_STRIPPED = 0x0200, 250 PELIB_IMAGE_FILE_DEBUG_STRIPPED = 0x0200,
251 PELIB_IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP = 0x0400, 251 PELIB_IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP = 0x0400,
252 PELIB_IMAGE_FILE_NET_RUN_FROM_SWAP = 0x0800, 252 PELIB_IMAGE_FILE_NET_RUN_FROM_SWAP = 0x0800,
253 PELIB_IMAGE_FILE_SYSTEM = 0x1000, 253 PELIB_IMAGE_FILE_SYSTEM = 0x1000,
254 PELIB_IMAGE_FILE_DLL = 0x2000, 254 PELIB_IMAGE_FILE_DLL = 0x2000,
255 PELIB_IMAGE_FILE_UP_SYSTEM_ONLY = 0x4000, 255 PELIB_IMAGE_FILE_UP_SYSTEM_ONLY = 0x4000,
256 PELIB_IMAGE_FILE_BYTES_REVERSED_HI = 0x8000 256 PELIB_IMAGE_FILE_BYTES_REVERSED_HI = 0x8000
257 }; 257 };
258 258
259 enum 259 enum
260 { 260 {
261 PELIB_IMAGE_NT_OPTIONAL_HDR32_MAGIC = 0x10b, 261 PELIB_IMAGE_NT_OPTIONAL_HDR32_MAGIC = 0x10b,
262 PELIB_IMAGE_NT_OPTIONAL_HDR64_MAGIC = 0x20b, 262 PELIB_IMAGE_NT_OPTIONAL_HDR64_MAGIC = 0x20b,
263 PELIB_IMAGE_ROM_OPTIONAL_HDR_MAGIC = 0x107 263 PELIB_IMAGE_ROM_OPTIONAL_HDR_MAGIC = 0x107
264 }; 264 };
265 265
266 enum 266 enum
267 { 267 {
268 PELIB_IMAGE_SUBSYSTEM_UNKNOWN = 0, 268 PELIB_IMAGE_SUBSYSTEM_UNKNOWN = 0,
269 PELIB_IMAGE_SUBSYSTEM_NATIVE = 1, 269 PELIB_IMAGE_SUBSYSTEM_NATIVE = 1,
270 PELIB_IMAGE_SUBSYSTEM_WINDOWS_GUI = 2, 270 PELIB_IMAGE_SUBSYSTEM_WINDOWS_GUI = 2,
271 PELIB_IMAGE_SUBSYSTEM_WINDOWS_CUI = 3, 271 PELIB_IMAGE_SUBSYSTEM_WINDOWS_CUI = 3,
272 PELIB_IMAGE_SUBSYSTEM_OS2_CUI = 5, 272 PELIB_IMAGE_SUBSYSTEM_OS2_CUI = 5,
273 PELIB_IMAGE_SUBSYSTEM_POSIX_CUI = 7, 273 PELIB_IMAGE_SUBSYSTEM_POSIX_CUI = 7,
274 PELIB_IMAGE_SUBSYSTEM_NATIVE_WINDOWS = 8, 274 PELIB_IMAGE_SUBSYSTEM_NATIVE_WINDOWS = 8,
275 PELIB_IMAGE_SUBSYSTEM_WINDOWS_CE_GUI = 9 275 PELIB_IMAGE_SUBSYSTEM_WINDOWS_CE_GUI = 9
276 }; 276 };
277 277
278 enum 278 enum
279 { 279 {
280 PELIB_RT_CURSOR = 1, // 1 280 PELIB_RT_CURSOR = 1, // 1
281 PELIB_RT_BITMAP, // 2 281 PELIB_RT_BITMAP, // 2
282 PELIB_RT_ICON, // 3 282 PELIB_RT_ICON, // 3
283 PELIB_RT_MENU, // 4 283 PELIB_RT_MENU, // 4
284 PELIB_RT_DIALOG, // 5 284 PELIB_RT_DIALOG, // 5
285 PELIB_RT_STRING, // 6 285 PELIB_RT_STRING, // 6
286 PELIB_RT_FONTDIR, // 7 286 PELIB_RT_FONTDIR, // 7
287 PELIB_RT_FONT, // 8 287 PELIB_RT_FONT, // 8
288 PELIB_RT_ACCELERATOR, // 9 288 PELIB_RT_ACCELERATOR, // 9
289 PELIB_RT_RCDATA, // 10 289 PELIB_RT_RCDATA, // 10
290 PELIB_RT_MESSAGETABLE, // 11 290 PELIB_RT_MESSAGETABLE, // 11
291 PELIB_RT_GROUP_CURSOR, // 12 291 PELIB_RT_GROUP_CURSOR, // 12
292 PELIB_RT_GROUP_ICON = 14, // 14 292 PELIB_RT_GROUP_ICON = 14, // 14
293 PELIB_RT_VERSION = 16, 293 PELIB_RT_VERSION = 16,
294 PELIB_RT_DLGINCLUDE, 294 PELIB_RT_DLGINCLUDE,
295 PELIB_RT_PLUGPLAY = 19, 295 PELIB_RT_PLUGPLAY = 19,
296 PELIB_RT_VXD, 296 PELIB_RT_VXD,
297 PELIB_RT_ANICURSOR, 297 PELIB_RT_ANICURSOR,
298 PELIB_RT_ANIICON, 298 PELIB_RT_ANIICON,
299 PELIB_RT_HTML, 299 PELIB_RT_HTML,
300 PELIB_RT_MANIFEST 300 PELIB_RT_MANIFEST
301 }; 301 };
302 302
303 template<typename T> 303 template<typename T>
304 unsigned int accumulate(unsigned int size, const T& v) 304 unsigned int accumulate(unsigned int size, const T& v)
305 { 305 {
306 return size + v.size(); 306 return size + v.size();
307 } 307 }
308 308
309 309
310 struct PELIB_IMAGE_DOS_HEADER 310 struct PELIB_IMAGE_DOS_HEADER
311 { 311 {
312 word e_magic; 312 word e_magic;
313 word e_cblp; 313 word e_cblp;
314 word e_cp; 314 word e_cp;
315 word e_crlc; 315 word e_crlc;
316 word e_cparhdr; 316 word e_cparhdr;
317 word e_minalloc; 317 word e_minalloc;
318 word e_maxalloc; 318 word e_maxalloc;
319 word e_ss; 319 word e_ss;
320 word e_sp; 320 word e_sp;
321 word e_csum; 321 word e_csum;
322 word e_ip; 322 word e_ip;
323 word e_cs; 323 word e_cs;
324 word e_lfarlc; 324 word e_lfarlc;
325 word e_ovno; 325 word e_ovno;
326 word e_res[4]; 326 word e_res[4];
327 word e_oemid; 327 word e_oemid;
328 word e_oeminfo; 328 word e_oeminfo;
329 word e_res2[10]; 329 word e_res2[10];
330 dword e_lfanew; 330 dword e_lfanew;
331 331
332 PELIB_IMAGE_DOS_HEADER(); 332 PELIB_IMAGE_DOS_HEADER();
333 333
334 static inline unsigned int size() {return 64;} 334 static inline unsigned int size() {return 64;}
335 }; 335 };
336 336
337 struct PELIB_IMAGE_FILE_HEADER 337 struct PELIB_IMAGE_FILE_HEADER
338 { 338 {
339 word Machine; 339 word Machine;
340 word NumberOfSections; 340 word NumberOfSections;
341 dword TimeDateStamp; 341 dword TimeDateStamp;
342 dword PointerToSymbolTable; 342 dword PointerToSymbolTable;
343 dword NumberOfSymbols; 343 dword NumberOfSymbols;
344 word SizeOfOptionalHeader; 344 word SizeOfOptionalHeader;
345 word Characteristics; 345 word Characteristics;
346 346
347 PELIB_IMAGE_FILE_HEADER() 347 PELIB_IMAGE_FILE_HEADER()
348 { 348 {
349 Machine = 0; 349 Machine = 0;
350 NumberOfSections = 0; 350 NumberOfSections = 0;
351 TimeDateStamp = 0; 351 TimeDateStamp = 0;
352 PointerToSymbolTable = 0; 352 PointerToSymbolTable = 0;
353 NumberOfSymbols = 0; 353 NumberOfSymbols = 0;
354 SizeOfOptionalHeader = 0; 354 SizeOfOptionalHeader = 0;
355 Characteristics = 0; 355 Characteristics = 0;
356 } 356 }
357 357
358 static inline unsigned int size() {return 20;} 358 static inline unsigned int size() {return 20;}
359 }; 359 };
360 360
361 struct PELIB_IMAGE_DATA_DIRECTORY 361 struct PELIB_IMAGE_DATA_DIRECTORY
362 { 362 {
363 dword VirtualAddress; 363 dword VirtualAddress;
364 dword Size; 364 dword Size;
365 365
366 PELIB_IMAGE_DATA_DIRECTORY() 366 PELIB_IMAGE_DATA_DIRECTORY()
367 { 367 {
368 VirtualAddress = 0; 368 VirtualAddress = 0;
369 Size = 0; 369 Size = 0;
370 } 370 }
371 371
372 static inline unsigned int size() {return 8;} 372 static inline unsigned int size() {return 8;}
373 }; 373 };
374 374
375 template<int> 375 template<int>
376 struct FieldSizes; 376 struct FieldSizes;
377 377
378 template<> 378 template<>
379 struct FieldSizes<32> 379 struct FieldSizes<32>
380 { 380 {
381 typedef dword VAR4_8; 381 typedef dword VAR4_8;
382 }; 382 };
383 383
384 template<> 384 template<>
385 struct FieldSizes<64> 385 struct FieldSizes<64>
386 { 386 {
387 typedef qword VAR4_8; 387 typedef qword VAR4_8;
388 }; 388 };
389 389
390 template<int x> 390 template<int x>
391 struct PELIB_IMAGE_OPTIONAL_HEADER_BASE 391 struct PELIB_IMAGE_OPTIONAL_HEADER_BASE
392 { 392 {
393 typedef typename FieldSizes<x>::VAR4_8 VAR4_8; 393 typedef typename FieldSizes<x>::VAR4_8 VAR4_8;
394 394
395 word Magic; 395 word Magic;
396 byte MajorLinkerVersion; 396 byte MajorLinkerVersion;
397 byte MinorLinkerVersion; 397 byte MinorLinkerVersion;
398 dword SizeOfCode; 398 dword SizeOfCode;
399 dword SizeOfInitializedData; 399 dword SizeOfInitializedData;
400 dword SizeOfUninitializedData; 400 dword SizeOfUninitializedData;
401 dword AddressOfEntryPoint; 401 dword AddressOfEntryPoint;
402 dword BaseOfCode; 402 dword BaseOfCode;
403 dword BaseOfData; 403 dword BaseOfData;
404 VAR4_8 ImageBase; 404 VAR4_8 ImageBase;
405 dword SectionAlignment; 405 dword SectionAlignment;
406 dword FileAlignment; 406 dword FileAlignment;
407 word MajorOperatingSystemVersion; 407 word MajorOperatingSystemVersion;
408 word MinorOperatingSystemVersion; 408 word MinorOperatingSystemVersion;
409 word MajorImageVersion; 409 word MajorImageVersion;
410 word MinorImageVersion; 410 word MinorImageVersion;
411 word MajorSubsystemVersion; 411 word MajorSubsystemVersion;
412 word MinorSubsystemVersion; 412 word MinorSubsystemVersion;
413 dword Win32VersionValue; 413 dword Win32VersionValue;
414 dword SizeOfImage; 414 dword SizeOfImage;
415 dword SizeOfHeaders; 415 dword SizeOfHeaders;
416 dword CheckSum; 416 dword CheckSum;
417 word Subsystem; 417 word Subsystem;
418 word DllCharacteristics; 418 word DllCharacteristics;
419 VAR4_8 SizeOfStackReserve; 419 VAR4_8 SizeOfStackReserve;
420 VAR4_8 SizeOfStackCommit; 420 VAR4_8 SizeOfStackCommit;
421 VAR4_8 SizeOfHeapReserve; 421 VAR4_8 SizeOfHeapReserve;
422 VAR4_8 SizeOfHeapCommit; 422 VAR4_8 SizeOfHeapCommit;
423 dword LoaderFlags; 423 dword LoaderFlags;
424 dword NumberOfRvaAndSizes; 424 dword NumberOfRvaAndSizes;
425// PELIB_IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; 425// PELIB_IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
426 426
427 PELIB_IMAGE_OPTIONAL_HEADER_BASE(); 427 PELIB_IMAGE_OPTIONAL_HEADER_BASE();
428 }; 428 };
429 429
430 template<int x> 430 template<int x>
431 PELIB_IMAGE_OPTIONAL_HEADER_BASE<x>::PELIB_IMAGE_OPTIONAL_HEADER_BASE() 431 PELIB_IMAGE_OPTIONAL_HEADER_BASE<x>::PELIB_IMAGE_OPTIONAL_HEADER_BASE()
432 { 432 {
433 Magic = 0; 433 Magic = 0;
434 MajorLinkerVersion = 0; 434 MajorLinkerVersion = 0;
435 MinorLinkerVersion = 0; 435 MinorLinkerVersion = 0;
436 SizeOfCode = 0; 436 SizeOfCode = 0;
437 SizeOfInitializedData = 0; 437 SizeOfInitializedData = 0;
438 SizeOfUninitializedData = 0; 438 SizeOfUninitializedData = 0;
439 AddressOfEntryPoint = 0; 439 AddressOfEntryPoint = 0;
440 BaseOfCode = 0; 440 BaseOfCode = 0;
441// BaseOfData = 0; 441// BaseOfData = 0;
442 ImageBase = 0; 442 ImageBase = 0;
443 SectionAlignment = 0; 443 SectionAlignment = 0;
444 FileAlignment = 0; 444 FileAlignment = 0;
445 MajorOperatingSystemVersion = 0; 445 MajorOperatingSystemVersion = 0;
446 MinorOperatingSystemVersion = 0; 446 MinorOperatingSystemVersion = 0;
447 MajorImageVersion = 0; 447 MajorImageVersion = 0;
448 MinorImageVersion = 0; 448 MinorImageVersion = 0;
449 MajorSubsystemVersion = 0; 449 MajorSubsystemVersion = 0;
450 MinorSubsystemVersion = 0; 450 MinorSubsystemVersion = 0;
451 Win32VersionValue = 0; 451 Win32VersionValue = 0;
452 SizeOfImage = 0; 452 SizeOfImage = 0;
453 SizeOfHeaders = 0; 453 SizeOfHeaders = 0;
454 CheckSum = 0; 454 CheckSum = 0;
455 Subsystem = 0; 455 Subsystem = 0;
456 DllCharacteristics = 0; 456 DllCharacteristics = 0;
457 SizeOfStackReserve = 0; 457 SizeOfStackReserve = 0;
458 SizeOfStackCommit = 0; 458 SizeOfStackCommit = 0;
459 SizeOfHeapReserve = 0; 459 SizeOfHeapReserve = 0;
460 SizeOfHeapCommit = 0; 460 SizeOfHeapCommit = 0;
461 LoaderFlags = 0; 461 LoaderFlags = 0;
462 NumberOfRvaAndSizes = 0; 462 NumberOfRvaAndSizes = 0;
463 } 463 }
464 464
465 template<int> 465 template<int>
466 struct PELIB_IMAGE_OPTIONAL_HEADER; 466 struct PELIB_IMAGE_OPTIONAL_HEADER;
467 467
468 template<> 468 template<>
469 struct PELIB_IMAGE_OPTIONAL_HEADER<32> : public PELIB_IMAGE_OPTIONAL_HEADER_BASE<32> 469 struct PELIB_IMAGE_OPTIONAL_HEADER<32> : public PELIB_IMAGE_OPTIONAL_HEADER_BASE<32>
470 { 470 {
471 dword BaseOfData; 471 dword BaseOfData;
472 472
473 static inline unsigned int size() {return 224 - 0x10 * 8;} 473 static inline unsigned int size() {return 224 - 0x10 * 8;}
474 }; 474 };
475 475
476 template<> 476 template<>
477 struct PELIB_IMAGE_OPTIONAL_HEADER<64> : public PELIB_IMAGE_OPTIONAL_HEADER_BASE<64> 477 struct PELIB_IMAGE_OPTIONAL_HEADER<64> : public PELIB_IMAGE_OPTIONAL_HEADER_BASE<64>
478 { 478 {
479 static inline unsigned int size() {return 240 - 0x10 * 8;} 479 static inline unsigned int size() {return 240 - 0x10 * 8;}
480 }; 480 };
481 481
482 template<int x> 482 template<int x>
483 struct PELIB_IMAGE_NT_HEADERS 483 struct PELIB_IMAGE_NT_HEADERS
484 { 484 {
485 dword Signature; 485 dword Signature;
486 PELIB_IMAGE_FILE_HEADER FileHeader; 486 PELIB_IMAGE_FILE_HEADER FileHeader;
487 PELIB_IMAGE_OPTIONAL_HEADER<x> OptionalHeader; 487 PELIB_IMAGE_OPTIONAL_HEADER<x> OptionalHeader;
488 std::vector<PELIB_IMAGE_DATA_DIRECTORY> dataDirectories; 488 std::vector<PELIB_IMAGE_DATA_DIRECTORY> dataDirectories;
489 489
490 unsigned int size() const 490 unsigned int size() const
491 { 491 {
492 return sizeof(dword) 492 return sizeof(dword)
493 + PELIB_IMAGE_FILE_HEADER::size() 493 + PELIB_IMAGE_FILE_HEADER::size()
494 + PELIB_IMAGE_OPTIONAL_HEADER<x>::size() 494 + PELIB_IMAGE_OPTIONAL_HEADER<x>::size()
495 + static_cast<unsigned int>(dataDirectories.size()) * PELIB_IMAGE_DATA_DIRECTORY::size(); 495 + static_cast<unsigned int>(dataDirectories.size()) * PELIB_IMAGE_DATA_DIRECTORY::size();
496 } 496 }
497 497
498 PELIB_IMAGE_NT_HEADERS() 498 PELIB_IMAGE_NT_HEADERS()
499 { 499 {
500 Signature = 0; 500 Signature = 0;
501 } 501 }
502 }; 502 };
503 503
504 const unsigned int PELIB_IMAGE_SIZEOF_SHORT_NAME = 8; 504 const unsigned int PELIB_IMAGE_SIZEOF_SHORT_NAME = 8;
505 505
506 struct PELIB_IMAGE_SECTION_HEADER 506 struct PELIB_IMAGE_SECTION_HEADER
507 { 507 {
508 byte Name[PELIB_IMAGE_SIZEOF_SHORT_NAME]; 508 byte Name[PELIB_IMAGE_SIZEOF_SHORT_NAME];
509 dword VirtualSize; 509 dword VirtualSize;
510 dword VirtualAddress; 510 dword VirtualAddress;
511 dword SizeOfRawData; 511 dword SizeOfRawData;
512 dword PointerToRawData; 512 dword PointerToRawData;
513 dword PointerToRelocations; 513 dword PointerToRelocations;
514 dword PointerToLinenumbers; 514 dword PointerToLinenumbers;
515 word NumberOfRelocations; 515 word NumberOfRelocations;
516 word NumberOfLinenumbers; 516 word NumberOfLinenumbers;
517 dword Characteristics; 517 dword Characteristics;
518 518
519 PELIB_IMAGE_SECTION_HEADER() 519 PELIB_IMAGE_SECTION_HEADER()
520 { 520 {
521 VirtualSize = 0; 521 VirtualSize = 0;
522 VirtualAddress = 0; 522 VirtualAddress = 0;
523 SizeOfRawData = 0; 523 SizeOfRawData = 0;
524 PointerToRawData = 0; 524 PointerToRawData = 0;
525 PointerToRelocations = 0; 525 PointerToRelocations = 0;
526 PointerToLinenumbers = 0; 526 PointerToLinenumbers = 0;
527 NumberOfRelocations = 0; 527 NumberOfRelocations = 0;
528 NumberOfLinenumbers = 0; 528 NumberOfLinenumbers = 0;
529 Characteristics = 0; 529 Characteristics = 0;
530 } 530 }
531 531
532 static inline unsigned int size() {return 40;} 532 static inline unsigned int size() {return 40;}
533 bool biggerFileOffset(const PELIB_IMAGE_SECTION_HEADER& ish) const; 533 bool biggerFileOffset(const PELIB_IMAGE_SECTION_HEADER& ish) const;
534 bool biggerVirtualAddress(const PELIB_IMAGE_SECTION_HEADER& ish) const; 534 bool biggerVirtualAddress(const PELIB_IMAGE_SECTION_HEADER& ish) const;
535 }; 535 };
536 536
537 template<int bits> 537 template<int bits>
538 struct PELIB_IMAGE_THUNK_DATA 538 struct PELIB_IMAGE_THUNK_DATA
539 { 539 {
540 typename FieldSizes<bits>::VAR4_8 Ordinal; 540 typename FieldSizes<bits>::VAR4_8 Ordinal;
541 541
542 PELIB_IMAGE_THUNK_DATA() 542 PELIB_IMAGE_THUNK_DATA()
543 { 543 {
544 Ordinal = 0; 544 Ordinal = 0;
545 } 545 }
546 546
547 static inline unsigned int size() {return 4;} 547 static inline unsigned int size() {return 4;}
548 }; 548 };
549 549
550 struct PELIB_IMAGE_IMPORT_DESCRIPTOR 550 struct PELIB_IMAGE_IMPORT_DESCRIPTOR
551 { 551 {
552 dword OriginalFirstThunk; 552 dword OriginalFirstThunk;
553 dword TimeDateStamp; 553 dword TimeDateStamp;
554 dword ForwarderChain; 554 dword ForwarderChain;
555 dword Name; 555 dword Name;
556 dword FirstThunk; 556 dword FirstThunk;
557 557
558 PELIB_IMAGE_IMPORT_DESCRIPTOR() 558 PELIB_IMAGE_IMPORT_DESCRIPTOR()
559 { 559 {
560 OriginalFirstThunk = 0; 560 OriginalFirstThunk = 0;
561 TimeDateStamp = 0; 561 TimeDateStamp = 0;
562 ForwarderChain = 0; 562 ForwarderChain = 0;
563 Name = 0; 563 Name = 0;
564 FirstThunk = 0; 564 FirstThunk = 0;
565 } 565 }
566 566
567 static inline unsigned int size() {return 20;} 567 static inline unsigned int size() {return 20;}
568 }; 568 };
569 569
570 struct PELIB_IMAGE_EXPORT_DIRECTORY 570 struct PELIB_IMAGE_EXPORT_DIRECTORY
571 { 571 {
572 dword Characteristics; 572 dword Characteristics;
573 dword TimeDateStamp; 573 dword TimeDateStamp;
574 word MajorVersion; 574 word MajorVersion;
575 word MinorVersion; 575 word MinorVersion;
576 dword Name; 576 dword Name;
577 dword Base; 577 dword Base;
578 dword NumberOfFunctions; 578 dword NumberOfFunctions;
579 dword NumberOfNames; 579 dword NumberOfNames;
580 dword AddressOfFunctions; 580 dword AddressOfFunctions;
581 dword AddressOfNames; 581 dword AddressOfNames;
582 dword AddressOfNameOrdinals; 582 dword AddressOfNameOrdinals;
583 583
584 PELIB_IMAGE_EXPORT_DIRECTORY() 584 PELIB_IMAGE_EXPORT_DIRECTORY()
585 { 585 {
586 Characteristics = 0; 586 Characteristics = 0;
587 TimeDateStamp = 0; 587 TimeDateStamp = 0;
588 MajorVersion = 0; 588 MajorVersion = 0;
589 MinorVersion = 0; 589 MinorVersion = 0;
590 Name = 0; 590 Name = 0;
591 Base = 0; 591 Base = 0;
592 NumberOfFunctions = 0; 592 NumberOfFunctions = 0;
593 NumberOfNames = 0; 593 NumberOfNames = 0;
594 AddressOfFunctions = 0; 594 AddressOfFunctions = 0;
595 NumberOfNames = 0; 595 NumberOfNames = 0;
596 AddressOfNameOrdinals = 0; 596 AddressOfNameOrdinals = 0;
597 } 597 }
598 598
599 static inline unsigned int size() {return 40;} 599 static inline unsigned int size() {return 40;}
600 }; 600 };
601 601
602 struct PELIB_IMAGE_BOUND_IMPORT_DESCRIPTOR 602 struct PELIB_IMAGE_BOUND_IMPORT_DESCRIPTOR
603 { 603 {
604 dword TimeDateStamp; 604 dword TimeDateStamp;
605 word OffsetModuleName; 605 word OffsetModuleName;
606 word NumberOfModuleForwarderRefs; 606 word NumberOfModuleForwarderRefs;
607 607
608 PELIB_IMAGE_BOUND_IMPORT_DESCRIPTOR() 608 PELIB_IMAGE_BOUND_IMPORT_DESCRIPTOR()
609 { 609 {
610 TimeDateStamp = 0; 610 TimeDateStamp = 0;
611 OffsetModuleName = 0; 611 OffsetModuleName = 0;
612 NumberOfModuleForwarderRefs = 0; 612 NumberOfModuleForwarderRefs = 0;
613 } 613 }
614 614
615 static unsigned int size() 615 static unsigned int size()
616 { 616 {
617 return 8; 617 return 8;
618 } 618 }
619 }; 619 };
620 620
621 // Stores all necessary information about a BoundImport field. 621 // Stores all necessary information about a BoundImport field.
622 struct PELIB_IMAGE_BOUND_DIRECTORY 622 struct PELIB_IMAGE_BOUND_DIRECTORY
623 { 623 {
624 PELIB_IMAGE_BOUND_IMPORT_DESCRIPTOR ibdDescriptor; ///< Information about the imported file. 624 PELIB_IMAGE_BOUND_IMPORT_DESCRIPTOR ibdDescriptor; ///< Information about the imported file.
625 std::string strModuleName; ///< Name of the imported file. 625 std::string strModuleName; ///< Name of the imported file.
626 std::vector<PELIB_IMAGE_BOUND_DIRECTORY> moduleForwarders; 626 std::vector<PELIB_IMAGE_BOUND_DIRECTORY> moduleForwarders;
627 627
628 // Will be used in std::find_if 628 // Will be used in std::find_if
629 // Passing by-reference not possible (see C++ Standard Core Language Defect Reports, Revision 29, Issue 106) 629 // Passing by-reference not possible (see C++ Standard Core Language Defect Reports, Revision 29, Issue 106)
630 /// Compares the passed filename to the struct's filename. 630 /// Compares the passed filename to the struct's filename.
631 bool equal(const std::string strModuleName) const; 631 bool equal(const std::string strModuleName) const;
632 632
633 unsigned int size() const; 633 unsigned int size() const;
634 }; 634 };
635 635
636 struct PELIB_EXP_FUNC_INFORMATION 636 struct PELIB_EXP_FUNC_INFORMATION
637 { 637 {
638 dword addroffunc; 638 dword addroffunc;
639 dword addrofname; 639 dword addrofname;
640 word ordinal; 640 word ordinal;
641 std::string funcname; 641 std::string funcname;
642 642
643 PELIB_EXP_FUNC_INFORMATION(); 643 PELIB_EXP_FUNC_INFORMATION();
644 644
645 bool equal(const std::string strFunctionName) const; 645 bool equal(const std::string strFunctionName) const;
646 inline unsigned int size() const 646 inline unsigned int size() const
647 { 647 {
648 unsigned int uiSize = 4; 648 unsigned int uiSize = 4;
649 if (addroffunc) uiSize += 2;// + 4; 649 if (addroffunc) uiSize += 2;// + 4;
650 if (!funcname.empty()) uiSize += 4 + (unsigned int)funcname.size() + 1; 650 if (!funcname.empty()) uiSize += 4 + (unsigned int)funcname.size() + 1;
651 return uiSize; 651 return uiSize;
652 } 652 }
653 }; 653 };
654 654
655 struct PELIB_IMAGE_RESOURCE_DIRECTORY 655 struct PELIB_IMAGE_RESOURCE_DIRECTORY
656 { 656 {
657 dword Characteristics; 657 dword Characteristics;
658 dword TimeDateStamp; 658 dword TimeDateStamp;
659 word MajorVersion; 659 word MajorVersion;
660 word MinorVersion; 660 word MinorVersion;
661 word NumberOfNamedEntries; 661 word NumberOfNamedEntries;
662 word NumberOfIdEntries; 662 word NumberOfIdEntries;
663 663
664 PELIB_IMAGE_RESOURCE_DIRECTORY(); 664 PELIB_IMAGE_RESOURCE_DIRECTORY();
665 665
666 static inline unsigned int size() {return 16;} 666 static inline unsigned int size() {return 16;}
667 }; 667 };
668 668
669 struct PELIB_IMAGE_RESOURCE_DIRECTORY_ENTRY 669 struct PELIB_IMAGE_RESOURCE_DIRECTORY_ENTRY
670 { 670 {
671 dword Name; 671 dword Name;
672 dword OffsetToData; 672 dword OffsetToData;
673 PELIB_IMAGE_RESOURCE_DIRECTORY_ENTRY(); 673 PELIB_IMAGE_RESOURCE_DIRECTORY_ENTRY();
674 static inline unsigned int size() {return 8;} 674 static inline unsigned int size() {return 8;}
675 }; 675 };
676 676
677 const unsigned int PELIB_IMAGE_SIZEOF_BASE_RELOCATION = 8; 677 const unsigned int PELIB_IMAGE_SIZEOF_BASE_RELOCATION = 8;
678 678
679 struct PELIB_IMG_RES_DIR_ENTRY 679 struct PELIB_IMG_RES_DIR_ENTRY
680 { 680 {
681 PELIB_IMAGE_RESOURCE_DIRECTORY_ENTRY irde; 681 PELIB_IMAGE_RESOURCE_DIRECTORY_ENTRY irde;
682 std::string wstrName; 682 std::string wstrName;
683 683
684 bool operator<(const PELIB_IMG_RES_DIR_ENTRY& first) const; 684 bool operator<(const PELIB_IMG_RES_DIR_ENTRY& first) const;
685 685
686 }; 686 };
687 687
688 struct PELIB_IMAGE_BASE_RELOCATION 688 struct PELIB_IMAGE_BASE_RELOCATION
689 { 689 {
690 dword VirtualAddress; 690 dword VirtualAddress;
691 dword SizeOfBlock; 691 dword SizeOfBlock;
692 692
693 PELIB_IMAGE_BASE_RELOCATION(); 693 PELIB_IMAGE_BASE_RELOCATION();
694 static inline unsigned int size() {return 8;} 694 static inline unsigned int size() {return 8;}
695 }; 695 };
696 696
697 struct PELIB_IMAGE_COR20_HEADER 697 struct PELIB_IMAGE_COR20_HEADER
698 { 698 {
699 dword cb; 699 dword cb;
700 word MajorRuntimeVersion; 700 word MajorRuntimeVersion;
701 word MinorRuntimeVersion; 701 word MinorRuntimeVersion;
702 PELIB_IMAGE_DATA_DIRECTORY MetaData; 702 PELIB_IMAGE_DATA_DIRECTORY MetaData;
703 dword Flags; 703 dword Flags;
704 dword EntryPointToken; 704 dword EntryPointToken;
705 PELIB_IMAGE_DATA_DIRECTORY Resources; 705 PELIB_IMAGE_DATA_DIRECTORY Resources;
706 PELIB_IMAGE_DATA_DIRECTORY StrongNameSignature; 706 PELIB_IMAGE_DATA_DIRECTORY StrongNameSignature;
707 PELIB_IMAGE_DATA_DIRECTORY CodeManagerTable; 707 PELIB_IMAGE_DATA_DIRECTORY CodeManagerTable;
708 PELIB_IMAGE_DATA_DIRECTORY VTableFixups; 708 PELIB_IMAGE_DATA_DIRECTORY VTableFixups;
709 PELIB_IMAGE_DATA_DIRECTORY ExportAddressTableJumps; 709 PELIB_IMAGE_DATA_DIRECTORY ExportAddressTableJumps;
710 PELIB_IMAGE_DATA_DIRECTORY ManagedNativeHeader; 710 PELIB_IMAGE_DATA_DIRECTORY ManagedNativeHeader;
711 711
712 PELIB_IMAGE_COR20_HEADER(); 712 PELIB_IMAGE_COR20_HEADER();
713 static inline unsigned int size() {return 72;} 713 static inline unsigned int size() {return 72;}
714 }; 714 };
715 715
716 // Used to store a file's export table. 716 // Used to store a file's export table.
717 struct PELIB_IMAGE_EXP_DIRECTORY 717 struct PELIB_IMAGE_EXP_DIRECTORY
718 { 718 {
719 /// The IMAGE_EXPORTED_DIRECTORY of a file's export table. 719 /// The IMAGE_EXPORTED_DIRECTORY of a file's export table.
720 PELIB_IMAGE_EXPORT_DIRECTORY ied; 720 PELIB_IMAGE_EXPORT_DIRECTORY ied;
721 /// The original filename of current file. 721 /// The original filename of current file.
722 std::string name; 722 std::string name;
723 std::vector<PELIB_EXP_FUNC_INFORMATION> functions; 723 std::vector<PELIB_EXP_FUNC_INFORMATION> functions;
724 inline unsigned int size() const 724 inline unsigned int size() const
725 { 725 {
726 return PELIB_IMAGE_EXPORT_DIRECTORY::size() + name.size() + 1 + 726 return PELIB_IMAGE_EXPORT_DIRECTORY::size() + name.size() + 1 +
727 std::accumulate(functions.begin(), functions.end(), 0, accumulate<PELIB_EXP_FUNC_INFORMATION>); 727 std::accumulate(functions.begin(), functions.end(), 0, accumulate<PELIB_EXP_FUNC_INFORMATION>);
728 } 728 }
729 }; 729 };
730 730
731 // Used for parsing a file's import table. It combines the function name, the hint 731 // Used for parsing a file's import table. It combines the function name, the hint
732 // and the IMAGE_THUNK_DATA of an imported function. 732 // and the IMAGE_THUNK_DATA of an imported function.
733 template<int bits> 733 template<int bits>
734 struct PELIB_THUNK_DATA 734 struct PELIB_THUNK_DATA
735 { 735 {
736 /// The IMAGE_THUNK_DATA struct of an imported function. 736 /// The IMAGE_THUNK_DATA struct of an imported function.
737 PELIB_IMAGE_THUNK_DATA<bits> itd; 737 PELIB_IMAGE_THUNK_DATA<bits> itd;
738 /// The hint of an imported function. 738 /// The hint of an imported function.
739 word hint; 739 word hint;
740 /// The function name of an imported function. 740 /// The function name of an imported function.
741 std::string fname; 741 std::string fname;
742 742
743 bool equalHint(word wHint) const 743 bool equalHint(word wHint) const
744 { 744 {
745 return hint == wHint; 745 return hint == wHint;
746// return itd.Ordinal == (wHint | IMAGE_ORDINAL_FLAGS<bits>::IMAGE_ORDINAL_FLAG); 746// return itd.Ordinal == (wHint | IMAGE_ORDINAL_FLAGS<bits>::IMAGE_ORDINAL_FLAG);
747 } 747 }
748 748
749 bool equalFunctionName(std::string strFunctionName) const 749 bool equalFunctionName(std::string strFunctionName) const
750 { 750 {
751 return isEqualNc(fname, strFunctionName); 751 return isEqualNc(fname, strFunctionName);
752 } 752 }
753 753
754 unsigned int size() const {return PELIB_IMAGE_THUNK_DATA<bits>::size() + fname.size() + 1 + sizeof(hint);} 754 unsigned int size() const {return PELIB_IMAGE_THUNK_DATA<bits>::size() + fname.size() + 1 + sizeof(hint);}
755 }; 755 };
756 756
757 // Used to store a file's import table. Every struct of this sort 757 // Used to store a file's import table. Every struct of this sort
758 // can store import information of one DLL. 758 // can store import information of one DLL.
759 template<int bits> 759 template<int bits>
760 struct PELIB_IMAGE_IMPORT_DIRECTORY 760 struct PELIB_IMAGE_IMPORT_DIRECTORY
761 { 761 {
762 /// The IMAGE_IMPORT_DESCRIPTOR of an imported DLL. 762 /// The IMAGE_IMPORT_DESCRIPTOR of an imported DLL.
763 PELIB_IMAGE_IMPORT_DESCRIPTOR impdesc; 763 PELIB_IMAGE_IMPORT_DESCRIPTOR impdesc;
764 /// The name of an imported DLL. 764 /// The name of an imported DLL.
765 std::string name; 765 std::string name;
766 /// All original first thunk values of an imported DLL. 766 /// All original first thunk values of an imported DLL.
767 std::vector<PELIB_THUNK_DATA<bits> > originalfirstthunk; 767 std::vector<PELIB_THUNK_DATA<bits> > originalfirstthunk;
768 /// All first thunk value of an imported DLL. 768 /// All first thunk value of an imported DLL.
769 std::vector<PELIB_THUNK_DATA<bits> > firstthunk; 769 std::vector<PELIB_THUNK_DATA<bits> > firstthunk;
770 770
771// bool operator==(std::string strFilename) const; 771// bool operator==(std::string strFilename) const;
772 inline unsigned int size() const 772 inline unsigned int size() const
773 { 773 {
774 return PELIB_IMAGE_IMPORT_DESCRIPTOR::size() + name.size() + 1 + // descriptor + dllname 774 return PELIB_IMAGE_IMPORT_DESCRIPTOR::size() + name.size() + 1 + // descriptor + dllname
775 std::accumulate(originalfirstthunk.begin(), originalfirstthunk.end(), 0, accumulate<PELIB_THUNK_DATA<bits> >) + // thunks (PeLib uses only one thunk) 775 std::accumulate(originalfirstthunk.begin(), originalfirstthunk.end(), 0, accumulate<PELIB_THUNK_DATA<bits> >) + // thunks (PeLib uses only one thunk)
776 PELIB_IMAGE_THUNK_DATA<bits>::size(); // zero-termination 776 PELIB_IMAGE_THUNK_DATA<bits>::size(); // zero-termination
777 } 777 }
778 778
779 bool operator==(std::string strFilename) const 779 bool operator==(std::string strFilename) const
780 { 780 {
781 return isEqualNc(this->name, strFilename); 781 return isEqualNc(this->name, strFilename);
782 } 782 }
783 }; 783 };
784 784
785 struct PELIB_IMAGE_RESOURCE_DATA_ENTRY 785 struct PELIB_IMAGE_RESOURCE_DATA_ENTRY
786 { 786 {
787 dword OffsetToData; 787 dword OffsetToData;
788 dword Size; 788 dword Size;
789 dword CodePage; 789 dword CodePage;
790 dword Reserved; 790 dword Reserved;
791 791
792 static inline unsigned int size() {return 16;} 792 static inline unsigned int size() {return 16;}
793 }; 793 };
794 794
795 struct PELIB_IMAGE_RESOURCE_DATA 795 struct PELIB_IMAGE_RESOURCE_DATA
796 { 796 {
797 PELIB_IMAGE_RESOURCE_DATA_ENTRY irdEntry; 797 PELIB_IMAGE_RESOURCE_DATA_ENTRY irdEntry;
798 std::vector<byte> vData; 798 std::vector<byte> vData;
799 }; 799 };
800 800
801 struct IMG_BASE_RELOC 801 struct IMG_BASE_RELOC
802 { 802 {
803 PELIB_IMAGE_BASE_RELOCATION ibrRelocation; 803 PELIB_IMAGE_BASE_RELOCATION ibrRelocation;
804 std::vector<word> vRelocData; 804 std::vector<word> vRelocData;
805 }; 805 };
806 806
807 struct PELIB_IMAGE_DEBUG_DIRECTORY 807 struct PELIB_IMAGE_DEBUG_DIRECTORY
808 { 808 {
809 dword Characteristics; 809 dword Characteristics;
810 dword TimeDateStamp; 810 dword TimeDateStamp;
811 word MajorVersion; 811 word MajorVersion;
812 word MinorVersion; 812 word MinorVersion;
813 dword Type; 813 dword Type;
814 dword SizeOfData; 814 dword SizeOfData;
815 dword AddressOfRawData; 815 dword AddressOfRawData;
816 dword PointerToRawData; 816 dword PointerToRawData;
817 817
818 static unsigned int size() {return 28;} 818 static unsigned int size() {return 28;}
819 }; 819 };
820 820
821 struct PELIB_IMG_DEBUG_DIRECTORY 821 struct PELIB_IMG_DEBUG_DIRECTORY
822 { 822 {
823 PELIB_IMAGE_DEBUG_DIRECTORY idd; 823 PELIB_IMAGE_DEBUG_DIRECTORY idd;
824 std::vector<byte> data; 824 std::vector<byte> data;
825 }; 825 };
826 826
827 template<int bits> 827 template<int bits>
828 struct PELIB_IMAGE_TLS_DIRECTORY_BASE 828 struct PELIB_IMAGE_TLS_DIRECTORY_BASE
829 { 829 {
830 typename FieldSizes<bits>::VAR4_8 StartAddressOfRawData; 830 typename FieldSizes<bits>::VAR4_8 StartAddressOfRawData;
831 typename FieldSizes<bits>::VAR4_8 EndAddressOfRawData; 831 typename FieldSizes<bits>::VAR4_8 EndAddressOfRawData;
832 typename FieldSizes<bits>::VAR4_8 AddressOfIndex; 832 typename FieldSizes<bits>::VAR4_8 AddressOfIndex;
833 typename FieldSizes<bits>::VAR4_8 AddressOfCallBacks; 833 typename FieldSizes<bits>::VAR4_8 AddressOfCallBacks;
834 dword SizeOfZeroFill; 834 dword SizeOfZeroFill;
835 dword Characteristics; 835 dword Characteristics;
836 }; 836 };
837 837
838 template<int bits> 838 template<int bits>
839 struct PELIB_IMAGE_TLS_DIRECTORY;// : public PELIB_IMAGE_TLS_DIRECTORY_BASE<bits> 839 struct PELIB_IMAGE_TLS_DIRECTORY;// : public PELIB_IMAGE_TLS_DIRECTORY_BASE<bits>
840 840
841 template<> 841 template<>
842 struct PELIB_IMAGE_TLS_DIRECTORY<32> : public PELIB_IMAGE_TLS_DIRECTORY_BASE<32> 842 struct PELIB_IMAGE_TLS_DIRECTORY<32> : public PELIB_IMAGE_TLS_DIRECTORY_BASE<32>
843 { 843 {
844// enum {size = 24}; 844// enum {size = 24};
845 static unsigned int size(){return 24;} 845 static unsigned int size(){return 24;}
846 }; 846 };
847 847
848 template<> 848 template<>
849 struct PELIB_IMAGE_TLS_DIRECTORY<64> : public PELIB_IMAGE_TLS_DIRECTORY_BASE<64> 849 struct PELIB_IMAGE_TLS_DIRECTORY<64> : public PELIB_IMAGE_TLS_DIRECTORY_BASE<64>
850 { 850 {
851// enum {size = 40}; 851// enum {size = 40};
852 static unsigned int size(){return 40;} 852 static unsigned int size(){return 40;}
853 }; 853 };
854 854
855 unsigned int fileSize(const std::string& filename); 855 unsigned int fileSize(const std::string& filename);
856 unsigned int fileSize(std::ifstream& file); 856 unsigned int fileSize(std::ifstream& file);
857 unsigned int fileSize(std::ofstream& file); 857 unsigned int fileSize(std::ofstream& file);
858 unsigned int fileSize(std::fstream& file); 858 unsigned int fileSize(std::fstream& file);
859 unsigned int alignOffset(unsigned int uiOffset, unsigned int uiAlignment); 859 unsigned int alignOffset(unsigned int uiOffset, unsigned int uiAlignment);
860 860
861 /// Determines if a file is a 32bit or 64bit PE file. 861 /// Determines if a file is a 32bit or 64bit PE file.
862 unsigned int getFileType(const std::string strFilename); 862 unsigned int getFileType(const std::string strFilename);
863 863
864 /// Opens a PE file. 864 /// Opens a PE file.
865 PeFile* openPeFile(const std::string& strFilename); 865 PeFile* openPeFile(const std::string& strFilename);
866 866
867 /* enum MzHeader_Field {e_magic, e_cblp, e_cp, e_crlc, e_cparhdr, e_minalloc, e_maxalloc, 867 /* enum MzHeader_Field {e_magic, e_cblp, e_cp, e_crlc, e_cparhdr, e_minalloc, e_maxalloc,
868 e_ss, e_sp, e_csum, e_ip, e_cs, e_lfarlc, e_ovno, e_res, e_oemid, 868 e_ss, e_sp, e_csum, e_ip, e_cs, e_lfarlc, e_ovno, e_res, e_oemid,
869 e_oeminfo, e_res2, e_lfanew}; 869 e_oeminfo, e_res2, e_lfanew};
870 enum PeHeader_Field {NtSignature, Machine, NumberOfSections, TimeDateStamp, PointerToSymbolTable, 870 enum PeHeader_Field {NtSignature, Machine, NumberOfSections, TimeDateStamp, PointerToSymbolTable,
871 NumberOfSymbols, SizeOfOptionalHeader, Characteristics, Magic, 871 NumberOfSymbols, SizeOfOptionalHeader, Characteristics, Magic,
872 MajorLinkerVersion, MinorLinkerVersion, SizeOfCode, SizeOfInitializedData, 872 MajorLinkerVersion, MinorLinkerVersion, SizeOfCode, SizeOfInitializedData,
873 SizeOfUninitializedData, AddressOfEntryPoint, BaseOfCode, BaseOfData, ImageBase, 873 SizeOfUninitializedData, AddressOfEntryPoint, BaseOfCode, BaseOfData, ImageBase,
874 SectionAlignment, FileAlignment, MajorOperatingSystemVersion, MinorOperatingSystemVersion, 874 SectionAlignment, FileAlignment, MajorOperatingSystemVersion, MinorOperatingSystemVersion,
875 MajorImageVersion, MinorImageVersion, MajorSubsystemVersion, MinorSubsystemVersion, 875 MajorImageVersion, MinorImageVersion, MajorSubsystemVersion, MinorSubsystemVersion,
876 Win32VersionValue, SizeOfImage, SizeOfHeaders, CheckSum, Subsystem, DllCharacteristics, 876 Win32VersionValue, SizeOfImage, SizeOfHeaders, CheckSum, Subsystem, DllCharacteristics,
877 SizeOfStackReserve, SizeOfStackCommit, SizeOfHeapReserve, SizeOfHeapCommit, 877 SizeOfStackReserve, SizeOfStackCommit, SizeOfHeapReserve, SizeOfHeapCommit,
878 LoaderFlags, NumberOfRvaAndSizes, DataDirectoryRva, DataDirectorySize}; 878 LoaderFlags, NumberOfRvaAndSizes, DataDirectoryRva, DataDirectorySize};
879 enum Section_Field {SectionName, VirtualSize, VirtualAddress, SizeOfRawData, PointerToRawData, PointerToRelocations, 879 enum Section_Field {SectionName, VirtualSize, VirtualAddress, SizeOfRawData, PointerToRawData, PointerToRelocations,
880 PointerToLinenumbers, NumberOfRelocations, NumberOfLinenumbers, SectionCharacteristics}; 880 PointerToLinenumbers, NumberOfRelocations, NumberOfLinenumbers, SectionCharacteristics};
881*/ 881*/
882} 882}
883 883
884#endif 884#endif
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/PeLibInc.h b/utils/zenutils/libraries/pelib-0.9/pelib/PeLibInc.h
index 84538bd2dd..7d3cabaa6b 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/PeLibInc.h
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/PeLibInc.h
@@ -1,32 +1,32 @@
1/* 1/*
2* PeLibInc.h - Part of the PeLib library. 2* PeLibInc.h - Part of the PeLib library.
3* 3*
4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) 4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5* All rights reserved. 5* All rights reserved.
6* 6*
7* This software is licensed under the zlib/libpng License. 7* This software is licensed under the zlib/libpng License.
8* For more details see http://www.opensource.org/licenses/zlib-license.php 8* For more details see http://www.opensource.org/licenses/zlib-license.php
9* or the license information file (license.htm) in the root directory 9* or the license information file (license.htm) in the root directory
10* of PeLib. 10* of PeLib.
11*/ 11*/
12 12
13#ifndef STD_H 13#ifndef STD_H
14#define STD_H 14#define STD_H
15 15
16#ifdef _MSC_VER 16#ifdef _MSC_VER
17 #ifndef for 17 #ifndef for
18 #define for if (0) {} else for 18 #define for if (0) {} else for
19 #endif 19 #endif
20#endif 20#endif
21 21
22#include <algorithm> 22#include <algorithm>
23#include <climits> 23#include <climits>
24#include <fstream> 24#include <fstream>
25#include <iostream> 25#include <iostream>
26#include <string> 26#include <string>
27#include <vector> 27#include <vector>
28#include <functional> 28#include <functional>
29// #include "PeLib.h" 29// #include "PeLib.h"
30#include "PeLibAux.h" 30#include "PeLibAux.h"
31 31
32#endif 32#endif
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/RelocationsDirectory.cpp b/utils/zenutils/libraries/pelib-0.9/pelib/RelocationsDirectory.cpp
index d8b5035abf..392261d242 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/RelocationsDirectory.cpp
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/RelocationsDirectory.cpp
@@ -1,211 +1,211 @@
1/* 1/*
2* Relocations.cpp - Part of the PeLib library. 2* Relocations.cpp - Part of the PeLib library.
3* 3*
4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) 4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5* All rights reserved. 5* All rights reserved.
6* 6*
7* This software is licensed under the zlib/libpng License. 7* This software is licensed under the zlib/libpng License.
8* For more details see http://www.opensource.org/licenses/zlib-license.php 8* For more details see http://www.opensource.org/licenses/zlib-license.php
9* or the license information file (license.htm) in the root directory 9* or the license information file (license.htm) in the root directory
10* of PeLib. 10* of PeLib.
11*/ 11*/
12 12
13#include "PeLibInc.h" 13#include "PeLibInc.h"
14#include "RelocationsDirectory.h" 14#include "RelocationsDirectory.h"
15 15
16namespace PeLib 16namespace PeLib
17{ 17{
18 void RelocationsDirectory::setRelocationData(unsigned int ulRelocation, unsigned int ulDataNumber, word wData) 18 void RelocationsDirectory::setRelocationData(unsigned int ulRelocation, unsigned int ulDataNumber, word wData)
19 { 19 {
20 m_vRelocations[ulRelocation].vRelocData[ulDataNumber] = wData; 20 m_vRelocations[ulRelocation].vRelocData[ulDataNumber] = wData;
21 } 21 }
22 22
23 void RelocationsDirectory::read(InputBuffer& inputbuffer, unsigned int uiSize) 23 void RelocationsDirectory::read(InputBuffer& inputbuffer, unsigned int uiSize)
24 { 24 {
25 IMG_BASE_RELOC ibrCurr; 25 IMG_BASE_RELOC ibrCurr;
26 26
27 std::vector<IMG_BASE_RELOC> vCurrReloc; 27 std::vector<IMG_BASE_RELOC> vCurrReloc;
28 28
29 do 29 do
30 { 30 {
31 inputbuffer >> ibrCurr.ibrRelocation.VirtualAddress; 31 inputbuffer >> ibrCurr.ibrRelocation.VirtualAddress;
32 inputbuffer >> ibrCurr.ibrRelocation.SizeOfBlock; 32 inputbuffer >> ibrCurr.ibrRelocation.SizeOfBlock;
33 33
34 ibrCurr.vRelocData.clear(); 34 ibrCurr.vRelocData.clear();
35 35
36 // That's not how to check if there are relocations, some DLLs start at VA 0. 36 // That's not how to check if there are relocations, some DLLs start at VA 0.
37 // if (!ibrCurr.ibrRelocation.VirtualAddress) break; 37 // if (!ibrCurr.ibrRelocation.VirtualAddress) break;
38 38
39 for (unsigned int i=0;i<(ibrCurr.ibrRelocation.SizeOfBlock - PELIB_IMAGE_SIZEOF_BASE_RELOCATION) / sizeof(word);i++) 39 for (unsigned int i=0;i<(ibrCurr.ibrRelocation.SizeOfBlock - PELIB_IMAGE_SIZEOF_BASE_RELOCATION) / sizeof(word);i++)
40 { 40 {
41 word wData; 41 word wData;
42 inputbuffer >> wData; 42 inputbuffer >> wData;
43 ibrCurr.vRelocData.push_back(wData); 43 ibrCurr.vRelocData.push_back(wData);
44 } 44 }
45 45
46 vCurrReloc.push_back(ibrCurr); 46 vCurrReloc.push_back(ibrCurr);
47 } while (ibrCurr.ibrRelocation.VirtualAddress && inputbuffer.get() < uiSize); 47 } while (ibrCurr.ibrRelocation.VirtualAddress && inputbuffer.get() < uiSize);
48 48
49 std::swap(vCurrReloc, m_vRelocations); 49 std::swap(vCurrReloc, m_vRelocations);
50 } 50 }
51 51
52 // TODO: Return value is wrong if buffer was too small. 52 // TODO: Return value is wrong if buffer was too small.
53 int RelocationsDirectory::read(const unsigned char* buffer, unsigned int buffersize) 53 int RelocationsDirectory::read(const unsigned char* buffer, unsigned int buffersize)
54 { 54 {
55 std::vector<unsigned char> vRelocDirectory(buffer, buffer + buffersize); 55 std::vector<unsigned char> vRelocDirectory(buffer, buffer + buffersize);
56 56
57 InputBuffer ibBuffer(vRelocDirectory); 57 InputBuffer ibBuffer(vRelocDirectory);
58 read(ibBuffer, buffersize); 58 read(ibBuffer, buffersize);
59 59
60 return NO_ERROR; 60 return NO_ERROR;
61 } 61 }
62 62
63 int RelocationsDirectory::read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize) 63 int RelocationsDirectory::read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize)
64 { 64 {
65 std::ifstream ifFile(strFilename.c_str(), std::ios::binary); 65 std::ifstream ifFile(strFilename.c_str(), std::ios::binary);
66 unsigned int ulFileSize = fileSize(ifFile); 66 unsigned int ulFileSize = fileSize(ifFile);
67 67
68 if (!ifFile) 68 if (!ifFile)
69 { 69 {
70 return ERROR_OPENING_FILE; 70 return ERROR_OPENING_FILE;
71 } 71 }
72 72
73 if (ulFileSize < uiOffset + uiSize) 73 if (ulFileSize < uiOffset + uiSize)
74 { 74 {
75 return ERROR_INVALID_FILE; 75 return ERROR_INVALID_FILE;
76 } 76 }
77 77
78 ifFile.seekg(uiOffset, std::ios::beg); 78 ifFile.seekg(uiOffset, std::ios::beg);
79 79
80 std::vector<unsigned char> vRelocDirectory(uiSize); 80 std::vector<unsigned char> vRelocDirectory(uiSize);
81 ifFile.read(reinterpret_cast<char*>(&vRelocDirectory[0]), uiSize); 81 ifFile.read(reinterpret_cast<char*>(&vRelocDirectory[0]), uiSize);
82 82
83 InputBuffer ibBuffer(vRelocDirectory); 83 InputBuffer ibBuffer(vRelocDirectory);
84 read(ibBuffer, uiSize); 84 read(ibBuffer, uiSize);
85 85
86 return NO_ERROR; 86 return NO_ERROR;
87 } 87 }
88 88
89 unsigned int RelocationsDirectory::size() const 89 unsigned int RelocationsDirectory::size() const
90 { 90 {
91 unsigned int size = static_cast<unsigned int>(m_vRelocations.size()) * PELIB_IMAGE_BASE_RELOCATION::size(); 91 unsigned int size = static_cast<unsigned int>(m_vRelocations.size()) * PELIB_IMAGE_BASE_RELOCATION::size();
92 92
93 for (unsigned int i=0;i<m_vRelocations.size();i++) 93 for (unsigned int i=0;i<m_vRelocations.size();i++)
94 { 94 {
95 size += static_cast<unsigned int>(m_vRelocations[i].vRelocData.size()) * sizeof(word); 95 size += static_cast<unsigned int>(m_vRelocations[i].vRelocData.size()) * sizeof(word);
96 } 96 }
97 97
98 return size; 98 return size;
99 } 99 }
100 100
101 void RelocationsDirectory::rebuild(std::vector<byte>& vBuffer) const 101 void RelocationsDirectory::rebuild(std::vector<byte>& vBuffer) const
102 { 102 {
103 OutputBuffer obBuffer(vBuffer); 103 OutputBuffer obBuffer(vBuffer);
104 104
105 for (unsigned int i=0;i<m_vRelocations.size();i++) 105 for (unsigned int i=0;i<m_vRelocations.size();i++)
106 { 106 {
107 obBuffer << m_vRelocations[i].ibrRelocation.VirtualAddress; 107 obBuffer << m_vRelocations[i].ibrRelocation.VirtualAddress;
108 obBuffer << m_vRelocations[i].ibrRelocation.SizeOfBlock; 108 obBuffer << m_vRelocations[i].ibrRelocation.SizeOfBlock;
109 109
110 for (unsigned int j=0;j<m_vRelocations[i].vRelocData.size();j++) 110 for (unsigned int j=0;j<m_vRelocations[i].vRelocData.size();j++)
111 { 111 {
112 obBuffer << m_vRelocations[i].vRelocData[j]; 112 obBuffer << m_vRelocations[i].vRelocData[j];
113 } 113 }
114 } 114 }
115 } 115 }
116 116
117 unsigned int RelocationsDirectory::calcNumberOfRelocations() const 117 unsigned int RelocationsDirectory::calcNumberOfRelocations() const
118 { 118 {
119 return static_cast<unsigned int>(m_vRelocations.size()); 119 return static_cast<unsigned int>(m_vRelocations.size());
120 } 120 }
121 121
122 dword RelocationsDirectory::getVirtualAddress(unsigned int ulRelocation) const 122 dword RelocationsDirectory::getVirtualAddress(unsigned int ulRelocation) const
123 { 123 {
124 return m_vRelocations[ulRelocation].ibrRelocation.VirtualAddress; 124 return m_vRelocations[ulRelocation].ibrRelocation.VirtualAddress;
125 } 125 }
126 126
127 dword RelocationsDirectory::getSizeOfBlock(unsigned int ulRelocation) const 127 dword RelocationsDirectory::getSizeOfBlock(unsigned int ulRelocation) const
128 { 128 {
129 return m_vRelocations[ulRelocation].ibrRelocation.SizeOfBlock; 129 return m_vRelocations[ulRelocation].ibrRelocation.SizeOfBlock;
130 } 130 }
131 131
132 unsigned int RelocationsDirectory::calcNumberOfRelocationData(unsigned int ulRelocation) const 132 unsigned int RelocationsDirectory::calcNumberOfRelocationData(unsigned int ulRelocation) const
133 { 133 {
134 return static_cast<unsigned int>(m_vRelocations[ulRelocation].vRelocData.size()); 134 return static_cast<unsigned int>(m_vRelocations[ulRelocation].vRelocData.size());
135 } 135 }
136 136
137 word RelocationsDirectory::getRelocationData(unsigned int ulRelocation, unsigned int ulDataNumber) const 137 word RelocationsDirectory::getRelocationData(unsigned int ulRelocation, unsigned int ulDataNumber) const
138 { 138 {
139 return m_vRelocations[ulRelocation].vRelocData[ulDataNumber]; 139 return m_vRelocations[ulRelocation].vRelocData[ulDataNumber];
140 } 140 }
141 141
142 void RelocationsDirectory::setVirtualAddress(unsigned int ulRelocation, dword dwValue) 142 void RelocationsDirectory::setVirtualAddress(unsigned int ulRelocation, dword dwValue)
143 { 143 {
144 m_vRelocations[ulRelocation].ibrRelocation.VirtualAddress = dwValue; 144 m_vRelocations[ulRelocation].ibrRelocation.VirtualAddress = dwValue;
145 } 145 }
146 146
147 void RelocationsDirectory::setSizeOfBlock(unsigned int ulRelocation, dword dwValue) 147 void RelocationsDirectory::setSizeOfBlock(unsigned int ulRelocation, dword dwValue)
148 { 148 {
149 m_vRelocations[ulRelocation].ibrRelocation.SizeOfBlock = dwValue; 149 m_vRelocations[ulRelocation].ibrRelocation.SizeOfBlock = dwValue;
150 } 150 }
151 151
152 void RelocationsDirectory::addRelocation() 152 void RelocationsDirectory::addRelocation()
153 { 153 {
154 IMG_BASE_RELOC newrelocation; 154 IMG_BASE_RELOC newrelocation;
155 m_vRelocations.push_back(newrelocation); 155 m_vRelocations.push_back(newrelocation);
156 } 156 }
157 157
158 void RelocationsDirectory::addRelocationData(unsigned int ulRelocation, word wValue) 158 void RelocationsDirectory::addRelocationData(unsigned int ulRelocation, word wValue)
159 { 159 {
160 m_vRelocations[ulRelocation].vRelocData.push_back(wValue); 160 m_vRelocations[ulRelocation].vRelocData.push_back(wValue);
161 } 161 }
162 162
163/* void RelocationsDirectory::removeRelocationData(unsigned int ulRelocation, word wValue) 163/* void RelocationsDirectory::removeRelocationData(unsigned int ulRelocation, word wValue)
164 { 164 {
165 // If you get an error with Borland C++ here you have two options: Upgrade your compiler 165 // If you get an error with Borland C++ here you have two options: Upgrade your compiler
166 // or use the commented line instead of the line below. 166 // or use the commented line instead of the line below.
167 m_vRelocations[ulRelocation].vRelocData.erase(std::remove(m_vRelocations[ulRelocation].vRelocData.begin(), m_vRelocations[ulRelocation].vRelocData.end(), wValue), m_vRelocations[ulRelocation].vRelocData.end()); 167 m_vRelocations[ulRelocation].vRelocData.erase(std::remove(m_vRelocations[ulRelocation].vRelocData.begin(), m_vRelocations[ulRelocation].vRelocData.end(), wValue), m_vRelocations[ulRelocation].vRelocData.end());
168 } 168 }
169*/ 169*/
170 void RelocationsDirectory::removeRelocation(unsigned int index) 170 void RelocationsDirectory::removeRelocation(unsigned int index)
171 { 171 {
172 m_vRelocations.erase(m_vRelocations.begin() + index); 172 m_vRelocations.erase(m_vRelocations.begin() + index);
173 } 173 }
174 174
175 void RelocationsDirectory::removeRelocationData(unsigned int relocindex, unsigned int dataindex) 175 void RelocationsDirectory::removeRelocationData(unsigned int relocindex, unsigned int dataindex)
176 { 176 {
177 m_vRelocations[relocindex].vRelocData.erase(m_vRelocations[relocindex].vRelocData.begin() + dataindex); 177 m_vRelocations[relocindex].vRelocData.erase(m_vRelocations[relocindex].vRelocData.begin() + dataindex);
178 } 178 }
179 179
180 int RelocationsDirectory::write(const std::string& strFilename, unsigned int uiOffset) const 180 int RelocationsDirectory::write(const std::string& strFilename, unsigned int uiOffset) const
181 { 181 {
182 std::fstream ofFile(strFilename.c_str(), std::ios_base::in); 182 std::fstream ofFile(strFilename.c_str(), std::ios_base::in);
183 183
184 if (!ofFile) 184 if (!ofFile)
185 { 185 {
186 ofFile.clear(); 186 ofFile.clear();
187 ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary); 187 ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary);
188 } 188 }
189 else 189 else
190 { 190 {
191 ofFile.close(); 191 ofFile.close();
192 ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary); 192 ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary);
193 } 193 }
194 194
195 if (!ofFile) 195 if (!ofFile)
196 { 196 {
197 return ERROR_OPENING_FILE; 197 return ERROR_OPENING_FILE;
198 } 198 }
199 199
200 ofFile.seekp(uiOffset, std::ios::beg); 200 ofFile.seekp(uiOffset, std::ios::beg);
201 201
202 std::vector<unsigned char> vBuffer; 202 std::vector<unsigned char> vBuffer;
203 rebuild(vBuffer); 203 rebuild(vBuffer);
204 204
205 ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), static_cast<std::streamsize>(vBuffer.size())); 205 ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), static_cast<std::streamsize>(vBuffer.size()));
206 206
207 ofFile.close(); 207 ofFile.close();
208 208
209 return NO_ERROR; 209 return NO_ERROR;
210 } 210 }
211} 211}
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/RelocationsDirectory.h b/utils/zenutils/libraries/pelib-0.9/pelib/RelocationsDirectory.h
index 60383381a3..0fc10500e0 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/RelocationsDirectory.h
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/RelocationsDirectory.h
@@ -1,70 +1,70 @@
1/* 1/*
2* Relocations.h - Part of the PeLib library. 2* Relocations.h - Part of the PeLib library.
3* 3*
4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) 4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5* All rights reserved. 5* All rights reserved.
6* 6*
7* This software is licensed under the zlib/libpng License. 7* This software is licensed under the zlib/libpng License.
8* For more details see http://www.opensource.org/licenses/zlib-license.php 8* For more details see http://www.opensource.org/licenses/zlib-license.php
9* or the license information file (license.htm) in the root directory 9* or the license information file (license.htm) in the root directory
10* of PeLib. 10* of PeLib.
11*/ 11*/
12 12
13#ifndef RELOCATIONSDIRECTORY_H 13#ifndef RELOCATIONSDIRECTORY_H
14#define RELOCATIONSDIRECTORY_H 14#define RELOCATIONSDIRECTORY_H
15 15
16namespace PeLib 16namespace PeLib
17{ 17{
18 /// Class that handles the relocations directory. 18 /// Class that handles the relocations directory.
19 /** 19 /**
20 * This class handles the relocations directory. 20 * This class handles the relocations directory.
21 **/ 21 **/
22 class RelocationsDirectory 22 class RelocationsDirectory
23 { 23 {
24 private: 24 private:
25 std::vector<IMG_BASE_RELOC> m_vRelocations; ///< Used to store the relocation data. 25 std::vector<IMG_BASE_RELOC> m_vRelocations; ///< Used to store the relocation data.
26 26
27 void read(InputBuffer& inputbuffer, unsigned int uiSize); 27 void read(InputBuffer& inputbuffer, unsigned int uiSize);
28 28
29 public: 29 public:
30 /// Returns the number of relocations in the relocations directory. 30 /// Returns the number of relocations in the relocations directory.
31 unsigned int calcNumberOfRelocations() const; // EXPORT 31 unsigned int calcNumberOfRelocations() const; // EXPORT
32 /// Returns the number of relocation data entries of a specific relocation. 32 /// Returns the number of relocation data entries of a specific relocation.
33 unsigned int calcNumberOfRelocationData(unsigned int ulRelocation) const; // EXPORT 33 unsigned int calcNumberOfRelocationData(unsigned int ulRelocation) const; // EXPORT
34 34
35 /// Read a file's relocations directory. 35 /// Read a file's relocations directory.
36 int read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize); // EXPORT 36 int read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize); // EXPORT
37 int read(const unsigned char* buffer, unsigned int buffersize); // EXPORT 37 int read(const unsigned char* buffer, unsigned int buffersize); // EXPORT
38 /// Rebuilds the relocations directory. 38 /// Rebuilds the relocations directory.
39 void rebuild(std::vector<byte>& vBuffer) const; // EXPORT 39 void rebuild(std::vector<byte>& vBuffer) const; // EXPORT
40 /// Returns the size of the relocations directory. 40 /// Returns the size of the relocations directory.
41 unsigned int size() const; // EXPORT 41 unsigned int size() const; // EXPORT
42 /// Writes the relocations directory to a file. 42 /// Writes the relocations directory to a file.
43 int write(const std::string& strFilename, unsigned int dwOffset) const; // EXPORT 43 int write(const std::string& strFilename, unsigned int dwOffset) const; // EXPORT
44 44
45 /// Returns the VA of a relocation. 45 /// Returns the VA of a relocation.
46 dword getVirtualAddress(unsigned int ulRelocation) const; // EXPORT 46 dword getVirtualAddress(unsigned int ulRelocation) const; // EXPORT
47 /// Returns the SizeOfBlock value of a relocation. 47 /// Returns the SizeOfBlock value of a relocation.
48 dword getSizeOfBlock(unsigned int ulRelocation) const; // EXPORT 48 dword getSizeOfBlock(unsigned int ulRelocation) const; // EXPORT
49 /// Returns the RelocationData of a relocation. 49 /// Returns the RelocationData of a relocation.
50 word getRelocationData(unsigned int ulRelocation, unsigned int ulDataNumber) const; // EXPORT 50 word getRelocationData(unsigned int ulRelocation, unsigned int ulDataNumber) const; // EXPORT
51 51
52 /// Changes the relocation data of a relocation. 52 /// Changes the relocation data of a relocation.
53 void setRelocationData(unsigned int ulRelocation, unsigned int ulDataNumber, word wData); // EXPORT 53 void setRelocationData(unsigned int ulRelocation, unsigned int ulDataNumber, word wData); // EXPORT
54 54
55 /// Changes the VirtualAddress of a relocation. 55 /// Changes the VirtualAddress of a relocation.
56 void setVirtualAddress(unsigned int ulRelocation, dword dwValue); // EXPORT 56 void setVirtualAddress(unsigned int ulRelocation, dword dwValue); // EXPORT
57 /// Changes the SizeOfBlock of a relocation. 57 /// Changes the SizeOfBlock of a relocation.
58 void setSizeOfBlock(unsigned int ulRelocation, dword dwValue); // EXPORT 58 void setSizeOfBlock(unsigned int ulRelocation, dword dwValue); // EXPORT
59 59
60 void addRelocation(); // EXPORT 60 void addRelocation(); // EXPORT
61 /// Adds new data to a relocation. 61 /// Adds new data to a relocation.
62 void addRelocationData(unsigned int ulRelocation, word wValue); // EXPORT 62 void addRelocationData(unsigned int ulRelocation, word wValue); // EXPORT
63 /// Removes data from a relocation. 63 /// Removes data from a relocation.
64// void removeRelocationData(unsigned int ulRelocation, word wValue); // EXPORT 64// void removeRelocationData(unsigned int ulRelocation, word wValue); // EXPORT
65 void removeRelocation(unsigned int index); // EXPORT 65 void removeRelocation(unsigned int index); // EXPORT
66 void removeRelocationData(unsigned int relocindex, unsigned int dataindex); // EXPORT 66 void removeRelocationData(unsigned int relocindex, unsigned int dataindex); // EXPORT
67 }; 67 };
68} 68}
69 69
70#endif 70#endif
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/ResourceDirectory.cpp b/utils/zenutils/libraries/pelib-0.9/pelib/ResourceDirectory.cpp
index 5e4d3010bf..d1e4c59e5a 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/ResourceDirectory.cpp
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/ResourceDirectory.cpp
@@ -1,1497 +1,1497 @@
1/* 1/*
2* ResourceDirectory.h - Part of the PeLib library. 2* ResourceDirectory.h - Part of the PeLib library.
3* 3*
4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) 4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5* All rights reserved. 5* All rights reserved.
6* 6*
7* This software is licensed under the zlib/libpng License. 7* This software is licensed under the zlib/libpng License.
8* For more details see http://www.opensource.org/licenses/zlib-license.php 8* For more details see http://www.opensource.org/licenses/zlib-license.php
9* or the license information file (license.htm) in the root directory 9* or the license information file (license.htm) in the root directory
10* of PeLib. 10* of PeLib.
11*/ 11*/
12 12
13#include "ResourceDirectory.h" 13#include "ResourceDirectory.h"
14 14
15namespace PeLib 15namespace PeLib
16{ 16{
17// -------------------------------------------------- ResourceChild ------------------------------------------- 17// -------------------------------------------------- ResourceChild -------------------------------------------
18 18
19 ResourceChild::ResourceChild() 19 ResourceChild::ResourceChild()
20 { 20 {
21 } 21 }
22 22
23 ResourceChild::ResourceChild(const ResourceChild& rhs) 23 ResourceChild::ResourceChild(const ResourceChild& rhs)
24 { 24 {
25 if (dynamic_cast<ResourceNode*>(rhs.child)) 25 if (dynamic_cast<ResourceNode*>(rhs.child))
26 { 26 {
27 ResourceNode* oldnode = static_cast<ResourceNode*>(rhs.child); 27 ResourceNode* oldnode = static_cast<ResourceNode*>(rhs.child);
28 28
29 entry = rhs.entry; 29 entry = rhs.entry;
30 30
31 child = new ResourceNode; 31 child = new ResourceNode;
32 child->uiElementRva = rhs.child->getElementRva(); 32 child->uiElementRva = rhs.child->getElementRva();
33 static_cast<ResourceNode*>(child)->header = oldnode->header; 33 static_cast<ResourceNode*>(child)->header = oldnode->header;
34 static_cast<ResourceNode*>(child)->children = oldnode->children; 34 static_cast<ResourceNode*>(child)->children = oldnode->children;
35 } 35 }
36 else 36 else
37 { 37 {
38 ResourceLeaf* oldnode = static_cast<ResourceLeaf*>(rhs.child); 38 ResourceLeaf* oldnode = static_cast<ResourceLeaf*>(rhs.child);
39 39
40 child = new ResourceLeaf; 40 child = new ResourceLeaf;
41 child->uiElementRva = rhs.child->getElementRva(); 41 child->uiElementRva = rhs.child->getElementRva();
42 static_cast<ResourceLeaf*>(child)->m_data = oldnode->m_data; 42 static_cast<ResourceLeaf*>(child)->m_data = oldnode->m_data;
43 static_cast<ResourceLeaf*>(child)->entry = oldnode->entry; 43 static_cast<ResourceLeaf*>(child)->entry = oldnode->entry;
44 } 44 }
45 } 45 }
46 46
47 ResourceChild& ResourceChild::operator=(const ResourceChild& rhs) 47 ResourceChild& ResourceChild::operator=(const ResourceChild& rhs)
48 { 48 {
49 if (this != &rhs) 49 if (this != &rhs)
50 { 50 {
51 if (dynamic_cast<ResourceNode*>(rhs.child)) 51 if (dynamic_cast<ResourceNode*>(rhs.child))
52 { 52 {
53 ResourceNode* oldnode = static_cast<ResourceNode*>(rhs.child); 53 ResourceNode* oldnode = static_cast<ResourceNode*>(rhs.child);
54 54
55 entry = rhs.entry; 55 entry = rhs.entry;
56 56
57 child = new ResourceNode; 57 child = new ResourceNode;
58 child->uiElementRva = rhs.child->getElementRva(); 58 child->uiElementRva = rhs.child->getElementRva();
59 static_cast<ResourceNode*>(child)->header = oldnode->header; 59 static_cast<ResourceNode*>(child)->header = oldnode->header;
60 static_cast<ResourceNode*>(child)->children = oldnode->children; 60 static_cast<ResourceNode*>(child)->children = oldnode->children;
61 } 61 }
62 else 62 else
63 { 63 {
64 ResourceLeaf* oldnode = static_cast<ResourceLeaf*>(rhs.child); 64 ResourceLeaf* oldnode = static_cast<ResourceLeaf*>(rhs.child);
65 65
66 child = new ResourceLeaf; 66 child = new ResourceLeaf;
67 child->uiElementRva = rhs.child->getElementRva(); 67 child->uiElementRva = rhs.child->getElementRva();
68 static_cast<ResourceLeaf*>(child)->m_data = oldnode->m_data; 68 static_cast<ResourceLeaf*>(child)->m_data = oldnode->m_data;
69 static_cast<ResourceLeaf*>(child)->entry = oldnode->entry; 69 static_cast<ResourceLeaf*>(child)->entry = oldnode->entry;
70 } 70 }
71 } 71 }
72 72
73 return *this; 73 return *this;
74 } 74 }
75 75
76 ResourceChild::~ResourceChild() 76 ResourceChild::~ResourceChild()
77 { 77 {
78 delete child; 78 delete child;
79 } 79 }
80 80
81 /** 81 /**
82 * Compares the resource child's id to the parameter dwId. 82 * Compares the resource child's id to the parameter dwId.
83 * @param dwId ID of a resource. 83 * @param dwId ID of a resource.
84 * @return True, if the resource child's id equals the parameter. 84 * @return True, if the resource child's id equals the parameter.
85 **/ 85 **/
86 bool ResourceChild::equalId(dword dwId) const 86 bool ResourceChild::equalId(dword dwId) const
87 { 87 {
88 return entry.irde.Name == dwId; 88 return entry.irde.Name == dwId;
89 } 89 }
90 90
91 /** 91 /**
92 * Compares the resource child's name to the parameter strName. 92 * Compares the resource child's name to the parameter strName.
93 * @param strName ID of a resource. 93 * @param strName ID of a resource.
94 * @return True, if the resource child's name equals the parameter. 94 * @return True, if the resource child's name equals the parameter.
95 **/ 95 **/
96 bool ResourceChild::equalName(std::string strName) const 96 bool ResourceChild::equalName(std::string strName) const
97 { 97 {
98 return entry.wstrName == strName; 98 return entry.wstrName == strName;
99 } 99 }
100 100
101 /** 101 /**
102 * Returns true if the resource was given a name. 102 * Returns true if the resource was given a name.
103 **/ 103 **/
104 bool ResourceChild::isNamedResource() const 104 bool ResourceChild::isNamedResource() const
105 { 105 {
106 return entry.wstrName.size() != 0; 106 return entry.wstrName.size() != 0;
107 } 107 }
108 108
109 /** 109 /**
110 * The children of a resource must be ordered in a certain way. First come the named resources 110 * The children of a resource must be ordered in a certain way. First come the named resources
111 * in sorted order, afterwards followed the unnamed resources in sorted order. 111 * in sorted order, afterwards followed the unnamed resources in sorted order.
112 **/ 112 **/
113 bool ResourceChild::operator<(const ResourceChild& rc) const 113 bool ResourceChild::operator<(const ResourceChild& rc) const
114 { 114 {
115 if (this->isNamedResource() && !rc.isNamedResource()) 115 if (this->isNamedResource() && !rc.isNamedResource())
116 { 116 {
117 return true; 117 return true;
118 } 118 }
119 else if (!this->isNamedResource() && rc.isNamedResource()) 119 else if (!this->isNamedResource() && rc.isNamedResource())
120 { 120 {
121 return false; 121 return false;
122 } 122 }
123 else if (this->isNamedResource() && rc.isNamedResource()) 123 else if (this->isNamedResource() && rc.isNamedResource())
124 { 124 {
125 return this->entry.wstrName < rc.entry.wstrName; 125 return this->entry.wstrName < rc.entry.wstrName;
126 } 126 }
127 else 127 else
128 { 128 {
129 return this->entry.irde.Name < rc.entry.irde.Name; 129 return this->entry.irde.Name < rc.entry.irde.Name;
130 } 130 }
131 } 131 }
132 132
133/* unsigned int ResourceChild::size() const 133/* unsigned int ResourceChild::size() const
134 { 134 {
135 return PELIB_IMAGE_RESOURCE_DIRECTORY_ENTRY::size() 135 return PELIB_IMAGE_RESOURCE_DIRECTORY_ENTRY::size()
136 + child->size() 136 + child->size()
137 + (entry.wstrName.size() ? entry.wstrName.size() + 2 : 0); 137 + (entry.wstrName.size() ? entry.wstrName.size() + 2 : 0);
138 } 138 }
139*/ 139*/
140// -------------------------------------------------- ResourceElement ------------------------------------------- 140// -------------------------------------------------- ResourceElement -------------------------------------------
141 141
142 /** 142 /**
143 * Returns the RVA of a ResourceElement. This is the RVA where the ResourceElement can be 143 * Returns the RVA of a ResourceElement. This is the RVA where the ResourceElement can be
144 * found in the file. 144 * found in the file.
145 * @return RVA of the ResourceElement. 145 * @return RVA of the ResourceElement.
146 **/ 146 **/
147 unsigned int ResourceElement::getElementRva() const 147 unsigned int ResourceElement::getElementRva() const
148 { 148 {
149 return uiElementRva; 149 return uiElementRva;
150 } 150 }
151 151
152// -------------------------------------------------- ResourceLeaf ------------------------------------------- 152// -------------------------------------------------- ResourceLeaf -------------------------------------------
153 153
154 /** 154 /**
155 * Checks if a ResourceElement is a leaf or not. 155 * Checks if a ResourceElement is a leaf or not.
156 * @return Always returns true. 156 * @return Always returns true.
157 **/ 157 **/
158 bool ResourceLeaf::isLeaf() const 158 bool ResourceLeaf::isLeaf() const
159 { 159 {
160 return true; 160 return true;
161 } 161 }
162 162
163 /** 163 /**
164 * Reads the next resource leaf from the InputBuffer. 164 * Reads the next resource leaf from the InputBuffer.
165 * @param inpBuffer An InputBuffer that holds the complete resource directory. 165 * @param inpBuffer An InputBuffer that holds the complete resource directory.
166 * @param uiOffset Offset of the resource leaf that's to be read. 166 * @param uiOffset Offset of the resource leaf that's to be read.
167 * @param uiRva RVA of the beginning of the resource directory. 167 * @param uiRva RVA of the beginning of the resource directory.
168 * @param pad Used for debugging purposes. 168 * @param pad Used for debugging purposes.
169 **/ 169 **/
170 int ResourceLeaf::read(InputBuffer& inpBuffer, unsigned int uiOffset, unsigned int uiRva/*, const std::string& pad*/) 170 int ResourceLeaf::read(InputBuffer& inpBuffer, unsigned int uiOffset, unsigned int uiRva/*, const std::string& pad*/)
171 { 171 {
172// std::cout << pad << "Leaf:" << std::endl; 172// std::cout << pad << "Leaf:" << std::endl;
173 173
174 // Invalid leaf. 174 // Invalid leaf.
175 if (uiOffset + PELIB_IMAGE_RESOURCE_DATA_ENTRY::size() > inpBuffer.size()) 175 if (uiOffset + PELIB_IMAGE_RESOURCE_DATA_ENTRY::size() > inpBuffer.size())
176 { 176 {
177 return 1; 177 return 1;
178 } 178 }
179 179
180 uiElementRva = uiOffset + uiRva; 180 uiElementRva = uiOffset + uiRva;
181 181
182 inpBuffer.set(uiOffset); 182 inpBuffer.set(uiOffset);
183 183
184 inpBuffer >> entry.OffsetToData; 184 inpBuffer >> entry.OffsetToData;
185 inpBuffer >> entry.Size; 185 inpBuffer >> entry.Size;
186 inpBuffer >> entry.CodePage; 186 inpBuffer >> entry.CodePage;
187 inpBuffer >> entry.Reserved; 187 inpBuffer >> entry.Reserved;
188 188
189/* std::cout << pad << std::hex << "Offset: " << entry.OffsetToData << std::endl; 189/* std::cout << pad << std::hex << "Offset: " << entry.OffsetToData << std::endl;
190 std::cout << pad << std::hex << "Size: " << entry.Size << std::endl; 190 std::cout << pad << std::hex << "Size: " << entry.Size << std::endl;
191 std::cout << pad << std::hex << "CodePage: " << entry.CodePage << std::endl; 191 std::cout << pad << std::hex << "CodePage: " << entry.CodePage << std::endl;
192 std::cout << pad << std::hex << "Reserved: " << entry.Reserved << std::endl; 192 std::cout << pad << std::hex << "Reserved: " << entry.Reserved << std::endl;
193*/ 193*/
194 // Invalid leaf. 194 // Invalid leaf.
195 if (entry.OffsetToData - uiRva + entry.Size > inpBuffer.size()) 195 if (entry.OffsetToData - uiRva + entry.Size > inpBuffer.size())
196 { 196 {
197// std::cout << entry.OffsetToData << " XXX " << uiRva << " - " << entry.Size << " - " << inpBuffer.size() << std::endl; 197// std::cout << entry.OffsetToData << " XXX " << uiRva << " - " << entry.Size << " - " << inpBuffer.size() << std::endl;
198 return 1; 198 return 1;
199 } 199 }
200 200
201// std::cout << entry.OffsetToData << " - " << uiRva << " - " << entry.Size << " - " << inpBuffer.size() << std::endl; 201// std::cout << entry.OffsetToData << " - " << uiRva << " - " << entry.Size << " - " << inpBuffer.size() << std::endl;
202 inpBuffer.set(entry.OffsetToData - uiRva); 202 inpBuffer.set(entry.OffsetToData - uiRva);
203 m_data.assign(inpBuffer.data() + inpBuffer.get(), inpBuffer.data() + inpBuffer.get() + entry.Size); 203 m_data.assign(inpBuffer.data() + inpBuffer.get(), inpBuffer.data() + inpBuffer.get() + entry.Size);
204// std::cout << pad << std::hex << "Vector: " << m_data.size() << std::endl; 204// std::cout << pad << std::hex << "Vector: " << m_data.size() << std::endl;
205// std::copy(m_data.begin(), m_data.end(), std::ostream_iterator<int>(std::cout << std::hex, " ")); 205// std::copy(m_data.begin(), m_data.end(), std::ostream_iterator<int>(std::cout << std::hex, " "));
206 return 0; 206 return 0;
207 } 207 }
208 208
209 /** 209 /**
210 * Rebuilds the current resource leaf. 210 * Rebuilds the current resource leaf.
211 * @param obBuffer OutputBuffer where the rebuilt resource leaf is stored. 211 * @param obBuffer OutputBuffer where the rebuilt resource leaf is stored.
212 * @param uiOffset Offset of the resource leaf inside the resource directory. 212 * @param uiOffset Offset of the resource leaf inside the resource directory.
213 * @param uiRva RVA of the resource directory. 213 * @param uiRva RVA of the resource directory.
214 **/ 214 **/
215 void ResourceLeaf::rebuild(OutputBuffer& obBuffer, unsigned int& uiOffset, unsigned int uiRva, const std::string&) const 215 void ResourceLeaf::rebuild(OutputBuffer& obBuffer, unsigned int& uiOffset, unsigned int uiRva, const std::string&) const
216 { 216 {
217// std::cout << std::hex << pad << "Leaf: " << uiOffset << std::endl; 217// std::cout << std::hex << pad << "Leaf: " << uiOffset << std::endl;
218 uiOffset += PELIB_IMAGE_RESOURCE_DATA_ENTRY::size(); 218 uiOffset += PELIB_IMAGE_RESOURCE_DATA_ENTRY::size();
219 219
220// obBuffer << entry.OffsetToData; 220// obBuffer << entry.OffsetToData;
221// obBuffer << uiOffset; 221// obBuffer << uiOffset;
222 obBuffer << uiRva + uiOffset + (uiOffset % 4); 222 obBuffer << uiRva + uiOffset + (uiOffset % 4);
223 obBuffer << entry.Size; 223 obBuffer << entry.Size;
224 obBuffer << entry.CodePage; 224 obBuffer << entry.CodePage;
225 obBuffer << entry.Reserved; 225 obBuffer << entry.Reserved;
226 226
227 while (uiOffset % 4) 227 while (uiOffset % 4)
228 { 228 {
229 uiOffset++; 229 uiOffset++;
230 obBuffer << (byte)0; 230 obBuffer << (byte)0;
231 } 231 }
232 232
233 uiOffset += static_cast<unsigned int>(m_data.size()); 233 uiOffset += static_cast<unsigned int>(m_data.size());
234 234
235 for (unsigned int i=0;i<m_data.size();i++) 235 for (unsigned int i=0;i<m_data.size();i++)
236 { 236 {
237 obBuffer << m_data[i]; 237 obBuffer << m_data[i];
238 } 238 }
239// std::cout << "LeafChild: " << std::endl; 239// std::cout << "LeafChild: " << std::endl;
240 } 240 }
241 241
242 void ResourceLeaf::makeValid() 242 void ResourceLeaf::makeValid()
243 { 243 {
244 entry.Size = static_cast<unsigned int>(m_data.size()); 244 entry.Size = static_cast<unsigned int>(m_data.size());
245 } 245 }
246 246
247/* /// Returns the size of a resource leaf. 247/* /// Returns the size of a resource leaf.
248 unsigned int ResourceLeaf::size() const 248 unsigned int ResourceLeaf::size() const
249 { 249 {
250 return PELIB_IMAGE_RESOURCE_DATA_ENTRY::size() + m_data.size(); 250 return PELIB_IMAGE_RESOURCE_DATA_ENTRY::size() + m_data.size();
251 } 251 }
252*/ 252*/
253 253
254 /** 254 /**
255 * Returns a vector that contains the raw data of a resource leaf. 255 * Returns a vector that contains the raw data of a resource leaf.
256 * @return Raw data of the resource. 256 * @return Raw data of the resource.
257 **/ 257 **/
258 std::vector<byte> ResourceLeaf::getData() const 258 std::vector<byte> ResourceLeaf::getData() const
259 { 259 {
260 return m_data; 260 return m_data;
261 } 261 }
262 262
263 /** 263 /**
264 * Overwrites the raw data of a resource. 264 * Overwrites the raw data of a resource.
265 * @param vData New data of the resource. 265 * @param vData New data of the resource.
266 **/ 266 **/
267 void ResourceLeaf::setData(const std::vector<byte>& vData) 267 void ResourceLeaf::setData(const std::vector<byte>& vData)
268 { 268 {
269 m_data = vData; 269 m_data = vData;
270 } 270 }
271 271
272 /** 272 /**
273 * Returns the leaf's OffsetToData value. That's the RVA where the raw data of the resource 273 * Returns the leaf's OffsetToData value. That's the RVA where the raw data of the resource
274 * can be found. 274 * can be found.
275 * @return The leaf's OffsetToData value. 275 * @return The leaf's OffsetToData value.
276 **/ 276 **/
277 dword ResourceLeaf::getOffsetToData() const 277 dword ResourceLeaf::getOffsetToData() const
278 { 278 {
279 return entry.OffsetToData; 279 return entry.OffsetToData;
280 } 280 }
281 281
282 /** 282 /**
283 * Returns the leaf's Size value. That's the size of the raw data of the resource. 283 * Returns the leaf's Size value. That's the size of the raw data of the resource.
284 * @return The leaf's Size value. 284 * @return The leaf's Size value.
285 **/ 285 **/
286 dword ResourceLeaf::getSize() const 286 dword ResourceLeaf::getSize() const
287 { 287 {
288 return entry.Size; 288 return entry.Size;
289 } 289 }
290 290
291 /** 291 /**
292 * Returns the leaf's CodePage value. 292 * Returns the leaf's CodePage value.
293 * @return The leaf's CodePage value. 293 * @return The leaf's CodePage value.
294 **/ 294 **/
295 dword ResourceLeaf::getCodePage() const 295 dword ResourceLeaf::getCodePage() const
296 { 296 {
297 return entry.CodePage; 297 return entry.CodePage;
298 } 298 }
299 299
300 /** 300 /**
301 * Returns the leaf's Reserved value. 301 * Returns the leaf's Reserved value.
302 * @return The leaf's Reserved value. 302 * @return The leaf's Reserved value.
303 **/ 303 **/
304 dword ResourceLeaf::getReserved() const 304 dword ResourceLeaf::getReserved() const
305 { 305 {
306 return entry.Reserved; 306 return entry.Reserved;
307 } 307 }
308 308
309 /** 309 /**
310 * Sets the leaf's OffsetToData value. 310 * Sets the leaf's OffsetToData value.
311 * @param dwValue The leaf's new OffsetToData value. 311 * @param dwValue The leaf's new OffsetToData value.
312 **/ 312 **/
313 void ResourceLeaf::setOffsetToData(dword dwValue) 313 void ResourceLeaf::setOffsetToData(dword dwValue)
314 { 314 {
315 entry.OffsetToData = dwValue; 315 entry.OffsetToData = dwValue;
316 } 316 }
317 317
318 /** 318 /**
319 * Sets the leaf's Size value. 319 * Sets the leaf's Size value.
320 * @param dwValue The leaf's new Size value. 320 * @param dwValue The leaf's new Size value.
321 **/ 321 **/
322 void ResourceLeaf::setSize(dword dwValue) 322 void ResourceLeaf::setSize(dword dwValue)
323 { 323 {
324 entry.Size = dwValue; 324 entry.Size = dwValue;
325 } 325 }
326 326
327 /** 327 /**
328 * Sets the leaf's CodePage value. 328 * Sets the leaf's CodePage value.
329 * @param dwValue The leaf's new CodePage value. 329 * @param dwValue The leaf's new CodePage value.
330 **/ 330 **/
331 void ResourceLeaf::setCodePage(dword dwValue) 331 void ResourceLeaf::setCodePage(dword dwValue)
332 { 332 {
333 entry.CodePage = dwValue; 333 entry.CodePage = dwValue;
334 } 334 }
335 335
336 /** 336 /**
337 * Sets the leaf's Reserved value. 337 * Sets the leaf's Reserved value.
338 * @param dwValue The leaf's new Reserved value. 338 * @param dwValue The leaf's new Reserved value.
339 **/ 339 **/
340 void ResourceLeaf::setReserved(dword dwValue) 340 void ResourceLeaf::setReserved(dword dwValue)
341 { 341 {
342 entry.Reserved = dwValue; 342 entry.Reserved = dwValue;
343 } 343 }
344 344
345 345
346// -------------------------------------------------- ResourceNode ------------------------------------------- 346// -------------------------------------------------- ResourceNode -------------------------------------------
347 347
348 /** 348 /**
349 * Checks if a ResourceElement is a leaf or not. 349 * Checks if a ResourceElement is a leaf or not.
350 * @return Always returns false. 350 * @return Always returns false.
351 **/ 351 **/
352 bool ResourceNode::isLeaf() const 352 bool ResourceNode::isLeaf() const
353 { 353 {
354 return false; 354 return false;
355 } 355 }
356 356
357 /** 357 /**
358 * Sorts the node's children and corrects the node's header. 358 * Sorts the node's children and corrects the node's header.
359 **/ 359 **/
360 void ResourceNode::makeValid() 360 void ResourceNode::makeValid()
361 { 361 {
362 std::sort(children.begin(), children.end()); 362 std::sort(children.begin(), children.end());
363 header.NumberOfNamedEntries = static_cast<PeLib::word>(std::count_if(children.begin(), children.end(), std::mem_fun_ref(&ResourceChild::isNamedResource))); 363 header.NumberOfNamedEntries = static_cast<PeLib::word>(std::count_if(children.begin(), children.end(), std::mem_fun_ref(&ResourceChild::isNamedResource)));
364 header.NumberOfIdEntries = static_cast<unsigned int>(children.size()) - header.NumberOfNamedEntries; 364 header.NumberOfIdEntries = static_cast<unsigned int>(children.size()) - header.NumberOfNamedEntries;
365 } 365 }
366 366
367 /** 367 /**
368 * Rebuilds the current resource node. 368 * Rebuilds the current resource node.
369 * @param obBuffer OutputBuffer where the rebuilt resource node is stored. 369 * @param obBuffer OutputBuffer where the rebuilt resource node is stored.
370 * @param uiOffset Offset of the resource node inside the resource directory. 370 * @param uiOffset Offset of the resource node inside the resource directory.
371 * @param uiRva RVA of the resource directory. 371 * @param uiRva RVA of the resource directory.
372 * @param pad Used for debugging. 372 * @param pad Used for debugging.
373 **/ 373 **/
374 void ResourceNode::rebuild(OutputBuffer& obBuffer, unsigned int& uiOffset, unsigned int uiRva, const std::string& pad) const 374 void ResourceNode::rebuild(OutputBuffer& obBuffer, unsigned int& uiOffset, unsigned int uiRva, const std::string& pad) const
375 { 375 {
376/* std::cout << std::hex << pad << uiOffset << std::endl; 376/* std::cout << std::hex << pad << uiOffset << std::endl;
377 377
378 std::cout << std::hex << pad << "header.Characteristics: " << header.Characteristics << std::endl; 378 std::cout << std::hex << pad << "header.Characteristics: " << header.Characteristics << std::endl;
379 std::cout << std::hex << pad << "header.TimeDateStamp: " << header.TimeDateStamp << std::endl; 379 std::cout << std::hex << pad << "header.TimeDateStamp: " << header.TimeDateStamp << std::endl;
380 std::cout << std::hex << pad << "header.MajorVersion: " << header.MajorVersion << std::endl; 380 std::cout << std::hex << pad << "header.MajorVersion: " << header.MajorVersion << std::endl;
381 std::cout << std::hex << pad << "header.MinorVersion: " << header.MinorVersion << std::endl; 381 std::cout << std::hex << pad << "header.MinorVersion: " << header.MinorVersion << std::endl;
382 std::cout << std::hex << pad << "header.NumberOfNamedEntries: " << header.NumberOfNamedEntries << std::endl; 382 std::cout << std::hex << pad << "header.NumberOfNamedEntries: " << header.NumberOfNamedEntries << std::endl;
383 std::cout << std::hex << pad << "header.NumberOfIdEntries: " << header.NumberOfIdEntries << std::endl; 383 std::cout << std::hex << pad << "header.NumberOfIdEntries: " << header.NumberOfIdEntries << std::endl;
384*/ 384*/
385 obBuffer << header.Characteristics; 385 obBuffer << header.Characteristics;
386 obBuffer << header.TimeDateStamp; 386 obBuffer << header.TimeDateStamp;
387 obBuffer << header.MajorVersion; 387 obBuffer << header.MajorVersion;
388 obBuffer << header.MinorVersion; 388 obBuffer << header.MinorVersion;
389 //std::cout << pad << "Children: " << children.size() << std::endl; 389 //std::cout << pad << "Children: " << children.size() << std::endl;
390 //std::cout << pad << std::count_if(children.begin(), children.end(), std::mem_fun_ref(&ResourceChild::isNamedResource)) << std::endl; 390 //std::cout << pad << std::count_if(children.begin(), children.end(), std::mem_fun_ref(&ResourceChild::isNamedResource)) << std::endl;
391 //std::cout << pad << children.size() - std::count_if(children.begin(), children.end(), std::mem_fun_ref(&ResourceChild::isNamedResource)) << std::endl; 391 //std::cout << pad << children.size() - std::count_if(children.begin(), children.end(), std::mem_fun_ref(&ResourceChild::isNamedResource)) << std::endl;
392// obBuffer << std::count_if(children.begin(), children.end(), std::mem_fun_ref(&ResourceChild::isNamedResource)); 392// obBuffer << std::count_if(children.begin(), children.end(), std::mem_fun_ref(&ResourceChild::isNamedResource));
393// obBuffer << children.size() - std::count_if(children.begin(), children.end(), std::mem_fun_ref(&ResourceChild::isNamedResource)); 393// obBuffer << children.size() - std::count_if(children.begin(), children.end(), std::mem_fun_ref(&ResourceChild::isNamedResource));
394 obBuffer << header.NumberOfNamedEntries; 394 obBuffer << header.NumberOfNamedEntries;
395 obBuffer << header.NumberOfIdEntries; 395 obBuffer << header.NumberOfIdEntries;
396 396
397 uiOffset += PELIB_IMAGE_RESOURCE_DIRECTORY::size(); 397 uiOffset += PELIB_IMAGE_RESOURCE_DIRECTORY::size();
398 398
399 for (unsigned int i=0;i<children.size();i++) 399 for (unsigned int i=0;i<children.size();i++)
400 { 400 {
401 obBuffer << (dword)0; 401 obBuffer << (dword)0;
402 obBuffer << (dword)0; 402 obBuffer << (dword)0;
403 } 403 }
404 404
405 unsigned int newoffs = (uiOffset + children.size() * 8); 405 unsigned int newoffs = (uiOffset + children.size() * 8);
406 406
407 for (unsigned int i=0;i<children.size();i++) 407 for (unsigned int i=0;i<children.size();i++)
408 { 408 {
409 if (!children[i].entry.wstrName.size()) 409 if (!children[i].entry.wstrName.size())
410 { 410 {
411 obBuffer.update(uiOffset, children[i].entry.irde.Name); 411 obBuffer.update(uiOffset, children[i].entry.irde.Name);
412 } 412 }
413 else 413 else
414 { 414 {
415 obBuffer.update(uiOffset, newoffs | PELIB_IMAGE_RESOURCE_NAME_IS_STRING); 415 obBuffer.update(uiOffset, newoffs | PELIB_IMAGE_RESOURCE_NAME_IS_STRING);
416 obBuffer << (word)children[i].entry.wstrName.size(); 416 obBuffer << (word)children[i].entry.wstrName.size();
417 newoffs += 2; 417 newoffs += 2;
418 for (unsigned int j=0;j<children[i].entry.wstrName.size();j++) 418 for (unsigned int j=0;j<children[i].entry.wstrName.size();j++)
419 { 419 {
420// std::cout << children[i].entry.wstrName[j]; 420// std::cout << children[i].entry.wstrName[j];
421 obBuffer << (word)children[i].entry.wstrName[j]; 421 obBuffer << (word)children[i].entry.wstrName[j];
422 newoffs += 2; 422 newoffs += 2;
423 } 423 }
424 } 424 }
425 uiOffset += 4; 425 uiOffset += 4;
426// obBuffer << children[i].entry.OffsetToData; 426// obBuffer << children[i].entry.OffsetToData;
427 obBuffer.update(uiOffset, newoffs | (children[i].entry.irde.OffsetToData & PELIB_IMAGE_RESOURCE_DATA_IS_DIRECTORY)); 427 obBuffer.update(uiOffset, newoffs | (children[i].entry.irde.OffsetToData & PELIB_IMAGE_RESOURCE_DATA_IS_DIRECTORY));
428 uiOffset += 4; 428 uiOffset += 4;
429 children[i].child->rebuild(obBuffer, newoffs, uiRva, pad + " "); 429 children[i].child->rebuild(obBuffer, newoffs, uiRva, pad + " ");
430 } 430 }
431 uiOffset = newoffs; 431 uiOffset = newoffs;
432 } 432 }
433 433
434 /** 434 /**
435 * Reads the next resource node from the InputBuffer. 435 * Reads the next resource node from the InputBuffer.
436 * @param inpBuffer An InputBuffer that holds the complete resource directory. 436 * @param inpBuffer An InputBuffer that holds the complete resource directory.
437 * @param uiOffset Offset of the resource node that's to be read. 437 * @param uiOffset Offset of the resource node that's to be read.
438 * @param uiRva RVA of the beginning of the resource directory. 438 * @param uiRva RVA of the beginning of the resource directory.
439 * @param pad Something I need for debugging. Will be removed soon. 439 * @param pad Something I need for debugging. Will be removed soon.
440 **/ 440 **/
441 int ResourceNode::read(InputBuffer& inpBuffer, unsigned int uiOffset, unsigned int uiRva/*, const std::string& pad*/) 441 int ResourceNode::read(InputBuffer& inpBuffer, unsigned int uiOffset, unsigned int uiRva/*, const std::string& pad*/)
442 { 442 {
443 // Not enough space to be a valid node. 443 // Not enough space to be a valid node.
444 if (uiOffset + PELIB_IMAGE_RESOURCE_DIRECTORY::size() > inpBuffer.size()) 444 if (uiOffset + PELIB_IMAGE_RESOURCE_DIRECTORY::size() > inpBuffer.size())
445 { 445 {
446 return 1; 446 return 1;
447 } 447 }
448 448
449 uiElementRva = uiOffset + uiRva; 449 uiElementRva = uiOffset + uiRva;
450 450
451 inpBuffer.set(uiOffset); 451 inpBuffer.set(uiOffset);
452 452
453 inpBuffer >> header.Characteristics; 453 inpBuffer >> header.Characteristics;
454 inpBuffer >> header.TimeDateStamp; 454 inpBuffer >> header.TimeDateStamp;
455 inpBuffer >> header.MajorVersion; 455 inpBuffer >> header.MajorVersion;
456 inpBuffer >> header.MinorVersion; 456 inpBuffer >> header.MinorVersion;
457 inpBuffer >> header.NumberOfNamedEntries; 457 inpBuffer >> header.NumberOfNamedEntries;
458 inpBuffer >> header.NumberOfIdEntries; 458 inpBuffer >> header.NumberOfIdEntries;
459 459
460 // Not enough space to be a valid node. 460 // Not enough space to be a valid node.
461 if (uiOffset + PELIB_IMAGE_RESOURCE_DIRECTORY::size() 461 if (uiOffset + PELIB_IMAGE_RESOURCE_DIRECTORY::size()
462 + (header.NumberOfNamedEntries + header.NumberOfIdEntries) * PELIB_IMAGE_RESOURCE_DIRECTORY_ENTRY::size() 462 + (header.NumberOfNamedEntries + header.NumberOfIdEntries) * PELIB_IMAGE_RESOURCE_DIRECTORY_ENTRY::size()
463 > inpBuffer.size()) 463 > inpBuffer.size())
464 { 464 {
465 return 1; 465 return 1;
466 } 466 }
467 467
468// std::cout << std::hex << pad << "Characteristics: " << header.Characteristics << std::endl; 468// std::cout << std::hex << pad << "Characteristics: " << header.Characteristics << std::endl;
469// std::cout << std::hex << pad << "TimeDateStamp: " << header.TimeDateStamp << std::endl; 469// std::cout << std::hex << pad << "TimeDateStamp: " << header.TimeDateStamp << std::endl;
470// std::cout << std::hex << pad << "MajorVersion: " << header.MajorVersion << std::endl; 470// std::cout << std::hex << pad << "MajorVersion: " << header.MajorVersion << std::endl;
471// std::cout << std::hex << pad << "MinorVersion: " << header.MinorVersion << std::endl; 471// std::cout << std::hex << pad << "MinorVersion: " << header.MinorVersion << std::endl;
472// std::cout << std::hex << pad << "NumberOfNamedEntries: " << header.NumberOfNamedEntries << std::endl; 472// std::cout << std::hex << pad << "NumberOfNamedEntries: " << header.NumberOfNamedEntries << std::endl;
473// std::cout << std::hex << pad << "NumberOfIdEntries: " << header.NumberOfIdEntries << std::endl; 473// std::cout << std::hex << pad << "NumberOfIdEntries: " << header.NumberOfIdEntries << std::endl;
474 474
475 for (int i=0;i<header.NumberOfNamedEntries + header.NumberOfIdEntries;i++) 475 for (int i=0;i<header.NumberOfNamedEntries + header.NumberOfIdEntries;i++)
476 { 476 {
477 ResourceChild rc; 477 ResourceChild rc;
478 inpBuffer >> rc.entry.irde.Name; 478 inpBuffer >> rc.entry.irde.Name;
479 inpBuffer >> rc.entry.irde.OffsetToData; 479 inpBuffer >> rc.entry.irde.OffsetToData;
480 480
481 unsigned int lastPos = inpBuffer.get(); 481 unsigned int lastPos = inpBuffer.get();
482 482
483 if (rc.entry.irde.Name & PELIB_IMAGE_RESOURCE_NAME_IS_STRING) 483 if (rc.entry.irde.Name & PELIB_IMAGE_RESOURCE_NAME_IS_STRING)
484 { 484 {
485 // Enough space to read string length? 485 // Enough space to read string length?
486 if ((rc.entry.irde.Name & ~PELIB_IMAGE_RESOURCE_NAME_IS_STRING) + 2 < inpBuffer.size()) 486 if ((rc.entry.irde.Name & ~PELIB_IMAGE_RESOURCE_NAME_IS_STRING) + 2 < inpBuffer.size())
487 { 487 {
488 inpBuffer.set(rc.entry.irde.Name & ~PELIB_IMAGE_RESOURCE_NAME_IS_STRING); 488 inpBuffer.set(rc.entry.irde.Name & ~PELIB_IMAGE_RESOURCE_NAME_IS_STRING);
489 word strlen; 489 word strlen;
490 inpBuffer >> strlen; 490 inpBuffer >> strlen;
491 491
492 // Enough space to read string? 492 // Enough space to read string?
493 if ((rc.entry.irde.Name & ~PELIB_IMAGE_RESOURCE_NAME_IS_STRING) + 2 * strlen < inpBuffer.size()) 493 if ((rc.entry.irde.Name & ~PELIB_IMAGE_RESOURCE_NAME_IS_STRING) + 2 * strlen < inpBuffer.size())
494 { 494 {
495 wchar_t c; 495 wchar_t c;
496 for (word i=0;i<strlen;i++) 496 for (word i=0;i<strlen;i++)
497 { 497 {
498 inpBuffer >> c; 498 inpBuffer >> c;
499 rc.entry.wstrName += c; 499 rc.entry.wstrName += c;
500 } 500 }
501 } 501 }
502 } 502 }
503 503
504// std::wcout << rc.entry.wstrName << std::endl; 504// std::wcout << rc.entry.wstrName << std::endl;
505 505
506// std::cout << strlen << std::endl; 506// std::cout << strlen << std::endl;
507 inpBuffer.set(lastPos); 507 inpBuffer.set(lastPos);
508 } 508 }
509 509
510 if (rc.entry.irde.OffsetToData & PELIB_IMAGE_RESOURCE_DATA_IS_DIRECTORY) 510 if (rc.entry.irde.OffsetToData & PELIB_IMAGE_RESOURCE_DATA_IS_DIRECTORY)
511 { 511 {
512 rc.child = new ResourceNode; 512 rc.child = new ResourceNode;
513 rc.child->read(inpBuffer, rc.entry.irde.OffsetToData & ~PELIB_IMAGE_RESOURCE_DATA_IS_DIRECTORY, uiRva/*, pad + " "*/); 513 rc.child->read(inpBuffer, rc.entry.irde.OffsetToData & ~PELIB_IMAGE_RESOURCE_DATA_IS_DIRECTORY, uiRva/*, pad + " "*/);
514 } 514 }
515 else 515 else
516 { 516 {
517 rc.child = new ResourceLeaf; 517 rc.child = new ResourceLeaf;
518 rc.child->read(inpBuffer, rc.entry.irde.OffsetToData, uiRva/*, pad + " "*/); 518 rc.child->read(inpBuffer, rc.entry.irde.OffsetToData, uiRva/*, pad + " "*/);
519 } 519 }
520// std::cout << std::hex << pad << "Entry " << i << "(Name): " << rc.entry.irde.Name << std::endl; 520// std::cout << std::hex << pad << "Entry " << i << "(Name): " << rc.entry.irde.Name << std::endl;
521// std::cout << std::hex << pad << "Entry " << i << "(Offset): " << rc.entry.irde.OffsetToData << std::endl; 521// std::cout << std::hex << pad << "Entry " << i << "(Offset): " << rc.entry.irde.OffsetToData << std::endl;
522 522
523 children.push_back(rc); 523 children.push_back(rc);
524 inpBuffer.set(lastPos); 524 inpBuffer.set(lastPos);
525 } 525 }
526 526
527 return 0; 527 return 0;
528 } 528 }
529 529
530 /** 530 /**
531 * Returns the number of children of the current node. Note that this number is the number 531 * Returns the number of children of the current node. Note that this number is the number
532 * of defined children, not the value from the header. 532 * of defined children, not the value from the header.
533 * @return Number of node's children. 533 * @return Number of node's children.
534 **/ 534 **/
535 unsigned int ResourceNode::getNumberOfChildren() const 535 unsigned int ResourceNode::getNumberOfChildren() const
536 { 536 {
537 return static_cast<unsigned int>(children.size()); 537 return static_cast<unsigned int>(children.size());
538 } 538 }
539 539
540 /** 540 /**
541 * Adds another child to the current node. 541 * Adds another child to the current node.
542 **/ 542 **/
543 void ResourceNode::addChild() 543 void ResourceNode::addChild()
544 { 544 {
545 ResourceChild c; 545 ResourceChild c;
546 c.child = 0; 546 c.child = 0;
547 children.push_back(c); 547 children.push_back(c);
548 } 548 }
549 549
550 /** 550 /**
551 * Returns a node's child. 551 * Returns a node's child.
552 * @param uiIndex Index of the child. 552 * @param uiIndex Index of the child.
553 * @return The child identified by uiIndex. This child can be either a ResourceNode or a ResourceLeaf. 553 * @return The child identified by uiIndex. This child can be either a ResourceNode or a ResourceLeaf.
554 **/ 554 **/
555 ResourceElement* ResourceNode::getChild(unsigned int uiIndex) 555 ResourceElement* ResourceNode::getChild(unsigned int uiIndex)
556 { 556 {
557 return children[uiIndex].child; 557 return children[uiIndex].child;
558 } 558 }
559 559
560 /** 560 /**
561 * Removes a child from the current node. 561 * Removes a child from the current node.
562 * @param uiIndex Index of the child. 562 * @param uiIndex Index of the child.
563 **/ 563 **/
564 void ResourceNode::removeChild(unsigned int uiIndex) 564 void ResourceNode::removeChild(unsigned int uiIndex)
565 { 565 {
566 children.erase(children.begin() + uiIndex); 566 children.erase(children.begin() + uiIndex);
567 } 567 }
568 568
569 /** 569 /**
570 * Returns the name of a child. 570 * Returns the name of a child.
571 * @param uiIndex Index of the child. 571 * @param uiIndex Index of the child.
572 * @return Either the name of the specified child or an empty string. 572 * @return Either the name of the specified child or an empty string.
573 **/ 573 **/
574 std::string ResourceNode::getChildName(unsigned int uiIndex) const 574 std::string ResourceNode::getChildName(unsigned int uiIndex) const
575 { 575 {
576 return children[uiIndex].entry.wstrName; 576 return children[uiIndex].entry.wstrName;
577 } 577 }
578 578
579 /** 579 /**
580 * Returns the Name value of a child. 580 * Returns the Name value of a child.
581 * @param uiIndex Index of the child. 581 * @param uiIndex Index of the child.
582 * @return Name value of a child. 582 * @return Name value of a child.
583 **/ 583 **/
584 dword ResourceNode::getOffsetToChildName(unsigned int uiIndex) const 584 dword ResourceNode::getOffsetToChildName(unsigned int uiIndex) const
585 { 585 {
586 return children[uiIndex].entry.irde.Name; 586 return children[uiIndex].entry.irde.Name;
587 } 587 }
588 588
589 /** 589 /**
590 * Returns the OffsetToData value of a child. 590 * Returns the OffsetToData value of a child.
591 * @param uiIndex Index of the child. 591 * @param uiIndex Index of the child.
592 * @return OffsetToData value of a child. 592 * @return OffsetToData value of a child.
593 **/ 593 **/
594 dword ResourceNode::getOffsetToChildData(unsigned int uiIndex) const 594 dword ResourceNode::getOffsetToChildData(unsigned int uiIndex) const
595 { 595 {
596 return children[uiIndex].entry.irde.OffsetToData; 596 return children[uiIndex].entry.irde.OffsetToData;
597 } 597 }
598 598
599 599
600 /** 600 /**
601 * Sets the name of a child. 601 * Sets the name of a child.
602 * @param uiIndex Index of the child. 602 * @param uiIndex Index of the child.
603 * @param strNewName New name of the resource. 603 * @param strNewName New name of the resource.
604 **/ 604 **/
605 void ResourceNode::setChildName(unsigned int uiIndex, const std::string& strNewName) 605 void ResourceNode::setChildName(unsigned int uiIndex, const std::string& strNewName)
606 { 606 {
607 children[uiIndex].entry.wstrName = strNewName; 607 children[uiIndex].entry.wstrName = strNewName;
608 } 608 }
609 609
610 /** 610 /**
611 * Sets the Name value of a child. 611 * Sets the Name value of a child.
612 * @param uiIndex Index of the child. 612 * @param uiIndex Index of the child.
613 * @param dwNewOffset New Name value of the resource. 613 * @param dwNewOffset New Name value of the resource.
614 **/ 614 **/
615 void ResourceNode::setOffsetToChildName(unsigned int uiIndex, dword dwNewOffset) 615 void ResourceNode::setOffsetToChildName(unsigned int uiIndex, dword dwNewOffset)
616 { 616 {
617 children[uiIndex].entry.irde.Name = dwNewOffset; 617 children[uiIndex].entry.irde.Name = dwNewOffset;
618 } 618 }
619 619
620 /** 620 /**
621 * Sets the OffsetToData value of a child. 621 * Sets the OffsetToData value of a child.
622 * @param uiIndex Index of the child. 622 * @param uiIndex Index of the child.
623 * @param dwNewOffset New OffsetToData value of the resource. 623 * @param dwNewOffset New OffsetToData value of the resource.
624 **/ 624 **/
625 void ResourceNode::setOffsetToChildData(unsigned int uiIndex, dword dwNewOffset) 625 void ResourceNode::setOffsetToChildData(unsigned int uiIndex, dword dwNewOffset)
626 { 626 {
627 children[uiIndex].entry.irde.OffsetToData = dwNewOffset; 627 children[uiIndex].entry.irde.OffsetToData = dwNewOffset;
628 } 628 }
629 629
630 /** 630 /**
631 * Returns the Characteristics value of the node. 631 * Returns the Characteristics value of the node.
632 * @return Characteristics value of the node. 632 * @return Characteristics value of the node.
633 **/ 633 **/
634 dword ResourceNode::getCharacteristics() const 634 dword ResourceNode::getCharacteristics() const
635 { 635 {
636 return header.Characteristics; 636 return header.Characteristics;
637 } 637 }
638 638
639 /** 639 /**
640 * Returns the TimeDateStamp value of the node. 640 * Returns the TimeDateStamp value of the node.
641 * @return TimeDateStamp value of the node. 641 * @return TimeDateStamp value of the node.
642 **/ 642 **/
643 dword ResourceNode::getTimeDateStamp() const 643 dword ResourceNode::getTimeDateStamp() const
644 { 644 {
645 return header.TimeDateStamp; 645 return header.TimeDateStamp;
646 } 646 }
647 647
648 /** 648 /**
649 * Returns the MajorVersion value of the node. 649 * Returns the MajorVersion value of the node.
650 * @return MajorVersion value of the node. 650 * @return MajorVersion value of the node.
651 **/ 651 **/
652 word ResourceNode::getMajorVersion() const 652 word ResourceNode::getMajorVersion() const
653 { 653 {
654 return header.MajorVersion; 654 return header.MajorVersion;
655 } 655 }
656 656
657 /** 657 /**
658 * Returns the MinorVersion value of the node. 658 * Returns the MinorVersion value of the node.
659 * @return MinorVersion value of the node. 659 * @return MinorVersion value of the node.
660 **/ 660 **/
661 word ResourceNode::getMinorVersion() const 661 word ResourceNode::getMinorVersion() const
662 { 662 {
663 return header.MinorVersion; 663 return header.MinorVersion;
664 } 664 }
665 665
666 /** 666 /**
667 * Returns the NumberOfNamedEntries value of the node. 667 * Returns the NumberOfNamedEntries value of the node.
668 * @return NumberOfNamedEntries value of the node. 668 * @return NumberOfNamedEntries value of the node.
669 **/ 669 **/
670 word ResourceNode::getNumberOfNamedEntries() const 670 word ResourceNode::getNumberOfNamedEntries() const
671 { 671 {
672 return header.NumberOfNamedEntries; 672 return header.NumberOfNamedEntries;
673 } 673 }
674 674
675 /** 675 /**
676 * Returns the NumberOfIdEntries value of the node. 676 * Returns the NumberOfIdEntries value of the node.
677 * @return NumberOfIdEntries value of the node. 677 * @return NumberOfIdEntries value of the node.
678 **/ 678 **/
679 word ResourceNode::getNumberOfIdEntries() const 679 word ResourceNode::getNumberOfIdEntries() const
680 { 680 {
681 return header.NumberOfIdEntries; 681 return header.NumberOfIdEntries;
682 } 682 }
683 683
684 /** 684 /**
685 * Sets the Characteristics value of the node. 685 * Sets the Characteristics value of the node.
686 * @param value New Characteristics value of the node. 686 * @param value New Characteristics value of the node.
687 **/ 687 **/
688 void ResourceNode::setCharacteristics(dword value) 688 void ResourceNode::setCharacteristics(dword value)
689 { 689 {
690 header.Characteristics = value; 690 header.Characteristics = value;
691 } 691 }
692 692
693 /** 693 /**
694 * Sets the TimeDateStamp value of the node. 694 * Sets the TimeDateStamp value of the node.
695 * @param value New TimeDateStamp value of the node. 695 * @param value New TimeDateStamp value of the node.
696 **/ 696 **/
697 void ResourceNode::setTimeDateStamp(dword value) 697 void ResourceNode::setTimeDateStamp(dword value)
698 { 698 {
699 header.TimeDateStamp = value; 699 header.TimeDateStamp = value;
700 } 700 }
701 701
702 /** 702 /**
703 * Sets the MajorVersion value of the node. 703 * Sets the MajorVersion value of the node.
704 * @param value New MajorVersion value of the node. 704 * @param value New MajorVersion value of the node.
705 **/ 705 **/
706 void ResourceNode::setMajorVersion(word value) 706 void ResourceNode::setMajorVersion(word value)
707 { 707 {
708 header.MajorVersion = value; 708 header.MajorVersion = value;
709 } 709 }
710 710
711 /** 711 /**
712 * Sets the MinorVersion value of the node. 712 * Sets the MinorVersion value of the node.
713 * @param value New MinorVersion value of the node. 713 * @param value New MinorVersion value of the node.
714 **/ 714 **/
715 void ResourceNode::setMinorVersion(word value) 715 void ResourceNode::setMinorVersion(word value)
716 { 716 {
717 header.MinorVersion = value; 717 header.MinorVersion = value;
718 } 718 }
719 719
720 /** 720 /**
721 * Sets the NumberOfNamedEntries value of the node. 721 * Sets the NumberOfNamedEntries value of the node.
722 * @param value New NumberOfNamedEntries value of the node. 722 * @param value New NumberOfNamedEntries value of the node.
723 **/ 723 **/
724 void ResourceNode::setNumberOfNamedEntries(word value) 724 void ResourceNode::setNumberOfNamedEntries(word value)
725 { 725 {
726 header.NumberOfNamedEntries = value; 726 header.NumberOfNamedEntries = value;
727 } 727 }
728 728
729 /** 729 /**
730 * Sets the NumberOfIdEntries value of the node. 730 * Sets the NumberOfIdEntries value of the node.
731 * @param value New NumberOfIdEntries value of the node. 731 * @param value New NumberOfIdEntries value of the node.
732 **/ 732 **/
733 void ResourceNode::setNumberOfIdEntries(word value) 733 void ResourceNode::setNumberOfIdEntries(word value)
734 { 734 {
735 header.NumberOfIdEntries = value; 735 header.NumberOfIdEntries = value;
736 } 736 }
737 737
738 738
739/* /// Returns the size of a resource node. 739/* /// Returns the size of a resource node.
740 unsigned int ResourceNode::size() const 740 unsigned int ResourceNode::size() const
741 { 741 {
742 if (children.size()) 742 if (children.size())
743 { 743 {
744 std::cout << std::accumulate(children.begin(), children.end(), 0, accumulate<ResourceChild>) << std::endl; 744 std::cout << std::accumulate(children.begin(), children.end(), 0, accumulate<ResourceChild>) << std::endl;
745 return PELIB_IMAGE_RESOURCE_DIRECTORY::size() 745 return PELIB_IMAGE_RESOURCE_DIRECTORY::size()
746 + std::accumulate(children.begin(), children.end(), 0, accumulate<ResourceChild>); 746 + std::accumulate(children.begin(), children.end(), 0, accumulate<ResourceChild>);
747 } 747 }
748 else 748 else
749 { 749 {
750 return 0; 750 return 0;
751 } 751 }
752 } 752 }
753*/ 753*/
754// -------------------------------------------------- ResourceDirectory ------------------------------------------- 754// -------------------------------------------------- ResourceDirectory -------------------------------------------
755 755
756 /** 756 /**
757 * Returns the root node of the resource directory. 757 * Returns the root node of the resource directory.
758 * @return Root node of the resource directory. 758 * @return Root node of the resource directory.
759 **/ 759 **/
760 ResourceNode* ResourceDirectory::getRoot() 760 ResourceNode* ResourceDirectory::getRoot()
761 { 761 {
762 return &m_rnRoot; 762 return &m_rnRoot;
763 } 763 }
764 764
765 /** 765 /**
766 * Correctly sorts the resource nodes of the resource tree. This function should be called 766 * Correctly sorts the resource nodes of the resource tree. This function should be called
767 * before calling rebuild. 767 * before calling rebuild.
768 **/ 768 **/
769 void ResourceDirectory::makeValid() 769 void ResourceDirectory::makeValid()
770 { 770 {
771 m_rnRoot.makeValid(); 771 m_rnRoot.makeValid();
772 } 772 }
773 773
774 /** 774 /**
775 * Reads the resource directory from a file. 775 * Reads the resource directory from a file.
776 * @param strFilename Name of the file. 776 * @param strFilename Name of the file.
777 * @param uiOffset File offset of the resource directory. 777 * @param uiOffset File offset of the resource directory.
778 * @param uiSize Raw size of the resource directory. 778 * @param uiSize Raw size of the resource directory.
779 * @param uiResDirRva RVA of the beginning of the resource directory. 779 * @param uiResDirRva RVA of the beginning of the resource directory.
780 **/ 780 **/
781 int ResourceDirectory::read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize, unsigned int uiResDirRva) 781 int ResourceDirectory::read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize, unsigned int uiResDirRva)
782 { 782 {
783 if (!uiSize || !uiOffset) 783 if (!uiSize || !uiOffset)
784 { 784 {
785 return 1; 785 return 1;
786 } 786 }
787 787
788 std::ifstream ifFile(strFilename.c_str(), std::ios::binary); 788 std::ifstream ifFile(strFilename.c_str(), std::ios::binary);
789 789
790 if (!ifFile) 790 if (!ifFile)
791 { 791 {
792// throw Exceptions::CannotOpenFile(ResourceDirectoryId, __LINE__); 792// throw Exceptions::CannotOpenFile(ResourceDirectoryId, __LINE__);
793 return 1; 793 return 1;
794 } 794 }
795 795
796 if (fileSize(ifFile) < uiOffset + uiSize) 796 if (fileSize(ifFile) < uiOffset + uiSize)
797 { 797 {
798// throw Exceptions::InvalidFormat(ResourceDirectoryId, __LINE__); 798// throw Exceptions::InvalidFormat(ResourceDirectoryId, __LINE__);
799 return 1; 799 return 1;
800 } 800 }
801 801
802 ifFile.seekg(uiOffset, std::ios::beg); 802 ifFile.seekg(uiOffset, std::ios::beg);
803 803
804 PELIB_IMAGE_RESOURCE_DIRECTORY irdCurrRoot; 804 PELIB_IMAGE_RESOURCE_DIRECTORY irdCurrRoot;
805 805
806 std::vector<byte> vResourceDirectory(uiSize); 806 std::vector<byte> vResourceDirectory(uiSize);
807 ifFile.read(reinterpret_cast<char*>(&vResourceDirectory[0]), uiSize); 807 ifFile.read(reinterpret_cast<char*>(&vResourceDirectory[0]), uiSize);
808 808
809 InputBuffer inpBuffer(vResourceDirectory); 809 InputBuffer inpBuffer(vResourceDirectory);
810 810
811// ResourceNode currNode; 811// ResourceNode currNode;
812 return m_rnRoot.read(inpBuffer, 0, uiResDirRva/*, ""*/); 812 return m_rnRoot.read(inpBuffer, 0, uiResDirRva/*, ""*/);
813// std::swap(currNode, m_rnRoot); 813// std::swap(currNode, m_rnRoot);
814 } 814 }
815 815
816 /** 816 /**
817 * Rebuilds the resource directory. 817 * Rebuilds the resource directory.
818 * @param vBuffer Buffer the source directory will be written to. 818 * @param vBuffer Buffer the source directory will be written to.
819 * @param uiRva RVA of the resource directory. 819 * @param uiRva RVA of the resource directory.
820 **/ 820 **/
821 void ResourceDirectory::rebuild(std::vector<byte>& vBuffer, unsigned int uiRva) const 821 void ResourceDirectory::rebuild(std::vector<byte>& vBuffer, unsigned int uiRva) const
822 { 822 {
823 OutputBuffer obBuffer(vBuffer); 823 OutputBuffer obBuffer(vBuffer);
824 unsigned int offs = 0; 824 unsigned int offs = 0;
825// std::cout << "Root: " << m_rnRoot.children.size() << std::endl; 825// std::cout << "Root: " << m_rnRoot.children.size() << std::endl;
826 m_rnRoot.rebuild(obBuffer, offs, uiRva, ""); 826 m_rnRoot.rebuild(obBuffer, offs, uiRva, "");
827 } 827 }
828 828
829 /** 829 /**
830 * Returns the size of the entire rebuilt resource directory. That's the size of the entire 830 * Returns the size of the entire rebuilt resource directory. That's the size of the entire
831 * structure as it's written back to a file. 831 * structure as it's written back to a file.
832 **/ 832 **/
833/* unsigned int ResourceDirectory::size() const 833/* unsigned int ResourceDirectory::size() const
834 { 834 {
835 return m_rnRoot.size(); 835 return m_rnRoot.size();
836 } 836 }
837*/ 837*/
838 /** 838 /**
839 * Writes the current resource directory back into a file. 839 * Writes the current resource directory back into a file.
840 * @param strFilename Name of the output file. 840 * @param strFilename Name of the output file.
841 * @param uiOffset File offset where the resource directory will be written to. 841 * @param uiOffset File offset where the resource directory will be written to.
842 * @param uiRva RVA of the file offset. 842 * @param uiRva RVA of the file offset.
843 **/ 843 **/
844 int ResourceDirectory::write(const std::string& strFilename, unsigned int uiOffset, unsigned int uiRva) const 844 int ResourceDirectory::write(const std::string& strFilename, unsigned int uiOffset, unsigned int uiRva) const
845 { 845 {
846 std::fstream ofFile(strFilename.c_str(), std::ios_base::in); 846 std::fstream ofFile(strFilename.c_str(), std::ios_base::in);
847 847
848 if (!ofFile) 848 if (!ofFile)
849 { 849 {
850 ofFile.clear(); 850 ofFile.clear();
851 ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary); 851 ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary);
852 } 852 }
853 else 853 else
854 { 854 {
855 ofFile.close(); 855 ofFile.close();
856 ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary); 856 ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary);
857 } 857 }
858 858
859 if (!ofFile) 859 if (!ofFile)
860 { 860 {
861 return ERROR_OPENING_FILE; 861 return ERROR_OPENING_FILE;
862 } 862 }
863 863
864 ofFile.seekp(uiOffset, std::ios::beg); 864 ofFile.seekp(uiOffset, std::ios::beg);
865 865
866 std::vector<unsigned char> vBuffer; 866 std::vector<unsigned char> vBuffer;
867 rebuild(vBuffer, uiRva); 867 rebuild(vBuffer, uiRva);
868 868
869 ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), static_cast<unsigned int>(vBuffer.size())); 869 ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), static_cast<unsigned int>(vBuffer.size()));
870 870
871 ofFile.close(); 871 ofFile.close();
872 872
873 return 0; 873 return 0;
874 } 874 }
875 875
876 /** 876 /**
877 * Adds another resource type. The new resource type is identified by the ID dwResTypeId. 877 * Adds another resource type. The new resource type is identified by the ID dwResTypeId.
878 * @param dwResTypeId ID which identifies the resource type. 878 * @param dwResTypeId ID which identifies the resource type.
879 **/ 879 **/
880 int ResourceDirectory::addResourceType(dword dwResTypeId) 880 int ResourceDirectory::addResourceType(dword dwResTypeId)
881 { 881 {
882 std::vector<ResourceChild>::iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalId), dwResTypeId)); 882 std::vector<ResourceChild>::iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalId), dwResTypeId));
883 if (Iter != m_rnRoot.children.end()) 883 if (Iter != m_rnRoot.children.end())
884 { 884 {
885 return 1; 885 return 1;
886 // throw Exceptions::EntryAlreadyExists(ResourceDirectoryId, __LINE__); 886 // throw Exceptions::EntryAlreadyExists(ResourceDirectoryId, __LINE__);
887 } 887 }
888 888
889 ResourceChild rcCurr; 889 ResourceChild rcCurr;
890 rcCurr.child = new ResourceNode; 890 rcCurr.child = new ResourceNode;
891 rcCurr.entry.irde.Name = dwResTypeId; 891 rcCurr.entry.irde.Name = dwResTypeId;
892 m_rnRoot.children.push_back(rcCurr); 892 m_rnRoot.children.push_back(rcCurr);
893 893
894 return 0; 894 return 0;
895 } 895 }
896 896
897 /** 897 /**
898 * Adds another resource type. The new resource type is identified by the name strResTypeName. 898 * Adds another resource type. The new resource type is identified by the name strResTypeName.
899 * @param strResTypeName Name which identifies the resource type. 899 * @param strResTypeName Name which identifies the resource type.
900 **/ 900 **/
901 int ResourceDirectory::addResourceType(const std::string& strResTypeName) 901 int ResourceDirectory::addResourceType(const std::string& strResTypeName)
902 { 902 {
903 std::vector<ResourceChild>::iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalName), strResTypeName)); 903 std::vector<ResourceChild>::iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalName), strResTypeName));
904 if (Iter != m_rnRoot.children.end()) 904 if (Iter != m_rnRoot.children.end())
905 { 905 {
906 return 1; 906 return 1;
907// throw Exceptions::EntryAlreadyExists(ResourceDirectoryId, __LINE__); 907// throw Exceptions::EntryAlreadyExists(ResourceDirectoryId, __LINE__);
908 } 908 }
909 909
910 ResourceChild rcCurr; 910 ResourceChild rcCurr;
911 rcCurr.entry.wstrName = strResTypeName; 911 rcCurr.entry.wstrName = strResTypeName;
912 rcCurr.child = new ResourceNode; 912 rcCurr.child = new ResourceNode;
913 m_rnRoot.children.push_back(rcCurr); 913 m_rnRoot.children.push_back(rcCurr);
914 914
915 return 0; 915 return 0;
916 } 916 }
917 917
918 /** 918 /**
919 * Removes the resource type identified by the ID dwResTypeId. 919 * Removes the resource type identified by the ID dwResTypeId.
920 * @param dwResTypeId ID which identifies the resource type. 920 * @param dwResTypeId ID which identifies the resource type.
921 **/ 921 **/
922 int ResourceDirectory::removeResourceType(dword dwResTypeId) 922 int ResourceDirectory::removeResourceType(dword dwResTypeId)
923 { 923 {
924 std::vector<ResourceChild>::iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalId), dwResTypeId)); 924 std::vector<ResourceChild>::iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalId), dwResTypeId));
925 if (Iter == m_rnRoot.children.end()) 925 if (Iter == m_rnRoot.children.end())
926 { 926 {
927 return 1; 927 return 1;
928// throw Exceptions::ResourceTypeDoesNotExist(ResourceDirectoryId, __LINE__); 928// throw Exceptions::ResourceTypeDoesNotExist(ResourceDirectoryId, __LINE__);
929 } 929 }
930 930
931 bool isNamed = false; 931 bool isNamed = false;
932 if (Iter->isNamedResource()) isNamed = true; 932 if (Iter->isNamedResource()) isNamed = true;
933 933
934 m_rnRoot.children.erase(Iter); 934 m_rnRoot.children.erase(Iter);
935 935
936 if (isNamed) m_rnRoot.header.NumberOfNamedEntries = static_cast<PeLib::word>(m_rnRoot.children.size()); 936 if (isNamed) m_rnRoot.header.NumberOfNamedEntries = static_cast<PeLib::word>(m_rnRoot.children.size());
937 else m_rnRoot.header.NumberOfIdEntries = static_cast<PeLib::word>(m_rnRoot.children.size()); 937 else m_rnRoot.header.NumberOfIdEntries = static_cast<PeLib::word>(m_rnRoot.children.size());
938 938
939 return 0; 939 return 0;
940 } 940 }
941 941
942 /** 942 /**
943 * Removes the resource type identified by the name strResTypeName. 943 * Removes the resource type identified by the name strResTypeName.
944 * @param strResTypeName Name which identifies the resource type. 944 * @param strResTypeName Name which identifies the resource type.
945 **/ 945 **/
946 int ResourceDirectory::removeResourceType(const std::string& strResTypeName) 946 int ResourceDirectory::removeResourceType(const std::string& strResTypeName)
947 { 947 {
948 std::vector<ResourceChild>::iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalName), strResTypeName)); 948 std::vector<ResourceChild>::iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalName), strResTypeName));
949 if (Iter == m_rnRoot.children.end()) 949 if (Iter == m_rnRoot.children.end())
950 { 950 {
951 return 1; 951 return 1;
952 // throw Exceptions::ResourceTypeDoesNotExist(ResourceDirectoryId, __LINE__); 952 // throw Exceptions::ResourceTypeDoesNotExist(ResourceDirectoryId, __LINE__);
953 } 953 }
954 954
955 bool isNamed = false; 955 bool isNamed = false;
956 if (Iter->isNamedResource()) isNamed = true; 956 if (Iter->isNamedResource()) isNamed = true;
957 957
958 m_rnRoot.children.erase(Iter); 958 m_rnRoot.children.erase(Iter);
959 959
960 if (isNamed) m_rnRoot.header.NumberOfNamedEntries = static_cast<PeLib::word>(m_rnRoot.children.size()); 960 if (isNamed) m_rnRoot.header.NumberOfNamedEntries = static_cast<PeLib::word>(m_rnRoot.children.size());
961 else m_rnRoot.header.NumberOfIdEntries = static_cast<PeLib::word>(m_rnRoot.children.size()); 961 else m_rnRoot.header.NumberOfIdEntries = static_cast<PeLib::word>(m_rnRoot.children.size());
962 962
963 return 0; 963 return 0;
964 } 964 }
965 965
966 /** 966 /**
967 * Removes the resource type identified by the index uiIndex. 967 * Removes the resource type identified by the index uiIndex.
968 * @param uiIndex Index which identifies the resource type. 968 * @param uiIndex Index which identifies the resource type.
969 **/ 969 **/
970 int ResourceDirectory::removeResourceTypeByIndex(unsigned int uiIndex) 970 int ResourceDirectory::removeResourceTypeByIndex(unsigned int uiIndex)
971 { 971 {
972 bool isNamed = false; 972 bool isNamed = false;
973 if (m_rnRoot.children[uiIndex].isNamedResource()) isNamed = true; 973 if (m_rnRoot.children[uiIndex].isNamedResource()) isNamed = true;
974 974
975 m_rnRoot.children.erase(m_rnRoot.children.begin() + uiIndex); 975 m_rnRoot.children.erase(m_rnRoot.children.begin() + uiIndex);
976 976
977 if (isNamed) m_rnRoot.header.NumberOfNamedEntries = static_cast<PeLib::word>(m_rnRoot.children.size()); 977 if (isNamed) m_rnRoot.header.NumberOfNamedEntries = static_cast<PeLib::word>(m_rnRoot.children.size());
978 else m_rnRoot.header.NumberOfIdEntries = static_cast<PeLib::word>(m_rnRoot.children.size()); 978 else m_rnRoot.header.NumberOfIdEntries = static_cast<PeLib::word>(m_rnRoot.children.size());
979 979
980 return 0; 980 return 0;
981 } 981 }
982 982
983 /** 983 /**
984 * Adds another resource to the resource tree. The first parameter identifies the resource type 984 * Adds another resource to the resource tree. The first parameter identifies the resource type
985 * of the new resource, the second parameter identifies the resource itself. 985 * of the new resource, the second parameter identifies the resource itself.
986 * @param dwResTypeId ID of the resource type. 986 * @param dwResTypeId ID of the resource type.
987 * @param dwResId ID of the resource. 987 * @param dwResId ID of the resource.
988 **/ 988 **/
989 int ResourceDirectory::addResource(dword dwResTypeId, dword dwResId) 989 int ResourceDirectory::addResource(dword dwResTypeId, dword dwResId)
990 { 990 {
991 ResourceChild rcCurr; 991 ResourceChild rcCurr;
992 rcCurr.entry.irde.Name = dwResId; 992 rcCurr.entry.irde.Name = dwResId;
993 return addResourceT(dwResTypeId, dwResId, rcCurr); 993 return addResourceT(dwResTypeId, dwResId, rcCurr);
994 } 994 }
995 995
996 /** 996 /**
997 * Adds another resource to the resource tree. The first parameter identifies the resource type 997 * Adds another resource to the resource tree. The first parameter identifies the resource type
998 * of the new resource, the second parameter identifies the resource itself. 998 * of the new resource, the second parameter identifies the resource itself.
999 * @param dwResTypeId ID of the resource type. 999 * @param dwResTypeId ID of the resource type.
1000 * @param strResName Name of the resource. 1000 * @param strResName Name of the resource.
1001 **/ 1001 **/
1002 int ResourceDirectory::addResource(dword dwResTypeId, const std::string& strResName) 1002 int ResourceDirectory::addResource(dword dwResTypeId, const std::string& strResName)
1003 { 1003 {
1004 ResourceChild rcCurr; 1004 ResourceChild rcCurr;
1005 rcCurr.entry.wstrName = strResName; 1005 rcCurr.entry.wstrName = strResName;
1006 return addResourceT(dwResTypeId, strResName, rcCurr); 1006 return addResourceT(dwResTypeId, strResName, rcCurr);
1007 } 1007 }
1008 1008
1009 /** 1009 /**
1010 * Adds another resource to the resource tree. The first parameter identifies the resource type 1010 * Adds another resource to the resource tree. The first parameter identifies the resource type
1011 * of the new resource, the second parameter identifies the resource itself. 1011 * of the new resource, the second parameter identifies the resource itself.
1012 * @param strResTypeName Name of the resource type. 1012 * @param strResTypeName Name of the resource type.
1013 * @param dwResId ID of the resource. 1013 * @param dwResId ID of the resource.
1014 **/ 1014 **/
1015 int ResourceDirectory::addResource(const std::string& strResTypeName, dword dwResId) 1015 int ResourceDirectory::addResource(const std::string& strResTypeName, dword dwResId)
1016 { 1016 {
1017 ResourceChild rcCurr; 1017 ResourceChild rcCurr;
1018 rcCurr.entry.irde.Name = dwResId; 1018 rcCurr.entry.irde.Name = dwResId;
1019 return addResourceT(strResTypeName, dwResId, rcCurr); 1019 return addResourceT(strResTypeName, dwResId, rcCurr);
1020 } 1020 }
1021 1021
1022 /** 1022 /**
1023 * Adds another resource to the resource tree. The first parameter identifies the resource type 1023 * Adds another resource to the resource tree. The first parameter identifies the resource type
1024 * of the new resource, the second parameter identifies the resource itself. 1024 * of the new resource, the second parameter identifies the resource itself.
1025 * @param strResTypeName Name of the resource type. 1025 * @param strResTypeName Name of the resource type.
1026 * @param strResName Name of the resource. 1026 * @param strResName Name of the resource.
1027 **/ 1027 **/
1028 int ResourceDirectory::addResource(const std::string& strResTypeName, const std::string& strResName) 1028 int ResourceDirectory::addResource(const std::string& strResTypeName, const std::string& strResName)
1029 { 1029 {
1030 ResourceChild rcCurr; 1030 ResourceChild rcCurr;
1031 rcCurr.entry.wstrName = strResName; 1031 rcCurr.entry.wstrName = strResName;
1032 return addResourceT(strResTypeName, strResName, rcCurr); 1032 return addResourceT(strResTypeName, strResName, rcCurr);
1033 } 1033 }
1034 1034
1035 /** 1035 /**
1036 * Removes a resource from the resource tree. The first parameter identifies the resource type 1036 * Removes a resource from the resource tree. The first parameter identifies the resource type
1037 * of the new resource, the second parameter identifies the resource itself. 1037 * of the new resource, the second parameter identifies the resource itself.
1038 * @param dwResTypeIndex ID of the resource type. 1038 * @param dwResTypeIndex ID of the resource type.
1039 * @param dwResId ID of the resource. 1039 * @param dwResId ID of the resource.
1040 **/ 1040 **/
1041 int ResourceDirectory::removeResource(dword dwResTypeIndex, dword dwResId) 1041 int ResourceDirectory::removeResource(dword dwResTypeIndex, dword dwResId)
1042 { 1042 {
1043 return removeResourceT(dwResTypeIndex, dwResId); 1043 return removeResourceT(dwResTypeIndex, dwResId);
1044 } 1044 }
1045 1045
1046 /** 1046 /**
1047 * Removes a resource from the resource tree. The first parameter identifies the resource type 1047 * Removes a resource from the resource tree. The first parameter identifies the resource type
1048 * of the new resource, the second parameter identifies the resource itself. 1048 * of the new resource, the second parameter identifies the resource itself.
1049 * @param dwResTypeIndex ID of the resource type. 1049 * @param dwResTypeIndex ID of the resource type.
1050 * @param strResName Name of the resource. 1050 * @param strResName Name of the resource.
1051 **/ 1051 **/
1052 int ResourceDirectory::removeResource(dword dwResTypeIndex, const std::string& strResName) 1052 int ResourceDirectory::removeResource(dword dwResTypeIndex, const std::string& strResName)
1053 { 1053 {
1054 return removeResourceT(dwResTypeIndex, strResName); 1054 return removeResourceT(dwResTypeIndex, strResName);
1055 } 1055 }
1056 1056
1057 /** 1057 /**
1058 * Removes a resource from the resource tree. The first parameter identifies the resource type 1058 * Removes a resource from the resource tree. The first parameter identifies the resource type
1059 * of the new resource, the second parameter identifies the resource itself. 1059 * of the new resource, the second parameter identifies the resource itself.
1060 * @param strResTypeName Name of the resource type. 1060 * @param strResTypeName Name of the resource type.
1061 * @param dwResId ID of the resource. 1061 * @param dwResId ID of the resource.
1062 **/ 1062 **/
1063 int ResourceDirectory::removeResource(const std::string& strResTypeName, dword dwResId) 1063 int ResourceDirectory::removeResource(const std::string& strResTypeName, dword dwResId)
1064 { 1064 {
1065 return removeResourceT(strResTypeName, dwResId); 1065 return removeResourceT(strResTypeName, dwResId);
1066 } 1066 }
1067 1067
1068 /** 1068 /**
1069 * Removes a resource from the resource tree. The first parameter identifies the resource type 1069 * Removes a resource from the resource tree. The first parameter identifies the resource type
1070 * of the new resource, the second parameter identifies the resource itself. 1070 * of the new resource, the second parameter identifies the resource itself.
1071 * @param strResTypeName Name of the resource type. 1071 * @param strResTypeName Name of the resource type.
1072 * @param strResName Name of the resource. 1072 * @param strResName Name of the resource.
1073 **/ 1073 **/
1074 int ResourceDirectory::removeResource(const std::string& strResTypeName, const std::string& strResName) 1074 int ResourceDirectory::removeResource(const std::string& strResTypeName, const std::string& strResName)
1075 { 1075 {
1076 return removeResourceT(strResTypeName, strResName); 1076 return removeResourceT(strResTypeName, strResName);
1077 } 1077 }
1078 1078
1079 /** 1079 /**
1080 * Returns the number of resource types. 1080 * Returns the number of resource types.
1081 **/ 1081 **/
1082 unsigned int ResourceDirectory::getNumberOfResourceTypes() const 1082 unsigned int ResourceDirectory::getNumberOfResourceTypes() const
1083 { 1083 {
1084 return static_cast<unsigned int>(m_rnRoot.children.size()); 1084 return static_cast<unsigned int>(m_rnRoot.children.size());
1085 } 1085 }
1086 1086
1087 /** 1087 /**
1088 * Returns the ID of a resource type which was specified through an index. 1088 * Returns the ID of a resource type which was specified through an index.
1089 * The valid range of the parameter uiIndex is 0...getNumberOfResourceTypes() - 1. 1089 * The valid range of the parameter uiIndex is 0...getNumberOfResourceTypes() - 1.
1090 * Leaving the invalid range leads to undefined behaviour. 1090 * Leaving the invalid range leads to undefined behaviour.
1091 * @param uiIndex Index which identifies a resource type. 1091 * @param uiIndex Index which identifies a resource type.
1092 * @return The ID of the specified resource type. 1092 * @return The ID of the specified resource type.
1093 **/ 1093 **/
1094 dword ResourceDirectory::getResourceTypeIdByIndex(unsigned int uiIndex) const 1094 dword ResourceDirectory::getResourceTypeIdByIndex(unsigned int uiIndex) const
1095 { 1095 {
1096 return m_rnRoot.children[uiIndex].entry.irde.Name; 1096 return m_rnRoot.children[uiIndex].entry.irde.Name;
1097 } 1097 }
1098 1098
1099 /** 1099 /**
1100 * Returns the name of a resource type which was specified through an index. 1100 * Returns the name of a resource type which was specified through an index.
1101 * The valid range of the parameter uiIndex is 0...getNumberOfResourceTypes() - 1. 1101 * The valid range of the parameter uiIndex is 0...getNumberOfResourceTypes() - 1.
1102 * Leaving the invalid range leads to undefined behaviour. 1102 * Leaving the invalid range leads to undefined behaviour.
1103 * @param uiIndex Index which identifies a resource type. 1103 * @param uiIndex Index which identifies a resource type.
1104 * @return The name of the specified resource type. 1104 * @return The name of the specified resource type.
1105 **/ 1105 **/
1106 std::string ResourceDirectory::getResourceTypeNameByIndex(unsigned int uiIndex) const 1106 std::string ResourceDirectory::getResourceTypeNameByIndex(unsigned int uiIndex) const
1107 { 1107 {
1108 return m_rnRoot.children[uiIndex].entry.wstrName; 1108 return m_rnRoot.children[uiIndex].entry.wstrName;
1109 } 1109 }
1110 1110
1111 /** 1111 /**
1112 * Converts the ID of a resource type to an index. 1112 * Converts the ID of a resource type to an index.
1113 * @param dwResTypeId ID of the resource type. 1113 * @param dwResTypeId ID of the resource type.
1114 * @return Index of that resource type. 1114 * @return Index of that resource type.
1115 **/ 1115 **/
1116 int ResourceDirectory::resourceTypeIdToIndex(dword dwResTypeId) const 1116 int ResourceDirectory::resourceTypeIdToIndex(dword dwResTypeId) const
1117 { 1117 {
1118 std::vector<ResourceChild>::const_iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalId), dwResTypeId)); 1118 std::vector<ResourceChild>::const_iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalId), dwResTypeId));
1119 if (Iter == m_rnRoot.children.end()) return -1; 1119 if (Iter == m_rnRoot.children.end()) return -1;
1120 return static_cast<unsigned int>(std::distance(m_rnRoot.children.begin(), Iter)); 1120 return static_cast<unsigned int>(std::distance(m_rnRoot.children.begin(), Iter));
1121 } 1121 }
1122 1122
1123 /** 1123 /**
1124 * Converts the name of a resource type to an index. 1124 * Converts the name of a resource type to an index.
1125 * @param strResTypeName ID of the resource type. 1125 * @param strResTypeName ID of the resource type.
1126 * @return Index of that resource type. 1126 * @return Index of that resource type.
1127 **/ 1127 **/
1128 int ResourceDirectory::resourceTypeNameToIndex(const std::string& strResTypeName) const 1128 int ResourceDirectory::resourceTypeNameToIndex(const std::string& strResTypeName) const
1129 { 1129 {
1130 std::vector<ResourceChild>::const_iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalName), strResTypeName)); 1130 std::vector<ResourceChild>::const_iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalName), strResTypeName));
1131 if (Iter == m_rnRoot.children.end()) return -1; 1131 if (Iter == m_rnRoot.children.end()) return -1;
1132 return static_cast<unsigned int>(std::distance(m_rnRoot.children.begin(), Iter)); 1132 return static_cast<unsigned int>(std::distance(m_rnRoot.children.begin(), Iter));
1133 } 1133 }
1134 1134
1135 /** 1135 /**
1136 * Returns the number of resources of a specific resource type. 1136 * Returns the number of resources of a specific resource type.
1137 * @param dwId ID of the resource type. 1137 * @param dwId ID of the resource type.
1138 * @return Number of resources of resource type dwId. 1138 * @return Number of resources of resource type dwId.
1139 **/ 1139 **/
1140 unsigned int ResourceDirectory::getNumberOfResources(dword dwId) const 1140 unsigned int ResourceDirectory::getNumberOfResources(dword dwId) const
1141 { 1141 {
1142// std::vector<ResourceChild>::const_iterator IterD = m_rnRoot.children.begin(); 1142// std::vector<ResourceChild>::const_iterator IterD = m_rnRoot.children.begin();
1143// std::cout << dwId << std::endl; 1143// std::cout << dwId << std::endl;
1144// while (IterD != m_rnRoot.children.end()) 1144// while (IterD != m_rnRoot.children.end())
1145// { 1145// {
1146// std::cout << IterD->entry.irde.Name << std::endl; 1146// std::cout << IterD->entry.irde.Name << std::endl;
1147// ++IterD; 1147// ++IterD;
1148// } 1148// }
1149 1149
1150 std::vector<ResourceChild>::const_iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalId), dwId)); 1150 std::vector<ResourceChild>::const_iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalId), dwId));
1151 if (Iter == m_rnRoot.children.end()) 1151 if (Iter == m_rnRoot.children.end())
1152 { 1152 {
1153 return 0xFFFFFFFF; 1153 return 0xFFFFFFFF;
1154 } 1154 }
1155 else 1155 else
1156 { 1156 {
1157 ResourceNode* currNode = static_cast<ResourceNode*>(Iter->child); 1157 ResourceNode* currNode = static_cast<ResourceNode*>(Iter->child);
1158 return static_cast<unsigned int>(currNode->children.size()); 1158 return static_cast<unsigned int>(currNode->children.size());
1159 } 1159 }
1160 } 1160 }
1161 1161
1162 /** 1162 /**
1163 * Returns the number of resources of a specific resource type. 1163 * Returns the number of resources of a specific resource type.
1164 * @param strResTypeName Name of the resource type. 1164 * @param strResTypeName Name of the resource type.
1165 * @return Number of resources of resource type strResTypeName. 1165 * @return Number of resources of resource type strResTypeName.
1166 **/ 1166 **/
1167 unsigned int ResourceDirectory::getNumberOfResources(const std::string& strResTypeName) const 1167 unsigned int ResourceDirectory::getNumberOfResources(const std::string& strResTypeName) const
1168 { 1168 {
1169 std::vector<ResourceChild>::const_iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalName), strResTypeName)); 1169 std::vector<ResourceChild>::const_iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalName), strResTypeName));
1170 if (Iter == m_rnRoot.children.end()) 1170 if (Iter == m_rnRoot.children.end())
1171 { 1171 {
1172 return 0xFFFFFFFF; 1172 return 0xFFFFFFFF;
1173 } 1173 }
1174 else 1174 else
1175 { 1175 {
1176 ResourceNode* currNode = static_cast<ResourceNode*>(Iter->child); 1176 ResourceNode* currNode = static_cast<ResourceNode*>(Iter->child);
1177 return static_cast<unsigned int>(currNode->children.size()); 1177 return static_cast<unsigned int>(currNode->children.size());
1178 } 1178 }
1179 } 1179 }
1180 1180
1181 /** 1181 /**
1182 * Returns the number of resources of a resource type which was specified through an index. 1182 * Returns the number of resources of a resource type which was specified through an index.
1183 * The valid range of the parameter uiIndex is 0...getNumberOfResourceTypes() - 1. 1183 * The valid range of the parameter uiIndex is 0...getNumberOfResourceTypes() - 1.
1184 * Leaving the invalid range leads to undefined behaviour. 1184 * Leaving the invalid range leads to undefined behaviour.
1185 * @param uiIndex Index which identifies a resource type. 1185 * @param uiIndex Index which identifies a resource type.
1186 * @return The number of resources of the specified resource type. 1186 * @return The number of resources of the specified resource type.
1187 **/ 1187 **/
1188 unsigned int ResourceDirectory::getNumberOfResourcesByIndex(unsigned int uiIndex) const 1188 unsigned int ResourceDirectory::getNumberOfResourcesByIndex(unsigned int uiIndex) const
1189 { 1189 {
1190 ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiIndex].child); 1190 ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiIndex].child);
1191 return static_cast<unsigned int>(currNode->children.size()); 1191 return static_cast<unsigned int>(currNode->children.size());
1192 } 1192 }
1193 1193
1194 /** 1194 /**
1195 * Gets the resource data of a specific resource. 1195 * Gets the resource data of a specific resource.
1196 * @param dwResTypeId Identifies the resource type of the resource. 1196 * @param dwResTypeId Identifies the resource type of the resource.
1197 * @param dwResId Identifies the resource. 1197 * @param dwResId Identifies the resource.
1198 * @param data Vector where the data is stored. 1198 * @param data Vector where the data is stored.
1199 **/ 1199 **/
1200 void ResourceDirectory::getResourceData(dword dwResTypeId, dword dwResId, std::vector<byte>& data) const 1200 void ResourceDirectory::getResourceData(dword dwResTypeId, dword dwResId, std::vector<byte>& data) const
1201 { 1201 {
1202 getResourceDataT(dwResTypeId, dwResId, data); 1202 getResourceDataT(dwResTypeId, dwResId, data);
1203 } 1203 }
1204 1204
1205 /** 1205 /**
1206 * Gets the resource data of a specific resource. 1206 * Gets the resource data of a specific resource.
1207 * @param dwResTypeId Identifies the resource type of the resource. 1207 * @param dwResTypeId Identifies the resource type of the resource.
1208 * @param strResName Identifies the resource. 1208 * @param strResName Identifies the resource.
1209 * @param data Vector where the data is stored. 1209 * @param data Vector where the data is stored.
1210 **/ 1210 **/
1211 void ResourceDirectory::getResourceData(dword dwResTypeId, const std::string& strResName, std::vector<byte>& data) const 1211 void ResourceDirectory::getResourceData(dword dwResTypeId, const std::string& strResName, std::vector<byte>& data) const
1212 { 1212 {
1213 getResourceDataT(dwResTypeId, strResName, data); 1213 getResourceDataT(dwResTypeId, strResName, data);
1214 } 1214 }
1215 1215
1216 /** 1216 /**
1217 * Gets the resource data of a specific resource. 1217 * Gets the resource data of a specific resource.
1218 * @param strResTypeName Identifies the resource type of the resource. 1218 * @param strResTypeName Identifies the resource type of the resource.
1219 * @param dwResId Identifies the resource. 1219 * @param dwResId Identifies the resource.
1220 * @param data Vector where the data is stored. 1220 * @param data Vector where the data is stored.
1221 **/ 1221 **/
1222 void ResourceDirectory::getResourceData(const std::string& strResTypeName, dword dwResId, std::vector<byte>& data) const 1222 void ResourceDirectory::getResourceData(const std::string& strResTypeName, dword dwResId, std::vector<byte>& data) const
1223 { 1223 {
1224 getResourceDataT(strResTypeName, dwResId, data); 1224 getResourceDataT(strResTypeName, dwResId, data);
1225 } 1225 }
1226 1226
1227 /** 1227 /**
1228 * Gets the resource data of a specific resource. 1228 * Gets the resource data of a specific resource.
1229 * @param strResTypeName Identifies the resource type of the resource. 1229 * @param strResTypeName Identifies the resource type of the resource.
1230 * @param strResName Identifies the resource. 1230 * @param strResName Identifies the resource.
1231 * @param data Vector where the data is stored. 1231 * @param data Vector where the data is stored.
1232 **/ 1232 **/
1233 void ResourceDirectory::getResourceData(const std::string& strResTypeName, const std::string& strResName, std::vector<byte>& data) const 1233 void ResourceDirectory::getResourceData(const std::string& strResTypeName, const std::string& strResName, std::vector<byte>& data) const
1234 { 1234 {
1235 getResourceDataT(strResTypeName, strResName, data); 1235 getResourceDataT(strResTypeName, strResName, data);
1236 } 1236 }
1237 1237
1238 /** 1238 /**
1239 * Gets the resource data of a specific resource by index. 1239 * Gets the resource data of a specific resource by index.
1240 * The valid range of the parameter uiResTypeIndex is 0...getNumberOfResourceTypes() - 1. 1240 * The valid range of the parameter uiResTypeIndex is 0...getNumberOfResourceTypes() - 1.
1241 * The valid range of the parameter uiResIndex is 0...getNumberOfResources() - 1. 1241 * The valid range of the parameter uiResIndex is 0...getNumberOfResources() - 1.
1242 * Leaving the invalid range leads to undefined behaviour. 1242 * Leaving the invalid range leads to undefined behaviour.
1243 * @param uiResTypeIndex Identifies the resource type of the resource. 1243 * @param uiResTypeIndex Identifies the resource type of the resource.
1244 * @param uiResIndex Identifies the resource. 1244 * @param uiResIndex Identifies the resource.
1245 * @param data Vector where the data is stored. 1245 * @param data Vector where the data is stored.
1246 **/ 1246 **/
1247 void ResourceDirectory::getResourceDataByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex, std::vector<byte>& data) const 1247 void ResourceDirectory::getResourceDataByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex, std::vector<byte>& data) const
1248 { 1248 {
1249 ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiResTypeIndex].child); 1249 ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiResTypeIndex].child);
1250 currNode = static_cast<ResourceNode*>(currNode->children[uiResIndex].child); 1250 currNode = static_cast<ResourceNode*>(currNode->children[uiResIndex].child);
1251 ResourceLeaf* currLeaf = static_cast<ResourceLeaf*>(currNode->children[0].child); 1251 ResourceLeaf* currLeaf = static_cast<ResourceLeaf*>(currNode->children[0].child);
1252 1252
1253 data.assign(currLeaf->m_data.begin(), currLeaf->m_data.end()); 1253 data.assign(currLeaf->m_data.begin(), currLeaf->m_data.end());
1254 } 1254 }
1255 1255
1256 /** 1256 /**
1257 * Sets the resource data of a specific resource. 1257 * Sets the resource data of a specific resource.
1258 * @param dwResTypeId Identifies the resource type of the resource. 1258 * @param dwResTypeId Identifies the resource type of the resource.
1259 * @param dwResId Identifies the resource. 1259 * @param dwResId Identifies the resource.
1260 * @param data The new resource data. 1260 * @param data The new resource data.
1261 **/ 1261 **/
1262 void ResourceDirectory::setResourceData(dword dwResTypeId, dword dwResId, std::vector<byte>& data) 1262 void ResourceDirectory::setResourceData(dword dwResTypeId, dword dwResId, std::vector<byte>& data)
1263 { 1263 {
1264 setResourceDataT(dwResTypeId, dwResId, data); 1264 setResourceDataT(dwResTypeId, dwResId, data);
1265 } 1265 }
1266 1266
1267 /** 1267 /**
1268 * Sets the resource data of a specific resource. 1268 * Sets the resource data of a specific resource.
1269 * @param dwResTypeId Identifies the resource type of the resource. 1269 * @param dwResTypeId Identifies the resource type of the resource.
1270 * @param strResName Identifies the resource. 1270 * @param strResName Identifies the resource.
1271 * @param data The new resource data. 1271 * @param data The new resource data.
1272 **/ 1272 **/
1273 void ResourceDirectory::setResourceData(dword dwResTypeId, const std::string& strResName, std::vector<byte>& data) 1273 void ResourceDirectory::setResourceData(dword dwResTypeId, const std::string& strResName, std::vector<byte>& data)
1274 { 1274 {
1275 setResourceDataT(dwResTypeId, strResName, data); 1275 setResourceDataT(dwResTypeId, strResName, data);
1276 } 1276 }
1277 1277
1278 /** 1278 /**
1279 * Sets the resource data of a specific resource. 1279 * Sets the resource data of a specific resource.
1280 * @param strResTypeName Identifies the resource type of the resource. 1280 * @param strResTypeName Identifies the resource type of the resource.
1281 * @param dwResId Identifies the resource. 1281 * @param dwResId Identifies the resource.
1282 * @param data The new resource data. 1282 * @param data The new resource data.
1283 **/ 1283 **/
1284 void ResourceDirectory::setResourceData(const std::string& strResTypeName, dword dwResId, std::vector<byte>& data) 1284 void ResourceDirectory::setResourceData(const std::string& strResTypeName, dword dwResId, std::vector<byte>& data)
1285 { 1285 {
1286 setResourceDataT(strResTypeName, dwResId, data); 1286 setResourceDataT(strResTypeName, dwResId, data);
1287 } 1287 }
1288 1288
1289 /** 1289 /**
1290 * Sets the resource data of a specific resource. 1290 * Sets the resource data of a specific resource.
1291 * @param strResTypeName Identifies the resource type of the resource. 1291 * @param strResTypeName Identifies the resource type of the resource.
1292 * @param strResName Identifies the resource. 1292 * @param strResName Identifies the resource.
1293 * @param data The new resource data. 1293 * @param data The new resource data.
1294 **/ 1294 **/
1295 void ResourceDirectory::setResourceData(const std::string& strResTypeName, const std::string& strResName, std::vector<byte>& data) 1295 void ResourceDirectory::setResourceData(const std::string& strResTypeName, const std::string& strResName, std::vector<byte>& data)
1296 { 1296 {
1297 setResourceDataT(strResTypeName, strResName, data); 1297 setResourceDataT(strResTypeName, strResName, data);
1298 } 1298 }
1299 1299
1300 /** 1300 /**
1301 * Sets the resource data of a specific resource by index. 1301 * Sets the resource data of a specific resource by index.
1302 * The valid range of the parameter uiResTypeIndex is 0...getNumberOfResourceTypes() - 1. 1302 * The valid range of the parameter uiResTypeIndex is 0...getNumberOfResourceTypes() - 1.
1303 * The valid range of the parameter uiResIndex is 0...getNumberOfResources() - 1. 1303 * The valid range of the parameter uiResIndex is 0...getNumberOfResources() - 1.
1304 * Leaving the invalid range leads to undefined behaviour. 1304 * Leaving the invalid range leads to undefined behaviour.
1305 * @param uiResTypeIndex Identifies the resource type of the resource. 1305 * @param uiResTypeIndex Identifies the resource type of the resource.
1306 * @param uiResIndex Identifies the resource. 1306 * @param uiResIndex Identifies the resource.
1307 * @param data The new resource data. 1307 * @param data The new resource data.
1308 **/ 1308 **/
1309 void ResourceDirectory::setResourceDataByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex, std::vector<byte>& data) 1309 void ResourceDirectory::setResourceDataByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex, std::vector<byte>& data)
1310 { 1310 {
1311 ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiResTypeIndex].child); 1311 ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiResTypeIndex].child);
1312 currNode = static_cast<ResourceNode*>(currNode->children[uiResIndex].child); 1312 currNode = static_cast<ResourceNode*>(currNode->children[uiResIndex].child);
1313 ResourceLeaf* currLeaf = static_cast<ResourceLeaf*>(currNode->children[0].child); 1313 ResourceLeaf* currLeaf = static_cast<ResourceLeaf*>(currNode->children[0].child);
1314 currLeaf->m_data.assign(data.begin(), data.end()); 1314 currLeaf->m_data.assign(data.begin(), data.end());
1315 } 1315 }
1316 1316
1317 /** 1317 /**
1318 * Gets the ID of a specific resource. 1318 * Gets the ID of a specific resource.
1319 * @param dwResTypeId Identifies the resource type of the resource. 1319 * @param dwResTypeId Identifies the resource type of the resource.
1320 * @param strResName Identifies the resource. 1320 * @param strResName Identifies the resource.
1321 * @return ID of the specified resource. 1321 * @return ID of the specified resource.
1322 **/ 1322 **/
1323 dword ResourceDirectory::getResourceId(dword dwResTypeId, const std::string& strResName) const 1323 dword ResourceDirectory::getResourceId(dword dwResTypeId, const std::string& strResName) const
1324 { 1324 {
1325 return getResourceIdT(dwResTypeId, strResName); 1325 return getResourceIdT(dwResTypeId, strResName);
1326 } 1326 }
1327 1327
1328 /** 1328 /**
1329 * Gets the ID of a specific resource. 1329 * Gets the ID of a specific resource.
1330 * @param strResTypeName Identifies the resource type of the resource. 1330 * @param strResTypeName Identifies the resource type of the resource.
1331 * @param strResName Identifies the resource. 1331 * @param strResName Identifies the resource.
1332 * @return ID of the specified resource. 1332 * @return ID of the specified resource.
1333 **/ 1333 **/
1334 dword ResourceDirectory::getResourceId(const std::string& strResTypeName, const std::string& strResName) const 1334 dword ResourceDirectory::getResourceId(const std::string& strResTypeName, const std::string& strResName) const
1335 { 1335 {
1336 return getResourceIdT(strResTypeName, strResName); 1336 return getResourceIdT(strResTypeName, strResName);
1337 } 1337 }
1338 1338
1339 /** 1339 /**
1340 * Gets the ID of a specific resource by index. 1340 * Gets the ID of a specific resource by index.
1341 * @param uiResTypeIndex Identifies the resource type of the resource. 1341 * @param uiResTypeIndex Identifies the resource type of the resource.
1342 * @param uiResIndex Identifies the resource. 1342 * @param uiResIndex Identifies the resource.
1343 * @return ID of the specified resource. 1343 * @return ID of the specified resource.
1344 **/ 1344 **/
1345 dword ResourceDirectory::getResourceIdByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex) const 1345 dword ResourceDirectory::getResourceIdByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex) const
1346 { 1346 {
1347 ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiResTypeIndex].child); 1347 ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiResTypeIndex].child);
1348 return currNode->children[uiResIndex].entry.irde.Name; 1348 return currNode->children[uiResIndex].entry.irde.Name;
1349 } 1349 }
1350 1350
1351 /** 1351 /**
1352 * Sets the ID of a specific resource. 1352 * Sets the ID of a specific resource.
1353 * @param dwResTypeId Identifies the resource type of the resource. 1353 * @param dwResTypeId Identifies the resource type of the resource.
1354 * @param dwResId Identifies the resource. 1354 * @param dwResId Identifies the resource.
1355 * @param dwNewResId New ID of the resource. 1355 * @param dwNewResId New ID of the resource.
1356 **/ 1356 **/
1357 void ResourceDirectory::setResourceId(dword dwResTypeId, dword dwResId, dword dwNewResId) 1357 void ResourceDirectory::setResourceId(dword dwResTypeId, dword dwResId, dword dwNewResId)
1358 { 1358 {
1359 setResourceIdT(dwResTypeId, dwResId, dwNewResId); 1359 setResourceIdT(dwResTypeId, dwResId, dwNewResId);
1360 } 1360 }
1361 1361
1362 /** 1362 /**
1363 * Sets the ID of a specific resource. 1363 * Sets the ID of a specific resource.
1364 * @param dwResTypeId Identifies the resource type of the resource. 1364 * @param dwResTypeId Identifies the resource type of the resource.
1365 * @param strResName Identifies the resource. 1365 * @param strResName Identifies the resource.
1366 * @param dwNewResId New ID of the resource. 1366 * @param dwNewResId New ID of the resource.
1367 **/ 1367 **/
1368 void ResourceDirectory::setResourceId(dword dwResTypeId, const std::string& strResName, dword dwNewResId) 1368 void ResourceDirectory::setResourceId(dword dwResTypeId, const std::string& strResName, dword dwNewResId)
1369 { 1369 {
1370 setResourceIdT(dwResTypeId, strResName, dwNewResId); 1370 setResourceIdT(dwResTypeId, strResName, dwNewResId);
1371 } 1371 }
1372 1372
1373 /** 1373 /**
1374 * Sets the ID of a specific resource. 1374 * Sets the ID of a specific resource.
1375 * @param strResTypeName Identifies the resource type of the resource. 1375 * @param strResTypeName Identifies the resource type of the resource.
1376 * @param dwResId Identifies the resource. 1376 * @param dwResId Identifies the resource.
1377 * @param dwNewResId New ID of the resource. 1377 * @param dwNewResId New ID of the resource.
1378 **/ 1378 **/
1379 void ResourceDirectory::setResourceId(const std::string& strResTypeName, dword dwResId, dword dwNewResId) 1379 void ResourceDirectory::setResourceId(const std::string& strResTypeName, dword dwResId, dword dwNewResId)
1380 { 1380 {
1381 setResourceIdT(strResTypeName, dwResId, dwNewResId); 1381 setResourceIdT(strResTypeName, dwResId, dwNewResId);
1382 } 1382 }
1383 1383
1384 /** 1384 /**
1385 * Sets the ID of a specific resource. 1385 * Sets the ID of a specific resource.
1386 * @param strResTypeName Identifies the resource type of the resource. 1386 * @param strResTypeName Identifies the resource type of the resource.
1387 * @param strResName Identifies the resource. 1387 * @param strResName Identifies the resource.
1388 * @param dwNewResId New ID of the resource. 1388 * @param dwNewResId New ID of the resource.
1389 **/ 1389 **/
1390 void ResourceDirectory::setResourceId(const std::string& strResTypeName, const std::string& strResName, dword dwNewResId) 1390 void ResourceDirectory::setResourceId(const std::string& strResTypeName, const std::string& strResName, dword dwNewResId)
1391 { 1391 {
1392 setResourceIdT(strResTypeName, strResName, dwNewResId); 1392 setResourceIdT(strResTypeName, strResName, dwNewResId);
1393 } 1393 }
1394 1394
1395 /** 1395 /**
1396 * Sets the ID of a specific resource by index. 1396 * Sets the ID of a specific resource by index.
1397 * @param uiResTypeIndex Identifies the resource type of the resource. 1397 * @param uiResTypeIndex Identifies the resource type of the resource.
1398 * @param uiResIndex Identifies the resource. 1398 * @param uiResIndex Identifies the resource.
1399 * @param dwNewResId New ID of the specified resource. 1399 * @param dwNewResId New ID of the specified resource.
1400 **/ 1400 **/
1401 void ResourceDirectory::setResourceIdByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex, dword dwNewResId) 1401 void ResourceDirectory::setResourceIdByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex, dword dwNewResId)
1402 { 1402 {
1403 ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiResTypeIndex].child); 1403 ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiResTypeIndex].child);
1404 currNode->children[uiResIndex].entry.irde.Name = dwNewResId; 1404 currNode->children[uiResIndex].entry.irde.Name = dwNewResId;
1405 } 1405 }
1406 1406
1407 /** 1407 /**
1408 * Gets the Name of a specific resource. 1408 * Gets the Name of a specific resource.
1409 * @param dwResTypeId Identifies the resource type of the resource. 1409 * @param dwResTypeId Identifies the resource type of the resource.
1410 * @param dwResId Identifies the resource. 1410 * @param dwResId Identifies the resource.
1411 * @return Name of the specified resource. 1411 * @return Name of the specified resource.
1412 **/ 1412 **/
1413 std::string ResourceDirectory::getResourceName(dword dwResTypeId, dword dwResId) const 1413 std::string ResourceDirectory::getResourceName(dword dwResTypeId, dword dwResId) const
1414 { 1414 {
1415 return getResourceNameT(dwResTypeId, dwResId); 1415 return getResourceNameT(dwResTypeId, dwResId);
1416 } 1416 }
1417 1417
1418 /** 1418 /**
1419 * Gets the Name of a specific resource. 1419 * Gets the Name of a specific resource.
1420 * @param strResTypeName Identifies the resource type of the resource. 1420 * @param strResTypeName Identifies the resource type of the resource.
1421 * @param dwResId Identifies the resource. 1421 * @param dwResId Identifies the resource.
1422 * @return Name of the specified resource. 1422 * @return Name of the specified resource.
1423 **/ 1423 **/
1424 std::string ResourceDirectory::getResourceName(const std::string& strResTypeName, dword dwResId) const 1424 std::string ResourceDirectory::getResourceName(const std::string& strResTypeName, dword dwResId) const
1425 { 1425 {
1426 return getResourceNameT(strResTypeName, dwResId); 1426 return getResourceNameT(strResTypeName, dwResId);
1427 } 1427 }
1428 1428
1429 /** 1429 /**
1430 * Gets the name of a specific resource by index. 1430 * Gets the name of a specific resource by index.
1431 * @param uiResTypeIndex Identifies the resource type of the resource. 1431 * @param uiResTypeIndex Identifies the resource type of the resource.
1432 * @param uiResIndex Identifies the resource. 1432 * @param uiResIndex Identifies the resource.
1433 * @return Name of the specified resource. 1433 * @return Name of the specified resource.
1434 **/ 1434 **/
1435 std::string ResourceDirectory::getResourceNameByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex) const 1435 std::string ResourceDirectory::getResourceNameByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex) const
1436 { 1436 {
1437 ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiResTypeIndex].child); 1437 ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiResTypeIndex].child);
1438 return currNode->children[uiResIndex].entry.wstrName; 1438 return currNode->children[uiResIndex].entry.wstrName;
1439 } 1439 }
1440 1440
1441 /** 1441 /**
1442 * Sets the name of a specific resource. 1442 * Sets the name of a specific resource.
1443 * @param dwResTypeId Identifies the resource type of the resource. 1443 * @param dwResTypeId Identifies the resource type of the resource.
1444 * @param dwResId Identifies the resource. 1444 * @param dwResId Identifies the resource.
1445 * @param strNewResName New name of the specified resource. 1445 * @param strNewResName New name of the specified resource.
1446 **/ 1446 **/
1447 void ResourceDirectory::setResourceName(dword dwResTypeId, dword dwResId, const std::string& strNewResName) 1447 void ResourceDirectory::setResourceName(dword dwResTypeId, dword dwResId, const std::string& strNewResName)
1448 { 1448 {
1449 setResourceNameT(dwResTypeId, dwResId, strNewResName); 1449 setResourceNameT(dwResTypeId, dwResId, strNewResName);
1450 } 1450 }
1451 1451
1452 /** 1452 /**
1453 * Sets the name of a specific resource. 1453 * Sets the name of a specific resource.
1454 * @param dwResTypeId Identifies the resource type of the resource. 1454 * @param dwResTypeId Identifies the resource type of the resource.
1455 * @param strResName Identifies the resource. 1455 * @param strResName Identifies the resource.
1456 * @param strNewResName New name of the specified resource. 1456 * @param strNewResName New name of the specified resource.
1457 **/ 1457 **/
1458 void ResourceDirectory::setResourceName(dword dwResTypeId, const std::string& strResName, const std::string& strNewResName) 1458 void ResourceDirectory::setResourceName(dword dwResTypeId, const std::string& strResName, const std::string& strNewResName)
1459 { 1459 {
1460 setResourceNameT(dwResTypeId, strResName, strNewResName); 1460 setResourceNameT(dwResTypeId, strResName, strNewResName);
1461 } 1461 }
1462 1462
1463 /** 1463 /**
1464 * Sets the name of a specific resource. 1464 * Sets the name of a specific resource.
1465 * @param strResTypeName Identifies the resource type of the resource. 1465 * @param strResTypeName Identifies the resource type of the resource.
1466 * @param dwResId Identifies the resource. 1466 * @param dwResId Identifies the resource.
1467 * @param strNewResName New name of the specified resource. 1467 * @param strNewResName New name of the specified resource.
1468 **/ 1468 **/
1469 void ResourceDirectory::setResourceName(const std::string& strResTypeName, dword dwResId, const std::string& strNewResName) 1469 void ResourceDirectory::setResourceName(const std::string& strResTypeName, dword dwResId, const std::string& strNewResName)
1470 { 1470 {
1471 setResourceNameT(strResTypeName, dwResId, strNewResName); 1471 setResourceNameT(strResTypeName, dwResId, strNewResName);
1472 } 1472 }
1473 1473
1474 /** 1474 /**
1475 * Sets the name of a specific resource. 1475 * Sets the name of a specific resource.
1476 * @param strResTypeName Identifies the resource type of the resource. 1476 * @param strResTypeName Identifies the resource type of the resource.
1477 * @param strResName Identifies the resource. 1477 * @param strResName Identifies the resource.
1478 * @param strNewResName New name of the specified resource. 1478 * @param strNewResName New name of the specified resource.
1479 **/ 1479 **/
1480 void ResourceDirectory::setResourceName(const std::string& strResTypeName, const std::string& strResName, const std::string& strNewResName) 1480 void ResourceDirectory::setResourceName(const std::string& strResTypeName, const std::string& strResName, const std::string& strNewResName)
1481 { 1481 {
1482 setResourceNameT(strResTypeName, strResName, strNewResName); 1482 setResourceNameT(strResTypeName, strResName, strNewResName);
1483 } 1483 }
1484 1484
1485 /** 1485 /**
1486 * Sets the name of a specific resource by index. 1486 * Sets the name of a specific resource by index.
1487 * @param uiResTypeIndex Identifies the resource type of the resource. 1487 * @param uiResTypeIndex Identifies the resource type of the resource.
1488 * @param uiResIndex Identifies the resource. 1488 * @param uiResIndex Identifies the resource.
1489 * @param strNewResName New name of the specified resource. 1489 * @param strNewResName New name of the specified resource.
1490 **/ 1490 **/
1491 void ResourceDirectory::setResourceNameByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex, const std::string& strNewResName) 1491 void ResourceDirectory::setResourceNameByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex, const std::string& strNewResName)
1492 { 1492 {
1493 ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiResTypeIndex].child); 1493 ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiResTypeIndex].child);
1494 currNode->children[uiResIndex].entry.wstrName = strNewResName; 1494 currNode->children[uiResIndex].entry.wstrName = strNewResName;
1495 } 1495 }
1496 1496
1497} 1497}
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/ResourceDirectory.h b/utils/zenutils/libraries/pelib-0.9/pelib/ResourceDirectory.h
index a0bba4c9b3..6a3dc3caef 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/ResourceDirectory.h
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/ResourceDirectory.h
@@ -1,735 +1,735 @@
1/* 1/*
2* ResourceDirectory.cpp - Part of the PeLib library. 2* ResourceDirectory.cpp - Part of the PeLib library.
3* 3*
4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) 4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5* All rights reserved. 5* All rights reserved.
6* 6*
7* This software is licensed under the zlib/libpng License. 7* This software is licensed under the zlib/libpng License.
8* For more details see http://www.opensource.org/licenses/zlib-license.php 8* For more details see http://www.opensource.org/licenses/zlib-license.php
9* or the license information file (license.htm) in the root directory 9* or the license information file (license.htm) in the root directory
10* of PeLib. 10* of PeLib.
11*/ 11*/
12 12
13#ifndef RESOURCEDIRECTORY_H 13#ifndef RESOURCEDIRECTORY_H
14#define RESOURCEDIRECTORY_H 14#define RESOURCEDIRECTORY_H
15 15
16#include "PeLibInc.h" 16#include "PeLibInc.h"
17 17
18namespace PeLib 18namespace PeLib
19{ 19{
20 class ResourceElement; 20 class ResourceElement;
21 21
22 /// The class ResourceChild is used to store information about a resource node. 22 /// The class ResourceChild is used to store information about a resource node.
23 class ResourceChild 23 class ResourceChild
24 { 24 {
25 friend class ResourceElement; 25 friend class ResourceElement;
26 friend class ResourceDirectory; 26 friend class ResourceDirectory;
27 friend class ResourceNode; 27 friend class ResourceNode;
28 friend class ResourceLeaf; 28 friend class ResourceLeaf;
29 29
30 /// Stores name and offset of a resource node. 30 /// Stores name and offset of a resource node.
31 PELIB_IMG_RES_DIR_ENTRY entry; 31 PELIB_IMG_RES_DIR_ENTRY entry;
32 /// A pointer to one of the node's child nodes. 32 /// A pointer to one of the node's child nodes.
33 ResourceElement* child; 33 ResourceElement* child;
34 34
35 public: 35 public:
36 /// Function which compares a resource ID to the node's resource ID. 36 /// Function which compares a resource ID to the node's resource ID.
37 bool equalId(dword wId) const; // EXPORT 37 bool equalId(dword wId) const; // EXPORT
38 /// Function which compares a string to the node's resource name. 38 /// Function which compares a string to the node's resource name.
39 bool equalName(std::string strName) const; // EXPORT 39 bool equalName(std::string strName) const; // EXPORT
40 /// Predicate that determines if a child is identified by name or by ID. 40 /// Predicate that determines if a child is identified by name or by ID.
41 bool isNamedResource() const; // EXPORT 41 bool isNamedResource() const; // EXPORT
42 /// Used for sorting a node's children. 42 /// Used for sorting a node's children.
43 bool operator<(const ResourceChild& rc) const; // EXPORT 43 bool operator<(const ResourceChild& rc) const; // EXPORT
44 /// Returns the size of a resource child. 44 /// Returns the size of a resource child.
45// unsigned int size() const; 45// unsigned int size() const;
46 46
47 /// Standard constructor. Does absolutely nothing. 47 /// Standard constructor. Does absolutely nothing.
48 ResourceChild(); 48 ResourceChild();
49 /// Makes a deep copy of a ResourceChild object. 49 /// Makes a deep copy of a ResourceChild object.
50 ResourceChild(const ResourceChild& rhs); 50 ResourceChild(const ResourceChild& rhs);
51 /// Makes a deep copy of a ResourceChild object. 51 /// Makes a deep copy of a ResourceChild object.
52 ResourceChild& operator=(const ResourceChild& rhs); 52 ResourceChild& operator=(const ResourceChild& rhs);
53 /// Deletes a ResourceChild object. 53 /// Deletes a ResourceChild object.
54 ~ResourceChild(); 54 ~ResourceChild();
55 }; 55 };
56 56
57 /// Base class for ResourceNode and ResourceLeaf, the elements of the resource tree. 57 /// Base class for ResourceNode and ResourceLeaf, the elements of the resource tree.
58 /// \todo write 58 /// \todo write
59 class ResourceElement 59 class ResourceElement
60 { 60 {
61 friend class ResourceChild; 61 friend class ResourceChild;
62 friend class ResourceNode; 62 friend class ResourceNode;
63 friend class ResourceLeaf; 63 friend class ResourceLeaf;
64 64
65 protected: 65 protected:
66 /// Stores RVA of the resource element in the file. 66 /// Stores RVA of the resource element in the file.
67 unsigned int uiElementRva; 67 unsigned int uiElementRva;
68 68
69 /// Reads the next resource element from the InputBuffer. 69 /// Reads the next resource element from the InputBuffer.
70 virtual int read(InputBuffer&, unsigned int, unsigned int/*, const std::string&*/) = 0; 70 virtual int read(InputBuffer&, unsigned int, unsigned int/*, const std::string&*/) = 0;
71 /// Writes the next resource element into the OutputBuffer. 71 /// Writes the next resource element into the OutputBuffer.
72 virtual void rebuild(OutputBuffer&, unsigned int&, unsigned int, const std::string&) const = 0; 72 virtual void rebuild(OutputBuffer&, unsigned int&, unsigned int, const std::string&) const = 0;
73 73
74 public: 74 public:
75 /// Returns the RVA of the element in the file. 75 /// Returns the RVA of the element in the file.
76 unsigned int getElementRva() const; // EXPORT 76 unsigned int getElementRva() const; // EXPORT
77 /// Indicates if the resource element is a leaf or a node. 77 /// Indicates if the resource element is a leaf or a node.
78 virtual bool isLeaf() const = 0; // EXPORT 78 virtual bool isLeaf() const = 0; // EXPORT
79 /// Corrects erroneous valeus in the ResourceElement. 79 /// Corrects erroneous valeus in the ResourceElement.
80 virtual void makeValid() = 0; // EXPORT 80 virtual void makeValid() = 0; // EXPORT
81 /// Returns the size of a resource element. 81 /// Returns the size of a resource element.
82// virtual unsigned int size() const = 0; 82// virtual unsigned int size() const = 0;
83 /// Necessary virtual destructor. 83 /// Necessary virtual destructor.
84 virtual ~ResourceElement() {} 84 virtual ~ResourceElement() {}
85 }; 85 };
86 86
87 /// ResourceLeafs represent the leafs of the resource tree: The actual resources. 87 /// ResourceLeafs represent the leafs of the resource tree: The actual resources.
88 class ResourceLeaf : public ResourceElement 88 class ResourceLeaf : public ResourceElement
89 { 89 {
90 friend class ResourceChild; 90 friend class ResourceChild;
91 friend class ResourceDirectory; 91 friend class ResourceDirectory;
92 template<typename T> friend struct fixNumberOfEntries; 92 template<typename T> friend struct fixNumberOfEntries;
93 93
94 private: 94 private:
95 /// The resource data. 95 /// The resource data.
96 std::vector<byte> m_data; 96 std::vector<byte> m_data;
97 /// PeLib equivalent of the Win32 structure IMAGE_RESOURCE_DATA_ENTRY 97 /// PeLib equivalent of the Win32 structure IMAGE_RESOURCE_DATA_ENTRY
98 PELIB_IMAGE_RESOURCE_DATA_ENTRY entry; 98 PELIB_IMAGE_RESOURCE_DATA_ENTRY entry;
99 99
100 protected: 100 protected:
101 int read(InputBuffer& inpBuffer, unsigned int uiOffset, unsigned int rva/*, const std::string&*/); 101 int read(InputBuffer& inpBuffer, unsigned int uiOffset, unsigned int rva/*, const std::string&*/);
102 /// Writes the next resource leaf into the OutputBuffer. 102 /// Writes the next resource leaf into the OutputBuffer.
103 void rebuild(OutputBuffer&, unsigned int& uiOffset, unsigned int uiRva, const std::string&) const; 103 void rebuild(OutputBuffer&, unsigned int& uiOffset, unsigned int uiRva, const std::string&) const;
104 104
105 public: 105 public:
106 /// Indicates if the resource element is a leaf or a node. 106 /// Indicates if the resource element is a leaf or a node.
107 bool isLeaf() const; // EXPORT 107 bool isLeaf() const; // EXPORT
108 /// Corrects erroneous valeus in the ResourceLeaf. 108 /// Corrects erroneous valeus in the ResourceLeaf.
109 void makeValid(); // EXPORT 109 void makeValid(); // EXPORT
110 /// Reads the next resource leaf from the InputBuffer. 110 /// Reads the next resource leaf from the InputBuffer.
111 /// Returns the size of a resource lead. 111 /// Returns the size of a resource lead.
112// unsigned int size() const; 112// unsigned int size() const;
113 113
114 /// Returns the resource data of this resource leaf. 114 /// Returns the resource data of this resource leaf.
115 std::vector<byte> getData() const; // EXPORT 115 std::vector<byte> getData() const; // EXPORT
116 /// Sets the resource data of this resource leaf. 116 /// Sets the resource data of this resource leaf.
117 void setData(const std::vector<byte>& vData); // EXPORT 117 void setData(const std::vector<byte>& vData); // EXPORT
118 118
119 /// Returns the OffsetToData value of this resource leaf. 119 /// Returns the OffsetToData value of this resource leaf.
120 dword getOffsetToData() const; // EXPORT 120 dword getOffsetToData() const; // EXPORT
121 /// Returns the Size value of this resource leaf. 121 /// Returns the Size value of this resource leaf.
122 dword getSize() const; // EXPORT 122 dword getSize() const; // EXPORT
123 /// Returns the CodePage value of this resource leaf. 123 /// Returns the CodePage value of this resource leaf.
124 dword getCodePage() const; // EXPORT 124 dword getCodePage() const; // EXPORT
125 /// Returns the Reserved value of this resource leaf. 125 /// Returns the Reserved value of this resource leaf.
126 dword getReserved() const; // EXPORT 126 dword getReserved() const; // EXPORT
127 127
128 /// Sets the OffsetToData value of this resource leaf. 128 /// Sets the OffsetToData value of this resource leaf.
129 void setOffsetToData(dword dwValue); // EXPORT 129 void setOffsetToData(dword dwValue); // EXPORT
130 /// Sets the Size value of this resource leaf. 130 /// Sets the Size value of this resource leaf.
131 void setSize(dword dwValue); // EXPORT 131 void setSize(dword dwValue); // EXPORT
132 /// Sets the CodePage value of this resource leaf. 132 /// Sets the CodePage value of this resource leaf.
133 void setCodePage(dword dwValue); // EXPORT 133 void setCodePage(dword dwValue); // EXPORT
134 /// Sets the Reserved value of this resource leaf. 134 /// Sets the Reserved value of this resource leaf.
135 void setReserved(dword dwValue); // EXPORT 135 void setReserved(dword dwValue); // EXPORT
136 }; 136 };
137 137
138 /// ResourceNodes represent the nodes in the resource tree. 138 /// ResourceNodes represent the nodes in the resource tree.
139 class ResourceNode : public ResourceElement 139 class ResourceNode : public ResourceElement
140 { 140 {
141 friend class ResourceChild; 141 friend class ResourceChild;
142 friend class ResourceDirectory; 142 friend class ResourceDirectory;
143 template<typename T> friend struct fixNumberOfEntries; 143 template<typename T> friend struct fixNumberOfEntries;
144 144
145 /// The node's children. 145 /// The node's children.
146 std::vector<ResourceChild> children; 146 std::vector<ResourceChild> children;
147 /// The node's header. Equivalent to IMAGE_RESOURCE_DIRECTORY from the Win32 API. 147 /// The node's header. Equivalent to IMAGE_RESOURCE_DIRECTORY from the Win32 API.
148 PELIB_IMAGE_RESOURCE_DIRECTORY header; 148 PELIB_IMAGE_RESOURCE_DIRECTORY header;
149 149
150 protected: 150 protected:
151 /// Reads the next resource node. 151 /// Reads the next resource node.
152 int read(InputBuffer& inpBuffer, unsigned int uiOffset, unsigned int rva/*, const std::string&*/); 152 int read(InputBuffer& inpBuffer, unsigned int uiOffset, unsigned int rva/*, const std::string&*/);
153 /// Writes the next resource node into the OutputBuffer. 153 /// Writes the next resource node into the OutputBuffer.
154 void rebuild(OutputBuffer&, unsigned int& uiOffset, unsigned int uiRva, const std::string&) const; 154 void rebuild(OutputBuffer&, unsigned int& uiOffset, unsigned int uiRva, const std::string&) const;
155 155
156 public: 156 public:
157 /// Indicates if the resource element is a leaf or a node. 157 /// Indicates if the resource element is a leaf or a node.
158 bool isLeaf() const; // EXPORT 158 bool isLeaf() const; // EXPORT
159 /// Corrects erroneous valeus in the ResourceNode. 159 /// Corrects erroneous valeus in the ResourceNode.
160 void makeValid(); // EXPORT 160 void makeValid(); // EXPORT
161 161
162 /// Returns the node's number of children. 162 /// Returns the node's number of children.
163 unsigned int getNumberOfChildren() const; // EXPORT 163 unsigned int getNumberOfChildren() const; // EXPORT
164 /// Adds another child to node. 164 /// Adds another child to node.
165 void addChild(); // EXPORT 165 void addChild(); // EXPORT
166 /// Returns a node's child. 166 /// Returns a node's child.
167 ResourceElement* getChild(unsigned int uiIndex); // EXPORT 167 ResourceElement* getChild(unsigned int uiIndex); // EXPORT
168 /// Removes a node's child. 168 /// Removes a node's child.
169 void removeChild(unsigned int uiIndex); // EXPORT 169 void removeChild(unsigned int uiIndex); // EXPORT
170 170
171 /// Returns the name of one of the node's children. 171 /// Returns the name of one of the node's children.
172 std::string getChildName(unsigned int uiIndex) const; // EXPORT 172 std::string getChildName(unsigned int uiIndex) const; // EXPORT
173 /// Returns the Name value of one of the node's children. 173 /// Returns the Name value of one of the node's children.
174 dword getOffsetToChildName(unsigned int uiIndex) const; // EXPORT 174 dword getOffsetToChildName(unsigned int uiIndex) const; // EXPORT
175 /// Returns the OffsetToData value of one of the node's children. 175 /// Returns the OffsetToData value of one of the node's children.
176 dword getOffsetToChildData(unsigned int uiIndex) const; // EXPORT 176 dword getOffsetToChildData(unsigned int uiIndex) const; // EXPORT
177 177
178 /// Sets the name of one of the node's children. 178 /// Sets the name of one of the node's children.
179 void setChildName(unsigned int uiIndex, const std::string& strNewName); // EXPORT 179 void setChildName(unsigned int uiIndex, const std::string& strNewName); // EXPORT
180 /// Sets the Name value of one of the node's children. 180 /// Sets the Name value of one of the node's children.
181 void setOffsetToChildName(unsigned int uiIndex, dword dwNewOffset); // EXPORT 181 void setOffsetToChildName(unsigned int uiIndex, dword dwNewOffset); // EXPORT
182 /// Sets the OffsetToData value of one of the node's children. 182 /// Sets the OffsetToData value of one of the node's children.
183 void setOffsetToChildData(unsigned int uiIndex, dword dwNewOffset); // EXPORT 183 void setOffsetToChildData(unsigned int uiIndex, dword dwNewOffset); // EXPORT
184 184
185 /// Returns the node's Characteristics value. 185 /// Returns the node's Characteristics value.
186 dword getCharacteristics() const; // EXPORT 186 dword getCharacteristics() const; // EXPORT
187 /// Returns the node's TimeDateStamp value. 187 /// Returns the node's TimeDateStamp value.
188 dword getTimeDateStamp() const; // EXPORT 188 dword getTimeDateStamp() const; // EXPORT
189 /// Returns the node's MajorVersion value. 189 /// Returns the node's MajorVersion value.
190 word getMajorVersion() const; // EXPORT 190 word getMajorVersion() const; // EXPORT
191 /// Returns the node's MinorVersion value. 191 /// Returns the node's MinorVersion value.
192 word getMinorVersion() const; // EXPORT 192 word getMinorVersion() const; // EXPORT
193 /// Returns the node's NumberOfNamedEntries value. 193 /// Returns the node's NumberOfNamedEntries value.
194 word getNumberOfNamedEntries() const; // EXPORT 194 word getNumberOfNamedEntries() const; // EXPORT
195 /// Returns the node's NumberOfIdEntries value. 195 /// Returns the node's NumberOfIdEntries value.
196 word getNumberOfIdEntries() const; // EXPORT 196 word getNumberOfIdEntries() const; // EXPORT
197 197
198 /// Sets the node's Characteristics value. 198 /// Sets the node's Characteristics value.
199 void setCharacteristics(dword value); // EXPORT 199 void setCharacteristics(dword value); // EXPORT
200 /// Sets the node's TimeDateStamp value. 200 /// Sets the node's TimeDateStamp value.
201 void setTimeDateStamp(dword value); // EXPORT 201 void setTimeDateStamp(dword value); // EXPORT
202 /// Sets the node's MajorVersion value. 202 /// Sets the node's MajorVersion value.
203 void setMajorVersion(word value); // EXPORT 203 void setMajorVersion(word value); // EXPORT
204 /// Sets the node's MinorVersion value. 204 /// Sets the node's MinorVersion value.
205 void setMinorVersion(word value); // EXPORT 205 void setMinorVersion(word value); // EXPORT
206 /// Sets the node's NumberOfNamedEntries value. 206 /// Sets the node's NumberOfNamedEntries value.
207 void setNumberOfNamedEntries(word value); // EXPORT 207 void setNumberOfNamedEntries(word value); // EXPORT
208 /// Sets the node's NumberOfIdEntries value. 208 /// Sets the node's NumberOfIdEntries value.
209 void setNumberOfIdEntries(word value); // EXPORT 209 void setNumberOfIdEntries(word value); // EXPORT
210 210
211 /// Returns the size of a resource node. 211 /// Returns the size of a resource node.
212// unsigned int size() const; 212// unsigned int size() const;
213 }; 213 };
214 214
215 /// Auxiliary functor which is used to search through the resource tree. 215 /// Auxiliary functor which is used to search through the resource tree.
216 /** 216 /**
217 * Traits class for the template functions of ResourceDirectory. 217 * Traits class for the template functions of ResourceDirectory.
218 * It's used to find out which function to use when searching for resource nodes or resource leafs 218 * It's used to find out which function to use when searching for resource nodes or resource leafs
219 * in a node's children vector. 219 * in a node's children vector.
220 **/ 220 **/
221 template<typename T> 221 template<typename T>
222 struct ResComparer 222 struct ResComparer
223 { 223 {
224 /// Pointer to a member function of ResourceChild 224 /// Pointer to a member function of ResourceChild
225 typedef bool(ResourceChild::*CompFunc)(T) const; 225 typedef bool(ResourceChild::*CompFunc)(T) const;
226 226
227 /// Return 0 for all unspecialized versions of ResComparer. 227 /// Return 0 for all unspecialized versions of ResComparer.
228 static CompFunc comp(); 228 static CompFunc comp();
229 }; 229 };
230 230
231 /// Auxiliary functor which is used to search through the resource tree. 231 /// Auxiliary functor which is used to search through the resource tree.
232 /** 232 /**
233 * ResComparer<dword> is used when a resource element is searched for by ID. 233 * ResComparer<dword> is used when a resource element is searched for by ID.
234 **/ 234 **/
235 template<> 235 template<>
236 struct ResComparer<dword> 236 struct ResComparer<dword>
237 { 237 {
238 /// Pointer to a member function of ResourceChild 238 /// Pointer to a member function of ResourceChild
239 typedef bool(ResourceChild::*CompFunc)(dword) const; 239 typedef bool(ResourceChild::*CompFunc)(dword) const;
240 240
241 /// Return the address of the ResourceChild member function that compares the ids of resource elements. 241 /// Return the address of the ResourceChild member function that compares the ids of resource elements.
242 static CompFunc comp() 242 static CompFunc comp()
243 { 243 {
244 return &ResourceChild::equalId; 244 return &ResourceChild::equalId;
245 } 245 }
246 }; 246 };
247 247
248 /// Auxiliary functor which is used to search through the resource tree. 248 /// Auxiliary functor which is used to search through the resource tree.
249 /** 249 /**
250 * This specializd version of ResComparer is used when a resource element is searched for by name. 250 * This specializd version of ResComparer is used when a resource element is searched for by name.
251 **/ 251 **/
252 template<> 252 template<>
253 struct ResComparer<std::string> 253 struct ResComparer<std::string>
254 { 254 {
255 /// Pointer to a member function of ResourceChild 255 /// Pointer to a member function of ResourceChild
256 typedef bool(ResourceChild::*CompFunc)(std::string) const; 256 typedef bool(ResourceChild::*CompFunc)(std::string) const;
257 257
258 /// Return the address of the ResourceChild member function that compares the names of resource elements. 258 /// Return the address of the ResourceChild member function that compares the names of resource elements.
259 static CompFunc comp() 259 static CompFunc comp()
260 { 260 {
261 return &ResourceChild::equalName; 261 return &ResourceChild::equalName;
262 } 262 }
263 }; 263 };
264 264
265 /// Unspecialized function that's used as base template for the specialized versions below. 265 /// Unspecialized function that's used as base template for the specialized versions below.
266 template<typename T> 266 template<typename T>
267 struct fixNumberOfEntries 267 struct fixNumberOfEntries
268 { 268 {
269 /// Fixes a resource node's header. 269 /// Fixes a resource node's header.
270 static void fix(ResourceNode*); 270 static void fix(ResourceNode*);
271 }; 271 };
272 272
273 /// Fixes NumberOfIdEntries value of a node. 273 /// Fixes NumberOfIdEntries value of a node.
274 template<> 274 template<>
275 struct fixNumberOfEntries<dword> 275 struct fixNumberOfEntries<dword>
276 { 276 {
277 /// Fixes a resource node's NumberOfIdEntries value. 277 /// Fixes a resource node's NumberOfIdEntries value.
278 static void fix(ResourceNode* node) 278 static void fix(ResourceNode* node)
279 { 279 {
280 node->header.NumberOfIdEntries = (unsigned int)node->children.size() - std::count_if(node->children.begin(), node->children.end(), std::mem_fun_ref(&ResourceChild::isNamedResource)); 280 node->header.NumberOfIdEntries = (unsigned int)node->children.size() - std::count_if(node->children.begin(), node->children.end(), std::mem_fun_ref(&ResourceChild::isNamedResource));
281 } 281 }
282 }; 282 };
283 283
284 /// Fixes NumberOfNamedEntries value of a node. 284 /// Fixes NumberOfNamedEntries value of a node.
285 template<> 285 template<>
286 struct fixNumberOfEntries<std::string> 286 struct fixNumberOfEntries<std::string>
287 { 287 {
288 /// Fixes a resource node's NumberOfNamedEntries value. 288 /// Fixes a resource node's NumberOfNamedEntries value.
289 static void fix(ResourceNode* node) 289 static void fix(ResourceNode* node)
290 { 290 {
291 node->header.NumberOfNamedEntries = static_cast<PeLib::word>(std::count_if(node->children.begin(), node->children.end(), std::mem_fun_ref(&ResourceChild::isNamedResource))); 291 node->header.NumberOfNamedEntries = static_cast<PeLib::word>(std::count_if(node->children.begin(), node->children.end(), std::mem_fun_ref(&ResourceChild::isNamedResource)));
292 } 292 }
293 }; 293 };
294 294
295 /// Class that represents the resource directory of a PE file. 295 /// Class that represents the resource directory of a PE file.
296 /** 296 /**
297 * The class ResourceDirectory represents the resource directory of a PE file. This class is fundamentally 297 * The class ResourceDirectory represents the resource directory of a PE file. This class is fundamentally
298 * different from the other classes of the PeLib library due to the structure of the ResourceDirectory. 298 * different from the other classes of the PeLib library due to the structure of the ResourceDirectory.
299 * For once, it's possible to manipulate the ResourceDirectory through a set of "high level" functions and 299 * For once, it's possible to manipulate the ResourceDirectory through a set of "high level" functions and
300 * and through a set of "low level" functions. The "high level" functions are the functions inside the 300 * and through a set of "low level" functions. The "high level" functions are the functions inside the
301 * ResourceDirectory class with the exception of getRoot.<br><br> 301 * ResourceDirectory class with the exception of getRoot.<br><br>
302 * getRoot on the other hand is the first "low level" function. Use it to retrieve the root node of the 302 * getRoot on the other hand is the first "low level" function. Use it to retrieve the root node of the
303 * resource tree. Then you can traverse through the tree and manipulate individual nodes and leafs 303 * resource tree. Then you can traverse through the tree and manipulate individual nodes and leafs
304 * directly using the functions provided by the classes ResourceNode and ResourceLeaf.<br><br> 304 * directly using the functions provided by the classes ResourceNode and ResourceLeaf.<br><br>
305 * There's another difference between the ResourceDirectory class and the other PeLib classes, which is 305 * There's another difference between the ResourceDirectory class and the other PeLib classes, which is
306 * once again caused by the special structure of the PE resource directory. The nodes of the resource 306 * once again caused by the special structure of the PE resource directory. The nodes of the resource
307 * tree must be in a certain order. Manipulating the resource tree does not directly sort the nodes 307 * tree must be in a certain order. Manipulating the resource tree does not directly sort the nodes
308 * correctly as this would cause more trouble than it fixes. That means it's your responsibility to 308 * correctly as this would cause more trouble than it fixes. That means it's your responsibility to
309 * fix the resource tree after manipulating it. PeLib makes the job easy for you, just call the 309 * fix the resource tree after manipulating it. PeLib makes the job easy for you, just call the
310 * ResourceDirectory::makeValid function.<br><br> 310 * ResourceDirectory::makeValid function.<br><br>
311 * You might also wonder why there's no size() function in this class. I did not forget it. It's just 311 * You might also wonder why there's no size() function in this class. I did not forget it. It's just
312 * that it's impossible to calculate the size of the resource directory without rebuilding it. So why 312 * that it's impossible to calculate the size of the resource directory without rebuilding it. So why
313 * should PeLib do this if you can do it just as easily by calling rebuild() and then checking the length 313 * should PeLib do this if you can do it just as easily by calling rebuild() and then checking the length
314 * of the returned vector.<br><br> 314 * of the returned vector.<br><br>
315 * There are also different ways to serialize (rebuild) the resource tree as it's not a fixed structure 315 * There are also different ways to serialize (rebuild) the resource tree as it's not a fixed structure
316 * that can easily be minimized like most other PE directories.<br><br> 316 * that can easily be minimized like most other PE directories.<br><br>
317 * This means it's entirely possible that the resource tree you read from a file differs from the one 317 * This means it's entirely possible that the resource tree you read from a file differs from the one
318 * PeLib creates. This might cause a minor issue. The original resource tree might be smaller (due to 318 * PeLib creates. This might cause a minor issue. The original resource tree might be smaller (due to
319 * different padding) so it's crucial that you check if there's enough space in the original resource 319 * different padding) so it's crucial that you check if there's enough space in the original resource
320 * directory before you write the rebuilt resource directory back to the file. 320 * directory before you write the rebuilt resource directory back to the file.
321 **/ 321 **/
322 class ResourceDirectory 322 class ResourceDirectory
323 { 323 {
324 private: 324 private:
325 /// The root node of the resource directory. 325 /// The root node of the resource directory.
326 ResourceNode m_rnRoot; 326 ResourceNode m_rnRoot;
327 327
328 // Prepare for some crazy syntax below to make Digital Mars happy. 328 // Prepare for some crazy syntax below to make Digital Mars happy.
329 329
330 /// Retrieves an iterator to a specified resource child. 330 /// Retrieves an iterator to a specified resource child.
331 template<typename S, typename T> 331 template<typename S, typename T>
332 std::vector<ResourceChild>::const_iterator locateResourceT(S restypeid, T resid) const; 332 std::vector<ResourceChild>::const_iterator locateResourceT(S restypeid, T resid) const;
333 333
334 /// Retrieves an iterator to a specified resource child. 334 /// Retrieves an iterator to a specified resource child.
335 template<typename S, typename T> 335 template<typename S, typename T>
336 std::vector<ResourceChild>::iterator locateResourceT(S restypeid, T resid); 336 std::vector<ResourceChild>::iterator locateResourceT(S restypeid, T resid);
337 337
338 /// Adds a new resource. 338 /// Adds a new resource.
339 template<typename S, typename T> 339 template<typename S, typename T>
340 int addResourceT(S restypeid, T resid, ResourceChild& rc); 340 int addResourceT(S restypeid, T resid, ResourceChild& rc);
341 341
342 /// Removes new resource. 342 /// Removes new resource.
343 template<typename S, typename T> 343 template<typename S, typename T>
344 int removeResourceT(S restypeid, T resid); 344 int removeResourceT(S restypeid, T resid);
345 345
346 /// Returns the data of a resource. 346 /// Returns the data of a resource.
347 template<typename S, typename T> 347 template<typename S, typename T>
348 int getResourceDataT(S restypeid, T resid, std::vector<byte>& data) const; 348 int getResourceDataT(S restypeid, T resid, std::vector<byte>& data) const;
349 349
350 /// Sets the data of a resource. 350 /// Sets the data of a resource.
351 template<typename S, typename T> 351 template<typename S, typename T>
352 int setResourceDataT(S restypeid, T resid, std::vector<byte>& data); 352 int setResourceDataT(S restypeid, T resid, std::vector<byte>& data);
353 353
354 /// Returns the ID of a resource. 354 /// Returns the ID of a resource.
355 template<typename S, typename T> 355 template<typename S, typename T>
356 dword getResourceIdT(S restypeid, T resid) const; 356 dword getResourceIdT(S restypeid, T resid) const;
357 357
358 /// Sets the ID of a resource. 358 /// Sets the ID of a resource.
359 template<typename S, typename T> 359 template<typename S, typename T>
360 int setResourceIdT(S restypeid, T resid, dword dwNewResId); 360 int setResourceIdT(S restypeid, T resid, dword dwNewResId);
361 361
362 /// Returns the name of a resource. 362 /// Returns the name of a resource.
363 template<typename S, typename T> 363 template<typename S, typename T>
364 std::string getResourceNameT(S restypeid, T resid) const; 364 std::string getResourceNameT(S restypeid, T resid) const;
365 365
366 /// Sets the name of a resource. 366 /// Sets the name of a resource.
367 template<typename S, typename T> 367 template<typename S, typename T>
368 int setResourceNameT(S restypeid, T resid, std::string strNewResName); 368 int setResourceNameT(S restypeid, T resid, std::string strNewResName);
369 369
370 public: 370 public:
371 ResourceNode* getRoot(); 371 ResourceNode* getRoot();
372 /// Corrects a erroneous resource directory. 372 /// Corrects a erroneous resource directory.
373 void makeValid(); 373 void makeValid();
374 /// Reads the resource directory from a file. 374 /// Reads the resource directory from a file.
375 int read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize, unsigned int uiResDirRva); 375 int read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize, unsigned int uiResDirRva);
376 /// Rebuilds the resource directory. 376 /// Rebuilds the resource directory.
377 void rebuild(std::vector<byte>& vBuffer, unsigned int uiRva) const; 377 void rebuild(std::vector<byte>& vBuffer, unsigned int uiRva) const;
378 /// Returns the size of the rebuilt resource directory. 378 /// Returns the size of the rebuilt resource directory.
379// unsigned int size() const; 379// unsigned int size() const;
380 /// Writes the resource directory to a file. 380 /// Writes the resource directory to a file.
381 int write(const std::string& strFilename, unsigned int uiOffset, unsigned int uiRva) const; 381 int write(const std::string& strFilename, unsigned int uiOffset, unsigned int uiRva) const;
382 382
383 /// Adds a new resource type. 383 /// Adds a new resource type.
384 int addResourceType(dword dwResTypeId); 384 int addResourceType(dword dwResTypeId);
385 /// Adds a new resource type. 385 /// Adds a new resource type.
386 int addResourceType(const std::string& strResTypeName); 386 int addResourceType(const std::string& strResTypeName);
387 387
388 /// Removes a resource type and all of it's resources. 388 /// Removes a resource type and all of it's resources.
389 int removeResourceType(dword dwResTypeId); 389 int removeResourceType(dword dwResTypeId);
390 /// Removes a resource type and all of it's resources. 390 /// Removes a resource type and all of it's resources.
391 int removeResourceType(const std::string& strResTypeName); 391 int removeResourceType(const std::string& strResTypeName);
392 392
393 /// Removes a resource type and all of it's resources. 393 /// Removes a resource type and all of it's resources.
394 int removeResourceTypeByIndex(unsigned int uiIndex); 394 int removeResourceTypeByIndex(unsigned int uiIndex);
395 395
396 /// Adds a new resource. 396 /// Adds a new resource.
397 int addResource(dword dwResTypeId, dword dwResId); 397 int addResource(dword dwResTypeId, dword dwResId);
398 /// Adds a new resource. 398 /// Adds a new resource.
399 int addResource(dword dwResTypeId, const std::string& strResName); 399 int addResource(dword dwResTypeId, const std::string& strResName);
400 /// Adds a new resource. 400 /// Adds a new resource.
401 int addResource(const std::string& strResTypeName, dword dwResId); 401 int addResource(const std::string& strResTypeName, dword dwResId);
402 /// Adds a new resource. 402 /// Adds a new resource.
403 int addResource(const std::string& strResTypeName, const std::string& strResName); 403 int addResource(const std::string& strResTypeName, const std::string& strResName);
404 404
405 /// Removes a resource. 405 /// Removes a resource.
406 int removeResource(dword dwResTypeId, dword dwResId); 406 int removeResource(dword dwResTypeId, dword dwResId);
407 /// Removes a resource. 407 /// Removes a resource.
408 int removeResource(dword dwResTypeId, const std::string& strResName); 408 int removeResource(dword dwResTypeId, const std::string& strResName);
409 /// Removes a resource. 409 /// Removes a resource.
410 int removeResource(const std::string& strResTypeName, dword dwResId); 410 int removeResource(const std::string& strResTypeName, dword dwResId);
411 /// Removes a resource. 411 /// Removes a resource.
412 int removeResource(const std::string& strResTypeName, const std::string& strResName); 412 int removeResource(const std::string& strResTypeName, const std::string& strResName);
413 413
414 /// Returns the number of resource types. 414 /// Returns the number of resource types.
415 unsigned int getNumberOfResourceTypes() const; 415 unsigned int getNumberOfResourceTypes() const;
416 416
417 /// Returns the ID of a resource type. 417 /// Returns the ID of a resource type.
418 dword getResourceTypeIdByIndex(unsigned int uiIndex) const; 418 dword getResourceTypeIdByIndex(unsigned int uiIndex) const;
419 /// Returns the name of a resource type. 419 /// Returns the name of a resource type.
420 std::string getResourceTypeNameByIndex(unsigned int uiIndex) const; 420 std::string getResourceTypeNameByIndex(unsigned int uiIndex) const;
421 421
422 /// Converts a resource type ID to an index. 422 /// Converts a resource type ID to an index.
423 int resourceTypeIdToIndex(dword dwResTypeId) const; 423 int resourceTypeIdToIndex(dword dwResTypeId) const;
424 /// Converts a resource type name to an index. 424 /// Converts a resource type name to an index.
425 int resourceTypeNameToIndex(const std::string& strResTypeName) const; 425 int resourceTypeNameToIndex(const std::string& strResTypeName) const;
426 426
427 /// Returns the number of resources of a certain resource type. 427 /// Returns the number of resources of a certain resource type.
428 unsigned int getNumberOfResources(dword dwId) const; 428 unsigned int getNumberOfResources(dword dwId) const;
429 /// Returns the number of resources of a certain resource type. 429 /// Returns the number of resources of a certain resource type.
430 unsigned int getNumberOfResources(const std::string& strResTypeName) const; 430 unsigned int getNumberOfResources(const std::string& strResTypeName) const;
431 431
432 /// Returns the number of resources of a certain resource type. 432 /// Returns the number of resources of a certain resource type.
433 unsigned int getNumberOfResourcesByIndex(unsigned int uiIndex) const; 433 unsigned int getNumberOfResourcesByIndex(unsigned int uiIndex) const;
434 434
435 /// Returns the data of a certain resource. 435 /// Returns the data of a certain resource.
436 void getResourceData(dword dwResTypeId, dword dwResId, std::vector<byte>& data) const; 436 void getResourceData(dword dwResTypeId, dword dwResId, std::vector<byte>& data) const;
437 /// Returns the data of a certain resource. 437 /// Returns the data of a certain resource.
438 void getResourceData(dword dwResTypeId, const std::string& strResName, std::vector<byte>& data) const; 438 void getResourceData(dword dwResTypeId, const std::string& strResName, std::vector<byte>& data) const;
439 /// Returns the data of a certain resource. 439 /// Returns the data of a certain resource.
440 void getResourceData(const std::string& strResTypeName, dword dwResId, std::vector<byte>& data) const; 440 void getResourceData(const std::string& strResTypeName, dword dwResId, std::vector<byte>& data) const;
441 /// Returns the data of a certain resource. 441 /// Returns the data of a certain resource.
442 void getResourceData(const std::string& strResTypeName, const std::string& strResName, std::vector<byte>& data) const; 442 void getResourceData(const std::string& strResTypeName, const std::string& strResName, std::vector<byte>& data) const;
443 443
444 /// Returns the data of a certain resource. 444 /// Returns the data of a certain resource.
445 void getResourceDataByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex, std::vector<byte>& data) const; 445 void getResourceDataByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex, std::vector<byte>& data) const;
446 446
447 /// Sets the data of a certain resource. 447 /// Sets the data of a certain resource.
448 void setResourceData(dword dwResTypeId, dword dwResId, std::vector<byte>& data); 448 void setResourceData(dword dwResTypeId, dword dwResId, std::vector<byte>& data);
449 /// Sets the data of a certain resource. 449 /// Sets the data of a certain resource.
450 void setResourceData(dword dwResTypeId, const std::string& strResName, std::vector<byte>& data); 450 void setResourceData(dword dwResTypeId, const std::string& strResName, std::vector<byte>& data);
451 /// Sets the data of a certain resource. 451 /// Sets the data of a certain resource.
452 void setResourceData(const std::string& strResTypeName, dword dwResId, std::vector<byte>& data); 452 void setResourceData(const std::string& strResTypeName, dword dwResId, std::vector<byte>& data);
453 /// Sets the data of a certain resource. 453 /// Sets the data of a certain resource.
454 void setResourceData(const std::string& strResTypeName, const std::string& strResName, std::vector<byte>& data); 454 void setResourceData(const std::string& strResTypeName, const std::string& strResName, std::vector<byte>& data);
455 455
456 /// Sets the data of a certain resource. 456 /// Sets the data of a certain resource.
457 void setResourceDataByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex, std::vector<byte>& data); 457 void setResourceDataByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex, std::vector<byte>& data);
458 458
459 /// Returns the ID of a certain resource. 459 /// Returns the ID of a certain resource.
460 dword getResourceId(dword dwResTypeId, const std::string& strResName) const; 460 dword getResourceId(dword dwResTypeId, const std::string& strResName) const;
461 /// Returns the ID of a certain resource. 461 /// Returns the ID of a certain resource.
462 dword getResourceId(const std::string& strResTypeName, const std::string& strResName) const; 462 dword getResourceId(const std::string& strResTypeName, const std::string& strResName) const;
463 463
464 /// Returns the ID of a certain resource. 464 /// Returns the ID of a certain resource.
465 dword getResourceIdByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex) const; 465 dword getResourceIdByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex) const;
466 466
467 /// Sets the ID of a certain resource. 467 /// Sets the ID of a certain resource.
468 void setResourceId(dword dwResTypeId, dword dwResId, dword dwNewResId); 468 void setResourceId(dword dwResTypeId, dword dwResId, dword dwNewResId);
469 /// Sets the ID of a certain resource. 469 /// Sets the ID of a certain resource.
470 void setResourceId(dword dwResTypeId, const std::string& strResName, dword dwNewResId); 470 void setResourceId(dword dwResTypeId, const std::string& strResName, dword dwNewResId);
471 /// Sets the ID of a certain resource. 471 /// Sets the ID of a certain resource.
472 void setResourceId(const std::string& strResTypeName, dword dwResId, dword dwNewResId); 472 void setResourceId(const std::string& strResTypeName, dword dwResId, dword dwNewResId);
473 /// Sets the ID of a certain resource. 473 /// Sets the ID of a certain resource.
474 void setResourceId(const std::string& strResTypeName, const std::string& strResName, dword dwNewResId); 474 void setResourceId(const std::string& strResTypeName, const std::string& strResName, dword dwNewResId);
475 475
476 /// Sets the ID of a certain resource. 476 /// Sets the ID of a certain resource.
477 void setResourceIdByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex, dword dwNewResId); 477 void setResourceIdByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex, dword dwNewResId);
478 478
479 /// Returns the name of a certain resource. 479 /// Returns the name of a certain resource.
480 std::string getResourceName(dword dwResTypeId, dword dwResId) const; 480 std::string getResourceName(dword dwResTypeId, dword dwResId) const;
481 /// Returns the name of a certain resource. 481 /// Returns the name of a certain resource.
482 std::string getResourceName(const std::string& strResTypeName, dword dwResId) const; 482 std::string getResourceName(const std::string& strResTypeName, dword dwResId) const;
483 483
484 /// Returns the name of a certain resource. 484 /// Returns the name of a certain resource.
485 std::string getResourceNameByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex) const; 485 std::string getResourceNameByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex) const;
486 486
487 /// Sets the name of a certain resource. 487 /// Sets the name of a certain resource.
488 void setResourceName(dword dwResTypeId, dword dwResId, const std::string& strNewResName); 488 void setResourceName(dword dwResTypeId, dword dwResId, const std::string& strNewResName);
489 /// Sets the name of a certain resource. 489 /// Sets the name of a certain resource.
490 void setResourceName(dword dwResTypeId, const std::string& strResName, const std::string& strNewResName); 490 void setResourceName(dword dwResTypeId, const std::string& strResName, const std::string& strNewResName);
491 /// Sets the name of a certain resource. 491 /// Sets the name of a certain resource.
492 void setResourceName(const std::string& strResTypeName, dword dwResId, const std::string& strNewResName); 492 void setResourceName(const std::string& strResTypeName, dword dwResId, const std::string& strNewResName);
493 /// Sets the name of a certain resource. 493 /// Sets the name of a certain resource.
494 void setResourceName(const std::string& strResTypeName, const std::string& strResName, const std::string& strNewResName); 494 void setResourceName(const std::string& strResTypeName, const std::string& strResName, const std::string& strNewResName);
495 495
496 /// Sets the name of a certain resource. 496 /// Sets the name of a certain resource.
497 void setResourceNameByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex, const std::string& strNewResName); 497 void setResourceNameByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex, const std::string& strNewResName);
498 }; 498 };
499 499
500 /** 500 /**
501 * Looks through the entire resource tree and returns a const_iterator to the resource specified 501 * Looks through the entire resource tree and returns a const_iterator to the resource specified
502 * by the parameters. 502 * by the parameters.
503 * @param restypeid Identifier of the resource type (either ID or name). 503 * @param restypeid Identifier of the resource type (either ID or name).
504 * @param resid Identifier of the resource (either ID or name). 504 * @param resid Identifier of the resource (either ID or name).
505 * @return A const_iterator to the specified resource. 505 * @return A const_iterator to the specified resource.
506 **/ 506 **/
507 template<typename S, typename T> 507 template<typename S, typename T>
508 std::vector<ResourceChild>::const_iterator ResourceDirectory::locateResourceT(S restypeid, T resid) const 508 std::vector<ResourceChild>::const_iterator ResourceDirectory::locateResourceT(S restypeid, T resid) const
509 { 509 {
510 typedef bool(ResourceChild::*CompFunc1)(S) const; 510 typedef bool(ResourceChild::*CompFunc1)(S) const;
511 typedef bool(ResourceChild::*CompFunc2)(T) const; 511 typedef bool(ResourceChild::*CompFunc2)(T) const;
512 512
513 CompFunc1 comp1 = ResComparer<S>::comp(); 513 CompFunc1 comp1 = ResComparer<S>::comp();
514 CompFunc2 comp2 = ResComparer<T>::comp(); 514 CompFunc2 comp2 = ResComparer<T>::comp();
515 515
516 std::vector<ResourceChild>::const_iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(comp1), restypeid)); 516 std::vector<ResourceChild>::const_iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(comp1), restypeid));
517 if (Iter == m_rnRoot.children.end()) 517 if (Iter == m_rnRoot.children.end())
518 { 518 {
519 return Iter; 519 return Iter;
520 } 520 }
521 521
522 ResourceNode* currNode = static_cast<ResourceNode*>(Iter->child); 522 ResourceNode* currNode = static_cast<ResourceNode*>(Iter->child);
523 std::vector<ResourceChild>::const_iterator ResIter = std::find_if(currNode->children.begin(), currNode->children.end(), std::bind2nd(std::mem_fun_ref(comp2), resid)); 523 std::vector<ResourceChild>::const_iterator ResIter = std::find_if(currNode->children.begin(), currNode->children.end(), std::bind2nd(std::mem_fun_ref(comp2), resid));
524 if (ResIter == currNode->children.end()) 524 if (ResIter == currNode->children.end())
525 { 525 {
526 return ResIter; 526 return ResIter;
527 } 527 }
528 528
529 return ResIter; 529 return ResIter;
530 } 530 }
531 531
532 /** 532 /**
533 * Looks through the entire resource tree and returns an iterator to the resource specified 533 * Looks through the entire resource tree and returns an iterator to the resource specified
534 * by the parameters. 534 * by the parameters.
535 * @param restypeid Identifier of the resource type (either ID or name). 535 * @param restypeid Identifier of the resource type (either ID or name).
536 * @param resid Identifier of the resource (either ID or name). 536 * @param resid Identifier of the resource (either ID or name).
537 * @return An iterator to the specified resource. 537 * @return An iterator to the specified resource.
538 **/ 538 **/
539 template<typename S, typename T> 539 template<typename S, typename T>
540 std::vector<ResourceChild>::iterator ResourceDirectory::locateResourceT(S restypeid, T resid) 540 std::vector<ResourceChild>::iterator ResourceDirectory::locateResourceT(S restypeid, T resid)
541 { 541 {
542 typedef bool(ResourceChild::*CompFunc1)(S) const; 542 typedef bool(ResourceChild::*CompFunc1)(S) const;
543 typedef bool(ResourceChild::*CompFunc2)(T) const; 543 typedef bool(ResourceChild::*CompFunc2)(T) const;
544 544
545 CompFunc1 comp1 = ResComparer<S>::comp(); 545 CompFunc1 comp1 = ResComparer<S>::comp();
546 CompFunc2 comp2 = ResComparer<T>::comp(); 546 CompFunc2 comp2 = ResComparer<T>::comp();
547 547
548 std::vector<ResourceChild>::iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(comp1), restypeid)); 548 std::vector<ResourceChild>::iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(comp1), restypeid));
549 if (Iter == m_rnRoot.children.end()) 549 if (Iter == m_rnRoot.children.end())
550 { 550 {
551 return Iter; 551 return Iter;
552 } 552 }
553 553
554 ResourceNode* currNode = static_cast<ResourceNode*>(Iter->child); 554 ResourceNode* currNode = static_cast<ResourceNode*>(Iter->child);
555 std::vector<ResourceChild>::iterator ResIter = std::find_if(currNode->children.begin(), currNode->children.end(), std::bind2nd(std::mem_fun_ref(comp2), resid)); 555 std::vector<ResourceChild>::iterator ResIter = std::find_if(currNode->children.begin(), currNode->children.end(), std::bind2nd(std::mem_fun_ref(comp2), resid));
556 if (ResIter == currNode->children.end()) 556 if (ResIter == currNode->children.end())
557 { 557 {
558 return ResIter; 558 return ResIter;
559 } 559 }
560 560
561 return ResIter; 561 return ResIter;
562 } 562 }
563 563
564 /** 564 /**
565 * Adds a new resource, resource type and ID are specified by the parameters. 565 * Adds a new resource, resource type and ID are specified by the parameters.
566 * @param restypeid Identifier of the resource type (either ID or name). 566 * @param restypeid Identifier of the resource type (either ID or name).
567 * @param resid Identifier of the resource (either ID or name). 567 * @param resid Identifier of the resource (either ID or name).
568 * @param rc ResourceChild that will be added. 568 * @param rc ResourceChild that will be added.
569 **/ 569 **/
570 template<typename S, typename T> 570 template<typename S, typename T>
571 int ResourceDirectory::addResourceT(S restypeid, T resid, ResourceChild& rc) 571 int ResourceDirectory::addResourceT(S restypeid, T resid, ResourceChild& rc)
572 { 572 {
573 typedef bool(ResourceChild::*CompFunc1)(S) const; 573 typedef bool(ResourceChild::*CompFunc1)(S) const;
574 typedef bool(ResourceChild::*CompFunc2)(T) const; 574 typedef bool(ResourceChild::*CompFunc2)(T) const;
575 575
576 CompFunc1 comp1 = ResComparer<S>::comp(); 576 CompFunc1 comp1 = ResComparer<S>::comp();
577 CompFunc2 comp2 = ResComparer<T>::comp(); 577 CompFunc2 comp2 = ResComparer<T>::comp();
578 578
579 std::vector<ResourceChild>::iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(comp1), restypeid)); 579 std::vector<ResourceChild>::iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(comp1), restypeid));
580 if (Iter == m_rnRoot.children.end()) 580 if (Iter == m_rnRoot.children.end())
581 { 581 {
582 return 1; 582 return 1;
583 // throw Exceptions::ResourceTypeDoesNotExist(ResourceDirectoryId, __LINE__); 583 // throw Exceptions::ResourceTypeDoesNotExist(ResourceDirectoryId, __LINE__);
584 } 584 }
585 585
586 ResourceNode* currNode = static_cast<ResourceNode*>(Iter->child); 586 ResourceNode* currNode = static_cast<ResourceNode*>(Iter->child);
587 std::vector<ResourceChild>::iterator ResIter = std::find_if(currNode->children.begin(), currNode->children.end(), std::bind2nd(std::mem_fun_ref(comp2), resid)); 587 std::vector<ResourceChild>::iterator ResIter = std::find_if(currNode->children.begin(), currNode->children.end(), std::bind2nd(std::mem_fun_ref(comp2), resid));
588 if (ResIter != currNode->children.end()) 588 if (ResIter != currNode->children.end())
589 { 589 {
590 return 1; 590 return 1;
591// throw Exceptions::EntryAlreadyExists(ResourceDirectoryId, __LINE__); 591// throw Exceptions::EntryAlreadyExists(ResourceDirectoryId, __LINE__);
592 } 592 }
593 593
594 rc.child = new ResourceNode; 594 rc.child = new ResourceNode;
595 ResourceChild rlnew; 595 ResourceChild rlnew;
596 rlnew.child = new ResourceLeaf; 596 rlnew.child = new ResourceLeaf;
597 ResourceNode* currNode2 = static_cast<ResourceNode*>(rc.child); 597 ResourceNode* currNode2 = static_cast<ResourceNode*>(rc.child);
598 currNode2->children.push_back(rlnew); 598 currNode2->children.push_back(rlnew);
599 currNode->children.push_back(rc); 599 currNode->children.push_back(rc);
600 600
601 fixNumberOfEntries<T>::fix(currNode); 601 fixNumberOfEntries<T>::fix(currNode);
602 fixNumberOfEntries<T>::fix(currNode2); 602 fixNumberOfEntries<T>::fix(currNode2);
603 603
604 return 0; 604 return 0;
605 } 605 }
606 606
607 /** 607 /**
608 * Removes a resource, resource type and ID are specified by the parameters. 608 * Removes a resource, resource type and ID are specified by the parameters.
609 * @param restypeid Identifier of the resource type (either ID or name). 609 * @param restypeid Identifier of the resource type (either ID or name).
610 * @param resid Identifier of the resource (either ID or name). 610 * @param resid Identifier of the resource (either ID or name).
611 **/ 611 **/
612 template<typename S, typename T> 612 template<typename S, typename T>
613 int ResourceDirectory::removeResourceT(S restypeid, T resid) 613 int ResourceDirectory::removeResourceT(S restypeid, T resid)
614 { 614 {
615 typedef bool(ResourceChild::*CompFunc1)(S) const; 615 typedef bool(ResourceChild::*CompFunc1)(S) const;
616 typedef bool(ResourceChild::*CompFunc2)(T) const; 616 typedef bool(ResourceChild::*CompFunc2)(T) const;
617 617
618 CompFunc1 comp1 = ResComparer<S>::comp(); 618 CompFunc1 comp1 = ResComparer<S>::comp();
619 CompFunc2 comp2 = ResComparer<T>::comp(); 619 CompFunc2 comp2 = ResComparer<T>::comp();
620 620
621 std::vector<ResourceChild>::iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(comp1), restypeid)); 621 std::vector<ResourceChild>::iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(comp1), restypeid));
622 if (Iter == m_rnRoot.children.end()) 622 if (Iter == m_rnRoot.children.end())
623 { 623 {
624 return 1; 624 return 1;
625 //throw Exceptions::ResourceTypeDoesNotExist(ResourceDirectoryId, __LINE__); 625 //throw Exceptions::ResourceTypeDoesNotExist(ResourceDirectoryId, __LINE__);
626 } 626 }
627 627
628 ResourceNode* currNode = static_cast<ResourceNode*>(Iter->child); 628 ResourceNode* currNode = static_cast<ResourceNode*>(Iter->child);
629 std::vector<ResourceChild>::iterator ResIter = std::find_if(currNode->children.begin(), currNode->children.end(), std::bind2nd(std::mem_fun_ref(comp2), resid)); 629 std::vector<ResourceChild>::iterator ResIter = std::find_if(currNode->children.begin(), currNode->children.end(), std::bind2nd(std::mem_fun_ref(comp2), resid));
630 if (ResIter == currNode->children.end()) 630 if (ResIter == currNode->children.end())
631 { 631 {
632 return 1; 632 return 1;
633 // throw Exceptions::InvalidName(ResourceDirectoryId, __LINE__); 633 // throw Exceptions::InvalidName(ResourceDirectoryId, __LINE__);
634 } 634 }
635 635
636 currNode->children.erase(ResIter); 636 currNode->children.erase(ResIter);
637 637
638 fixNumberOfEntries<T>::fix(currNode); 638 fixNumberOfEntries<T>::fix(currNode);
639 639
640 return 0; 640 return 0;
641 } 641 }
642 642
643 /** 643 /**
644 * Returns the data of a resource, resource type and ID are specified by the parameters. 644 * Returns the data of a resource, resource type and ID are specified by the parameters.
645 * @param restypeid Identifier of the resource type (either ID or name). 645 * @param restypeid Identifier of the resource type (either ID or name).
646 * @param resid Identifier of the resource (either ID or name). 646 * @param resid Identifier of the resource (either ID or name).
647 * @param data The data of the resource will be written into this vector. 647 * @param data The data of the resource will be written into this vector.
648 **/ 648 **/
649 template<typename S, typename T> 649 template<typename S, typename T>
650 int ResourceDirectory::getResourceDataT(S restypeid, T resid, std::vector<byte>& data) const 650 int ResourceDirectory::getResourceDataT(S restypeid, T resid, std::vector<byte>& data) const
651 { 651 {
652 std::vector<ResourceChild>::const_iterator ResIter = locateResourceT(restypeid, resid); 652 std::vector<ResourceChild>::const_iterator ResIter = locateResourceT(restypeid, resid);
653 ResourceNode* currNode = static_cast<ResourceNode*>(ResIter->child); 653 ResourceNode* currNode = static_cast<ResourceNode*>(ResIter->child);
654 ResourceLeaf* currLeaf = static_cast<ResourceLeaf*>(currNode->children[0].child); 654 ResourceLeaf* currLeaf = static_cast<ResourceLeaf*>(currNode->children[0].child);
655 data.assign(currLeaf->m_data.begin(), currLeaf->m_data.end()); 655 data.assign(currLeaf->m_data.begin(), currLeaf->m_data.end());
656 656
657 return 0; 657 return 0;
658 } 658 }
659 659
660 /** 660 /**
661 * Sets the data of a resource, resource type and ID are specified by the parameters. 661 * Sets the data of a resource, resource type and ID are specified by the parameters.
662 * @param restypeid Identifier of the resource type (either ID or name). 662 * @param restypeid Identifier of the resource type (either ID or name).
663 * @param resid Identifier of the resource (either ID or name). 663 * @param resid Identifier of the resource (either ID or name).
664 * @param data The new data of the resource is taken from this vector. 664 * @param data The new data of the resource is taken from this vector.
665 **/ 665 **/
666 template<typename S, typename T> 666 template<typename S, typename T>
667 int ResourceDirectory::setResourceDataT(S restypeid, T resid, std::vector<byte>& data) 667 int ResourceDirectory::setResourceDataT(S restypeid, T resid, std::vector<byte>& data)
668 { 668 {
669 std::vector<ResourceChild>::iterator ResIter = locateResourceT(restypeid, resid); 669 std::vector<ResourceChild>::iterator ResIter = locateResourceT(restypeid, resid);
670 ResourceNode* currNode = static_cast<ResourceNode*>(ResIter->child); 670 ResourceNode* currNode = static_cast<ResourceNode*>(ResIter->child);
671 ResourceLeaf* currLeaf = static_cast<ResourceLeaf*>(currNode->children[0].child); 671 ResourceLeaf* currLeaf = static_cast<ResourceLeaf*>(currNode->children[0].child);
672 currLeaf->m_data.assign(data.begin(), data.end()); 672 currLeaf->m_data.assign(data.begin(), data.end());
673 673
674 return 0; 674 return 0;
675 } 675 }
676 676
677 /** 677 /**
678 * Returns the id of a resource, resource type and ID are specified by the parameters. 678 * Returns the id of a resource, resource type and ID are specified by the parameters.
679 * Note: Calling this function with resid == the ID of the resource makes no sense at all. 679 * Note: Calling this function with resid == the ID of the resource makes no sense at all.
680 * @param restypeid Identifier of the resource type (either ID or name). 680 * @param restypeid Identifier of the resource type (either ID or name).
681 * @param resid Identifier of the resource (either ID or name). 681 * @param resid Identifier of the resource (either ID or name).
682 * @return The ID of the specified resource. 682 * @return The ID of the specified resource.
683 **/ 683 **/
684 template<typename S, typename T> 684 template<typename S, typename T>
685 dword ResourceDirectory::getResourceIdT(S restypeid, T resid) const 685 dword ResourceDirectory::getResourceIdT(S restypeid, T resid) const
686 { 686 {
687 std::vector<ResourceChild>::const_iterator ResIter = locateResourceT(restypeid, resid); 687 std::vector<ResourceChild>::const_iterator ResIter = locateResourceT(restypeid, resid);
688 return ResIter->entry.irde.Name; 688 return ResIter->entry.irde.Name;
689 } 689 }
690 690
691 /** 691 /**
692 * Sets the id of a resource, resource type and ID are specified by the parameters. 692 * Sets the id of a resource, resource type and ID are specified by the parameters.
693 * @param restypeid Identifier of the resource type (either ID or name). 693 * @param restypeid Identifier of the resource type (either ID or name).
694 * @param resid Identifier of the resource (either ID or name). 694 * @param resid Identifier of the resource (either ID or name).
695 * @param dwNewResId New ID of the resource. 695 * @param dwNewResId New ID of the resource.
696 **/ 696 **/
697 template<typename S, typename T> 697 template<typename S, typename T>
698 int ResourceDirectory::setResourceIdT(S restypeid, T resid, dword dwNewResId) 698 int ResourceDirectory::setResourceIdT(S restypeid, T resid, dword dwNewResId)
699 { 699 {
700 std::vector<ResourceChild>::iterator ResIter = locateResourceT(restypeid, resid); 700 std::vector<ResourceChild>::iterator ResIter = locateResourceT(restypeid, resid);
701 ResIter->entry.irde.Name = dwNewResId; 701 ResIter->entry.irde.Name = dwNewResId;
702 return 0; 702 return 0;
703 } 703 }
704 704
705 /** 705 /**
706 * Returns the name of a resource, resource type and ID are specified by the parameters. 706 * Returns the name of a resource, resource type and ID are specified by the parameters.
707 * Note: Calling this function with resid == the name of the resource makes no sense at all. 707 * Note: Calling this function with resid == the name of the resource makes no sense at all.
708 * @param restypeid Identifier of the resource type (either ID or name). 708 * @param restypeid Identifier of the resource type (either ID or name).
709 * @param resid Identifier of the resource (either ID or name). 709 * @param resid Identifier of the resource (either ID or name).
710 * @return The name of the specified resource. 710 * @return The name of the specified resource.
711 **/ 711 **/
712 template<typename S, typename T> 712 template<typename S, typename T>
713 std::string ResourceDirectory::getResourceNameT(S restypeid, T resid) const 713 std::string ResourceDirectory::getResourceNameT(S restypeid, T resid) const
714 { 714 {
715 std::vector<ResourceChild>::const_iterator ResIter = locateResourceT(restypeid, resid); 715 std::vector<ResourceChild>::const_iterator ResIter = locateResourceT(restypeid, resid);
716 return ResIter->entry.wstrName; 716 return ResIter->entry.wstrName;
717 } 717 }
718 718
719 /** 719 /**
720 * Sets the name of a resource, resource type and ID are specified by the parameters. 720 * Sets the name of a resource, resource type and ID are specified by the parameters.
721 * @param restypeid Identifier of the resource type (either ID or name). 721 * @param restypeid Identifier of the resource type (either ID or name).
722 * @param resid Identifier of the resource (either ID or name). 722 * @param resid Identifier of the resource (either ID or name).
723 * @param strNewResName The new name of the resource. 723 * @param strNewResName The new name of the resource.
724 **/ 724 **/
725 template<typename S, typename T> 725 template<typename S, typename T>
726 int ResourceDirectory::setResourceNameT(S restypeid, T resid, std::string strNewResName) 726 int ResourceDirectory::setResourceNameT(S restypeid, T resid, std::string strNewResName)
727 { 727 {
728 std::vector<ResourceChild>::iterator ResIter = locateResourceT(restypeid, resid); 728 std::vector<ResourceChild>::iterator ResIter = locateResourceT(restypeid, resid);
729 ResIter->entry.wstrName = strNewResName; 729 ResIter->entry.wstrName = strNewResName;
730 730
731 return 0; 731 return 0;
732 } 732 }
733} 733}
734 734
735#endif 735#endif
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/TlsDirectory.h b/utils/zenutils/libraries/pelib-0.9/pelib/TlsDirectory.h
index ebea929f94..8190e65c3c 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/TlsDirectory.h
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/TlsDirectory.h
@@ -1,304 +1,304 @@
1/* 1/*
2* TlsDirectory.h - Part of the PeLib library. 2* TlsDirectory.h - Part of the PeLib library.
3* 3*
4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) 4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5* All rights reserved. 5* All rights reserved.
6* 6*
7* This software is licensed under the zlib/libpng License. 7* This software is licensed under the zlib/libpng License.
8* For more details see http://www.opensource.org/licenses/zlib-license.php 8* For more details see http://www.opensource.org/licenses/zlib-license.php
9* or the license information file (license.htm) in the root directory 9* or the license information file (license.htm) in the root directory
10* of PeLib. 10* of PeLib.
11*/ 11*/
12 12
13#ifndef TLSDIRECTORY_H 13#ifndef TLSDIRECTORY_H
14#define TLSDIRECTORY_H 14#define TLSDIRECTORY_H
15 15
16namespace PeLib 16namespace PeLib
17{ 17{
18 /// Class that handles the TLS directory. 18 /// Class that handles the TLS directory.
19 /** 19 /**
20 * This class handles the TLS (Thread Local Storage) directory. 20 * This class handles the TLS (Thread Local Storage) directory.
21 **/ 21 **/
22 template<int bits> 22 template<int bits>
23 class TlsDirectory 23 class TlsDirectory
24 { 24 {
25 private: 25 private:
26 PELIB_IMAGE_TLS_DIRECTORY<bits> m_tls; ///< Structure that holds all information about the directory. 26 PELIB_IMAGE_TLS_DIRECTORY<bits> m_tls; ///< Structure that holds all information about the directory.
27 27
28 void read(InputBuffer& inputbuffer); 28 void read(InputBuffer& inputbuffer);
29 29
30 public: 30 public:
31 /// Reads a file's TLS directory. 31 /// Reads a file's TLS directory.
32 int read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize); // EXPORT 32 int read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize); // EXPORT
33 int read(unsigned char* buffer, unsigned int buffersize); // EXPORT 33 int read(unsigned char* buffer, unsigned int buffersize); // EXPORT
34 /// Rebuilds the TLS directory. 34 /// Rebuilds the TLS directory.
35 void rebuild(std::vector<byte>& vBuffer) const; // EXPORT 35 void rebuild(std::vector<byte>& vBuffer) const; // EXPORT
36 /// Returns the size of the TLS Directory. 36 /// Returns the size of the TLS Directory.
37 unsigned int size() const; // EXPORT 37 unsigned int size() const; // EXPORT
38 /// Writes the TLS directory to a file. 38 /// Writes the TLS directory to a file.
39 int write(const std::string& strFilename, unsigned int dwOffset) const; // EXPORT 39 int write(const std::string& strFilename, unsigned int dwOffset) const; // EXPORT
40 40
41 /// Returns the StartAddressOfRawData value of the TLS header. 41 /// Returns the StartAddressOfRawData value of the TLS header.
42 dword getStartAddressOfRawData() const; // EXPORT 42 dword getStartAddressOfRawData() const; // EXPORT
43 /// Returns the EndAddressOfRawData value of the TLS header. 43 /// Returns the EndAddressOfRawData value of the TLS header.
44 dword getEndAddressOfRawData() const; // EXPORT 44 dword getEndAddressOfRawData() const; // EXPORT
45 /// Returns the AddressOfIndex value of the TLS header. 45 /// Returns the AddressOfIndex value of the TLS header.
46 dword getAddressOfIndex() const; // EXPORT 46 dword getAddressOfIndex() const; // EXPORT
47 /// Returns the AddressOfCallBacks value of the TLS header. 47 /// Returns the AddressOfCallBacks value of the TLS header.
48 dword getAddressOfCallBacks() const; // EXPORT 48 dword getAddressOfCallBacks() const; // EXPORT
49 /// Returns the SizeOfZeroFill value of the TLS header. 49 /// Returns the SizeOfZeroFill value of the TLS header.
50 dword getSizeOfZeroFill() const; // EXPORT 50 dword getSizeOfZeroFill() const; // EXPORT
51 /// Returns the Characteristics value of the TLS header. 51 /// Returns the Characteristics value of the TLS header.
52 dword getCharacteristics() const; // EXPORT 52 dword getCharacteristics() const; // EXPORT
53 53
54 /// Sets the StartAddressOfRawData value of the TLS header. 54 /// Sets the StartAddressOfRawData value of the TLS header.
55 void setStartAddressOfRawData(dword dwValue); // EXPORT 55 void setStartAddressOfRawData(dword dwValue); // EXPORT
56 /// Sets the EndAddressOfRawData value of the TLS header. 56 /// Sets the EndAddressOfRawData value of the TLS header.
57 void setEndAddressOfRawData(dword dwValue); // EXPORT 57 void setEndAddressOfRawData(dword dwValue); // EXPORT
58 /// Sets the AddressOfIndex value of the TLS header. 58 /// Sets the AddressOfIndex value of the TLS header.
59 void setAddressOfIndex(dword dwValue); // EXPORT 59 void setAddressOfIndex(dword dwValue); // EXPORT
60 /// Sets the AddressOfCallBacks value of the TLS header. 60 /// Sets the AddressOfCallBacks value of the TLS header.
61 void setAddressOfCallBacks(dword dwValue); // EXPORT 61 void setAddressOfCallBacks(dword dwValue); // EXPORT
62 /// Sets the SizeOfZeroFill value of the TLS header. 62 /// Sets the SizeOfZeroFill value of the TLS header.
63 void setSizeOfZeroFill(dword dwValue); // EXPORT 63 void setSizeOfZeroFill(dword dwValue); // EXPORT
64 /// Sets the Characteristics value of the TLS header. 64 /// Sets the Characteristics value of the TLS header.
65 void setCharacteristics(dword dwValue); // EXPORT 65 void setCharacteristics(dword dwValue); // EXPORT
66 }; 66 };
67 67
68 template<int bits> 68 template<int bits>
69 void TlsDirectory<bits>::read(InputBuffer& inputBuffer) 69 void TlsDirectory<bits>::read(InputBuffer& inputBuffer)
70 { 70 {
71 PELIB_IMAGE_TLS_DIRECTORY<bits> itdCurr; 71 PELIB_IMAGE_TLS_DIRECTORY<bits> itdCurr;
72 72
73 inputBuffer >> itdCurr.StartAddressOfRawData; 73 inputBuffer >> itdCurr.StartAddressOfRawData;
74 inputBuffer >> itdCurr.EndAddressOfRawData; 74 inputBuffer >> itdCurr.EndAddressOfRawData;
75 inputBuffer >> itdCurr.AddressOfIndex; 75 inputBuffer >> itdCurr.AddressOfIndex;
76 inputBuffer >> itdCurr.AddressOfCallBacks; 76 inputBuffer >> itdCurr.AddressOfCallBacks;
77 inputBuffer >> itdCurr.SizeOfZeroFill; 77 inputBuffer >> itdCurr.SizeOfZeroFill;
78 inputBuffer >> itdCurr.Characteristics; 78 inputBuffer >> itdCurr.Characteristics;
79 79
80 std::swap(itdCurr, m_tls); 80 std::swap(itdCurr, m_tls);
81 } 81 }
82 82
83 template<int bits> 83 template<int bits>
84 int TlsDirectory<bits>::read(unsigned char* buffer, unsigned int buffersize) 84 int TlsDirectory<bits>::read(unsigned char* buffer, unsigned int buffersize)
85 { 85 {
86 if (buffersize < PELIB_IMAGE_TLS_DIRECTORY<bits>::size()) 86 if (buffersize < PELIB_IMAGE_TLS_DIRECTORY<bits>::size())
87 { 87 {
88 return ERROR_INVALID_FILE; 88 return ERROR_INVALID_FILE;
89 } 89 }
90 90
91 std::vector<byte> vTlsDirectory(buffer, buffer + buffersize); 91 std::vector<byte> vTlsDirectory(buffer, buffer + buffersize);
92 92
93 InputBuffer ibBuffer(vTlsDirectory); 93 InputBuffer ibBuffer(vTlsDirectory);
94 read(ibBuffer); 94 read(ibBuffer);
95 return NO_ERROR; 95 return NO_ERROR;
96 } 96 }
97 97
98 /** 98 /**
99 * Reads a file's TLS directory. 99 * Reads a file's TLS directory.
100 * @param strFilename Name of the file. 100 * @param strFilename Name of the file.
101 * @param uiOffset File offset of the TLS directory. 101 * @param uiOffset File offset of the TLS directory.
102 * @param uiSize Size of the TLS directory. 102 * @param uiSize Size of the TLS directory.
103 **/ 103 **/
104 template<int bits> 104 template<int bits>
105 int TlsDirectory<bits>::read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize) 105 int TlsDirectory<bits>::read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize)
106 { 106 {
107 std::ifstream ifFile(strFilename.c_str(), std::ios::binary); 107 std::ifstream ifFile(strFilename.c_str(), std::ios::binary);
108 unsigned int ulFileSize = fileSize(ifFile); 108 unsigned int ulFileSize = fileSize(ifFile);
109 109
110 if (!ifFile) 110 if (!ifFile)
111 { 111 {
112 return ERROR_OPENING_FILE; 112 return ERROR_OPENING_FILE;
113 } 113 }
114 114
115 if (ulFileSize < uiOffset + uiSize) 115 if (ulFileSize < uiOffset + uiSize)
116 { 116 {
117 return ERROR_INVALID_FILE; 117 return ERROR_INVALID_FILE;
118 } 118 }
119 119
120 ifFile.seekg(uiOffset, std::ios::beg); 120 ifFile.seekg(uiOffset, std::ios::beg);
121 121
122 std::vector<byte> vTlsDirectory(uiSize); 122 std::vector<byte> vTlsDirectory(uiSize);
123 ifFile.read(reinterpret_cast<char*>(&vTlsDirectory[0]), uiSize); 123 ifFile.read(reinterpret_cast<char*>(&vTlsDirectory[0]), uiSize);
124 124
125 InputBuffer ibBuffer(vTlsDirectory); 125 InputBuffer ibBuffer(vTlsDirectory);
126 read(ibBuffer); 126 read(ibBuffer);
127 return NO_ERROR; 127 return NO_ERROR;
128 } 128 }
129 129
130 /** 130 /**
131 * Rebuilds the current TLS Directory. 131 * Rebuilds the current TLS Directory.
132 * @param vBuffer Buffer where the TLS directory will be written to. 132 * @param vBuffer Buffer where the TLS directory will be written to.
133 **/ 133 **/
134 template<int bits> 134 template<int bits>
135 void TlsDirectory<bits>::rebuild(std::vector<byte>& vBuffer) const 135 void TlsDirectory<bits>::rebuild(std::vector<byte>& vBuffer) const
136 { 136 {
137 OutputBuffer obBuffer(vBuffer); 137 OutputBuffer obBuffer(vBuffer);
138 138
139 obBuffer << m_tls.StartAddressOfRawData; 139 obBuffer << m_tls.StartAddressOfRawData;
140 obBuffer << m_tls.EndAddressOfRawData; 140 obBuffer << m_tls.EndAddressOfRawData;
141 obBuffer << m_tls.AddressOfIndex; 141 obBuffer << m_tls.AddressOfIndex;
142 obBuffer << m_tls.AddressOfCallBacks; 142 obBuffer << m_tls.AddressOfCallBacks;
143 obBuffer << m_tls.SizeOfZeroFill; 143 obBuffer << m_tls.SizeOfZeroFill;
144 obBuffer << m_tls.Characteristics; 144 obBuffer << m_tls.Characteristics;
145 } 145 }
146 146
147 /** 147 /**
148 * Returns the size of the TLS directory. Due to the static nature of this structure the return value 148 * Returns the size of the TLS directory. Due to the static nature of this structure the return value
149 * will always be 24. 149 * will always be 24.
150 * @return Size in bytes. 150 * @return Size in bytes.
151 **/ 151 **/
152 template<int bits> 152 template<int bits>
153 unsigned int TlsDirectory<bits>::size() const 153 unsigned int TlsDirectory<bits>::size() const
154 { 154 {
155 return PELIB_IMAGE_TLS_DIRECTORY<bits>::size(); 155 return PELIB_IMAGE_TLS_DIRECTORY<bits>::size();
156 } 156 }
157 157
158 /** 158 /**
159 * @param strFilename Name of the file. 159 * @param strFilename Name of the file.
160 * @param dwOffset File offset the TLS Directory will be written to. 160 * @param dwOffset File offset the TLS Directory will be written to.
161 **/ 161 **/
162 template<int bits> 162 template<int bits>
163 int TlsDirectory<bits>::write(const std::string& strFilename, unsigned int dwOffset) const 163 int TlsDirectory<bits>::write(const std::string& strFilename, unsigned int dwOffset) const
164 { 164 {
165 std::fstream ofFile(strFilename.c_str(), std::ios_base::in); 165 std::fstream ofFile(strFilename.c_str(), std::ios_base::in);
166 166
167 if (!ofFile) 167 if (!ofFile)
168 { 168 {
169 ofFile.clear(); 169 ofFile.clear();
170 ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary); 170 ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary);
171 } 171 }
172 else 172 else
173 { 173 {
174 ofFile.close(); 174 ofFile.close();
175 ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary); 175 ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary);
176 } 176 }
177 177
178 if (!ofFile) 178 if (!ofFile)
179 { 179 {
180 return ERROR_OPENING_FILE; 180 return ERROR_OPENING_FILE;
181 } 181 }
182 182
183 ofFile.seekp(dwOffset, std::ios::beg); 183 ofFile.seekp(dwOffset, std::ios::beg);
184 184
185 std::vector<unsigned char> vBuffer; 185 std::vector<unsigned char> vBuffer;
186 rebuild(vBuffer); 186 rebuild(vBuffer);
187 187
188 ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), vBuffer.size()); 188 ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), vBuffer.size());
189 189
190 ofFile.close(); 190 ofFile.close();
191 191
192 return NO_ERROR; 192 return NO_ERROR;
193 } 193 }
194 194
195 /** 195 /**
196 * @return The StartAddressOfRawData value of the TLS directory. 196 * @return The StartAddressOfRawData value of the TLS directory.
197 **/ 197 **/
198 template<int bits> 198 template<int bits>
199 dword TlsDirectory<bits>::getStartAddressOfRawData() const 199 dword TlsDirectory<bits>::getStartAddressOfRawData() const
200 { 200 {
201 return m_tls.StartAddressOfRawData; 201 return m_tls.StartAddressOfRawData;
202 } 202 }
203 203
204 /** 204 /**
205 * @return The EndAddressOfRawData value of the TLS directory. 205 * @return The EndAddressOfRawData value of the TLS directory.
206 **/ 206 **/
207 template<int bits> 207 template<int bits>
208 dword TlsDirectory<bits>::getEndAddressOfRawData() const 208 dword TlsDirectory<bits>::getEndAddressOfRawData() const
209 { 209 {
210 return m_tls.EndAddressOfRawData; 210 return m_tls.EndAddressOfRawData;
211 } 211 }
212 212
213 /** 213 /**
214 * @return The AddressOfIndex value of the TLS directory. 214 * @return The AddressOfIndex value of the TLS directory.
215 **/ 215 **/
216 template<int bits> 216 template<int bits>
217 dword TlsDirectory<bits>::getAddressOfIndex() const 217 dword TlsDirectory<bits>::getAddressOfIndex() const
218 { 218 {
219 return m_tls.AddressOfIndex; 219 return m_tls.AddressOfIndex;
220 } 220 }
221 221
222 /** 222 /**
223 * @return The AddressOfCallBacks value of the TLS directory. 223 * @return The AddressOfCallBacks value of the TLS directory.
224 **/ 224 **/
225 template<int bits> 225 template<int bits>
226 dword TlsDirectory<bits>::getAddressOfCallBacks() const 226 dword TlsDirectory<bits>::getAddressOfCallBacks() const
227 { 227 {
228 return m_tls.AddressOfCallBacks; 228 return m_tls.AddressOfCallBacks;
229 } 229 }
230 230
231 /** 231 /**
232 * @return The SizeOfZeroFill value of the TLS directory. 232 * @return The SizeOfZeroFill value of the TLS directory.
233 **/ 233 **/
234 template<int bits> 234 template<int bits>
235 dword TlsDirectory<bits>::getSizeOfZeroFill() const 235 dword TlsDirectory<bits>::getSizeOfZeroFill() const
236 { 236 {
237 return m_tls.SizeOfZeroFill; 237 return m_tls.SizeOfZeroFill;
238 } 238 }
239 239
240 /** 240 /**
241 * @return The Characteristics value of the TLS directory. 241 * @return The Characteristics value of the TLS directory.
242 **/ 242 **/
243 template<int bits> 243 template<int bits>
244 dword TlsDirectory<bits>::getCharacteristics() const 244 dword TlsDirectory<bits>::getCharacteristics() const
245 { 245 {
246 return m_tls.Characteristics; 246 return m_tls.Characteristics;
247 } 247 }
248 248
249 /** 249 /**
250 * @param dwValue The new StartAddressOfRawData value of the TLS directory. 250 * @param dwValue The new StartAddressOfRawData value of the TLS directory.
251 **/ 251 **/
252 template<int bits> 252 template<int bits>
253 void TlsDirectory<bits>::setStartAddressOfRawData(dword dwValue) 253 void TlsDirectory<bits>::setStartAddressOfRawData(dword dwValue)
254 { 254 {
255 m_tls.StartAddressOfRawData = dwValue; 255 m_tls.StartAddressOfRawData = dwValue;
256 } 256 }
257 257
258 /** 258 /**
259 * @param dwValue The new EndAddressOfRawData value of the TLS directory. 259 * @param dwValue The new EndAddressOfRawData value of the TLS directory.
260 **/ 260 **/
261 template<int bits> 261 template<int bits>
262 void TlsDirectory<bits>::setEndAddressOfRawData(dword dwValue) 262 void TlsDirectory<bits>::setEndAddressOfRawData(dword dwValue)
263 { 263 {
264 m_tls.EndAddressOfRawData = dwValue; 264 m_tls.EndAddressOfRawData = dwValue;
265 } 265 }
266 266
267 /** 267 /**
268 * @param dwValue The new AddressOfIndex value of the TLS directory. 268 * @param dwValue The new AddressOfIndex value of the TLS directory.
269 **/ 269 **/
270 template<int bits> 270 template<int bits>
271 void TlsDirectory<bits>::setAddressOfIndex(dword dwValue) 271 void TlsDirectory<bits>::setAddressOfIndex(dword dwValue)
272 { 272 {
273 m_tls.AddressOfIndex = dwValue; 273 m_tls.AddressOfIndex = dwValue;
274 } 274 }
275 275
276 /** 276 /**
277 * @param dwValue The new AddressOfCallBacks value of the TLS directory. 277 * @param dwValue The new AddressOfCallBacks value of the TLS directory.
278 **/ 278 **/
279 template<int bits> 279 template<int bits>
280 void TlsDirectory<bits>::setAddressOfCallBacks(dword dwValue) 280 void TlsDirectory<bits>::setAddressOfCallBacks(dword dwValue)
281 { 281 {
282 m_tls.AddressOfCallBacks = dwValue; 282 m_tls.AddressOfCallBacks = dwValue;
283 } 283 }
284 284
285 /** 285 /**
286 * @param dwValue The new SizeOfZeroFill value of the TLS directory. 286 * @param dwValue The new SizeOfZeroFill value of the TLS directory.
287 **/ 287 **/
288 template<int bits> 288 template<int bits>
289 void TlsDirectory<bits>::setSizeOfZeroFill(dword dwValue) 289 void TlsDirectory<bits>::setSizeOfZeroFill(dword dwValue)
290 { 290 {
291 m_tls.SizeOfZeroFill = dwValue; 291 m_tls.SizeOfZeroFill = dwValue;
292 } 292 }
293 293
294 /** 294 /**
295 * @param dwValue The new Characteristics value of the TLS directory. 295 * @param dwValue The new Characteristics value of the TLS directory.
296 **/ 296 **/
297 template<int bits> 297 template<int bits>
298 void TlsDirectory<bits>::setCharacteristics(dword dwValue) 298 void TlsDirectory<bits>::setCharacteristics(dword dwValue)
299 { 299 {
300 m_tls.Characteristics = dwValue; 300 m_tls.Characteristics = dwValue;
301 } 301 }
302 302
303} 303}
304#endif 304#endif
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/buffer/InputBuffer.cpp b/utils/zenutils/libraries/pelib-0.9/pelib/buffer/InputBuffer.cpp
index ae2584edb1..579b152659 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/buffer/InputBuffer.cpp
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/buffer/InputBuffer.cpp
@@ -1,58 +1,58 @@
1/* 1/*
2* InputBuffer.cpp - Part of the PeLib library. 2* InputBuffer.cpp - Part of the PeLib library.
3* 3*
4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) 4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5* All rights reserved. 5* All rights reserved.
6* 6*
7* This software is licensed under the zlib/libpng License. 7* This software is licensed under the zlib/libpng License.
8* For more details see http://www.opensource.org/licenses/zlib-license.php 8* For more details see http://www.opensource.org/licenses/zlib-license.php
9* or the license information file (license.htm) in the root directory 9* or the license information file (license.htm) in the root directory
10* of PeLib. 10* of PeLib.
11*/ 11*/
12 12
13#include "InputBuffer.h" 13#include "InputBuffer.h"
14 14
15namespace PeLib 15namespace PeLib
16{ 16{
17 unsigned long InputBuffer::get() 17 unsigned long InputBuffer::get()
18 { 18 {
19 return ulIndex; 19 return ulIndex;
20 } 20 }
21 21
22 InputBuffer::InputBuffer(std::vector<unsigned char>& vBuffer) : m_vBuffer(vBuffer), ulIndex(0) 22 InputBuffer::InputBuffer(std::vector<unsigned char>& vBuffer) : m_vBuffer(vBuffer), ulIndex(0)
23 { 23 {
24 } 24 }
25 25
26 const unsigned char* InputBuffer::data() const 26 const unsigned char* InputBuffer::data() const
27 { 27 {
28 return &m_vBuffer[0]; 28 return &m_vBuffer[0];
29 } 29 }
30 30
31 unsigned long InputBuffer::size() 31 unsigned long InputBuffer::size()
32 { 32 {
33 return static_cast<unsigned long>(m_vBuffer.size()); 33 return static_cast<unsigned long>(m_vBuffer.size());
34 } 34 }
35 35
36 void InputBuffer::read(char* lpBuffer, unsigned long ulSize) 36 void InputBuffer::read(char* lpBuffer, unsigned long ulSize)
37 { 37 {
38 std::copy(&m_vBuffer[ulIndex], &m_vBuffer[ulIndex + ulSize], lpBuffer); 38 std::copy(&m_vBuffer[ulIndex], &m_vBuffer[ulIndex + ulSize], lpBuffer);
39 ulIndex += ulSize; 39 ulIndex += ulSize;
40 } 40 }
41 41
42 void InputBuffer::reset() 42 void InputBuffer::reset()
43 { 43 {
44 m_vBuffer.clear(); 44 m_vBuffer.clear();
45 } 45 }
46 46
47 void InputBuffer::set(unsigned long ulIndex) 47 void InputBuffer::set(unsigned long ulIndex)
48 { 48 {
49 this->ulIndex = ulIndex; 49 this->ulIndex = ulIndex;
50 } 50 }
51 51
52 void InputBuffer::setBuffer(std::vector<unsigned char>& vBuffer) 52 void InputBuffer::setBuffer(std::vector<unsigned char>& vBuffer)
53 { 53 {
54 m_vBuffer = vBuffer; 54 m_vBuffer = vBuffer;
55 ulIndex = 0; 55 ulIndex = 0;
56 } 56 }
57} 57}
58 58
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/buffer/InputBuffer.h b/utils/zenutils/libraries/pelib-0.9/pelib/buffer/InputBuffer.h
index fc5a14e357..18a7b1b7bc 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/buffer/InputBuffer.h
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/buffer/InputBuffer.h
@@ -1,52 +1,52 @@
1/* 1/*
2* InputBuffer.h - Part of the PeLib library. 2* InputBuffer.h - Part of the PeLib library.
3* 3*
4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) 4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5* All rights reserved. 5* All rights reserved.
6* 6*
7* This software is licensed under the zlib/libpng License. 7* This software is licensed under the zlib/libpng License.
8* For more details see http://www.opensource.org/licenses/zlib-license.php 8* For more details see http://www.opensource.org/licenses/zlib-license.php
9* or the license information file (license.htm) in the root directory 9* or the license information file (license.htm) in the root directory
10* of PeLib. 10* of PeLib.
11*/ 11*/
12 12
13#ifndef INPUTBUFFER_H 13#ifndef INPUTBUFFER_H
14#define INPUTBUFFER_H 14#define INPUTBUFFER_H
15 15
16#include <vector> 16#include <vector>
17#include <iterator> 17#include <iterator>
18#include <cassert> 18#include <cassert>
19 19
20namespace PeLib 20namespace PeLib
21{ 21{
22 class InputBuffer 22 class InputBuffer
23 { 23 {
24 private: 24 private:
25 std::vector<unsigned char>& m_vBuffer; 25 std::vector<unsigned char>& m_vBuffer;
26 unsigned long ulIndex; 26 unsigned long ulIndex;
27 27
28 public: 28 public:
29 InputBuffer(std::vector<unsigned char>& vBuffer); 29 InputBuffer(std::vector<unsigned char>& vBuffer);
30 30
31 const unsigned char* data() const; 31 const unsigned char* data() const;
32 unsigned long size(); 32 unsigned long size();
33 33
34 template<typename T> 34 template<typename T>
35 InputBuffer& operator>>(T& value) 35 InputBuffer& operator>>(T& value)
36 { 36 {
37 assert(ulIndex + sizeof(value) <= m_vBuffer.size()); 37 assert(ulIndex + sizeof(value) <= m_vBuffer.size());
38 value = *(T*)(&m_vBuffer[ulIndex]);//reinterpret_cast<T*>(&m_vBuffer[ulIndex]); 38 value = *(T*)(&m_vBuffer[ulIndex]);//reinterpret_cast<T*>(&m_vBuffer[ulIndex]);
39 ulIndex += sizeof(T); 39 ulIndex += sizeof(T);
40 return *this; 40 return *this;
41 } 41 }
42 42
43 void read(char* lpBuffer, unsigned long ulSize); 43 void read(char* lpBuffer, unsigned long ulSize);
44 void reset(); 44 void reset();
45 void set(unsigned long ulIndex); 45 void set(unsigned long ulIndex);
46 unsigned long get(); 46 unsigned long get();
47 void setBuffer(std::vector<unsigned char>& vBuffer); 47 void setBuffer(std::vector<unsigned char>& vBuffer);
48// void updateData(unsigned long ulIndex, 48// void updateData(unsigned long ulIndex,
49 }; 49 };
50} 50}
51 51
52#endif 52#endif
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/buffer/OutputBuffer.cpp b/utils/zenutils/libraries/pelib-0.9/pelib/buffer/OutputBuffer.cpp
index b47fbb6ff8..4ad8471d83 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/buffer/OutputBuffer.cpp
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/buffer/OutputBuffer.cpp
@@ -1,41 +1,41 @@
1/* 1/*
2* OutputBuffer.cpp - Part of the PeLib library. 2* OutputBuffer.cpp - Part of the PeLib library.
3* 3*
4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) 4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5* All rights reserved. 5* All rights reserved.
6* 6*
7* This software is licensed under the zlib/libpng License. 7* This software is licensed under the zlib/libpng License.
8* For more details see http://www.opensource.org/licenses/zlib-license.php 8* For more details see http://www.opensource.org/licenses/zlib-license.php
9* or the license information file (license.htm) in the root directory 9* or the license information file (license.htm) in the root directory
10* of PeLib. 10* of PeLib.
11*/ 11*/
12 12
13#include "OutputBuffer.h" 13#include "OutputBuffer.h"
14 14
15namespace PeLib 15namespace PeLib
16{ 16{
17 OutputBuffer::OutputBuffer(std::vector<unsigned char>& vBuffer) : m_vBuffer(vBuffer) 17 OutputBuffer::OutputBuffer(std::vector<unsigned char>& vBuffer) : m_vBuffer(vBuffer)
18 { 18 {
19 m_vBuffer.clear(); 19 m_vBuffer.clear();
20 } 20 }
21 21
22 const unsigned char* OutputBuffer::data() const 22 const unsigned char* OutputBuffer::data() const
23 { 23 {
24 return &m_vBuffer[0]; 24 return &m_vBuffer[0];
25 } 25 }
26 26
27 unsigned long OutputBuffer::size() 27 unsigned long OutputBuffer::size()
28 { 28 {
29 return static_cast<unsigned long>(m_vBuffer.size()); 29 return static_cast<unsigned long>(m_vBuffer.size());
30 } 30 }
31 31
32 void OutputBuffer::add(const char* lpBuffer, unsigned long ulSize) 32 void OutputBuffer::add(const char* lpBuffer, unsigned long ulSize)
33 { 33 {
34 std::copy(lpBuffer, lpBuffer + ulSize, std::back_inserter(m_vBuffer)); 34 std::copy(lpBuffer, lpBuffer + ulSize, std::back_inserter(m_vBuffer));
35 } 35 }
36 36
37 void OutputBuffer::reset() 37 void OutputBuffer::reset()
38 { 38 {
39 m_vBuffer.clear(); 39 m_vBuffer.clear();
40 } 40 }
41} 41}
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/buffer/OutputBuffer.h b/utils/zenutils/libraries/pelib-0.9/pelib/buffer/OutputBuffer.h
index f1ab99039b..06049ddd9d 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/buffer/OutputBuffer.h
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/buffer/OutputBuffer.h
@@ -1,51 +1,51 @@
1/* 1/*
2* OutputBuffer.h - Part of the PeLib library. 2* OutputBuffer.h - Part of the PeLib library.
3* 3*
4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) 4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5* All rights reserved. 5* All rights reserved.
6* 6*
7* This software is licensed under the zlib/libpng License. 7* This software is licensed under the zlib/libpng License.
8* For more details see http://www.opensource.org/licenses/zlib-license.php 8* For more details see http://www.opensource.org/licenses/zlib-license.php
9* or the license information file (license.htm) in the root directory 9* or the license information file (license.htm) in the root directory
10* of PeLib. 10* of PeLib.
11*/ 11*/
12 12
13#ifndef OUTPUTBUFFER_H 13#ifndef OUTPUTBUFFER_H
14#define OUTPUTBUFFER_H 14#define OUTPUTBUFFER_H
15 15
16#include <vector> 16#include <vector>
17#include <iterator> 17#include <iterator>
18 18
19namespace PeLib 19namespace PeLib
20{ 20{
21 class OutputBuffer 21 class OutputBuffer
22 { 22 {
23 private: 23 private:
24 std::vector<unsigned char>& m_vBuffer; 24 std::vector<unsigned char>& m_vBuffer;
25 25
26 public: 26 public:
27 OutputBuffer(std::vector<unsigned char>& vBuffer); 27 OutputBuffer(std::vector<unsigned char>& vBuffer);
28 const unsigned char* data() const; 28 const unsigned char* data() const;
29 unsigned long size(); 29 unsigned long size();
30 30
31 template<typename T> 31 template<typename T>
32 OutputBuffer& operator<<(const T& value) 32 OutputBuffer& operator<<(const T& value)
33 { 33 {
34 const unsigned char* p = reinterpret_cast<const unsigned char*>(&value); 34 const unsigned char* p = reinterpret_cast<const unsigned char*>(&value);
35 std::copy(p, p + sizeof(value), std::back_inserter(m_vBuffer)); 35 std::copy(p, p + sizeof(value), std::back_inserter(m_vBuffer));
36 return *this; 36 return *this;
37 } 37 }
38 void add(const char* lpBuffer, unsigned long ulSize); 38 void add(const char* lpBuffer, unsigned long ulSize);
39 void reset(); 39 void reset();
40 void resize(unsigned int uiSize); 40 void resize(unsigned int uiSize);
41 void set(unsigned int uiPosition); 41 void set(unsigned int uiPosition);
42 42
43 template<typename T> 43 template<typename T>
44 void update(unsigned long ulIndex, const T& value) 44 void update(unsigned long ulIndex, const T& value)
45 { 45 {
46 *(T*)(&m_vBuffer[ulIndex]) = value; 46 *(T*)(&m_vBuffer[ulIndex]) = value;
47 } 47 }
48 }; 48 };
49} 49}
50 50
51#endif 51#endif
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/changelog.txt b/utils/zenutils/libraries/pelib-0.9/pelib/changelog.txt
index 37a7c36229..8099edf3db 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/changelog.txt
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/changelog.txt
@@ -1,321 +1,321 @@
1PeLib 0.09 alpha (February 09, 2005) 1PeLib 0.09 alpha (February 09, 2005)
2 2
3Added: 3Added:
4- Added PeHeaderT<x>::setIddBaseRelocRva(dword value) 4- Added PeHeaderT<x>::setIddBaseRelocRva(dword value)
5- Added PeHeaderT<x>::setIddBaseRelocSize(dword value) 5- Added PeHeaderT<x>::setIddBaseRelocSize(dword value)
6- Added PeHeaderT<x>::setIddArchitectureRva(dword value) 6- Added PeHeaderT<x>::setIddArchitectureRva(dword value)
7- Added PeHeaderT<x>::setIddArchitectureSize(dword value) 7- Added PeHeaderT<x>::setIddArchitectureSize(dword value)
8- Added PeHeaderT<x>::setIddComHeaderRva(dword value) 8- Added PeHeaderT<x>::setIddComHeaderRva(dword value)
9- Added PeHeaderT<x>::setIddComHeaderSize(dword value) 9- Added PeHeaderT<x>::setIddComHeaderSize(dword value)
10- Added void PeHeaderT<x>::setImageDataDirectoryRva(dword dwDirectory, dword value) 10- Added void PeHeaderT<x>::setImageDataDirectoryRva(dword dwDirectory, dword value)
11- Added void PeHeaderT<x>::setImageDataDirectorySize(dword dwDirectory, dword value) 11- Added void PeHeaderT<x>::setImageDataDirectorySize(dword dwDirectory, dword value)
12- Added bool PeHeaderT<x>::isValid() const 12- Added bool PeHeaderT<x>::isValid() const
13- Added int PeHeaderT<x>::read(const unsigned char* pcBuffer, unsigned int uiSize, unsigned int uiOffset); 13- Added int PeHeaderT<x>::read(const unsigned char* pcBuffer, unsigned int uiSize, unsigned int uiOffset);
14- Added int BoundImportDirectory::read(unsigned char* pcBuffer, unsigned int uiSize); 14- Added int BoundImportDirectory::read(unsigned char* pcBuffer, unsigned int uiSize);
15- Added int BoundImportDirectory::read(InputBuffer& inpBuffer, unsigned char* data, unsigned int dwSize); 15- Added int BoundImportDirectory::read(InputBuffer& inpBuffer, unsigned char* data, unsigned int dwSize);
16- Added unsigned int BoundImportDirectory::totalModules() 16- Added unsigned int BoundImportDirectory::totalModules()
17- Added DebugDirectory::setData to set the debug data of individual entries in the DebugDirectory. 17- Added DebugDirectory::setData to set the debug data of individual entries in the DebugDirectory.
18- Added DebugDirectory::getData to get the debug data of individual entries in the DebugDirectory. 18- Added DebugDirectory::getData to get the debug data of individual entries in the DebugDirectory.
19- Added int IatDirectory::read(unsigned char* buffer, unsigned int buffersize) 19- Added int IatDirectory::read(unsigned char* buffer, unsigned int buffersize)
20- Optimized the size and rebuild methods to avoid duplicate strings for files that appear 20- Optimized the size and rebuild methods to avoid duplicate strings for files that appear
21 more than once in the BoundImport Directory. 21 more than once in the BoundImport Directory.
22- Added two read functions to TlsDirectory and updated the return values of the old read function. 22- Added two read functions to TlsDirectory and updated the return values of the old read function.
23- Added two read functions to ComHeaderDirectory and updated the return values of the old read function. 23- Added two read functions to ComHeaderDirectory and updated the return values of the old read function.
24- Added two read functions to RelocationsDirectory and updated the return values of the old read function. 24- Added two read functions to RelocationsDirectory and updated the return values of the old read function.
25- Added void RelocationsDirectory::addRelocation() 25- Added void RelocationsDirectory::addRelocation()
26- Added void RelocationsDirectory::removeRelocation(unsigned int index) 26- Added void RelocationsDirectory::removeRelocation(unsigned int index)
27- Added void DebugDirectory::clear() 27- Added void DebugDirectory::clear()
28- Added void ExportDirectory::removeFunction(unsigned int index) 28- Added void ExportDirectory::removeFunction(unsigned int index)
29- Added void ExportDirectory::clear() 29- Added void ExportDirectory::clear()
30- Added unsigned int ExportDirectory::calcNumberOfFunctions() 30- Added unsigned int ExportDirectory::calcNumberOfFunctions()
31- Added void ExportDirectory::setAddressOfNameOrdinals(dword value) 31- Added void ExportDirectory::setAddressOfNameOrdinals(dword value)
32 32
33Bugfixes: 33Bugfixes:
34- Fixed a bug in TlsDirectory<bits>::size() 34- Fixed a bug in TlsDirectory<bits>::size()
35- Fixed a bug in PeHeaderT<64>::isValid(dword) 35- Fixed a bug in PeHeaderT<64>::isValid(dword)
36- Fixed a bug in PeHeaderT<bits>::removeDataDirectory(dword) 36- Fixed a bug in PeHeaderT<bits>::removeDataDirectory(dword)
37- Fixed a bug in BoundImportDirectory::rebuild() 37- Fixed a bug in BoundImportDirectory::rebuild()
38- Fixed a bug in BoundImportDirectory::read() (Potential buffer overflow) 38- Fixed a bug in BoundImportDirectory::read() (Potential buffer overflow)
39- Fixed a bug in BoundImportDirectory::read() (Bug caused incorrect results when reading the directory more than once) 39- Fixed a bug in BoundImportDirectory::read() (Bug caused incorrect results when reading the directory more than once)
40- Fixed a bug when reading the debug data of individual DebugDirectory entries. 40- Fixed a bug when reading the debug data of individual DebugDirectory entries.
41- Fixed a bug that caused non-existing data directories to be read (PeFile). 41- Fixed a bug that caused non-existing data directories to be read (PeFile).
42- Fixed a bug that caused problems when reading import directories that were located close to the end of the file (ImportDirectory). 42- Fixed a bug that caused problems when reading import directories that were located close to the end of the file (ImportDirectory).
43- Fixed a minor bug in PeHeader::calcSizeOfImage 43- Fixed a minor bug in PeHeader::calcSizeOfImage
44- Fixed some return values and removed all exception handling blocks. 44- Fixed some return values and removed all exception handling blocks.
45 45
46Changes: 46Changes:
47- Changed return values of PeHeader::addSection 47- Changed return values of PeHeader::addSection
48- Changed return values of PeHeader::read 48- Changed return values of PeHeader::read
49- Changed behaviour: PeHeader::m_uiOffset is initialized to 0 in default constructors. 49- Changed behaviour: PeHeader::m_uiOffset is initialized to 0 in default constructors.
50- Changed return value of BoundImportDirectory::getNumberOfModules() from int to unsigned int 50- Changed return value of BoundImportDirectory::getNumberOfModules() from int to unsigned int
51- Changed name of BoundImportDirectory::getNumberOfModules to calcNumberOfModules 51- Changed name of BoundImportDirectory::getNumberOfModules to calcNumberOfModules
52- Changed the return values of the PeFile::read* functions. 52- Changed the return values of the PeFile::read* functions.
53- Renamed IatDirectory::removeAll to IatDirectory::clear 53- Renamed IatDirectory::removeAll to IatDirectory::clear
54- Renamed IatDirectory::numberOfAddresses to IatDirectory::calcNumberOfAddresses 54- Renamed IatDirectory::numberOfAddresses to IatDirectory::calcNumberOfAddresses
55- Changed the parameter types of IatDirectory::getAddress from dword to unsigned int 55- Changed the parameter types of IatDirectory::getAddress from dword to unsigned int
56- Changed the parameter types of IatDirectory::removeAddress from dword to unsigned int 56- Changed the parameter types of IatDirectory::removeAddress from dword to unsigned int
57- All constants taken from windows.h that were redefined in PeLibAux.h now have the prefix PELIB_ to avoid 57- All constants taken from windows.h that were redefined in PeLibAux.h now have the prefix PELIB_ to avoid
58 conflicts with windows.h if both files are included to a project. 58 conflicts with windows.h if both files are included to a project.
59- Changed PELIB_IMAGE_TLS_DIRECTORY<bits>::size from an enum to a function. 59- Changed PELIB_IMAGE_TLS_DIRECTORY<bits>::size from an enum to a function.
60- Changed the name of RelocationsDirectory::getNumberOfRelocationData to calcNumberOfRelocationData 60- Changed the name of RelocationsDirectory::getNumberOfRelocationData to calcNumberOfRelocationData
61- Changed void RelocationsDirectory::removeRelocationData(unsigned int ulRelocation, word wValue) 61- Changed void RelocationsDirectory::removeRelocationData(unsigned int ulRelocation, word wValue)
62 to void RelocationsDirectory::removeRelocationData(unsigned int relocindex, unsigned int dataindex) 62 to void RelocationsDirectory::removeRelocationData(unsigned int relocindex, unsigned int dataindex)
63- Removed dword ExportDirectory::getNumberOfNameOrdinals() 63- Removed dword ExportDirectory::getNumberOfNameOrdinals()
64- Removed dword ExportDirectory::getNumberOfAddressOfFunctionNames() 64- Removed dword ExportDirectory::getNumberOfAddressOfFunctionNames()
65- Removed dword ExportDirectory::getNumberOfAddressOfFunctions() 65- Removed dword ExportDirectory::getNumberOfAddressOfFunctions()
66- Changed the parameters of some functions in ExportDirectory from dword to unsigned int. 66- Changed the parameters of some functions in ExportDirectory from dword to unsigned int.
67 67
68 68
69January 16, 2005 PeLib 0.08 alpha 69January 16, 2005 PeLib 0.08 alpha
70 70
71Added: 71Added:
72- Added std::string ExportDirectory::getNameString() 72- Added std::string ExportDirectory::getNameString()
73- Added resource type RT_MANIFEST to PeLibAux.h 73- Added resource type RT_MANIFEST to PeLibAux.h
74- Added the following functions of PeHeaderT<int x>: setIddDebugRva, setIddDebugSize, 74- Added the following functions of PeHeaderT<int x>: setIddDebugRva, setIddDebugSize,
75 setIddDelayImportRva, setIddDelayImportSize, setIddExceptionRva, setIddExceptionSize, setIddGlobalPtrRva, 75 setIddDelayImportRva, setIddDelayImportSize, setIddExceptionRva, setIddExceptionSize, setIddGlobalPtrRva,
76 setIddGlobalPtrSize, setIddIatRva, setIddIatSize, setIddLoadConfigRva, setIddLoadConfigSize, 76 setIddGlobalPtrSize, setIddIatRva, setIddIatSize, setIddLoadConfigRva, setIddLoadConfigSize,
77 setIddResourceRva, setIddResourceSize, setIddResourceRva, setIddResourceSize, setIddSecurityRva, 77 setIddResourceRva, setIddResourceSize, setIddResourceRva, setIddResourceSize, setIddSecurityRva,
78 setIddSecuritySize, setIddTlsRva, setIddTlsSize 78 setIddSecuritySize, setIddTlsRva, setIddTlsSize
79- ImportDirectory32 and ImportDirectory64 are now available. 79- ImportDirectory32 and ImportDirectory64 are now available.
80- Added ImportDirectory<bits>::setFileName(dword, currdir, const std::string&) 80- Added ImportDirectory<bits>::setFileName(dword, currdir, const std::string&)
81- Added ImportDirectory<bits>::setFirstThunk(dword, currdir, dword) 81- Added ImportDirectory<bits>::setFirstThunk(dword, currdir, dword)
82- Added ImportDirectory<bits>::setForwarderChain(dword, currdir, dword) 82- Added ImportDirectory<bits>::setForwarderChain(dword, currdir, dword)
83- Added ImportDirectory<bits>::setRvaOfName(dword, currdir, dword) 83- Added ImportDirectory<bits>::setRvaOfName(dword, currdir, dword)
84- Added ImportDirectory<bits>::setOriginalFirstThunk(dword, currdir, dword) 84- Added ImportDirectory<bits>::setOriginalFirstThunk(dword, currdir, dword)
85- Added ImportDirectory<bits>::setTimeDateStamp(dword, currdir, dword) 85- Added ImportDirectory<bits>::setTimeDateStamp(dword, currdir, dword)
86- Added ImportDirectory<bits>::setOriginalFirstThunk(dword, dword, currdir, dword) 86- Added ImportDirectory<bits>::setOriginalFirstThunk(dword, dword, currdir, dword)
87- Added ImportDirectory<bits>::setFirstThunk(dword, dword, currdir, dword) 87- Added ImportDirectory<bits>::setFirstThunk(dword, dword, currdir, dword)
88- Added ImportDirectory<bits>::setFunctionHint(dword, dword, currdir, word) 88- Added ImportDirectory<bits>::setFunctionHint(dword, dword, currdir, word)
89- Added ImportDirectory<bits>::setFunctionName(dword, dword, currdir, const std::string&) 89- Added ImportDirectory<bits>::setFunctionName(dword, dword, currdir, const std::string&)
90- Added dword BoundImportDirectory::getTimeDateStamp(dword dwBidnr, dword forwardedModule) const 90- Added dword BoundImportDirectory::getTimeDateStamp(dword dwBidnr, dword forwardedModule) const
91- Added word BoundImportDirectory::getOffsetModuleName(dword dwBidnr, dword forwardedModule) const 91- Added word BoundImportDirectory::getOffsetModuleName(dword dwBidnr, dword forwardedModule) const
92- Added word BoundImportDirectory::getNumberOfModuleForwarderRefs(dword dwBidnr, dword forwardedModule) const 92- Added word BoundImportDirectory::getNumberOfModuleForwarderRefs(dword dwBidnr, dword forwardedModule) const
93- Added std::string BoundImportDirectory::getModuleName(dword dwBidnr, dword forwardedModule) const 93- Added std::string BoundImportDirectory::getModuleName(dword dwBidnr, dword forwardedModule) const
94- Added void BoundImportDirectory::setTimeDateStamp(dword dwBidnr, dword forwardedModule, dword dwTds) 94- Added void BoundImportDirectory::setTimeDateStamp(dword dwBidnr, dword forwardedModule, dword dwTds)
95- Added void BoundImportDirectory::setOffsetModuleName(dword dwBidnr, dword forwardedModule, word wOmn) 95- Added void BoundImportDirectory::setOffsetModuleName(dword dwBidnr, dword forwardedModule, word wOmn)
96- Added void BoundImportDirectory::setNumberOfModuleForwarderRefs(dword dwBidnr, dword forwardedModule, word wMfr) 96- Added void BoundImportDirectory::setNumberOfModuleForwarderRefs(dword dwBidnr, dword forwardedModule, word wMfr)
97- Added void BoundImportDirectory::setModuleName(dword dwBidnr, dword forwardedModule, const std::string& strModuleName) 97- Added void BoundImportDirectory::setModuleName(dword dwBidnr, dword forwardedModule, const std::string& strModuleName)
98- Added word calcNumberOfModuleForwarderRefs(dword dwBidnr) const 98- Added word calcNumberOfModuleForwarderRefs(dword dwBidnr) const
99- Added void addForwardedModule(dword dwBidnr, const std::string& name, dword timeStamp = 0, word offsetModuleName = 0, word forwardedModules = 0) 99- Added void addForwardedModule(dword dwBidnr, const std::string& name, dword timeStamp = 0, word offsetModuleName = 0, word forwardedModules = 0)
100- Added void removeForwardedModule(dword dwBidnr, word forwardedModule) 100- Added void removeForwardedModule(dword dwBidnr, word forwardedModule)
101- Added PeHeaderT<x>::addDataDirectory() 101- Added PeHeaderT<x>::addDataDirectory()
102- Added PeHeaderT<x>::removeDataDirectory(dword) 102- Added PeHeaderT<x>::removeDataDirectory(dword)
103 103
104Bugfixes: 104Bugfixes:
105- Fixed a bug in MzHeader::isValid 105- Fixed a bug in MzHeader::isValid
106- Fixed a bug in PeHeaderT<x>::size() 106- Fixed a bug in PeHeaderT<x>::size()
107- Fixed a bug in PeHeaderT<x>::calcRva() 107- Fixed a bug in PeHeaderT<x>::calcRva()
108- Fixed a bug in PeHeaderT<x>::calcSizeOfImage() 108- Fixed a bug in PeHeaderT<x>::calcSizeOfImage()
109- Fixed a bug in PeHeaderT<x>::getSectionName(dword) 109- Fixed a bug in PeHeaderT<x>::getSectionName(dword)
110- Fixed a bug in PeHeaderT<x>::calcStartOfCode() 110- Fixed a bug in PeHeaderT<x>::calcStartOfCode()
111- Fixed a bug in PELIB_THUNK_DATA<bits>::bool equalHint(word wHint) const 111- Fixed a bug in PELIB_THUNK_DATA<bits>::bool equalHint(word wHint) const
112- Fixed a bug in PELIB_IMAGE_THUNK_DATA<bits>::bool equalHint(word wHint) const 112- Fixed a bug in PELIB_IMAGE_THUNK_DATA<bits>::bool equalHint(word wHint) const
113- Fixed a bug in int ImportDirectory<bits>::removeFunction(const std::string& strFilename, word wHint) 113- Fixed a bug in int ImportDirectory<bits>::removeFunction(const std::string& strFilename, word wHint)
114- Fixed a bug in int ImportDirectory<bits>::removeFile(const std::string& strFilename) 114- Fixed a bug in int ImportDirectory<bits>::removeFile(const std::string& strFilename)
115- Function hints are now properly added when rebuilding import directories. 115- Function hints are now properly added when rebuilding import directories.
116- Reading and rebuilding bound import directories now works with forwarded modules. 116- Reading and rebuilding bound import directories now works with forwarded modules.
117 117
118Changes: 118Changes:
119- Changed behaviour: Removed all exceptions from the MzHeader class. The functions work with return values now. 119- Changed behaviour: Removed all exceptions from the MzHeader class. The functions work with return values now.
120- Changed behaviour: The MzHeader::read() functions stopped checking if the MzHeader begins with "MZ". 120- Changed behaviour: The MzHeader::read() functions stopped checking if the MzHeader begins with "MZ".
121- Changed behaviour: PeHeaderT<int x>::addSection(std::string, dword) doesn't use exceptions anymore. 121- Changed behaviour: PeHeaderT<int x>::addSection(std::string, dword) doesn't use exceptions anymore.
122 Return values now indicate if the function succeeded or failed. 122 Return values now indicate if the function succeeded or failed.
123- Changed behaviour: PeHeaderT<int x>::getSectionWithOffset(dword) doesn't use exceptions anymore. 123- Changed behaviour: PeHeaderT<int x>::getSectionWithOffset(dword) doesn't use exceptions anymore.
124 Return values now indicate if the function succeeded or failed. 124 Return values now indicate if the function succeeded or failed.
125- Changed behaviour: PeHeaderT<int x>::getSectionWithRva(dword) doesn't use exceptions anymore. 125- Changed behaviour: PeHeaderT<int x>::getSectionWithRva(dword) doesn't use exceptions anymore.
126 Return values now indicate if the function succeeded or failed. 126 Return values now indicate if the function succeeded or failed.
127- Changed behaviour: PeHeaderT<int x>::rvaToOffset(dword) doesn't use exceptions anymore. 127- Changed behaviour: PeHeaderT<int x>::rvaToOffset(dword) doesn't use exceptions anymore.
128 Return values now indicate if the function succeeded or failed. 128 Return values now indicate if the function succeeded or failed.
129- Changed behaviour: PeHeaderT<int x>::write(std::string, unsigned int) doesn't use exceptions anymore. 129- Changed behaviour: PeHeaderT<int x>::write(std::string, unsigned int) doesn't use exceptions anymore.
130 Return values now indicate if the function succeeded or failed. 130 Return values now indicate if the function succeeded or failed.
131- Changed behaviour: PeHeaderT<int x>::writeSectionData(const std::string& strFilename, word wSecnr, 131- Changed behaviour: PeHeaderT<int x>::writeSectionData(const std::string& strFilename, word wSecnr,
132 const std::vector<byte>& vBuffer) doesn't use exceptions anymore. 132 const std::vector<byte>& vBuffer) doesn't use exceptions anymore.
133 Return values now indicate if the function succeeded or failed. 133 Return values now indicate if the function succeeded or failed.
134- Changed behaviour: PeHeaderT<int x>::writeSections(std::string) doesn't use exceptions anymore. 134- Changed behaviour: PeHeaderT<int x>::writeSections(std::string) doesn't use exceptions anymore.
135 Return values now indicate if the function succeeded or failed. 135 Return values now indicate if the function succeeded or failed.
136- Changed behaviour: Return value of PeHeaderT<x>::calcSpaceAfterHeader() changed from unsigned long 136- Changed behaviour: Return value of PeHeaderT<x>::calcSpaceAfterHeader() changed from unsigned long
137 to unsigned int. 137 to unsigned int.
138- Changed behaviour: Return value of PeHeaderT<x>::calcStartOfCode() changed from unsigned long 138- Changed behaviour: Return value of PeHeaderT<x>::calcStartOfCode() changed from unsigned long
139 to unsigned int. 139 to unsigned int.
140- Changed behaviour: Return value of PeHeaderT<x>::calcOffset() changed from unsigned long 140- Changed behaviour: Return value of PeHeaderT<x>::calcOffset() changed from unsigned long
141 to unsigned int. 141 to unsigned int.
142- Changed behaviour: Return value of PeHeaderT<x>::offsetToRva(dword) changed from unsigned long 142- Changed behaviour: Return value of PeHeaderT<x>::offsetToRva(dword) changed from unsigned long
143 to unsigned int. 143 to unsigned int.
144- Changed behaviour: Return value of PeHeaderT<x>::offsetToVa(dword) changed from unsigned long 144- Changed behaviour: Return value of PeHeaderT<x>::offsetToVa(dword) changed from unsigned long
145 to unsigned int. 145 to unsigned int.
146- Renamed ExportDirectory::setName(std::string) to ExportDirectory::setNameString(std::string) 146- Renamed ExportDirectory::setName(std::string) to ExportDirectory::setNameString(std::string)
147- Renamed the PeHeaderT::getId* functions to PeHeaderT::getIdd* 147- Renamed the PeHeaderT::getId* functions to PeHeaderT::getIdd*
148- Renamed PeHeaderT::getImageDirectoryRva to PeHeaderT::getImageDataDirectoryRva 148- Renamed PeHeaderT::getImageDirectoryRva to PeHeaderT::getImageDataDirectoryRva
149- Renamed PeHeaderT::getImageDirectorySize to PeHeaderT::getImageDataDirectorySize 149- Renamed PeHeaderT::getImageDirectorySize to PeHeaderT::getImageDataDirectorySize
150- Renamed void PeHeaderT<x>::setWinVersionValue(dword dwValue) to void PeHeaderT<x>::setWin32VersionValue(dword dwValue) 150- Renamed void PeHeaderT<x>::setWinVersionValue(dword dwValue) to void PeHeaderT<x>::setWin32VersionValue(dword dwValue)
151- Renamed the following functions of PeHeaderT<int x>: setIdImportRva to setIddImportRva, 151- Renamed the following functions of PeHeaderT<int x>: setIdImportRva to setIddImportRva,
152 setIdImportSize to setIddImportSize, setIdExportRva to setIddExportRva, setIdExportSize to setIddExportSize 152 setIdImportSize to setIddImportSize, setIdExportRva to setIddExportRva, setIdExportSize to setIddExportSize
153- Renamed dword ImportDirectory<bits>::getName to dword ImportDirectory<bits>::getRvaOfName 153- Renamed dword ImportDirectory<bits>::getName to dword ImportDirectory<bits>::getRvaOfName
154- Changed behaviour: All removeFunction and removeFile functions from ImportDirectory.h return int instead 154- Changed behaviour: All removeFunction and removeFile functions from ImportDirectory.h return int instead
155 of void now. 155 of void now.
156- Changed behavior: ResourceDirectory::resourceTypeNameToIndex returns int instead of unsigned int. 156- Changed behavior: ResourceDirectory::resourceTypeNameToIndex returns int instead of unsigned int.
157 157
158------------------------------------------------------------------------------------------------------------- 158-------------------------------------------------------------------------------------------------------------
159 159
160July 18, 2004 PeLib 0.07 alpha 160July 18, 2004 PeLib 0.07 alpha
161 161
162Added: 162Added:
163- Full support of the PE+ format. 163- Full support of the PE+ format.
164- ImportDirectory::getName(string, currdir) 164- ImportDirectory::getName(string, currdir)
165- ImportDirectory::getFirstThunk(dword, currdir) 165- ImportDirectory::getFirstThunk(dword, currdir)
166- ImportDirectory::getOriginalFirstThunk(dword, currdir) 166- ImportDirectory::getOriginalFirstThunk(dword, currdir)
167- ImportDirectory::getForwarderChain(dword, currdir) 167- ImportDirectory::getForwarderChain(dword, currdir)
168- ImportDirectory::getName(dword, currdir) 168- ImportDirectory::getName(dword, currdir)
169- ImportDirectory::getTimeDateStamp(dword, currdir) 169- ImportDirectory::getTimeDateStamp(dword, currdir)
170- PeLib::getFileType(string) 170- PeLib::getFileType(string)
171- PeLib::openPeFile(string) 171- PeLib::openPeFile(string)
172- Added class PeFileVisitor 172- Added class PeFileVisitor
173- Added PeFile::visit(PeFileVisitor&) 173- Added PeFile::visit(PeFileVisitor&)
174 174
175Bugfixes: 175Bugfixes:
176- Fixed a bug in PeHeader::rvaToOffset 176- Fixed a bug in PeHeader::rvaToOffset
177 177
178Changes: 178Changes:
179- Renamed ImportDirectory::OLD to PeLib::OLDDIR and ImportDirectory::NEW to PeLib::NEWDIR 179- Renamed ImportDirectory::OLD to PeLib::OLDDIR and ImportDirectory::NEW to PeLib::NEWDIR
180- Renamed Relocations to RelocationsDirectory 180- Renamed Relocations to RelocationsDirectory
181- Renamed ImportAddressTable to IatDirectory 181- Renamed ImportAddressTable to IatDirectory
182- Renamed ComDescriptor to ComHeader 182- Renamed ComDescriptor to ComHeader
183- Renamed PeFile::comDescDir to PeFile::comDir 183- Renamed PeFile::comDescDir to PeFile::comDir
184- Changed unsigned long ExportDirectory::getFunctionIndex to unsigned int ExportDirectory::getFunctionIndex 184- Changed unsigned long ExportDirectory::getFunctionIndex to unsigned int ExportDirectory::getFunctionIndex
185 185
186------------------------------------------------------------------------------------------------------------- 186-------------------------------------------------------------------------------------------------------------
187 187
188July 4, 2004 PeLib 0.06 alpha 188July 4, 2004 PeLib 0.06 alpha
189 189
190Added: 190Added:
191- TlsDirectory class 191- TlsDirectory class
192 192
193Changes: 193Changes:
194- ResourceElement::read and ResourceElement::rebuild are now protected. 194- ResourceElement::read and ResourceElement::rebuild are now protected.
195 195
196Bugfixes: 196Bugfixes:
197- Fixed a bug in PeHeader::rvaToOffset 197- Fixed a bug in PeHeader::rvaToOffset
198 198
199------------------------------------------------------------------------------------------------------------- 199-------------------------------------------------------------------------------------------------------------
200 200
201June 26, 2004 PeLib 0.05 alpha 201June 26, 2004 PeLib 0.05 alpha
202 202
203Added: 203Added:
204- Constructor, Copy constructor, assignment operator and destructor for ResourceChild. 204- Constructor, Copy constructor, assignment operator and destructor for ResourceChild.
205- ResourceDirectory::getRoot() 205- ResourceDirectory::getRoot()
206- ResourceElement::isLeaf() 206- ResourceElement::isLeaf()
207- ResourceElement::getElementRva 207- ResourceElement::getElementRva
208- 10 new functions in ResourceLeaf. 208- 10 new functions in ResourceLeaf.
209- 22 new functions in ResourceNode. 209- 22 new functions in ResourceNode.
210- Added the RT_* constants which identify resource types to PeLibAux.h 210- Added the RT_* constants which identify resource types to PeLibAux.h
211- Added a new example (examples/ResourceTree) which shows how to use low level ResourceDirectory functions. 211- Added a new example (examples/ResourceTree) which shows how to use low level ResourceDirectory functions.
212- Added PELIB_IMAGE_DEBUG_DIRECTORY and PELIB_IMG_DEBUG_DIRECTORY 212- Added PELIB_IMAGE_DEBUG_DIRECTORY and PELIB_IMG_DEBUG_DIRECTORY
213- Added the new class DebugDirectory which handles the debug directory of PE files. 213- Added the new class DebugDirectory which handles the debug directory of PE files.
214- Added readDebugDirectory() and debugDir() to PeFile. 214- Added readDebugDirectory() and debugDir() to PeFile.
215 215
216Removed: 216Removed:
217- ~ResourceNode() 217- ~ResourceNode()
218 218
219------------------------------------------------------------------------------------------------------------- 219-------------------------------------------------------------------------------------------------------------
220 220
221June 12, 2004 PeLib 0.04 alpha 221June 12, 2004 PeLib 0.04 alpha
222 222
223New: 223New:
224- Finally implemented the class ResourceDirectory. That means lots of new functions I won't explicitly list here. 224- Finally implemented the class ResourceDirectory. That means lots of new functions I won't explicitly list here.
225 Check the documentation. 225 Check the documentation.
226 226
227Removed: 227Removed:
228- The files buffer/ResTree.cpp and buffer/ResTree.h are obsolete and were removed. 228- The files buffer/ResTree.cpp and buffer/ResTree.h are obsolete and were removed.
229 229
230Bugfixes: 230Bugfixes:
231- Fixed PeHeader::calcStartOfCode 231- Fixed PeHeader::calcStartOfCode
232- Fixed PeHeader::getSectionWithRva 232- Fixed PeHeader::getSectionWithRva
233 233
234Changes: 234Changes:
235- Changed PeHeader::read to throw an exception if the NT signature is not 'PE'\0\0 235- Changed PeHeader::read to throw an exception if the NT signature is not 'PE'\0\0
236- Changed the 2nd parameter of void MzHeader::read(unsigned char*, unsigned long) from unsigned long to unsigned int. 236- Changed the 2nd parameter of void MzHeader::read(unsigned char*, unsigned long) from unsigned long to unsigned int.
237- Changed the return value of MzHeader::size from long to int. 237- Changed the return value of MzHeader::size from long to int.
238- Changed parameters of MzHeader::getReservedWords1, MzHeader::getReservedWords2, MzHeader::setReservedWords1 and 238- Changed parameters of MzHeader::getReservedWords1, MzHeader::getReservedWords2, MzHeader::setReservedWords1 and
239 MzHeader::setReservedWords2 from long to int. 239 MzHeader::setReservedWords2 from long to int.
240- Changed MzHeader::read(std::string) to MzHeader::read(const std::string&) 240- Changed MzHeader::read(std::string) to MzHeader::read(const std::string&)
241- Changed return value of BoundImportDirectory::getModuleIndex from long to int. 241- Changed return value of BoundImportDirectory::getModuleIndex from long to int.
242- Changed return value of BoundImportDirectory::size from long to int. 242- Changed return value of BoundImportDirectory::size from long to int.
243- Changed return value of ComDescriptor::size from long to int. 243- Changed return value of ComDescriptor::size from long to int.
244- Changed return value of ImportAddressTable::size from long to int. 244- Changed return value of ImportAddressTable::size from long to int.
245- Changed return value of Relocations::getNumberOfRelocations from long to int. 245- Changed return value of Relocations::getNumberOfRelocations from long to int.
246- Changed return value of Relocations::getNumberOfRelocationData from long to int. 246- Changed return value of Relocations::getNumberOfRelocationData from long to int.
247- Changed return value of Relocations::size from long to int. 247- Changed return value of Relocations::size from long to int.
248- Changed parameter of Relocations::getVirtualAddress from long to int. 248- Changed parameter of Relocations::getVirtualAddress from long to int.
249- Changed parameter of Relocations::getSizeOfBlock from long to int. 249- Changed parameter of Relocations::getSizeOfBlock from long to int.
250- Changed parameter of Relocations::getRelocationData from long to int. 250- Changed parameter of Relocations::getRelocationData from long to int.
251- Changed parameters of Relocations::setRelocationData from long to int. 251- Changed parameters of Relocations::setRelocationData from long to int.
252- Changed parameters of Relocations::setVirtualAddress from long to int. 252- Changed parameters of Relocations::setVirtualAddress from long to int.
253- Changed parameters of Relocations::setSizeOfBlock from long to int. 253- Changed parameters of Relocations::setSizeOfBlock from long to int.
254- Changed parameters of Relocations::addRelocationData from long to int. 254- Changed parameters of Relocations::addRelocationData from long to int.
255- Changed parameters of Relocations::removeRelocationData from long to int. 255- Changed parameters of Relocations::removeRelocationData from long to int.
256- Changed return value of ExportDirectory::getFunctionIndex(const std::string&) const from unsigned int to int. 256- Changed return value of ExportDirectory::getFunctionIndex(const std::string&) const from unsigned int to int.
257 257
258------------------------------------------------------------------------------------------------------------- 258-------------------------------------------------------------------------------------------------------------
259 259
260May 31, 2004: PeLib 0.03 alpha 260May 31, 2004: PeLib 0.03 alpha
261 261
262Bugfixes: 262Bugfixes:
263- Fixed some bugs in FileDump.cpp 263- Fixed some bugs in FileDump.cpp
264 264
265Changes: 265Changes:
266- Modified PeLibAux.cpp to make PeLib VC++ 7.1 compatible. 266- Modified PeLibAux.cpp to make PeLib VC++ 7.1 compatible.
267- Changed vector access from .at to operator[] all over the project. 267- Changed vector access from .at to operator[] all over the project.
268 Real undefined behaviour is probably better than spontaniously terminating applications. 268 Real undefined behaviour is probably better than spontaniously terminating applications.
269 269
270New: 270New:
271- Added makefiles for Borland C++ commandline tools (tested on version 5.6.4) 271- Added makefiles for Borland C++ commandline tools (tested on version 5.6.4)
272- Added makefiles for Digital Mars Compiler (tested on version 8.38n) 272- Added makefiles for Digital Mars Compiler (tested on version 8.38n)
273 Note that support for DMC is not yet complete. PeLib compiles though, the examples don't yet but the 273 Note that support for DMC is not yet complete. PeLib compiles though, the examples don't yet but the
274 reason for this is that I am unable to correctly specifiy the PeLib object files when compiling. 274 reason for this is that I am unable to correctly specifiy the PeLib object files when compiling.
275- Added makefiles for Visual C++ 7.1 (tested on compiler Version 13.10.3052) 275- Added makefiles for Visual C++ 7.1 (tested on compiler Version 13.10.3052)
276 276
277------------------------------------------------------------------------------------------------------------- 277-------------------------------------------------------------------------------------------------------------
278 278
279Mai 1, 2004: PeLib 0.02 alpha 279Mai 1, 2004: PeLib 0.02 alpha
280 280
281Bugfixes: 281Bugfixes:
282- Fixed a bug in FileDump's and OON2's makefile.g++ 282- Fixed a bug in FileDump's and OON2's makefile.g++
283- Fixed ImportDirectory::size 283- Fixed ImportDirectory::size
284- Changed parameter of PELIB_THUNK_DATA::equalHint from dword to word 284- Changed parameter of PELIB_THUNK_DATA::equalHint from dword to word
285- Fixed a bug in PeHeader::read (PeLib always assumed 0x10 data directories in version 0.01 alpha) 285- Fixed a bug in PeHeader::read (PeLib always assumed 0x10 data directories in version 0.01 alpha)
286 286
287Changes: 287Changes:
288- Slightly changed ImportDirectory::removeFile (Changed function's signature) 288- Slightly changed ImportDirectory::removeFile (Changed function's signature)
289- Moved the definitions of byte, word and dword into the PeLib namespace. 289- Moved the definitions of byte, word and dword into the PeLib namespace.
290- Renamed PELIB_THUNK_DATA::equalName to PELIB_THUNK_DATA::equalFunctionName 290- Renamed PELIB_THUNK_DATA::equalName to PELIB_THUNK_DATA::equalFunctionName
291- Started to add size() functions to structs defined in PeLibAux.h 291- Started to add size() functions to structs defined in PeLibAux.h
292- Moved PeFile::writeSectionData to PeHeader::writeSectionData 292- Moved PeFile::writeSectionData to PeHeader::writeSectionData
293- Moved PeFile::writeSections to PeHeader::writeSections 293- Moved PeFile::writeSections to PeHeader::writeSections
294 294
295New: 295New:
296- Added ImportDirectory::hasFunction 296- Added ImportDirectory::hasFunction
297- Wrote BoundImportDirectory::size 297- Wrote BoundImportDirectory::size
298- Added accumulate function to PeLibAux.h 298- Added accumulate function to PeLibAux.h
299- Added PELIB_IMAGE_SECTION_HEADER::biggerFileOffset 299- Added PELIB_IMAGE_SECTION_HEADER::biggerFileOffset
300- Added PELIB_IMAGE_SECTION_HEADER::biggerVirtualAddress 300- Added PELIB_IMAGE_SECTION_HEADER::biggerVirtualAddress
301- Added PeHeader::calcSizeOfImage 301- Added PeHeader::calcSizeOfImage
302- Added PeHeader::enlargeLastSection 302- Added PeHeader::enlargeLastSection
303 303
304Removed: 304Removed:
305- Removed PeFile::write 305- Removed PeFile::write
306- Removed PeFile::writeImportDirectory 306- Removed PeFile::writeImportDirectory
307 307
308Other changes: 308Other changes:
309- Rewrote parts of ImportDirectory::read 309- Rewrote parts of ImportDirectory::read
310- Rewrote ImportDirectory::removeFunction (both version). 310- Rewrote ImportDirectory::removeFunction (both version).
311- Changed std::ios:: to std::ios_base:: in ImportDirectory 311- Changed std::ios:: to std::ios_base:: in ImportDirectory
312- Changed ImportDirectory::addFunction (both versions) 312- Changed ImportDirectory::addFunction (both versions)
313- Changed ExportDirectory::rebuild 313- Changed ExportDirectory::rebuild
314- Changed ExportDirectory::size 314- Changed ExportDirectory::size
315- Rewrote ImportDirectory::size 315- Rewrote ImportDirectory::size
316- Rewrote PeHeader::size 316- Rewrote PeHeader::size
317- Rewrote ComDescriptor::size 317- Rewrote ComDescriptor::size
318 318
319------------------------------------------------------------------------------------------------------------- 319-------------------------------------------------------------------------------------------------------------
320 320
321April 9, 2004: PeLib 0.01 alpha Initial release \ No newline at end of file 321April 9, 2004: PeLib 0.01 alpha Initial release \ No newline at end of file
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/license.htm b/utils/zenutils/libraries/pelib-0.9/pelib/license.htm
index 2978aa7920..74f3b5a83c 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/license.htm
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/license.htm
@@ -1,35 +1,35 @@
1<html> 1<html>
2<body> 2<body>
3<h1>The zlib/libpng License</h1> 3<h1>The zlib/libpng License</h1>
4 4
5<tt> 5<tt>
6 6
7<p>Copyright (c) 2004 - Sebastian Porst</p> 7<p>Copyright (c) 2004 - Sebastian Porst</p>
8 8
9 <p>This software is provided 'as-is', without any express or implied 9 <p>This software is provided 'as-is', without any express or implied
10 warranty. In no event will the authors be held liable for any damages 10 warranty. In no event will the authors be held liable for any damages
11 arising from the use of this software.</p> 11 arising from the use of this software.</p>
12 12
13 <p>Permission is granted to anyone to use this software for any purpose, 13 <p>Permission is granted to anyone to use this software for any purpose,
14 including commercial applications, and to alter it and redistribute it 14 including commercial applications, and to alter it and redistribute it
15 freely, subject to the following restrictions:</p> 15 freely, subject to the following restrictions:</p>
16 16
17<blockquote> 17<blockquote>
18 18
19 <p>1. The origin of this software must not be misrepresented; you must not 19 <p>1. The origin of this software must not be misrepresented; you must not
20 claim that you wrote the original software. If you use this software 20 claim that you wrote the original software. If you use this software
21 in a product, an acknowledgment in the product documentation would be 21 in a product, an acknowledgment in the product documentation would be
22 appreciated but is not required.</p> 22 appreciated but is not required.</p>
23 23
24 <p>2. Altered source versions must be plainly marked as such, and must not be 24 <p>2. Altered source versions must be plainly marked as such, and must not be
25 misrepresented as being the original software.</p> 25 misrepresented as being the original software.</p>
26 26
27 <p>3. This notice may not be removed or altered from any source 27 <p>3. This notice may not be removed or altered from any source
28 distribution.</p> 28 distribution.</p>
29 29
30</blockquote> 30</blockquote>
31 31
32</tt> 32</tt>
33 33
34</body> 34</body>
35</html> \ No newline at end of file 35</html> \ No newline at end of file
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/readme.txt b/utils/zenutils/libraries/pelib-0.9/pelib/readme.txt
index b26a3e5287..65f289a8fe 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/readme.txt
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/readme.txt
@@ -1,44 +1,44 @@
1PeLib - Version 0.09 (alpha release) 1PeLib - Version 0.09 (alpha release)
2========================================= 2=========================================
3 3
4Copyright 2004 by Sebastian Porst 4Copyright 2004 by Sebastian Porst
5WWW: http://www.pelib.com 5WWW: http://www.pelib.com
6E-Mail: webmaster@the-interweb.com 6E-Mail: webmaster@the-interweb.com
7 7
8========================================= 8=========================================
9 9
101. What is PeLib? 101. What is PeLib?
112. Where can I find a documentation of PeLib DLL? 112. Where can I find a documentation of PeLib DLL?
123. Which license is used for PeLib? 123. Which license is used for PeLib?
134. Which compilers are being supported? 134. Which compilers are being supported?
145. How do I compile PeLib? 145. How do I compile PeLib?
15 15
161. What is PeLib DLL? 161. What is PeLib DLL?
17 PeLib is an open-source C++ library to modify 17 PeLib is an open-source C++ library to modify
18 PE files. See http://www.pelib.com for more details. 18 PE files. See http://www.pelib.com for more details.
19 19
202. Where can I find a documentation of PeLib DLL? 202. Where can I find a documentation of PeLib DLL?
21 http://www.pelib.com 21 http://www.pelib.com
22 22
233. All parts of PeLib are distributed under the zlib/libpng license. 233. All parts of PeLib are distributed under the zlib/libpng license.
24 See license.htm for details. 24 See license.htm for details.
25 25
264. The following compilers have been tested: 264. The following compilers have been tested:
27 MingW with g++ 3.2.3 27 MingW with g++ 3.2.3
28 Visual C++ 7.1 / Compiler version 13.10.3052 28 Visual C++ 7.1 / Compiler version 13.10.3052
29 Borland C++ 5.6.4 (currently not supported) 29 Borland C++ 5.6.4 (currently not supported)
30 Digital Mars Compiler 8.38n (currently not supported) 30 Digital Mars Compiler 8.38n (currently not supported)
31 31
325. Go into the PeLib/source directory and enter the following lines 325. Go into the PeLib/source directory and enter the following lines
33 depending on which compiler you use. 33 depending on which compiler you use.
34 34
35 g++: make -f makefile.g++ 35 g++: make -f makefile.g++
36 Borland C++: make -f makefile.bcc (currently not supported) 36 Borland C++: make -f makefile.bcc (currently not supported)
37 Visual C++ 7.1: nmake makefile.vc7 37 Visual C++ 7.1: nmake makefile.vc7
38 Digital Mars: make makefile.dmc (currently not supported) 38 Digital Mars: make makefile.dmc (currently not supported)
39 39
40 If the compilation is succesful there should be some *.o/*.obj files 40 If the compilation is succesful there should be some *.o/*.obj files
41 and (if you used g++) a PeLib.a file in the lib directory. 41 and (if you used g++) a PeLib.a file in the lib directory.
42 Then go to the examples directory and pick one example (I 42 Then go to the examples directory and pick one example (I
43 suggest FileDump) and try to build it with the same make 43 suggest FileDump) and try to build it with the same make
44 command as above. \ No newline at end of file 44 command as above. \ No newline at end of file