mirror of
https://github.com/claunia/libexeinfo.git
synced 2025-12-16 19:14:24 +00:00
Added NE resident and non-resident names.
This commit is contained in:
@@ -109,6 +109,20 @@ namespace exeinfo
|
|||||||
Console.WriteLine("\t\t\t{0}: {1}", strings.Key, strings.Value);
|
Console.WriteLine("\t\t\t{0}: {1}", strings.Key, strings.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(((NE)neExe).ResidentNames != null)
|
||||||
|
{
|
||||||
|
Console.WriteLine("\tResident names:");
|
||||||
|
foreach(NE.ResidentName name in ((NE)neExe).ResidentNames)
|
||||||
|
Console.WriteLine("\t\t{0} at index {1}", name.name, name.entryTableIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(((NE)neExe).NonResidentNames != null)
|
||||||
|
{
|
||||||
|
Console.WriteLine("\tNon-resident names:");
|
||||||
|
foreach(NE.ResidentName name in ((NE)neExe).NonResidentNames)
|
||||||
|
Console.WriteLine("\t\t{0} at index {1}", name.name, name.entryTableIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(lxExe.Recognized)
|
else if(lxExe.Recognized)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -213,6 +213,40 @@ namespace libexeinfo
|
|||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ResidentName[] GetResidentStrings(Stream stream, uint neStart, ushort tableOff, ushort upperLimit)
|
||||||
|
{
|
||||||
|
if(tableOff >= upperLimit) return null;
|
||||||
|
|
||||||
|
List<ResidentName> names = new List<ResidentName>();
|
||||||
|
byte stringSize;
|
||||||
|
byte[] nameString;
|
||||||
|
byte[] DW = new byte[2];
|
||||||
|
|
||||||
|
long oldPosition = stream.Position;
|
||||||
|
|
||||||
|
stream.Position = neStart + tableOff;
|
||||||
|
while(stream.Position < upperLimit + neStart)
|
||||||
|
{
|
||||||
|
stringSize = (byte)stream.ReadByte();
|
||||||
|
|
||||||
|
if(stringSize == 0) break;
|
||||||
|
|
||||||
|
nameString = new byte[stringSize];
|
||||||
|
stream.Read(nameString, 0, stringSize);
|
||||||
|
stream.Read(DW, 0, 2);
|
||||||
|
|
||||||
|
names.Add(new ResidentName
|
||||||
|
{
|
||||||
|
name = Encoding.ASCII.GetString(nameString),
|
||||||
|
entryTableIndex = BitConverter.ToUInt16(DW, 0)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
stream.Position = oldPosition;
|
||||||
|
|
||||||
|
return names.Count > 0 ? names.ToArray() : null;
|
||||||
|
}
|
||||||
|
|
||||||
public static ResourceTable GetResources(Stream stream, uint neStart, ushort tableOff, ushort upperLimit)
|
public static ResourceTable GetResources(Stream stream, uint neStart, ushort tableOff, ushort upperLimit)
|
||||||
{
|
{
|
||||||
long oldPosition = stream.Position;
|
long oldPosition = stream.Position;
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ namespace libexeinfo
|
|||||||
public NEHeader Header;
|
public NEHeader Header;
|
||||||
public ResourceTable Resources;
|
public ResourceTable Resources;
|
||||||
public Version[] Versions;
|
public Version[] Versions;
|
||||||
|
public ResidentName[] ResidentNames;
|
||||||
|
public ResidentName[] NonResidentNames;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="T:libexeinfo.NE" /> class.
|
/// Initializes a new instance of the <see cref="T:libexeinfo.NE" /> class.
|
||||||
@@ -194,13 +196,37 @@ namespace libexeinfo
|
|||||||
if(Header.imported_names_offset >= Header.resource_table_offset &&
|
if(Header.imported_names_offset >= Header.resource_table_offset &&
|
||||||
Header.imported_names_offset <= resourceUpperLimit) resourceUpperLimit = Header.imported_names_offset;
|
Header.imported_names_offset <= resourceUpperLimit) resourceUpperLimit = Header.imported_names_offset;
|
||||||
|
|
||||||
if(Header.resource_table_offset >= resourceUpperLimit || Header.resource_table_offset == 0) return;
|
if(Header.resource_table_offset < resourceUpperLimit && Header.resource_table_offset != 0)
|
||||||
|
{
|
||||||
Resources = GetResources(BaseStream, BaseExecutable.Header.new_offset, Header.resource_table_offset,
|
Resources = GetResources(BaseStream, BaseExecutable.Header.new_offset, Header.resource_table_offset,
|
||||||
resourceUpperLimit);
|
resourceUpperLimit);
|
||||||
Versions = GetVersions().ToArray();
|
Versions = GetVersions().ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resourceUpperLimit = ushort.MaxValue;
|
||||||
|
|
||||||
|
if(Header.entry_table_offset >= Header.resident_names_offset &&
|
||||||
|
Header.entry_table_offset <= resourceUpperLimit) resourceUpperLimit = Header.entry_table_offset;
|
||||||
|
if(Header.segment_table_offset >= Header.resident_names_offset &&
|
||||||
|
Header.segment_table_offset <= resourceUpperLimit) resourceUpperLimit = Header.segment_table_offset;
|
||||||
|
if(Header.module_reference_offset >= Header.resident_names_offset &&
|
||||||
|
Header.module_reference_offset <= resourceUpperLimit)
|
||||||
|
resourceUpperLimit = Header.module_reference_offset;
|
||||||
|
if(Header.nonresident_names_offset >= Header.resident_names_offset &&
|
||||||
|
Header.nonresident_names_offset <= resourceUpperLimit)
|
||||||
|
resourceUpperLimit = (ushort)Header.nonresident_names_offset;
|
||||||
|
if(Header.imported_names_offset >= Header.resident_names_offset &&
|
||||||
|
Header.imported_names_offset <= resourceUpperLimit) resourceUpperLimit = Header.imported_names_offset;
|
||||||
|
|
||||||
|
if(Header.resource_table_offset < resourceUpperLimit && Header.resource_table_offset != 0)
|
||||||
|
ResidentNames = GetResidentStrings(BaseStream, BaseExecutable.Header.new_offset,
|
||||||
|
Header.resident_names_offset, resourceUpperLimit);
|
||||||
|
|
||||||
|
if(Header.nonresident_table_size > 0)
|
||||||
|
NonResidentNames = GetResidentStrings(BaseStream, Header.nonresident_names_offset,
|
||||||
|
0, (ushort)(Header.nonresident_names_offset + Header.nonresident_table_size));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Identifies if the specified executable is a Microsoft New Executable
|
/// Identifies if the specified executable is a Microsoft New Executable
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -141,5 +141,17 @@ namespace libexeinfo
|
|||||||
public uint dwSignature;
|
public uint dwSignature;
|
||||||
public uint dwStrucVersion;
|
public uint dwStrucVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public struct ResidentName
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Text of string
|
||||||
|
/// </summary>
|
||||||
|
public string name;
|
||||||
|
/// <summary>
|
||||||
|
/// Index in the entry table this string refers to
|
||||||
|
/// </summary>
|
||||||
|
public ushort entryTableIndex;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user