Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Aug 4, 2022
1 parent 6056d4b commit 98e8838
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion frida_mode/hook/frida_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ __attribute__((visibility("default"))) void afl_persistent_hook(
// do a length check matching the target!

void **esp = (void **)regs->esp;
void * arg1 = esp[0];
void *arg1 = esp[0];
void **arg2 = &esp[1];
memcpy(arg1, input_buf, input_buf_len);
*arg2 = (void *)input_buf_len;
Expand Down
2 changes: 1 addition & 1 deletion frida_mode/include/instrument.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extern gboolean instrument_unique;
extern guint64 instrument_hash_zero;
extern char *instrument_coverage_unstable_filename;
extern gboolean instrument_coverage_insn;
extern char * instrument_regs_filename;
extern char *instrument_regs_filename;

extern gboolean instrument_use_fixed_seed;
extern guint64 instrument_fixed_seed;
Expand Down
11 changes: 10 additions & 1 deletion frida_mode/src/instrument/instrument.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ gboolean instrument_use_fixed_seed = FALSE;
guint64 instrument_fixed_seed = 0;
char *instrument_coverage_unstable_filename = NULL;
gboolean instrument_coverage_insn = FALSE;
char * instrument_regs_filename = NULL;
char *instrument_regs_filename = NULL;

static GumStalkerTransformer *transformer = NULL;

Expand Down Expand Up @@ -237,9 +237,12 @@ static void instrument_basic_block(GumStalkerIterator *iterator,
}

if (unlikely(instrument_regs_filename != NULL)) {

gum_stalker_iterator_put_callout(iterator, instrument_write_regs,
(void *)(size_t)regs_fd, NULL);

}

}

}
Expand Down Expand Up @@ -274,6 +277,7 @@ static void instrument_basic_block(GumStalkerIterator *iterator,
instrument_flush(output);
instrument_debug_end(output);
instrument_coverage_end(instr->address + instr->size);

}

void instrument_config(void) {
Expand Down Expand Up @@ -404,6 +408,7 @@ void instrument_init(void) {
instrument_regs_filename == NULL ? " " : instrument_regs_filename);

if (instrument_regs_filename != NULL) {

char *path =
g_canonicalize_filename(instrument_regs_filename, g_get_current_dir());

Expand All @@ -415,6 +420,7 @@ void instrument_init(void) {
if (regs_fd < 0) { FFATAL("Failed to open regs file '%s'", path); }

g_free(path);

}

asan_init();
Expand Down Expand Up @@ -444,6 +450,7 @@ void instrument_on_fork() {
}

void instrument_regs_format(int fd, char *format, ...) {

va_list ap;
char buffer[4096] = {0};
int ret;
Expand All @@ -458,4 +465,6 @@ void instrument_regs_format(int fd, char *format, ...) {
len = strnlen(buffer, sizeof(buffer));

IGNORED_RETURN(write(fd, buffer, len));

}

2 changes: 2 additions & 0 deletions frida_mode/src/instrument/instrument_arm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ void instrument_cache(const cs_insn *instr, GumStalkerOutput *output) {
}

void instrument_write_regs(GumCpuContext *cpu_context, gpointer user_data) {

int fd = (int)user_data;
instrument_regs_format(fd,
"r0 : 0x%08x, r1 : 0x%08x, r2 : 0x%08x, r3 : 0x%08x\n",
Expand All @@ -97,6 +98,7 @@ void instrument_write_regs(GumCpuContext *cpu_context, gpointer user_data) {
fd, "r12: 0x%08x, sp : 0x%08x, lr : 0x%08x, pc : 0x%08x\n",
cpu_context->r12, cpu_context->sp, cpu_context->lr, cpu_context->pc);
instrument_regs_format(fd, "cpsr: 0x%08x\n\n", cpu_context->cpsr);

}

#endif
Expand Down
2 changes: 2 additions & 0 deletions frida_mode/src/instrument/instrument_arm64.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ void instrument_cache(const cs_insn *instr, GumStalkerOutput *output) {
}

void instrument_write_regs(GumCpuContext *cpu_context, gpointer user_data) {

int fd = (int)(size_t)user_data;
instrument_regs_format(
fd, "x0 : 0x%016x, x1 : 0x%016x, x2 : 0x%016x, x3 : 0x%016x\n",
Expand Down Expand Up @@ -440,6 +441,7 @@ void instrument_write_regs(GumCpuContext *cpu_context, gpointer user_data) {
fd, "x28: 0x%016x, fp : 0x%016x, lr : 0x%016x, sp : 0x%016x\n",
cpu_context->x[28], cpu_context->fp, cpu_context->lr, cpu_context->sp);
instrument_regs_format(fd, "pc : 0x%016x\n\n", cpu_context->pc);

}

#endif
Expand Down
2 changes: 2 additions & 0 deletions frida_mode/src/instrument/instrument_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ static void instrument_disasm(guint8 *start, guint8 *end,

count = cs_disasm(capstone, curr, size, GPOINTER_TO_SIZE(curr), 0, &insn);
if (insn == NULL) {

instrument_debug("\t0x%" G_GINT64_MODIFIER "x\t* 0x%016" G_GSIZE_MODIFIER
"x\n",
(uint64_t)(size_t)curr, *(size_t *)curr);

len += sizeof(size_t);
continue;

}

for (i = 0; i != count; i++) {
Expand Down
2 changes: 2 additions & 0 deletions frida_mode/src/instrument/instrument_x64.c
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ gpointer instrument_cur(GumStalkerOutput *output) {
}

void instrument_write_regs(GumCpuContext *cpu_context, gpointer user_data) {

int fd = (int)(size_t)user_data;
instrument_regs_format(
fd, "rax: 0x%016x, rbx: 0x%016x, rcx: 0x%016x, rdx: 0x%016x\n",
Expand All @@ -483,6 +484,7 @@ void instrument_write_regs(GumCpuContext *cpu_context, gpointer user_data) {
fd, "r12: 0x%016x, r13: 0x%016x, r14: 0x%016x, r15: 0x%016x\n",
cpu_context->r12, cpu_context->r13, cpu_context->r14, cpu_context->r15);
instrument_regs_format(fd, "rip: 0x%016x\n\n", cpu_context->rip);

}

#endif
Expand Down
2 changes: 2 additions & 0 deletions frida_mode/src/instrument/instrument_x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ void instrument_cache(const cs_insn *instr, GumStalkerOutput *output) {
}

void instrument_write_regs(GumCpuContext *cpu_context, gpointer user_data) {

int fd = (int)(size_t)user_data;
instrument_regs_format(
fd, "eax: 0x%08x, ebx: 0x%08x, ecx: 0x%08x, edx: 0x%08x\n",
Expand All @@ -279,6 +280,7 @@ void instrument_write_regs(GumCpuContext *cpu_context, gpointer user_data) {
fd, "esi: 0x%08x, edi: 0x%08x, ebp: 0x%08x, esp: 0x%08x\n",
cpu_context->esi, cpu_context->edi, cpu_context->ebp, cpu_context->esp);
instrument_regs_format(fd, "eip: 0x%08x\n\n", cpu_context->eip);

}

#endif
Expand Down
2 changes: 2 additions & 0 deletions frida_mode/src/js/js_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ __attribute__((visibility("default"))) void js_api_set_instrument_no_optimize(

__attribute__((visibility("default"))) void js_api_set_instrument_regs_file(
char *path) {

instrument_regs_filename = g_strdup(path);

}

__attribute__((visibility("default"))) void js_api_set_instrument_seed(
Expand Down

0 comments on commit 98e8838

Please sign in to comment.