hxpeff.h
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:7k
源码类别:

Symbian

开发平台:

Visual C++

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