diff options
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 27 |
1 files changed, 26 insertions, 1 deletions
| @@ -8,6 +8,20 @@ | |||
| 8 | #include "util.h" | 8 | #include "util.h" |
| 9 | #include "vm.h" | 9 | #include "vm.h" |
| 10 | 10 | ||
| 11 | void hex2bytes(char *hex) | ||
| 12 | { | ||
| 13 | size_t len = strlen(hex); | ||
| 14 | char bytes[len + 1]; | ||
| 15 | |||
| 16 | for (size_t i = 0; i < len; ++i) { | ||
| 17 | char hdig[3] = { hex[i*2], hex[i*2+1], '\0' }; | ||
| 18 | sscanf(hdig, "%hhx", &bytes[i]); | ||
| 19 | } | ||
| 20 | |||
| 21 | memcpy(hex, bytes, len); | ||
| 22 | hex[len] = '\0'; | ||
| 23 | } | ||
| 24 | |||
| 11 | int main(int argc, char *argv[]) | 25 | int main(int argc, char *argv[]) |
| 12 | { | 26 | { |
| 13 | if (argc < 2) { | 27 | if (argc < 2) { |
| @@ -23,7 +37,7 @@ int main(int argc, char *argv[]) | |||
| 23 | waitpid(pid, NULL, __WALL); | 37 | waitpid(pid, NULL, __WALL); |
| 24 | LOG("Attached to process %d\n", pid); | 38 | LOG("Attached to process %d\n", pid); |
| 25 | 39 | ||
| 26 | char *byte_seq = "secret text"; | 40 | char *byte_seq = "DEADBEEF"; |
| 27 | size_t byte_seq_len = strlen(byte_seq); | 41 | size_t byte_seq_len = strlen(byte_seq); |
| 28 | MemscanResult *head = memscan(pid, (uint8_t*)byte_seq, byte_seq_len); | 42 | MemscanResult *head = memscan(pid, (uint8_t*)byte_seq, byte_seq_len); |
| 29 | MemscanResult *cur = head; | 43 | MemscanResult *cur = head; |
| @@ -39,7 +53,18 @@ int main(int argc, char *argv[]) | |||
| 39 | cur->mapping->name); | 53 | cur->mapping->name); |
| 40 | cur = cur->next; | 54 | cur = cur->next; |
| 41 | } | 55 | } |
| 56 | |||
| 42 | printf("\n\n"); | 57 | printf("\n\n"); |
| 58 | |||
| 59 | char *buf = "CAFEBABE"; | ||
| 60 | size_t len = strlen(buf); | ||
| 61 | cur = head; | ||
| 62 | while (cur) { | ||
| 63 | void *address = cur->mapping->begin + cur->offset; | ||
| 64 | memwrite(pid, address, (uint8_t*)buf, len); | ||
| 65 | cur = cur->next; | ||
| 66 | } | ||
| 67 | |||
| 43 | ptrace(PTRACE_DETACH, pid, NULL, NULL); | 68 | ptrace(PTRACE_DETACH, pid, NULL, NULL); |
| 44 | LOG("Detached from process %d\n", pid); | 69 | LOG("Detached from process %d\n", pid); |
| 45 | 70 | ||
