-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.c
More file actions
71 lines (55 loc) · 1.75 KB
/
Copy pathexample.c
File metadata and controls
71 lines (55 loc) · 1.75 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <plinux.h>
#include <dlfcn.h>
#include <string.h>
int main(int argc, char *argv[])
{
if (argc != 2)
{
fprintf(stderr, "Usage: %s <PID>\n", argv[0]);
return EXIT_FAILURE;
}
pid_t pid = atoi(argv[1]);
if (pid <= 0)
{
fprintf(stderr, "[*] Invalid PID: %s\n", argv[1]);
return EXIT_FAILURE;
}
if (plinux_attach(pid) == -1)
{
perror("[*] Failed to attach to process");
return EXIT_FAILURE;
}
printf("[*] Successfully attached to process %d\n", pid);
const char *malloc_symbol = "malloc";
void *malloc_addr = plinux_resolve(pid, malloc_symbol);
if (!malloc_addr)
{
fprintf(stderr, "[*] Failed to resolve symbol: %s\n", malloc_symbol);
plinux_detach(pid);
return EXIT_FAILURE;
}
printf("[*] Resolved address for '%s': %p\n", malloc_symbol, malloc_addr);
void *alloc = (void*)plinux_call(pid, malloc_addr, 1000); // call malloc
printf("[*] Memory malloc allocated in '%p'\n", alloc);
const char *hello = "Hello World";
plinux_write_memory(pid, alloc, hello, strlen(hello));
const char *puts_symbol = "puts";
void *puts_addr = plinux_resolve(pid, puts_symbol);
if (!puts_addr)
{
fprintf(stderr, "[*] Failed to resolve symbol: %s\n", puts_symbol);
plinux_detach(pid);
return EXIT_FAILURE;
}
printf("[*] Resolved address for '%s': %p\n", puts_symbol, puts_addr);
plinux_call(pid, puts, alloc); // call puts
if (plinux_detach(pid) == -1)
{
perror("[*] Failed to detach from process");
return EXIT_FAILURE;
}
printf("[*] Successfully detached from process %d\n", pid);
return EXIT_SUCCESS;
}