diff options
| author | kat <kat@vector35.com> | 2025-07-28 08:49:18 -0400 |
|---|---|---|
| committer | kat <kat@vector35.com> | 2025-07-28 08:52:47 -0400 |
| commit | ecfc947a39aa8be76b5f378c77b845622bca8b5f (patch) | |
| tree | 8dd9cd7d76df935bd7799c87c4748ec1adcbde2c /view/sharedcache | |
| parent | 0d031494987b6e1f36ebaaf3b0b92c278cd8ca6b (diff) | |
Improve and migrate to fmt logging functions in Mach-O/KernelCache/SharedCache
Diffstat (limited to 'view/sharedcache')
| -rw-r--r-- | view/sharedcache/core/MachO.cpp | 12 | ||||
| -rw-r--r-- | view/sharedcache/core/MachOProcessor.cpp | 2 | ||||
| -rw-r--r-- | view/sharedcache/core/MappedFile.cpp | 2 | ||||
| -rw-r--r-- | view/sharedcache/core/SharedCache.cpp | 2 | ||||
| -rw-r--r-- | view/sharedcache/core/SharedCacheController.cpp | 10 | ||||
| -rw-r--r-- | view/sharedcache/core/SharedCacheView.cpp | 28 | ||||
| -rw-r--r-- | view/sharedcache/core/SlideInfo.cpp | 16 | ||||
| -rw-r--r-- | view/sharedcache/core/Utility.cpp | 2 | ||||
| -rw-r--r-- | view/sharedcache/core/VirtualMemory.cpp | 2 |
9 files changed, 38 insertions, 38 deletions
diff --git a/view/sharedcache/core/MachO.cpp b/view/sharedcache/core/MachO.cpp index 969591a0..1c1224db 100644 --- a/view/sharedcache/core/MachO.cpp +++ b/view/sharedcache/core/MachO.cpp @@ -489,9 +489,9 @@ std::vector<CacheSymbol> SharedCacheMachOHeader::ReadSymbolTable(VirtualMemory& if (nlist.n_strx >= stringInfo.entries) { // TODO: where logger? - LogError( - "Symbol entry at index %llu has a string offset of %u which is outside the strings buffer of size %llu " - "for symbol table %x", + LogErrorF( + "Symbol entry at index {} has a string offset of {:#x} which is outside the strings buffer of size {:#x} " + "for symbol table {:#x}", entryIndex, nlist.n_strx, stringInfo.address, stringInfo.entries); continue; } @@ -511,7 +511,7 @@ std::vector<CacheSymbol> SharedCacheMachOHeader::ReadSymbolTable(VirtualMemory& if (!symbolType.has_value()) { // TODO: Where logger? - LogError("Symbol %s at address %llx has unknown symbol type", symbolName.c_str(), symbolAddress); + LogErrorF("Symbol {:?} at address {:#x} has unknown symbol type", symbolName.c_str(), symbolAddress); continue; } @@ -531,7 +531,7 @@ std::vector<CacheSymbol> SharedCacheMachOHeader::ReadSymbolTable(VirtualMemory& if (!flags.has_value()) { // TODO: where logger? - LogError("Symbol %s at address %llx is not in any section", symbolName.c_str(), symbolAddress); + LogErrorF("Symbol {:?} at address {:#x} is not in any section", symbolName.c_str(), symbolAddress); continue; } @@ -599,7 +599,7 @@ bool SharedCacheMachOHeader::AddExportTerminalSymbol( symbols.emplace_back(DataSymbol, symbolAddress, symbolName); break; default: - LogWarn("Unhandled export symbol kind: %llx", symbolFlags & EXPORT_SYMBOL_FLAGS_KIND_MASK); + LogWarnF("Unhandled export symbol kind: {:#x}", symbolFlags & EXPORT_SYMBOL_FLAGS_KIND_MASK); return false; } diff --git a/view/sharedcache/core/MachOProcessor.cpp b/view/sharedcache/core/MachOProcessor.cpp index c6e2c288..df2fcfde 100644 --- a/view/sharedcache/core/MachOProcessor.cpp +++ b/view/sharedcache/core/MachOProcessor.cpp @@ -377,6 +377,6 @@ void SharedCacheMachOProcessor::ApplyHeaderDataVariables(SharedCacheMachOHeader& } catch (ReadException&) { - m_logger->LogError("Error when applying Mach-O header types at %llx", header.textBase); + m_logger->LogErrorF("Error when applying Mach-O header types at {:#x}", header.textBase); } } diff --git a/view/sharedcache/core/MappedFile.cpp b/view/sharedcache/core/MappedFile.cpp index e0b805bc..21bda4f8 100644 --- a/view/sharedcache/core/MappedFile.cpp +++ b/view/sharedcache/core/MappedFile.cpp @@ -89,7 +89,7 @@ MapStatus MappedFile::Map() void* result = mmap(nullptr, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fileno(fd), 0u); if (result == MAP_FAILED) { - BinaryNinja::LogError("mmap failed: %s", strerror(errno)); // Use errno to log the reason + BinaryNinja::LogErrorF("mmap failed: {}", strerror(errno)); // Use errno to log the reason return MapStatus::Error; } _mmap = static_cast<uint8_t*>(result); diff --git a/view/sharedcache/core/SharedCache.cpp b/view/sharedcache/core/SharedCache.cpp index c36c9ede..0a14cfaf 100644 --- a/view/sharedcache/core/SharedCache.cpp +++ b/view/sharedcache/core/SharedCache.cpp @@ -444,7 +444,7 @@ void SharedCache::ProcessEntrySlideInfo(const CacheEntry& entry) const } } - LogWarn("Failed to register revive callback for slide mapping %llx in entry '%s'", mapping.address, entry.GetFileName().c_str()); + LogWarnF("Failed to register revive callback for slide mapping {:#x} in entry {:?}", mapping.address, entry.GetFileName().c_str()); } } diff --git a/view/sharedcache/core/SharedCacheController.cpp b/view/sharedcache/core/SharedCacheController.cpp index a9e0937c..ce3fde2c 100644 --- a/view/sharedcache/core/SharedCacheController.cpp +++ b/view/sharedcache/core/SharedCacheController.cpp @@ -35,7 +35,7 @@ void DeleteController(const FileMetadata& file) // Someone is still holding the controller, lets warn about this. // 2 is expected here because we have one held in `controllers` and one held by `controller`. if (controller->m_refs > 2) - LogWarn("Deleting SharedCacheController for view %llx, but there are still %d references", id, + LogWarnF("Deleting SharedCacheController for view {:#x}, but there are still {} references", id, controller->m_refs.load()); // Go through the file accessor cache and remove the entries we reference. @@ -47,7 +47,7 @@ void DeleteController(const FileMetadata& file) } controllers.erase(it); - LogDebug("Deleted SharedCacheController for view %s", file.GetFilename().c_str()); + LogDebugF("Deleted SharedCacheController for view {:?}", file.GetFilename().c_str()); } } @@ -135,7 +135,7 @@ bool SharedCacheController::ApplyRegion(BinaryView& view, const CacheRegion& reg // Skip filtered regions, this defaults to just LINKEDIT regions. if (std::regex_match(region.name, m_regionFilter)) { - m_logger->LogDebug("Skipping filtered region at %llx", region.start); + m_logger->LogDebugF("Skipping filtered region at {:#x}", region.start); return false; } @@ -148,7 +148,7 @@ bool SharedCacheController::ApplyRegion(BinaryView& view, const CacheRegion& reg catch (std::exception& e) { // This happens if we have not mapped in all the relevant entries. - m_logger->LogError("Failed to read region: %s", e.what()); + m_logger->LogErrorF("Failed to read region: {}", e.what()); return false; } @@ -239,7 +239,7 @@ bool SharedCacheController::ApplyImage(BinaryView& view, const CacheImage& image { // Let the user know there was an error in processing the objc stuff but let the image load // regardless, as its non-critical. - m_logger->LogError("Failed to process ObjC information: %s", e.what()); + m_logger->LogErrorF("Failed to process ObjC information: {}", e.what()); } } diff --git a/view/sharedcache/core/SharedCacheView.cpp b/view/sharedcache/core/SharedCacheView.cpp index e9699ab1..8277f887 100644 --- a/view/sharedcache/core/SharedCacheView.cpp +++ b/view/sharedcache/core/SharedCacheView.cpp @@ -16,7 +16,7 @@ SharedCacheViewType::SharedCacheViewType() : BinaryViewType(VIEW_NAME, VIEW_NAME void SharedCacheViewType::Register() { auto fdLimit = AdjustFileDescriptorLimit(); - LogDebug("Shared Cache processing initialized with a max file descriptor limit of %lld", fdLimit); + LogDebugF("Shared Cache processing initialized with a max file descriptor limit of {}", fdLimit); // Adjust the global accessor cache to the fdlimit. FileAccessorCache::Global().SetCacheSize(fdLimit); @@ -37,7 +37,7 @@ Ref<Settings> SharedCacheViewType::GetLoadSettingsForData(BinaryView* data) Ref<BinaryView> viewRef = Parse(data); if (!viewRef || !viewRef->Init()) { - LogWarn("Failed to initialize view of type '%s'. Generating default load settings.", GetName().c_str()); + LogWarnF("Failed to initialize view of type '{}'. Generating default load settings.", GetName().c_str()); viewRef = data; } @@ -190,7 +190,7 @@ bool SharedCacheView::Init() } else { - m_logger->LogError("Unknown magic: %s", magic); + m_logger->LogErrorF("Unknown magic: {:?}", magic); return false; } @@ -224,10 +224,10 @@ bool SharedCacheView::Init() case DSCPlatformWatchOS: case DSCPlatformWatchOSSimulator: case DSCPlatformBridgeOS: - m_logger->LogError("Unsupported platform: %d", platform); + m_logger->LogErrorF("Unsupported platform: {}", platform); return false; default: - m_logger->LogWarn("Unknown platform: %d", platform); + m_logger->LogWarnF("Unknown platform: {}", platform); return false; } @@ -353,7 +353,7 @@ bool SharedCacheView::Init() if (!err.empty() || !headerType.type) { - m_logger->LogError("Failed to parse header type: %s", err.c_str()); + m_logger->LogErrorF("Failed to parse header type: {}", err); return false; } @@ -783,7 +783,7 @@ bool SharedCacheView::Init() GetParentView()->Read(&primaryBase, basePointer, 8); if (primaryBase == 0) { - m_logger->LogError("Failed to read primary base at 0x%llx", basePointer); + m_logger->LogErrorF("Failed to read primary base at {:#x}", basePointer); return false; } @@ -855,7 +855,7 @@ bool SharedCacheView::InitController() auto totalEntries = sharedCacheBuilder.GetCache().GetEntries().size(); auto endTime = std::chrono::high_resolution_clock::now(); std::chrono::duration<double> elapsed = endTime - startTime; - m_logger->LogInfo("Processing %zu entries took %.3f seconds", totalEntries, elapsed.count()); + m_logger->LogInfoF("Processing {} entries took {:.3f} seconds", totalEntries, elapsed.count()); // If we can't store all of our files for this cache in the accessor cache we might run into issues, warn the user. if (totalEntries > FileAccessorCache::Global().GetCacheSize()) @@ -900,7 +900,7 @@ bool SharedCacheView::InitController() sharedCache.ProcessEntrySlideInfo(entry); auto endTime = std::chrono::high_resolution_clock::now(); std::chrono::duration<double> elapsed = endTime - startTime; - m_logger->LogInfo("Processing slide info took %.3f seconds", elapsed.count()); + m_logger->LogInfoF("Processing slide info took {:.3f} seconds", elapsed.count()); } { @@ -913,7 +913,7 @@ bool SharedCacheView::InitController() auto endTime = std::chrono::high_resolution_clock::now(); std::chrono::duration<double> elapsed = endTime - startTime; const auto& images = sharedCache.GetImages(); - m_logger->LogInfo("Processing %zu images took %.3f seconds", images.size(), elapsed.count()); + m_logger->LogInfoF("Processing {} images took {:.3f} seconds", images.size(), elapsed.count()); // Warn if we found no images, and provide the likely explanation if (images.empty()) m_logger->LogWarn("Failed to process any images, likely missing cache files."); @@ -926,7 +926,7 @@ bool SharedCacheView::InitController() sharedCache.ProcessEntryRegions(entry); auto endTime = std::chrono::high_resolution_clock::now(); std::chrono::duration<double> elapsed = endTime - startTime; - m_logger->LogInfo("Processing %zu regions took %.3f seconds", sharedCache.GetRegions().size(), elapsed.count()); + m_logger->LogInfoF("Processing {} regions took {:.3f} seconds", sharedCache.GetRegions().size(), elapsed.count()); } // TODO: Here we should have all the regions and what not for the virtual memory populated, I think it might be a good idea @@ -944,7 +944,7 @@ bool SharedCacheView::InitController() sharedCache.ProcessSymbols(); auto endTime = std::chrono::high_resolution_clock::now(); std::chrono::duration<double> elapsed = endTime - startTime; - logger->LogInfo("Processing %zu symbols took %.3f seconds (separate thread)", sharedCache.GetSymbols().size(), elapsed.count()); + logger->LogInfoF("Processing {} symbols took {:.3f} seconds (separate thread)", sharedCache.GetSymbols().size(), elapsed.count()); }); } @@ -953,7 +953,7 @@ bool SharedCacheView::InitController() std::string autoLoadPattern = ".*libsystem_c.dylib"; if (settings && settings->Contains("loader.dsc.autoLoadPattern")) autoLoadPattern = settings->Get<std::string>("loader.dsc.autoLoadPattern", this); - m_logger->LogDebug("Loading images using pattern: %s", autoLoadPattern.c_str()); + m_logger->LogDebugF("Loading images using pattern: {:?}", autoLoadPattern); { // TODO: Refusing to add undo action "Added section libsystem_c.dylib::__macho_header", there is literally @@ -970,7 +970,7 @@ bool SharedCacheView::InitController() ++loadedImages; auto endTime = std::chrono::high_resolution_clock::now(); std::chrono::duration<double> elapsed = endTime - startTime; - m_logger->LogInfo("Automatically loading %zu images took %.3f seconds", loadedImages, elapsed.count()); + m_logger->LogInfoF("Automatically loading {} images took {:.3f} seconds", loadedImages, elapsed.count()); } return true; diff --git a/view/sharedcache/core/SlideInfo.cpp b/view/sharedcache/core/SlideInfo.cpp index cedb4ab8..d1352ff7 100644 --- a/view/sharedcache/core/SlideInfo.cpp +++ b/view/sharedcache/core/SlideInfo.cpp @@ -167,7 +167,7 @@ std::vector<SlideMappingInfo> SlideInfoProcessor::ReadEntryInfo(const MappedFile auto slideInfoVersion = accessor.ReadUInt32(slideInfoAddress); if (slideInfoVersion != 2 && slideInfoVersion != 3) { - m_logger->LogError("Unsupported slide info version %d", slideInfoVersion); + m_logger->LogErrorF("Unsupported slide info version {}", slideInfoVersion); return {}; } @@ -216,15 +216,15 @@ std::vector<SlideMappingInfo> SlideInfoProcessor::ReadEntryInfo(const MappedFile } else { - m_logger->LogError("Unknown slide info version: %d", map.slideInfoVersion); + m_logger->LogErrorF("Unknown slide info version: {}", map.slideInfoVersion); continue; } mappings.emplace_back(map); - m_logger->LogDebug("File: %s", entry.GetFilePath().c_str()); - m_logger->LogDebug("Slide Info Address: 0x%llx", map.address); - m_logger->LogDebug("Mapping Address: 0x%llx", map.mappingInfo.address); - m_logger->LogDebug("Slide Info Version: %d", map.slideInfoVersion); + m_logger->LogDebugF("File: {:?}", entry.GetFilePath().c_str()); + m_logger->LogDebugF("Slide Info Address: {:#x}", map.address); + m_logger->LogDebugF("Mapping Address: {:#x}", map.mappingInfo.address); + m_logger->LogDebugF("Slide Info Version: {}", map.slideInfoVersion); } return mappings; @@ -255,7 +255,7 @@ void SlideInfoProcessor::ApplyMappings(MappedFileAccessor& accessor, const std:: break; default: m_logger->LogError( - "Cannot apply slide info version: %d @ %llx", mapping.slideInfoVersion, mapping.mappingInfo.address); + "Cannot apply slide info version: {} @ {:#x}", mapping.slideInfoVersion, mapping.mappingInfo.address); break; } } @@ -273,7 +273,7 @@ std::vector<SlideMappingInfo> SlideInfoProcessor::ProcessEntry(MappedFileAccesso { // Just log an error, we technically can continue as if the slide info is not applied for a given entry it does // not necessarily mean we cannot do analysis on others. - m_logger->LogError("Error processing slide info for entry `%s`: %s", entry.GetFileName().c_str(), e.what()); + m_logger->LogErrorF("Error processing slide info for entry {:?}: {}", entry.GetFileName().c_str(), e.what()); return {}; } } diff --git a/view/sharedcache/core/Utility.cpp b/view/sharedcache/core/Utility.cpp index 6f8323bf..515d62c7 100644 --- a/view/sharedcache/core/Utility.cpp +++ b/view/sharedcache/core/Utility.cpp @@ -126,7 +126,7 @@ void ApplySymbol(Ref<BinaryView> view, Ref<TypeLibrary> typeLib, Ref<Symbol> sym } else { - LogWarn("Failed to find id type for %llx, objective-c processor not ran?", func->GetStart()); + LogWarnF("Failed to find id type for {:#x}, objective-c processor not ran?", func->GetStart()); } } } diff --git a/view/sharedcache/core/VirtualMemory.cpp b/view/sharedcache/core/VirtualMemory.cpp index dc52bf0f..475d0430 100644 --- a/view/sharedcache/core/VirtualMemory.cpp +++ b/view/sharedcache/core/VirtualMemory.cpp @@ -11,7 +11,7 @@ void VirtualMemory::MapRegion(WeakFileAccessor fileAccessor, AddressRange mapped if (existingRange.Overlaps(mappedRange)) { // Handle overlapping regions, e.g., throw an exception or skip the mapping - BinaryNinja::LogError("Overlapping memory region %llx", existingRange.start); + BinaryNinja::LogErrorF("Overlapping memory region {:#x}", existingRange.start); } } |
