1
+ #include <stdlib.h>
1
2
#include <unistd.h>
2
3
#include <argp.h>
3
4
#include <arpa/inet.h>
7
8
#include <sys/capability.h>
8
9
9
10
#include "lemon.h"
10
- #include "ebpf/mem.ebpf.skel.h"
11
11
12
- extern int init_translation (struct ram_regions * restrict ram_regions , struct mem_ebpf * restrict skel );
12
+ extern int load_ebpf_mem_progs (void );
13
+ extern int init_translation (struct ram_regions * restrict ram_regions );
13
14
extern int dump_on_disk (const struct options * restrict opts , const struct ram_regions * restrict ram_regions );
14
15
extern int dump_on_net (const struct options * restrict opts , const struct ram_regions * restrict ram_regions );
15
16
extern int increase_priority_and_launch_stealers (void );
16
- extern int init_mmap (struct mem_ebpf * restrict skel );
17
- extern void cleanup_mmap (void );
18
17
extern int join_cpu_stealers (void );
19
18
extern int check_capability (const cap_value_t cap );
20
19
extern int toggle_kptr (void );
@@ -32,48 +31,6 @@ static const struct argp_option options[] = {
32
31
};
33
32
static const char doc [] = "Lemon - An eBPF Memory Dump Tool for x64 and ARM64 Linux and Android" ;
34
33
35
- /*
36
- * load_ebpf_mem_progs() - Initialize and attach eBPF programs for memory access
37
- * @skel: Output pointer to the initialized mem_ebpf skeleton
38
- *
39
- * Opens, loads, attaches the eBPF programs, and sets up shared memory.
40
- * Returns 0 on success or a negative error code on failure.
41
- */
42
- static int load_ebpf_mem_progs (struct mem_ebpf * * restrict skel ) {
43
- int ret ;
44
-
45
- /* Check if we have sufficient capabilities to set RLIMIT_MEMLOCK (required by libbpf...)*/
46
- if ((check_capability (CAP_PERFMON ) <= 0 ) && (check_capability (CAP_SYS_ADMIN ) <= 0 )) {
47
- WARN ("LEMON does not have CAP_PERFMON needed to modify RLIMIT_MEMLOCK" );
48
- }
49
-
50
- /* Open the BPF object file */
51
- * skel = mem_ebpf__open ();
52
- if (!skel ) {
53
- perror ("Failed to open BPF skeleton" );
54
- return errno ;
55
- }
56
-
57
- /* Load the BPF objectes */
58
- if (mem_ebpf__load (* skel )) {
59
- perror ("Failed to load BPF object" );
60
- return errno ;
61
- }
62
-
63
- /* Attach the uprobe to the 'read_kernel_memory' function in the current executable */
64
- if (mem_ebpf__attach (* skel )) {
65
- fprintf (stderr , "Failed to attach program\n" );
66
- return errno ;
67
- }
68
-
69
- /* Create the mmap */
70
- if ((ret = init_mmap (* skel ))) {
71
- return ret ;
72
- }
73
-
74
- return 0 ;
75
- }
76
-
77
34
/*
78
35
* parse_opt() - Argument parser callback for argp
79
36
* @key: Option key
@@ -163,7 +120,6 @@ static int check_kernel_version() {
163
120
164
121
int main (int argc , char * * argv )
165
122
{
166
- struct mem_ebpf * skel = NULL ;
167
123
struct ram_regions ram_regions ;
168
124
struct options opts = {0 };
169
125
struct argp argp = {options , parse_opt , "" , doc };
@@ -214,13 +170,13 @@ int main(int argc, char **argv)
214
170
}
215
171
216
172
/* Load eBPF progs that read memory */
217
- if ((ret = load_ebpf_mem_progs (& skel ))) return ret ;
173
+ if ((ret = load_ebpf_mem_progs ())) return ret ;
218
174
219
175
/* Disable kptr_restrict if needed */
220
176
if ((ret = toggle_kptr ())) return ret ;
221
177
222
178
/* Determine the memory dumpable regions */
223
- if ((ret = init_translation (& ram_regions , skel ))) goto cleanup ;
179
+ if ((ret = init_translation (& ram_regions ))) goto cleanup ;
224
180
225
181
/* Dump on a file */
226
182
if (opts .disk_mode ) {
@@ -234,10 +190,6 @@ int main(int argc, char **argv)
234
190
235
191
/* Cleanup: close BPF object */
236
192
cleanup :
237
- if (skel ) {
238
- cleanup_mmap ();
239
- mem_ebpf__destroy (skel );
240
- }
241
193
join_cpu_stealers ();
242
194
243
195
/* Restore kptr_restrict if needed */
0 commit comments