From 84cc761ad4008a4a3c6e9a98f83764c51be64eeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Andr=C3=A9=20Vadla=20Ravn=C3=A5s?= Date: Fri, 3 May 2024 14:45:06 +0200 Subject: [PATCH] tests: Wire up macOS/arm64(e) cross-arch logic --- tests/process-unix.c | 10 ++++----- tests/runner.vala | 39 ++++++++++++++++++++++-------------- tests/test-host-session.vala | 10 +++++++-- 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/tests/process-unix.c b/tests/process-unix.c index 71f99b521..ecd33b722 100644 --- a/tests/process-unix.c +++ b/tests/process-unix.c @@ -159,16 +159,16 @@ frida_test_process_backend_create (const char * path, gchar ** argv, # elif defined (HAVE_ARM) pref = (arch == FRIDA_TEST_ARCH_CURRENT) ? CPU_TYPE_ARM : CPU_TYPE_ARM64; # elif defined (HAVE_ARM64) -# if __has_feature (ptrauth_calls) pref = CPU_TYPE_ARM64; +# if __has_feature (ptrauth_calls) + if (arch == FRIDA_TEST_ARCH_CURRENT) +# else if (arch == FRIDA_TEST_ARCH_OTHER) +# endif { - special_path = g_strconcat (path, "64", NULL); + special_path = g_strconcat (path, "-arm64e", NULL); path = special_path; } -# else - pref = (arch == FRIDA_TEST_ARCH_CURRENT) ? CPU_TYPE_ARM64 : CPU_TYPE_ARM; -# endif # endif posix_spawnattr_setbinpref_np (&attr, 1, &pref, &ocount); diff --git a/tests/runner.vala b/tests/runner.vala index dce328683..ebf283e2f 100644 --- a/tests/runner.vala +++ b/tests/runner.vala @@ -12,13 +12,23 @@ namespace Frida.Test { public static void run (string[] args) { Environment.init (ref args); - if (os () == MACOS) { - switch (cpu ()) { - case ARM_64: - can_test_cross_arch_injection = false; - break; - case X86_64: - try { + if (can_test_cross_arch_injection && os () == MACOS) { + try { + switch (cpu ()) { + case ARM_64: + if (Gum.query_ptrauth_support () == UNSUPPORTED) { + string output; + GLib.Process.spawn_command_line_sync ("nvram boot-args", out output); + + string[] tokens = output.strip ().split ("\t"); + assert (tokens.length == 2); + + unowned string boot_args = tokens[1]; + + can_test_cross_arch_injection = "-arm64e_preview_abi" in boot_args; + } + break; + case X86_64: string raw_version; GLib.Process.spawn_command_line_sync ("sw_vers -productVersion", out raw_version); @@ -29,14 +39,13 @@ namespace Frida.Test { uint minor = uint.parse (tokens[1]); bool newer_than_mojave = major > 10 || (major == 10 && minor > 4); - if (newer_than_mojave) - can_test_cross_arch_injection = false; - } catch (GLib.Error e) { - assert_not_reached (); - } - break; - default: - break; + can_test_cross_arch_injection = !newer_than_mojave; + break; + default: + break; + } + } catch (GLib.Error e) { + assert_not_reached (); } } diff --git a/tests/test-host-session.vala b/tests/test-host-session.vala index 91f42e0b4..25cfa3ee5 100644 --- a/tests/test-host-session.vala +++ b/tests/test-host-session.vala @@ -2146,7 +2146,10 @@ namespace Frida.HostSessionTest { switch (Frida.Test.os ()) { case Frida.Test.OS.MACOS: - suffix = "macos"; + if (Frida.Test.cpu () == ARM_64) + suffix = (Gum.query_ptrauth_support () == SUPPORTED) ? "macos-arm64e" : "macos"; + else + suffix = "macos"; break; case Frida.Test.OS.TVOS: suffix = "tvos"; @@ -2162,7 +2165,10 @@ namespace Frida.HostSessionTest { private static string target_name_of_other (string name) { string suffix; if (Frida.Test.os () == Frida.Test.OS.MACOS) { - suffix = "macos32"; + if (Frida.Test.cpu () == ARM_64) + suffix = (Gum.query_ptrauth_support () == SUPPORTED) ? "macos" : "macos-arm64e"; + else + suffix = "macos32"; } else { suffix = (Gum.query_ptrauth_support () == SUPPORTED) ? "ios64" : "ios32"; }