OcMachoLib: Implement MachoGetLastAddress via MachoGet*Segment.
@@ -18,6 +18,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
+#include <Library/OcMachoLib.h>
/**
Returns the last virtual address of a MACH-O.
@@ -32,8 +33,7 @@ MachoGetLastAddress64 (
{
UINT64 LastAddress;
- MACH_LOAD_COMMAND_PTR Command;
- UINTN Index;
+ CONST MACH_SEGMENT_COMMAND_64 *Segment;
UINT64 Address;
ASSERT (MachHeader != NULL);
@@ -44,20 +44,18 @@ MachoGetLastAddress64 (
LastAddress = 0;
- Command.Hdr = &MachHeader->Commands[0];
-
- for (Index = 0; Index < MachHeader->NumberOfCommands; ++Index) {
- if (Command.Hdr->Type == MACH_LOAD_COMMAND_SEGMENT_64) {
- Address = (Command.Segment64->VirtualAddress + Command.Hdr->Size);
+ for (
+ Segment = MachoGetFirstSegment64 (MachHeader);
+ Segment != NULL;
+ Segment = MachoGetNextSegment64 (MachHeader, Segment)
+ ) {
+ Address = (Segment->VirtualAddress + Segment->Hdr.Size);
if (Address > LastAddress) {
LastAddress = Address;
}
}
- Command.Hdr = NEXT_MACH_LOAD_COMMAND (Command.Hdr);
- }
-
return LastAddress;
}
