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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
const std = @import("std");
pub fn gum_stalker(b: *std.Build, opts: struct {
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
}) *std.Build.Step.Compile {
const dep = b.dependency("frida-gum", .{});
const capstone_dep = b.dependency("capstone", .{});
// stub gumenumtypes.h — normally generated by gnome.mkenums
const wf = b.addWriteFiles();
_ = wf.add("gum/gumenumtypes.h",
\\#ifndef __GUM_ENUM_TYPES_H__
\\#define __GUM_ENUM_TYPES_H__
\\#include <glib-object.h>
\\G_BEGIN_DECLS
\\GType gum_elf_type_get_type (void) G_GNUC_CONST;
\\#define GUM_TYPE_ELF_TYPE (gum_elf_type_get_type ())
\\GType gum_elf_osabi_get_type (void) G_GNUC_CONST;
\\#define GUM_TYPE_ELF_OSABI (gum_elf_osabi_get_type ())
\\GType gum_elf_machine_get_type (void) G_GNUC_CONST;
\\#define GUM_TYPE_ELF_MACHINE (gum_elf_machine_get_type ())
\\GType gum_elf_source_mode_get_type (void) G_GNUC_CONST;
\\#define GUM_TYPE_ELF_SOURCE_MODE (gum_elf_source_mode_get_type ())
\\G_END_DECLS
\\#endif
);
// C-only module (translate-c can't handle GLib's _Pragma macros)
const c_mod = b.createModule(.{
.target = opts.target,
// .optimize = opts.optimize,
.optimize = .Debug,
.link_libc = true,
});
// include paths for C source compilation
c_mod.addIncludePath(dep.path(""));
c_mod.addIncludePath(dep.path("gum"));
c_mod.addIncludePath(dep.path("gum/arch-x86"));
c_mod.addIncludePath(dep.path("gum/arch-arm"));
c_mod.addIncludePath(dep.path("gum/arch-arm64"));
c_mod.addIncludePath(dep.path("gum/arch-mips"));
c_mod.addIncludePath(dep.path("gum/backend-linux/include"));
c_mod.addIncludePath(dep.path("gum/backend-elf"));
c_mod.addIncludePath(dep.path("gum/backend-posix"));
c_mod.addIncludePath(dep.path("libs"));
c_mod.addIncludePath(dep.path("libs/gum/heap"));
c_mod.addIncludePath(dep.path("libs/gum/prof"));
c_mod.addIncludePath(capstone_dep.path("include/capstone"));
c_mod.addIncludePath(capstone_dep.path("include"));
c_mod.addIncludePath(wf.getDirectory());
// system libraries
c_mod.linkSystemLibrary("glib-2.0", .{});
c_mod.linkSystemLibrary("gobject-2.0", .{});
// config defines — replaces meson's config.h + add_project_arguments
// platform / arch
c_mod.addCMacro("HAVE_LINUX", "1");
c_mod.addCMacro("HAVE_I386", "1");
c_mod.addCMacro("HAVE_ELF", "1");
c_mod.addCMacro("HAVE_GLIBC", "1");
// frida-gum options
c_mod.addCMacro("GUM_STATIC", "1");
c_mod.addCMacro("GUM_USE_SYSTEM_ALLOC", "1");
c_mod.addCMacro("FRIDA_VERSION", "\"16.x\"");
// compiler feature detection
c_mod.addCMacro("HAVE_SYNC_LOCK", "1");
c_mod.addCMacro("HAVE_CLEAR_CACHE", "1");
c_mod.addCMacro("HAVE_CLTZ", "1");
c_mod.addCMacro("HAVE_POPCOUNT", "1");
c_mod.addCMacro("HAVE_PACK_PRAGMA", "1");
// system headers
c_mod.addCMacro("HAVE_ELF_H", "1");
c_mod.addCMacro("HAVE_LINK_H", "1");
c_mod.addCMacro("HAVE_STDINT_H", "1");
c_mod.addCMacro("HAVE_SYS_AUXV_H", "1");
c_mod.addCMacro("HAVE_ASM_PRCTL_H", "1");
c_mod.addCMacro("HAVE_SYS_USER_H", "1");
// system functions / types
c_mod.addCMacro("HAVE_MADVISE", "1");
c_mod.addCMacro("HAVE_LONG_DOUBLE", "1");
c_mod.addCMacro("HAVE_LONG_LONG_INT", "1");
c_mod.addCMacro("HAVE_UNSIGNED_LONG_LONG_INT", "1");
c_mod.addCMacro("HAVE_PTHREAD_ATTR_GETSTACK", "1");
c_mod.addCMacro("HAVE_PTHREAD_SETNAME_NP", "1");
// NOTE: HAVE_FRIDA_GLIB omitted — system GLib lacks frida's patches
// capstone compat (frida-gum uses capstone 5 type names)
c_mod.addCMacro("CAPSTONE_ARM_COMPAT_HEADER", "1");
c_mod.addCMacro("CAPSTONE_AARCH64_COMPAT_HEADER", "1");
c_mod.addCMacro("CAPSTONE_SYSTEMZ_COMPAT_HEADER", "1");
// GLib / compiler flags
c_mod.addCMacro("_GNU_SOURCE", "1");
c_mod.addCMacro("G_LOG_DOMAIN", "\"Frida\"");
c_mod.addCMacro("GLIB_VERSION_MIN_REQUIRED", "GLIB_VERSION_2_56");
c_mod.addCMacro("G_DISABLE_DEPRECATED", "");
// core + arch writers (unconditional in upstream meson)
c_mod.addCSourceFiles(.{
.root = dep.path("gum"),
.files = &.{
"gum.c",
"gumapiresolver.c",
"gumbacktracer.c",
"gumcloak.c",
"gumcodeallocator.c",
"gumcodesegment.c",
// gumdarwingrafter.c and gumdarwinmodule.c omitted (darwin only)
"gumelfmodule.c",
"gumeventsink.c",
"gumexceptor.c",
"gumheapapi.c",
"guminterceptor.c",
"guminvocationcontext.c",
"guminvocationlistener.c",
"gumkernel.c",
"gumleb.c",
"gumlibc.c",
"gummemory.c",
"gummemorymap.c",
"gummetalarray.c",
"gummetalhash.c",
"gummoduleapiresolver.c",
"gummodulemap.c",
"gumprintf.c",
"gumprocess.c",
"gumthreadregistry.c",
"gummodule.c",
"gummodulefacade.c",
"gummoduleregistry.c",
"gumreturnaddress.c",
"gumspinlock.c",
"gumstalker.c",
"gumswiftapiresolver.c",
// arch writers (x86 only — arm/arm64/mips need frida's capstone fork)
"arch-x86/gumx86writer.c",
"arch-x86/gumx86relocator.c",
"arch-x86/gumx86reader.c",
// x86 backend
"arch-x86/gumx86backtracer.c",
"backend-x86/gumcpucontext-x86.c",
"backend-x86/gumprocess-x86.c",
"backend-x86/guminterceptor-x86.c",
"backend-x86/gumstalker-x86.c",
// linux + posix backend
"backend-linux/gummemory-linux.c",
"backend-posix/gummemory-posix.c",
"backend-linux/gumprocess-linux.c",
"backend-linux/gumthreadregistry-linux.c",
"backend-linux/gummoduleregistry-linux.c",
"backend-linux/gummodule-linux.c",
"backend-posix/gumtls-posix.c",
"backend-posix/gumexceptor-posix.c",
"backend-posix/gummemoryaccessmonitor-posix.c",
// elf backend
"backend-elf/gummodule-elf.c",
"backend-elf/gummoduleregistry-elf.c",
},
});
// x86 assembly glue
c_mod.addAssemblyFile(dep.path("gum/backend-x86/gumstalker-x86-glue.S"));
const stalker_lib = b.addLibrary(.{
.name = "gumstalker",
.linkage = .static,
.root_module = c_mod,
});
stalker_lib.installHeadersDirectory(capstone_dep.path("include/capstone"), "capstone", .{});
stalker_lib.installHeader(capstone_dep.path("include/platform.h"), "capstone/platform.h");
return stalker_lib;
}
|