Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages

PeHeader.h

00001 /* 00002 * PeHeader.h - Part of the PeLib library. 00003 * 00004 * Copyright (c) 2004 Sebastian Porst (webmaster@the-interweb.com) 00005 * All rights reserved. 00006 * 00007 * This software is licensed under the zlib/libpng License. 00008 * For more details see http://www.opensource.org/licenses/zlib-license.php 00009 * or the license information file (license.htm) in the root directory 00010 * of PeLib. 00011 */ 00012 00013 #ifndef PEHEADER_H 00014 #define PEHEADER_H 00015 00016 #include "PeLibAux.h" 00017 00018 namespace PeLib 00019 { 00020 class PeHeader 00021 { 00022 protected: 00023 virtual void readBaseOfData(InputBuffer& ibBuffer) = 0; 00024 virtual void rebuildBaseOfData(OutputBuffer& obBuffer) const = 0; 00025 00026 public: 00027 virtual ~PeHeader(); 00028 }; 00029 00031 00037 template<int x> 00038 class PeHeaderT : public PeHeader 00039 { 00040 protected: 00041 std::vector<PELIB_IMAGE_SECTION_HEADER> m_vIsh; 00042 PELIB_IMAGE_NT_HEADERS<x> m_inthHeader; 00043 dword m_uiOffset; 00044 00045 public: 00046 typedef typename FieldSizes<x>::VAR4_8 VAR4_8; 00047 00049 int addSection(const std::string& strName, dword dwSize); 00050 00051 unsigned int calcSizeOfImage() const; 00052 00054 unsigned int calcSpaceAfterHeader() const; 00055 00057 unsigned int calcStartOfCode() const; 00058 00060 unsigned int calcOffset(/*unsigned int uiSize*/) const; 00061 00063 unsigned int calcRva(/*unsigned int uiSize*/) const; 00064 00066 word calcNumberOfSections() const; 00067 00068 void enlargeLastSection(unsigned int uiSize); 00069 00071 word getSectionWithOffset(VAR4_8 dwOffset) const; 00072 00074 word getSectionWithRva(VAR4_8 rva) const; 00075 00076 bool isValid(unsigned int) const; 00077 00079 void makeValid(dword dwOffset); 00080 00082 unsigned int offsetToRva(VAR4_8 dwOffset) const; 00083 00085 unsigned int offsetToVa(VAR4_8 dwOffset) const; 00086 00088 int read(std::string strFilename, unsigned int uiOffset); 00089 00091 void rebuild(std::vector<byte>& vBuffer) const; 00092 00094 typename FieldSizes<x>::VAR4_8 rvaToOffset(VAR4_8 dwRva) const; 00095 00097 typename FieldSizes<x>::VAR4_8 rvaToVa(VAR4_8 dwRva) const; 00098 00100 unsigned int size() const; 00101 00102 typename FieldSizes<x>::VAR4_8 vaToRva(VAR4_8 dwRva) const; 00103 typename FieldSizes<x>::VAR4_8 vaToOffset(VAR4_8 dwRva) const; 00104 00106 int write(std::string strFilename, unsigned int uiOffset) const; 00107 00109 int writeSections(const std::string& strFilename) const; 00111 int writeSectionData(const std::string& strFilename, word wSecnr, const std::vector<byte>& vBuffer) const; 00112 00113 // header getters 00115 dword getNtSignature() const; 00117 word getMachine() const; 00119 word getNumberOfSections() const; 00121 dword getTimeDateStamp() const; 00123 dword getPointerToSymbolTable() const; 00125 dword getNumberOfSymbols() const; 00127 word getSizeOfOptionalHeader() const; 00129 word getCharacteristics() const; 00130 00132 word getMagic() const; 00134 byte getMajorLinkerVersion() const; 00136 byte getMinorLinkerVersion() const; 00138 dword getSizeOfCode() const; 00140 dword getSizeOfInitializedData() const; 00142 dword getSizeOfUninitializedData() const; 00144 dword getAddressOfEntryPoint() const; 00146 dword getBaseOfCode() const; 00148 VAR4_8 getImageBase() const; 00150 dword getSectionAlignment() const; 00152 dword getFileAlignment() const; 00154 word getMajorOperatingSystemVersion() const; 00156 word getMinorOperatingSystemVersion() const; 00158 word getMajorImageVersion() const; 00160 word getMinorImageVersion() const; 00162 word getMajorSubsystemVersion() const; 00164 word getMinorSubsystemVersion() const; 00166 dword getWin32VersionValue() const; 00168 dword getSizeOfImage() const; 00170 dword getSizeOfHeaders() const; 00172 dword getCheckSum() const; 00174 word getSubsystem() const; 00176 word getDllCharacteristics() const; 00178 VAR4_8 getSizeOfStackReserve() const; 00180 VAR4_8 getSizeOfStackCommit() const; 00182 VAR4_8 getSizeOfHeapReserve() const; 00184 VAR4_8 getSizeOfHeapCommit() const; 00186 dword getLoaderFlags() const; 00188 dword getNumberOfRvaAndSizes() const; 00189 dword calcNumberOfRvaAndSizes() const; 00190 00191 void addDataDirectory(); 00192 void removeDataDirectory(dword index); 00193 00194 // image directory getters 00196 dword getIddExportRva() const; 00198 dword getIddExportSize() const; 00200 dword getIddImportRva() const; 00202 dword getIddImportSize() const; 00204 dword getIddResourceRva() const; 00206 dword getIddResourceSize() const; 00208 dword getIddExceptionRva() const; 00210 dword getIddExceptionSize() const; 00212 dword getIddSecurityRva() const; 00214 dword getIddSecuritySize() const; 00216 dword getIddBaseRelocRva() const; 00218 dword getIddBaseRelocSize() const; 00220 dword getIddDebugRva() const; 00222 dword getIddDebugSize() const; 00224 dword getIddArchitectureRva() const; 00226 dword getIddArchitectureSize() const; 00228 dword getIddGlobalPtrRva() const; 00230 dword getIddGlobalPtrSize() const; 00232 dword getIddTlsRva() const; 00234 dword getIddTlsSize() const; 00236 dword getIddLoadConfigRva() const; 00238 dword getIddLoadConfigSize() const; 00240 dword getIddBoundImportRva() const; 00242 dword getIddBoundImportSize() const; 00244 dword getIddIatRva() const; 00246 dword getIddIatSize() const; 00248 dword getIddDelayImportRva() const; 00250 dword getIddDelayImportSize() const; 00252 dword getIddComHeaderRva() const; 00254 dword getIddComHeaderSize() const; 00255 00257 dword getImageDataDirectoryRva(dword dwDirectory) const; 00259 dword getImageDataDirectorySize(dword dwDirectory) const; 00260 00261 // section getters 00263 std::string getSectionName(word uiSectionnr) const; 00265 dword getVirtualSize(word uiSectionnr) const; 00267 dword getVirtualAddress(word uiSectionnr) const; 00269 dword getSizeOfRawData(word uiSectionnr) const; 00271 dword getPointerToRawData(word uiSectionnr) const; 00273 dword getPointerToRelocations(word uiSectionnr) const; 00275 dword getPointerToLinenumbers(word uiSectionnr) const; 00277 dword getNumberOfRelocations(word uiSectionnr) const; 00279 dword getNumberOfLinenumbers(word uiSectionnr) const; 00281 dword getCharacteristics(word uiSectionnr) const; 00282 00283 // header setters 00285 void setNtSignature(dword value); 00287 void setMachine(word value); 00289 void setNumberOfSections(word value); 00291 void setTimeDateStamp(dword value); 00293 void setPointerToSymbolTable(dword value); 00295 void setNumberOfSymbols(dword value); 00297 void setSizeOfOptionalHeader(word value); 00299 void setCharacteristics(word value); 00300 00302 void setMagic(word value); 00304 void setMajorLinkerVersion(byte value); 00306 void setMinorLinkerVersion(byte value); 00308 void setSizeOfCode(dword value); 00310 void setSizeOfInitializedData(dword value); 00312 void setSizeOfUninitializedData(dword value); 00314 void setAddressOfEntryPoint(dword value); 00316 void setBaseOfCode(dword value); 00318 void setImageBase(VAR4_8 value); 00320 void setSectionAlignment(dword value); 00322 void setFileAlignment(dword value); 00324 void setMajorOperatingSystemVersion(word value); 00326 void setMinorOperatingSystemVersion(word value); 00328 void setMajorImageVersion(word value); 00330 void setMinorImageVersion(word value); 00332 void setMajorSubsystemVersion(word value); 00334 void setMinorSubsystemVersion(word value); 00336 void setWin32VersionValue(dword value); 00338 void setSizeOfImage(dword value); 00340 void setSizeOfHeaders(dword value); 00342 void setCheckSum(dword value); 00344 void setSubsystem(word value); 00346 void setDllCharacteristics(word value); 00348 void setSizeOfStackReserve(VAR4_8 value); 00350 void setSizeOfStackCommit(VAR4_8 value); 00352 void setSizeOfHeapReserve(VAR4_8 value); 00354 void setSizeOfHeapCommit(VAR4_8 value); 00356 void setLoaderFlags(dword value); 00358 void setNumberOfRvaAndSizes(dword value); 00359 00360 // image directory getters 00361 void setIddDebugRva(dword dwValue); 00362 void setIddDebugSize(dword dwValue); 00363 void setIddDelayImportRva(dword dwValue); 00364 void setIddDelayImportSize(dword dwValue); 00365 void setIddExceptionRva(dword dwValue); 00366 void setIddExceptionSize(dword dwValue); 00367 void setIddGlobalPtrRva(dword dwValue); 00368 void setIddGlobalPtrSize(dword dwValue); 00369 void setIddIatRva(dword dwValue); 00370 void setIddIatSize(dword dwValue); 00371 void setIddLoadConfigRva(dword dwValue); 00372 void setIddLoadConfigSize(dword dwValue); 00373 void setIddResourceRva(dword dwValue); 00374 void setIddResourceSize(dword dwValue); 00375 void setIddSecurityRva(dword dwValue); 00376 void setIddSecuritySize(dword dwValue); 00377 void setIddTlsRva(dword dwValue); 00378 void setIddTlsSize(dword dwValue); 00379 00380 void setIddImportRva(dword dwValue); 00381 void setIddImportSize(dword dwValue); 00382 void setIddExportRva(dword dwValue); 00383 void setIddExportSize(dword dwValue); 00384 00386 void setSectionName(word uiSectionnr, std::string strName); 00388 void setVirtualSize(word uiSectionnr, dword dwValue); 00390 void setVirtualAddress(word uiSectionnr, dword dwValue); 00392 void setSizeOfRawData(word uiSectionnr, dword dwValue); 00394 void setPointerToRawData(word uiSectionnr, dword dwValue); 00396 void setPointerToRelocations(word uiSectionnr, dword dwValue); 00398 void setPointerToLinenumbers(word uiSectionnr, dword dwValue); 00400 void setNumberOfRelocations(word uiSectionnr, dword dwValue); 00402 void setNumberOfLinenumbers(word uiSectionnr, dword dwValue); 00404 void setCharacteristics(word uiSectionnr, dword dwValue); 00405 }; 00406 00407 class PeHeader32 : public PeHeaderT<32> 00408 { 00409 private: 00410 void readBaseOfData(InputBuffer& ibBuffer); 00411 void rebuildBaseOfData(OutputBuffer& obBuffer) const; 00412 public: 00414 dword getBaseOfData() const; 00416 void setBaseOfData(dword value); 00417 }; 00418 00419 class PeHeader64 : public PeHeaderT<64> 00420 { 00421 private: 00422 void readBaseOfData(InputBuffer& ibBuffer); 00423 void rebuildBaseOfData(OutputBuffer& obBuffer) const; 00424 }; 00425 00426 template<int x> 00427 void PeHeaderT<x>::addDataDirectory() 00428 { 00429 m_inthHeader.dataDirectories.push_back(PELIB_IMAGE_DATA_DIRECTORY()); 00430 } 00431 00432 template<int x> 00433 void removeDataDirectory(dword index) 00434 { 00435 m_inthHeader.dataDirectories.erase(m_inthHeader.dataDirectories.begin() + index); 00436 } 00437 00449 template<int x> 00450 int PeHeaderT<x>::addSection(const std::string& strName, dword dwSize) 00451 { 00452 unsigned int uiSecnr = calcNumberOfSections(); 00453 00454 if (uiSecnr) // Always allow 1 section. 00455 { 00456 if (uiSecnr == 0xFFFF || calcSpaceAfterHeader() < PELIB_IMAGE_SECTION_HEADER::size()) 00457 { 00458 return 1; 00459 // throw Exceptions::InsufficientSpace(PeHeaderId, __LINE__); 00460 } 00461 00462 if (!getFileAlignment()) 00463 { 00464 return 2; 00465 // throw Exceptions::InvalidFileAlignment(PeHeaderId, __LINE__); 00466 } 00467 00468 if (!getSectionAlignment()) 00469 { 00470 return 3; 00471 // throw Exceptions::InvalidSectionAlignment(PeHeaderId, __LINE__); 00472 } 00473 } 00474 00475 dword dwOffset = calcOffset(/*dwSize*/); 00476 dword dwRva = calcRva(/*dwSize*/); 00477 00478 PELIB_IMAGE_SECTION_HEADER ishdCurr; 00479 m_vIsh.push_back(ishdCurr); 00480 00481 setSectionName(uiSecnr, strName); 00482 setSizeOfRawData(uiSecnr, alignOffset(dwSize, getFileAlignment())); 00483 setPointerToRawData(uiSecnr, dwOffset); 00484 setVirtualSize(uiSecnr, alignOffset(dwSize, getSectionAlignment())); 00485 setVirtualAddress(uiSecnr, dwRva); 00486 setCharacteristics(uiSecnr, IMAGE_SCN_MEM_WRITE | IMAGE_SCN_MEM_READ | IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_CNT_CODE); 00487 00488 return 0; 00489 } 00490 00496 template<int x> 00497 unsigned int PeHeaderT<x>::calcSizeOfImage() const 00498 { 00499 // Major note here: It's possible for sections to exist with a Virtual Size of 0. 00500 // That's why it's necessary to use std::max(Vsize, RawSize) here. 00501 // An example for such a file is dbeng6.exe (made by Sybase). 00502 // In this file each and every section has a VSize of 0 but it still runs. 00503 00504 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)); 00505 return ishLastSection->VirtualAddress + std::max(ishLastSection->VirtualSize, ishLastSection->SizeOfRawData); 00506 } 00507 00515 template<int x> 00516 unsigned int PeHeaderT<x>::calcSpaceAfterHeader() const 00517 { 00518 return (calcStartOfCode() > size() + m_uiOffset) ? calcStartOfCode() - (size() + m_uiOffset) : 0; 00519 } 00520 00530 template<int x> 00531 unsigned int PeHeaderT<x>::calcStartOfCode() const 00532 { 00533 unsigned int directories = calcNumberOfRvaAndSizes(); 00534 dword dwMinOffset = 0xFFFFFFFF; 00535 if (directories >= 1 && getIddExportRva() && rvaToOffset(getIddExportRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddExportRva()); 00536 if (directories >= 2 && getIddImportRva() && rvaToOffset(getIddImportRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddImportRva()); 00537 if (directories >= 3 && getIddResourceRva() && rvaToOffset(getIddResourceRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddResourceRva()); 00538 if (directories >= 4 && getIddExceptionRva() && rvaToOffset(getIddExceptionRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddExceptionRva()); 00539 if (directories >= 5 && getIddSecurityRva() && rvaToOffset(getIddSecurityRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddSecurityRva()); 00540 if (directories >= 6 && getIddBaseRelocRva() && rvaToOffset(getIddBaseRelocRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddBaseRelocRva()); 00541 if (directories >= 7 && getIddDebugRva() && rvaToOffset(getIddDebugRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddDebugRva()); 00542 if (directories >= 8 && getIddArchitectureRva() && rvaToOffset(getIddArchitectureRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddArchitectureRva()); 00543 if (directories >= 9 && getIddGlobalPtrRva() && rvaToOffset(getIddGlobalPtrRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddGlobalPtrRva()); 00544 if (directories >= 10 && getIddTlsRva() && rvaToOffset(getIddTlsRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddTlsRva()); 00545 if (directories >= 11 && getIddLoadConfigRva() && rvaToOffset(getIddLoadConfigRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddLoadConfigRva()); 00546 if (directories >= 12 && getIddBoundImportRva() && rvaToOffset(getIddBoundImportRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddBoundImportRva()); 00547 if (directories >= 13 && getIddIatRva() && rvaToOffset(getIddIatRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddIatRva()); 00548 if (directories >= 14 && getIddDelayImportRva() && rvaToOffset(getIddDelayImportRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddDelayImportRva()); 00549 if (directories >= 15 && getIddComHeaderRva() && rvaToOffset(getIddComHeaderRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddComHeaderRva()); 00550 00551 for (word i=0;i<calcNumberOfSections();i++) 00552 { 00553 if ((getPointerToRawData(i) < dwMinOffset || dwMinOffset == 0xFFFFFFFF) && getSizeOfRawData(i)) 00554 { 00555 if (getPointerToRawData(i)) dwMinOffset = getPointerToRawData(i); 00556 } 00557 } 00558 return dwMinOffset; 00559 } 00560 00566 template<int x> 00567 unsigned int PeHeaderT<x>::calcOffset(/*unsigned int uiSize*/) const 00568 { 00569 unsigned int maxoffset = size(); 00570 00571 for (word i=0;i<calcNumberOfSections();i++) 00572 { 00573 if (getPointerToRawData(i) + getSizeOfRawData(i) > maxoffset) maxoffset = getPointerToRawData(i) + getSizeOfRawData(i); 00574 } 00575 00576 return alignOffset(maxoffset, getFileAlignment()); 00577 } 00578 00584 template<int x> 00585 unsigned int PeHeaderT<x>::calcRva(/*unsigned int uiSize*/) const 00586 { 00587 // Major note here: It's possible for sections to exist with a Virtual Size of 0. 00588 // That's why it's necessary to use std::max(Vsize, RawSize) here. 00589 // An example for such a file is dbeng6.exe (made by Sybase). 00590 // In this file each and every section has a VSize of 0 but it still runs. 00591 00592 unsigned int maxoffset = size(); 00593 for (word i=0;i<calcNumberOfSections();i++) 00594 { 00595 if (getVirtualAddress(i) + std::max(getVirtualSize(i), getSizeOfRawData(i)) > maxoffset) maxoffset = getVirtualAddress(i) + std::max(getVirtualSize(i), getSizeOfRawData(i)); 00596 } 00597 00598 return alignOffset(maxoffset, getSectionAlignment()); 00599 } 00600 00606 template<int x> 00607 word PeHeaderT<x>::calcNumberOfSections() const 00608 { 00609 return static_cast<PeLib::word>(m_vIsh.size()); 00610 } 00611 00616 template<int x> 00617 void PeHeaderT<x>::enlargeLastSection(unsigned int uiSize) 00618 { 00619 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)); 00620 unsigned int uiRawDataSize = alignOffset(ishLastSection->SizeOfRawData + uiSize, getFileAlignment()); 00621 00622 ishLastSection->SizeOfRawData = uiRawDataSize; 00623 ishLastSection->VirtualSize = ishLastSection->SizeOfRawData; 00624 00625 setSizeOfImage(calcSizeOfImage()); 00626 } 00627 00633 template<int x> 00634 word PeHeaderT<x>::getSectionWithOffset(VAR4_8 dwOffset) const 00635 { 00636 for (word i=0;i<calcNumberOfSections();i++) 00637 { 00638 if (getPointerToRawData(i) <= dwOffset && getPointerToRawData(i) + getSizeOfRawData(i) > dwOffset) return i; 00639 } 00640 00641 return -1; 00642 } 00643 00649 template<int x> 00650 word PeHeaderT<x>::getSectionWithRva(VAR4_8 dwRva) const 00651 { 00652 // Major note here: It's possible for sections to exist with a Virtual Size of 0. 00653 // That's why it's necessary to use std::max(Vsize, RawSize) here. 00654 // An example for such a file is dbeng6.exe (made by Sybase). 00655 // In this file each and every section has a VSize of 0 but it still runs. 00656 00657 for (word i=0;i<calcNumberOfSections();i++) 00658 { 00659 // Weird VC++7 error doesn't allow me to use std::max here. 00660 dword max = getVirtualSize(i) >= getSizeOfRawData(i) ? getVirtualSize(i) : getSizeOfRawData(i); 00661 if (getVirtualAddress(i) <= dwRva && getVirtualAddress(i) + max > dwRva) return i; 00662 } 00663 00664 return -1; 00665 } 00666 00675 template<int x> 00676 void PeHeaderT<x>::makeValid(dword dwOffset) 00677 { 00678 setNtSignature(IMAGE_NT_SIGNATURE); // 'PE' 00679 setMachine(IMAGE_FILE_MACHINE_I386); 00680 setNumberOfSections(calcNumberOfSections()); 00681 00682 // Check if 64 bits. 00683 setSizeOfOptionalHeader(PELIB_IMAGE_OPTIONAL_HEADER<x>::size() + calcNumberOfRvaAndSizes() * 8); 00684 00685 // Check if 64 bits. 00686 dword dwCharacteristics = IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_32BIT_MACHINE; 00687 setCharacteristics(dwCharacteristics); 00688 00689 // Check if 64 bits. 00690 setMagic(IMAGE_NT_OPTIONAL_HDR32_MAGIC); 00691 00692 // setImageBase(0x01000000); 00693 00694 // Align file and section alignment values 00695 unsigned int dwAlignedOffset = alignOffset(getSectionAlignment(), 0x1000); 00696 setSectionAlignment(dwAlignedOffset ? dwAlignedOffset : 0x1000); 00697 00698 dwAlignedOffset = alignOffset(getFileAlignment(), 0x200); 00699 setFileAlignment(dwAlignedOffset ? dwAlignedOffset : 0x200); 00700 00701 // setMajorSubsystemVersion(4); 00702 // setSubsystem(IMAGE_SUBSYSTEM_WINDOWS_GUI); 00703 setNumberOfRvaAndSizes(calcNumberOfRvaAndSizes()); 00704 00705 // Code below depends on code above. Don't change the order. 00706 dword dwSizeOfHeaders = alignOffset(dwOffset + size(), getFileAlignment()); 00707 setSizeOfHeaders(dwSizeOfHeaders); 00708 00709 dword dwSizeOfImage = alignOffset(dwSizeOfHeaders, getSectionAlignment()); 00710 00711 for (int i=0;i<calcNumberOfSections();i++) 00712 { 00713 dwSizeOfImage += alignOffset(getVirtualSize(i), getSectionAlignment()); 00714 } 00715 00716 dwSizeOfImage = alignOffset(dwSizeOfImage, getSectionAlignment()); 00717 setSizeOfImage(dwSizeOfImage); 00718 } 00719 00720 template<int x> 00721 unsigned int PeHeaderT<x>::offsetToRva(VAR4_8 dwOffset) const 00722 { 00723 if (dwOffset < calcStartOfCode()) return dwOffset; 00724 00725 PeLib::word uiSecnr = getSectionWithOffset(dwOffset); 00726 00727 if (uiSecnr == 0xFFFF) return -1; 00728 00729 return getVirtualAddress(uiSecnr) + dwOffset - getPointerToRawData(uiSecnr); 00730 } 00731 00737 template<int x> 00738 unsigned int PeHeaderT<x>::offsetToVa(VAR4_8 dwOffset) const 00739 { 00740 if (dwOffset < calcStartOfCode()) return getImageBase() + dwOffset; 00741 00742 PeLib::word uiSecnr = getSectionWithOffset(dwOffset); 00743 00744 if (uiSecnr == 0xFFFF) return -1; 00745 00746 return getImageBase() + getVirtualAddress(uiSecnr) + dwOffset - getPointerToRawData(uiSecnr); 00747 } 00748 00756 template<int x> 00757 int PeHeaderT<x>::read(std::string strFilename, unsigned int uiOffset) 00758 { 00759 std::ifstream ifFile(strFilename.c_str(), std::ios::binary); 00760 00761 if (!ifFile) 00762 { 00763 // throw Exceptions::CannotOpenFile(PeHeaderId, __LINE__); 00764 return 1; 00765 } 00766 00767 // File too small 00768 if (fileSize(ifFile) < uiOffset + m_inthHeader.size()) 00769 { 00770 // throw Exceptions::InvalidFormat(PeHeaderId, __LINE__); 00771 return 1; 00772 } 00773 00774 std::vector<unsigned char> vBuffer(m_inthHeader.size()); 00775 00776 ifFile.seekg(uiOffset, std::ios::beg); 00777 ifFile.read(reinterpret_cast<char*>(&vBuffer[0]), static_cast<std::streamsize>(vBuffer.size())); 00778 00779 InputBuffer ibBuffer(vBuffer); 00780 ibBuffer >> m_inthHeader.Signature; 00781 00782 if (m_inthHeader.Signature != 17744) 00783 { 00784 return 1; 00785 // throw Exceptions::InvalidFormat(PeHeaderId, __LINE__); 00786 } 00787 00788 #define DEB std::cout << std::dec << __LINE__ << std::endl; 00789 00790 ibBuffer >> m_inthHeader.FileHeader.Machine; 00791 ibBuffer >> m_inthHeader.FileHeader.NumberOfSections; 00792 ibBuffer >> m_inthHeader.FileHeader.TimeDateStamp; 00793 ibBuffer >> m_inthHeader.FileHeader.PointerToSymbolTable; 00794 ibBuffer >> m_inthHeader.FileHeader.NumberOfSymbols; 00795 ibBuffer >> m_inthHeader.FileHeader.SizeOfOptionalHeader; 00796 ibBuffer >> m_inthHeader.FileHeader.Characteristics; 00797 ibBuffer >> m_inthHeader.OptionalHeader.Magic; 00798 00799 ibBuffer >> m_inthHeader.OptionalHeader.MajorLinkerVersion; 00800 ibBuffer >> m_inthHeader.OptionalHeader.MinorLinkerVersion; 00801 ibBuffer >> m_inthHeader.OptionalHeader.SizeOfCode; 00802 ibBuffer >> m_inthHeader.OptionalHeader.SizeOfInitializedData; 00803 ibBuffer >> m_inthHeader.OptionalHeader.SizeOfUninitializedData; 00804 ibBuffer >> m_inthHeader.OptionalHeader.AddressOfEntryPoint; 00805 ibBuffer >> m_inthHeader.OptionalHeader.BaseOfCode; 00806 readBaseOfData(ibBuffer); 00807 // ibBuffer >> m_inthHeader.OptionalHeader.BaseOfData; 00808 ibBuffer >> m_inthHeader.OptionalHeader.ImageBase; 00809 ibBuffer >> m_inthHeader.OptionalHeader.SectionAlignment; 00810 ibBuffer >> m_inthHeader.OptionalHeader.FileAlignment; 00811 ibBuffer >> m_inthHeader.OptionalHeader.MajorOperatingSystemVersion; 00812 ibBuffer >> m_inthHeader.OptionalHeader.MinorOperatingSystemVersion; 00813 ibBuffer >> m_inthHeader.OptionalHeader.MajorImageVersion; 00814 ibBuffer >> m_inthHeader.OptionalHeader.MinorImageVersion; 00815 ibBuffer >> m_inthHeader.OptionalHeader.MajorSubsystemVersion; 00816 ibBuffer >> m_inthHeader.OptionalHeader.MinorSubsystemVersion; 00817 ibBuffer >> m_inthHeader.OptionalHeader.Win32VersionValue; 00818 ibBuffer >> m_inthHeader.OptionalHeader.SizeOfImage; 00819 ibBuffer >> m_inthHeader.OptionalHeader.SizeOfHeaders; 00820 ibBuffer >> m_inthHeader.OptionalHeader.CheckSum; 00821 ibBuffer >> m_inthHeader.OptionalHeader.Subsystem; 00822 ibBuffer >> m_inthHeader.OptionalHeader.DllCharacteristics; 00823 ibBuffer >> m_inthHeader.OptionalHeader.SizeOfStackReserve; 00824 ibBuffer >> m_inthHeader.OptionalHeader.SizeOfStackCommit; 00825 ibBuffer >> m_inthHeader.OptionalHeader.SizeOfHeapReserve; 00826 ibBuffer >> m_inthHeader.OptionalHeader.SizeOfHeapCommit; 00827 ibBuffer >> m_inthHeader.OptionalHeader.LoaderFlags; 00828 ibBuffer >> m_inthHeader.OptionalHeader.NumberOfRvaAndSizes; 00829 00830 vBuffer.resize(m_inthHeader.OptionalHeader.NumberOfRvaAndSizes * 8 + m_inthHeader.FileHeader.NumberOfSections * 0x28); 00831 00832 ifFile.read(reinterpret_cast<char*>(&vBuffer[0]), static_cast<std::streamsize>(vBuffer.size())); 00833 00834 ibBuffer.setBuffer(vBuffer); 00835 00836 PELIB_IMAGE_DATA_DIRECTORY idd; 00837 00838 for (unsigned int i=0;i<m_inthHeader.OptionalHeader.NumberOfRvaAndSizes;i++) 00839 { 00840 ibBuffer >> idd.VirtualAddress; 00841 ibBuffer >> idd.Size; 00842 m_inthHeader.dataDirectories.push_back(idd); 00843 } 00844 00845 // Sections 00846 const unsigned int nrSections = getNumberOfSections(); 00847 00848 // File too small. 00849 if (fileSize(ifFile) < uiOffset + m_inthHeader.size() + nrSections * PELIB_IMAGE_SECTION_HEADER::size()) 00850 { 00851 // throw Exceptions::InvalidFormat(PeHeaderId, __LINE__); 00852 return 1; 00853 } 00854 00855 // vBuffer.resize(nrSections * PELIB_IMAGE_SECTION_HEADER::size()); 00856 // ifFile.seekg(uiOffset, std::ios::beg); 00857 // ifFile.read(reinterpret_cast<char*>(&vBuffer[0]), static_cast<std::streamsize>(vBuffer.size())); 00858 00859 InputBuffer ibBufferSec(vBuffer); 00860 00861 PELIB_IMAGE_SECTION_HEADER ishCurr; 00862 00863 std::vector<PELIB_IMAGE_SECTION_HEADER> vIshdCurr; 00864 00865 for (unsigned int i=0;i<nrSections;i++) 00866 { 00867 ibBuffer.read(reinterpret_cast<char*>(ishCurr.Name), 8); 00868 ibBuffer >> ishCurr.VirtualSize; 00869 ibBuffer >> ishCurr.VirtualAddress; 00870 ibBuffer >> ishCurr.SizeOfRawData; 00871 ibBuffer >> ishCurr.PointerToRawData; 00872 ibBuffer >> ishCurr.PointerToRelocations; 00873 ibBuffer >> ishCurr.PointerToLinenumbers; 00874 ibBuffer >> ishCurr.NumberOfRelocations; 00875 ibBuffer >> ishCurr.NumberOfLinenumbers; 00876 ibBuffer >> ishCurr.Characteristics; 00877 vIshdCurr.push_back(ishCurr); 00878 } 00879 00880 std::swap(vIshdCurr, m_vIsh); 00881 m_uiOffset = uiOffset; 00882 00883 ifFile.close(); 00884 00885 return 0; 00886 } 00887 00894 template<int x> 00895 void PeHeaderT<x>::rebuild(std::vector<byte>& vBuffer) const 00896 { 00897 OutputBuffer obBuffer(vBuffer); 00898 00899 obBuffer << m_inthHeader.Signature; 00900 00901 obBuffer << m_inthHeader.FileHeader.Machine; 00902 obBuffer << m_inthHeader.FileHeader.NumberOfSections; 00903 obBuffer << m_inthHeader.FileHeader.TimeDateStamp; 00904 obBuffer << m_inthHeader.FileHeader.PointerToSymbolTable; 00905 obBuffer << m_inthHeader.FileHeader.NumberOfSymbols; 00906 obBuffer << m_inthHeader.FileHeader.SizeOfOptionalHeader; 00907 obBuffer << m_inthHeader.FileHeader.Characteristics; 00908 obBuffer << m_inthHeader.OptionalHeader.Magic; 00909 obBuffer << m_inthHeader.OptionalHeader.MajorLinkerVersion; 00910 obBuffer << m_inthHeader.OptionalHeader.MinorLinkerVersion; 00911 obBuffer << m_inthHeader.OptionalHeader.SizeOfCode; 00912 obBuffer << m_inthHeader.OptionalHeader.SizeOfInitializedData; 00913 obBuffer << m_inthHeader.OptionalHeader.SizeOfUninitializedData; 00914 obBuffer << m_inthHeader.OptionalHeader.AddressOfEntryPoint; 00915 obBuffer << m_inthHeader.OptionalHeader.BaseOfCode; 00916 rebuildBaseOfData(obBuffer); 00917 // obBuffer << m_inthHeader.OptionalHeader.BaseOfData; 00918 obBuffer << m_inthHeader.OptionalHeader.ImageBase; 00919 obBuffer << m_inthHeader.OptionalHeader.SectionAlignment; 00920 obBuffer << m_inthHeader.OptionalHeader.FileAlignment; 00921 obBuffer << m_inthHeader.OptionalHeader.MajorOperatingSystemVersion; 00922 obBuffer << m_inthHeader.OptionalHeader.MinorOperatingSystemVersion; 00923 obBuffer << m_inthHeader.OptionalHeader.MajorImageVersion; 00924 obBuffer << m_inthHeader.OptionalHeader.MinorImageVersion; 00925 obBuffer << m_inthHeader.OptionalHeader.MajorSubsystemVersion; 00926 obBuffer << m_inthHeader.OptionalHeader.MinorSubsystemVersion; 00927 obBuffer << m_inthHeader.OptionalHeader.Win32VersionValue; 00928 obBuffer << m_inthHeader.OptionalHeader.SizeOfImage; 00929 obBuffer << m_inthHeader.OptionalHeader.SizeOfHeaders; 00930 obBuffer << m_inthHeader.OptionalHeader.CheckSum; 00931 obBuffer << m_inthHeader.OptionalHeader.Subsystem; 00932 obBuffer << m_inthHeader.OptionalHeader.DllCharacteristics; 00933 obBuffer << m_inthHeader.OptionalHeader.SizeOfStackReserve; 00934 obBuffer << m_inthHeader.OptionalHeader.SizeOfStackCommit; 00935 obBuffer << m_inthHeader.OptionalHeader.SizeOfHeapReserve; 00936 obBuffer << m_inthHeader.OptionalHeader.SizeOfHeapCommit; 00937 obBuffer << m_inthHeader.OptionalHeader.LoaderFlags; 00938 obBuffer << m_inthHeader.OptionalHeader.NumberOfRvaAndSizes; 00939 00940 // The 0x10 data directories 00941 for (unsigned int i=0;i<calcNumberOfRvaAndSizes();i++) 00942 { 00943 obBuffer << m_inthHeader.dataDirectories[i].VirtualAddress; 00944 obBuffer << m_inthHeader.dataDirectories[i].Size; 00945 } 00946 00947 // The section definitions 00948 const unsigned int nrSections = calcNumberOfSections(); 00949 for (unsigned int i=0;i<nrSections;i++) 00950 { 00951 char temp[9] = {0}; 00952 strcpy(temp, getSectionName(i).c_str()); 00953 obBuffer.add(temp, 8); 00954 obBuffer << m_vIsh[i].VirtualSize; 00955 obBuffer << m_vIsh[i].VirtualAddress; 00956 obBuffer << m_vIsh[i].SizeOfRawData; 00957 obBuffer << m_vIsh[i].PointerToRawData; 00958 obBuffer << m_vIsh[i].PointerToRelocations; 00959 obBuffer << m_vIsh[i].PointerToLinenumbers; 00960 obBuffer << m_vIsh[i].NumberOfRelocations; 00961 obBuffer << m_vIsh[i].NumberOfLinenumbers; 00962 obBuffer << m_vIsh[i].Characteristics; 00963 } 00964 } 00965 00972 template<int x> 00973 typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::rvaToOffset(VAR4_8 dwRva) const 00974 { 00975 // Not correct 00976 if (dwRva < 0x1000) return dwRva; 00977 PeLib::word uiSecnr = getSectionWithRva(dwRva); 00978 if (uiSecnr == 0xFFFF || dwRva > getVirtualAddress(uiSecnr) + getSizeOfRawData(uiSecnr)) 00979 { 00980 return -1; 00981 } 00982 00983 return getPointerToRawData(uiSecnr) + dwRva - getVirtualAddress(uiSecnr); 00984 } 00985 00991 template<int x> 00992 typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::rvaToVa(VAR4_8 dwRva) const 00993 { 00994 return getImageBase() + dwRva; 00995 } 00996 01002 template<int x> 01003 unsigned int PeHeaderT<x>::size() const 01004 { 01005 return m_inthHeader.size() + getNumberOfSections() * PELIB_IMAGE_SECTION_HEADER::size(); 01006 } 01007 01008 // \todo Not sure if this works. 01009 template<int x> 01010 typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::vaToRva(VAR4_8 dwRva) const 01011 { 01012 if (dwRva - getImageBase() < calcStartOfCode()) return dwRva - getImageBase(); 01013 01014 if (getSectionWithRva(dwRva - getImageBase()) == 0xFFFF) return -1; 01015 01016 return dwRva - getImageBase(); 01017 } 01018 01019 template<int x> 01020 typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::vaToOffset(VAR4_8 dwRva) const 01021 { 01022 return rvaToOffset(dwRva - getImageBase()); 01023 } 01024 01033 template<int x> 01034 int PeHeaderT<x>::write(std::string strFilename, unsigned int uiOffset) const 01035 { 01036 std::fstream ofFile(strFilename.c_str(), std::ios_base::binary | std::ios_base::in | std::ios_base::out); 01037 01038 if (!ofFile) 01039 { 01040 ofFile.clear(); 01041 ofFile.open(strFilename.c_str(), std::ios_base::binary | std::ios_base::in | std::ios_base::out | std::ios_base::trunc); 01042 if (!ofFile) 01043 { 01044 return 1; 01045 } 01046 } 01047 ofFile.seekp(uiOffset, std::ios::beg); 01048 01049 std::vector<unsigned char> vBuffer; 01050 01051 rebuild(vBuffer); 01052 01053 ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), vBuffer.size()); 01054 01055 ofFile.close(); 01056 01057 return 0; 01058 } 01059 01060 01068 template<int x> 01069 int PeHeaderT<x>::writeSectionData(const std::string& strFilename, word wSecnr, const std::vector<byte>& vBuffer) const 01070 { 01071 std::fstream ofFile(strFilename.c_str(), std::ios::in | std::ios::out | std::ios::binary); 01072 01073 if (!ofFile) 01074 { 01075 ofFile.clear(); 01076 01077 return 1; 01078 } 01079 01080 ofFile.seekp(getPointerToRawData(wSecnr), std::ios::beg); 01081 01082 ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), std::min(vBuffer.size(), getSizeOfRawData(wSecnr))); 01083 01084 ofFile.close(); 01085 01086 return 1; 01087 } 01088 01089 template<int x> 01090 int PeHeaderT<x>::writeSections(const std::string& strFilename) const 01091 { 01092 std::fstream ofFile(strFilename.c_str(), std::ios::in | std::ios::out | std::ios::binary); 01093 01094 if (!ofFile) 01095 { 01096 ofFile.clear(); 01097 01098 return 1; 01099 } 01100 01101 unsigned int uiFilesize = fileSize(ofFile); 01102 01103 for (int i=0;i<calcNumberOfSections();i++) 01104 { 01105 if (uiFilesize < getPointerToRawData(i) + getSizeOfRawData(i)) 01106 { 01107 unsigned int uiToWrite = getPointerToRawData(i) + getSizeOfRawData(i) - uiFilesize; 01108 std::vector<char> vBuffer(uiToWrite); 01109 ofFile.seekp(0, std::ios::end); 01110 ofFile.write(&vBuffer[0], vBuffer.size()); 01111 uiFilesize = getPointerToRawData(i) + getSizeOfRawData(i); 01112 } 01113 } 01114 01115 ofFile.close(); 01116 01117 return 0; 01118 } 01119 01124 template<int x> 01125 dword PeHeaderT<x>::getNtSignature() const 01126 { 01127 return m_inthHeader.Signature; 01128 } 01129 01134 template<int x> 01135 word PeHeaderT<x>::getMachine() const 01136 { 01137 return m_inthHeader.FileHeader.Machine; 01138 } 01139 01140 01146 template<int x> 01147 word PeHeaderT<x>::getNumberOfSections() const 01148 { 01149 return m_inthHeader.FileHeader.NumberOfSections; 01150 } 01151 01156 template<int x> 01157 dword PeHeaderT<x>::getTimeDateStamp() const 01158 { 01159 return m_inthHeader.FileHeader.TimeDateStamp; 01160 } 01161 01166 template<int x> 01167 dword PeHeaderT<x>::getPointerToSymbolTable() const 01168 { 01169 return m_inthHeader.FileHeader.PointerToSymbolTable; 01170 } 01171 01176 template<int x> 01177 dword PeHeaderT<x>::getNumberOfSymbols() const 01178 { 01179 return m_inthHeader.FileHeader.NumberOfSymbols; 01180 } 01181 01186 template<int x> 01187 word PeHeaderT<x>::getSizeOfOptionalHeader() const 01188 { 01189 return m_inthHeader.FileHeader.SizeOfOptionalHeader; 01190 } 01191 01195 template<int x> 01196 word PeHeaderT<x>::getCharacteristics() const 01197 { 01198 return m_inthHeader.FileHeader.Characteristics; 01199 } 01200 01204 template<int x> 01205 word PeHeaderT<x>::getMagic() const 01206 { 01207 return m_inthHeader.OptionalHeader.Magic; 01208 } 01209 01213 template<int x> 01214 byte PeHeaderT<x>::getMajorLinkerVersion() const 01215 { 01216 return m_inthHeader.OptionalHeader.MajorLinkerVersion; 01217 } 01218 01222 template<int x> 01223 byte PeHeaderT<x>::getMinorLinkerVersion() const 01224 { 01225 return m_inthHeader.OptionalHeader.MinorLinkerVersion; 01226 } 01227 01231 template<int x> 01232 dword PeHeaderT<x>::getSizeOfCode() const 01233 { 01234 return m_inthHeader.OptionalHeader.SizeOfCode; 01235 } 01236 01240 template<int x> 01241 dword PeHeaderT<x>::getSizeOfInitializedData() const 01242 { 01243 return m_inthHeader.OptionalHeader.SizeOfInitializedData; 01244 } 01245 01249 template<int x> 01250 dword PeHeaderT<x>::getSizeOfUninitializedData() const 01251 { 01252 return m_inthHeader.OptionalHeader.SizeOfUninitializedData; 01253 } 01254 01258 template<int x> 01259 dword PeHeaderT<x>::getAddressOfEntryPoint() const 01260 { 01261 return m_inthHeader.OptionalHeader.AddressOfEntryPoint; 01262 } 01263 01267 template<int x> 01268 dword PeHeaderT<x>::getBaseOfCode() const 01269 { 01270 return m_inthHeader.OptionalHeader.BaseOfCode; 01271 } 01272 01276 template<int x> 01277 typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::getImageBase() const 01278 { 01279 return m_inthHeader.OptionalHeader.ImageBase; 01280 } 01281 01285 template<int x> 01286 dword PeHeaderT<x>::getSectionAlignment() const 01287 { 01288 return m_inthHeader.OptionalHeader.SectionAlignment; 01289 } 01290 01294 template<int x> 01295 dword PeHeaderT<x>::getFileAlignment() const 01296 { 01297 return m_inthHeader.OptionalHeader.FileAlignment; 01298 } 01299 01303 template<int x> 01304 word PeHeaderT<x>::getMajorOperatingSystemVersion() const 01305 { 01306 return m_inthHeader.OptionalHeader.MajorOperatingSystemVersion; 01307 } 01308 01312 template<int x> 01313 word PeHeaderT<x>::getMinorOperatingSystemVersion() const 01314 { 01315 return m_inthHeader.OptionalHeader.MinorOperatingSystemVersion; 01316 } 01317 01321 template<int x> 01322 word PeHeaderT<x>::getMajorImageVersion() const 01323 { 01324 return m_inthHeader.OptionalHeader.MajorImageVersion; 01325 } 01326 01330 template<int x> 01331 word PeHeaderT<x>::getMinorImageVersion() const 01332 { 01333 return m_inthHeader.OptionalHeader.MinorImageVersion; 01334 } 01335 01339 template<int x> 01340 word PeHeaderT<x>::getMajorSubsystemVersion() const 01341 { 01342 return m_inthHeader.OptionalHeader.MajorSubsystemVersion; 01343 } 01344 01348 template<int x> 01349 word PeHeaderT<x>::getMinorSubsystemVersion() const 01350 { 01351 return m_inthHeader.OptionalHeader.MinorSubsystemVersion; 01352 } 01353 01357 template<int x> 01358 dword PeHeaderT<x>::getWin32VersionValue() const 01359 { 01360 return m_inthHeader.OptionalHeader.Win32VersionValue; 01361 } 01362 01366 template<int x> 01367 dword PeHeaderT<x>::getSizeOfImage() const 01368 { 01369 return m_inthHeader.OptionalHeader.SizeOfImage; 01370 } 01371 01375 template<int x> 01376 dword PeHeaderT<x>::getSizeOfHeaders() const 01377 { 01378 return m_inthHeader.OptionalHeader.SizeOfHeaders; 01379 } 01380 01384 template<int x> 01385 dword PeHeaderT<x>::getCheckSum() const 01386 { 01387 return m_inthHeader.OptionalHeader.CheckSum; 01388 } 01389 01393 template<int x> 01394 word PeHeaderT<x>::getSubsystem() const 01395 { 01396 return m_inthHeader.OptionalHeader.Subsystem; 01397 } 01398 01402 template<int x> 01403 word PeHeaderT<x>::getDllCharacteristics() const 01404 { 01405 return m_inthHeader.OptionalHeader.DllCharacteristics; 01406 } 01407 01411 template<int x> 01412 typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::getSizeOfStackReserve() const 01413 { 01414 return m_inthHeader.OptionalHeader.SizeOfStackReserve; 01415 } 01416 01420 template<int x> 01421 typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::getSizeOfStackCommit() const 01422 { 01423 return m_inthHeader.OptionalHeader.SizeOfStackCommit; 01424 } 01425 01429 template<int x> 01430 typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::getSizeOfHeapReserve() const 01431 { 01432 return m_inthHeader.OptionalHeader.SizeOfHeapReserve; 01433 } 01434 01438 template<int x> 01439 typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::getSizeOfHeapCommit() const 01440 { 01441 return m_inthHeader.OptionalHeader.SizeOfHeapCommit; 01442 } 01443 01447 template<int x> 01448 dword PeHeaderT<x>::getLoaderFlags() const 01449 { 01450 return m_inthHeader.OptionalHeader.LoaderFlags; 01451 } 01452 01456 template<int x> 01457 dword PeHeaderT<x>::getNumberOfRvaAndSizes() const 01458 { 01459 return m_inthHeader.OptionalHeader.NumberOfRvaAndSizes; 01460 } 01461 01462 template<int x> 01463 dword PeHeaderT<x>::calcNumberOfRvaAndSizes() const 01464 { 01465 return static_cast<dword>(m_inthHeader.dataDirectories.size()); 01466 } 01467 01472 template<int x> 01473 dword PeHeaderT<x>::getIddExportRva() const 01474 { 01475 return m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress; 01476 } 01477 01482 template<int x> 01483 dword PeHeaderT<x>::getIddExportSize() const 01484 { 01485 return m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_EXPORT].Size; 01486 } 01487 01492 template<int x> 01493 dword PeHeaderT<x>::getIddImportRva() const 01494 { 01495 return m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress; 01496 } 01497 01502 template<int x> 01503 dword PeHeaderT<x>::getIddImportSize() const 01504 { 01505 return m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_IMPORT].Size; 01506 } 01507 01512 template<int x> 01513 dword PeHeaderT<x>::getIddResourceRva() const 01514 { 01515 return m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress; 01516 } 01517 01522 template<int x> 01523 dword PeHeaderT<x>::getIddResourceSize() const 01524 { 01525 return m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_RESOURCE].Size; 01526 } 01527 01532 template<int x> 01533 dword PeHeaderT<x>::getIddExceptionRva() const 01534 { 01535 return m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_EXCEPTION].VirtualAddress; 01536 } 01537 01542 template<int x> 01543 dword PeHeaderT<x>::getIddExceptionSize() const 01544 { 01545 return m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_EXCEPTION].Size; 01546 } 01547 01552 template<int x> 01553 dword PeHeaderT<x>::getIddSecurityRva() const 01554 { 01555 return m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_SECURITY].VirtualAddress; 01556 } 01557 01562 template<int x> 01563 dword PeHeaderT<x>::getIddSecuritySize() const 01564 { 01565 return m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_SECURITY].Size; 01566 } 01567 01572 template<int x> 01573 dword PeHeaderT<x>::getIddBaseRelocRva() const 01574 { 01575 return m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress; 01576 } 01577 01582 template<int x> 01583 dword PeHeaderT<x>::getIddBaseRelocSize() const 01584 { 01585 return m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_BASERELOC].Size; 01586 } 01587 01592 template<int x> 01593 dword PeHeaderT<x>::getIddDebugRva() const 01594 { 01595 return m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress; 01596 } 01597 01602 template<int x> 01603 dword PeHeaderT<x>::getIddDebugSize() const 01604 { 01605 return m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_DEBUG].Size; 01606 } 01607 01612 template<int x> 01613 dword PeHeaderT<x>::getIddArchitectureRva() const 01614 { 01615 return m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_ARCHITECTURE].VirtualAddress; 01616 } 01617 01622 template<int x> 01623 dword PeHeaderT<x>::getIddArchitectureSize() const 01624 { 01625 return m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_ARCHITECTURE].Size; 01626 } 01627 01632 template<int x> 01633 dword PeHeaderT<x>::getIddGlobalPtrRva() const 01634 { 01635 return m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_GLOBALPTR].VirtualAddress; 01636 } 01637 01642 template<int x> 01643 dword PeHeaderT<x>::getIddGlobalPtrSize() const 01644 { 01645 return m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_GLOBALPTR].Size; 01646 } 01647 01652 template<int x> 01653 dword PeHeaderT<x>::getIddTlsRva() const 01654 { 01655 return m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_TLS].VirtualAddress; 01656 } 01657 01662 template<int x> 01663 dword PeHeaderT<x>::getIddTlsSize() const 01664 { 01665 return m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_TLS].Size; 01666 } 01667 01672 template<int x> 01673 dword PeHeaderT<x>::getIddLoadConfigRva() const 01674 { 01675 return m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG].VirtualAddress; 01676 } 01677 01682 template<int x> 01683 dword PeHeaderT<x>::getIddLoadConfigSize() const 01684 { 01685 return m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG].Size; 01686 } 01687 01692 template<int x> 01693 dword PeHeaderT<x>::getIddBoundImportRva() const 01694 { 01695 return m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT].VirtualAddress; 01696 } 01697 01702 template<int x> 01703 dword PeHeaderT<x>::getIddBoundImportSize() const 01704 { 01705 return m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT].Size; 01706 } 01707 01712 template<int x> 01713 dword PeHeaderT<x>::getIddIatRva() const 01714 { 01715 return m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_IAT].VirtualAddress; 01716 } 01717 01722 template<int x> 01723 dword PeHeaderT<x>::getIddIatSize() const 01724 { 01725 return m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_IAT].Size; 01726 } 01727 01732 template<int x> 01733 dword PeHeaderT<x>::getIddDelayImportRva() const 01734 { 01735 return m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT].VirtualAddress; 01736 } 01737 01742 template<int x> 01743 dword PeHeaderT<x>::getIddDelayImportSize() const 01744 { 01745 return m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT].Size; 01746 } 01747 01752 template<int x> 01753 dword PeHeaderT<x>::getIddComHeaderRva() const 01754 { 01755 return m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress; 01756 } 01757 01762 template<int x> 01763 dword PeHeaderT<x>::getIddComHeaderSize() const 01764 { 01765 return m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].Size; 01766 } 01767 01773 template<int x> 01774 dword PeHeaderT<x>::getImageDataDirectoryRva(dword dwDirectory) const 01775 { 01776 return m_inthHeader.dataDirectories[dwDirectory].VirtualAddress; 01777 } 01778 01784 template<int x> 01785 dword PeHeaderT<x>::getImageDataDirectorySize(dword dwDirectory) const 01786 { 01787 return m_inthHeader.dataDirectories[dwDirectory].Size; 01788 } 01789 01795 template<int x> 01796 std::string PeHeaderT<x>::getSectionName(word wSectionnr) const 01797 { 01798 std::string sectionName = ""; 01799 01800 for (unsigned int i=0;i<sizeof(m_vIsh[wSectionnr].Name);i++) 01801 { 01802 if (m_vIsh[wSectionnr].Name[i]) sectionName += m_vIsh[wSectionnr].Name[i]; 01803 } 01804 01805 return sectionName; 01806 } 01807 01813 template<int x> 01814 dword PeHeaderT<x>::getVirtualSize(word wSectionnr) const 01815 { 01816 return m_vIsh[wSectionnr].VirtualSize; 01817 } 01818 01824 template<int x> 01825 dword PeHeaderT<x>::getVirtualAddress(word wSectionnr) const 01826 { 01827 return m_vIsh[wSectionnr].VirtualAddress; 01828 } 01829 01835 template<int x> 01836 dword PeHeaderT<x>::getSizeOfRawData(word wSectionnr) const 01837 { 01838 return m_vIsh[wSectionnr].SizeOfRawData; 01839 } 01840 01846 template<int x> 01847 dword PeHeaderT<x>::getPointerToRawData(word wSectionnr) const 01848 { 01849 return m_vIsh[wSectionnr].PointerToRawData; 01850 } 01851 01857 template<int x> 01858 dword PeHeaderT<x>::getPointerToRelocations(word wSectionnr) const 01859 { 01860 return m_vIsh[wSectionnr].PointerToRelocations; 01861 } 01862 01868 template<int x> 01869 dword PeHeaderT<x>::getPointerToLinenumbers(word wSectionnr) const 01870 { 01871 return m_vIsh[wSectionnr].PointerToLinenumbers; 01872 } 01873 01879 template<int x> 01880 dword PeHeaderT<x>::getNumberOfRelocations(word wSectionnr) const 01881 { 01882 return m_vIsh[wSectionnr].NumberOfRelocations; 01883 } 01884 01890 template<int x> 01891 dword PeHeaderT<x>::getNumberOfLinenumbers(word wSectionnr) const 01892 { 01893 return m_vIsh[wSectionnr].NumberOfLinenumbers; 01894 } 01895 01901 template<int x> 01902 dword PeHeaderT<x>::getCharacteristics(word wSectionnr) const 01903 { 01904 return m_vIsh[wSectionnr].Characteristics; 01905 } 01906 01911 template<int x> 01912 void PeHeaderT<x>::setNtSignature(dword dwValue) 01913 { 01914 m_inthHeader.Signature = dwValue; 01915 } 01916 01921 template<int x> 01922 void PeHeaderT<x>::setMachine(word wValue) 01923 { 01924 m_inthHeader.FileHeader.Machine = wValue; 01925 } 01926 01931 template<int x> 01932 void PeHeaderT<x>::setNumberOfSections(word wValue) 01933 { 01934 m_inthHeader.FileHeader.NumberOfSections = wValue; 01935 } 01936 01941 template<int x> 01942 void PeHeaderT<x>::setTimeDateStamp(dword dwValue) 01943 { 01944 m_inthHeader.FileHeader.TimeDateStamp = dwValue; 01945 } 01946 01951 template<int x> 01952 void PeHeaderT<x>::setPointerToSymbolTable(dword dwValue) 01953 { 01954 m_inthHeader.FileHeader.PointerToSymbolTable = dwValue; 01955 } 01956 01961 template<int x> 01962 void PeHeaderT<x>::setNumberOfSymbols(dword dwValue) 01963 { 01964 m_inthHeader.FileHeader.NumberOfSymbols = dwValue; 01965 } 01966 01971 template<int x> 01972 void PeHeaderT<x>::setSizeOfOptionalHeader(word wValue) 01973 { 01974 m_inthHeader.FileHeader.SizeOfOptionalHeader = wValue; 01975 } 01976 01981 template<int x> 01982 void PeHeaderT<x>::setCharacteristics(word wValue) 01983 { 01984 m_inthHeader.FileHeader.Characteristics = wValue; 01985 } 01986 01991 template<int x> 01992 void PeHeaderT<x>::setMagic(word wValue) 01993 { 01994 m_inthHeader.OptionalHeader.Magic = wValue; 01995 } 01996 02001 template<int x> 02002 void PeHeaderT<x>::setMajorLinkerVersion(byte bValue) 02003 { 02004 m_inthHeader.OptionalHeader.MajorLinkerVersion = bValue; 02005 } 02006 02011 template<int x> 02012 void PeHeaderT<x>::setMinorLinkerVersion(byte bValue) 02013 { 02014 m_inthHeader.OptionalHeader.MinorLinkerVersion = bValue; 02015 } 02016 02021 template<int x> 02022 void PeHeaderT<x>::setSizeOfCode(dword dwValue) 02023 { 02024 m_inthHeader.OptionalHeader.SizeOfCode = dwValue; 02025 } 02026 02031 template<int x> 02032 void PeHeaderT<x>::setSizeOfInitializedData(dword dwValue) 02033 { 02034 m_inthHeader.OptionalHeader.SizeOfInitializedData = dwValue; 02035 } 02036 02041 template<int x> 02042 void PeHeaderT<x>::setSizeOfUninitializedData(dword dwValue) 02043 { 02044 m_inthHeader.OptionalHeader.SizeOfUninitializedData = dwValue; 02045 } 02046 02051 template<int x> 02052 void PeHeaderT<x>::setAddressOfEntryPoint(dword dwValue) 02053 { 02054 m_inthHeader.OptionalHeader.AddressOfEntryPoint = dwValue; 02055 } 02056 02061 template<int x> 02062 void PeHeaderT<x>::setBaseOfCode(dword dwValue) 02063 { 02064 m_inthHeader.OptionalHeader.BaseOfCode = dwValue; 02065 } 02066 02071 template<int x> 02072 void PeHeaderT<x>::setImageBase(typename FieldSizes<x>::VAR4_8 dwValue) 02073 { 02074 m_inthHeader.OptionalHeader.ImageBase = dwValue; 02075 } 02076 02081 template<int x> 02082 void PeHeaderT<x>::setSectionAlignment(dword dwValue) 02083 { 02084 m_inthHeader.OptionalHeader.SectionAlignment = dwValue; 02085 } 02086 02091 template<int x> 02092 void PeHeaderT<x>::setFileAlignment(dword dwValue) 02093 { 02094 m_inthHeader.OptionalHeader.FileAlignment = dwValue; 02095 } 02096 02101 template<int x> 02102 void PeHeaderT<x>::setMajorOperatingSystemVersion(word wValue) 02103 { 02104 m_inthHeader.OptionalHeader.MajorOperatingSystemVersion = wValue; 02105 } 02106 02111 template<int x> 02112 void PeHeaderT<x>::setMinorOperatingSystemVersion(word wValue) 02113 { 02114 m_inthHeader.OptionalHeader.MinorOperatingSystemVersion = wValue; 02115 } 02116 02121 template<int x> 02122 void PeHeaderT<x>::setMajorImageVersion(word wValue) 02123 { 02124 m_inthHeader.OptionalHeader.MajorImageVersion = wValue; 02125 } 02126 02131 template<int x> 02132 void PeHeaderT<x>::setMinorImageVersion(word wValue) 02133 { 02134 m_inthHeader.OptionalHeader.MinorImageVersion = wValue; 02135 } 02136 02141 template<int x> 02142 void PeHeaderT<x>::setMajorSubsystemVersion(word wValue) 02143 { 02144 m_inthHeader.OptionalHeader.MajorSubsystemVersion = wValue; 02145 } 02146 02151 template<int x> 02152 void PeHeaderT<x>::setMinorSubsystemVersion(word wValue) 02153 { 02154 m_inthHeader.OptionalHeader.MinorSubsystemVersion = wValue; 02155 } 02156 02161 template<int x> 02162 void PeHeaderT<x>::setWin32VersionValue(dword dwValue) 02163 { 02164 m_inthHeader.OptionalHeader.Win32VersionValue = dwValue; 02165 } 02166 02171 template<int x> 02172 void PeHeaderT<x>::setSizeOfImage(dword dwValue) 02173 { 02174 m_inthHeader.OptionalHeader.SizeOfImage = dwValue; 02175 } 02176 02181 template<int x> 02182 void PeHeaderT<x>::setSizeOfHeaders(dword dwValue) 02183 { 02184 m_inthHeader.OptionalHeader.SizeOfHeaders = dwValue; 02185 } 02186 02191 template<int x> 02192 void PeHeaderT<x>::setCheckSum(dword dwValue) 02193 { 02194 m_inthHeader.OptionalHeader.CheckSum = dwValue; 02195 } 02196 02201 template<int x> 02202 void PeHeaderT<x>::setSubsystem(word wValue) 02203 { 02204 m_inthHeader.OptionalHeader.Subsystem = wValue; 02205 } 02206 02211 template<int x> 02212 void PeHeaderT<x>::setDllCharacteristics(word wValue) 02213 { 02214 m_inthHeader.OptionalHeader.DllCharacteristics = wValue; 02215 } 02216 02221 template<int x> 02222 void PeHeaderT<x>::setSizeOfStackReserve(typename FieldSizes<x>::VAR4_8 dwValue) 02223 { 02224 m_inthHeader.OptionalHeader.SizeOfStackReserve = dwValue; 02225 } 02226 02231 template<int x> 02232 void PeHeaderT<x>::setSizeOfStackCommit(typename FieldSizes<x>::VAR4_8 dwValue) 02233 { 02234 m_inthHeader.OptionalHeader.SizeOfStackCommit = dwValue; 02235 } 02236 02241 template<int x> 02242 void PeHeaderT<x>::setSizeOfHeapReserve(typename FieldSizes<x>::VAR4_8 dwValue) 02243 { 02244 m_inthHeader.OptionalHeader.SizeOfHeapReserve = dwValue; 02245 } 02246 02251 template<int x> 02252 void PeHeaderT<x>::setSizeOfHeapCommit(typename FieldSizes<x>::VAR4_8 dwValue) 02253 { 02254 m_inthHeader.OptionalHeader.SizeOfHeapCommit = dwValue; 02255 } 02256 02261 template<int x> 02262 void PeHeaderT<x>::setLoaderFlags(dword dwValue) 02263 { 02264 m_inthHeader.OptionalHeader.LoaderFlags = dwValue; 02265 } 02266 02271 template<int x> 02272 void PeHeaderT<x>::setNumberOfRvaAndSizes(dword dwValue) 02273 { 02274 m_inthHeader.OptionalHeader.NumberOfRvaAndSizes = dwValue; 02275 } 02276 02277 template<int x> 02278 void PeHeaderT<x>::setIddDebugRva(dword dwValue) 02279 { 02280 m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress = dwValue; 02281 } 02282 02283 template<int x> 02284 void PeHeaderT<x>::setIddDebugSize(dword dwValue) 02285 { 02286 m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_DEBUG].Size = dwValue; 02287 } 02288 02289 template<int x> 02290 void PeHeaderT<x>::setIddDelayImportRva(dword dwValue) 02291 { 02292 m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT].VirtualAddress = dwValue; 02293 } 02294 02295 template<int x> 02296 void PeHeaderT<x>::setIddDelayImportSize(dword dwValue) 02297 { 02298 m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT].Size = dwValue; 02299 } 02300 02301 template<int x> 02302 void PeHeaderT<x>::setIddExceptionRva(dword dwValue) 02303 { 02304 m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_EXCEPTION].VirtualAddress = dwValue; 02305 } 02306 02307 template<int x> 02308 void PeHeaderT<x>::setIddExceptionSize(dword dwValue) 02309 { 02310 m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_EXCEPTION].Size = dwValue; 02311 } 02312 02313 template<int x> 02314 void PeHeaderT<x>::setIddGlobalPtrRva(dword dwValue) 02315 { 02316 m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_GLOBALPTR].VirtualAddress = dwValue; 02317 } 02318 02319 template<int x> 02320 void PeHeaderT<x>::setIddGlobalPtrSize(dword dwValue) 02321 { 02322 m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_GLOBALPTR].Size = dwValue; 02323 } 02324 02325 template<int x> 02326 void PeHeaderT<x>::setIddIatRva(dword dwValue) 02327 { 02328 m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_IAT].VirtualAddress = dwValue; 02329 } 02330 02331 template<int x> 02332 void PeHeaderT<x>::setIddIatSize(dword dwValue) 02333 { 02334 m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_IAT].Size = dwValue; 02335 } 02336 02337 template<int x> 02338 void PeHeaderT<x>::setIddLoadConfigRva(dword dwValue) 02339 { 02340 m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG].VirtualAddress = dwValue; 02341 } 02342 02343 template<int x> 02344 void PeHeaderT<x>::setIddLoadConfigSize(dword dwValue) 02345 { 02346 m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG].Size = dwValue; 02347 } 02348 02349 template<int x> 02350 void PeHeaderT<x>::setIddResourceRva(dword dwValue) 02351 { 02352 m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress = dwValue; 02353 } 02354 02355 template<int x> 02356 void PeHeaderT<x>::setIddResourceSize(dword dwValue) 02357 { 02358 m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_RESOURCE].Size = dwValue; 02359 } 02360 02361 template<int x> 02362 void PeHeaderT<x>::setIddSecurityRva(dword dwValue) 02363 { 02364 m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_SECURITY].VirtualAddress = dwValue; 02365 } 02366 02367 template<int x> 02368 void PeHeaderT<x>::setIddSecuritySize(dword dwValue) 02369 { 02370 m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_SECURITY].Size = dwValue; 02371 } 02372 02373 template<int x> 02374 void PeHeaderT<x>::setIddTlsRva(dword dwValue) 02375 { 02376 m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_TLS].VirtualAddress = dwValue; 02377 } 02378 02379 template<int x> 02380 void PeHeaderT<x>::setIddTlsSize(dword dwValue) 02381 { 02382 m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_TLS].Size = dwValue; 02383 } 02384 02389 template<int x> 02390 void PeHeaderT<x>::setIddExportRva(dword dwValue) 02391 { 02392 m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress = dwValue; 02393 } 02394 02399 template<int x> 02400 void PeHeaderT<x>::setIddExportSize(dword dwValue) 02401 { 02402 m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_EXPORT].Size = dwValue; 02403 } 02404 02409 template<int x> 02410 void PeHeaderT<x>::setIddImportRva(dword dwValue) 02411 { 02412 m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress = dwValue; 02413 } 02414 02419 template<int x> 02420 void PeHeaderT<x>::setIddImportSize(dword dwValue) 02421 { 02422 m_inthHeader.dataDirectories[IMAGE_DIRECTORY_ENTRY_IMPORT].Size = dwValue; 02423 } 02424 02430 template<int x> 02431 void PeHeaderT<x>::setSectionName(word wSectionnr, std::string strName) 02432 { 02433 strncpy(reinterpret_cast<char*>(m_vIsh[wSectionnr].Name), strName.c_str(), sizeof(m_vIsh[wSectionnr].Name)); 02434 } 02435 02441 template<int x> 02442 void PeHeaderT<x>::setVirtualSize(word wSectionnr, dword dwValue) 02443 { 02444 m_vIsh[wSectionnr].VirtualSize = dwValue; 02445 } 02446 02452 template<int x> 02453 void PeHeaderT<x>::setVirtualAddress(word wSectionnr, dword dwValue) 02454 { 02455 m_vIsh[wSectionnr].VirtualAddress = dwValue; 02456 } 02457 02463 template<int x> 02464 void PeHeaderT<x>::setSizeOfRawData(word wSectionnr, dword dwValue) 02465 { 02466 m_vIsh[wSectionnr].SizeOfRawData = dwValue; 02467 } 02468 02474 template<int x> 02475 void PeHeaderT<x>::setPointerToRawData(word wSectionnr, dword dwValue) 02476 { 02477 m_vIsh[wSectionnr].PointerToRawData = dwValue; 02478 } 02479 02485 template<int x> 02486 void PeHeaderT<x>::setPointerToRelocations(word wSectionnr, dword dwValue) 02487 { 02488 m_vIsh[wSectionnr].PointerToRelocations = dwValue; 02489 } 02490 02496 template<int x> 02497 void PeHeaderT<x>::setPointerToLinenumbers(word wSectionnr, dword dwValue) 02498 { 02499 m_vIsh[wSectionnr].PointerToLinenumbers = dwValue; 02500 } 02501 02507 template<int x> 02508 void PeHeaderT<x>::setNumberOfRelocations(word wSectionnr, dword dwValue) 02509 { 02510 m_vIsh[wSectionnr].NumberOfRelocations = dwValue; 02511 } 02512 02518 template<int x> 02519 void PeHeaderT<x>::setNumberOfLinenumbers(word wSectionnr, dword dwValue) 02520 { 02521 m_vIsh[wSectionnr].NumberOfLinenumbers = dwValue; 02522 } 02523 02529 template<int x> 02530 void PeHeaderT<x>::setCharacteristics(word wSectionnr, dword dwValue) 02531 { 02532 m_vIsh[wSectionnr].Characteristics = dwValue; 02533 } 02534 } 02535 02536 #endif

Generated on Mon Jan 17 20:50:08 2005 for PeLib by doxygen 1.3.7