-
-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] Start wiring up a test runner injectable
Co-authored-by: Håvard Sørbø <[email protected]>
- Loading branch information
Showing
8 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
subdir('swiftapiresolver') | ||
|
||
core_sources = [ | ||
'tls.c', | ||
'cloak.c', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
_gum_swift_api_resolver_tests_run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
global: | ||
gum_swift_api_resolver_tests_run; | ||
|
||
local: | ||
*; | ||
}; |