diff --git a/SabreTools.Serialization/Extensions.PortableExecutable.cs b/SabreTools.Serialization/Extensions.PortableExecutable.cs index e6c0a479..494a0a81 100644 --- a/SabreTools.Serialization/Extensions.PortableExecutable.cs +++ b/SabreTools.Serialization/Extensions.PortableExecutable.cs @@ -27,26 +27,26 @@ namespace SabreTools.Serialization return 0; // If the RVA matches a section start exactly, use that - var matchingSection = Array.Find(sections, s => s != null && s.VirtualAddress == rva); + var matchingSection = Array.Find(sections, s => s.VirtualAddress == rva); if (matchingSection != null) return rva - matchingSection.VirtualAddress + matchingSection.PointerToRawData; // Loop through all of the sections for (int i = 0; i < sections.Length; i++) { - // If the section is invalid, just skip it - if (sections[i] == null) + // If the section "starts" at 0, just skip it + var section = sections[i]; + if (section.PointerToRawData == 0) continue; - // If the section "starts" at 0, just skip it - if (sections[i]!.PointerToRawData == 0) + // If the virtual address is greater than the RVA + if (rva < section.VirtualAddress) continue; // Attempt to derive the physical address from the current section - var section = sections[i]!; - if (rva >= section.VirtualAddress && section.VirtualSize != 0 && rva <= section.VirtualAddress + section.VirtualSize) + if (section.VirtualSize != 0 && rva <= section.VirtualAddress + section.VirtualSize) return rva - section.VirtualAddress + section.PointerToRawData; - else if (rva >= section.VirtualAddress && section.SizeOfRawData != 0 && rva <= section.VirtualAddress + section.SizeOfRawData) + else if (section.SizeOfRawData != 0 && rva <= section.VirtualAddress + section.SizeOfRawData) return rva - section.VirtualAddress + section.PointerToRawData; } @@ -72,19 +72,19 @@ namespace SabreTools.Serialization // Loop through all of the sections for (int i = 0; i < sections.Length; i++) { - // If the section is invalid, just skip it - var section = sections[i]; - if (section == null) - continue; - // If the section "starts" at 0, just skip it + var section = sections[i]; if (section.PointerToRawData == 0) continue; + // If the virtual address is greater than the RVA + if (rva < section.VirtualAddress) + continue; + // Attempt to derive the physical address from the current section - if (rva >= section.VirtualAddress && section.VirtualSize != 0 && rva <= section.VirtualAddress + section.VirtualSize) + if (section.VirtualSize != 0 && rva <= section.VirtualAddress + section.VirtualSize) return i; - else if (rva >= section.VirtualAddress && section.SizeOfRawData != 0 && rva <= section.VirtualAddress + section.SizeOfRawData) + else if (section.SizeOfRawData != 0 && rva <= section.VirtualAddress + section.SizeOfRawData) return i; } diff --git a/SabreTools.Serialization/Printers/AACSMediaKeyBlock.cs b/SabreTools.Serialization/Printers/AACSMediaKeyBlock.cs index 3c57422a..41f4c13f 100644 --- a/SabreTools.Serialization/Printers/AACSMediaKeyBlock.cs +++ b/SabreTools.Serialization/Printers/AACSMediaKeyBlock.cs @@ -35,6 +35,7 @@ namespace SabreTools.Serialization.Printers var record = records[i]; Print(builder, record, i); } + builder.AppendLine(); } @@ -84,17 +85,11 @@ namespace SabreTools.Serialization.Printers private static void Print(StringBuilder builder, EndOfMediaKeyBlockRecord record) { - if (record == null) - return; - builder.AppendLine(record.SignatureData, " Signature data"); } - private static void Print(StringBuilder builder, ExplicitSubsetDifferenceRecord? record) + private static void Print(StringBuilder builder, ExplicitSubsetDifferenceRecord record) { - if (record == null) - return; - builder.AppendLine(" Subset Differences:"); builder.AppendLine(" -------------------------"); if (record?.SubsetDifferences == null || record.SubsetDifferences.Length == 0) @@ -103,27 +98,18 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < record.SubsetDifferences.Length; j++) + for (int i = 0; i < record.SubsetDifferences.Length; i++) { - var sd = record.SubsetDifferences[j]; - builder.AppendLine($" Subset Difference {j}"); - if (sd == null) - { - builder.AppendLine(" [NULL]"); - } - else - { - builder.AppendLine(sd.Mask, " Mask"); - builder.AppendLine(sd.Number, " Number"); - } + var sd = record.SubsetDifferences[i]; + + builder.AppendLine($" Subset Difference {i}"); + builder.AppendLine(sd.Mask, " Mask"); + builder.AppendLine(sd.Number, " Number"); } } - private static void Print(StringBuilder builder, MediaKeyDataRecord? record) + private static void Print(StringBuilder builder, MediaKeyDataRecord record) { - if (record == null) - return; - builder.AppendLine(" Media Keys:"); builder.AppendLine(" -------------------------"); if (record?.MediaKeyData == null || record.MediaKeyData.Length == 0) @@ -132,18 +118,15 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < record.MediaKeyData.Length; j++) + for (int i = 0; i < record.MediaKeyData.Length; i++) { - var mk = record.MediaKeyData[j]; - builder.AppendLine(mk, $" Media key {j}"); + var mk = record.MediaKeyData[i]; + builder.AppendLine(mk, $" Media key {i}"); } } - private static void Print(StringBuilder builder, SubsetDifferenceIndexRecord? record) + private static void Print(StringBuilder builder, SubsetDifferenceIndexRecord record) { - if (record == null) - return; - builder.AppendLine($" Span: {record.Span} (0x{record.Span:X})"); builder.AppendLine(" Offsets:"); builder.AppendLine(" -------------------------"); @@ -153,27 +136,21 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < record.Offsets.Length; j++) + for (int i = 0; i < record.Offsets.Length; i++) { - var offset = record.Offsets[j]; - builder.AppendLine(offset, $" Offset {j}"); + var offset = record.Offsets[i]; + builder.AppendLine(offset, $" Offset {i}"); } } - private static void Print(StringBuilder builder, TypeAndVersionRecord? record) + private static void Print(StringBuilder builder, TypeAndVersionRecord record) { - if (record == null) - return; - builder.AppendLine($" Media key block type: {record.MediaKeyBlockType} (0x{record.MediaKeyBlockType:X})"); builder.AppendLine(record.VersionNumber, " Version number"); } - private static void Print(StringBuilder builder, DriveRevocationListRecord? record) + private static void Print(StringBuilder builder, DriveRevocationListRecord record) { - if (record == null) - return; - builder.AppendLine(record.TotalNumberOfEntries, " Total number of entries"); builder.AppendLine(" Signature Blocks:"); builder.AppendLine(" -------------------------"); @@ -183,48 +160,33 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < record.SignatureBlocks.Length; j++) + for (int i = 0; i < record.SignatureBlocks.Length; i++) { - var block = record.SignatureBlocks[j]; - builder.AppendLine($" Signature Block {j}"); - if (block == null) - { - builder.AppendLine(" [NULL]"); - continue; - } + var block = record.SignatureBlocks[i]; + builder.AppendLine($" Signature Block {i}"); builder.AppendLine(block.NumberOfEntries, " Number of entries"); builder.AppendLine(" Entry Fields:"); builder.AppendLine(" -------------------------"); if (block.EntryFields == null || block.EntryFields.Length == 0) { builder.AppendLine(" No entry fields"); + continue; } - else + + for (int j = 0; j < block.EntryFields.Length; j++) { - for (int k = 0; k < block.EntryFields.Length; k++) - { - var ef = block.EntryFields[k]; - builder.AppendLine($" Entry {k}"); - if (ef == null) - { - builder.AppendLine(" [NULL]"); - } - else - { - builder.AppendLine(ef.Range, " Range"); - builder.AppendLine(ef.DriveID, " Drive ID"); - } - } + var ef = block.EntryFields[j]; + + builder.AppendLine($" Entry {j}"); + builder.AppendLine(ef.Range, " Range"); + builder.AppendLine(ef.DriveID, " Drive ID"); } } } - private static void Print(StringBuilder builder, HostRevocationListRecord? record) + private static void Print(StringBuilder builder, HostRevocationListRecord record) { - if (record == null) - return; - builder.AppendLine($" Total number of entries: {record.TotalNumberOfEntries} (0x{record.TotalNumberOfEntries:X})"); builder.AppendLine(" Signature Blocks:"); builder.AppendLine(" -------------------------"); @@ -234,16 +196,11 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < record.SignatureBlocks.Length; j++) + for (int i = 0; i < record.SignatureBlocks.Length; i++) { - builder.AppendLine($" Signature Block {j}"); - var block = record.SignatureBlocks[j]; - if (block == null) - { - builder.AppendLine(" [NULL]"); - continue; - } + var block = record.SignatureBlocks[i]; + builder.AppendLine($" Signature Block {i}"); builder.AppendLine(block.NumberOfEntries, " Number of entries"); builder.AppendLine(" Entry Fields:"); builder.AppendLine(" -------------------------"); @@ -253,37 +210,24 @@ namespace SabreTools.Serialization.Printers continue; } - for (int k = 0; k < block.EntryFields.Length; k++) + for (int j = 0; j < block.EntryFields.Length; j++) { - var ef = block.EntryFields[k]; - builder.AppendLine($" Entry {k}"); - if (ef == null) - { - builder.AppendLine(" [NULL]"); - } - else - { + var ef = block.EntryFields[j]; - builder.AppendLine(ef.Range, " Range"); - builder.AppendLine(ef.HostID, " Host ID"); - } + builder.AppendLine($" Entry {j}"); + builder.AppendLine(ef.Range, " Range"); + builder.AppendLine(ef.HostID, " Host ID"); } } } - private static void Print(StringBuilder builder, VerifyMediaKeyRecord? record) + private static void Print(StringBuilder builder, VerifyMediaKeyRecord record) { - if (record == null) - return; - builder.AppendLine(record.CiphertextValue, " Ciphertext value"); } - private static void Print(StringBuilder builder, CopyrightRecord? record) + private static void Print(StringBuilder builder, CopyrightRecord record) { - if (record == null) - return; - builder.AppendLine(record.Copyright, " Copyright"); } } diff --git a/SabreTools.Serialization/Printers/BSP.cs b/SabreTools.Serialization/Printers/BSP.cs index 59bece65..723bf6e6 100644 --- a/SabreTools.Serialization/Printers/BSP.cs +++ b/SabreTools.Serialization/Printers/BSP.cs @@ -52,14 +52,9 @@ namespace SabreTools.Serialization.Printers string specialLumpName = GetLumpName(i); builder.AppendLine($" Lump {i}{specialLumpName}"); - if (lump == null) - { - builder.AppendLine(" [NULL]"); - continue; - } - builder.AppendLine(lump.Offset, " Offset"); builder.AppendLine(lump.Length, " Length"); + switch ((LumpType)i) { case LumpType.LUMP_ENTITIES: @@ -112,6 +107,7 @@ namespace SabreTools.Serialization.Printers break; } } + builder.AppendLine(); } @@ -146,12 +142,12 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < lump.Entities.Length; j++) + for (int i = 0; i < lump.Entities.Length; i++) { // TODO: Implement entity printing - var entity = lump.Entities[j]; - builder.AppendLine($" Entity {j}"); - builder.AppendLine(" Entity data is not parsed properly"); + var entity = lump.Entities[i]; + + builder.AppendLine($" Entity {i}: Not printed yet"); } } @@ -163,10 +159,11 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < lump.Planes.Length; j++) + for (int i = 0; i < lump.Planes.Length; i++) { - var plane = lump.Planes[j]; - builder.AppendLine($" Plane {j}"); + var plane = lump.Planes[i]; + + builder.AppendLine($" Plane {i}"); builder.AppendLine($" Normal vector: ({plane.NormalVector?.X}, {plane.NormalVector?.Y}, {plane.NormalVector?.Z})"); builder.AppendLine(plane.Distance, " Distance"); builder.AppendLine($" Plane type: {plane.PlaneType} (0x{plane.PlaneType:X})"); @@ -192,22 +189,22 @@ namespace SabreTools.Serialization.Printers builder.AppendLine(lump.Header.Offsets, " Offsets"); } + builder.AppendLine(" Textures:"); if (lump?.Textures == null || lump.Textures.Length == 0) { builder.AppendLine(" No texture data"); + return; } - else + + for (int i = 0; i < lump.Textures.Length; i++) { - builder.AppendLine(" Textures:"); - for (int j = 0; j < lump.Textures.Length; j++) - { - var texture = lump.Textures[j]; - builder.AppendLine($" Texture {j}"); - builder.AppendLine(texture.Name, " Name"); - builder.AppendLine(texture.Width, " Width"); - builder.AppendLine(texture.Height, " Height"); - builder.AppendLine(texture.Offsets, " Offsets"); - } + var texture = lump.Textures[i]; + + builder.AppendLine($" Texture {i}"); + builder.AppendLine(texture.Name, " Name"); + builder.AppendLine(texture.Width, " Width"); + builder.AppendLine(texture.Height, " Height"); + builder.AppendLine(texture.Offsets, " Offsets"); } } @@ -219,10 +216,10 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < lump.Vertices.Length; j++) + for (int i = 0; i < lump.Vertices.Length; i++) { - var vertex = lump.Vertices[j]; - builder.AppendLine($" Vertex {j}: ({vertex.X}, {vertex.Y}, {vertex.Z})"); + var vertex = lump.Vertices[i]; + builder.AppendLine($" Vertex {i}: ({vertex.X}, {vertex.Y}, {vertex.Z})"); } } @@ -246,10 +243,11 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < lump.Nodes.Length; j++) + for (int i = 0; i < lump.Nodes.Length; i++) { - var node = lump.Nodes[j]; - builder.AppendLine($" Node {j}"); + var node = lump.Nodes[i]; + + builder.AppendLine($" Node {i}"); builder.AppendLine(node.Children, " Children"); builder.AppendLine(node.Mins, " Mins"); builder.AppendLine(node.Maxs, " Maxs"); @@ -266,10 +264,11 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < lump.Texinfos.Length; j++) + for (int i = 0; i < lump.Texinfos.Length; i++) { - var texinfo = lump.Texinfos[j]; - builder.AppendLine($" Texinfo {j}"); + var texinfo = lump.Texinfos[i]; + + builder.AppendLine($" Texinfo {i}"); builder.AppendLine($" S-Vector: ({texinfo.SVector?.X}, {texinfo.SVector?.Y}, {texinfo.SVector?.Z})"); builder.AppendLine(texinfo.TextureSShift, " Texture shift in S direction"); builder.AppendLine($" T-Vector: ({texinfo.TVector?.X}, {texinfo.TVector?.Y}, {texinfo.TVector?.Z})"); @@ -287,10 +286,11 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < lump.Faces.Length; j++) + for (int i = 0; i < lump.Faces.Length; i++) { - var face = lump.Faces[j]; - builder.AppendLine($" Face {j}"); + var face = lump.Faces[i]; + + builder.AppendLine($" Face {i}"); builder.AppendLine(face.PlaneIndex, " Plane index"); builder.AppendLine(face.PlaneSideCount, " Plane side count"); builder.AppendLine(face.FirstEdgeIndex, " First surfedge index"); @@ -317,10 +317,11 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < lump.Clipnodes.Length; j++) + for (int i = 0; i < lump.Clipnodes.Length; i++) { - var clipnode = lump.Clipnodes[j]; - builder.AppendLine($" Clipnode {j}"); + var clipnode = lump.Clipnodes[i]; + + builder.AppendLine($" Clipnode {i}"); builder.AppendLine(clipnode.PlaneIndex, " Plane index"); builder.AppendLine(clipnode.ChildrenIndices, " Children indices"); } @@ -334,10 +335,11 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < lump.Leaves.Length; j++) + for (int i = 0; i < lump.Leaves.Length; i++) { - var leaf = lump.Leaves[j]; - builder.AppendLine($" Leaf {j}"); + var leaf = lump.Leaves[i]; + + builder.AppendLine($" Leaf {i}"); builder.AppendLine($" Contents: {leaf.Contents} (0x{leaf.Contents:X})"); builder.AppendLine(leaf.VisOffset, " Visibility offset"); builder.AppendLine(leaf.Mins, " Mins"); @@ -356,10 +358,10 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < lump.Marksurfaces.Length; j++) + for (int i = 0; i < lump.Marksurfaces.Length; i++) { - var marksurface = lump.Marksurfaces[j]; - builder.AppendLine(marksurface, $" Marksurface {j}"); + var marksurface = lump.Marksurfaces[i]; + builder.AppendLine(marksurface, $" Marksurface {i}"); } } @@ -371,10 +373,10 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < lump.Edges.Length; j++) + for (int i = 0; i < lump.Edges.Length; i++) { - var edge = lump.Edges[j]; - builder.AppendLine($" Edge {j}"); + var edge = lump.Edges[i]; + builder.AppendLine($" Edge {i}"); builder.AppendLine(edge.VertexIndices, " Vertex indices"); } } @@ -387,10 +389,10 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < lump.Surfedges.Length; j++) + for (int i = 0; i < lump.Surfedges.Length; i++) { - var surfedge = lump.Surfedges[j]; - builder.AppendLine(surfedge, $" Surfedge {j}"); + var surfedge = lump.Surfedges[i]; + builder.AppendLine(surfedge, $" Surfedge {i}"); } } @@ -402,10 +404,11 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < lump.Models.Length; j++) + for (int i = 0; i < lump.Models.Length; i++) { - var bmodel = lump.Models[j]; - builder.AppendLine($" Model {j}"); + var bmodel = lump.Models[i]; + + builder.AppendLine($" Model {i}"); builder.AppendLine($" Mins: {bmodel.Mins?.X}, {bmodel.Mins?.Y}, {bmodel.Mins?.Z}"); builder.AppendLine($" Maxs: {bmodel.Maxs?.X}, {bmodel.Maxs?.Y}, {bmodel.Maxs?.Z}"); builder.AppendLine($" Origin vector: {bmodel.OriginVector?.X}, {bmodel.OriginVector?.Y}, {bmodel.OriginVector?.Z}"); diff --git a/SabreTools.Serialization/Printers/CFB.cs b/SabreTools.Serialization/Printers/CFB.cs index e5b61c3d..1cc9ec39 100644 --- a/SabreTools.Serialization/Printers/CFB.cs +++ b/SabreTools.Serialization/Printers/CFB.cs @@ -63,56 +63,58 @@ namespace SabreTools.Serialization.Printers { builder.AppendLine($" DIFAT Entry {i}: {header.DIFAT[i]} (0x{header.DIFAT[i]:X})"); } + builder.AppendLine(); } - private static void Print(StringBuilder builder, SectorNumber[]? sectorNumbers, string name) + private static void Print(StringBuilder builder, SectorNumber[]? entries, string name) { builder.AppendLine($" {name} Sectors Information:"); builder.AppendLine(" -------------------------"); - if (sectorNumbers == null || sectorNumbers.Length == 0) + if (entries == null || entries.Length == 0) { builder.AppendLine($" No {name} sectors"); builder.AppendLine(); return; } - for (int i = 0; i < sectorNumbers.Length; i++) + for (int i = 0; i < entries.Length; i++) { - builder.AppendLine($" {name} Sector Entry {i}: {sectorNumbers[i]} (0x{sectorNumbers[i]:X})"); + builder.AppendLine($" {name} Sector Entry {i}: {entries[i]} (0x{entries[i]:X})"); } + builder.AppendLine(); } - private static void Print(StringBuilder builder, DirectoryEntry[]? directoryEntries) + private static void Print(StringBuilder builder, DirectoryEntry[]? entries) { builder.AppendLine(" Directory Entries Information:"); builder.AppendLine(" -------------------------"); - if (directoryEntries == null || directoryEntries.Length == 0) + if (entries == null || entries.Length == 0) { builder.AppendLine(" No directory entries"); builder.AppendLine(); return; } - for (int i = 0; i < directoryEntries.Length; i++) + for (int i = 0; i < entries.Length; i++) { - var directoryEntry = directoryEntries[i]; + var entry = entries[i]; builder.AppendLine($" Directory Entry {i}"); - builder.AppendLine(directoryEntry.Name, " Name"); - builder.AppendLine(directoryEntry.NameLength, " Name length"); - builder.AppendLine($" Object type: {directoryEntry.ObjectType} (0x{directoryEntry.ObjectType:X})"); - builder.AppendLine($" Color flag: {directoryEntry.ColorFlag} (0x{directoryEntry.ColorFlag:X})"); - builder.AppendLine($" Left sibling ID: {directoryEntry.LeftSiblingID} (0x{directoryEntry.LeftSiblingID:X})"); - builder.AppendLine($" Right sibling ID: {directoryEntry.RightSiblingID} (0x{directoryEntry.RightSiblingID:X})"); - builder.AppendLine($" Child ID: {directoryEntry.ChildID} (0x{directoryEntry.ChildID:X})"); - builder.AppendLine(directoryEntry.CLSID, " CLSID"); - builder.AppendLine(directoryEntry.StateBits, " State bits"); - builder.AppendLine(directoryEntry.CreationTime, " Creation time"); - builder.AppendLine(directoryEntry.ModifiedTime, " Modification time"); - builder.AppendLine(directoryEntry.StartingSectorLocation, " Staring sector location"); - builder.AppendLine(directoryEntry.StreamSize, " Stream size"); + builder.AppendLine(entry.Name, " Name"); + builder.AppendLine(entry.NameLength, " Name length"); + builder.AppendLine($" Object type: {entry.ObjectType} (0x{entry.ObjectType:X})"); + builder.AppendLine($" Color flag: {entry.ColorFlag} (0x{entry.ColorFlag:X})"); + builder.AppendLine($" Left sibling ID: {entry.LeftSiblingID} (0x{entry.LeftSiblingID:X})"); + builder.AppendLine($" Right sibling ID: {entry.RightSiblingID} (0x{entry.RightSiblingID:X})"); + builder.AppendLine($" Child ID: {entry.ChildID} (0x{entry.ChildID:X})"); + builder.AppendLine(entry.CLSID, " CLSID"); + builder.AppendLine(entry.StateBits, " State bits"); + builder.AppendLine(entry.CreationTime, " Creation time"); + builder.AppendLine(entry.ModifiedTime, " Modification time"); + builder.AppendLine(entry.StartingSectorLocation, " Staring sector location"); + builder.AppendLine(entry.StreamSize, " Stream size"); } builder.AppendLine(); diff --git a/SabreTools.Serialization/Printers/CIA.cs b/SabreTools.Serialization/Printers/CIA.cs index a7d7e05d..aa9de05c 100644 --- a/SabreTools.Serialization/Printers/CIA.cs +++ b/SabreTools.Serialization/Printers/CIA.cs @@ -71,12 +71,6 @@ namespace SabreTools.Serialization.Printers } builder.AppendLine($" Certificate {i}{certificateName}"); - if (certificate == null) - { - builder.AppendLine(" [NULL]"); - continue; - } - builder.AppendLine($" Signature type: {certificate.SignatureType} (0x{certificate.SignatureType:X})"); builder.AppendLine(certificate.SignatureSize, " Signature size"); builder.AppendLine(certificate.PaddingSize, " Padding size"); @@ -100,6 +94,7 @@ namespace SabreTools.Serialization.Printers break; } } + builder.AppendLine(); } @@ -175,12 +170,6 @@ namespace SabreTools.Serialization.Printers } builder.AppendLine($" Certificate {i}{certificateName}"); - if (certificate == null) - { - builder.AppendLine(" [NULL]"); - continue; - } - builder.AppendLine($" Signature type: {certificate.SignatureType} (0x{certificate.SignatureType:X})"); builder.AppendLine(certificate.SignatureSize, " Signature size"); builder.AppendLine(certificate.PaddingSize, " Padding size"); @@ -205,6 +194,7 @@ namespace SabreTools.Serialization.Printers } } } + builder.AppendLine(); } @@ -257,18 +247,14 @@ namespace SabreTools.Serialization.Printers for (int i = 0; i < tmd.ContentInfoRecords.Length; i++) { var contentInfoRecord = tmd.ContentInfoRecords[i]; - builder.AppendLine($" Content Info Record {i}"); - if (contentInfoRecord == null) - { - builder.AppendLine(" [NULL]"); - continue; - } + builder.AppendLine($" Content Info Record {i}"); builder.AppendLine(contentInfoRecord.ContentIndexOffset, " Content index offset"); builder.AppendLine(contentInfoRecord.ContentCommandCount, " Content command count"); builder.AppendLine(contentInfoRecord.UnhashedContentRecordsSHA256Hash, $" SHA-256 hash of the next {contentInfoRecord.ContentCommandCount} records not hashed"); } } + builder.AppendLine(); builder.AppendLine(" Ticket Content Chunk Records Information:"); @@ -282,13 +268,8 @@ namespace SabreTools.Serialization.Printers for (int i = 0; i < tmd.ContentChunkRecords.Length; i++) { var contentChunkRecord = tmd.ContentChunkRecords[i]; - builder.AppendLine($" Content Chunk Record {i}"); - if (contentChunkRecord == null) - { - builder.AppendLine(" [NULL]"); - continue; - } + builder.AppendLine($" Content Chunk Record {i}"); builder.AppendLine(contentChunkRecord.ContentId, " Content ID"); builder.AppendLine($" Content index: {contentChunkRecord.ContentIndex} (0x{contentChunkRecord.ContentIndex:X})"); builder.AppendLine($" Content type: {contentChunkRecord.ContentType} (0x{contentChunkRecord.ContentType:X})"); @@ -296,6 +277,7 @@ namespace SabreTools.Serialization.Printers builder.AppendLine(contentChunkRecord.SHA256Hash, " SHA-256 hash"); } } + builder.AppendLine(); builder.AppendLine(" Ticket Certificate Chain Information:"); @@ -318,12 +300,6 @@ namespace SabreTools.Serialization.Printers } builder.AppendLine($" Certificate {i}{certificateName}"); - if (certificate == null) - { - builder.AppendLine(" [NULL]"); - continue; - } - builder.AppendLine($" Signature type: {certificate.SignatureType} (0x{certificate.SignatureType:X})"); builder.AppendLine(certificate.SignatureSize, " Signature size"); builder.AppendLine(certificate.PaddingSize, " Padding size"); @@ -348,6 +324,7 @@ namespace SabreTools.Serialization.Printers } } } + builder.AppendLine(); } @@ -365,13 +342,8 @@ namespace SabreTools.Serialization.Printers for (int i = 0; i < partitions.Length; i++) { var partitionHeader = partitions[i]; - builder.AppendLine($" NCCH Partition Header {i}"); - if (partitionHeader == null) - { - builder.AppendLine(" [NULL]"); - continue; - } + builder.AppendLine($" NCCH Partition Header {i}"); if (partitionHeader.MagicID == string.Empty) { builder.AppendLine(" Empty partition, no data can be parsed"); @@ -428,6 +400,7 @@ namespace SabreTools.Serialization.Printers builder.AppendLine(partitionHeader.ExeFSSuperblockHash, " ExeFS superblock SHA-256 hash"); builder.AppendLine(partitionHeader.RomFSSuperblockHash, " RomFS superblock SHA-256 hash"); } + builder.AppendLine(); } @@ -449,6 +422,5 @@ namespace SabreTools.Serialization.Printers builder.AppendLine(metaData.IconData, " Icon data"); builder.AppendLine(); } - } } \ No newline at end of file diff --git a/SabreTools.Serialization/Printers/InstallShieldCabinet.cs b/SabreTools.Serialization/Printers/InstallShieldCabinet.cs index c178ada3..7d09101f 100644 --- a/SabreTools.Serialization/Printers/InstallShieldCabinet.cs +++ b/SabreTools.Serialization/Printers/InstallShieldCabinet.cs @@ -163,6 +163,7 @@ namespace SabreTools.Serialization.Printers builder.AppendLine(descriptor.FileGroupOffsets[i], $" File Group Offset {i}"); } } + builder.AppendLine(); builder.AppendLine(" Component offsets:"); @@ -178,6 +179,7 @@ namespace SabreTools.Serialization.Printers builder.AppendLine(descriptor.ComponentOffsets[i], $" Component Offset {i}"); } } + builder.AppendLine(); builder.AppendLine(descriptor.SetupTypesOffset, " Setup types offset"); @@ -202,6 +204,7 @@ namespace SabreTools.Serialization.Printers { builder.AppendLine(entries[i], $" File Descriptor Offset {i}"); } + builder.AppendLine(); } @@ -220,6 +223,7 @@ namespace SabreTools.Serialization.Printers { builder.AppendLine(entries[i], $" Directory Name {i}"); } + builder.AppendLine(); } @@ -284,6 +288,7 @@ namespace SabreTools.Serialization.Printers builder.AppendLine(value.DescriptorOffset, " Descriptor offset"); builder.AppendLine(value.NextOffset, " Next offset"); } + builder.AppendLine(); } @@ -300,31 +305,27 @@ namespace SabreTools.Serialization.Printers for (int i = 0; i < entries.Length; i++) { - var fileGroup = entries[i]; - builder.AppendLine($" File Group {i}:"); - if (fileGroup == null) - { - builder.AppendLine(" Unassigned file group"); - continue; - } + var entry = entries[i]; - builder.AppendLine(fileGroup.NameOffset, " Name offset"); - builder.AppendLine(fileGroup.Name, " Name"); - builder.AppendLine(fileGroup.ExpandedSize, " Expanded size"); - builder.AppendLine(fileGroup.CompressedSize, " Compressed size"); - builder.AppendLine($" Attributes: {fileGroup.Attributes} (0x{fileGroup.Attributes:X})"); - builder.AppendLine(fileGroup.FirstFile, " First file"); - builder.AppendLine(fileGroup.LastFile, " Last file"); - builder.AppendLine(fileGroup.UnknownStringOffset, " Unknown string offset"); - builder.AppendLine(fileGroup.OperatingSystemOffset, " Operating system offset"); - builder.AppendLine(fileGroup.LanguageOffset, " Language offset"); - builder.AppendLine(fileGroup.HTTPLocationOffset, " HTTP location offset"); - builder.AppendLine(fileGroup.FTPLocationOffset, " FTP location offset"); - builder.AppendLine(fileGroup.MiscOffset, " Misc. offset"); - builder.AppendLine(fileGroup.TargetDirectoryOffset, " Target directory offset"); - builder.AppendLine($" Overwrite flags: {fileGroup.OverwriteFlags} (0x{fileGroup.OverwriteFlags:X})"); - builder.AppendLine(fileGroup.Reserved, " Reserved"); + builder.AppendLine($" File Group {i}:"); + builder.AppendLine(entry.NameOffset, " Name offset"); + builder.AppendLine(entry.Name, " Name"); + builder.AppendLine(entry.ExpandedSize, " Expanded size"); + builder.AppendLine(entry.CompressedSize, " Compressed size"); + builder.AppendLine($" Attributes: {entry.Attributes} (0x{entry.Attributes:X})"); + builder.AppendLine(entry.FirstFile, " First file"); + builder.AppendLine(entry.LastFile, " Last file"); + builder.AppendLine(entry.UnknownStringOffset, " Unknown string offset"); + builder.AppendLine(entry.OperatingSystemOffset, " Operating system offset"); + builder.AppendLine(entry.LanguageOffset, " Language offset"); + builder.AppendLine(entry.HTTPLocationOffset, " HTTP location offset"); + builder.AppendLine(entry.FTPLocationOffset, " FTP location offset"); + builder.AppendLine(entry.MiscOffset, " Misc. offset"); + builder.AppendLine(entry.TargetDirectoryOffset, " Target directory offset"); + builder.AppendLine($" Overwrite flags: {entry.OverwriteFlags} (0x{entry.OverwriteFlags:X})"); + builder.AppendLine(entry.Reserved, " Reserved"); } + builder.AppendLine(); } @@ -341,64 +342,61 @@ namespace SabreTools.Serialization.Printers for (int i = 0; i < entries.Length; i++) { - var component = entries[i]; - builder.AppendLine($" Component {i}:"); - if (component == null) - { - builder.AppendLine(" Unassigned component"); - continue; - } + var entry = entries[i]; - builder.AppendLine(component.IdentifierOffset, " Identifier offset"); - builder.AppendLine(component.Identifier, " Identifier"); - builder.AppendLine(component.DescriptorOffset, " Descriptor offset"); - builder.AppendLine(component.DisplayNameOffset, " Display name offset"); - builder.AppendLine(component.DisplayName, " Display name"); - builder.AppendLine($" Status: {component.Status} (0x{component.Status:X})"); - builder.AppendLine(component.PasswordOffset, " Password offset"); - builder.AppendLine(component.MiscOffset, " Misc. offset"); - builder.AppendLine(component.ComponentIndex, " Component index"); - builder.AppendLine(component.NameOffset, " Name offset"); - builder.AppendLine(component.Name, " Name"); - builder.AppendLine(component.CDRomFolderOffset, " CD-ROM folder offset"); - builder.AppendLine(component.HTTPLocationOffset, " HTTP location offset"); - builder.AppendLine(component.FTPLocationOffset, " FTP location offset"); - builder.AppendLine(component.Guid, " GUIDs"); - builder.AppendLine(component.CLSIDOffset, " CLSID offset"); - builder.AppendLine(component.CLSID, " CLSID"); - builder.AppendLine(component.Reserved2, " Reserved 2"); - builder.AppendLine(component.Reserved3, " Reserved 3"); - builder.AppendLine(component.DependsCount, " Depends count"); - builder.AppendLine(component.DependsOffset, " Depends offset"); - builder.AppendLine(component.FileGroupCount, " File group count"); - builder.AppendLine(component.FileGroupNamesOffset, " File group names offset"); + builder.AppendLine($" Component {i}:"); + builder.AppendLine(entry.IdentifierOffset, " Identifier offset"); + builder.AppendLine(entry.Identifier, " Identifier"); + builder.AppendLine(entry.DescriptorOffset, " Descriptor offset"); + builder.AppendLine(entry.DisplayNameOffset, " Display name offset"); + builder.AppendLine(entry.DisplayName, " Display name"); + builder.AppendLine($" Status: {entry.Status} (0x{entry.Status:X})"); + builder.AppendLine(entry.PasswordOffset, " Password offset"); + builder.AppendLine(entry.MiscOffset, " Misc. offset"); + builder.AppendLine(entry.ComponentIndex, " Component index"); + builder.AppendLine(entry.NameOffset, " Name offset"); + builder.AppendLine(entry.Name, " Name"); + builder.AppendLine(entry.CDRomFolderOffset, " CD-ROM folder offset"); + builder.AppendLine(entry.HTTPLocationOffset, " HTTP location offset"); + builder.AppendLine(entry.FTPLocationOffset, " FTP location offset"); + builder.AppendLine(entry.Guid, " GUIDs"); + builder.AppendLine(entry.CLSIDOffset, " CLSID offset"); + builder.AppendLine(entry.CLSID, " CLSID"); + builder.AppendLine(entry.Reserved2, " Reserved 2"); + builder.AppendLine(entry.Reserved3, " Reserved 3"); + builder.AppendLine(entry.DependsCount, " Depends count"); + builder.AppendLine(entry.DependsOffset, " Depends offset"); + builder.AppendLine(entry.FileGroupCount, " File group count"); + builder.AppendLine(entry.FileGroupNamesOffset, " File group names offset"); builder.AppendLine(); builder.AppendLine(" File group names:"); builder.AppendLine(" -------------------------"); - if (component.FileGroupNames == null || component.FileGroupNames.Length == 0) + if (entry.FileGroupNames == null || entry.FileGroupNames.Length == 0) { builder.AppendLine(" No file group names"); } else { - for (int j = 0; j < component.FileGroupNames.Length; j++) + for (int j = 0; j < entry.FileGroupNames.Length; j++) { - builder.AppendLine(component.FileGroupNames[j], $" File Group Name {j}"); + builder.AppendLine(entry.FileGroupNames[j], $" File Group Name {j}"); } } + builder.AppendLine(); - builder.AppendLine(component.X3Count, " X3 count"); - builder.AppendLine(component.X3Offset, " X3 offset"); - builder.AppendLine(component.SubComponentsCount, " Sub-components count"); - builder.AppendLine(component.SubComponentsOffset, " Sub-components offset"); - builder.AppendLine(component.NextComponentOffset, " Next component offset"); - builder.AppendLine(component.OnInstallingOffset, " On installing offset"); - builder.AppendLine(component.OnInstalledOffset, " On installed offset"); - builder.AppendLine(component.OnUninstallingOffset, " On uninstalling offset"); - builder.AppendLine(component.OnUninstalledOffset, " On uninstalled offset"); + builder.AppendLine(entry.X3Count, " X3 count"); + builder.AppendLine(entry.X3Offset, " X3 offset"); + builder.AppendLine(entry.SubComponentsCount, " Sub-components count"); + builder.AppendLine(entry.SubComponentsOffset, " Sub-components offset"); + builder.AppendLine(entry.NextComponentOffset, " Next component offset"); + builder.AppendLine(entry.OnInstallingOffset, " On installing offset"); + builder.AppendLine(entry.OnInstalledOffset, " On installed offset"); + builder.AppendLine(entry.OnUninstallingOffset, " On uninstalling offset"); + builder.AppendLine(entry.OnUninstalledOffset, " On uninstalled offset"); } + builder.AppendLine(); } } diff --git a/SabreTools.Serialization/Printers/LinearExecutable.cs b/SabreTools.Serialization/Printers/LinearExecutable.cs index 41f6d06d..32f458cf 100644 --- a/SabreTools.Serialization/Printers/LinearExecutable.cs +++ b/SabreTools.Serialization/Printers/LinearExecutable.cs @@ -239,26 +239,26 @@ namespace SabreTools.Serialization.Printers builder.AppendLine(); } - private static void Print(StringBuilder builder, EntryTableBundle[]? bundles) + private static void Print(StringBuilder builder, EntryTableBundle[]? entries) { builder.AppendLine(" Entry Table Information:"); builder.AppendLine(" -------------------------"); - if (bundles == null || bundles.Length == 0) + if (entries == null || entries.Length == 0) { builder.AppendLine(" No entry table bundles"); builder.AppendLine(); return; } - for (int i = 0; i < bundles.Length; i++) + for (int i = 0; i < entries.Length; i++) { - var bundle = bundles[i]; + var entry = entries[i]; builder.AppendLine($" Entry Table Bundle {i}"); - builder.AppendLine(bundle.Entries, " Entries"); - builder.AppendLine($" Bundle type: {bundle.BundleType} (0x{bundle.BundleType:X})"); + builder.AppendLine(entry.Entries, " Entries"); + builder.AppendLine($" Bundle type: {entry.BundleType} (0x{entry.BundleType:X})"); builder.AppendLine(); - Print(builder, bundle.TableEntries, bundle.BundleType); + Print(builder, entry.TableEntries, entry.BundleType); } builder.AppendLine(); @@ -275,11 +275,11 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < entries.Length; j++) + for (int i = 0; i < entries.Length; i++) { - var entry = entries[j]; + var entry = entries[i]; - builder.AppendLine($" Entry Table Entry {j}"); + builder.AppendLine($" Entry Table Entry {i}"); switch (type & ~BundleType.ParameterTypingInformationPresent) { case BundleType.UnusedEntry: diff --git a/SabreTools.Serialization/Printers/N3DS.cs b/SabreTools.Serialization/Printers/N3DS.cs index 23332b6f..e2120682 100644 --- a/SabreTools.Serialization/Printers/N3DS.cs +++ b/SabreTools.Serialization/Printers/N3DS.cs @@ -55,11 +55,11 @@ namespace SabreTools.Serialization.Printers { for (int i = 0; i < header.PartitionsTable.Length; i++) { - var partitionTableEntry = header.PartitionsTable[i]; + var entry = header.PartitionsTable[i]; builder.AppendLine($" Partition table entry {i}"); - builder.AppendLine(partitionTableEntry.Offset, " Offset"); - builder.AppendLine(partitionTableEntry.Length, " Length"); + builder.AppendLine(entry.Offset, " Offset"); + builder.AppendLine(entry.Length, " Length"); } } @@ -168,6 +168,7 @@ namespace SabreTools.Serialization.Printers builder.AppendLine(header.TestData.FilledAA, " Filled with AA"); builder.AppendLine(header.TestData.FinalByte, " Final byte"); } + builder.AppendLine(); } @@ -206,58 +207,60 @@ namespace SabreTools.Serialization.Printers if (header.MagicID == string.Empty) { builder.AppendLine(" Empty backup header, no data can be parsed"); + builder.AppendLine(); + return; } else if (header.MagicID != Constants.NCCHMagicNumber) { builder.AppendLine(" Unrecognized backup header, no data can be parsed"); + builder.AppendLine(); + return; + } + + // Backup header omits RSA signature + builder.AppendLine(header.MagicID, " Magic ID"); + builder.AppendLine(header.ContentSizeInMediaUnits, " Content size in media units"); + builder.AppendLine(header.PartitionId, " Partition ID"); + builder.AppendLine(header.MakerCode, " Maker code"); + builder.AppendLine(header.Version, " Version"); + builder.AppendLine(header.VerificationHash, " Verification hash"); + builder.AppendLine(header.ProgramId, " Program ID"); + builder.AppendLine(header.Reserved1, " Reserved 1"); + builder.AppendLine(header.LogoRegionHash, " Logo region SHA-256 hash"); + builder.AppendLine(header.ProductCode, " Product code"); + builder.AppendLine(header.ExtendedHeaderHash, " Extended header SHA-256 hash"); + builder.AppendLine(header.ExtendedHeaderSizeInBytes, " Extended header size in bytes"); + builder.AppendLine(header.Reserved2, " Reserved 2"); + builder.AppendLine(" Flags:"); + if (header.Flags == null) + { + builder.AppendLine(" [NULL]"); } else { - // Backup header omits RSA signature - builder.AppendLine(header.MagicID, " Magic ID"); - builder.AppendLine(header.ContentSizeInMediaUnits, " Content size in media units"); - builder.AppendLine(header.PartitionId, " Partition ID"); - builder.AppendLine(header.MakerCode, " Maker code"); - builder.AppendLine(header.Version, " Version"); - builder.AppendLine(header.VerificationHash, " Verification hash"); - builder.AppendLine(header.ProgramId, " Program ID"); - builder.AppendLine(header.Reserved1, " Reserved 1"); - builder.AppendLine(header.LogoRegionHash, " Logo region SHA-256 hash"); - builder.AppendLine(header.ProductCode, " Product code"); - builder.AppendLine(header.ExtendedHeaderHash, " Extended header SHA-256 hash"); - builder.AppendLine(header.ExtendedHeaderSizeInBytes, " Extended header size in bytes"); - builder.AppendLine(header.Reserved2, " Reserved 2"); - builder.AppendLine(" Flags:"); - if (header.Flags == null) - { - builder.AppendLine(" [NULL]"); - } - else - { - builder.AppendLine(header.Flags.Reserved0, " Reserved 0"); - builder.AppendLine(header.Flags.Reserved1, " Reserved 1"); - builder.AppendLine(header.Flags.Reserved2, " Reserved 2"); - builder.AppendLine($" Crypto method: {header.Flags.CryptoMethod} (0x{header.Flags.CryptoMethod:X})"); - builder.AppendLine($" Content platform: {header.Flags.ContentPlatform} (0x{header.Flags.ContentPlatform:X})"); - builder.AppendLine($" Content type: {header.Flags.MediaPlatformIndex} (0x{header.Flags.MediaPlatformIndex:X})"); - builder.AppendLine(header.Flags.ContentUnitSize, " Content unit size"); - builder.AppendLine($" Bitmasks: {header.Flags.BitMasks} (0x{header.Flags.BitMasks:X})"); - } - builder.AppendLine(header.PlainRegionOffsetInMediaUnits, " Plain region offset, in media units"); - builder.AppendLine(header.PlainRegionSizeInMediaUnits, " Plain region size, in media units"); - builder.AppendLine(header.LogoRegionOffsetInMediaUnits, " Logo region offset, in media units"); - builder.AppendLine(header.LogoRegionSizeInMediaUnits, " Logo region size, in media units"); - builder.AppendLine(header.ExeFSOffsetInMediaUnits, " ExeFS offset, in media units"); - builder.AppendLine(header.ExeFSSizeInMediaUnits, " ExeFS size, in media units"); - builder.AppendLine(header.ExeFSHashRegionSizeInMediaUnits, " ExeFS hash region size, in media units"); - builder.AppendLine(header.Reserved3, " Reserved 3"); - builder.AppendLine(header.RomFSOffsetInMediaUnits, " RomFS offset, in media units"); - builder.AppendLine(header.RomFSSizeInMediaUnits, " RomFS size, in media units"); - builder.AppendLine(header.RomFSHashRegionSizeInMediaUnits, " RomFS hash region size, in media units"); - builder.AppendLine(header.Reserved4, " Reserved 4"); - builder.AppendLine(header.ExeFSSuperblockHash, " ExeFS superblock SHA-256 hash"); - builder.AppendLine(header.RomFSSuperblockHash, " RomFS superblock SHA-256 hash"); + builder.AppendLine(header.Flags.Reserved0, " Reserved 0"); + builder.AppendLine(header.Flags.Reserved1, " Reserved 1"); + builder.AppendLine(header.Flags.Reserved2, " Reserved 2"); + builder.AppendLine($" Crypto method: {header.Flags.CryptoMethod} (0x{header.Flags.CryptoMethod:X})"); + builder.AppendLine($" Content platform: {header.Flags.ContentPlatform} (0x{header.Flags.ContentPlatform:X})"); + builder.AppendLine($" Content type: {header.Flags.MediaPlatformIndex} (0x{header.Flags.MediaPlatformIndex:X})"); + builder.AppendLine(header.Flags.ContentUnitSize, " Content unit size"); + builder.AppendLine($" Bitmasks: {header.Flags.BitMasks} (0x{header.Flags.BitMasks:X})"); } + builder.AppendLine(header.PlainRegionOffsetInMediaUnits, " Plain region offset, in media units"); + builder.AppendLine(header.PlainRegionSizeInMediaUnits, " Plain region size, in media units"); + builder.AppendLine(header.LogoRegionOffsetInMediaUnits, " Logo region offset, in media units"); + builder.AppendLine(header.LogoRegionSizeInMediaUnits, " Logo region size, in media units"); + builder.AppendLine(header.ExeFSOffsetInMediaUnits, " ExeFS offset, in media units"); + builder.AppendLine(header.ExeFSSizeInMediaUnits, " ExeFS size, in media units"); + builder.AppendLine(header.ExeFSHashRegionSizeInMediaUnits, " ExeFS hash region size, in media units"); + builder.AppendLine(header.Reserved3, " Reserved 3"); + builder.AppendLine(header.RomFSOffsetInMediaUnits, " RomFS offset, in media units"); + builder.AppendLine(header.RomFSSizeInMediaUnits, " RomFS size, in media units"); + builder.AppendLine(header.RomFSHashRegionSizeInMediaUnits, " RomFS hash region size, in media units"); + builder.AppendLine(header.Reserved4, " Reserved 4"); + builder.AppendLine(header.ExeFSSuperblockHash, " ExeFS superblock SHA-256 hash"); + builder.AppendLine(header.RomFSSuperblockHash, " RomFS superblock SHA-256 hash"); builder.AppendLine(); } @@ -586,29 +589,7 @@ namespace SabreTools.Serialization.Printers var entry = entries[i]; builder.AppendLine($" ExeFS Header {i}"); - builder.AppendLine(" File headers:"); - if (entry.FileHeaders == null || entry.FileHeaders.Length == 0) - { - builder.AppendLine(" No file headers"); - } - else - { - for (int j = 0; j < entry.FileHeaders.Length; j++) - { - var fileHeader = entry.FileHeaders[j]; - builder.AppendLine($" File Header {j}"); - if (fileHeader == null) - { - builder.AppendLine(" [NULL]"); - continue; - } - - builder.AppendLine(fileHeader.FileName, " File name"); - builder.AppendLine(fileHeader.FileOffset, " File offset"); - builder.AppendLine(fileHeader.FileSize, " File size"); - } - } - + Print(builder, entry.FileHeaders); builder.AppendLine(entry.Reserved, " Reserved"); builder.AppendLine(" File hashes:"); @@ -621,20 +602,36 @@ namespace SabreTools.Serialization.Printers for (int j = 0; j < entry.FileHashes.Length; j++) { var fileHash = entry.FileHashes[j]; - builder.AppendLine($" File Hash {j}"); - if (fileHash == null) - { - builder.AppendLine(" [NULL]"); - continue; - } + builder.AppendLine($" File Hash {j}"); builder.AppendLine(fileHash, " SHA-256"); } } } + builder.AppendLine(); } + private static void Print(StringBuilder builder, ExeFSFileHeader[]? entries) + { + builder.AppendLine(" File headers:"); + if (entries == null || entries.Length == 0) + { + builder.AppendLine(" No file headers"); + return; + } + + for (int i = 0; i < entries.Length; i++) + { + var entry = entries[i]; + + builder.AppendLine($" File Header {i}"); + builder.AppendLine(entry.FileName, " File name"); + builder.AppendLine(entry.FileOffset, " File offset"); + builder.AppendLine(entry.FileSize, " File size"); + } + } + private static void Print(StringBuilder builder, RomFSHeader[]? entries) { builder.AppendLine(" RomFS Header Information:"); @@ -648,32 +645,28 @@ namespace SabreTools.Serialization.Printers for (int i = 0; i < entries.Length; i++) { - var romFSHeader = entries[i]; - builder.AppendLine($" RomFS Header {i}"); - if (romFSHeader == null) - { - builder.AppendLine(" Unrecognized RomFS data, no data can be parsed"); - continue; - } + var entry = entries[i]; - builder.AppendLine(romFSHeader.MagicString, " Magic string"); - builder.AppendLine(romFSHeader.MagicNumber, " Magic number"); - builder.AppendLine(romFSHeader.MasterHashSize, " Master hash size"); - builder.AppendLine(romFSHeader.Level1LogicalOffset, " Level 1 logical offset"); - builder.AppendLine(romFSHeader.Level1HashdataSize, " Level 1 hashdata size"); - builder.AppendLine(romFSHeader.Level1BlockSizeLog2, " Level 1 block size"); - builder.AppendLine(romFSHeader.Reserved1, " Reserved 1"); - builder.AppendLine(romFSHeader.Level2LogicalOffset, " Level 2 logical offset"); - builder.AppendLine(romFSHeader.Level2HashdataSize, " Level 2 hashdata size"); - builder.AppendLine(romFSHeader.Level2BlockSizeLog2, " Level 2 block size"); - builder.AppendLine(romFSHeader.Reserved2, " Reserved 2"); - builder.AppendLine(romFSHeader.Level3LogicalOffset, " Level 3 logical offset"); - builder.AppendLine(romFSHeader.Level3HashdataSize, " Level 3 hashdata size"); - builder.AppendLine(romFSHeader.Level3BlockSizeLog2, " Level 3 block size"); - builder.AppendLine(romFSHeader.Reserved3, " Reserved 3"); - builder.AppendLine(romFSHeader.Reserved4, " Reserved 4"); - builder.AppendLine(romFSHeader.OptionalInfoSize, " Optional info size"); + builder.AppendLine($" RomFS Header {i}"); + builder.AppendLine(entry.MagicString, " Magic string"); + builder.AppendLine(entry.MagicNumber, " Magic number"); + builder.AppendLine(entry.MasterHashSize, " Master hash size"); + builder.AppendLine(entry.Level1LogicalOffset, " Level 1 logical offset"); + builder.AppendLine(entry.Level1HashdataSize, " Level 1 hashdata size"); + builder.AppendLine(entry.Level1BlockSizeLog2, " Level 1 block size"); + builder.AppendLine(entry.Reserved1, " Reserved 1"); + builder.AppendLine(entry.Level2LogicalOffset, " Level 2 logical offset"); + builder.AppendLine(entry.Level2HashdataSize, " Level 2 hashdata size"); + builder.AppendLine(entry.Level2BlockSizeLog2, " Level 2 block size"); + builder.AppendLine(entry.Reserved2, " Reserved 2"); + builder.AppendLine(entry.Level3LogicalOffset, " Level 3 logical offset"); + builder.AppendLine(entry.Level3HashdataSize, " Level 3 hashdata size"); + builder.AppendLine(entry.Level3BlockSizeLog2, " Level 3 block size"); + builder.AppendLine(entry.Reserved3, " Reserved 3"); + builder.AppendLine(entry.Reserved4, " Reserved 4"); + builder.AppendLine(entry.OptionalInfoSize, " Optional info size"); } + builder.AppendLine(); } } diff --git a/SabreTools.Serialization/Printers/NewExecutable.cs b/SabreTools.Serialization/Printers/NewExecutable.cs index b2e455ae..ab2cdde8 100644 --- a/SabreTools.Serialization/Printers/NewExecutable.cs +++ b/SabreTools.Serialization/Printers/NewExecutable.cs @@ -214,6 +214,7 @@ namespace SabreTools.Serialization.Printers builder.AppendLine(typeAndNameString.Value.Text, " Text", Encoding.ASCII); } } + builder.AppendLine(); } @@ -278,15 +279,10 @@ namespace SabreTools.Serialization.Printers foreach (var entry in entries) { builder.AppendLine($" Imported-Name Table at Offset {entry.Key}"); - if (entry.Value == null) - { - builder.AppendLine(" [NULL]"); - continue; - } - builder.AppendLine(entry.Value.Length, " Length"); builder.AppendLine(entry.Value.NameString, " Name string", Encoding.ASCII); } + builder.AppendLine(); } diff --git a/SabreTools.Serialization/Printers/Nitro.cs b/SabreTools.Serialization/Printers/Nitro.cs index d75c4485..42470fe9 100644 --- a/SabreTools.Serialization/Printers/Nitro.cs +++ b/SabreTools.Serialization/Printers/Nitro.cs @@ -157,8 +157,8 @@ namespace SabreTools.Serialization.Printers builder.AppendLine(); return; } - builder.AppendLine(); + builder.AppendLine(); Print(builder, table.FolderAllocationTable); Print(builder, table.NameList); } diff --git a/SabreTools.Serialization/Printers/PFF.cs b/SabreTools.Serialization/Printers/PFF.cs index 28258d82..95f2aebf 100644 --- a/SabreTools.Serialization/Printers/PFF.cs +++ b/SabreTools.Serialization/Printers/PFF.cs @@ -40,35 +40,31 @@ namespace SabreTools.Serialization.Printers builder.AppendLine(); } - private static void Print(StringBuilder builder, Segment[]? segments) + private static void Print(StringBuilder builder, Segment[]? entries) { builder.AppendLine(" Segments Information:"); builder.AppendLine(" -------------------------"); - if (segments == null || segments.Length == 0) + if (entries == null || entries.Length == 0) { builder.AppendLine(" No segments"); builder.AppendLine(); return; } - for (int i = 0; i < segments.Length; i++) + for (int i = 0; i < entries.Length; i++) { - var segment = segments[i]; - builder.AppendLine($" Segment {i}"); - if (segment == null) - { - builder.AppendLine(" [NULL]"); - continue; - } + var entry = entries[i]; - builder.AppendLine(segment.Deleted, " Deleted"); - builder.AppendLine(segment.FileLocation, " File location"); - builder.AppendLine(segment.FileSize, " File size"); - builder.AppendLine(segment.PackedDate, " Packed date"); - builder.AppendLine(segment.FileName, " File name"); - builder.AppendLine(segment.ModifiedDate, " Modified date"); - builder.AppendLine(segment.CompressionLevel, " Compression level"); + builder.AppendLine($" Segment {i}"); + builder.AppendLine(entry.Deleted, " Deleted"); + builder.AppendLine(entry.FileLocation, " File location"); + builder.AppendLine(entry.FileSize, " File size"); + builder.AppendLine(entry.PackedDate, " Packed date"); + builder.AppendLine(entry.FileName, " File name"); + builder.AppendLine(entry.ModifiedDate, " Modified date"); + builder.AppendLine(entry.CompressionLevel, " Compression level"); } + builder.AppendLine(); } diff --git a/SabreTools.Serialization/Printers/PIC.cs b/SabreTools.Serialization/Printers/PIC.cs index bf663404..8252b781 100644 --- a/SabreTools.Serialization/Printers/PIC.cs +++ b/SabreTools.Serialization/Printers/PIC.cs @@ -45,6 +45,7 @@ namespace SabreTools.Serialization.Printers else { var header = entry.Header; + builder.AppendLine(header.DiscInformationIdentifier, " Disc information identifier"); builder.AppendLine(header.DiscInformationFormat, " Disc information format"); builder.AppendLine(header.Reserved0, " Reserved"); @@ -52,24 +53,28 @@ namespace SabreTools.Serialization.Printers builder.AppendLine(header.BytesInUse, " Bytes in use"); builder.AppendLine(header.Reserved1, " Reserved"); } + if (entry.Body == null) { builder.AppendLine(" No body"); } else { - DiscInformationUnitBody body = entry.Body; + var body = entry.Body; + builder.AppendLine(body.DiscTypeIdentifier, " Disc type identifer"); builder.AppendLine(body.DiscSizeClassVersion, " Disc size class version"); builder.AppendLine(body.FormatDependentContents, " Format-dependent contents"); } + if (entry.Trailer == null) { builder.AppendLine(" No trailer"); } else { - DiscInformationUnitTrailer trailer = entry.Trailer; + var trailer = entry.Trailer; + builder.AppendLine(trailer.DiscManufacturerID, " Disc manufacturer ID"); builder.AppendLine(trailer.MediaTypeID, " Media type ID"); builder.AppendLine(trailer.TimeStamp, " Timestamp"); diff --git a/SabreTools.Serialization/Printers/PKZIP.cs b/SabreTools.Serialization/Printers/PKZIP.cs index db12ecf8..0fab82e7 100644 --- a/SabreTools.Serialization/Printers/PKZIP.cs +++ b/SabreTools.Serialization/Printers/PKZIP.cs @@ -96,57 +96,48 @@ namespace SabreTools.Serialization.Printers builder.AppendLine(); } - private static void Print(StringBuilder builder, CentralDirectoryFileHeader[]? headers) + private static void Print(StringBuilder builder, CentralDirectoryFileHeader[]? entries) { builder.AppendLine(" Central Directory File Headers Information:"); builder.AppendLine(" -------------------------"); - if (headers == null || headers.Length == 0) + if (entries == null || entries.Length == 0) { builder.AppendLine(" No central directory file headers"); builder.AppendLine(); return; } - for (int i = 0; i < headers.Length; i++) + for (int i = 0; i < entries.Length; i++) { - var record = headers[i]; - Print(builder, record, i); + var entry = entries[i]; + + builder.AppendLine($" Central Directory File Header Entry {i}"); + builder.AppendLine(entry.Signature, " Signature"); + builder.AppendLine($" Host system: {entry.HostSystem} (0x{entry.HostSystem:X})"); + builder.AppendLine(entry.VersionMadeBy, " Version made by"); + builder.AppendLine(entry.VersionNeededToExtract, " Version needed to extract"); + builder.AppendLine($" Flags: {entry.Flags} (0x{entry.Flags:X})"); + builder.AppendLine($" Compression method: {entry.CompressionMethod} (0x{entry.CompressionMethod:X})"); + builder.AppendLine(entry.LastModifedFileTime, " Last modified file time"); // TODO: Parse from MS-DOS + builder.AppendLine(entry.LastModifiedFileDate, " Last modified file date"); // TODO: Parse from MS-DOS + builder.AppendLine(entry.CRC32, " CRC-32"); + builder.AppendLine(entry.CompressedSize, " Compressed size"); + builder.AppendLine(entry.UncompressedSize, " Uncompressed size"); + builder.AppendLine(entry.FileNameLength, " File name length"); + builder.AppendLine(entry.ExtraFieldLength, " Extra field length"); + builder.AppendLine(entry.FileCommentLength, " File comment length"); + builder.AppendLine(entry.DiskNumberStart, " Disk number start"); + builder.AppendLine($" Internal file attributes: {entry.InternalFileAttributes} (0x{entry.InternalFileAttributes:X})"); + builder.AppendLine(entry.ExternalFileAttributes, " External file attributes"); + builder.AppendLine(entry.RelativeOffsetOfLocalHeader, " Relative offset of local header"); + builder.AppendLine(entry.FileName, " File name"); + builder.AppendLine(entry.ExtraField, " Extra field"); + builder.AppendLine(entry.FileComment, " File comment"); } + builder.AppendLine(); } - private static void Print(StringBuilder builder, CentralDirectoryFileHeader? header, int index) - { - builder.AppendLine($" Central Directory File Header Entry {index}"); - if (header == null) - { - builder.AppendLine(" [NULL]"); - return; - } - - builder.AppendLine(header.Signature, " Signature"); - builder.AppendLine($" Host system: {header.HostSystem} (0x{header.HostSystem:X})"); - builder.AppendLine(header.VersionMadeBy, " Version made by"); - builder.AppendLine(header.VersionNeededToExtract, " Version needed to extract"); - builder.AppendLine($" Flags: {header.Flags} (0x{header.Flags:X})"); - builder.AppendLine($" Compression method: {header.CompressionMethod} (0x{header.CompressionMethod:X})"); - builder.AppendLine(header.LastModifedFileTime, " Last modified file time"); // TODO: Parse from MS-DOS - builder.AppendLine(header.LastModifiedFileDate, " Last modified file date"); // TODO: Parse from MS-DOS - builder.AppendLine(header.CRC32, " CRC-32"); - builder.AppendLine(header.CompressedSize, " Compressed size"); - builder.AppendLine(header.UncompressedSize, " Uncompressed size"); - builder.AppendLine(header.FileNameLength, " File name length"); - builder.AppendLine(header.ExtraFieldLength, " Extra field length"); - builder.AppendLine(header.FileCommentLength, " File comment length"); - builder.AppendLine(header.DiskNumberStart, " Disk number start"); - builder.AppendLine($" Internal file attributes: {header.InternalFileAttributes} (0x{header.InternalFileAttributes:X})"); - builder.AppendLine(header.ExternalFileAttributes, " External file attributes"); - builder.AppendLine(header.RelativeOffsetOfLocalHeader, " Relative offset of local header"); - builder.AppendLine(header.FileName, " File name"); - builder.AppendLine(header.ExtraField, " Extra field"); - builder.AppendLine(header.FileComment, " File comment"); - } - private static void Print(StringBuilder builder, ArchiveExtraDataRecord? record) { builder.AppendLine(" Archive Extra Data Record Information:"); @@ -199,6 +190,7 @@ namespace SabreTools.Serialization.Printers Print(builder, localFileHeader, encryptionHeader, fileDatum, dataDescriptor, zip64DataDescriptor, i); } + builder.AppendLine(); } @@ -211,12 +203,6 @@ namespace SabreTools.Serialization.Printers int index) { builder.AppendLine($" Local File Entry {index}"); - if (localFileHeader == null) - { - builder.AppendLine(" [NULL]"); - return; - } - builder.AppendLine(localFileHeader.Signature, " [Local File Header] Signature"); builder.AppendLine(localFileHeader.Version, " [Local File Header] Version"); builder.AppendLine($" [Local File Header] Flags: {localFileHeader.Flags} (0x{localFileHeader.Flags:X})"); diff --git a/SabreTools.Serialization/Printers/PortableExecutable.cs b/SabreTools.Serialization/Printers/PortableExecutable.cs index 2aa97f90..31a6264b 100644 --- a/SabreTools.Serialization/Printers/PortableExecutable.cs +++ b/SabreTools.Serialization/Printers/PortableExecutable.cs @@ -271,6 +271,7 @@ namespace SabreTools.Serialization.Printers builder.AppendLine(" Physical address: 0 (0x00000000)"); builder.AppendLine(" Size: 0 (0x00000000)"); } + builder.AppendLine(); } @@ -288,13 +289,8 @@ namespace SabreTools.Serialization.Printers for (int i = 0; i < entries!.Length; i++) { var entry = entries[i]; - builder.AppendLine($" Section Table Entry {i}"); - if (entry == null) - { - builder.AppendLine(" [NULL]"); - continue; - } + builder.AppendLine($" Section Table Entry {i}"); builder.AppendLine(entry.Name, " Name", Encoding.ASCII); builder.AppendLine(entry.VirtualSize, " Virtual size"); builder.AppendLine(entry.VirtualAddress, " Virtual address"); @@ -309,6 +305,7 @@ namespace SabreTools.Serialization.Printers // TODO: Add COFFRelocations // TODO: Add COFFLineNumbers } + builder.AppendLine(); } @@ -329,13 +326,8 @@ namespace SabreTools.Serialization.Printers for (int i = 0; i < entries.Length; i++) { var entry = entries[i]; - builder.AppendLine($" COFF Symbol Table Entry {i} (Subtype {currentSymbolType})"); - if (entry == null) - { - builder.AppendLine(" [NULL]"); - continue; - } + builder.AppendLine($" COFF Symbol Table Entry {i} (Subtype {currentSymbolType})"); if (currentSymbolType == 0) { if (entry.ShortName != null) @@ -445,6 +437,7 @@ namespace SabreTools.Serialization.Printers if (auxSymbolsRemaining == 0) currentSymbolType = 0; } + builder.AppendLine(); } @@ -484,13 +477,8 @@ namespace SabreTools.Serialization.Printers for (int i = 0; i < entries.Length; i++) { var entry = entries[i]; - builder.AppendLine($" Attribute Certificate Table Entry {i}"); - if (entry == null) - { - builder.AppendLine(" [NULL]"); - continue; - } + builder.AppendLine($" Attribute Certificate Table Entry {i}"); builder.AppendLine(entry.Length, " Length"); builder.AppendLine($" Revision: {entry.Revision} (0x{entry.Revision:X})"); builder.AppendLine($" Certificate type: {entry.CertificateType} (0x{entry.CertificateType:X})"); @@ -598,6 +586,7 @@ namespace SabreTools.Serialization.Printers builder.AppendLine(typeOffsetFieldEntry.Offset, " Offset"); } } + builder.AppendLine(); } @@ -616,13 +605,8 @@ namespace SabreTools.Serialization.Printers for (int i = 0; i < table.DebugDirectoryTable.Length; i++) { var entry = table.DebugDirectoryTable[i]; - builder.AppendLine($" Debug Directory Table Entry {i}"); - if (entry == null) - { - builder.AppendLine(" [NULL]"); - continue; - } + builder.AppendLine($" Debug Directory Table Entry {i}"); builder.AppendLine(entry.Characteristics, " Characteristics"); builder.AppendLine(entry.TimeDateStamp, " Time/Date stamp"); builder.AppendLine(entry.MajorVersion, " Major version"); @@ -632,6 +616,7 @@ namespace SabreTools.Serialization.Printers builder.AppendLine(entry.AddressOfRawData, " Address of raw data"); builder.AppendLine(entry.PointerToRawData, " Pointer to raw data"); } + builder.AppendLine(); } @@ -679,12 +664,13 @@ namespace SabreTools.Serialization.Printers { for (int i = 0; i < table.ExportAddressTable.Length; i++) { - var exportAddressTableEntry = table.ExportAddressTable[i]; + var entry = table.ExportAddressTable[i]; builder.AppendLine($" Export Address Table Entry {i}"); - builder.AppendLine(exportAddressTableEntry.ExportRVA, " Export RVA / Forwarder RVA"); + builder.AppendLine(entry.ExportRVA, " Export RVA / Forwarder RVA"); } } + builder.AppendLine(); builder.AppendLine(" Name Pointer Table Information:"); @@ -697,11 +683,13 @@ namespace SabreTools.Serialization.Printers { for (int i = 0; i < table.NamePointerTable.Pointers.Length; i++) { - var namePointerTableEntry = table.NamePointerTable.Pointers[i]; + var entry = table.NamePointerTable.Pointers[i]; + builder.AppendLine($" Name Pointer Table Entry {i}"); - builder.AppendLine(namePointerTableEntry, " Pointer"); + builder.AppendLine(entry, " Pointer"); } } + builder.AppendLine(); builder.AppendLine(" Ordinal Table Information:"); @@ -714,11 +702,13 @@ namespace SabreTools.Serialization.Printers { for (int i = 0; i < table.OrdinalTable.Indexes.Length; i++) { - var ordinalTableEntry = table.OrdinalTable.Indexes[i]; + var entry = table.OrdinalTable.Indexes[i]; + builder.AppendLine($" Ordinal Table Entry {i}"); - builder.AppendLine(ordinalTableEntry, " Index"); + builder.AppendLine(entry, " Index"); } } + builder.AppendLine(); builder.AppendLine(" Export Name Table Information:"); @@ -731,11 +721,13 @@ namespace SabreTools.Serialization.Printers { for (int i = 0; i < table.ExportNameTable.Strings.Length; i++) { - var exportNameTableEntry = table.ExportNameTable.Strings[i]; + var entry = table.ExportNameTable.Strings[i]; + builder.AppendLine($" Export Name Table Entry {i}"); - builder.AppendLine(exportNameTableEntry, " String"); + builder.AppendLine(entry, " String"); } } + builder.AppendLine(); } @@ -761,17 +753,17 @@ namespace SabreTools.Serialization.Printers { for (int i = 0; i < table.ImportDirectoryTable.Length; i++) { - var importDirectoryTableEntry = table.ImportDirectoryTable[i]; + var entry = table.ImportDirectoryTable[i]; builder.AppendLine($" Import Directory Table Entry {i}"); - builder.AppendLine(importDirectoryTableEntry.ImportLookupTableRVA, " Import lookup table RVA"); - builder.AppendLine(importDirectoryTableEntry.ImportLookupTableRVA.ConvertVirtualAddress(sectionTable), " Import lookup table Physical Address"); - builder.AppendLine(importDirectoryTableEntry.TimeDateStamp, " Time/Date stamp"); - builder.AppendLine(importDirectoryTableEntry.ForwarderChain, " Forwarder chain"); - builder.AppendLine(importDirectoryTableEntry.NameRVA, " Name RVA"); - builder.AppendLine(importDirectoryTableEntry.Name, " Name"); - builder.AppendLine(importDirectoryTableEntry.ImportAddressTableRVA, " Import address table RVA"); - builder.AppendLine(importDirectoryTableEntry.ImportAddressTableRVA.ConvertVirtualAddress(sectionTable), " Import address table Physical Address"); + builder.AppendLine(entry.ImportLookupTableRVA, " Import lookup table RVA"); + builder.AppendLine(entry.ImportLookupTableRVA.ConvertVirtualAddress(sectionTable), " Import lookup table Physical Address"); + builder.AppendLine(entry.TimeDateStamp, " Time/Date stamp"); + builder.AppendLine(entry.ForwarderChain, " Forwarder chain"); + builder.AppendLine(entry.NameRVA, " Name RVA"); + builder.AppendLine(entry.Name, " Name"); + builder.AppendLine(entry.ImportAddressTableRVA, " Import address table RVA"); + builder.AppendLine(entry.ImportAddressTableRVA.ConvertVirtualAddress(sectionTable), " Import address table Physical Address"); } } @@ -801,22 +793,23 @@ namespace SabreTools.Serialization.Printers for (int i = 0; i < importLookupTable.Length; i++) { - var importLookupTableEntry = importLookupTable[i]; + var entry = importLookupTable[i]; builder.AppendLine($" Import Lookup Table {index} Entry {i}"); - builder.AppendLine(importLookupTableEntry.OrdinalNameFlag, " Ordinal/Name flag"); - if (importLookupTableEntry.OrdinalNameFlag) + builder.AppendLine(entry.OrdinalNameFlag, " Ordinal/Name flag"); + if (entry.OrdinalNameFlag) { - builder.AppendLine(importLookupTableEntry.OrdinalNumber, " Ordinal number"); + builder.AppendLine(entry.OrdinalNumber, " Ordinal number"); } else { - builder.AppendLine(importLookupTableEntry.HintNameTableRVA, " Hint/Name table RVA"); - builder.AppendLine(importLookupTableEntry.HintNameTableRVA.ConvertVirtualAddress(sectionTable), " Hint/Name table Physical Address"); + builder.AppendLine(entry.HintNameTableRVA, " Hint/Name table RVA"); + builder.AppendLine(entry.HintNameTableRVA.ConvertVirtualAddress(sectionTable), " Hint/Name table Physical Address"); } } } } + builder.AppendLine(); builder.AppendLine(" Import Address Tables Information:"); @@ -843,22 +836,23 @@ namespace SabreTools.Serialization.Printers for (int i = 0; i < importAddressTable.Length; i++) { - var importAddressTableEntry = importAddressTable[i]; + var entry = importAddressTable[i]; builder.AppendLine($" Import Address Table {index} Entry {i}"); - builder.AppendLine(importAddressTableEntry.OrdinalNameFlag, " Ordinal/Name flag"); - if (importAddressTableEntry.OrdinalNameFlag) + builder.AppendLine(entry.OrdinalNameFlag, " Ordinal/Name flag"); + if (entry.OrdinalNameFlag) { - builder.AppendLine(importAddressTableEntry.OrdinalNumber, " Ordinal number"); + builder.AppendLine(entry.OrdinalNumber, " Ordinal number"); } else { - builder.AppendLine(importAddressTableEntry.HintNameTableRVA, " Hint/Name table RVA"); - builder.AppendLine(importAddressTableEntry.HintNameTableRVA.ConvertVirtualAddress(sectionTable), " Hint/Name table Physical Address"); + builder.AppendLine(entry.HintNameTableRVA, " Hint/Name table RVA"); + builder.AppendLine(entry.HintNameTableRVA.ConvertVirtualAddress(sectionTable), " Hint/Name table Physical Address"); } } } } + builder.AppendLine(); builder.AppendLine(" Hint/Name Table Information:"); @@ -871,13 +865,14 @@ namespace SabreTools.Serialization.Printers { for (int i = 0; i < table.HintNameTable.Length; i++) { - var hintNameTableEntry = table.HintNameTable[i]; + var entry = table.HintNameTable[i]; builder.AppendLine($" Hint/Name Table Entry {i}"); - builder.AppendLine(hintNameTableEntry.Hint, " Hint"); - builder.AppendLine(hintNameTableEntry.Name, " Name"); + builder.AppendLine(entry.Hint, " Hint"); + builder.AppendLine(entry.Name, " Name"); } } + builder.AppendLine(); } @@ -924,8 +919,6 @@ namespace SabreTools.Serialization.Printers for (int i = 0; i < table.Entries.Length; i++) { var entry = table.Entries[i]; - if (entry == null) - continue; var newTypes = new List(types ?? []); if (entry.Name?.UnicodeString != null) @@ -1656,11 +1649,6 @@ namespace SabreTools.Serialization.Printers for (int i = 0; i < assemblyManifest.AssemblyIdentities.Length; i++) { var assemblyIdentity = assemblyManifest.AssemblyIdentities[i]; - if (assemblyIdentity == null) - { - builder.AppendLine($"{padding} [Assembly Identity {i}] [NULL]"); - continue; - } builder.AppendLine(assemblyIdentity.Name, $"{padding}[Assembly Identity {i}] Name"); builder.AppendLine(assemblyIdentity.Version, $"{padding}[Assembly Identity {i}] Version"); @@ -1679,11 +1667,6 @@ namespace SabreTools.Serialization.Printers for (int i = 0; i < assemblyManifest.COMInterfaceExternalProxyStub.Length; i++) { var comInterfaceExternalProxyStub = assemblyManifest.COMInterfaceExternalProxyStub[i]; - if (comInterfaceExternalProxyStub == null) - { - builder.AppendLine($"{padding} [COM Interface External Proxy Stub {i}] [NULL]"); - continue; - } builder.AppendLine(comInterfaceExternalProxyStub.IID, $"{padding}[COM Interface External Proxy Stub {i}] IID"); builder.AppendLine(comInterfaceExternalProxyStub.Name, $"{padding}[COM Interface External Proxy Stub {i}] Name"); @@ -1715,11 +1698,6 @@ namespace SabreTools.Serialization.Printers for (int j = 0; j < dependency.DependentAssembly.BindingRedirect.Length; j++) { var bindingRedirect = dependency.DependentAssembly.BindingRedirect[j]; - if (bindingRedirect == null) - { - builder.AppendLine($"{padding}[Dependency {i} Binding Redirect {j}] [NULL]"); - continue; - } builder.AppendLine(bindingRedirect.OldVersion, $"{padding}[Dependency {i} Binding Redirect {j}] Old version"); builder.AppendLine(bindingRedirect.NewVersion, $"{padding}[Dependency {i} Binding Redirect {j}] New version"); @@ -1753,11 +1731,6 @@ namespace SabreTools.Serialization.Printers for (int j = 0; j < file.COMClass.Length; j++) { var comClass = file.COMClass[j]; - if (comClass == null) - { - builder.AppendLine($"{padding}[File {i} COM Class {j}] [NULL]"); - continue; - } builder.AppendLine(comClass.CLSID, $"{padding}[File {i} COM Class {j}] CLSID"); builder.AppendLine(comClass.ThreadingModel, $"{padding}[File {i} COM Class {j}] Threading model"); @@ -1770,12 +1743,6 @@ namespace SabreTools.Serialization.Printers for (int k = 0; k < comClass.ProgIDs.Length; k++) { var progId = comClass.ProgIDs[k]; - if (progId == null) - { - builder.AppendLine($"{padding}[File {i} COM Class {j} Prog ID {k}] [NULL]"); - continue; - } - builder.AppendLine(progId.Value, $"{padding}[File {i} COM Class {j} Prog ID {k}] Value"); } } @@ -1787,11 +1754,6 @@ namespace SabreTools.Serialization.Printers for (int j = 0; j < file.COMInterfaceProxyStub.Length; j++) { var comInterfaceProxyStub = file.COMInterfaceProxyStub[j]; - if (comInterfaceProxyStub == null) - { - builder.AppendLine($"{padding}[File {i} COM Interface Proxy Stub {j}] [NULL]"); - continue; - } builder.AppendLine(comInterfaceProxyStub.IID, $"{padding}[File {i} COM Interface Proxy Stub {j}] IID"); builder.AppendLine(comInterfaceProxyStub.Name, $"{padding}[File {i} COM Interface Proxy Stub {j}] Name"); @@ -1807,11 +1769,6 @@ namespace SabreTools.Serialization.Printers for (int j = 0; j < file.Typelib.Length; j++) { var typeLib = file.Typelib[j]; - if (typeLib == null) - { - builder.AppendLine($"{padding}[File {i} Type Lib {j}] [NULL]"); - continue; - } builder.AppendLine(typeLib.TLBID, $"{padding}[File {i} Type Lib {j}] TLBID"); builder.AppendLine(typeLib.Version, $"{padding}[File {i} Type Lib {j}] Version"); @@ -1826,11 +1783,6 @@ namespace SabreTools.Serialization.Printers for (int j = 0; j < file.WindowClass.Length; j++) { var windowClass = file.WindowClass[j]; - if (windowClass == null) - { - builder.AppendLine($"{padding}[File {i} Window Class {j}] [NULL]"); - continue; - } builder.AppendLine(windowClass.Versioned, $"{padding}[File {i} Window Class {j}] Versioned"); builder.AppendLine(windowClass.Value, $"{padding}[File {i} Window Class {j}] Value"); @@ -1877,12 +1829,8 @@ namespace SabreTools.Serialization.Printers { int offset = 0; - byte[]? magic = entry.Data.ReadBytes(ref offset, Math.Min(entry.Data.Length, 16)); - if (magic == null) - { - // No-op - } - else if (magic[0] == 0x4D && magic[1] == 0x5A) + byte[] magic = entry.Data.ReadBytes(ref offset, Math.Min(entry.Data.Length, 16)); + if (magic[0] == 0x4D && magic[1] == 0x5A) { builder.AppendLine($"{padding}Data: [Embedded Executable File]"); // TODO: Parse this out and print separately } diff --git a/SabreTools.Serialization/Printers/Quantum.cs b/SabreTools.Serialization/Printers/Quantum.cs index c277b692..3aa0cbf1 100644 --- a/SabreTools.Serialization/Printers/Quantum.cs +++ b/SabreTools.Serialization/Printers/Quantum.cs @@ -56,13 +56,8 @@ namespace SabreTools.Serialization.Printers for (int i = 0; i < entries.Length; i++) { var fileDescriptor = entries[i]; - builder.AppendLine($" File Descriptor {i}"); - if (fileDescriptor == null) - { - builder.AppendLine(" [NULL]"); - continue; - } + builder.AppendLine($" File Descriptor {i}"); builder.AppendLine(fileDescriptor.FileNameSize, " File name size"); builder.AppendLine(fileDescriptor.FileName, " File name"); builder.AppendLine(fileDescriptor.CommentFieldSize, " Comment field size"); @@ -73,6 +68,7 @@ namespace SabreTools.Serialization.Printers if (fileDescriptor.Unknown != null) builder.AppendLine(fileDescriptor.Unknown.Value, " Unknown (Checksum?)"); } + builder.AppendLine(); } } diff --git a/SabreTools.Serialization/Printers/SGA.cs b/SabreTools.Serialization/Printers/SGA.cs index dac02d3f..28894d15 100644 --- a/SabreTools.Serialization/Printers/SGA.cs +++ b/SabreTools.Serialization/Printers/SGA.cs @@ -56,6 +56,7 @@ namespace SabreTools.Serialization.Printers builder.AppendLine(header6.Dummy0, " Dummy 0"); break; } + builder.AppendLine(); } @@ -104,6 +105,7 @@ namespace SabreTools.Serialization.Printers builder.AppendLine($" Unrecognized directory type"); break; } + builder.AppendLine(); } @@ -188,14 +190,9 @@ namespace SabreTools.Serialization.Printers for (int i = 0; i < sections.Length; i++) { - builder.AppendLine($" Section {i}"); var section = sections[i]; - if (section == null) - { - builder.AppendLine(" [NULL]"); - continue; - } + builder.AppendLine($" Section {i}"); builder.AppendLine(section.Alias, " Alias"); builder.AppendLine(section.Name, " Name"); builder.AppendLine(section.FolderStartIndex, " Folder start index"); @@ -204,6 +201,7 @@ namespace SabreTools.Serialization.Printers builder.AppendLine(section.FileEndIndex, " File end index"); builder.AppendLine(section.FolderRootIndex, " Folder root index"); } + builder.AppendLine(); } @@ -220,14 +218,9 @@ namespace SabreTools.Serialization.Printers for (int i = 0; i < sections.Length; i++) { - builder.AppendLine($" Section {i}"); var section = sections[i]; - if (section == null) - { - builder.AppendLine(" [NULL]"); - continue; - } + builder.AppendLine($" Section {i}"); builder.AppendLine(section.Alias, " Alias"); builder.AppendLine(section.Name, " Name"); builder.AppendLine(section.FolderStartIndex, " Folder start index"); @@ -236,6 +229,7 @@ namespace SabreTools.Serialization.Printers builder.AppendLine(section.FileEndIndex, " File end index"); builder.AppendLine(section.FolderRootIndex, " Folder root index"); } + builder.AppendLine(); } @@ -252,14 +246,9 @@ namespace SabreTools.Serialization.Printers for (int i = 0; i < folders.Length; i++) { - builder.AppendLine($" Folder {i}"); var folder = folders[i]; - if (folder == null) - { - builder.AppendLine(" [NULL]"); - continue; - } + builder.AppendLine($" Folder {i}"); builder.AppendLine(folder.NameOffset, " Name offset"); builder.AppendLine(folder.Name, " Name"); builder.AppendLine(folder.FolderStartIndex, " Folder start index"); @@ -267,6 +256,7 @@ namespace SabreTools.Serialization.Printers builder.AppendLine(folder.FileStartIndex, " File start index"); builder.AppendLine(folder.FileEndIndex, " File end index"); } + builder.AppendLine(); } @@ -283,14 +273,9 @@ namespace SabreTools.Serialization.Printers for (int i = 0; i < folders.Length; i++) { - builder.AppendLine($" Folder {i}"); - var folder = folders[i] as Folder5; - if (folder == null) - { - builder.AppendLine(" [NULL]"); - continue; - } + var folder = folders[i]; + builder.AppendLine($" Folder {i}"); builder.AppendLine(folder.NameOffset, " Name offset"); builder.AppendLine(folder.Name, " Name"); builder.AppendLine(folder.FolderStartIndex, " Folder start index"); @@ -298,6 +283,7 @@ namespace SabreTools.Serialization.Printers builder.AppendLine(folder.FileStartIndex, " File start index"); builder.AppendLine(folder.FileEndIndex, " File end index"); } + builder.AppendLine(); } @@ -314,14 +300,9 @@ namespace SabreTools.Serialization.Printers for (int i = 0; i < files.Length; i++) { - builder.AppendLine($" File {i}"); var file = files[i]; - if (file == null) - { - builder.AppendLine(" [NULL]"); - continue; - } + builder.AppendLine($" File {i}"); builder.AppendLine(file.NameOffset, " Name offset"); builder.AppendLine(file.Name, " Name"); builder.AppendLine(file.Offset, " Offset"); @@ -331,6 +312,7 @@ namespace SabreTools.Serialization.Printers builder.AppendLine(file.Dummy0, " Dummy 0"); builder.AppendLine(file.Type, " Type"); } + builder.AppendLine(); } @@ -347,14 +329,9 @@ namespace SabreTools.Serialization.Printers for (int i = 0; i < files.Length; i++) { - builder.AppendLine($" File {i}"); var file = files[i]; - if (file == null) - { - builder.AppendLine(" [NULL]"); - continue; - } + builder.AppendLine($" File {i}"); builder.AppendLine(file.NameOffset, " Name offset"); builder.AppendLine(file.Name, " Name"); builder.AppendLine(file.Offset, " Offset"); @@ -365,6 +342,7 @@ namespace SabreTools.Serialization.Printers builder.AppendLine(file.Type, " Type"); builder.AppendLine(file.CRC32, " CRC32"); } + builder.AppendLine(); } @@ -381,14 +359,9 @@ namespace SabreTools.Serialization.Printers for (int i = 0; i < files.Length; i++) { - builder.AppendLine($" File {i}"); var file = files[i]; - if (file == null) - { - builder.AppendLine(" [NULL]"); - continue; - } + builder.AppendLine($" File {i}"); builder.AppendLine(file.NameOffset, " Name offset"); builder.AppendLine(file.Name, " Name"); builder.AppendLine(file.Offset, " Offset"); @@ -400,6 +373,7 @@ namespace SabreTools.Serialization.Printers builder.AppendLine(file.CRC32, " CRC32"); builder.AppendLine(file.HashOffset, " Hash offset"); } + builder.AppendLine(); } } diff --git a/SabreTools.Serialization/Printers/VBSP.cs b/SabreTools.Serialization/Printers/VBSP.cs index 19fc6fbb..c904e0e8 100644 --- a/SabreTools.Serialization/Printers/VBSP.cs +++ b/SabreTools.Serialization/Printers/VBSP.cs @@ -54,14 +54,9 @@ namespace SabreTools.Serialization.Printers string specialLumpName = GetLumpName(i); builder.AppendLine($" Lump {i}{specialLumpName}"); - if (lump == null) - { - builder.AppendLine(" [NULL]"); - continue; - } - builder.AppendLine(lump.Offset, " Offset"); builder.AppendLine(lump.Length, " Length"); + switch ((LumpType)i) { case LumpType.LUMP_ENTITIES: @@ -290,6 +285,7 @@ namespace SabreTools.Serialization.Printers break; } } + builder.AppendLine(); } @@ -373,12 +369,12 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < lump.Entities.Length; j++) + for (int i = 0; i < lump.Entities.Length; i++) { // TODO: Implement entity printing - var entity = lump.Entities[j]; - builder.AppendLine($" Entity {j}"); - builder.AppendLine(" Entity data is not parsed properly"); + var entity = lump.Entities[i]; + + builder.AppendLine($" Entity {i}: Not printed yet"); } } @@ -390,10 +386,11 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < lump.Planes.Length; j++) + for (int i = 0; i < lump.Planes.Length; i++) { - var plane = lump.Planes[j]; - builder.AppendLine($" Plane {j}"); + var plane = lump.Planes[i]; + + builder.AppendLine($" Plane {i}"); builder.AppendLine($" Normal vector: ({plane.NormalVector?.X}, {plane.NormalVector?.Y}, {plane.NormalVector?.Z})"); builder.AppendLine(plane.Distance, " Distance"); builder.AppendLine($" Plane type: {plane.PlaneType} (0x{plane.PlaneType:X})"); @@ -408,10 +405,11 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < lump.Texdatas.Length; j++) + for (int i = 0; i < lump.Texdatas.Length; i++) { - var texdata = lump.Texdatas[j]; - builder.AppendLine($" Texture {j}"); + var texdata = lump.Texdatas[i]; + + builder.AppendLine($" Texture {i}"); builder.AppendLine($" Reflectivity: ({texdata.Reflectivity?.X}, {texdata.Reflectivity?.Y}, {texdata.Reflectivity?.Z})"); builder.AppendLine(texdata.NameStringTableID, " Name string table ID"); builder.AppendLine(texdata.Width, " Width"); @@ -429,10 +427,10 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < lump.Vertices.Length; j++) + for (int i = 0; i < lump.Vertices.Length; i++) { - var vertex = lump.Vertices[j]; - builder.AppendLine($" Vertex {j}: ({vertex.X}, {vertex.Y}, {vertex.Z})"); + var vertex = lump.Vertices[i]; + builder.AppendLine($" Vertex {i}: ({vertex.X}, {vertex.Y}, {vertex.Z})"); } } @@ -456,10 +454,11 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < lump.Nodes.Length; j++) + for (int i = 0; i < lump.Nodes.Length; i++) { - var node = lump.Nodes[j]; - builder.AppendLine($" Node {j}"); + var node = lump.Nodes[i]; + + builder.AppendLine($" Node {i}"); builder.AppendLine(node.Children, " Children"); builder.AppendLine(node.Mins, " Mins"); builder.AppendLine(node.Maxs, " Maxs"); @@ -478,10 +477,11 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < lump.Texinfos.Length; j++) + for (int i = 0; i < lump.Texinfos.Length; i++) { - var texinfo = lump.Texinfos[j]; - builder.AppendLine($" Texinfo {j}"); + var texinfo = lump.Texinfos[i]; + + builder.AppendLine($" Texinfo {i}"); builder.AppendLine($" Texture S-Vector: ({texinfo.TextureSVector?.X}, {texinfo.TextureSVector?.Y}, {texinfo.TextureSVector?.Z})"); builder.AppendLine(texinfo.TextureSShift, " Texture shift in S direction"); builder.AppendLine($" Texture T-Vector: ({texinfo.TextureTVector?.X}, {texinfo.TextureTVector?.Y}, {texinfo.TextureTVector?.Z})"); @@ -503,10 +503,11 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < lump.Faces.Length; j++) + for (int i = 0; i < lump.Faces.Length; i++) { - var face = lump.Faces[j]; - builder.AppendLine($" Face {j}"); + var face = lump.Faces[i]; + + builder.AppendLine($" Face {i}"); builder.AppendLine(face.PlaneNum, " Plane number"); builder.AppendLine(face.Side, " Side"); builder.AppendLine(face.OnNode, " On node"); @@ -557,6 +558,7 @@ namespace SabreTools.Serialization.Printers builder.AppendLine(" Collision data skipped..."); } } + builder.AppendLine(" Keydata skipped..."); } } @@ -574,55 +576,58 @@ namespace SabreTools.Serialization.Printers if (lump == null) { builder.AppendLine(" No data"); + return; + } + + builder.AppendLine(lump.Count, " Count"); + if (lump.Data == null || lump.Data.Length == 0) + { + builder.AppendLine(" No occluder data"); } else { - builder.AppendLine(lump.Count, " Count"); - if (lump.Data == null || lump.Data.Length == 0) + for (int i = 0; i < lump.Data.Length; i++) { - builder.AppendLine(" No occluder data"); + var data = lump.Data[i]; + + builder.AppendLine($" Occluder Data {i}"); + builder.AppendLine(data.Flags, " Flags"); + builder.AppendLine(data.FirstPoly, " First poly"); + builder.AppendLine(data.PolyCount, " Poly count"); + builder.AppendLine($" Mins: {data.Mins?.X}, {data.Mins?.Y}, {data.Mins?.Z}"); + builder.AppendLine($" Maxs: {data.Maxs?.X}, {data.Maxs?.Y}, {data.Maxs?.Z}"); + builder.AppendLine(data.Area, " Area"); } - else + } + + builder.AppendLine(lump.PolyDataCount, " Polydata count"); + if (lump.PolyData == null || lump.PolyData.Length == 0) + { + builder.AppendLine(" No occluder polydata"); + } + else + { + for (int i = 0; i < lump.PolyData.Length; i++) { - for (int j = 0; j < lump.Data.Length; j++) - { - var data = lump.Data[j]; - builder.AppendLine($" Occluder Data {j}"); - builder.AppendLine(data.Flags, " Flags"); - builder.AppendLine(data.FirstPoly, " First poly"); - builder.AppendLine(data.PolyCount, " Poly count"); - builder.AppendLine($" Mins: {data.Mins?.X}, {data.Mins?.Y}, {data.Mins?.Z}"); - builder.AppendLine($" Maxs: {data.Maxs?.X}, {data.Maxs?.Y}, {data.Maxs?.Z}"); - builder.AppendLine(data.Area, " Area"); - } + var polydata = lump.PolyData[i]; + + builder.AppendLine($" Occluder Polydata {i}"); + builder.AppendLine(polydata.FirstVertexIndex, " First vertex index"); + builder.AppendLine(polydata.VertexCount, " Vertex count"); + builder.AppendLine(polydata.PlanEnum, " Plan enum"); } - builder.AppendLine(lump.PolyDataCount, " Polydata count"); - if (lump.PolyData == null || lump.PolyData.Length == 0) + } + + builder.AppendLine(lump.VertexIndexCount, " Vertex index count"); + if (lump.VertexIndicies == null || lump.VertexIndicies.Length == 0) + { + builder.AppendLine(" No vertex indicies"); + } + else + { + for (int i = 0; i < lump.VertexIndicies.Length; i++) { - builder.AppendLine(" No occluder polydata"); - } - else - { - for (int j = 0; j < lump.PolyData.Length; j++) - { - var polydata = lump.PolyData[j]; - builder.AppendLine($" Occluder Polydata {j}"); - builder.AppendLine(polydata.FirstVertexIndex, " First vertex index"); - builder.AppendLine(polydata.VertexCount, " Vertex count"); - builder.AppendLine(polydata.PlanEnum, " Plan enum"); - } - } - builder.AppendLine(lump.VertexIndexCount, " Vertex index count"); - if (lump.VertexIndicies == null || lump.VertexIndicies.Length == 0) - { - builder.AppendLine(" No vertex indicies"); - } - else - { - for (int j = 0; j < lump.VertexIndicies.Length; j++) - { - builder.AppendLine($" Vertex Index {j}: {lump.VertexIndicies[j]}"); - } + builder.AppendLine($" Vertex Index {i}: {lump.VertexIndicies[i]}"); } } } @@ -638,6 +643,7 @@ namespace SabreTools.Serialization.Printers for (int i = 0; i < lump.Leaves.Length; i++) { var leaf = lump.Leaves[i]; + builder.AppendLine($" Leaf {i}"); builder.AppendLine($" Contents: {leaf.Contents} (0x{leaf.Contents:X})"); builder.AppendLine(leaf.Cluster, " Cluster"); @@ -683,10 +689,10 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < lump.Marksurfaces.Length; j++) + for (int i = 0; i < lump.Marksurfaces.Length; i++) { - var marksurface = lump.Marksurfaces[j]; - builder.AppendLine(marksurface, $" Marksurface {j}"); + var marksurface = lump.Marksurfaces[i]; + builder.AppendLine(marksurface, $" Marksurface {i}"); } } @@ -698,10 +704,10 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < lump.Edges.Length; j++) + for (int i = 0; i < lump.Edges.Length; i++) { - var edge = lump.Edges[j]; - builder.AppendLine($" Edge {j}"); + var edge = lump.Edges[i]; + builder.AppendLine($" Edge {i}"); builder.AppendLine(edge.VertexIndices, " Vertex indices"); } } @@ -714,10 +720,10 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < lump.Surfedges.Length; j++) + for (int i = 0; i < lump.Surfedges.Length; i++) { - var surfedge = lump.Surfedges[j]; - builder.AppendLine(surfedge, $" Surfedge {j}"); + var surfedge = lump.Surfedges[i]; + builder.AppendLine(surfedge, $" Surfedge {i}"); } } @@ -729,10 +735,11 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < lump.Models.Length; j++) + for (int i = 0; i < lump.Models.Length; i++) { - var model = lump.Models[j]; - builder.AppendLine($" Model {j}"); + var model = lump.Models[i]; + + builder.AppendLine($" Model {i}"); builder.AppendLine($" Mins: ({model.Mins?.X}, {model.Mins?.Y}, {model.Mins?.Z})"); builder.AppendLine($" Maxs: ({model.Maxs?.X}, {model.Maxs?.Y}, {model.Maxs?.Z})"); builder.AppendLine($" Origin vector: ({model.OriginVector?.X}, {model.OriginVector?.Y}, {model.OriginVector?.Z})"); @@ -753,6 +760,7 @@ namespace SabreTools.Serialization.Printers for (int j = 0; j < lump.WorldLights.Length; j++) { var worldlight = lump.WorldLights[j]; + builder.AppendLine($" World Light {j}"); builder.AppendLine($" Origin: ({worldlight.Origin?.X}, {worldlight.Origin?.Y}, {worldlight.Origin?.Z})"); builder.AppendLine($" Intensity: ({worldlight.Intensity?.X}, {worldlight.Intensity?.Y}, {worldlight.Intensity?.Z})"); @@ -781,10 +789,10 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < lump.Map.Length; j++) + for (int i = 0; i < lump.Map.Length; i++) { - var entry = lump.Map[j]; - builder.AppendLine($" Map entry {j}: {entry}"); + var entry = lump.Map[i]; + builder.AppendLine($" Map entry {i}: {entry}"); } } @@ -796,10 +804,10 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < lump.Map.Length; j++) + for (int i = 0; i < lump.Map.Length; i++) { - var entry = lump.Map[j]; - builder.AppendLine($" Map entry {j}: {entry}"); + var entry = lump.Map[i]; + builder.AppendLine($" Map entry {i}: {entry}"); } } @@ -811,10 +819,11 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < lump.Brushes.Length; j++) + for (int i = 0; i < lump.Brushes.Length; i++) { - var brush = lump.Brushes[j]; - builder.AppendLine($" Brush {j}"); + var brush = lump.Brushes[i]; + + builder.AppendLine($" Brush {i}"); builder.AppendLine(brush.FirstSide, " First brushside"); builder.AppendLine(brush.NumSides, " Number of brushsides"); builder.AppendLine($" Contents: {brush.Contents} (0x{brush.Contents:X})"); @@ -829,10 +838,11 @@ namespace SabreTools.Serialization.Printers return; } - for (int j = 0; j < lump.Brushsides.Length; j++) + for (int i = 0; i < lump.Brushsides.Length; i++) { - var brushside = lump.Brushsides[j]; - builder.AppendLine($" Brushside {j}"); + var brushside = lump.Brushsides[i]; + + builder.AppendLine($" Brushside {i}"); builder.AppendLine(brushside.PlaneNum, " Plane number"); builder.AppendLine(brushside.TextureInfo, " Texture info"); builder.AppendLine(brushside.DisplacementInfo, " Displacement info"); @@ -851,6 +861,7 @@ namespace SabreTools.Serialization.Printers for (int i = 0; i < lump.Infos.Length; i++) { var info = lump.Infos[i]; + builder.AppendLine($" Disp Info {i}"); builder.AppendLine($" Start position: ({info.StartPosition?.X}, {info.StartPosition?.Y}, {info.StartPosition?.Z})"); builder.AppendLine(info.DispVertStart, " Index into disp verts"); @@ -891,6 +902,7 @@ namespace SabreTools.Serialization.Printers } } } + builder.AppendLine($" Corner Neighbors:"); if (info.CornerNeighbors == null || info.CornerNeighbors.Length == 0) { @@ -906,6 +918,7 @@ namespace SabreTools.Serialization.Printers builder.AppendLine(cornerNeighbor.NeighborCount, " Neighbor count"); } } + builder.AppendLine(info.AllowedVerts, " Allowed verts"); } } @@ -921,6 +934,7 @@ namespace SabreTools.Serialization.Printers for (int i = 0; i < lump.Verts.Length; i++) { var vert = lump.Verts[i]; + builder.AppendLine($" Disp Vert {i}"); builder.AppendLine($" Vec: ({vert.Vec?.X}, {vert.Vec?.Y}, {vert.Vec?.Z})"); builder.AppendLine(vert.Dist, " Dist"); @@ -940,19 +954,19 @@ namespace SabreTools.Serialization.Printers if (lump.Directories == null || lump.Directories.Length == 0) { builder.AppendLine(" No directories"); + return; } - else + + for (int i = 0; i < lump.Directories.Length; i++) { - for (int i = 0; i < lump.Directories.Length; i++) - { - var dir = lump.Directories[i]; - builder.AppendLine($" Game Lump Directory {i}"); - builder.AppendLine(dir.Id, " Id"); - builder.AppendLine(dir.Flags, " Flags"); - builder.AppendLine(dir.Version, " Version"); - builder.AppendLine(dir.FileOffset, " File offset"); - builder.AppendLine(dir.FileLength, " File length"); - } + var dir = lump.Directories[i]; + + builder.AppendLine($" Game Lump Directory {i}"); + builder.AppendLine(dir.Id, " Id"); + builder.AppendLine(dir.Flags, " Flags"); + builder.AppendLine(dir.Version, " Version"); + builder.AppendLine(dir.FileOffset, " File offset"); + builder.AppendLine(dir.FileLength, " File length"); } } @@ -978,6 +992,7 @@ namespace SabreTools.Serialization.Printers for (int i = 0; i < lump.Cubemaps.Length; i++) { var cubemap = lump.Cubemaps[i]; + builder.AppendLine($" Cubemap {i}"); builder.AppendLine(cubemap.Origin, " Origin"); builder.AppendLine(cubemap.Size, " Size"); @@ -1025,6 +1040,7 @@ namespace SabreTools.Serialization.Printers for (int i = 0; i < lump.Overlays.Length; i++) { var overlay = lump.Overlays[i]; + builder.AppendLine($" Overlay {i}"); builder.AppendLine(overlay.Id, " Id"); builder.AppendLine(overlay.TexInfo, " Texinfo"); @@ -1044,6 +1060,7 @@ namespace SabreTools.Serialization.Printers builder.AppendLine($" UV Point {j}: ({point.X}, {point.Y}, {point.Z})"); } } + builder.AppendLine($" Origin: ({overlay.Origin?.X}, {overlay.Origin?.Y}, {overlay.Origin?.Z})"); builder.AppendLine($" Basis normal: ({overlay.BasisNormal?.X}, {overlay.BasisNormal?.Y}, {overlay.BasisNormal?.Z})"); } @@ -1060,6 +1077,7 @@ namespace SabreTools.Serialization.Printers for (int i = 0; i < lump.Tris.Length; i++) { var tri = lump.Tris[i]; + builder.AppendLine($" Disp Tri {i}"); builder.AppendLine($" Tags: {tri.Tags} (0x{tri.Tags:X})"); } @@ -1076,6 +1094,7 @@ namespace SabreTools.Serialization.Printers for (int i = 0; i < lump.Indicies.Length; i++) { var index = lump.Indicies[i]; + builder.AppendLine($" Index {i}"); builder.AppendLine(index.AmbientSampleCount, " Ambient sample count"); builder.AppendLine(index.FirstAmbientSample, " First ambient sample"); @@ -1093,6 +1112,7 @@ namespace SabreTools.Serialization.Printers for (int i = 0; i < lump.Lightings.Length; i++) { var lighting = lump.Lightings[i]; + builder.AppendLine($" Lighting {i}"); builder.AppendLine(" Colors array skipped..."); builder.AppendLine(lighting.X, " X"); diff --git a/SabreTools.Serialization/Wrappers/BSP.cs b/SabreTools.Serialization/Wrappers/BSP.cs index 8c57545e..d4f971da 100644 --- a/SabreTools.Serialization/Wrappers/BSP.cs +++ b/SabreTools.Serialization/Wrappers/BSP.cs @@ -115,12 +115,8 @@ namespace SabreTools.Serialization.Wrappers if (index < 0 || index >= Model.Header.Lumps.Length) return false; - // Get the lump - var lump = Model.Header.Lumps[index]; - if (lump == null) - return false; - // Read the data + var lump = Model.Header.Lumps[index]; var data = ReadFromDataSource(lump.Offset, lump.Length); if (data == null) return false; diff --git a/SabreTools.Serialization/Wrappers/CFB.cs b/SabreTools.Serialization/Wrappers/CFB.cs index 5e5b1dbd..5c272bd3 100644 --- a/SabreTools.Serialization/Wrappers/CFB.cs +++ b/SabreTools.Serialization/Wrappers/CFB.cs @@ -98,14 +98,14 @@ namespace SabreTools.Serialization.Wrappers /// /// Initial FAT sector /// Ordered list of sector numbers, null on error - public List? GetFATSectorChain(Models.CFB.SectorNumber? startingSector) + public List? GetFATSectorChain(Models.CFB.SectorNumber? startingSector) { // If we have an invalid sector if (startingSector == null || startingSector < 0 || Model.FATSectorNumbers == null || (long)startingSector >= Model.FATSectorNumbers.Length) return null; // Setup the returned list - var sectors = new List { startingSector }; + var sectors = new List { startingSector.Value }; var lastSector = startingSector; while (true) @@ -169,7 +169,7 @@ namespace SabreTools.Serialization.Wrappers public long FATSectorToFileOffset(Models.CFB.SectorNumber? sector) { // If we have an invalid sector number - if (sector == null || sector > SabreTools.Models.CFB.SectorNumber.MAXREGSECT) + if (sector == null || sector > Models.CFB.SectorNumber.MAXREGSECT) return -1; // Convert based on the sector shift value @@ -185,14 +185,14 @@ namespace SabreTools.Serialization.Wrappers /// /// Initial Mini FAT sector /// Ordered list of sector numbers, null on error - public List? GetMiniFATSectorChain(Models.CFB.SectorNumber? startingSector) + public List? GetMiniFATSectorChain(Models.CFB.SectorNumber? startingSector) { // If we have an invalid sector if (startingSector == null || startingSector < 0 || Model.MiniFATSectorNumbers == null || (long)startingSector >= Model.MiniFATSectorNumbers.Length) return null; // Setup the returned list - var sectors = new List { startingSector }; + var sectors = new List { startingSector.Value }; var lastSector = startingSector; while (true) @@ -256,7 +256,7 @@ namespace SabreTools.Serialization.Wrappers public long MiniFATSectorToFileOffset(Models.CFB.SectorNumber? sector) { // If we have an invalid sector number - if (sector == null || sector > SabreTools.Models.CFB.SectorNumber.MAXREGSECT) + if (sector == null || sector > Models.CFB.SectorNumber.MAXREGSECT) return -1; // Convert based on the sector shift value diff --git a/SabreTools.Serialization/Wrappers/GCF.cs b/SabreTools.Serialization/Wrappers/GCF.cs index 72b33626..d690927b 100644 --- a/SabreTools.Serialization/Wrappers/GCF.cs +++ b/SabreTools.Serialization/Wrappers/GCF.cs @@ -73,9 +73,6 @@ namespace SabreTools.Serialization.Wrappers while (index != Model.DataBlockHeader?.BlockCount) { var nextBlock = Model.BlockEntries[index]; - if (nextBlock == null) - break; - blockEntries.Add(nextBlock); index = nextBlock.NextBlockEntryIndex; } diff --git a/SabreTools.Serialization/Wrappers/MicrosoftCabinet.cs b/SabreTools.Serialization/Wrappers/MicrosoftCabinet.cs index 31496a7c..532275cc 100644 --- a/SabreTools.Serialization/Wrappers/MicrosoftCabinet.cs +++ b/SabreTools.Serialization/Wrappers/MicrosoftCabinet.cs @@ -127,12 +127,8 @@ namespace SabreTools.Serialization.Wrappers if (fileIndex < 0 || Model.Files == null || fileIndex >= Model.Files.Length) return null; - // Get the file header - var file = Model.Files[fileIndex]; - if (file == null) - return null; - // If we have an invalid DateTime + var file = Model.Files[fileIndex]; if (file.Date == 0 && file.Time == 0) return null; diff --git a/SabreTools.Serialization/Wrappers/PAK.cs b/SabreTools.Serialization/Wrappers/PAK.cs index 03f5b5d7..3be21b0a 100644 --- a/SabreTools.Serialization/Wrappers/PAK.cs +++ b/SabreTools.Serialization/Wrappers/PAK.cs @@ -122,12 +122,8 @@ namespace SabreTools.Serialization.Wrappers if (index < 0 || index >= DirectoryItems.Length) return false; - // Get the directory item - var directoryItem = DirectoryItems[index]; - if (directoryItem == null) - return false; - // Read the item data + var directoryItem = DirectoryItems[index]; var data = ReadFromDataSource((int)directoryItem.ItemOffset, (int)directoryItem.ItemLength); if (data == null) return false; diff --git a/SabreTools.Serialization/Wrappers/PFF.cs b/SabreTools.Serialization/Wrappers/PFF.cs index cb432471..e88256e8 100644 --- a/SabreTools.Serialization/Wrappers/PFF.cs +++ b/SabreTools.Serialization/Wrappers/PFF.cs @@ -131,14 +131,10 @@ namespace SabreTools.Serialization.Wrappers if (index < 0 || index >= Segments.Length) return false; - // Get the segment information - var file = Segments[index]; - if (file == null) - return false; - // Get the read index and length - int offset = (int)file.FileLocation; - int size = (int)file.FileSize; + var segment = Segments[index]; + int offset = (int)segment.FileLocation; + int size = (int)segment.FileSize; try { @@ -146,7 +142,7 @@ namespace SabreTools.Serialization.Wrappers Directory.CreateDirectory(outputDirectory); // Create the output path - string filePath = Path.Combine(outputDirectory, file.FileName ?? $"file{index}"); + string filePath = Path.Combine(outputDirectory, segment.FileName ?? $"file{index}"); using FileStream fs = File.OpenWrite(filePath); // Read the data block diff --git a/SabreTools.Serialization/Wrappers/VBSP.cs b/SabreTools.Serialization/Wrappers/VBSP.cs index 681c2d41..97521641 100644 --- a/SabreTools.Serialization/Wrappers/VBSP.cs +++ b/SabreTools.Serialization/Wrappers/VBSP.cs @@ -115,12 +115,8 @@ namespace SabreTools.Serialization.Wrappers if (index < 0 || index >= Model.Header.Lumps.Length) return false; - // Get the lump - var lump = Model.Header.Lumps[index]; - if (lump == null) - return false; - // Read the data + var lump = Model.Header.Lumps[index]; var data = ReadFromDataSource(lump.Offset, lump.Length); if (data == null) return false; diff --git a/SabreTools.Serialization/Wrappers/WAD3.cs b/SabreTools.Serialization/Wrappers/WAD3.cs index 2efb72f5..ae5befa0 100644 --- a/SabreTools.Serialization/Wrappers/WAD3.cs +++ b/SabreTools.Serialization/Wrappers/WAD3.cs @@ -114,12 +114,8 @@ namespace SabreTools.Serialization.Wrappers if (index < 0 || index >= Model.DirEntries.Length) return false; - // Get the lump - var lump = Model.DirEntries[index]; - if (lump == null) - return false; - // Read the data -- TODO: Handle uncompressed lumps (see BSP.ExtractTexture) + var lump = Model.DirEntries[index]; var data = ReadFromDataSource((int)lump.Offset, (int)lump.Length); if (data == null) return false; diff --git a/SabreTools.Serialization/Wrappers/XZP.cs b/SabreTools.Serialization/Wrappers/XZP.cs index 5c7d6638..7bbe8a10 100644 --- a/SabreTools.Serialization/Wrappers/XZP.cs +++ b/SabreTools.Serialization/Wrappers/XZP.cs @@ -119,10 +119,8 @@ namespace SabreTools.Serialization.Wrappers if (index < 0 || index >= Model.DirectoryEntries.Length) return false; - // Get the directory entry - var directoryEntry = Model.DirectoryEntries[index]; - // Get the associated directory item + var directoryEntry = Model.DirectoryEntries[index]; var directoryItem = Array.Find(Model.DirectoryItems, di => di?.FileNameCRC == directoryEntry.FileNameCRC); if (directoryItem == null) return false;