From c627e746134912921b16f7ddfb60fec7bc344d58 Mon Sep 17 00:00:00 2001 From: Steve-xmh Date: Tue, 7 Nov 2023 19:28:45 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=86=E5=88=AB=E5=88=B0=E5=A4=9A=E6=9E=B6?= =?UTF-8?q?=E6=9E=84=E6=89=A7=E8=A1=8C=E6=96=87=E4=BB=B6=E6=97=B6=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E9=80=89=E6=8B=A9=E5=BD=93=E5=89=8D=E6=9E=B6=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scl-core/src/utils.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/scl-core/src/utils.rs b/scl-core/src/utils.rs index 7b8371f..ae3c2ee 100644 --- a/scl-core/src/utils.rs +++ b/scl-core/src/utils.rs @@ -200,6 +200,17 @@ pub enum Arch { ARM64, } +impl Default for Arch { + fn default() -> Self { + #[cfg(target_arch = "x86")] + return Arch::X86; + #[cfg(target_arch = "x86_64")] + return Arch::X64; + #[cfg(target_arch = "aarch64")] + return Arch::ARM64; + } +} + impl Display for Arch { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str(self.as_ref()) @@ -328,6 +339,11 @@ pub async fn get_exec_arch(file_path: impl AsRef) -> DynResult< file.read_exact(&mut buf).await?; + // 多架构 Mach-O,默认取当前运行架构 + // 一般出现于 /usr/bin/java 中 + if buf[0] == 0xCA && buf[1] == 0xFE && buf[2] == 0xBA && buf[3] == 0xBE { + return Ok(Arch::default()); + } // Mach-O Magic Number // CF FA ED FE if !(buf[0] == 0xCF && buf[1] == 0xFA && buf[2] == 0xED && buf[3] == 0xFE) {