1 #include "../../qemu_mode/qemuafl/qemuafl/api.h"
2
3 #include <stdint.h>
4 #include <string.h>
5
6 #define g2h(x) ((void *)((unsigned long)(x) + guest_base))
7 #define h2g(x) ((uint64_t)(x)-guest_base)
8
afl_persistent_hook(struct x86_64_regs * regs,uint64_t guest_base,uint8_t * input_buf,uint32_t input_buf_len)9 void afl_persistent_hook(struct x86_64_regs *regs, uint64_t guest_base,
10 uint8_t *input_buf, uint32_t input_buf_len) {
11
12 // In this example the register RDI is pointing to the memory location
13 // of the target buffer, and the length of the input is in RSI.
14 // This can be seen with a debugger, e.g. gdb (and "disass main")
15
16 memcpy(g2h(regs->rdi), input_buf, input_buf_len);
17 regs->rsi = input_buf_len;
18
19 }
20
21 #undef g2h
22 #undef h2g
23
afl_persistent_hook_init(void)24 int afl_persistent_hook_init(void) {
25
26 // 1 for shared memory input (faster), 0 for normal input (you have to use
27 // read(), input_buf will be NULL)
28 return 1;
29
30 }
31
32