From 48ea3b19f14aaea3827ea9bbcb6c914e79b01ef4 Mon Sep 17 00:00:00 2001 From: Download-Fritz Date: Sun, 21 Oct 2018 14:39:04 +0200 Subject: [PATCH] OcMachoLib: Get C++ symbols via relocations only from the extern ones. --- Include/Library/OcMachoLib.h | 4 +-- Library/OcMachoLib/CxxSymbols.c | 2 +- Library/OcMachoLib/Symbols.c | 43 ++++++--------------------------- 3 files changed, 10 insertions(+), 39 deletions(-) diff --git a/Include/Library/OcMachoLib.h b/Include/Library/OcMachoLib.h index ac205573..f82e1c2f 100644 --- a/Include/Library/OcMachoLib.h +++ b/Include/Library/OcMachoLib.h @@ -293,7 +293,7 @@ MachoRelocateSymbol64 ( ); /** - Retrieves a symbol by the Relocation it is referenced by. + Retrieves a C++ symbol by the Relocation it is referenced by. @param[in,out] Context Context of the Mach-O. @param[in] Relocation The Relocation to evaluate. @@ -302,7 +302,7 @@ MachoRelocateSymbol64 ( **/ CONST MACH_NLIST_64 * -MachoGetCxxSymbolByRelocation64 ( +MachoGetCxxSymbolByExternRelocation64 ( IN OUT VOID *Context, IN CONST MACH_RELOCATION_INFO *Relocation ); diff --git a/Library/OcMachoLib/CxxSymbols.c b/Library/OcMachoLib/CxxSymbols.c index ced75e69..506c2c7c 100644 --- a/Library/OcMachoLib/CxxSymbols.c +++ b/Library/OcMachoLib/CxxSymbols.c @@ -571,7 +571,7 @@ MachoGetMetaclassSymbolFromSmcpSymbol64 ( return NULL; } - return MachoGetCxxSymbolByRelocation64 (Context, Relocation); + return MachoGetCxxSymbolByExternRelocation64 (Context, Relocation); } /** diff --git a/Library/OcMachoLib/Symbols.c b/Library/OcMachoLib/Symbols.c index 3175c3dc..d5a552a8 100644 --- a/Library/OcMachoLib/Symbols.c +++ b/Library/OcMachoLib/Symbols.c @@ -385,16 +385,16 @@ MachoRelocateSymbol64 ( } /** - Retrieves a symbol by the Relocation it is referenced by. + Retrieves a C++ symbol by the extern Relocation it is referenced by. @param[in,out] Context Context of the Mach-O. - @param[in] Relocation The Relocation to evaluate. + @param[in] Relocation The extern Relocation to evaluate. @retval NULL NULL is returned on failure. **/ CONST MACH_NLIST_64 * -MachoGetCxxSymbolByRelocation64 ( +MachoGetCxxSymbolByExternRelocation64 ( IN OUT VOID *Context, IN CONST MACH_RELOCATION_INFO *Relocation ) @@ -402,14 +402,11 @@ MachoGetCxxSymbolByRelocation64 ( OC_MACHO_CONTEXT *MachoContext; CONST MACH_NLIST_64 *SymbolTable; CONST CHAR8 *StringTable; - CONST MACH_SECTION_64 *Section; - UINT64 Value; - UINTN Index; CONST MACH_NLIST_64 *Symbol; - CONST CHAR8 *Name; ASSERT (Context != NULL); ASSERT (Relocation != NULL); + ASSERT (Relocation->Extern != 0); MachoContext = (OC_MACHO_CONTEXT *)Context; @@ -427,35 +424,9 @@ MachoGetCxxSymbolByRelocation64 ( // ASSERT (((UINT32)Relocation->Address & MACH_RELOC_SCATTERED) == 0); - if (Relocation->Extern != 0) { - Symbol = &SymbolTable[Relocation->SymbolNumber]; - if (InternalSymbolIsSane (MachoContext, Symbol)) { - return Symbol; - } - - return NULL; - } - - Section = MachoGetSectionByIndex64 (Context, Relocation->SymbolNumber); - if (Section == NULL) { - return NULL; - } - - Value = *(CONST UINT64 *)( - (UINTN)((CONST OC_MACHO_CONTEXT *)Context)->MachHeader - + (Section->Address + Relocation->Address) - ); - for (Index = 0; Index < MachoContext->NumSymbols; ++Index) { - Symbol = &SymbolTable[Index]; - Name = (StringTable + Symbol->UnifiedName.StringIndex); - - if ((Symbol->Value == Value) && MachoIsSymbolNameCxx (Name)) { - if (InternalSymbolIsSane (MachoContext, Symbol)) { - return Symbol; - } - - return NULL; - } + Symbol = &SymbolTable[Relocation->SymbolNumber]; + if (InternalSymbolIsSane (MachoContext, Symbol)) { + return Symbol; } return NULL;