mirror of
https://github.com/SabreTools/BinaryObjectScanner.git
synced 2026-07-08 18:06:34 +00:00
Start re-adding entry point
This commit is contained in:
@@ -112,6 +112,44 @@ namespace BurnOutSharp.Builder
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find the section a revlative virtual address lives in
|
||||
/// </summary>
|
||||
/// <param name="rva">Relative virtual address to convert</param>
|
||||
/// <param name="sections">Array of sections to check against</param>
|
||||
/// <returns>Section index, null on error</returns>
|
||||
public static int ContainingSectionIndex(this uint rva, Models.PortableExecutable.SectionHeader[] sections)
|
||||
{
|
||||
// If we have an invalid section table, we can't do anything
|
||||
if (sections == null || sections.Length == 0)
|
||||
return -1;
|
||||
|
||||
// If the RVA is 0, we just return -1 because it's invalid
|
||||
if (rva == 0)
|
||||
return -1;
|
||||
|
||||
// Loop through all of the sections
|
||||
for (int i = 0; i < sections.Length; i++)
|
||||
{
|
||||
// If the section is invalid, just skip it
|
||||
if (sections[i] == null)
|
||||
continue;
|
||||
|
||||
// If the section "starts" at 0, just skip it
|
||||
if (sections[i].PointerToRawData == 0)
|
||||
continue;
|
||||
|
||||
// Attempt to derive the physical address from the current section
|
||||
var section = sections[i];
|
||||
if (rva >= section.VirtualAddress && section.VirtualSize != 0 && rva <= section.VirtualAddress + section.VirtualSize)
|
||||
return i;
|
||||
else if (rva >= section.VirtualAddress && section.SizeOfRawData != 0 && rva <= section.VirtualAddress + section.SizeOfRawData)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read overlay data as a SecuROM AddD overlay data
|
||||
/// </summary>
|
||||
|
||||
@@ -3239,6 +3239,20 @@ namespace BurnOutSharp.Wrappers
|
||||
return SectionNames.Any(n => n.StartsWith(sectionName));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the section index corresponding to the entry point, if possible
|
||||
/// </summary>
|
||||
/// <returns>Section index on success, null on error</returns>
|
||||
public int FindEntryPointSectionIndex()
|
||||
{
|
||||
// If we don't have an entry point
|
||||
if (OH_AddressOfEntryPoint.ConvertVirtualAddress(SectionTable) == 0)
|
||||
return -1;
|
||||
|
||||
// Otherwise, find the section it exists within
|
||||
return OH_AddressOfEntryPoint.ContainingSectionIndex(SectionTable);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the first section based on name, if possible
|
||||
/// </summary>
|
||||
|
||||
@@ -74,6 +74,7 @@ Below are all current helper methods along with a brief description.
|
||||
| | `GetFirstSectionStrings(string, bool)` | Get the first section found ASCII and Unicode wide character strings (length >= 5) whose name matches the provided value, if it exists. |
|
||||
| | `GetLastSectionStrings(string, bool)` | Get the last section found ASCII and Unicode wide character strings (length >= 5) whose name matches the provided value, if it exists. |
|
||||
| | `GetSectionStrings(int)` | Get the section found ASCII and Unicode wide character strings (length >= 5) whose index matches the provided value, if it exists. |
|
||||
| | `FindEntryPointSection()` | Get the section header for the section that contains the entry point, if it exists. |
|
||||
| | `GetTableData(int)` | Get the table raw data whose index matches the provided value, if it exists. |
|
||||
| | `GetTableStrings(int)` | Get the table found ASCII and Unicode wide character strings (length >= 5) whose index matches the provided value, if it exists. |
|
||||
|
||||
|
||||
Reference in New Issue
Block a user