From 0172df8be7d436645ccb598a10e4d7b51e44aba1 Mon Sep 17 00:00:00 2001 From: quentin Date: Thu, 7 Sep 2023 19:40:48 +0200 Subject: [PATCH] Bump project version to 15 for seek history serialization --- librz/core/project_migrate.c | 18 +++++- librz/include/rz_project.h | 5 +- test/db/cmd/project | 1 + test/integration/test_project_migrate.c | 48 +++++++++++++- test/prj/v15-seek-history.rzdb | 86 +++++++++++++++++++++++++ 5 files changed, 155 insertions(+), 3 deletions(-) create mode 100644 test/prj/v15-seek-history.rzdb diff --git a/librz/core/project_migrate.c b/librz/core/project_migrate.c index 3a61bf94c11..579a2ae0588 100644 --- a/librz/core/project_migrate.c +++ b/librz/core/project_migrate.c @@ -533,7 +533,7 @@ RZ_API bool rz_project_migrate_v12_v13(RzProject *prj, RzSerializeResultInfo *re // -- // Migration 13 -> 14 // -// Changes from : +// Changes from 8e29b959b86a35bbbfed599989f077dba6e0ebd5: // Removed {stack,reg} from "/core/analysis/functions/vars" // and converted into storage object { ..., storage: { type: ... } } @@ -592,6 +592,21 @@ RZ_API bool rz_project_migrate_v13_v14(RzProject *prj, RzSerializeResultInfo *re return true; } +// -- +// Migration 14 -> 15 +// +// Changes from : +// 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, @@ -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 diff --git a/librz/include/rz_project.h b/librz/include/rz_project.h index 412834257bb..59ad94642cb 100644 --- a/librz/include/rz_project.h +++ b/librz/include/rz_project.h @@ -12,7 +12,7 @@ extern "C" { #endif -#define RZ_PROJECT_VERSION 14 +#define RZ_PROJECT_VERSION 15 typedef Sdb RzProject; @@ -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 diff --git a/test/db/cmd/project b/test/db/cmd/project index 27f865d5ae2..f2e21eec02c 100644 --- a/test/db/cmd/project +++ b/test/db/cmd/project @@ -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 diff --git a/test/integration/test_project_migrate.c b/test/integration/test_project_migrate.c index ab21cffb0f3..8dcb41a252e 100644 --- a/test/integration/test_project_migrate.c +++ b/test/integration/test_project_migrate.c @@ -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 { \ @@ -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() { @@ -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); @@ -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); @@ -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; } diff --git a/test/prj/v15-seek-history.rzdb b/test/prj/v15-seek-history.rzdb new file mode 100644 index 00000000000..71fbd8c21f7 --- /dev/null +++ b/test/prj/v15-seek-history.rzdb @@ -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}