Skip to content

Commit

Permalink
Fix linking error of windows_heap.c
Browse files Browse the repository at this point in the history
  • Loading branch information
Basstorm committed Oct 9, 2021
1 parent da3deb9 commit cc2fdda
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
42 changes: 32 additions & 10 deletions librz/core/cpdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,26 +116,34 @@ static void rz_core_bin_pdb_types_print(const RzTypeDB *db, const RzPdb *pdb, co
}
}

static void rz_core_bin_pdb_gvars_print(const RzPdb *pdb, const ut64 img_base, const RzCmdStateOutput *state) {
rz_return_if_fail(pdb && state);
/**
* \brief Return the PDB global vars string
*
* \param pdb PDB instance
* \param img_base image base addr
* \param pj JSON instance
* \param mode RzOutputMode
* \return char *
*/
RZ_API char *rz_core_bin_pdb_gvars_as_string(RZ_NONNULL const RzPdb *pdb, const ut64 img_base, PJ *pj, const RzOutputMode mode) {
rz_return_val_if_fail(pdb, NULL);
PeImageSectionHeader *sctn_header = 0;
RzPdbGDataStream *gsym_data_stream = 0;
RzPdbPeStream *pe_stream = 0;
RzPdbOmapStream *omap_stream;
GDataGlobal *gdata = 0;
RzListIter *it = 0;
PJ *pj = state->d.pj;
char *name;
RzStrBuf *buf = rz_strbuf_new(NULL);
if (!buf) {
return;
return NULL;
}
RzStrBuf *cmd = rz_strbuf_new(NULL);
if (!cmd) {
rz_strbuf_free(buf);
return;
return NULL;
}
if (state->mode == RZ_OUTPUT_MODE_JSON) {
if (mode == RZ_OUTPUT_MODE_JSON) {
pj_o(pj);
pj_ka(pj, "gvars");
}
Expand All @@ -144,14 +152,14 @@ static void rz_core_bin_pdb_gvars_print(const RzPdb *pdb, const ut64 img_base, c
omap_stream = pdb->s_omap;
if (!pe_stream) {
rz_strbuf_free(buf);
return;
return NULL;
}
rz_list_foreach (gsym_data_stream->global_list, it, gdata) {
sctn_header = rz_list_get_n(pe_stream->sections_hdrs, (gdata->segment - 1));
if (sctn_header) {
name = rz_demangler_msvc(gdata->name);
name = (name) ? name : strdup(gdata->name);
switch (state->mode) {
switch (mode) {
case RZ_OUTPUT_MODE_JSON: // JSON
pj_o(pj);
pj_kN(pj, "address", (img_base + rz_bin_pdb_omap_remap(omap_stream, gdata->offset + sctn_header->virtual_address)));
Expand All @@ -171,12 +179,26 @@ static void rz_core_bin_pdb_gvars_print(const RzPdb *pdb, const ut64 img_base, c
free(name);
}
}
if (state->mode == RZ_OUTPUT_MODE_JSON) {
if (mode == RZ_OUTPUT_MODE_JSON) {
pj_end(pj);
pj_end(pj);
// We will need this for Windows Heap.
rz_strbuf_append(buf, pj_string(pj));
}
rz_cons_print(rz_strbuf_get(buf));
char *str = rz_strbuf_get(buf);
rz_strbuf_free(buf);
return str;
}

static void rz_core_bin_pdb_gvars_print(const RzPdb *pdb, const ut64 img_base, const RzCmdStateOutput *state) {
rz_return_if_fail(pdb && state);
char *str = rz_core_bin_pdb_gvars_as_string(pdb, img_base, state->d.pj, state->mode);
// We don't need to print the output of JSON because the RzCmdStateOutput will handle it.
if (state->mode == RZ_OUTPUT_MODE_STANDARD) {
rz_cons_print(str);
}
free(str);
return;
}

static void pdb_set_symbols(const RzCore *core, const RzPdb *pdb, const ut64 img_base) {
Expand Down
10 changes: 9 additions & 1 deletion librz/core/windows_heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,18 +347,26 @@ static bool GetHeapGlobalsOffset(RzDebug *dbg, HANDLE h_proc) {
} else {
eprintf("Warning: Cannot find base address, flags will probably be misplaced\n");
}
char *j = rz_bin_pdb_gvars_as_string(pdb, baddr, RZ_OUTPUT_MODE_JSON);
PJ *pj = pj_new();
if (!pj) {
rz_bin_pdb_free(pdb);
goto fail;
}
char *j = rz_core_bin_pdb_gvars_as_string(pdb, baddr, pj, RZ_OUTPUT_MODE_JSON);
if (!j) {
rz_bin_pdb_free(pdb);
pj_free(pj);
goto fail;
}
pj_free(pj);
rz_bin_pdb_free(pdb);
RzJson *json = rz_json_parse(j);
if (!json) {
RZ_LOG_ERROR("rz_core_pdb_info returned invalid JSON");
free(j);
goto fail;
}
free(j);

// Go through gvars array and search for the heap globals symbols
const RzJson *gvars = rz_json_get(json, "gvars");
Expand Down
1 change: 1 addition & 0 deletions librz/include/rz_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@ 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 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 char *rz_core_bin_pdb_gvars_as_string(RZ_NONNULL const RzPdb *pdb, const ut64 img_base, PJ *pj, const RzOutputMode mode);
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 cc2fdda

Please sign in to comment.