Skip to content

Commit ecfc947

Browse files
committed
Improve and migrate to fmt logging functions in Mach-O/KernelCache/SharedCache
1 parent 0d03149 commit ecfc947

16 files changed

+112
-114
lines changed

view/kernelcache/core/KernelCache.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ void KernelCache::ProcessRelocations(Ref<BinaryView> view, linkedit_data_command
131131
fixupsHeader.imports_format = parentReader.Read32();
132132
fixupsHeader.symbols_format = parentReader.Read32();
133133

134-
LogDebugF("Chained Fixups: Header @ 0x{:x}// Fixups version 0x{:x}", fixupHeaderAddress, fixupsHeader.fixups_version);
134+
LogDebugF("Chained Fixups: Header @ {:#x} // Fixups version {:#x}", fixupHeaderAddress, fixupsHeader.fixups_version);
135135

136136
if (fixupsHeader.fixups_version > 0)
137137
{

view/kernelcache/core/KernelCacheController.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ void DeleteController(const FileMetadata& file)
3333
// Someone is still holding the controller, lets warn about this.
3434
// 2 is expected here because we have one held in `controllers` and one held by `controller`.
3535
if (controller->m_refs > 2)
36-
LogWarn("Deleting KernelCacheController for view %llx, but there are still %d references", id,
36+
LogWarnF("Deleting KernelCacheController for view {:#x}, but there are still {} references", id,
3737
controller->m_refs.load());
3838

3939
controllers.erase(it);
40-
LogDebug("Deleted KernelCacheController for view %s", file.GetFilename().c_str());
40+
LogDebugF("Deleted KernelCacheController for view {:?}", file.GetFilename());
4141
}
4242
}
4343

view/kernelcache/core/KernelCacheView.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Ref<Settings> KernelCacheViewType::GetLoadSettingsForData(BinaryView* data)
114114
Ref<BinaryView> viewRef = Parse(data);
115115
if (!viewRef || !viewRef->Init())
116116
{
117-
LogWarn("Failed to initialize view of type '%s'. Generating default load settings.", GetName().c_str());
117+
LogWarnF("Failed to initialize view of type {:?}. Generating default load settings.", GetName());
118118
viewRef = data;
119119
}
120120

@@ -882,7 +882,7 @@ bool KernelCacheView::Init()
882882
}
883883
catch (ReadException&)
884884
{
885-
LogError("Error when applying Mach-O header types at %" PRIx64, textSegOffset);
885+
LogErrorF("Error when applying Mach-O header types at {:#x}", textSegOffset);
886886
}
887887

888888
return InitController();
@@ -943,7 +943,7 @@ bool KernelCacheView::InitController()
943943
kernelCache.ProcessSymbols();
944944
auto endTime = std::chrono::high_resolution_clock::now();
945945
std::chrono::duration<double> elapsed = endTime - startTime;
946-
logger->LogInfo("Processing %zu symbols took %.3f seconds (separate thread)", kernelCache.GetSymbols().size(), elapsed.count());
946+
logger->LogInfoF("Processing {} symbols took {:.3f} seconds (separate thread)", kernelCache.GetSymbols().size(), elapsed.count());
947947
});
948948
}
949949

@@ -952,7 +952,7 @@ bool KernelCacheView::InitController()
952952
std::string autoLoadPattern = ".*libsystem_c.dylib";
953953
if (settings && settings->Contains("loader.kc.autoLoadPattern"))
954954
autoLoadPattern = settings->Get<std::string>("loader.kc.autoLoadPattern", this);
955-
m_logger->LogDebug("Loading images using pattern: %s", autoLoadPattern.c_str());
955+
m_logger->LogDebugF("Loading images using pattern: {:?}", autoLoadPattern);
956956

957957
{
958958
// TODO: Refusing to add undo action "Added section libsystem_c.dylib::__macho_header", there is literally
@@ -969,7 +969,7 @@ bool KernelCacheView::InitController()
969969
++loadedImages;
970970
auto endTime = std::chrono::high_resolution_clock::now();
971971
std::chrono::duration<double> elapsed = endTime - startTime;
972-
m_logger->LogInfo("Automatically loading %zu images took %.3f seconds", loadedImages, elapsed.count());
972+
m_logger->LogInfoF("Automatically loading {} images took {:.3f} seconds", loadedImages, elapsed.count());
973973
}
974974

975975
if (auto loadedImageMetadata = GetParentView()->QueryMetadata("KernelCacheLoadedImages"))

