diff --git a/BurnOutSharp.Builder/Extensions.cs b/BurnOutSharp.Builder/Extensions.cs
index 21b5d8fb..7aa7bd88 100644
--- a/BurnOutSharp.Builder/Extensions.cs
+++ b/BurnOutSharp.Builder/Extensions.cs
@@ -112,6 +112,44 @@ namespace BurnOutSharp.Builder
return 0;
}
+ ///
+ /// Find the section a revlative virtual address lives in
+ ///
+ /// Relative virtual address to convert
+ /// Array of sections to check against
+ /// Section index, null on error
+ 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;
+ }
+
///
/// Read overlay data as a SecuROM AddD overlay data
///
diff --git a/BurnOutSharp.Wrappers/PortableExecutable.cs b/BurnOutSharp.Wrappers/PortableExecutable.cs
index e3c5bc68..e4c054ed 100644
--- a/BurnOutSharp.Wrappers/PortableExecutable.cs
+++ b/BurnOutSharp.Wrappers/PortableExecutable.cs
@@ -3239,6 +3239,20 @@ namespace BurnOutSharp.Wrappers
return SectionNames.Any(n => n.StartsWith(sectionName));
}
+ ///
+ /// Get the section index corresponding to the entry point, if possible
+ ///
+ /// Section index on success, null on error
+ 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);
+ }
+
///
/// Get the first section based on name, if possible
///
diff --git a/Developer Guide.md b/Developer Guide.md
index 6a3c825e..0f13a196 100644
--- a/Developer Guide.md
+++ b/Developer Guide.md
@@ -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. |