| ... | @@ -39,6 +39,18 @@ pub const Coff = struct { | ... | @@ -39,6 +39,18 @@ pub const Coff = struct { |
| 39 | guid: [16]u8, | 39 | guid: [16]u8, |
| 40 | age: u32, | 40 | age: u32, |
| 41 | | 41 | |
| | 42 | pub fn init(allocator: *mem.Allocator, in_file: File) Coff { |
| | 43 | return Coff{ |
| | 44 | .in_file = in_file, |
| | 45 | .allocator = allocator, |
| | 46 | .coff_header = undefined, |
| | 47 | .pe_header = undefined, |
| | 48 | .sections = ArrayList(Section).init(allocator), |
| | 49 | .guid = undefined, |
| | 50 | .age = undefined, |
| | 51 | }; |
| | 52 | } |
| | 53 | |
| 42 | pub fn loadHeader(self: *Coff) !void { | 54 | pub fn loadHeader(self: *Coff) !void { |
| 43 | const pe_pointer_offset = 0x3C; | 55 | const pe_pointer_offset = 0x3C; |
| 44 | | 56 | |
| ... | @@ -142,10 +154,10 @@ pub const Coff = struct { | ... | @@ -142,10 +154,10 @@ pub const Coff = struct { |
| 142 | } | 154 | } |
| 143 | | 155 | |
| 144 | pub fn loadSections(self: *Coff) !void { | 156 | pub fn loadSections(self: *Coff) !void { |
| 145 | if (self.sections.len != 0) | 157 | if (self.sections.len == self.coff_header.number_of_sections) |
| 146 | return; | 158 | return; |
| 147 | | 159 | |
| 148 | self.sections = ArrayList(Section).init(self.allocator); | 160 | try self.sections.ensureCapacity(self.coff_header.number_of_sections); |
| 149 | | 161 | |
| 150 | var file_stream = self.in_file.inStream(); | 162 | var file_stream = self.in_file.inStream(); |
| 151 | const in = &file_stream.stream; | 163 | const in = &file_stream.stream; |