Properly detect universal binaries when packing .app bundles (#179)

This commit is contained in:
Caelan
2024-07-17 12:53:20 +01:00
committed by GitHub
parent 1aea8dd1dc
commit c0a9476c22
2 changed files with 5 additions and 28 deletions

View File

@@ -7,7 +7,11 @@ public class BinDetect
MH_MAGIC = 0xfeedface, MH_MAGIC = 0xfeedface,
MH_CIGAM = 0xcefaedfe, MH_CIGAM = 0xcefaedfe,
MH_MAGIC_64 = 0xfeedfacf, MH_MAGIC_64 = 0xfeedfacf,
MH_CIGAM_64 = 0xcffaedfe MH_CIGAM_64 = 0xcffaedfe,
// https://developer.apple.com/documentation/kernel/fat_header/1558632-magic/
// https://opensource.apple.com/source/file/file-80.40.2/file/magic/Magdir/cafebabe.auto.html
FAT_MAGIC = 0xcafebabe,
FAT_CIGAM = 0xbebafeca,
} }
public static bool IsMachOImage(string filePath) public static bool IsMachOImage(string filePath)

View File

@@ -1,27 +0,0 @@
namespace Velopack.Packaging;
public class MachO
{
private enum MagicMachO : uint
{
MH_MAGIC = 0xfeedface,
MH_CIGAM = 0xcefaedfe,
MH_MAGIC_64 = 0xfeedfacf,
MH_CIGAM_64 = 0xcffaedfe,
// https://developer.apple.com/documentation/kernel/fat_header/1558632-magic/
// https://opensource.apple.com/source/file/file-80.40.2/file/magic/Magdir/cafebabe.auto.html
FAT_MAGIC = 0xcafebabe,
FAT_CIGAM = 0xbebafeca,
}
public static bool IsMachOImage(string filePath)
{
using (BinaryReader reader = new BinaryReader(File.OpenRead(filePath))) {
if (reader.BaseStream.Length < 256) // Header size
return false;
uint magic = reader.ReadUInt32();
return Enum.IsDefined(typeof(MagicMachO), magic);
}
}
}