Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix iOS file loading and account for if the next function is not mappable to a raw address in the binary #316

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cpp2IL.Core/Utils/MiscUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
17 changes: 16 additions & 1 deletion LibCpp2IL/MachO/MachOFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MachOExportEntry>();
// DEBUG
// var debugDict = new Dictionary<long, string>();
// 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<long, string>();
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.");

Expand Down
Loading