fix trisomic jump
This commit is contained in:
parent
fba60ca76e
commit
8a5bfae528
|
@ -15,8 +15,8 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#define JUMP "\xe9"
|
#define JUMP "\xe9"
|
||||||
// #define TEXT_OFFSET "\xba\xba\xba\xba\xba\xba\xba\xba"
|
#define TEXT_OFFSET "\xba\xba\xba\xba\xba\xba\xba\xba"
|
||||||
// #define SECTION_SIZE "\xca\xca\xca\xca\xca\xca\xca\xca"
|
#define SECTION_SIZE "\xca\xca\xca\xca\xca\xca\xca\xca"
|
||||||
|
|
||||||
typedef struct payload
|
typedef struct payload
|
||||||
{
|
{
|
||||||
|
|
2
print.s
2
print.s
|
@ -18,5 +18,5 @@ _start:
|
||||||
pop rdi
|
pop rdi
|
||||||
pop rax
|
pop rax
|
||||||
jmp 0x00000000
|
jmp 0x00000000
|
||||||
|
|
||||||
msg db "..WOODY..",10
|
msg db "..WOODY..",10
|
||||||
|
section_sisze dq 0xcacacacacacacaca
|
20
srcs/woody.c
20
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)
|
int insert_payload(t_elf_content *woody, t_payload *payload, size_t payload_position)
|
||||||
{
|
{
|
||||||
char *ptr = ft_strnstr_nullterminated(payload->payload, JUMP, payload->len);
|
char *ptr_jmp = ft_strnstr_nullterminated(payload->payload, JUMP, payload->len);
|
||||||
if (ptr)
|
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;
|
printf("test a jumo = %ld\n", ptr_jmp - 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 + 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(&payload->payload[jmp_index + 1], &jump_value, sizeof(jump_value));
|
||||||
ft_memcpy(woody->file + payload_position, payload->payload, payload->len);
|
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("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("Code cave start = %ld (%lx)\n", payload_position, payload_position);
|
||||||
printf("Payload size = %ld (%lx)\n", payload->len, payload->len);
|
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_SUCCESS;
|
||||||
}
|
}
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
Loading…
Reference in New Issue