Skip to content

Commit

Permalink
[WIP] Start wiring up a test runner injectable
Browse files Browse the repository at this point in the history
Co-authored-by: Håvard Sørbø <[email protected]>
  • Loading branch information
oleavr and hsorbo committed Sep 20, 2023
1 parent 4a8c27e commit 78fc865
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/core/meson.build
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
subdir('swiftapiresolver')

core_sources = [
'tls.c',
'cloak.c',
Expand Down
2 changes: 2 additions & 0 deletions tests/core/swiftapiresolver/loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
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' });
18 changes: 18 additions & 0 deletions tests/core/swiftapiresolver/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
extra_link_args = []
extra_link_depends = []

if host_os_family == 'darwin'
symlist = 'runner.symbols'
extra_link_args += '-Wl,-exported_symbols_list,' + meson.current_source_dir() / symlist
extra_link_depends += symlist
elif host_os_family != 'windows'
symscript = 'runner.version'
extra_link_args += '-Wl,--version-script,' + meson.current_source_dir() / symscript
extra_link_depends += [symscript]
endif

shared_module('testswiftapiresolver', 'runner.c',
dependencies: [gum_dep],
link_args: extra_link_args,
link_depends: extra_link_depends,
)
31 changes: 31 additions & 0 deletions tests/core/swiftapiresolver/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import frida
from pathlib import Path
import sys


def on_message(message, data):
print("on_message:", message)


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)

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)

sys.stdin.read()
53 changes: 53 additions & 0 deletions tests/core/swiftapiresolver/runner.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (C) 2023 Ole André Vadla Ravnås <[email protected]>
* Copyright (C) 2023 Håvard Sørbø <[email protected]>
*
* Licence: wxWindows Library Licence, Version 3.1
*/

#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
init (void)
{
gum_init_embedded ();
}

void
gum_swift_api_resolver_tests_main (const gchar * agent_parameters,
FridaUnloadPolicy * unload_policy,
gpointer injector_state)
{
*unload_policy = FRIDA_UNLOAD_POLICY_RESIDENT;
}

void
gum_swift_api_resolver_tests_run (void)
{
GumApiResolver * resolver;

resolver = gum_api_resolver_make ("swift");
g_assert_nonnull (resolver);

gum_api_resolver_enumerate_matches (resolver, "*!*", on_match, NULL, NULL);

g_object_unref (resolver);
}

static gboolean
on_match (const GumApiDetails * details,
gpointer user_data)
{
return TRUE;
}
16 changes: 16 additions & 0 deletions tests/core/swiftapiresolver/runner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Runner {
constructor() {
this.stateBuf = Memory.alloc(Process.pageSize);
}

getStateBufferLocation() {
return this.stateBuf;
}
}

const runner = new Runner();
globalThis.runner = runner;

rpc.exports = {
getStateBufferLocation: runner.getStateBufferLocation.bind(runner),
};
1 change: 1 addition & 0 deletions tests/core/swiftapiresolver/runner.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_gum_swift_api_resolver_tests_run
7 changes: 7 additions & 0 deletions tests/core/swiftapiresolver/runner.version
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
global:
gum_swift_api_resolver_tests_run;

local:
*;
};

0 comments on commit 78fc865

Please sign in to comment.