1 // ResourceFile.h 2 3 #ifndef RESOURCE_FILE_H 4 #define RESOURCE_FILE_H 5 6 #include <ByteOrder.h> 7 #include <List.h> 8 9 #include "OffsetFile.h" 10 11 class Exception; 12 class ResourceItem; 13 struct MemArea; 14 struct resource_info; 15 struct PEFContainerHeader; 16 17 class ResourceFile { 18 public: 19 ResourceFile(); 20 virtual ~ResourceFile(); 21 22 void Init(BFile& file); // throws Exception 23 void Unset(); 24 status_t InitCheck() const; 25 26 bool AddItem(ResourceItem* item, int32 index = -1); 27 ResourceItem* RemoveItem(int32 index); 28 bool RemoveItem(ResourceItem* item); 29 int32 IndexOf(ResourceItem* item) const; 30 ResourceItem* ItemAt(int32 index) const; 31 int32 CountItems() const; 32 33 uint32 GetResourcesSize() const; 34 uint32 WriteResources(void* buffer, uint32 size); 35 void WriteTest(); 36 37 void PrintToStream(bool longInfo = true); 38 39 private: 40 void _InitFile(BFile& file); 41 void _InitELFFile(BFile& file); 42 void _InitPEFFile(BFile& file, 43 const PEFContainerHeader& pefHeader); 44 void _ReadHeader(); 45 void _ReadIndex(); 46 bool _ReadIndexEntry(int32 index, 47 uint32 tableOffset, 48 bool peekAhead); 49 void _ReadInfoTable(); 50 bool _ReadInfoTableEnd(const void* data, 51 int32 dataSize); 52 const void* _ReadResourceInfo(const MemArea& area, 53 const resource_info* info, 54 type_code type, 55 bool* readIndices); 56 57 inline int16 _GetInt16(int16 value); 58 inline uint16 _GetUInt16(uint16 value); 59 inline int32 _GetInt32(int32 value); 60 inline uint32 _GetUInt32(uint32 value); 61 62 private: 63 BList fItems; 64 OffsetFile fFile; 65 uint32 fFileType; 66 off_t fFileSize; 67 int32 fResourceCount; 68 ResourceItem* fInfoTableItem; 69 bool fHostEndianess; 70 }; 71 72 // _GetInt16 73 inline 74 int16 75 ResourceFile::_GetInt16(int16 value) 76 { 77 return (fHostEndianess ? value : B_SWAP_INT16(value)); 78 } 79 80 // _GetUInt16 81 inline 82 uint16 83 ResourceFile::_GetUInt16(uint16 value) 84 { 85 return (fHostEndianess ? value : B_SWAP_INT16(value)); 86 } 87 88 // _GetInt32 89 inline 90 int32 91 ResourceFile::_GetInt32(int32 value) 92 { 93 return (fHostEndianess ? value : B_SWAP_INT32(value)); 94 } 95 96 // _GetUInt32 97 inline 98 uint32 99 ResourceFile::_GetUInt32(uint32 value) 100 { 101 return (fHostEndianess ? value : B_SWAP_INT32(value)); 102 } 103 104 105 #endif // RESOURCE_FILE_H 106