view/kernelcache/core/MachO.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ std::optional<KernelCacheMachOHeader> KernelCacheMachOHeader::ParseHeaderForAddr
7676
{
7777
for (size_t i = 0; i < header.ident.ncmds; i++)
7878
{
79-
// BNLogInfo("of 0x%llx", reader.GetOffset());
79+
// BNLogInfoF("of {:#x}", reader.GetOffset());
8080
load_command load;
8181
segment_command_64 segment64;
8282
section_64 sect = {};
@@ -367,7 +367,7 @@ std::optional<KernelCacheMachOHeader> KernelCacheMachOHeader::ParseHeaderForAddr
367367
(void)reader.Read(&thread.stateppc64.r1, sizeof(thread.stateppc64) - (3 * 8));
368368
break;
369369
default:
370-
m_logger->LogError("Unknown archid: %x", m_archId);
370+
m_logger->LogErrorF("Unknown archid: {:#x}", m_archId);
371371
}
372372
373373
}*/
@@ -390,16 +390,16 @@ std::optional<KernelCacheMachOHeader> KernelCacheMachOHeader::ParseHeaderForAddr
390390
header.buildVersion.minos = reader.Read32();
391391
header.buildVersion.sdk = reader.Read32();
392392
header.buildVersion.ntools = reader.Read32();
393-
// m_logger->LogDebug("Platform: %s", BuildPlatformToString(header.buildVersion.platform).c_str());
394-
// m_logger->LogDebug("MinOS: %s", BuildToolVersionToString(header.buildVersion.minos).c_str());
395-
// m_logger->LogDebug("SDK: %s", BuildToolVersionToString(header.buildVersion.sdk).c_str());
393+
// m_logger->LogDebugF("Platform: {}", BuildPlatformToString(header.buildVersion.platform));
394+
// m_logger->LogDebugF("MinOS: {}", BuildToolVersionToString(header.buildVersion.minos));
395+
// m_logger->LogDebugF("SDK: {}", BuildToolVersionToString(header.buildVersion.sdk));
396396
for (uint32_t j = 0; (i < header.buildVersion.ntools) && (j < 10); j++)
397397
{
398398
uint32_t tool = reader.Read32();
399399
uint32_t version = reader.Read32();
400400
header.buildToolVersions.push_back({tool, version});
401-
// m_logger->LogDebug("Build Tool: %s: %s", BuildToolToString(tool).c_str(),
402-
// BuildToolVersionToString(version).c_str());
401+
// m_logger->LogDebugF("Build Tool: {}: {}", BuildToolToString(tool),
402+
// BuildToolVersionToString(version));
403403
}
404404
break;
405405
}
@@ -506,7 +506,7 @@ std::vector<CacheSymbol> KernelCacheMachOHeader::ReadSymbolTable(Ref<BinaryView>
506506
if (!symbolType.has_value())
507507
{
508508
// TODO: Where logger?
509-
LogError("Symbol %s at address %llx has unknown symbol type", symbolName.c_str(), symbolAddress);
509+
LogErrorF("Symbol {:?} at address {:#x} has unknown symbol type", symbolName, symbolAddress);
510510
continue;
511511
}
512512

@@ -526,7 +526,7 @@ std::vector<CacheSymbol> KernelCacheMachOHeader::ReadSymbolTable(Ref<BinaryView>
526526
if (!flags.has_value())
527527
{
528528
// TODO: where logger?
529-
LogError("Symbol %s at address %llx is not in any section", symbolName.c_str(), symbolAddress);
529+
LogErrorF("Symbol {} at address {:#x} is not in any section", symbolName, symbolAddress);
530530
continue;
531531
}
532532

@@ -549,7 +549,7 @@ std::vector<CacheSymbol> KernelCacheMachOHeader::ReadSymbolTable(Ref<BinaryView>
549549
return symbolList;
550550
}
551551
catch (ReadException& ex) {
552-
LogError("Failed to read symbol table: %s", ex.what());
552+
LogErrorF("Failed to read symbol table: {}", ex.what());
553553
return {};
554554
}
555555

@@ -600,7 +600,7 @@ bool KernelCacheMachOHeader::AddExportTerminalSymbol(
600600
symbols.emplace_back(DataSymbol, symbolAddress, symbolName);
601601
break;
602602
default:
603-
LogWarn("Unhandled export symbol kind: %llx", symbolFlags & EXPORT_SYMBOL_FLAGS_KIND_MASK);
603+
LogWarnF("Unhandled export symbol kind: {:#x}", symbolFlags & EXPORT_SYMBOL_FLAGS_KIND_MASK);
604604
return false;
605605
}
606606

view/kernelcache/core/MachOProcessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,6 @@ void KernelCacheMachOProcessor::ApplyHeaderDataVariables(KernelCacheMachOHeader&
327327
}
328328
catch (ReadException&)
329329
{
330-
m_logger->LogError("Error when applying Mach-O header types at %llx", header.textBase);
330+
m_logger->LogErrorF("Error when applying Mach-O header types at {:#x}", header.textBase);
331331
}
332332
}

view/kernelcache/core/Utility.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void ApplySymbol(Ref<BinaryView> view, Ref<TypeLibrary> typeLib, Ref<Symbol> sym
126126
}
127127
else
128128
{
129-
LogWarn("Failed to find id type for %llx, objective-c processor not ran?", func->GetStart());
129+
LogWarnF("Failed to find id type for {:#x}, objective-c processor not ran?", func->GetStart());
130130
}
131131
}
132132
}

0 commit comments

Comments
 (0)