🐛 Fix Built-in Pandoc is not working on Unix-like

Fix https://github.com/siyuan-note/siyuan/issues/16623

Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
Daniel 2025-12-19 20:13:57 +08:00
parent 43c8ccb96b
commit bc238a245f
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -239,17 +239,20 @@ func IsValidPandocBin(binPath string) bool {
}
isBin := false
// 常见二进制魔数ELF, PE("MZ"), Mach-O/FAT
// 常见二进制魔数ELF, PE("MZ"), Mach-O (32/64, big/little), FAT
if len(header) >= 4 {
switch {
case bytes.Equal(header[:4], []byte{0x7f, 'E', 'L', 'F'}):
isBin = true // ELF
case bytes.Equal(header[:4], []byte{0xfe, 0xed, 0xfa, 0xce}):
isBin = true // Mach-O
case bytes.Equal(header[:4], []byte{0xce, 0xfa, 0xed, 0xfe}):
isBin = true // Mach-O (swapped)
case bytes.Equal(header[:4], []byte{0xca, 0xfe, 0xba, 0xbe}):
isBin = true // FAT
// Mach-O / Mach-O swapped (32-bit)
case bytes.Equal(header[:4], []byte{0xfe, 0xed, 0xfa, 0xce}), bytes.Equal(header[:4], []byte{0xce, 0xfa, 0xed, 0xfe}):
isBin = true
// Mach-O 64-bit / swapped
case bytes.Equal(header[:4], []byte{0xfe, 0xed, 0xfa, 0xcf}), bytes.Equal(header[:4], []byte{0xcf, 0xfa, 0xed, 0xfe}):
isBin = true
// FAT / FAT swapped
case bytes.Equal(header[:4], []byte{0xca, 0xfe, 0xba, 0xbe}), bytes.Equal(header[:4], []byte{0xbe, 0xba, 0xfe, 0xca}):
isBin = true
}
}
// PE only needs first 2 bytes "MZ"