diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-09-12 14:26:21 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-09-12 14:26:21 -0400 |
| commit | a75753338657b85588fe6c54a40fecac0584b336 (patch) | |
| tree | 9d0e1f367a172d04284b808c629394b4e45d7a98 /std/coff.zig | |
| parent | 178d69191ba008dffd70d2854df09cec556b59dd (diff) | |
| download | zig-a75753338657b85588fe6c54a40fecac0584b336.tar.gz zig-a75753338657b85588fe6c54a40fecac0584b336.zip | |
fix zig fmt on windows
closes #1069
Diffstat (limited to 'std/coff.zig')
| -rw-r--r-- | std/coff.zig | 52 |
1 files changed, 23 insertions, 29 deletions
diff --git a/std/coff.zig b/std/coff.zig index 379fd1af42..bf5a93ef30 100644 --- a/std/coff.zig +++ b/std/coff.zig @@ -8,9 +8,9 @@ const ArrayList = std.ArrayList; // CoffHeader.machine values // see https://msdn.microsoft.com/en-us/library/windows/desktop/ms680313(v=vs.85).aspx -const IMAGE_FILE_MACHINE_I386 = 0x014c; -const IMAGE_FILE_MACHINE_IA64 = 0x0200; -const IMAGE_FILE_MACHINE_AMD64 = 0x8664; +const IMAGE_FILE_MACHINE_I386 = 0x014c; +const IMAGE_FILE_MACHINE_IA64 = 0x0200; +const IMAGE_FILE_MACHINE_AMD64 = 0x8664; // OptionalHeader.magic values // see https://msdn.microsoft.com/en-us/library/windows/desktop/ms680339(v=vs.85).aspx @@ -20,7 +20,7 @@ const IMAGE_NT_OPTIONAL_HDR64_MAGIC = 0x20b; const IMAGE_NUMBEROF_DIRECTORY_ENTRIES = 16; const DEBUG_DIRECTORY = 6; -pub const CoffError = error { +pub const CoffError = error{ InvalidPEMagic, InvalidPEHeader, InvalidMachine, @@ -56,24 +56,21 @@ pub const Coff = struct { var pe_header_magic: [4]u8 = undefined; try in.readNoEof(pe_header_magic[0..]); - if (!mem.eql(u8, pe_header_magic, []u8{'P', 'E', 0, 0})) + if (!mem.eql(u8, pe_header_magic, []u8{ 'P', 'E', 0, 0 })) return error.InvalidPEHeader; - self.coff_header = CoffHeader { + self.coff_header = CoffHeader{ .machine = try in.readIntLe(u16), - .number_of_sections = try in.readIntLe(u16), - .timedate_stamp = try in.readIntLe(u32), - .pointer_to_symbol_table = try in.readIntLe(u32), - .number_of_symbols = try in.readIntLe(u32), - .size_of_optional_header = try in.readIntLe(u16), - .characteristics = try in.readIntLe(u16), + .number_of_sections = try in.readIntLe(u16), + .timedate_stamp = try in.readIntLe(u32), + .pointer_to_symbol_table = try in.readIntLe(u32), + .number_of_symbols = try in.readIntLe(u32), + .size_of_optional_header = try in.readIntLe(u16), + .characteristics = try in.readIntLe(u16), }; switch (self.coff_header.machine) { - IMAGE_FILE_MACHINE_I386, - IMAGE_FILE_MACHINE_AMD64, - IMAGE_FILE_MACHINE_IA64 - => {}, + IMAGE_FILE_MACHINE_I386, IMAGE_FILE_MACHINE_AMD64, IMAGE_FILE_MACHINE_IA64 => {}, else => return error.InvalidMachine, } @@ -89,11 +86,9 @@ pub const Coff = struct { var skip_size: u16 = undefined; if (self.pe_header.magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC) { skip_size = 2 * @sizeOf(u8) + 8 * @sizeOf(u16) + 18 * @sizeOf(u32); - } - else if (self.pe_header.magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC) { + } else if (self.pe_header.magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC) { skip_size = 2 * @sizeOf(u8) + 8 * @sizeOf(u16) + 12 * @sizeOf(u32) + 5 * @sizeOf(u64); - } - else + } else return error.InvalidPEMagic; try self.in_file.seekForward(skip_size); @@ -103,7 +98,7 @@ pub const Coff = struct { return error.InvalidPEHeader; for (self.pe_header.data_directory) |*data_dir| { - data_dir.* = OptionalHeader.DataDirectory { + data_dir.* = OptionalHeader.DataDirectory{ .virtual_address = try in.readIntLe(u32), .size = try in.readIntLe(u32), }; @@ -114,7 +109,7 @@ pub const Coff = struct { try self.loadSections(); const header = (self.getSection(".rdata") orelse return error.MissingCoffSection).header; - // The linker puts a chunk that contains the .pdb path right after the + // The linker puts a chunk that contains the .pdb path right after the // debug_directory. const debug_dir = &self.pe_header.data_directory[DEBUG_DIRECTORY]; const file_offset = debug_dir.virtual_address - header.virtual_address + header.pointer_to_raw_data; @@ -159,10 +154,10 @@ pub const Coff = struct { var i: u16 = 0; while (i < self.coff_header.number_of_sections) : (i += 1) { try in.readNoEof(name[0..]); - try self.sections.append(Section { - .header = SectionHeader { + try self.sections.append(Section{ + .header = SectionHeader{ .name = name, - .misc = SectionHeader.Misc { .physical_address = try in.readIntLe(u32) }, + .misc = SectionHeader.Misc{ .physical_address = try in.readIntLe(u32) }, .virtual_address = try in.readIntLe(u32), .size_of_raw_data = try in.readIntLe(u32), .pointer_to_raw_data = try in.readIntLe(u32), @@ -184,7 +179,6 @@ pub const Coff = struct { } return null; } - }; const CoffHeader = struct { @@ -194,13 +188,13 @@ const CoffHeader = struct { pointer_to_symbol_table: u32, number_of_symbols: u32, size_of_optional_header: u16, - characteristics: u16 + characteristics: u16, }; const OptionalHeader = struct { const DataDirectory = struct { virtual_address: u32, - size: u32 + size: u32, }; magic: u16, @@ -214,7 +208,7 @@ pub const Section = struct { const SectionHeader = struct { const Misc = union { physical_address: u32, - virtual_size: u32 + virtual_size: u32, }; name: [8]u8, |
