mirror of
https://github.com/SabreTools/BinaryObjectScanner.git
synced 2026-07-11 03:17:00 +00:00
Port MZ to new printing
This commit is contained in:
81
BinaryObjectScanner.Printing/MSDOS.cs
Normal file
81
BinaryObjectScanner.Printing/MSDOS.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using System.Text;
|
||||
using SabreTools.Models.MSDOS;
|
||||
|
||||
namespace BinaryObjectScanner.Printing
|
||||
{
|
||||
public static class MSDOS
|
||||
{
|
||||
public static void Print(StringBuilder builder, Executable executable)
|
||||
{
|
||||
builder.AppendLine("MS-DOS Executable Information:");
|
||||
builder.AppendLine("-------------------------");
|
||||
builder.AppendLine();
|
||||
|
||||
Print(builder, executable.Header);
|
||||
Print(builder, executable.RelocationTable);
|
||||
}
|
||||
|
||||
#if NET48
|
||||
private static void Print(StringBuilder builder, ExecutableHeader header)
|
||||
#else
|
||||
private static void Print(StringBuilder builder, ExecutableHeader? header)
|
||||
#endif
|
||||
{
|
||||
builder.AppendLine(" Header Information:");
|
||||
builder.AppendLine(" -------------------------");
|
||||
if (header == null)
|
||||
{
|
||||
builder.AppendLine(" No header");
|
||||
builder.AppendLine();
|
||||
return;
|
||||
}
|
||||
|
||||
builder.AppendLine($" Magic number: {header.Magic}");
|
||||
builder.AppendLine($" Last page bytes: {header.LastPageBytes} (0x{header.LastPageBytes:X})");
|
||||
builder.AppendLine($" Pages: {header.Pages} (0x{header.Pages:X})");
|
||||
builder.AppendLine($" Relocation items: {header.RelocationItems} (0x{header.RelocationItems:X})");
|
||||
builder.AppendLine($" Header paragraph size: {header.HeaderParagraphSize} (0x{header.HeaderParagraphSize:X})");
|
||||
builder.AppendLine($" Minimum extra paragraphs: {header.MinimumExtraParagraphs} (0x{header.MinimumExtraParagraphs:X})");
|
||||
builder.AppendLine($" Maximum extra paragraphs: {header.MaximumExtraParagraphs} (0x{header.MaximumExtraParagraphs:X})");
|
||||
builder.AppendLine($" Initial SS value: {header.InitialSSValue} (0x{header.InitialSSValue:X})");
|
||||
builder.AppendLine($" Initial SP value: {header.InitialSPValue} (0x{header.InitialSPValue:X})");
|
||||
builder.AppendLine($" Checksum: {header.Checksum} (0x{header.Checksum:X})");
|
||||
builder.AppendLine($" Initial IP value: {header.InitialIPValue} (0x{header.InitialIPValue:X})");
|
||||
builder.AppendLine($" Initial CS value: {header.InitialCSValue} (0x{header.InitialCSValue:X})");
|
||||
builder.AppendLine($" Relocation table address: {header.RelocationTableAddr} (0x{header.RelocationTableAddr:X})");
|
||||
builder.AppendLine($" Overlay number: {header.OverlayNumber} (0x{header.OverlayNumber:X})");
|
||||
builder.AppendLine();
|
||||
}
|
||||
|
||||
#if NET48
|
||||
private static void Print(StringBuilder builder, RelocationEntry[] entries)
|
||||
#else
|
||||
private static void Print(StringBuilder builder, RelocationEntry?[]? entries)
|
||||
#endif
|
||||
{
|
||||
builder.AppendLine(" Relocation Table Information:");
|
||||
builder.AppendLine(" -------------------------");
|
||||
if (entries == null || entries.Length == 0)
|
||||
{
|
||||
builder.AppendLine(" No relocation table items");
|
||||
builder.AppendLine();
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < entries.Length; i++)
|
||||
{
|
||||
var entry = entries[i];
|
||||
builder.AppendLine($" Relocation Table Entry {i}");
|
||||
if (entry == null)
|
||||
{
|
||||
builder.AppendLine($" [NULL]");
|
||||
continue;
|
||||
}
|
||||
|
||||
builder.AppendLine($" Offset: {entry.Offset} (0x{entry.Offset:X})");
|
||||
builder.AppendLine($" Segment: {entry.Segment} (0x{entry.Segment:X})");
|
||||
}
|
||||
builder.AppendLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ namespace BinaryObjectScanner.Printing
|
||||
{
|
||||
public static class MicrosoftCabinet
|
||||
{
|
||||
|
||||
public static void Print(StringBuilder builder, Cabinet cabinet)
|
||||
{
|
||||
builder.AppendLine("Microsoft Cabinet Information:");
|
||||
@@ -15,7 +14,7 @@ namespace BinaryObjectScanner.Printing
|
||||
|
||||
Print(builder, cabinet.Header);
|
||||
Print(builder, cabinet.Folders);
|
||||
PrintFiles(builder, cabinet.Files);
|
||||
Print(builder, cabinet.Files);
|
||||
}
|
||||
|
||||
#if NET48
|
||||
@@ -131,9 +130,9 @@ namespace BinaryObjectScanner.Printing
|
||||
}
|
||||
|
||||
#if NET48
|
||||
private static void PrintFiles(StringBuilder builder, CFFILE[] entries)
|
||||
private static void Print(StringBuilder builder, CFFILE[] entries)
|
||||
#else
|
||||
private static void PrintFiles(StringBuilder builder, CFFILE?[]? entries)
|
||||
private static void Print(StringBuilder builder, CFFILE?[]? entries)
|
||||
#endif
|
||||
{
|
||||
builder.AppendLine(" Files:");
|
||||
|
||||
@@ -252,72 +252,10 @@ namespace BinaryObjectScanner.Wrappers
|
||||
public override StringBuilder PrettyPrint()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.AppendLine("MS-DOS Executable Information:");
|
||||
builder.AppendLine("-------------------------");
|
||||
builder.AppendLine();
|
||||
|
||||
PrintHeader(builder);
|
||||
PrintRelocationTable(builder);
|
||||
|
||||
Printing.MSDOS.Print(builder, _model);
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Print header information
|
||||
/// </summary>
|
||||
/// <param name="builder">StringBuilder to append information to</param>
|
||||
private void PrintHeader(StringBuilder builder)
|
||||
{
|
||||
builder.AppendLine(" Header Information:");
|
||||
builder.AppendLine(" -------------------------");
|
||||
builder.AppendLine($" Magic number: {Magic}");
|
||||
builder.AppendLine($" Last page bytes: {LastPageBytes} (0x{LastPageBytes:X})");
|
||||
builder.AppendLine($" Pages: {Pages} (0x{Pages:X})");
|
||||
builder.AppendLine($" Relocation items: {RelocationItems} (0x{RelocationItems:X})");
|
||||
builder.AppendLine($" Header paragraph size: {HeaderParagraphSize} (0x{HeaderParagraphSize:X})");
|
||||
builder.AppendLine($" Minimum extra paragraphs: {MinimumExtraParagraphs} (0x{MinimumExtraParagraphs:X})");
|
||||
builder.AppendLine($" Maximum extra paragraphs: {MaximumExtraParagraphs} (0x{MaximumExtraParagraphs:X})");
|
||||
builder.AppendLine($" Initial SS value: {InitialSSValue} (0x{InitialSSValue:X})");
|
||||
builder.AppendLine($" Initial SP value: {InitialSPValue} (0x{InitialSPValue:X})");
|
||||
builder.AppendLine($" Checksum: {Checksum} (0x{Checksum:X})");
|
||||
builder.AppendLine($" Initial IP value: {InitialIPValue} (0x{InitialIPValue:X})");
|
||||
builder.AppendLine($" Initial CS value: {InitialCSValue} (0x{InitialCSValue:X})");
|
||||
builder.AppendLine($" Relocation table address: {RelocationTableAddr} (0x{RelocationTableAddr:X})");
|
||||
builder.AppendLine($" Overlay number: {OverlayNumber} (0x{OverlayNumber:X})");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Print relocation table information
|
||||
/// </summary>
|
||||
/// <param name="builder">StringBuilder to append information to</param>
|
||||
private void PrintRelocationTable(StringBuilder builder)
|
||||
{
|
||||
builder.AppendLine(" Relocation Table Information:");
|
||||
builder.AppendLine(" -------------------------");
|
||||
if (RelocationItems == 0 || RelocationTable == null || RelocationTable.Length == 0)
|
||||
{
|
||||
builder.AppendLine(" No relocation table items");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < RelocationTable.Length; i++)
|
||||
{
|
||||
var entry = RelocationTable[i];
|
||||
builder.AppendLine($" Relocation Table Entry {i}");
|
||||
if (entry == null)
|
||||
{
|
||||
builder.AppendLine($" [NULL]");
|
||||
continue;
|
||||
}
|
||||
|
||||
builder.AppendLine($" Offset: {entry.Offset} (0x{entry.Offset:X})");
|
||||
builder.AppendLine($" Segment: {entry.Segment} (0x{entry.Segment:X})");
|
||||
}
|
||||
}
|
||||
builder.AppendLine();
|
||||
}
|
||||
|
||||
#if NET6_0_OR_GREATER
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
Reference in New Issue
Block a user