home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 March / CMCD0304.ISO / Software / Freeware / Programare / nullsoft / nsis20.exe / Source / ResourceEditor.h < prev    next >
C/C++ Source or Header  |  2004-02-05  |  5KB  |  170 lines

  1. /*
  2.   Copyright (C) 2002 Amir Szekely <kichik@netvision.net.il>
  3.  
  4.   This software is provided 'as-is', without any express or implied
  5.   warranty.  In no event will the authors be held liable for any damages
  6.   arising from the use of this software.
  7.  
  8.   Permission is granted to anyone to use this software for any purpose,
  9.   including commercial applications, and to alter it and redistribute it
  10.   freely, subject to the following restrictions:
  11.  
  12.   1. The origin of this software must not be misrepresented; you must not
  13.   claim that you wrote the original software. If you use this software
  14.   in a product, an acknowledgment in the product documentation would be
  15.   appreciated but is not required.
  16.  
  17.   2. Altered source versions must be plainly marked as such, and must not be
  18.   misrepresented as being the original software.
  19.  
  20.   3. This notice may not be removed or altered from any source distribution.
  21. */
  22.  
  23. #if !defined(AFX_RESOURCEEDITOR_H__683BF710_E805_4093_975B_D5729186A89A__INCLUDED_)
  24. #define AFX_RESOURCEEDITOR_H__683BF710_E805_4093_975B_D5729186A89A__INCLUDED_
  25.  
  26. #if _MSC_VER > 1000
  27. #pragma once
  28. #endif // _MSC_VER > 1000
  29.  
  30. #ifdef RESOURCE_EDITOR_NOT_API
  31.  
  32. #include "Platform.h"
  33. #include <WinNT.h>
  34. #include <Time.h>
  35. #include <Vector>
  36. #include <Queue>
  37.  
  38. #endif // #ifdef RESOURCE_EDITOR_NOT_API
  39.  
  40. #include <StdExcept>
  41. using namespace std;
  42.  
  43. class CResourceDirectory;
  44. class CResourceDirectoryEntry;
  45. class CResourceDataEntry;
  46.  
  47. // Resource directory with entries
  48. typedef struct RESOURCE_DIRECTORY {
  49.   IMAGE_RESOURCE_DIRECTORY Header;
  50.   IMAGE_RESOURCE_DIRECTORY_ENTRY Entries[1];
  51. } *PRESOURCE_DIRECTORY;
  52.  
  53. class CResourceEditor {
  54. public:
  55.   CResourceEditor(BYTE* pbPE, int iSize);
  56.   virtual ~CResourceEditor();
  57.  
  58.   bool  UpdateResource(char* szType, char* szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize);
  59.   bool  UpdateResource(WORD szType, char* szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize);
  60.   bool  UpdateResource(char* szType, WORD szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize);
  61.   bool  UpdateResource(WORD szType, WORD szName, LANGID wLanguage, BYTE* lpData, DWORD dwSize);
  62.   BYTE* GetResource(char* szType, char* szName, LANGID wLanguage);
  63.   void  FreeResource(BYTE* pbResource);
  64.  
  65.   bool  AddExtraVirtualSize2PESection(const char* pszSectionName, int addsize);
  66.   DWORD Save(BYTE* pbBuf, DWORD &dwSize);
  67.  
  68. private:
  69.   BYTE* m_pbPE;
  70.   int   m_iSize;
  71.  
  72.   PIMAGE_DOS_HEADER m_dosHeader;
  73.   PIMAGE_NT_HEADERS m_ntHeaders;
  74.  
  75.   DWORD m_dwResourceSectionIndex;
  76.   DWORD m_dwResourceSectionVA;
  77.  
  78.   CResourceDirectory* m_cResDir;
  79.  
  80.   CResourceDirectory* ScanDirectory(PRESOURCE_DIRECTORY rdRoot, PRESOURCE_DIRECTORY rdToScan);
  81.  
  82.   void WriteRsrcSec(BYTE* pbRsrcSec);
  83.   void SetOffsets(CResourceDirectory* resDir, DWORD newResDirAt);
  84. };
  85.  
  86. #ifdef RESOURCE_EDITOR_NOT_API
  87.  
  88. class CResourceDirectory {
  89. public:
  90.   CResourceDirectory(PIMAGE_RESOURCE_DIRECTORY prd);
  91.   virtual ~CResourceDirectory();
  92.  
  93.   IMAGE_RESOURCE_DIRECTORY GetInfo();
  94.  
  95.   CResourceDirectoryEntry* GetEntry(unsigned int i);
  96.   void AddEntry(CResourceDirectoryEntry* entry);
  97.   void RemoveEntry(int i);
  98.   int  CountEntries();
  99.   int  Find(char* szName);
  100.   int  Find(WORD wId);
  101.  
  102.   DWORD GetSize();
  103.  
  104.   void Destroy();
  105.  
  106.   DWORD m_dwWrittenAt;
  107.  
  108. private:
  109.   IMAGE_RESOURCE_DIRECTORY m_rdDir;
  110.   vector<CResourceDirectoryEntry*> m_vEntries;
  111. };
  112.  
  113. class CResourceDirectoryEntry {
  114. public:
  115.   CResourceDirectoryEntry(char* szName, CResourceDirectory* rdSubDir);
  116.   CResourceDirectoryEntry(char* szName, CResourceDataEntry* rdeData);
  117.   virtual ~CResourceDirectoryEntry();
  118.  
  119.   bool HasName();
  120.   char* GetName();
  121.   int GetNameLength();
  122.  
  123.   WORD GetId();
  124.  
  125.   bool IsDataDirectory();
  126.   CResourceDirectory* GetSubDirectory();
  127.  
  128.   CResourceDataEntry* GetDataEntry();
  129.  
  130.   DWORD m_dwWrittenAt;
  131.  
  132. private:
  133.   bool m_bHasName;
  134.   union {
  135.     char* m_szName;
  136.     WORD m_wId;
  137.   };
  138.  
  139.   bool m_bIsDataDirectory;
  140.   union {
  141.     CResourceDirectory* m_rdSubDir;
  142.     CResourceDataEntry* m_rdeData;
  143.   };
  144. };
  145.  
  146. class CResourceDataEntry {
  147. public:
  148.   CResourceDataEntry(BYTE* pbData, DWORD dwSize, DWORD dwCodePage = 0);
  149.   ~CResourceDataEntry();
  150.  
  151.   BYTE* GetData();
  152.  
  153.   void SetData(BYTE* pbData, DWORD dwSize);
  154.   void SetData(BYTE* pbData, DWORD dwSize, DWORD dwCodePage);
  155.  
  156.   DWORD GetSize();
  157.   DWORD GetCodePage();
  158.  
  159.   DWORD m_dwWrittenAt;
  160.  
  161. private:
  162.   BYTE* m_pbData;
  163.   DWORD m_dwSize;
  164.   DWORD m_dwCodePage;
  165. };
  166.  
  167. #endif // #ifdef RESOURCE_EDITOR_NOT_API
  168.  
  169. #endif // !defined(AFX_RESOURCEEDITOR_H__683BF710_E805_4093_975B_D5729186A89A__INCLUDED_)
  170.