Skip to content

Commit 44e634b

Browse files
committed
fruity: Embed idund for embedded assets
Idun now always goes through idund on Windows and Linux, so ship the daemon inside the library when assets are embedded, extracting it to a temporary file before starting the device monitor. With installed assets Idun installs idund next to the library and resolves it from there. A daemon that fails to start is reported on stderr and leaves Apple devices unavailable instead of failing the whole backend.
1 parent e6db304 commit 44e634b

4 files changed

Lines changed: 73 additions & 2 deletions

File tree

‎meson.build‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,11 +727,18 @@ openssl_dep = dependency('openssl',
727727
)
728728

729729
idun_libs = []
730+
have_idund_blob = false
730731
if have_fruity_backend
731732
idun_dep = dependency('idun-1.0', default_options: ['default_library=static'])
732733
backend_reqs_private += 'idun-1.0'
733734
if idun_dep.type_name() == 'internal'
734-
idun_libs += subproject('idun').get_variable('idun')
735+
idun_sp = subproject('idun')
736+
idun_libs += idun_sp.get_variable('idun')
737+
if assets_mode == 'embedded' and idun_sp.get_variable('build_daemon')
738+
idund_raw = idun_sp.get_variable('idund')
739+
have_idund_blob = true
740+
vala_flags += '--define=HAVE_IDUND_BLOB'
741+
endif
735742
endif
736743
idun_vapidir = idun_dep.get_variable('vapidir', default_value: '')
737744
if idun_vapidir != ''

‎src/fruity/fruity-host-session.vala‎

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ namespace Frida {
88
new Gee.HashMap<Idun.Device, FruityHostSessionProvider> ();
99

1010
private Cancellable io_cancellable = new Cancellable ();
11+
#if HAVE_IDUND_BLOB
12+
private TemporaryDirectory daemon_dir = new TemporaryDirectory ();
13+
private TemporaryFile? daemon_file;
14+
15+
#if WINDOWS
16+
private const string DAEMON_FILENAME = "idund.exe";
17+
#else
18+
private const string DAEMON_FILENAME = "idund";
19+
#endif
20+
#endif
1121

1222
construct {
1323
device_monitor.device_attached.connect (on_device_attached);
@@ -18,9 +28,34 @@ namespace Frida {
1828
#if !MACOS
1929
migrate_pairing_store ();
2030
#endif
21-
yield device_monitor.start (cancellable);
31+
try {
32+
#if HAVE_IDUND_BLOB
33+
device_monitor.daemon_path = extract_daemon ();
34+
#endif
35+
yield device_monitor.start (cancellable);
36+
} catch (Efni.Error e) {
37+
printerr ("Unable to start idund: %s\n", e.message);
38+
}
2239
}
2340

41+
#if HAVE_IDUND_BLOB
42+
private string extract_daemon () throws Efni.Error {
43+
#if WINDOWS
44+
var blob = Frida.Data.Idund.get_idund_exe_blob ();
45+
#else
46+
var blob = Frida.Data.Idund.get_idund_blob ();
47+
#endif
48+
try {
49+
daemon_file = new TemporaryFile.from_stream (DAEMON_FILENAME, new MemoryInputStream.from_data (blob.data, null),
50+
daemon_dir);
51+
} catch (Error e) {
52+
throw new Efni.Error.PERMISSION_DENIED ("%s", e.message);
53+
}
54+
FileUtils.chmod (daemon_file.path, 0700);
55+
return daemon_file.path;
56+
}
57+
#endif
58+
2459
#if !MACOS
2560
private static void migrate_pairing_store () {
2661
string config_dir = Environment.get_user_config_dir ();

‎src/fruity/idund.resources‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[resource-compiler]
2+
namespace = Frida.Data.Idund

‎src/meson.build‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,33 @@ if have_fruity_backend
592592
'fruity' / 'injector.vala',
593593
]
594594
backend_deps += idun_dep
595+
596+
if have_idund_blob
597+
idund = custom_target('frida-idund',
598+
input: idund_raw,
599+
output: 'idund' + exe_suffix,
600+
command: post_process + ['executable', 're.frida.Idund'],
601+
)
602+
idund_data = custom_target('frida-data-idund',
603+
input: [
604+
'fruity' / 'idund.resources',
605+
idund,
606+
],
607+
output: [
608+
'frida-data-idund.vapi',
609+
'frida-data-idund.h',
610+
'frida-data-idund.c',
611+
'frida-data-idund-blob' + resource_blob_extension,
612+
],
613+
command: [
614+
resource_compiler_cmd_array,
615+
'-c', '@INPUT0@',
616+
'-o', meson.current_build_dir() / 'frida-data-idund',
617+
'@INPUT1@',
618+
],
619+
)
620+
backend_sources += [idund_data]
621+
endif
595622
endif
596623

597624
if have_droidy_backend

0 commit comments

Comments
 (0)