Skip to content

Commit

Permalink
Split rz_core_pdb_info_print function to make it clear
Browse files Browse the repository at this point in the history
  • Loading branch information
Basstorm committed Oct 8, 2021
1 parent 2dcf80b commit cc13b06
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 18 deletions.
13 changes: 11 additions & 2 deletions librz/core/cbin.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,12 @@ RZ_API bool rz_core_bin_print(RzCore *core, RzBinFile *bf, ut32 mask, RzCoreBinF
if (mask & RZ_CORE_BIN_ACC_PDB) {
if (state->mode & (RZ_OUTPUT_MODE_STANDARD | RZ_OUTPUT_MODE_JSON | RZ_OUTPUT_MODE_RIZIN)) {
RzCmdStateOutput *st = add_header(state, RZ_OUTPUT_MODE_STANDARD, "pdb");
rz_core_pdb_info_print(core, core->bin->file, st);
RzPdb *pdb = rz_core_pdb_load_info(core, core->bin->file);
if (!pdb) {
return false;
}
rz_core_pdb_info_print(core, core->analysis->typedb, pdb, st);
rz_bin_pdb_free(pdb);
add_footer(state, st);
}
}
Expand Down Expand Up @@ -5133,7 +5138,11 @@ RZ_API bool rz_core_bin_archs_print(RzBin *bin, RzCmdStateOutput *state) {

RZ_API bool rz_core_bin_pdb_load(RZ_NONNULL RzCore *core, RZ_NONNULL const char *filename) {
rz_cons_push();
rz_core_pdb_info_print(core, filename, NULL);
RzPdb *pdb = rz_core_pdb_load_info(core, filename);
if (!pdb) {
return false;
}
rz_bin_pdb_free(pdb);
const char *buf = rz_cons_get_buffer();
if (!buf) {
rz_cons_pop();
Expand Down
8 changes: 6 additions & 2 deletions librz/core/cmd_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,12 @@ RZ_IPI RzCmdStatus rz_cmd_info_pdb_show_handler(RzCore *core, int argc, const ch
free(filename);
return RZ_CMD_STATUS_ERROR;
}

rz_core_pdb_info_print(core, filename, state);
RzPdb *pdb = rz_core_pdb_load_info(core, filename);
if (!pdb) {
return false;
}
rz_core_pdb_info_print(core, core->analysis->typedb, pdb, state);
rz_bin_pdb_free(pdb);
free(filename);
return RZ_CMD_STATUS_OK;
}
Expand Down
43 changes: 30 additions & 13 deletions librz/core/cpdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,14 @@ static void pdb_set_symbols(const RzCore *core, const RzPdb *pdb, const ut64 img
}

/**
* \brief Print parsed PDB file info and integrate with typedb
* \brief Parse PDB file info and integrate with typedb
*
* \param core RzCore instance
* \param file Path of PDB file
* \param state Output State
* \return bool
*/
RZ_API bool rz_core_pdb_info_print(RzCore *core, const char *file, RzCmdStateOutput *state) {
rz_return_val_if_fail(core && file, false);
RZ_API RzPdb *rz_core_pdb_load_info(RZ_NONNULL RzCore *core, RZ_NONNULL const char *file) {
rz_return_val_if_fail(core && file, NULL);

ut64 baddr = rz_config_get_i(core->config, "bin.baddr");
if (core->bin->cur && core->bin->cur->o && core->bin->cur->o->opts.baseaddr) {
Expand All @@ -236,18 +235,36 @@ RZ_API bool rz_core_pdb_info_print(RzCore *core, const char *file, RzCmdStateOut

RzPdb *pdb = rz_bin_pdb_parse_from_file(file);
if (!pdb) {
return false;
return NULL;
}

// Save compound types into types database
rz_parse_pdb_types(core->analysis->typedb, pdb);
if (state) {
rz_cmd_state_output_array_start(state);
rz_core_bin_pdb_types_print(core->analysis->typedb, pdb, state);
rz_core_bin_pdb_gvars_print(pdb, baddr, state);
rz_cmd_state_output_array_end(state);
}
pdb_set_symbols(core, pdb, baddr);
rz_bin_pdb_free(pdb);
return true;
return pdb;
}

/**
* \brief Print parsed PDB file info
*
* \param db RzTypeDB
* \param pdb instance of PDB
* \param state Output State
* \return void
*/
RZ_API void rz_core_pdb_info_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzTypeDB *db, RZ_NONNULL RzPdb *pdb, RZ_NONNULL RzCmdStateOutput *state) {
rz_return_if_fail(db && pdb && state);

ut64 baddr = rz_config_get_i(core->config, "bin.baddr");
if (core->bin->cur && core->bin->cur->o && core->bin->cur->o->opts.baseaddr) {
baddr = core->bin->cur->o->opts.baseaddr;
} else {
eprintf("Warning: Cannot find base address, flags will probably be misplaced\n");
}

rz_cmd_state_output_array_start(state);
rz_core_bin_pdb_types_print(core->analysis->typedb, pdb, state);
rz_core_bin_pdb_gvars_print(pdb, baddr, state);
rz_cmd_state_output_array_end(state);
return;
}
3 changes: 2 additions & 1 deletion librz/include/rz_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,8 @@ RZ_API RZ_OWN char *rz_core_bin_field_build_flag_name(RZ_NONNULL RzBinClass *cls
RZ_API char *rz_core_bin_method_flags_str(ut64 flags, int mode);
RZ_API RZ_OWN char *rz_core_bin_pdb_get_filename(RZ_NONNULL RzCore *core);
RZ_API bool rz_core_bin_pdb_load(RZ_NONNULL RzCore *core, RZ_NONNULL const char *filename);
RZ_API bool rz_core_pdb_info_print(RzCore *core, const char *file, RzCmdStateOutput *state);
RZ_API RzPdb *rz_core_pdb_load_info(RZ_NONNULL RzCore *core, RZ_NONNULL const char *file);
RZ_API void rz_core_pdb_info_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzTypeDB *db, RZ_NONNULL RzPdb *pdb, RZ_NONNULL RzCmdStateOutput *state);
RZ_API RzCmdStatus rz_core_bin_plugins_print(RzBin *bin, RzCmdStateOutput *state);

RZ_API bool rz_core_bin_archs_print(RZ_NONNULL RzBin *bin, RZ_NONNULL RzCmdStateOutput *state);
Expand Down

0 comments on commit cc13b06

Please sign in to comment.