diff --git a/Include/Library/OcMachoLib.h b/Include/Library/OcMachoLib.h index 256f7833..826cf031 100644 --- a/Include/Library/OcMachoLib.h +++ b/Include/Library/OcMachoLib.h @@ -322,14 +322,18 @@ MachoIsSymbolValueInRange64 ( @param[in,out] Context Context of the Mach-O. @param[in] Address Address to search for. + @param[out] Symbol Buffer to output the symbol referenced by the + Relocation into. The output is undefined when FALSE + is returned. May be NULL. - @returns NULL NULL is returned on failure. + @returns Whether the Relocation exists. **/ -MACH_NLIST_64 * +BOOLEAN MachoGetSymbolByExternRelocationOffset64 ( IN OUT OC_MACHO_CONTEXT *Context, - IN UINT64 Address + IN UINT64 Address, + OUT MACH_NLIST_64 **Symbol ); /** diff --git a/Library/OcMachoLib/CxxSymbols.c b/Library/OcMachoLib/CxxSymbols.c index 9fee6c83..24d95f7f 100644 --- a/Library/OcMachoLib/CxxSymbols.c +++ b/Library/OcMachoLib/CxxSymbols.c @@ -569,6 +569,9 @@ MachoGetMetaclassSymbolFromSmcpSymbol64 ( IN CONST MACH_NLIST_64 *Smcp ) { + MACH_NLIST_64 *Symbol; + BOOLEAN Result; + ASSERT (Context != NULL); ASSERT (Smcp != NULL); @@ -576,10 +579,16 @@ MachoGetMetaclassSymbolFromSmcpSymbol64 ( return NULL; } - return MachoGetSymbolByExternRelocationOffset64 ( + Result = MachoGetSymbolByExternRelocationOffset64 ( Context, - Smcp->Value + Smcp->Value, + &Symbol ); + if (Result) { + return Symbol; + } + + return NULL; } /** diff --git a/Library/OcMachoLib/Symbols.c b/Library/OcMachoLib/Symbols.c index 1ecffd4f..11885a38 100644 --- a/Library/OcMachoLib/Symbols.c +++ b/Library/OcMachoLib/Symbols.c @@ -297,14 +297,18 @@ MachoGetIndirectSymbolName64 ( @param[in,out] Context Context of the Mach-O. @param[in] Address Address to search for. + @param[out] Symbol Buffer to output the symbol referenced by the + Relocation into. The output is undefined when FALSE + is returned. May be NULL. - @returns NULL NULL is returned on failure. + @returns Whether the Relocation exists. **/ -MACH_NLIST_64 * +BOOLEAN MachoGetSymbolByExternRelocationOffset64 ( IN OUT OC_MACHO_CONTEXT *Context, - IN UINT64 Address + IN UINT64 Address, + OUT MACH_NLIST_64 **Symbol ) { CONST MACH_RELOCATION_INFO *Relocation; @@ -313,10 +317,11 @@ MachoGetSymbolByExternRelocationOffset64 ( Relocation = InternalGetExternalRelocationByOffset (Context, Address); if (Relocation != NULL) { - return MachoGetSymbolByIndex64 (Context, Relocation->SymbolNumber); + *Symbol = MachoGetSymbolByIndex64 (Context, Relocation->SymbolNumber); + return TRUE; } - return NULL; + return FALSE; } /**