-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
44 lines (38 loc) · 943 Bytes
/
main.c
File metadata and controls
44 lines (38 loc) · 943 Bytes
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
#include "rsym.h"
#include <stdio.h>
int main(int argc, char *argv[])
{
if (argc < 3)
{
fprintf(stderr, "usage: %s <process> <image> <symbol>\n", argv[0]);
return 1;
}
const char *process = argv[1];
const char *image = argv[2];
const char *symbol = argc > 3 ? argv[3] : NULL;
pid_t pid = get_pid_by_name(process);
if (!pid)
{
fprintf(stderr, "process not found: %s\n", process);
return 1;
}
if (symbol)
{
mach_vm_address_t addr = rsym(pid, image, symbol, true);
if (addr)
{
printf("0x%llx\n", (unsigned long long)addr);
return 0;
}
fprintf(stderr, "symbol not found\n");
return 1;
}
mach_vm_address_t base = rbase(pid, image);
if (base)
{
printf("0x%llx\n", (unsigned long long)base);
return 0;
}
fprintf(stderr, "not found\n");
return 1;
}