diff --git a/includes/woody.h b/includes/woody.h index f47c5a4..2807779 100644 --- a/includes/woody.h +++ b/includes/woody.h @@ -15,8 +15,8 @@ #include #define JUMP "\xe9" -// #define TEXT_OFFSET "\xba\xba\xba\xba\xba\xba\xba\xba" -// #define SECTION_SIZE "\xca\xca\xca\xca\xca\xca\xca\xca" +#define TEXT_OFFSET "\xba\xba\xba\xba\xba\xba\xba\xba" +#define SECTION_SIZE "\xca\xca\xca\xca\xca\xca\xca\xca" typedef struct payload { diff --git a/print.s b/print.s index c30897a..4e386bd 100644 --- a/print.s +++ b/print.s @@ -18,5 +18,5 @@ _start: pop rdi pop rax jmp 0x00000000 - msg db "..WOODY..",10 + section_sisze dq 0xcacacacacacacaca \ No newline at end of file diff --git a/srcs/woody.c b/srcs/woody.c index 24a9728..0ad2708 100644 --- a/srcs/woody.c +++ b/srcs/woody.c @@ -100,11 +100,21 @@ t_payload *get_payload() int insert_payload(t_elf_content *woody, t_payload *payload, size_t payload_position) { - char *ptr = ft_strnstr_nullterminated(payload->payload, JUMP, payload->len); - if (ptr) + char *ptr_jmp = ft_strnstr_nullterminated(payload->payload, JUMP, payload->len); + char *ptr_text_section = ft_strnstr_nullterminated(payload->payload, TEXT_OFFSET, payload->len); + char *ptr_section_size = ft_strnstr_nullterminated(payload->payload, SECTION_SIZE, payload->len); + (void)ptr_section_size; + (void)ptr_text_section; + printf("text_section = %ld and size = %ld\n", woody->text_section->sh_offset, woody->text_section->sh_size); + if (ptr_jmp) { - int32_t jmp_index = ptr - payload->payload; - int32_t jump_value = ((payload_position + payload->len) - woody->Ehdr->e_entry) * -1; + printf("test a jumo = %ld\n", ptr_jmp - payload->payload); + printf("test a jumo = %ld\n", ptr_jmp - payload->payload + sizeof(JUMP)); + printf("jump base = %ld\n", payload->len); + printf("the jump = %ld\n", payload->len - 16); + + int32_t jmp_index = ptr_jmp - payload->payload; + int32_t jump_value = (payload_position - woody->Ehdr->e_entry + jmp_index - 1) * -1; ft_memcpy(&payload->payload[jmp_index + 1], &jump_value, sizeof(jump_value)); ft_memcpy(woody->file + payload_position, payload->payload, payload->len); @@ -112,7 +122,7 @@ int insert_payload(t_elf_content *woody, t_payload *payload, size_t payload_posi printf("Old entry : %ld (%lx)\n", woody->Ehdr->e_entry, woody->Ehdr->e_entry); printf("Code cave start = %ld (%lx)\n", payload_position, payload_position); printf("Payload size = %ld (%lx)\n", payload->len, payload->len); - printf("Backwar d offset = %d (%x)\n", jump_value, jump_value); + printf("Backwar d offset = %d (%x)(%x)\n", jump_value, jump_value, -jump_value); return EXIT_SUCCESS; } return EXIT_FAILURE;