-
Notifications
You must be signed in to change notification settings - Fork 34
/
inject.c
64 lines (51 loc) · 1.24 KB
/
inject.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <frida-core.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/xattr.h>
int
main (int argc, char * argv[])
{
int result = 0;
const char * path = "/data/local/tmp/android-inject-example/agent.so";
const char * context = "u:object_r:frida_file:s0";
FridaInjector * injector;
int pid;
GError * error;
guint id;
frida_init ();
if (argc != 2)
goto bad_usage;
pid = atoi (argv[1]);
if (pid <= 0)
goto bad_usage;
frida_selinux_patch_policy ();
if (setxattr (path, XATTR_NAME_SELINUX, context, strlen (context) + 1, 0) != 0)
goto setxattr_failed;
injector = frida_injector_new ();
error = NULL;
id = frida_injector_inject_library_file_sync (injector, pid, path, "example_agent_main", "example data", NULL, &error);
if (error != NULL)
{
g_printerr ("%s\n", error->message);
g_clear_error (&error);
result = 1;
}
frida_injector_close_sync (injector, NULL, NULL);
g_object_unref (injector);
frida_deinit ();
return result;
bad_usage:
{
g_printerr ("Usage: %s <pid>\n", argv[0]);
frida_deinit ();
return 1;
}
setxattr_failed:
{
g_printerr ("Failed to set SELinux permissions\n");
frida_deinit ();
return 1;
}
}