diff --git a/Cpp2IL.Core/Utils/MiscUtils.cs b/Cpp2IL.Core/Utils/MiscUtils.cs index 415191e8..fd2fc7a3 100644 --- a/Cpp2IL.Core/Utils/MiscUtils.cs +++ b/Cpp2IL.Core/Utils/MiscUtils.cs @@ -222,6 +222,9 @@ public static ulong GetAddressOfNextFunctionStart(ulong current) if (ret <= current && upper == _allKnownFunctionStarts.Count - 1) return 0; + if (!LibCpp2IlMain.Binary!.TryMapVirtualAddressToRaw(ret, out _)) + return 0; + return ret; } diff --git a/LibCpp2IL/MachO/MachOFile.cs b/LibCpp2IL/MachO/MachOFile.cs index e2cdd721..f4c3034e 100644 --- a/LibCpp2IL/MachO/MachOFile.cs +++ b/LibCpp2IL/MachO/MachOFile.cs @@ -76,8 +76,23 @@ public MachOFile(MemoryStream input) : base(input) var dyldData = _loadCommands.FirstOrDefault(c => c.Command is LoadCommandId.LC_DYLD_INFO or LoadCommandId.LC_DYLD_INFO_ONLY)?.CommandData as MachODynamicLinkerCommand; var exports = dyldData?.Exports ?? Array.Empty(); + // DEBUG + // var debugDict = new Dictionary(); + // for (int index = 0; index < exports.Length; ++index) { + // var export = exports[index]; + // Console.WriteLine($"Export: {export.Name[1..]} -> 0x{export.Address:X}"); + // // detect duplicate + // if (debugDict.ContainsKey(export.Address) && debugDict[export.Address] != export.Name[1..]) { + // Console.WriteLine($"Duplicate: {export.Name[1..]} -> 0x{export.Address:X}"); + // } + // debugDict[export.Address] = export.Name[1..]; + // } _exportAddressesDict = exports.ToDictionary(e => e.Name[1..], e => e.Address); //Skip the first character, which is a leading underscore inserted by the compiler - _exportNamesDict = _exportAddressesDict.ToDictionary(kvp => kvp.Value, kvp => kvp.Key); + _exportNamesDict = new Dictionary(); + foreach (var export in exports) // there may be duplicate names + { + _exportNamesDict[export.Address] = export.Name[1..]; + } LibLogger.VerboseNewline($"Found {_exportAddressesDict.Count} exports in the DYLD info load command.");