diff options
author | comex | 2015-02-18 02:22:36 -0500 |
---|---|---|
committer | comex | 2015-02-18 02:22:36 -0500 |
commit | 7c26a1964d2d2e54f87d9c42735f6c99b546abd4 (patch) | |
tree | f50838e492aa101a4d87e6ef01d1dc2611f32f97 /test | |
parent | more fixes (diff) | |
download | substitute-7c26a1964d2d2e54f87d9c42735f6c99b546abd4.tar.gz |
Fix hook-function:
- Thread stoppage is now complemented by sigaction to catch injected
threads (sigaction is not used exclusively because the rest of the
program could be trying to use sigaction itself in the meantime - this
is a real thing, ask Dolphin)
- mprotect is no longer used due to max_protection possibly getting in
the way; instead, a copy is created and mapped onto the original.
Diffstat (limited to 'test')
-rw-r--r-- | test/test-execmem.c | 11 | ||||
-rw-r--r-- | test/test-pc-patch.c (renamed from test/test-stop-threads.c) | 22 |
2 files changed, 21 insertions, 12 deletions
diff --git a/test/test-execmem.c b/test/test-execmem.c index 5ec64e9..9125d68 100644 --- a/test/test-execmem.c +++ b/test/test-execmem.c @@ -25,13 +25,18 @@ int test(size_t a) { return 1000; } +static int ewrite(void *dst, const void *src, size_t len) { + struct execmem_foreign_write w = {dst, src, len}; + return execmem_foreign_write_with_pc_patch(&w, 1, NULL, NULL); +} + int main() { printf("this should be 5: %d\n", test(0)); - printf("=> %d\n", execmem_write(test, other, OTHER_SIZE)); + printf("=> %d\n", ewrite(test, other, OTHER_SIZE)); printf(" %s\n", strerror(errno)); printf("this should be 6: %d\n", test(0)); - printf("=> %d\n", execmem_write(hcreate, other, OTHER_SIZE)); + printf("=> %d\n", ewrite(hcreate, other, OTHER_SIZE)); printf(" %s\n", strerror(errno)); - printf("modified shared cache func: %d\n", hcreate(0)); + printf("modified shared cache func should be 6: %d\n", hcreate(0)); } diff --git a/test/test-stop-threads.c b/test/test-pc-patch.c index d53d8cd..5ae3570 100644 --- a/test/test-stop-threads.c +++ b/test/test-pc-patch.c @@ -1,7 +1,8 @@ #include "substitute-internal.h" -#include "stop-other-threads.h" +#include "execmem.h" #include <stdio.h> #include <unistd.h> +#include <stdlib.h> #include <pthread.h> #include <assert.h> /* printf without taking any locks - because they might be taken at stop time */ @@ -32,14 +33,17 @@ int main() { for (long i = 0; i < 10; i++) pthread_create(&pts[i], NULL, some_thread, (void *) i); sleep(1); - void *stop_token; - ulprintf("stopping\n"); - assert(!stop_other_threads(&stop_token)); - ulprintf("stopped\n"); - assert(!apply_pc_patch_callback(stop_token, patch_callback, NULL)); - ulprintf("resuming\n"); - assert(!resume_other_threads(stop_token)); - ulprintf("resumed\n"); + char *foo = malloc(0x10000); + static char bar[16]; + struct execmem_foreign_write writes[] = { + {foo, bar, 5}, + {foo + 7, bar + 7, 3}, + }; + int ret = execmem_foreign_write_with_pc_patch(writes, + sizeof(writes)/sizeof(*writes), + patch_callback, + NULL); + ulprintf("==> %d\n", ret); void *out; for (long i = 0; i < 10; i++) assert(!pthread_join(pts[i], &out)); |