1 #ifndef LOADER_OBJECTFILE_H_
2 #define LOADER_OBJECTFILE_H_
8 const unsigned int FORMAT_ID = 2;
11 /// Offset of the identifier in the file.
12 unsigned int nameOffset;
13 /// Type ID of referenced object.
15 /// File-offset of the object's actual data.
16 unsigned int dataOffset;
20 /// File-relative offset of the referenced object's
22 unsigned int nameOffset;
23 /// Target position for linking/inlining.
24 unsigned int referenceOffset;
27 /// True if the object should be copied rather that
28 /// just writing a reference.
33 /// File-relative offset to the image's path string.
34 unsigned int pathOffset;
35 /// File-relative offset of the target position of the
36 /// image's reference.
37 unsigned int destOffset;
64 struct ObjectFileHeader {
68 /// Version ID of the object file format
69 /// For now it must match FORMAT_ID for the loader to be
71 /// Backwards compatibility might be implemented at some
72 /// point in the future, but don't bet on that ever
74 unsigned int versionId;
76 /// File-relative offsets of the export section's begin
77 /// and end respectively.
78 /// Exports are named and typed addresses within the
79 /// file. This is essentially an array of Export structs.
80 unsigned int exportsBegin;
81 unsigned int exportsEnd;
83 /// File-relative offsets of the externals section's
84 /// begin and end respectively.
85 /// Each external names an entity which must be linked in
86 /// for this object file to function properly. This is
87 /// essentially an array of External structs.
88 unsigned int externalsBegin;
89 unsigned int externalsEnd;
91 /// File-relative offsets of the image section's begin and
93 /// Denotes an array of Image structs.
94 unsigned int imagesBegin;
95 unsigned int imagesEnd;
97 /// File-relative offsets of the objet section's begin
98 /// and end respectively.
99 /// Each object begins with its type ID followed by its
100 /// size and finally the raw object data.
101 /// All referecte type fields should contain either a
102 /// file-relative offset or zero to indicate a null
104 /// This can be sen as a linked list where the next
105 /// object for a node can be obtained by adding the size
106 /// of to int and the object to the current node's
108 unsigned int objectsBegin;
109 unsigned int objectsEnd;
111 /// File-relative offsets of the array section's begin
112 /// and end respectively.
113 /// Each array consists of an unsigned integer indicating
114 /// its size followed by a boolean flag which is true if
115 /// the arrays consists of pointers followed by the data.
116 unsigned int arraysBegin;
117 unsigned int arraysEnd;
119 /// File-relative offsets of the script section's begin
120 /// and end respectively.
121 /// Each script is an unsigned int with the length in
122 /// bytes followed by the script text.
123 unsigned int scriptsBegin;
124 unsigned int scriptsEnd;
128 /// Check if there are any problems with the file header.
129 /// Throws a std::runtime_error on failure.
130 void IntegrityCheck(unsigned int fileSize) const;
131 Export *ExportsBegin();
132 Export *ExportsEnd();
133 External *ExternalsBegin();
134 External *ExternalsEnd();
135 Image *ImagesBegin();
137 Object *ObjectsBegin();
138 Object *ObjectsEnd();
139 Array *ArraysBegin();
141 Script *ScriptsBegin();
142 Script *ScriptsEnd();
148 unsigned int fsize) const;
151 struct LoadedExport {