Skip to content

Commit

Permalink
test/integration/open: check base address (#4597)
Browse files Browse the repository at this point in the history
  • Loading branch information
XVilka authored Aug 29, 2024
1 parent 5780411 commit 9c5e97d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
9 changes: 9 additions & 0 deletions librz/core/cfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,15 @@ static bool map_multi_dex(RzCore *core, RzIODesc *desc, ut32 id) {
return true;
}

/**
* \brief Load the binary specified by the \p filenameuri URI using \p baddr base address
*
* \param core A pointer to the `RzCore` object used for opening file into
* \param filenameuri A file name/path or any other URI supported by Rizin
* \param baddr The base address to use for loading. UT64_MAX value enables autodetection
*
* \return true if loading successfully completed, false otherwise.
*/
RZ_API bool rz_core_bin_load(RZ_NONNULL RzCore *r, RZ_NULLABLE const char *filenameuri, ut64 baddr) {
rz_return_val_if_fail(r, false);

Expand Down
13 changes: 7 additions & 6 deletions test/integration/test_open_analyse_save_load_project.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,23 @@ bool test_open_analyse_save() {
// 1. Open the file
RzCore *core = rz_core_new();
mu_assert_notnull(core, "new RzCore instance");
ut64 loadaddr = 0;
const char *fpath = "bins/elf/ls";
RzCoreFile *file = rz_core_file_open(core, fpath, RZ_PERM_R, loadaddr);
const char *fpath = "bins/elf/dectest32";
RzCoreFile *file = rz_core_file_open(core, fpath, RZ_PERM_R, 0);
mu_assert_notnull(file, "open file");
rz_core_bin_load(core, fpath, loadaddr);
rz_core_bin_load(core, fpath, UT64_MAX);

ut64 loadaddr = rz_config_get_i(core->config, "bin.baddr");
mu_assert_eq(loadaddr, 0x08048000, "base address");

// 2. Analyse the file
rz_core_analysis_all(core);
rz_core_analysis_everything(core, false, "esil");

RzList *functionsold = rz_analysis_function_list(core->analysis);
mu_assert_notnull(functionsold, "export functions list");
eprintf("functions count = %d\n", rz_list_length(functionsold));

// 3. Remove the function
const char *fcnname = "fcn.0000ebe0";
const char *fcnname = "sym.Aeropause";
RzAnalysisFunction *fcn = rz_analysis_get_function_byname(core->analysis, fcnname);
mu_assert_notnull(fcn, "find function");
rz_analysis_function_delete(fcn);
Expand Down

0 comments on commit 9c5e97d

Please sign in to comment.