From a6ff82c4e51aecc45a095f86c09e08f33791c87a Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Fri, 29 Jul 2016 20:52:46 +1000 Subject: [PATCH 1/2] Remove an unused variable. --- inject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inject.c b/inject.c index 345ce70..93c19a0 100644 --- a/inject.c +++ b/inject.c @@ -242,7 +242,7 @@ _launch_payload(int pid, void *code_cave, size_t code_cave_size, void *stack_add int inject_code(int pid, unsigned char *payload, size_t payload_len) { - int ret = 0, status = 0; + int ret = 0; void *payload_addr = NULL, *stack = NULL, *code_cave = NULL, From d919d3915582b161a075a375287bd634c810ba8b Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Fri, 29 Jul 2016 21:02:10 +1000 Subject: [PATCH 2/2] Reduce memory allocation very slightly. Prior to this commit, a word-aligned payload would result in an allocation that was one word larger than required. This commit modifies the rounding logic so we only round up if the payload is not already word-aligned. Closes #2 --- inject.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/inject.c b/inject.c index 93c19a0..c404fcd 100644 --- a/inject.c +++ b/inject.c @@ -104,7 +104,10 @@ _mmap_data(int pid, size_t len, void *base_address, int protections, int flags, long shellcode_len = ftell(f); CHECK(shellcode_len > 0, "ftell error"); // align shellcode size to 32/64-bit boundary - long shellcode_len_aligned = shellcode_len + (sizeof(void*) - (shellcode_len % sizeof(void*))); + long shellcode_len_aligned = shellcode_len; + if (shellcode_len % sizeof(void*) != 0) { + shellcode_len_aligned += sizeof(void*) - shellcode_len % sizeof(void*); + } CHECK(fseek(f, 0, SEEK_SET) == 0, "fseek error"); shellcode = malloc(shellcode_len_aligned); memset(shellcode, 0x90, shellcode_len_aligned); // fill with NOPs