mirror of
https://github.com/SabreTools/BinaryObjectScanner.git
synced 2026-02-14 05:36:07 +00:00
Add first part of NE printing
This commit is contained in:
@@ -17,6 +17,8 @@ namespace ExecutableTest
|
||||
// Loop through the args
|
||||
foreach (string arg in args)
|
||||
{
|
||||
Console.WriteLine($"Checking possible path: {arg}");
|
||||
|
||||
// Check the file exists
|
||||
if (!File.Exists(arg))
|
||||
{
|
||||
@@ -59,18 +61,24 @@ namespace ExecutableTest
|
||||
continue;
|
||||
}
|
||||
|
||||
// Try to read the new executable info
|
||||
// Try to read the executable info
|
||||
stream.Seek(msdos.Header.NewExeHeaderAddr, SeekOrigin.Begin);
|
||||
magic = stream.ReadBytes(4);
|
||||
|
||||
// New Executable
|
||||
if (magic[0] == 'N' && magic[1] == 'E')
|
||||
{
|
||||
Console.WriteLine($"New executable found. No parsing currently available.");
|
||||
Console.WriteLine();
|
||||
continue;
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
var newExecutable = NewExecutable.ParseExecutable(stream);
|
||||
if (newExecutable == null)
|
||||
{
|
||||
Console.WriteLine("Something went wrong parsing New Executable");
|
||||
Console.WriteLine();
|
||||
continue;
|
||||
}
|
||||
|
||||
// TODO: Implement NE reading
|
||||
// Print the executable info to screen
|
||||
PrintNewExecutable(newExecutable);
|
||||
}
|
||||
|
||||
// Linear Executable
|
||||
@@ -103,7 +111,6 @@ namespace ExecutableTest
|
||||
/// <summary>
|
||||
/// Pretty print the MS-DOS executable information
|
||||
/// </summary>
|
||||
/// <param name="executable"></param>
|
||||
private static void PrintMSDOS(BurnOutSharp.Models.MSDOS.Executable executable)
|
||||
{
|
||||
Console.WriteLine("MS-DOS Executable Information:");
|
||||
@@ -148,10 +155,123 @@ namespace ExecutableTest
|
||||
for (int i = 0; i < executable.RelocationTable.Length; i++)
|
||||
{
|
||||
var entry = executable.RelocationTable[i];
|
||||
Console.WriteLine($" Relocation Table Entry {i} - Offset = {entry.Offset}, Segment = {entry.Segment}");
|
||||
Console.WriteLine($" Relocation Table Entry {i}");
|
||||
Console.WriteLine($" Offset = {entry.Offset}");
|
||||
Console.WriteLine($" Segment = {entry.Segment}");
|
||||
}
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pretty print the New Executable information
|
||||
/// </summary>
|
||||
private static void PrintNewExecutable(BurnOutSharp.Models.NewExecutable.Executable executable)
|
||||
{
|
||||
Console.WriteLine("New Executable Information:");
|
||||
Console.WriteLine("-------------------------");
|
||||
Console.WriteLine();
|
||||
|
||||
Console.WriteLine(" MS-DOS Stub Information:");
|
||||
Console.WriteLine(" -------------------------");
|
||||
Console.WriteLine(" See 'MS-DOS Executable Information' for details");
|
||||
Console.WriteLine();
|
||||
|
||||
Console.WriteLine(" Header Information:");
|
||||
Console.WriteLine(" -------------------------");
|
||||
Console.WriteLine($" Magic number: {BitConverter.ToString(executable.Header.Magic).Replace("-", string.Empty)}");
|
||||
Console.WriteLine($" Linker version: {executable.Header.LinkerVersion}");
|
||||
Console.WriteLine($" Linker revision: {executable.Header.LinkerRevision}");
|
||||
Console.WriteLine($" Entry table offset: {executable.Header.EntryTableOffset}");
|
||||
Console.WriteLine($" Entry table size: {executable.Header.EntryTableSize}");
|
||||
Console.WriteLine($" CRC checksum: {executable.Header.CrcChecksum}");
|
||||
Console.WriteLine($" Flag word: {executable.Header.FlagWord}");
|
||||
Console.WriteLine($" Automatic data segment number: {executable.Header.AutomaticDataSegmentNumber}");
|
||||
Console.WriteLine($" Initial heap allocation: {executable.Header.InitialHeapAlloc}");
|
||||
Console.WriteLine($" Initial stack allocation: {executable.Header.InitialStackAlloc}");
|
||||
Console.WriteLine($" Initial CS:IP setting: {executable.Header.InitialCSIPSetting}");
|
||||
Console.WriteLine($" Initial SS:SP setting: {executable.Header.InitialSSSPSetting}");
|
||||
Console.WriteLine($" File segment count: {executable.Header.FileSegmentCount}");
|
||||
Console.WriteLine($" Module reference table size: {executable.Header.ModuleReferenceTableSize}");
|
||||
Console.WriteLine($" Non-resident name table size: {executable.Header.NonResidentNameTableSize}");
|
||||
Console.WriteLine($" Segment table offset: {executable.Header.SegmentTableOffset}");
|
||||
Console.WriteLine($" Resource table offset: {executable.Header.ResourceTableOffset}");
|
||||
Console.WriteLine($" Resident name table offset: {executable.Header.ResidentNameTableOffset}");
|
||||
Console.WriteLine($" Module reference table offset: {executable.Header.ModuleReferenceTableOffset}");
|
||||
Console.WriteLine($" Imported names table offset: {executable.Header.ImportedNamesTableOffset}");
|
||||
Console.WriteLine($" Non-resident name table offset: {executable.Header.NonResidentNamesTableOffset}");
|
||||
Console.WriteLine($" Moveable entries count: {executable.Header.MovableEntriesCount}");
|
||||
Console.WriteLine($" Segment alignment shift count: {executable.Header.SegmentAlignmentShiftCount}");
|
||||
Console.WriteLine($" Resource entries count: {executable.Header.ResourceEntriesCount}");
|
||||
Console.WriteLine($" Target operating system: {executable.Header.TargetOperatingSystem}");
|
||||
Console.WriteLine($" Additional flags: {executable.Header.AdditionalFlags}");
|
||||
Console.WriteLine($" Return thunk offset: {executable.Header.ReturnThunkOffset}");
|
||||
Console.WriteLine($" Segment reference thunk offset: {executable.Header.SegmentReferenceThunkOffset}");
|
||||
Console.WriteLine($" Minimum code swap area size: {executable.Header.MinCodeSwapAreaSize}");
|
||||
Console.WriteLine($" Windows SDK revision: {executable.Header.WindowsSDKRevision}");
|
||||
Console.WriteLine($" Windows SDK version: {executable.Header.WindowsSDKVersion}");
|
||||
Console.WriteLine();
|
||||
|
||||
Console.WriteLine(" Segment Table Information:");
|
||||
Console.WriteLine(" -------------------------");
|
||||
if (executable.Header.FileSegmentCount == 0 || executable.SegmentTable.Length == 0)
|
||||
{
|
||||
Console.WriteLine(" No segment table items");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < executable.SegmentTable.Length; i++)
|
||||
{
|
||||
var entry = executable.SegmentTable[i];
|
||||
Console.WriteLine($" Segment Table Entry {i}");
|
||||
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();
|
||||
|
||||
Console.WriteLine(" Resource Table Information:");
|
||||
Console.WriteLine(" -------------------------");
|
||||
Console.WriteLine($" Alignment shift count: {executable.ResourceTable.AlignmentShiftCount}");
|
||||
if (executable.Header.ResourceEntriesCount == 0 || executable.ResourceTable.ResourceTypes.Length == 0)
|
||||
{
|
||||
Console.WriteLine(" No resource table items");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < executable.ResourceTable.ResourceTypes.Length; i++)
|
||||
{
|
||||
// TODO: If not integer type, print out name
|
||||
var entry = executable.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++)
|
||||
{
|
||||
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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Console.WriteLine();
|
||||
|
||||
// TODO: Add table printing
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user