vfs: check userland buffers before reading them.
[haiku.git] / src / tools / restest / ResourceFile.h
blob035c9d58e4c28e4f715b8b4f90df48217574e8ac
1 // ResourceFile.h
3 #ifndef RESOURCE_FILE_H
4 #define RESOURCE_FILE_H
6 #include <ByteOrder.h>
7 #include <List.h>
9 #include "OffsetFile.h"
11 class Exception;
12 class ResourceItem;
13 struct MemArea;
14 struct resource_info;
15 struct PEFContainerHeader;
17 class ResourceFile {
18 public:
19 ResourceFile();
20 virtual ~ResourceFile();
22 void Init(BFile& file); // throws Exception
23 void Unset();
24 status_t InitCheck() const;
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;
33 uint32 GetResourcesSize() const;
34 uint32 WriteResources(void* buffer, uint32 size);
35 void WriteTest();
37 void PrintToStream(bool longInfo = true);
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);
57 inline int16 _GetInt16(int16 value);
58 inline uint16 _GetUInt16(uint16 value);
59 inline int32 _GetInt32(int32 value);
60 inline uint32 _GetUInt32(uint32 value);
62 private:
63 BList fItems;
64 OffsetFile fFile;
65 uint32 fFileType;
66 off_t fFileSize;
67 int32 fResourceCount;
68 ResourceItem* fInfoTableItem;
69 bool fHostEndianess;
72 // _GetInt16
73 inline
74 int16
75 ResourceFile::_GetInt16(int16 value)
77 return (fHostEndianess ? value : B_SWAP_INT16(value));
80 // _GetUInt16
81 inline
82 uint16
83 ResourceFile::_GetUInt16(uint16 value)
85 return (fHostEndianess ? value : B_SWAP_INT16(value));
88 // _GetInt32
89 inline
90 int32
91 ResourceFile::_GetInt32(int32 value)
93 return (fHostEndianess ? value : B_SWAP_INT32(value));
96 // _GetUInt32
97 inline
98 uint32
99 ResourceFile::_GetUInt32(uint32 value)
101 return (fHostEndianess ? value : B_SWAP_INT32(value));
105 #endif // RESOURCE_FILE_H