diff --git a/src/Ultra.Core/Parser/UltraEventPipeProcessor.cs b/src/Ultra.Core/Parser/UltraEventPipeProcessor.cs index 1582344..3303a23 100644 --- a/src/Ultra.Core/Parser/UltraEventPipeProcessor.cs +++ b/src/Ultra.Core/Parser/UltraEventPipeProcessor.cs @@ -97,7 +97,7 @@ private void SamplerParserOnEventNativeModule(UltraNativeModuleTraceEvent evt) { if (evt.ModulePath is not null) { - Console.WriteLine($"Module {evt.NativeModuleEventKind} Path: {evt.ModulePath}, LoadAddress: 0x{evt.LoadAddress:X}, Size: 0x{evt.Size:X}, Timestamp: {evt.TimestampUtc}"); + Console.WriteLine($"Module {evt.NativeModuleEventKind} Path: {evt.ModulePath}, LoadAddress: 0x{evt.LoadAddress:X}, Size: 0x{evt.Size:X}, Timestamp: {evt.TimestampUtc}, Uuid: {evt.Uuid}"); if (evt.NativeModuleEventKind == UltraSamplerNativeModuleEventKind.Unloaded) { diff --git a/src/Ultra.Sampler/MacOS/MacOSUltraSampler.cs b/src/Ultra.Sampler/MacOS/MacOSUltraSampler.cs index ce33114..6a5dd20 100644 --- a/src/Ultra.Sampler/MacOS/MacOSUltraSampler.cs +++ b/src/Ultra.Sampler/MacOS/MacOSUltraSampler.cs @@ -243,16 +243,17 @@ private static bool TryGetUuidFromMacHeader(nint headerPtr, out Guid guid) if (header->magic != MacOSLibSystem.MH_MAGIC_64) throw new InvalidOperationException("Invalid magic header"); var nbCommands = header->ncmds; - var commands = (MacOSLibSystem.load_command*)((byte*)header + sizeof(MacOSLibSystem.mach_header_64)); - for(uint i = 0; i < nbCommands; i++) + ref var firstCommand = ref *(MacOSLibSystem.load_command*)((byte*)header + sizeof(MacOSLibSystem.mach_header_64)); + ref var command = ref firstCommand; + for (uint i = 0; i < nbCommands; i++) { - var command = commands[i]; if (command.cmd == MacOSLibSystem.LC_UUID) { - var uuidCommand = (MacOSLibSystem.uuid_command*)Unsafe.AsPointer(ref command); - guid = uuidCommand->uuid; + ref var uuidCommand = ref Unsafe.As(ref command); + guid = uuidCommand.uuid; return true; } + command = ref Unsafe.AddByteOffset(ref command, command.cmdsize); } return false; @@ -267,10 +268,10 @@ private static ulong GetDyldCodeSize(nint headerPtr) if (header->magic != MacOSLibSystem.MH_MAGIC_64) throw new InvalidOperationException("Invalid magic header"); var nbCommands = header->ncmds; - var commands = (MacOSLibSystem.load_command*)((byte*)header + sizeof(MacOSLibSystem.mach_header_64)); - for(uint i = 0; i < nbCommands; i++) + ref var firstCommand = ref *(MacOSLibSystem.load_command*)((byte*)header + sizeof(MacOSLibSystem.mach_header_64)); + ref var command = ref firstCommand; + for (uint i = 0; i < nbCommands; i++) { - ref var command = ref commands[i]; if (command.cmd == MacOSLibSystem.LC_SEGMENT_64) { ref var segment = ref Unsafe.As(ref command); @@ -279,13 +280,14 @@ private static ulong GetDyldCodeSize(nint headerPtr) startAddress = segment.vmaddr; } } + command = ref Unsafe.AddByteOffset(ref command, command.cmdsize); } if (startAddress == ulong.MaxValue) return 0; - + + command = ref firstCommand; for (uint i = 0; i < nbCommands; i++) { - ref var command = ref commands[i]; if (command.cmd == MacOSLibSystem.LC_SEGMENT_64) { ref var segment = ref Unsafe.As(ref command); @@ -296,6 +298,7 @@ private static ulong GetDyldCodeSize(nint headerPtr) size = newSize; } } + command = ref Unsafe.AddByteOffset(ref command, command.cmdsize); } return size;