Skip to content

Commit

Permalink
meson: Add support for picking backends to include
Browse files Browse the repository at this point in the history
  • Loading branch information
oleavr committed Mar 5, 2024
1 parent cc360c7 commit c2560de
Show file tree
Hide file tree
Showing 8 changed files with 502 additions and 469 deletions.
5 changes: 5 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ build_tests = get_option('tests') \
.allowed()

cdata = configuration_data()

if cc.get_define('FRIDA_VERSION') == ''
version = meson.project_version()
tokens = version.split('.')
Expand All @@ -182,6 +183,10 @@ endif

cdata.set_quoted('FRIDA_PREFIX', get_option('prefix'))

foreach name : get_option('backends')
vala_flags += '--define=HAVE_@0@_BACKEND'.format(name.underscorify().to_upper())
endforeach

exe_suffix = (host_os_family == 'windows') ? '.exe' : ''
if host_os_family == 'windows'
shlib_suffix = '.dll'
Expand Down
7 changes: 7 additions & 0 deletions meson.options
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
option('backends',
type: 'array',
choices: ['local', 'fruity', 'droidy', 'socket', 'barebone'],
value: ['local', 'fruity', 'droidy', 'socket', 'barebone'],
description: 'Backends to include'
)

option('assets',
type: 'combo',
choices: ['embedded', 'installed'],
Expand Down
121 changes: 58 additions & 63 deletions src/barebone/meson.build
Original file line number Diff line number Diff line change
@@ -1,64 +1,59 @@
barebone_sources = []
backend_sources += files(
'barebone-host-session.vala',
'script.vala',
'machine.vala',
'allocator.vala',
'callback.vala',
'memory-scanner.vala',
'interceptor.vala',
'rust-module.vala',
'arch-x86' / 'machine.vala',
'arch-x86_64' / 'machine.vala',
'arch-arm' / 'machine.vala',
'arch-arm64' / 'machine.vala',
'arch-unknown' / 'machine.vala',
)
barebone_script_runtime = custom_target('frida-barebone-script-runtime',
input: [
'package.json',
'package-lock.json',
'script-runtime' / 'console.ts',
'script-runtime' / 'entrypoint.ts',
'script-runtime' / 'gdb.ts',
'script-runtime' / 'hexdump.ts',
'script-runtime' / 'message-dispatcher.ts',
'script-runtime' / 'primitives.ts',
],
output: [
'script-runtime.js',
],
command: [
find_program('generate-script-runtime.py'),
meson.current_source_dir(),
meson.current_build_dir(),
],
)
backend_sources += custom_target('frida-data-barebone',
input: [
'barebone.resources',
barebone_script_runtime,
'helpers/memory-scanner-arm64.elf',
],
output: [
'frida-data-barebone.vapi',
'frida-data-barebone.h',
'frida-data-barebone.c',
'frida-data-barebone-blob' + resource_blob_extension,
],
command: [
resource_compiler,
'--toolchain=' + host_toolchain,
'--machine=' + host_arch,
'-c', '@INPUT0@',
'-o', meson.current_build_dir() / 'frida-data-barebone',
'@INPUT1@',
'@INPUT2@',
],
)

if quickjs_dep.found()
barebone_sources += files(
'barebone-host-session.vala',
'script.vala',
'machine.vala',
'allocator.vala',
'callback.vala',
'memory-scanner.vala',
'interceptor.vala',
'rust-module.vala',
'arch-x86/machine.vala',
'arch-x86_64/machine.vala',
'arch-arm/machine.vala',
'arch-arm64/machine.vala',
'arch-unknown/machine.vala',
)
barebone_script_runtime = custom_target('frida-barebone-script-runtime',
input: [
'package.json',
'package-lock.json',
'script-runtime/console.ts',
'script-runtime/entrypoint.ts',
'script-runtime/gdb.ts',
'script-runtime/hexdump.ts',
'script-runtime/message-dispatcher.ts',
'script-runtime/primitives.ts',
],
output: [
'script-runtime.js',
],
command: [
find_program('generate-script-runtime.py'),
meson.current_source_dir(),
meson.current_build_dir(),
],
)
barebone_data = custom_target('frida-data-barebone',
input: [
'barebone.resources',
barebone_script_runtime,
'helpers/memory-scanner-arm64.elf',
],
output: [
'frida-data-barebone.vapi',
'frida-data-barebone.h',
'frida-data-barebone.c',
'frida-data-barebone-blob' + resource_blob_extension,
],
command: [
resource_compiler,
'--toolchain=' + host_toolchain,
'--machine=' + host_arch,
'-c', '@INPUT0@',
'-o', join_paths(meson.current_build_dir(), 'frida-data-barebone'),
'@INPUT1@',
'@INPUT2@',
],
)
barebone_sources += barebone_data

backend_deps += quickjs_dep
endif
backend_deps += quickjs_dep
2 changes: 1 addition & 1 deletion src/compiler/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ if have_compiler_backend
resource_compiler,
'--toolchain=' + host_toolchain,
'-c', '@INPUT0@',
'-o', join_paths(meson.current_build_dir(), 'frida-data-compiler'),
'-o', meson.current_build_dir() / 'frida-data-compiler',
'@INPUT1@',
'@INPUT2@',
],
Expand Down
4 changes: 4 additions & 0 deletions src/control-service.vala
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace Frida {
ControlServiceOptions opts = (options != null) ? options : new ControlServiceOptions ();

HostSession host_session;
#if HAVE_LOCAL_BACKEND
#if WINDOWS
var tempdir = new TemporaryDirectory ();
host_session = new WindowsHostSession (new WindowsHelperProcess (tempdir), tempdir);
Expand All @@ -62,6 +63,9 @@ namespace Frida {
#if QNX
host_session = new QnxHostSession ();
#endif
#else
assert_not_reached ();
#endif

Object (
host_session: host_session,
Expand Down
8 changes: 8 additions & 0 deletions src/frida.vala
Original file line number Diff line number Diff line change
Expand Up @@ -3229,6 +3229,7 @@ namespace Frida {
public signal void uninjected (uint id);

public static Injector new () {
#if HAVE_LOCAL_BACKEND
#if WINDOWS
var tempdir = new TemporaryDirectory ();
var helper = new WindowsHelperProcess (tempdir);
Expand All @@ -3249,10 +3250,14 @@ namespace Frida {
#endif
#if QNX
return new Qinjector ();
#endif
#else
assert_not_reached ();
#endif
}

public static Injector new_inprocess () {
#if HAVE_LOCAL_BACKEND
#if WINDOWS
var tempdir = new TemporaryDirectory ();
var helper = new WindowsHelperBackend (PrivilegeLevel.NORMAL);
Expand All @@ -3273,6 +3278,9 @@ namespace Frida {
#endif
#if QNX
return new Qinjector ();
#endif
#else
assert_not_reached ();
#endif
}

Expand Down
12 changes: 12 additions & 0 deletions src/host-session-service.vala
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,33 @@ namespace Frida {
public HostSessionService.with_default_backends () {
add_local_backends ();
#if !IOS && !ANDROID && !TVOS
#if HAVE_FRUITY_BACKEND
add_backend (new FruityHostSessionBackend ());
#endif
#if HAVE_DROIDY_BACKEND
add_backend (new DroidyHostSessionBackend ());
#endif
#endif
#if HAVE_SOCKET_BACKEND
add_backend (new SocketHostSessionBackend ());
#endif
#if HAVE_BAREBONE_BACKEND
add_backend (new BareboneHostSessionBackend ());
#endif
}

public HostSessionService.with_local_backend_only () {
add_local_backends ();
}

public HostSessionService.with_socket_backend_only () {
#if HAVE_SOCKET_BACKEND
add_backend (new SocketHostSessionBackend ());
#endif
}

private void add_local_backends () {
#if HAVE_LOCAL_BACKEND
#if WINDOWS
add_backend (new WindowsHostSessionBackend ());
#endif
Expand All @@ -40,6 +51,7 @@ namespace Frida {
#endif
#if QNX
add_backend (new QnxHostSessionBackend ());
#endif
#endif
}

Expand Down
Loading

0 comments on commit c2560de

Please sign in to comment.