Skip to content

Commit

Permalink
Better typed syx snapshot check result (AFLplusplus#74)
Browse files Browse the repository at this point in the history
* better typed snapshot check

* edit compile_commands.json to use the real compiler
  • Loading branch information
rmalmain authored May 22, 2024
1 parent 9f3e239 commit 9d2197b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
6 changes: 5 additions & 1 deletion include/libafl/syx-snapshot/syx-snapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ typedef struct SyxSnapshotState {
// Root
} SyxSnapshotState;

typedef struct SyxSnapshotCheckResult {
uint64_t nb_inconsistencies;
} SyxSnapshotCheckResult;

void syx_snapshot_init(bool cached_bdrvs);

//
Expand All @@ -71,7 +75,7 @@ void syx_snapshot_free(SyxSnapshot *snapshot);

void syx_snapshot_root_restore(SyxSnapshot *snapshot);

uint64_t syx_snapshot_check_memory_consistency(SyxSnapshot *snapshot);
SyxSnapshotCheckResult syx_snapshot_check(SyxSnapshot* ref_snapshot);

// Push the current RAM state and saves it
void syx_snapshot_increment_push(SyxSnapshot *snapshot, DeviceSnapshotKind kind, char **devices);
Expand Down
16 changes: 11 additions & 5 deletions libafl/syx-snapshot/syx-snapshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,6 @@ static void root_restore_check_memory_rb(gpointer rb_idstr_hash, gpointer rb_dir
SyxSnapshot *snapshot = args->snapshot;
RAMBlock *rb = ramblock_lookup(rb_idstr_hash);

args->nb_inconsistent_pages = 0;
if (rb) {
SYX_PRINTF("Checking memory consistency of %s... ", rb->idstr);
SyxSnapshotRAMBlock *rb_snapshot = g_hash_table_lookup(snapshot->root_snapshot->rbs_snapshot, rb_idstr_hash);
Expand Down Expand Up @@ -610,12 +609,19 @@ static void root_restore_check_memory_rb(gpointer rb_idstr_hash, gpointer rb_dir
}
}

uint64_t syx_snapshot_check_memory_consistency(SyxSnapshot *snapshot) {
SyxSnapshotCheckResult syx_snapshot_check(SyxSnapshot* ref_snapshot) {
struct rb_check_memory_args args = {
.snapshot = snapshot
.snapshot = ref_snapshot,
.nb_inconsistent_pages = 0,
};
g_hash_table_foreach(snapshot->rbs_dirty_list, root_restore_check_memory_rb, &args);
return args.nb_inconsistent_pages;

g_hash_table_foreach(ref_snapshot->rbs_dirty_list, root_restore_check_memory_rb, &args);

struct SyxSnapshotCheckResult res = {
.nb_inconsistencies = args.nb_inconsistent_pages
};

return res;
}

void syx_snapshot_root_restore(SyxSnapshot *snapshot) {
Expand Down
15 changes: 15 additions & 0 deletions linker_interceptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@
rpath_pattern = r"^'.*,-rpath,(.*)'$"
rpath_link_pattern = r"^.*,-rpath-link,(.*)$"

linker_interceptor_pattern = r"(\": \")(.*linker_interceptor.py)( )"
linker_interceptorpp_pattern = r"(\": \")(.*linker_interceptor\+\+.py)( )"

def fix_compile_commands():
with open("compile_commands.json", 'r') as f:
compile_commands = f.read()

res = re.sub(linker_interceptor_pattern, rf"\g<1>{CC}\g<3>", compile_commands)
res = re.sub(linker_interceptorpp_pattern, rf"\g<1>{CXX}\g<3>", res)

with open("compile_commands.json", 'w') as f:
f.write(res)

def process_args(args):
global out_args, shareds, search, is_linking_qemu
prev_o = False
Expand Down Expand Up @@ -75,6 +88,8 @@ def process_args(args):
for entry in compile_commands:
sources.append(entry["file"])

fix_compile_commands()

with open(OUT, 'w') as f:
json.dump({
'cmd': out_args,
Expand Down

0 comments on commit 9d2197b

Please sign in to comment.