Skip to content

Commit

Permalink
Bump project version to 15 for seek history serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
laomaiweng committed Sep 10, 2023
1 parent e1ba294 commit 0172df8
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 3 deletions.
18 changes: 17 additions & 1 deletion librz/core/project_migrate.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ RZ_API bool rz_project_migrate_v12_v13(RzProject *prj, RzSerializeResultInfo *re
// --
// Migration 13 -> 14
//
// Changes from <commit hash not yet known>:
// Changes from 8e29b959b86a35bbbfed599989f077dba6e0ebd5:
// Removed {stack,reg} from "/core/analysis/functions/vars"
// and converted into storage object { ..., storage: { type: ... } }

Expand Down Expand Up @@ -592,6 +592,21 @@ RZ_API bool rz_project_migrate_v13_v14(RzProject *prj, RzSerializeResultInfo *re
return true;
}

// --
// Migration 14 -> 15
//
// Changes from <commit hash not yet known>:
// Added serialization functionality for seek history
// New namespace: /core/seek

RZ_API bool rz_project_migrate_v14_v15(RzProject *prj, RzSerializeResultInfo *res) {
Sdb *core_db;
RZ_SERIALIZE_SUB(prj, core_db, res, "core", return false;);
sdb_ns(core_db, "seek", true);

return true;
}

static bool (*const migrations[])(RzProject *prj, RzSerializeResultInfo *res) = {
rz_project_migrate_v1_v2,
rz_project_migrate_v2_v3,
Expand All @@ -606,6 +621,7 @@ static bool (*const migrations[])(RzProject *prj, RzSerializeResultInfo *res) =
rz_project_migrate_v11_v12,
rz_project_migrate_v12_v13,
rz_project_migrate_v13_v14,
rz_project_migrate_v14_v15,
};

/// Migrate the given project to the current version in-place
Expand Down
5 changes: 4 additions & 1 deletion librz/include/rz_project.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
extern "C" {
#endif

#define RZ_PROJECT_VERSION 14
#define RZ_PROJECT_VERSION 15

typedef Sdb RzProject;

Expand Down Expand Up @@ -57,6 +57,9 @@ RZ_API bool rz_project_migrate_v8_v9(RzProject *prj, RzSerializeResultInfo *res)
RZ_API bool rz_project_migrate_v9_v10(RzProject *prj, RzSerializeResultInfo *res);
RZ_API bool rz_project_migrate_v10_v11(RzProject *prj, RzSerializeResultInfo *res);
RZ_API bool rz_project_migrate_v11_v12(RzProject *prj, RzSerializeResultInfo *res);
RZ_API bool rz_project_migrate_v12_v13(RzProject *prj, RzSerializeResultInfo *res);
RZ_API bool rz_project_migrate_v13_v14(RzProject *prj, RzSerializeResultInfo *res);
RZ_API bool rz_project_migrate_v14_v15(RzProject *prj, RzSerializeResultInfo *res);
RZ_API bool rz_project_migrate(RzProject *prj, unsigned long version, RzSerializeResultInfo *res);

#ifdef __cplusplus
Expand Down
1 change: 1 addition & 0 deletions test/db/cmd/project
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ Detailed project load info:
project migrated from version 11 to 12.
project migrated from version 12 to 13.
project migrated from version 13 to 14.
project migrated from version 14 to 15.
EOF
RUN

Expand Down
48 changes: 47 additions & 1 deletion test/integration/test_project_migrate.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,23 @@ static bool test_migrate_v9_v10_v11_stack_vars_sp() {
mu_end;
}

static bool test_migrate_v14_v15() {
RzProject *prj = rz_project_load_file_raw("prj/v14-float_ex1_hightec.rzdb.gz");
mu_assert_notnull(prj, "load raw project");
RzSerializeResultInfo *res = rz_serialize_result_info_new();
bool s = rz_project_migrate_v14_v15(prj, res);
mu_assert_true(s, "migrate success");

Sdb *core_db = sdb_ns(prj, "core", false);
mu_assert_notnull(core_db, "core ns");
Sdb *seek_db = sdb_ns(core_db, "seek", false);
mu_assert_notnull(seek_db, "seek ns");

rz_serialize_result_info_free(res);
rz_project_free(prj);
mu_end;
}

/// Load project of given version from file into core and check the log for migration success messages
#define BEGIN_LOAD_TEST(core, version, file) \
do { \
Expand Down Expand Up @@ -845,7 +862,6 @@ static bool test_load_v9_v10_stack_vars_sp(int version, const char *prj_file) {

rz_core_free(core);
mu_end;
mu_end;
}

static bool test_load_v12() {
Expand Down Expand Up @@ -877,6 +893,34 @@ static bool test_load_v14() {
mu_end;
}

static bool test_load_v15_seek_history() {
RzCore *core = rz_core_new();

// enable the cursor so we can check the deserialized value
rz_print_set_cursor(core->print, true, 0, 0);

BEGIN_LOAD_TEST(core, 15, "prj/v15-seek-history.rzdb");

mu_assert_eq(rz_vector_len(&core->seek_history.undos), 1, "bad number of undos");
RzCoreSeekItem *item = rz_vector_index_ptr(&core->seek_history.undos, 0);
mu_assert_eq(item->offset, 0x5ae0, "bad undo offset");
mu_assert_eq(item->cursor, 1, "bad undo cursor");

mu_assert_eq(rz_vector_len(&core->seek_history.redos), 2, "bad number of redos");
item = rz_vector_index_ptr(&core->seek_history.redos, 1);
mu_assert_eq(item->offset, 0x5b00, "bad first redo offset");
mu_assert_eq(item->cursor, 3, "bad first redo cursor");
item = rz_vector_index_ptr(&core->seek_history.redos, 0);
mu_assert_eq(item->offset, 0x5b10, "bad second redo offset");
mu_assert_eq(item->cursor, 4, "bad second redo cursor");

// core offset not restored from current seek history item, so not checked
mu_assert_eq(rz_print_get_cursor(core->print), 2, "bad current cursor");

rz_core_free(core);
mu_end;
}

int all_tests() {
mu_run_test(test_migrate_v1_v2_noreturn);
mu_run_test(test_migrate_v1_v2_noreturn_empty);
Expand All @@ -894,6 +938,7 @@ int all_tests() {
mu_run_test(test_migrate_v9_v10_v11_stack_vars_bp);
mu_run_test(test_migrate_v9_v10_v11_stack_vars_sp);
mu_run_test(test_migrate_v2_v12);
mu_run_test(test_migrate_v14_v15);
mu_run_test(test_load_v1_noreturn);
mu_run_test(test_load_v1_noreturn_empty);
mu_run_test(test_load_v1_unknown_type);
Expand All @@ -913,6 +958,7 @@ int all_tests() {
mu_run_test(test_load_v9_v10_stack_vars_sp, 10, "prj/v10-sp-vars.rzdb");
mu_run_test(test_load_v12);
mu_run_test(test_load_v14);
mu_run_test(test_load_v15_seek_history);
return tests_passed != tests_run;
}

Expand Down
86 changes: 86 additions & 0 deletions test/prj/v15-seek-history.rzdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/
type=rizin rz-db project
version=15

/core
blocksize=0x100
offset=0x5af0

/core/analysis

/core/analysis/blocks

/core/analysis/callables

/core/analysis/cc

/core/analysis/classes

/core/analysis/classes/attrs

/core/analysis/functions

/core/analysis/hints

/core/analysis/imports

/core/analysis/meta

/core/analysis/meta/spaces
name=CS
spacestack=["*"]

/core/analysis/meta/spaces/spaces
bin=s

/core/analysis/noreturn

/core/analysis/types

/core/analysis/vars

/core/analysis/xrefs

/core/config
asm.arch=x86
asm.bits=64
cfg.seek.histsize=63
cfg.seek.silent=false
cfg.wseek=false
prj.compress=false
prj.file=./test/prj/v15-seek-history.rzdb

/core/debug

/core/debug/breakpoints

/core/file
relative=../bins/elf/ls

/core/flags
base=0
realnames=0

/core/flags/flags

/core/flags/spaces
name=fs
spacestack=["*"]

/core/flags/spaces/spaces
classes=s
relocs=s
sections=s
segments=s
strings=s
symbols=s

/core/flags/tags

/core/flags/zones

/core/seek
-1={"offset":23264,"cursor":1,"current":false}
0={"offset":23280,"cursor":2,"current":true}
1={"offset":23296,"cursor":3,"current":false}
2={"offset":23312,"cursor":4,"current":false}

0 comments on commit 0172df8

Please sign in to comment.