@@ -243,16 +243,17 @@ private static bool TryGetUuidFromMacHeader(nint headerPtr, out Guid guid)
243
243
if ( header ->magic != MacOSLibSystem . MH_MAGIC_64 ) throw new InvalidOperationException ( "Invalid magic header" ) ;
244
244
245
245
var nbCommands = header ->ncmds ;
246
- var commands = ( MacOSLibSystem . load_command * ) ( ( byte * ) header + sizeof ( MacOSLibSystem . mach_header_64 ) ) ;
247
- for ( uint i = 0 ; i < nbCommands ; i ++ )
246
+ ref var firstCommand = ref * ( MacOSLibSystem . load_command * ) ( ( byte * ) header + sizeof ( MacOSLibSystem . mach_header_64 ) ) ;
247
+ ref var command = ref firstCommand ;
248
+ for ( uint i = 0 ; i < nbCommands ; i ++ )
248
249
{
249
- var command = commands [ i ] ;
250
250
if ( command . cmd == MacOSLibSystem . LC_UUID )
251
251
{
252
- var uuidCommand = ( MacOSLibSystem . uuid_command * ) Unsafe . AsPointer ( ref command ) ;
253
- guid = uuidCommand -> uuid ;
252
+ ref var uuidCommand = ref Unsafe . As < MacOSLibSystem . load_command , MacOSLibSystem . uuid_command > ( ref command ) ;
253
+ guid = uuidCommand . uuid ;
254
254
return true ;
255
255
}
256
+ command = ref Unsafe . AddByteOffset ( ref command , command . cmdsize ) ;
256
257
}
257
258
258
259
return false ;
@@ -267,10 +268,10 @@ private static ulong GetDyldCodeSize(nint headerPtr)
267
268
if ( header ->magic != MacOSLibSystem . MH_MAGIC_64 ) throw new InvalidOperationException ( "Invalid magic header" ) ;
268
269
269
270
var nbCommands = header ->ncmds ;
270
- var commands = ( MacOSLibSystem . load_command * ) ( ( byte * ) header + sizeof ( MacOSLibSystem . mach_header_64 ) ) ;
271
- for ( uint i = 0 ; i < nbCommands ; i ++ )
271
+ ref var firstCommand = ref * ( MacOSLibSystem . load_command * ) ( ( byte * ) header + sizeof ( MacOSLibSystem . mach_header_64 ) ) ;
272
+ ref var command = ref firstCommand ;
273
+ for ( uint i = 0 ; i < nbCommands ; i ++ )
272
274
{
273
- ref var command = ref commands [ i ] ;
274
275
if ( command . cmd == MacOSLibSystem . LC_SEGMENT_64 )
275
276
{
276
277
ref var segment = ref Unsafe . As < MacOSLibSystem . load_command , MacOSLibSystem . segment_command_64 > ( ref command ) ;
@@ -279,13 +280,14 @@ private static ulong GetDyldCodeSize(nint headerPtr)
279
280
startAddress = segment . vmaddr ;
280
281
}
281
282
}
283
+ command = ref Unsafe . AddByteOffset ( ref command , command . cmdsize ) ;
282
284
}
283
285
284
286
if ( startAddress == ulong . MaxValue ) return 0 ;
285
-
287
+
288
+ command = ref firstCommand ;
286
289
for ( uint i = 0 ; i < nbCommands ; i ++ )
287
290
{
288
- ref var command = ref commands [ i ] ;
289
291
if ( command . cmd == MacOSLibSystem . LC_SEGMENT_64 )
290
292
{
291
293
ref var segment = ref Unsafe . As < MacOSLibSystem . load_command , MacOSLibSystem . segment_command_64 > ( ref command ) ;
@@ -296,6 +298,7 @@ private static ulong GetDyldCodeSize(nint headerPtr)
296
298
size = newSize ;
297
299
}
298
300
}
301
+ command = ref Unsafe . AddByteOffset ( ref command , command . cmdsize ) ;
299
302
}
300
303
301
304
return size ;
0 commit comments