diff options
| author | Orfeas <38209077+0xfea5@users.noreply.github.com> | 2024-04-16 22:14:29 +0300 |
|---|---|---|
| committer | Orfeas <38209077+0xfea5@users.noreply.github.com> | 2024-04-19 20:20:13 +0300 |
| commit | 7e8bd04389875d8569463f42923792557edc2908 (patch) | |
| tree | aad1922fcfdd0af286531b3b2b58aa6c3da67be8 /src/vm.c | |
| parent | Memory scanning to find byte patterns (diff) | |
| download | linux-game-trainer-7e8bd04389875d8569463f42923792557edc2908.tar.gz linux-game-trainer-7e8bd04389875d8569463f42923792557edc2908.zip | |
Write other process' memory
Diffstat (limited to 'src/vm.c')
| -rw-r--r-- | src/vm.c | 27 |
1 files changed, 16 insertions, 11 deletions
| @@ -1,3 +1,4 @@ | |||
| 1 | #include <sys/ptrace.h> | ||
| 1 | #include <stdlib.h> | 2 | #include <stdlib.h> |
| 2 | #include <stdio.h> | 3 | #include <stdio.h> |
| 3 | #include <string.h> | 4 | #include <string.h> |
| @@ -63,15 +64,6 @@ VMMapping* parse_vmmap (int pid) | |||
| 63 | } else { | 64 | } else { |
| 64 | head = cur = new_mapping; | 65 | head = cur = new_mapping; |
| 65 | } | 66 | } |
| 66 | |||
| 67 | LOG("%p-%p %c%c%c%c %s\n", | ||
| 68 | cur->begin, | ||
| 69 | cur->end, | ||
| 70 | cur->r ? 'r' : '-', | ||
| 71 | cur->w ? 'w' : '-', | ||
| 72 | cur->x ? 'x' : '-', | ||
| 73 | cur->s ? 's' : 'p', | ||
| 74 | cur->name); | ||
| 75 | } | 67 | } |
| 76 | 68 | ||
| 77 | return head; | 69 | return head; |
| @@ -91,7 +83,7 @@ MemscanResult* memscan(int pid, uint8_t *byte_seq, uint64_t byte_seq_len) | |||
| 91 | { | 83 | { |
| 92 | char fmem_path[1024] = {0}; | 84 | char fmem_path[1024] = {0}; |
| 93 | sprintf(fmem_path, "/proc/%d/mem", pid); | 85 | sprintf(fmem_path, "/proc/%d/mem", pid); |
| 94 | FILE *fmem = fopen(fmem_path, "rb+"); | 86 | FILE *fmem = fopen(fmem_path, "rb"); |
| 95 | VMMapping *vmmaps_head = parse_vmmap(pid); | 87 | VMMapping *vmmaps_head = parse_vmmap(pid); |
| 96 | VMMapping *cur_vmmap = vmmaps_head; | 88 | VMMapping *cur_vmmap = vmmaps_head; |
| 97 | MemscanResult *cur = NULL, *head = NULL; | 89 | MemscanResult *cur = NULL, *head = NULL; |
| @@ -101,7 +93,6 @@ MemscanResult* memscan(int pid, uint8_t *byte_seq, uint64_t byte_seq_len) | |||
| 101 | cur_vmmap = cur_vmmap->next; | 93 | cur_vmmap = cur_vmmap->next; |
| 102 | continue; | 94 | continue; |
| 103 | } | 95 | } |
| 104 | LOG("Scanning [%p]\n", cur_vmmap->begin); | ||
| 105 | 96 | ||
| 106 | size_t region_size = cur_vmmap->end - cur_vmmap->begin; | 97 | size_t region_size = cur_vmmap->end - cur_vmmap->begin; |
| 107 | uint8_t region_data[region_size]; | 98 | uint8_t region_data[region_size]; |
| @@ -135,6 +126,20 @@ MemscanResult* memscan(int pid, uint8_t *byte_seq, uint64_t byte_seq_len) | |||
| 135 | 126 | ||
| 136 | cur_vmmap = cur_vmmap->next; | 127 | cur_vmmap = cur_vmmap->next; |
| 137 | } | 128 | } |
| 129 | fclose(fmem); | ||
| 138 | 130 | ||
| 139 | return head; | 131 | return head; |
| 140 | } | 132 | } |
| 133 | |||
| 134 | void memwrite(int pid, void *address, uint8_t *data, size_t data_len) | ||
| 135 | { | ||
| 136 | char fmem_path[1024] = {0}; | ||
| 137 | sprintf(fmem_path, "/proc/%d/mem", pid); | ||
| 138 | FILE *fmem = fopen(fmem_path, "rb+"); | ||
| 139 | |||
| 140 | fseek(fmem, (off_t)address, SEEK_SET); | ||
| 141 | fwrite(data, 1, data_len, fmem); | ||
| 142 | fclose(fmem); | ||
| 143 | |||
| 144 | LOG("Data written successfully at address %p\n", address); | ||
| 145 | } | ||
