mirror of
https://github.com/SabreTools/BinaryObjectScanner.git
synced 2026-05-06 20:43:44 +00:00
Add NE Resident Name table structures
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using BurnOutSharp.Tools;
|
||||
|
||||
namespace BurnOutSharp.ExecutableType.Microsoft.Entries
|
||||
{
|
||||
/// <summary>
|
||||
/// These name strings are case-sensitive and are not null-terminated
|
||||
/// </summary>
|
||||
public class ResidentNameTableEntry
|
||||
{
|
||||
/// <summary>
|
||||
/// Length of the name string that follows.
|
||||
/// A zero value indicates the end of the name table.
|
||||
/// </summary>
|
||||
public byte Length;
|
||||
|
||||
/// <summary>
|
||||
/// ASCII text of the name string.
|
||||
/// </summary>
|
||||
public byte[] Data;
|
||||
|
||||
/// <summary>
|
||||
/// Ordinal number (index into entry table).
|
||||
/// This value is ignored for the module name.
|
||||
/// </summary>
|
||||
public ushort OrdinalNumber;
|
||||
|
||||
/// <summary>
|
||||
/// ASCII text of the name string
|
||||
/// </summary>
|
||||
public string DataAsString
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Data == null)
|
||||
return string.Empty;
|
||||
|
||||
// Try to read direct as ASCII
|
||||
try
|
||||
{
|
||||
return Encoding.ASCII.GetString(Data);
|
||||
}
|
||||
catch { }
|
||||
|
||||
// If ASCII encoding fails, then just return an empty string
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public static ResidentNameTableEntry Deserialize(Stream stream)
|
||||
{
|
||||
var rnte = new ResidentNameTableEntry();
|
||||
|
||||
rnte.Length = stream.ReadByteValue();
|
||||
if (rnte.Length == 0)
|
||||
return rnte;
|
||||
|
||||
rnte.Data = stream.ReadBytes(rnte.Length);
|
||||
rnte.OrdinalNumber = stream.ReadUInt16();
|
||||
|
||||
return rnte;
|
||||
}
|
||||
|
||||
public static ResidentNameTableEntry Deserialize(byte[] content, ref int offset)
|
||||
{
|
||||
var rnte = new ResidentNameTableEntry();
|
||||
|
||||
rnte.Length = content.ReadByte(ref offset);
|
||||
if (rnte.Length == 0)
|
||||
return rnte;
|
||||
|
||||
rnte.Data = content.ReadBytes(ref offset, rnte.Length);
|
||||
rnte.OrdinalNumber = content.ReadUInt16(ref offset);
|
||||
|
||||
return rnte;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using BurnOutSharp.ExecutableType.Microsoft.Entries;
|
||||
|
||||
namespace BurnOutSharp.ExecutableType.Microsoft.Tables
|
||||
{
|
||||
/// <summary>
|
||||
/// The resident-name table follows the resource table, and contains this
|
||||
/// module's name string and resident exported procedure name strings. The
|
||||
/// first string in this table is this module's name. These name strings
|
||||
/// are case-sensitive and are not null-terminated.
|
||||
/// </summary>
|
||||
public class ResidentNameTable
|
||||
{
|
||||
/// <summary>
|
||||
/// The first string in this table is this module's name.
|
||||
/// These name strings are case-sensitive and are not null-terminated.
|
||||
/// </summary>
|
||||
public ResidentNameTableEntry[] NameTableEntries;
|
||||
|
||||
public static ResidentNameTable Deserialize(Stream stream)
|
||||
{
|
||||
var rnt = new ResidentNameTable();
|
||||
|
||||
var nameTableEntries = new List<ResidentNameTableEntry>();
|
||||
while (true)
|
||||
{
|
||||
var rnte = ResidentNameTableEntry.Deserialize(stream);
|
||||
if (rnte == null || rnte.Length == 0)
|
||||
break;
|
||||
|
||||
nameTableEntries.Add(rnte);
|
||||
}
|
||||
|
||||
rnt.NameTableEntries = nameTableEntries.ToArray();
|
||||
|
||||
return rnt;
|
||||
}
|
||||
|
||||
public static ResidentNameTable Deserialize(byte[] content, ref int offset)
|
||||
{
|
||||
var rnt = new ResidentNameTable();
|
||||
|
||||
var nameTableEntries = new List<ResidentNameTableEntry>();
|
||||
while (true)
|
||||
{
|
||||
var rnte = ResidentNameTableEntry.Deserialize(content, ref offset);
|
||||
if (rnte == null || rnte.Length == 0)
|
||||
break;
|
||||
|
||||
nameTableEntries.Add(rnte);
|
||||
}
|
||||
|
||||
rnt.NameTableEntries = nameTableEntries.ToArray();
|
||||
|
||||
return rnt;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user