mirror of
https://github.com/SabreTools/BinaryObjectScanner.git
synced 2026-09-22 06:45:03 +00:00
Fix wrapper printing, add to info
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SharpCompress.Compressors;
|
||||
using SharpCompress.Compressors.Deflate;
|
||||
using static BurnOutSharp.Builder.Extensions;
|
||||
|
||||
namespace BurnOutSharp.Wrappers
|
||||
{
|
||||
@@ -166,64 +163,12 @@ namespace BurnOutSharp.Wrappers
|
||||
/// <inheritdoc/>
|
||||
public override void Print()
|
||||
{
|
||||
Console.WriteLine("New Executable Information:");
|
||||
Console.WriteLine("BFPK Information:");
|
||||
Console.WriteLine("-------------------------");
|
||||
Console.WriteLine();
|
||||
|
||||
// Stub
|
||||
PrintStubHeader();
|
||||
PrintStubExtendedHeader();
|
||||
|
||||
// Header
|
||||
PrintHeader();
|
||||
|
||||
// Tables
|
||||
PrintSegmentTable();
|
||||
PrintResourceTable();
|
||||
PrintResidentNameTable();
|
||||
PrintModuleReferenceTable();
|
||||
PrintImportedNameTable();
|
||||
PrintEntryTable();
|
||||
PrintNonresidentNameTable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Print stub header information
|
||||
/// </summary>
|
||||
private void PrintStubHeader()
|
||||
{
|
||||
Console.WriteLine(" MS-DOS Stub Header Information:");
|
||||
Console.WriteLine(" -------------------------");
|
||||
Console.WriteLine($" Magic number: {BitConverter.ToString(Stub_Magic).Replace("-", string.Empty)}");
|
||||
Console.WriteLine($" Last page bytes: {Stub_LastPageBytes}");
|
||||
Console.WriteLine($" Pages: {Stub_Pages}");
|
||||
Console.WriteLine($" Relocation items: {Stub_RelocationItems}");
|
||||
Console.WriteLine($" Header paragraph size: {Stub_HeaderParagraphSize}");
|
||||
Console.WriteLine($" Minimum extra paragraphs: {Stub_MinimumExtraParagraphs}");
|
||||
Console.WriteLine($" Maximum extra paragraphs: {Stub_MaximumExtraParagraphs}");
|
||||
Console.WriteLine($" Initial SS value: {Stub_InitialSSValue}");
|
||||
Console.WriteLine($" Initial SP value: {Stub_InitialSPValue}");
|
||||
Console.WriteLine($" Checksum: {Stub_Checksum}");
|
||||
Console.WriteLine($" Initial IP value: {Stub_InitialIPValue}");
|
||||
Console.WriteLine($" Initial CS value: {Stub_InitialCSValue}");
|
||||
Console.WriteLine($" Relocation table address: {Stub_RelocationTableAddr}");
|
||||
Console.WriteLine($" Overlay number: {Stub_OverlayNumber}");
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Print stub extended header information
|
||||
/// </summary>
|
||||
private void PrintStubExtendedHeader()
|
||||
{
|
||||
Console.WriteLine(" MS-DOS Stub Extended Header Information:");
|
||||
Console.WriteLine(" -------------------------");
|
||||
Console.WriteLine($" Reserved words: {string.Join(", ", Stub_Reserved1)}");
|
||||
Console.WriteLine($" OEM identifier: {Stub_OEMIdentifier}");
|
||||
Console.WriteLine($" OEM information: {Stub_OEMInformation}");
|
||||
Console.WriteLine($" Reserved words: {string.Join(", ", Stub_Reserved2)}");
|
||||
Console.WriteLine($" New EXE header address: {Stub_NewExeHeaderAddr}");
|
||||
Console.WriteLine();
|
||||
PrintFileTable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -233,255 +178,34 @@ namespace BurnOutSharp.Wrappers
|
||||
{
|
||||
Console.WriteLine(" Header Information:");
|
||||
Console.WriteLine(" -------------------------");
|
||||
Console.WriteLine($" Magic number: {BitConverter.ToString(Magic).Replace("-", string.Empty)}");
|
||||
Console.WriteLine($" Linker version: {LinkerVersion}");
|
||||
Console.WriteLine($" Linker revision: {LinkerRevision}");
|
||||
Console.WriteLine($" Entry table offset: {EntryTableOffset}");
|
||||
Console.WriteLine($" Entry table size: {EntryTableSize}");
|
||||
Console.WriteLine($" CRC checksum: {CrcChecksum}");
|
||||
Console.WriteLine($" Flag word: {FlagWord}");
|
||||
Console.WriteLine($" Automatic data segment number: {AutomaticDataSegmentNumber}");
|
||||
Console.WriteLine($" Initial heap allocation: {InitialHeapAlloc}");
|
||||
Console.WriteLine($" Initial stack allocation: {InitialStackAlloc}");
|
||||
Console.WriteLine($" Initial CS:IP setting: {InitialCSIPSetting}");
|
||||
Console.WriteLine($" Initial SS:SP setting: {InitialSSSPSetting}");
|
||||
Console.WriteLine($" File segment count: {FileSegmentCount}");
|
||||
Console.WriteLine($" Module reference table size: {ModuleReferenceTableSize}");
|
||||
Console.WriteLine($" Non-resident name table size: {NonResidentNameTableSize}");
|
||||
Console.WriteLine($" Segment table offset: {SegmentTableOffset}");
|
||||
Console.WriteLine($" Resource table offset: {ResourceTableOffset}");
|
||||
Console.WriteLine($" Resident name table offset: {ResidentNameTableOffset}");
|
||||
Console.WriteLine($" Module reference table offset: {ModuleReferenceTableOffset}");
|
||||
Console.WriteLine($" Imported names table offset: {ImportedNamesTableOffset}");
|
||||
Console.WriteLine($" Non-resident name table offset: {NonResidentNamesTableOffset}");
|
||||
Console.WriteLine($" Moveable entries count: {MovableEntriesCount}");
|
||||
Console.WriteLine($" Segment alignment shift count: {SegmentAlignmentShiftCount}");
|
||||
Console.WriteLine($" Resource entries count: {ResourceEntriesCount}");
|
||||
Console.WriteLine($" Target operating system: {TargetOperatingSystem}");
|
||||
Console.WriteLine($" Additional flags: {AdditionalFlags}");
|
||||
Console.WriteLine($" Return thunk offset: {ReturnThunkOffset}");
|
||||
Console.WriteLine($" Segment reference thunk offset: {SegmentReferenceThunkOffset}");
|
||||
Console.WriteLine($" Minimum code swap area size: {MinCodeSwapAreaSize}");
|
||||
Console.WriteLine($" Windows SDK revision: {WindowsSDKRevision}");
|
||||
Console.WriteLine($" Windows SDK version: {WindowsSDKVersion}");
|
||||
Console.WriteLine($" Magic: {Magic}");
|
||||
Console.WriteLine($" Version: {Version}");
|
||||
Console.WriteLine($" Files: {Files}");
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Print segment table information
|
||||
/// Print file table information
|
||||
/// </summary>
|
||||
private void PrintSegmentTable()
|
||||
private void PrintFileTable()
|
||||
{
|
||||
Console.WriteLine(" Segment Table Information:");
|
||||
Console.WriteLine(" File Table Information:");
|
||||
Console.WriteLine(" -------------------------");
|
||||
if (FileSegmentCount == 0 || SegmentTable.Length == 0)
|
||||
if (Files == 0 || FileTable == null || FileTable.Length == 0)
|
||||
{
|
||||
Console.WriteLine(" No segment table items");
|
||||
Console.WriteLine(" No file table items");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < SegmentTable.Length; i++)
|
||||
for (int i = 0; i < FileTable.Length; i++)
|
||||
{
|
||||
var entry = SegmentTable[i];
|
||||
Console.WriteLine($" Segment Table Entry {i}");
|
||||
var entry = FileTable[i];
|
||||
Console.WriteLine($" File Table Entry {i}");
|
||||
Console.WriteLine($" Name size = {entry.NameSize}");
|
||||
Console.WriteLine($" Name = {entry.Name}");
|
||||
Console.WriteLine($" Uncompressed size = {entry.UncompressedSize}");
|
||||
Console.WriteLine($" Offset = {entry.Offset}");
|
||||
Console.WriteLine($" Length = {entry.Length}");
|
||||
Console.WriteLine($" Flag word = {entry.FlagWord}");
|
||||
Console.WriteLine($" Minimum allocation size = {entry.MinimumAllocationSize}");
|
||||
}
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Print resource table information
|
||||
/// </summary>
|
||||
private void PrintResourceTable()
|
||||
{
|
||||
Console.WriteLine(" Resource Table Information:");
|
||||
Console.WriteLine(" -------------------------");
|
||||
Console.WriteLine($" Alignment shift count: {ResourceTable.AlignmentShiftCount}");
|
||||
if (ResourceEntriesCount == 0 || ResourceTable.ResourceTypes.Length == 0)
|
||||
{
|
||||
Console.WriteLine(" No resource table items");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < ResourceTable.ResourceTypes.Length; i++)
|
||||
{
|
||||
// TODO: If not integer type, print out name
|
||||
var entry = ResourceTable.ResourceTypes[i];
|
||||
Console.WriteLine($" Resource Table Entry {i}");
|
||||
Console.WriteLine($" Type ID = {entry.TypeID} (Is Integer Type: {entry.IsIntegerType()})");
|
||||
Console.WriteLine($" Resource count = {entry.ResourceCount}");
|
||||
Console.WriteLine($" Reserved = {entry.Reserved}");
|
||||
Console.WriteLine($" Resources = ");
|
||||
if (entry.ResourceCount == 0 || entry.Resources.Length == 0)
|
||||
{
|
||||
Console.WriteLine(" No resource items");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int j = 0; j < entry.Resources.Length; j++)
|
||||
{
|
||||
// TODO: If not integer type, print out name
|
||||
var resource = entry.Resources[j];
|
||||
Console.WriteLine($" Resource Entry {i}");
|
||||
Console.WriteLine($" Offset = {resource.Offset}");
|
||||
Console.WriteLine($" Length = {resource.Length}");
|
||||
Console.WriteLine($" Flag word = {resource.FlagWord}");
|
||||
Console.WriteLine($" Resource ID = {resource.ResourceID} (Is Integer Type: {resource.IsIntegerType()})");
|
||||
Console.WriteLine($" Reserved = {resource.Reserved}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ResourceTable.TypeAndNameStrings.Count == 0)
|
||||
{
|
||||
Console.WriteLine(" No resource table type/name strings");
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var typeAndNameString in ResourceTable.TypeAndNameStrings)
|
||||
{
|
||||
Console.WriteLine($" Resource Type/Name Offset {typeAndNameString.Key}");
|
||||
Console.WriteLine($" Length = {typeAndNameString.Value.Length}");
|
||||
Console.WriteLine($" Text = {Encoding.ASCII.GetString(typeAndNameString.Value.Text)}");
|
||||
}
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Print resident-name table information
|
||||
/// </summary>
|
||||
private void PrintResidentNameTable()
|
||||
{
|
||||
Console.WriteLine(" Resident-Name Table Information:");
|
||||
Console.WriteLine(" -------------------------");
|
||||
if (ResidentNameTableOffset == 0 || ResidentNameTable.Length == 0)
|
||||
{
|
||||
Console.WriteLine(" No resident-name table items");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < ResidentNameTable.Length; i++)
|
||||
{
|
||||
var entry = ResidentNameTable[i];
|
||||
Console.WriteLine($" Resident-Name Table Entry {i}");
|
||||
Console.WriteLine($" Length = {entry.Length}");
|
||||
Console.WriteLine($" Name string = {(entry.NameString != null ? Encoding.ASCII.GetString(entry.NameString) : "[EMPTY]")}");
|
||||
Console.WriteLine($" Ordinal number = {entry.OrdinalNumber}");
|
||||
}
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Print module-reference table information
|
||||
/// </summary>
|
||||
private void PrintModuleReferenceTable()
|
||||
{
|
||||
Console.WriteLine(" Module-Reference Table Information:");
|
||||
Console.WriteLine(" -------------------------");
|
||||
if (ModuleReferenceTableSize == 0 || ModuleReferenceTable.Length == 0)
|
||||
{
|
||||
Console.WriteLine(" No module-reference table items");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < ModuleReferenceTable.Length; i++)
|
||||
{
|
||||
// TODO: Read the imported names table and print value here
|
||||
var entry = ModuleReferenceTable[i];
|
||||
Console.WriteLine($" Module-Reference Table Entry {i}");
|
||||
Console.WriteLine($" Offset = {entry.Offset} (adjusted to be {entry.Offset + Stub_NewExeHeaderAddr + ImportedNamesTableOffset})");
|
||||
}
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Print imported-name table information
|
||||
/// </summary>
|
||||
private void PrintImportedNameTable()
|
||||
{
|
||||
Console.WriteLine(" Imported-Name Table Information:");
|
||||
Console.WriteLine(" -------------------------");
|
||||
if (ImportedNamesTableOffset == 0 || ImportedNameTable.Count == 0)
|
||||
{
|
||||
Console.WriteLine(" No imported-name table items");
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var entry in ImportedNameTable)
|
||||
{
|
||||
Console.WriteLine($" Imported-Name Table at Offset {entry.Key}");
|
||||
Console.WriteLine($" Length = {entry.Value.Length}");
|
||||
Console.WriteLine($" Name string = {(entry.Value.NameString != null ? Encoding.ASCII.GetString(entry.Value.NameString) : "[EMPTY]")}");
|
||||
}
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Print entry table information
|
||||
/// </summary>
|
||||
private void PrintEntryTable()
|
||||
{
|
||||
Console.WriteLine(" Entry Table Information:");
|
||||
Console.WriteLine(" -------------------------");
|
||||
if (EntryTableSize == 0 || EntryTable.Length == 0)
|
||||
{
|
||||
Console.WriteLine(" No entry table items");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < EntryTable.Length; i++)
|
||||
{
|
||||
var entry = EntryTable[i];
|
||||
Console.WriteLine($" Entry Table Entry {i}");
|
||||
Console.WriteLine($" Entry count = {entry.EntryCount}");
|
||||
Console.WriteLine($" Segment indicator = {entry.SegmentIndicator} ({entry.GetEntryType()})");
|
||||
switch (entry.GetEntryType())
|
||||
{
|
||||
case BurnOutSharp.Models.NewExecutable.SegmentEntryType.FixedSegment:
|
||||
Console.WriteLine($" Flag word = {entry.FixedFlagWord}");
|
||||
Console.WriteLine($" Offset = {entry.FixedOffset}");
|
||||
break;
|
||||
case BurnOutSharp.Models.NewExecutable.SegmentEntryType.MoveableSegment:
|
||||
Console.WriteLine($" Flag word = {entry.MoveableFlagWord}");
|
||||
Console.WriteLine($" Reserved = {entry.MoveableReserved}");
|
||||
Console.WriteLine($" Segment number = {entry.MoveableSegmentNumber}");
|
||||
Console.WriteLine($" Offset = {entry.MoveableOffset}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Print nonresident-name table information
|
||||
/// </summary>
|
||||
private void PrintNonresidentNameTable()
|
||||
{
|
||||
Console.WriteLine(" Nonresident-Name Table Information:");
|
||||
Console.WriteLine(" -------------------------");
|
||||
if (NonResidentNameTableSize == 0 || NonResidentNameTable.Length == 0)
|
||||
{
|
||||
Console.WriteLine(" No nonresident-name table items");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < NonResidentNameTable.Length; i++)
|
||||
{
|
||||
var entry = NonResidentNameTable[i];
|
||||
Console.WriteLine($" Nonresident-Name Table Entry {i}");
|
||||
Console.WriteLine($" Length = {entry.Length}");
|
||||
Console.WriteLine($" Name string = {(entry.NameString != null ? Encoding.ASCII.GetString(entry.NameString) : "[EMPTY]")}");
|
||||
Console.WriteLine($" Ordinal number = {entry.OrdinalNumber}");
|
||||
Console.WriteLine($" Compressed Size = {entry.CompressedSize}");
|
||||
}
|
||||
}
|
||||
Console.WriteLine();
|
||||
|
||||
@@ -292,6 +292,25 @@ namespace Test
|
||||
}
|
||||
}
|
||||
|
||||
// BFPK archive
|
||||
else if (IsBFPK(magic))
|
||||
{
|
||||
// Build the BFPK information
|
||||
Console.WriteLine("Creating BFPK deserializer");
|
||||
Console.WriteLine();
|
||||
|
||||
var bfpk = BFPK.Create(stream);
|
||||
if (bfpk == null)
|
||||
{
|
||||
Console.WriteLine("Something went wrong parsing BFPK archive");
|
||||
Console.WriteLine();
|
||||
return;
|
||||
}
|
||||
|
||||
// Print the BFPK info to screen
|
||||
bfpk.Print();
|
||||
}
|
||||
|
||||
// MoPaQ (MPQ) archive
|
||||
else if (IsMoPaQ(magic))
|
||||
{
|
||||
@@ -334,6 +353,17 @@ namespace Test
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determine if the magic bytes indicate an BFPK archive
|
||||
/// </summary>
|
||||
private static bool IsBFPK(byte[] magic)
|
||||
{
|
||||
if (magic == null || magic.Length < 4)
|
||||
return false;
|
||||
|
||||
return magic[0] == 'B' && magic[1] == 'F' && magic[2] == 'P' && magic[3] == 'K';
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determine if the magic bytes indicate an MoPaQ archive
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user