mirror of
https://github.com/acidanthera/OpenCorePkg.git
synced 2025-12-08 19:25:01 +00:00
OcMachoLib: Introduce MachoSymbolGetFileOffset64() API.
This commit is contained in:
parent
6b4d5120b6
commit
51c63ec135
@ -359,6 +359,21 @@ MachoRelocateSymbol64 (
|
||||
IN OUT MACH_NLIST_64 *Symbol
|
||||
);
|
||||
|
||||
/**
|
||||
Retrieves the Mach-O file offset of the address pointed to by Symbol.
|
||||
|
||||
@param[in] Context Context of the Mach-O.
|
||||
@param[in] Symbol Symbol to retrieve the offset of.
|
||||
|
||||
@retval 0 0 is returned on failure.
|
||||
|
||||
**/
|
||||
UINT32
|
||||
MachoSymbolGetFileOffset64 (
|
||||
IN OUT OC_MACHO_CONTEXT *Context,
|
||||
IN OUT MACH_NLIST_64 *Symbol
|
||||
);
|
||||
|
||||
/**
|
||||
Returns whether Name is pure virtual.
|
||||
|
||||
|
||||
@ -476,3 +476,41 @@ MachoRelocateSymbol64 (
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
Retrieves the Mach-O file offset of the address pointed to by Symbol.
|
||||
|
||||
@param[in] Context Context of the Mach-O.
|
||||
@param[in] Symbol Symbol to retrieve the offset of.
|
||||
|
||||
@retval 0 0 is returned on failure.
|
||||
|
||||
**/
|
||||
UINT32
|
||||
MachoSymbolGetFileOffset64 (
|
||||
IN OUT OC_MACHO_CONTEXT *Context,
|
||||
IN OUT MACH_NLIST_64 *Symbol
|
||||
)
|
||||
{
|
||||
UINT64 Offset;
|
||||
|
||||
CONST MACH_SECTION_64 *Section;
|
||||
|
||||
ASSERT (Context != NULL);
|
||||
ASSERT (Symbol != NULL);
|
||||
|
||||
Section = MachoGetSectionByIndex64 (Context, Symbol->Section);
|
||||
if ((Section == NULL) || (Symbol->Value < Section->Address)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Offset = (Symbol->Value - Section->Address);
|
||||
if (Offset > Section->Size) {
|
||||
return 0;
|
||||
}
|
||||
//
|
||||
// The check against Section->Size guarantees a 32-bit value for the current
|
||||
// library implementation.
|
||||
//
|
||||
return (Section->Offset + (UINT32)Offset);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user