@@ -1856,9 +1856,11 @@ bool MachoView::InitializeHeader(MachOHeader& header, bool isMainHeader, uint64_
1856
1856
parseObjCStructs = false ;
1857
1857
if (!GetSectionByName (" __cfstring" ))
1858
1858
parseCFStrings = false ;
1859
+
1860
+ std::unique_ptr<MachoObjCProcessor> objcProcessor;
1859
1861
if (parseObjCStructs || parseCFStrings)
1860
1862
{
1861
- m_objcProcessor = new MachoObjCProcessor (this );
1863
+ objcProcessor = std::make_unique< MachoObjCProcessor> (this );
1862
1864
}
1863
1865
if (parseObjCStructs)
1864
1866
{
@@ -2067,7 +2069,7 @@ bool MachoView::InitializeHeader(MachOHeader& header, bool isMainHeader, uint64_
2067
2069
{
2068
2070
// Add functions for all function symbols
2069
2071
m_logger->LogDebug (" Parsing symbol table\n " );
2070
- ParseSymbolTable (reader, header, header.symtab , indirectSymbols);
2072
+ ParseSymbolTable (reader, header, header.symtab , indirectSymbols, objcProcessor. get () );
2071
2073
}
2072
2074
catch (std::exception&)
2073
2075
{
@@ -2088,8 +2090,8 @@ bool MachoView::InitializeHeader(MachOHeader& header, bool isMainHeader, uint64_
2088
2090
uint64_t slidTarget = target + m_imageBaseAdjustment;
2089
2091
relocation.address = slidTarget;
2090
2092
DefineRelocation (m_arch, relocation, slidTarget, relocationLocation);
2091
- if (m_objcProcessor )
2092
- m_objcProcessor ->AddRelocatedPointer (relocationLocation, slidTarget);
2093
+ if (objcProcessor )
2094
+ objcProcessor ->AddRelocatedPointer (relocationLocation, slidTarget);
2093
2095
}
2094
2096
for (auto & [relocation, name] : header.externalRelocations )
2095
2097
{
@@ -2369,7 +2371,7 @@ bool MachoView::InitializeHeader(MachOHeader& header, bool isMainHeader, uint64_
2369
2371
if (parseCFStrings)
2370
2372
{
2371
2373
try {
2372
- m_objcProcessor ->ProcessObjCLiterals ();
2374
+ objcProcessor ->ProcessObjCLiterals ();
2373
2375
}
2374
2376
catch (std::exception& ex)
2375
2377
{
@@ -2381,14 +2383,13 @@ bool MachoView::InitializeHeader(MachOHeader& header, bool isMainHeader, uint64_
2381
2383
if (parseObjCStructs)
2382
2384
{
2383
2385
try {
2384
- m_objcProcessor ->ProcessObjCData ();
2386
+ objcProcessor ->ProcessObjCData ();
2385
2387
}
2386
2388
catch (std::exception& ex)
2387
2389
{
2388
2390
m_logger->LogError (" Failed to process Objective-C Metadata. Binary may be malformed" );
2389
2391
m_logger->LogError (" Error: %s" , ex.what ());
2390
2392
}
2391
- delete m_objcProcessor;
2392
2393
}
2393
2394
2394
2395
@@ -2976,7 +2977,8 @@ void MachoView::ParseDynamicTable(BinaryReader& reader, MachOHeader& header, BNS
2976
2977
}
2977
2978
2978
2979
2979
- void MachoView::ParseSymbolTable (BinaryReader& reader, MachOHeader& header, const symtab_command& symtab, const vector<uint32_t >& indirectSymbols)
2980
+ void MachoView::ParseSymbolTable (BinaryReader& reader, MachOHeader& header, const symtab_command& symtab,
2981
+ const vector<uint32_t >& indirectSymbols, MachoObjCProcessor* objcProcessor)
2980
2982
{
2981
2983
if (header.ident .filetype == MH_DSYM)
2982
2984
{
@@ -3004,12 +3006,12 @@ void MachoView::ParseSymbolTable(BinaryReader& reader, MachOHeader& header, cons
3004
3006
if (header.chainedFixupsPresent )
3005
3007
{
3006
3008
m_logger->LogDebug (" Chained Fixups" );
3007
- ParseChainedFixups (header, header.chainedFixups );
3009
+ ParseChainedFixups (header, header.chainedFixups , objcProcessor );
3008
3010
}
3009
3011
else if (header.chainStartsPresent )
3010
3012
{
3011
3013
m_logger->LogDebug (" Chained Starts" );
3012
- ParseChainedStarts (header, header.chainStarts );
3014
+ ParseChainedStarts (header, header.chainStarts , objcProcessor );
3013
3015
}
3014
3016
if (header.exportTriePresent && header.isMainHeader )
3015
3017
ParseExportTrie (reader, header.exportTrie );
@@ -3197,7 +3199,8 @@ void MachoView::ParseSymbolTable(BinaryReader& reader, MachOHeader& header, cons
3197
3199
}
3198
3200
3199
3201
3200
- void MachoView::ParseChainedFixups (MachOHeader& header, linkedit_data_command chainedFixups)
3202
+ void MachoView::ParseChainedFixups (
3203
+ MachOHeader& header, linkedit_data_command chainedFixups, MachoObjCProcessor* objcProcessor)
3201
3204
{
3202
3205
if (!chainedFixups.dataoff )
3203
3206
return ;
@@ -3596,9 +3599,9 @@ void MachoView::ParseChainedFixups(MachOHeader& header, linkedit_data_command ch
3596
3599
reloc.address = GetStart () + (chainEntryAddress - m_universalImageOffset);
3597
3600
DefineRelocation (m_arch, reloc, entryOffset, reloc.address );
3598
3601
3599
- if (m_objcProcessor )
3602
+ if (objcProcessor )
3600
3603
{
3601
- m_objcProcessor ->AddRelocatedPointer (reloc.address , entryOffset);
3604
+ objcProcessor ->AddRelocatedPointer (reloc.address , entryOffset);
3602
3605
}
3603
3606
}
3604
3607
@@ -3627,7 +3630,7 @@ void MachoView::ParseChainedFixups(MachOHeader& header, linkedit_data_command ch
3627
3630
}
3628
3631
3629
3632
3630
- void MachoView::ParseChainedStarts (MachOHeader& header, section_64 chainedStarts)
3633
+ void MachoView::ParseChainedStarts (MachOHeader& header, section_64 chainedStarts, MachoObjCProcessor* objcProcessor )
3631
3634
{
3632
3635
if (!chainedStarts.offset )
3633
3636
return ;
@@ -3799,9 +3802,9 @@ void MachoView::ParseChainedStarts(MachOHeader& header, section_64 chainedStarts
3799
3802
DefineRelocation (m_arch, reloc, entryOffset, reloc.address );
3800
3803
m_logger->LogDebug (" Chained Starts: Adding relocated pointer %llx -> %llx" , reloc.address , entryOffset);
3801
3804
3802
- if (m_objcProcessor )
3805
+ if (objcProcessor )
3803
3806
{
3804
- m_objcProcessor ->AddRelocatedPointer (reloc.address , entryOffset);
3807
+ objcProcessor ->AddRelocatedPointer (reloc.address , entryOffset);
3805
3808
}
3806
3809
}
3807
3810
0 commit comments