diff --git a/tests/core/swiftapiresolver/loader.js b/tests/core/swiftapiresolver/loader.js deleted file mode 100644 index e6d625c69..000000000 --- a/tests/core/swiftapiresolver/loader.js +++ /dev/null @@ -1,2 +0,0 @@ -const runner = Module.load(Process.getHomeDir() + '/src/frida/build/tmp-macos-arm64/frida-gum/tests/core/swiftapiresolver/libtestswiftapiresolver.dylib'); -const run = new NativeFunction(runner.getExportByName('gum_swift_api_resolver_tests_run'), 'void', [], { exceptions: 'propagate' }); diff --git a/tests/core/swiftapiresolver/run.py b/tests/core/swiftapiresolver/run.py index 5217c4509..c2f5a32f7 100644 --- a/tests/core/swiftapiresolver/run.py +++ b/tests/core/swiftapiresolver/run.py @@ -1,6 +1,7 @@ import frida from pathlib import Path import sys +import time def on_message(message, data): @@ -8,24 +9,21 @@ def on_message(message, data): runner_src_dir = Path(__file__).parent - runner_path = runner_src_dir.parent.parent.parent.parent / "build" / "tmp-macos-arm64" / "frida-gum" / "tests" / "core" / "swiftapiresolver" / "libtestswiftapiresolver.dylib" -print("runner_path:", runner_path) device = frida.get_remote_device() -target = device.get_process("Xcode") - -session = device.attach(target.pid) +session = device.attach("Xcode") script = session.create_script((runner_src_dir / "runner.js").read_text(encoding="utf-8")) script.on("message", on_message) script.load() -state_buffer_location = script.exports.get_state_buffer_location() - -device = frida.get_remote_device() -id = device.inject_library_file(target.pid, str(runner_path), "gum_swift_api_resolver_tests_main", state_buffer_location) -print("Injected:", id) +script.post({ "type": "start" }, runner_path.read_bytes()) -sys.stdin.read() +print("Running...") +t1 = time.time() +num_matches = script.exports_sync.run("*!*") +t2 = time.time() +duration = int((t2 - t1) * 1000) +print(f"Got {num_matches} matches in {duration} ms.") diff --git a/tests/core/swiftapiresolver/runner.c b/tests/core/swiftapiresolver/runner.c index bfa1b6e55..fa41fa47d 100644 --- a/tests/core/swiftapiresolver/runner.c +++ b/tests/core/swiftapiresolver/runner.c @@ -7,47 +7,44 @@ #include "gum.h" -typedef guint FridaUnloadPolicy; - -enum _FridaUnloadPolicy -{ - FRIDA_UNLOAD_POLICY_IMMEDIATE, - FRIDA_UNLOAD_POLICY_RESIDENT, - FRIDA_UNLOAD_POLICY_DEFERRED, -}; - static gboolean on_match (const GumApiDetails * details, gpointer user_data); -__attribute__ ((constructor)) static void +static GumApiResolver * resolver; + +void init (void) { gum_init_embedded (); + + resolver = gum_api_resolver_make ("swift"); + g_assert_nonnull (resolver); } void -gum_swift_api_resolver_tests_main (const gchar * agent_parameters, - FridaUnloadPolicy * unload_policy, - gpointer injector_state) +finalize (void) { - *unload_policy = FRIDA_UNLOAD_POLICY_RESIDENT; + g_object_unref (resolver); + + gum_deinit_embedded (); } -void -gum_swift_api_resolver_tests_run (void) +guint +run (const gchar * query) { - GumApiResolver * resolver; - - resolver = gum_api_resolver_make ("swift"); - g_assert_nonnull (resolver); + guint num_matches = 0; - gum_api_resolver_enumerate_matches (resolver, "*!*", on_match, NULL, NULL); + gum_api_resolver_enumerate_matches (resolver, query, on_match, &num_matches, NULL); - g_object_unref (resolver); + return num_matches; } static gboolean on_match (const GumApiDetails * details, gpointer user_data) { + guint * num_matches = user_data; + + (*num_matches)++; + return TRUE; } diff --git a/tests/core/swiftapiresolver/runner.js b/tests/core/swiftapiresolver/runner.js index 55bb7b2c0..f3cb84533 100644 --- a/tests/core/swiftapiresolver/runner.js +++ b/tests/core/swiftapiresolver/runner.js @@ -1,16 +1,24 @@ class Runner { constructor() { - this.stateBuf = Memory.alloc(Process.pageSize); + this._cm = null; + this._run = null; + recv('start', this._onStart); } - getStateBufferLocation() { - return this.stateBuf; + run(query) { + return this._run(Memory.allocUtf8String(query)); } + + _onStart = (message, data) => { + this._cm = new CModule(data); + this._run = new NativeFunction(this._cm.run, 'uint', ['pointer'], { exceptions: 'propagate' }); + }; } const runner = new Runner(); -globalThis.runner = runner; rpc.exports = { - getStateBufferLocation: runner.getStateBufferLocation.bind(runner), + run(query) { + return runner.run(query); + } }; diff --git a/tests/core/swiftapiresolver/runner.symbols b/tests/core/swiftapiresolver/runner.symbols index 59a83d482..ca4f9ecd1 100644 --- a/tests/core/swiftapiresolver/runner.symbols +++ b/tests/core/swiftapiresolver/runner.symbols @@ -1 +1,3 @@ -_gum_swift_api_resolver_tests_run +_init +_finalize +_run diff --git a/tests/core/swiftapiresolver/runner.version b/tests/core/swiftapiresolver/runner.version index fec9de3f9..e8618a23a 100644 --- a/tests/core/swiftapiresolver/runner.version +++ b/tests/core/swiftapiresolver/runner.version @@ -1,6 +1,8 @@ { global: - gum_swift_api_resolver_tests_run; + init; + finalize; + run; local: *;