Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix libafl_qemu_read_reg and libafl_qemu_write_reg #71

Merged
merged 1 commit into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions cpu-target.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@

//// --- Begin LibAFL code ---

#include "exec/gdbstub.h"

#include "libafl/exit.h"
#include "libafl/hook.h"

int gdb_write_register(CPUState *cpu, uint8_t *mem_buf, int reg);

static __thread GByteArray *libafl_qemu_mem_buf = NULL;

target_ulong libafl_page_from_addr(target_ulong addr);
Expand Down Expand Up @@ -128,29 +132,26 @@ int libafl_qemu_cpu_index(CPUState* cpu)

int libafl_qemu_write_reg(CPUState* cpu, int reg, uint8_t* val)
{
CPUClass *cc = CPU_GET_CLASS(cpu);
if (reg < cc->gdb_num_core_regs) {
return cc->gdb_write_register(cpu, val, reg);
}
return 0;
return gdb_write_register(cpu, val, reg);
}

int libafl_qemu_read_reg(CPUState* cpu, int reg, uint8_t* val)
{
int len;

if (libafl_qemu_mem_buf == NULL) {
libafl_qemu_mem_buf = g_byte_array_sized_new(64);
}

CPUClass *cc = CPU_GET_CLASS(cpu);
if (reg < cc->gdb_num_core_regs) {
g_byte_array_set_size(libafl_qemu_mem_buf, 0);
int len = cc->gdb_read_register(cpu, libafl_qemu_mem_buf, reg);
if (len > 0) {
memcpy(val, libafl_qemu_mem_buf->data, len);
}
return len;
g_byte_array_set_size(libafl_qemu_mem_buf, 0);

len = gdb_read_register(cpu, libafl_qemu_mem_buf, reg);

if (len > 0) {
memcpy(val, libafl_qemu_mem_buf->data, len);
}
return 0;

return len;
}

int libafl_qemu_num_regs(CPUState* cpu)
Expand Down
7 changes: 6 additions & 1 deletion gdbstub/gdbstub.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,12 @@ int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg)
return 0;
}

static int gdb_write_register(CPUState *cpu, uint8_t *mem_buf, int reg)

//// --- Begin LibAFL code ---
int gdb_write_register(CPUState *cpu, uint8_t *mem_buf, int reg);
/* static */
//// --- End LibAFL code ---
int gdb_write_register(CPUState *cpu, uint8_t *mem_buf, int reg)
{
CPUClass *cc = CPU_GET_CLASS(cpu);
GDBRegisterState *r;
Expand Down
Loading