hxpeff.h
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:6k
源码类别:

Symbian

开发平台:

C/C++

  1. /* ***** BEGIN LICENSE BLOCK ***** 
  2.  * Version: RCSL 1.0/RPSL 1.0 
  3.  *  
  4.  * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 
  5.  *      
  6.  * The contents of this file, and the files included with this file, are 
  7.  * subject to the current version of the RealNetworks Public Source License 
  8.  * Version 1.0 (the "RPSL") available at 
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed 
  10.  * the file under the RealNetworks Community Source License Version 1.0 
  11.  * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 
  12.  * in which case the RCSL will apply. You may also obtain the license terms 
  13.  * directly from RealNetworks.  You may not use this file except in 
  14.  * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 
  15.  * applicable to this file, the RCSL.  Please see the applicable RPSL or 
  16.  * RCSL for the rights, obligations and limitations governing use of the 
  17.  * contents of the file.  
  18.  *  
  19.  * This file is part of the Helix DNA Technology. RealNetworks is the 
  20.  * developer of the Original Code and owns the copyrights in the portions 
  21.  * it created. 
  22.  *  
  23.  * This file, and the files included with this file, is distributed and made 
  24.  * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  25.  * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  26.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 
  27.  * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
  28.  * 
  29.  * Technology Compatibility Kit Test Suite(s) Location: 
  30.  *    http://www.helixcommunity.org/content/tck 
  31.  * 
  32.  * Contributor(s): 
  33.  *  
  34.  * ***** END LICENSE BLOCK ***** */ 
  35. #ifndef _hxpeff_h
  36. #define _hxpeff_h
  37. #include "chxdataf.h"
  38. #include "hxtypes.h"
  39. #include "hxresult.h"
  40. #include "littobig.h"
  41. /*
  42. MACROS
  43. */
  44. //
  45. // Used to make reading in the headers easier to write.
  46. //
  47. #define     IF_ERROR_RETURN(x) if (x != HXR_OK) return x
  48. /*
  49. DEFINITIONS
  50. */
  51. #ifndef _WIN32
  52. #define IMAGE_DOS_SIGNATURE 0x5A4D
  53. #define IMAGE_OS2_SIGNATURE 0x454E
  54. #define IMAGE_OS2_SIGNATURE_LE 0x454C
  55. #define IMAGE_NT_SIGNATURE 0x00004550
  56. #endif
  57. #define SIZE_OF_NT_SIGNATURE sizeof(ULONG32)
  58. /*
  59. Structures
  60. */
  61. /*
  62. This is the DOS file image header.
  63. */
  64. typedef struct _HX_IMAGE_DOS_HEADER
  65. {
  66. UINT16 e_magic;
  67. UINT16 e_cblp;
  68. UINT16 e_cp;
  69. UINT16 e_crlc;
  70. UINT16 e_cparhdr;
  71. UINT16 e_minalloc;
  72. UINT16 e_maxalloc;
  73. UINT16 e_ss;
  74. UINT16 e_sp;
  75. UINT16 e_csum;
  76. UINT16 e_ip;
  77. UINT16 e_cs;
  78. UINT16 e_lfarlc;
  79. UINT16 e_ovno;
  80. UINT16 e_res[4];
  81. UINT16 e_oemid;
  82. UINT16 e_oeminfo;
  83. UINT16 e_res2[10];
  84. ULONG32 e_lfanew;
  85. } HX_IMAGE_DOS_HEADER, *PHX_IMAGE_DOS_HEADER;
  86. /*
  87. This structure is the PEF file header.
  88. */
  89. typedef struct _HX_IMAGE_FILE_HEADER
  90. {
  91. UINT16 Machine;
  92. UINT16 NumberOfSections;
  93. ULONG32 TimeDateStamp;
  94. ULONG32 PointerToSymbolTable;
  95. ULONG32 NumberOfSymbols;
  96. UINT16 SizeOfOptionalHeader;
  97. UINT16 Characteristics;
  98. } HX_IMAGE_FILE_HEADER, *PHX_IMAGE_FILE_HEADER;
  99. #define IMAGE_SIZEOF_FILE_HEADER 20
  100. typedef struct _HX_IMAGE_DATA_DIRECTORY {
  101.     ULONG32   VirtualAddress;
  102.     ULONG32   Size;
  103. } HX_IMAGE_DATA_DIRECTORY, *PHX_IMAGE_DATA_DIRECTORY;
  104. #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES    16
  105. typedef struct _HX_IMAGE_FILE_OPTIONAL_HEADER
  106. {
  107. UINT16 Magic;
  108. UCHAR MajorLinkerVersion;
  109. UCHAR MinorLinkerVersion;
  110. ULONG32 SizeOfCode;
  111. ULONG32 SizeOfInitializedData;
  112. ULONG32 SizeOfUninitializedData;
  113. ULONG32 AddressOfEntryPoint;
  114. ULONG32 BaseOfCode;
  115. ULONG32 BaseOfData;
  116. //
  117. // NT Additional fields.
  118. //
  119. ULONG32 ImageBase;
  120. ULONG32 SectionAlignment;
  121. ULONG32 FileAlignment;
  122. UINT16 MajorOperatingSystemVersion;
  123. UINT16  MinorOperatingSystemVersion;
  124. UINT16  MajorImageVersion;
  125. UINT16 MinorImageVersion;
  126. UINT16 MajorSubsystemVersion;
  127. UINT16 MinorSubsystemVersion;
  128. ULONG32 Reserved1;
  129. ULONG32 SizeOfImage;
  130. ULONG32 SizeOfHeaders;
  131. ULONG32 CheckSum;
  132. UINT16 Subsystem;
  133. UINT16 DllCharacteristics;
  134. ULONG32 SizeOfStackReserve;
  135. ULONG32 SizeOfStackCommit;
  136. ULONG32 SizeOfHeapReserve;
  137. ULONG32 SizeOfHeapCommit;
  138. ULONG32 LoaderFlags;
  139. ULONG32 NumberOfRvaAndSizes;
  140. HX_IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
  141. } HX_IMAGE_FILE_OPTIONAL_HEADER,  *PHX_IMAGE_FILE_OPTIONAL_HEADER;
  142. #define  IMAGE_SIZEOF_SHORT_NAME 8
  143. typedef  struct _HX_IMAGE_SECTION_HEADER 
  144. {
  145. UCHAR Name[IMAGE_SIZEOF_SHORT_NAME];
  146. union
  147. {
  148. ULONG32 PhysicalAddress;
  149. ULONG32 VirtualSize;
  150. } Misc;
  151. ULONG32 VirtualAddress;
  152. ULONG32 SizeOfRawData;
  153. ULONG32 PointerToRawData;
  154. ULONG32 PointerToRelocations;
  155. ULONG32 PointerToLinenumbers;
  156. UINT16 NumberOfRelocations;
  157. UINT16 NumberOfLinenumbers;
  158. ULONG32 Characteristics;
  159. } HX_IMAGE_SECTION_HEADER, *PHX_IMAGE_SECTION_HEADER;
  160. class CHXPeff : public CLittleEndianToBigEndian
  161. {
  162. public:
  163. CHXPeff();
  164. ~CHXPeff();
  165. HX_RESULT open(const char*  path);
  166. HX_RESULT close();
  167. HX_RESULT FindSectionNamed(const char* name, ULONG32& size, ULONG32& pos);
  168. HX_RESULT GetSectionHeaderNamed(const char* name,HX_IMAGE_SECTION_HEADER& h);
  169. //
  170. // Utility functions.
  171. //
  172. HX_RESULT GetDosHeader(HX_IMAGE_DOS_HEADER* header) { memcpy(header,&mDosHeader,sizeof(mDosHeader)); return HXR_OK;}; /* Flawfinder: ignore */
  173. HX_RESULT GetPeffHeader(HX_IMAGE_FILE_HEADER* header) { memcpy(header,&mPeffHeader,sizeof(mPeffHeader)); return HXR_OK;}; /* Flawfinder: ignore */
  174. HX_RESULT GetPeffOptHeader(HX_IMAGE_FILE_OPTIONAL_HEADER* header) { memcpy(header,&mOptionalPeffHeader,sizeof(mOptionalPeffHeader)); return HXR_OK;}; /* Flawfinder: ignore */
  175. CHXDataFile*   mFile;
  176. protected:
  177. HX_RESULT ReadByte(UCHAR&   sz);
  178. HX_RESULT ReadWord(UINT16& w);
  179. HX_RESULT ReadDWord(ULONG32& dw);
  180. BOOL   mBigEndian; // Used to store the test for big endianness.
  181. ULONG32   mPeffDataStart;
  182. private:
  183. HX_RESULT FindPeffDataStart(void);
  184. HX_RESULT InitializeHeaderMembers(void);
  185. HX_RESULT InitializePeffHeader(void);
  186. HX_RESULT InitializeDosHeader(void);
  187. HX_RESULT InitializeOptionalPeffHeader(void);
  188. HX_RESULT GetSectionHeader(HX_IMAGE_SECTION_HEADER&   header);
  189. HX_IMAGE_DOS_HEADER mDosHeader;
  190. HX_IMAGE_FILE_HEADER mPeffHeader;
  191. HX_IMAGE_FILE_OPTIONAL_HEADER mOptionalPeffHeader;
  192. UINT16 mNumberOfSections;
  193. UINT16 mCurrentSection;
  194. };
  195. #endif //_hxpeff_h