Use API instead of the direct use of pdb command (#3855)
This commit is contained in:
parent
7a50bd7e5a
commit
a66b6c76c1
2 changed files with 48 additions and 2 deletions
|
|
@ -233,7 +233,29 @@ RZ_API RZ_OWN RzGraph /*<RzGraphNodeInfo *>*/ *rz_core_graph_callgraph(RZ_NONNUL
|
|||
typedef char *(*GraphBodyFn)(RzCore *core, ut64 addr, RzAnalysisBlock *bb);
|
||||
|
||||
static inline char *block_disasm(RzCore *core, ut64 addr, RzAnalysisBlock *bb) {
|
||||
return rz_core_cmd_strf(core, "pdb @ 0x%" PFMT64x, addr);
|
||||
RzAnalysisBlock *b = rz_analysis_find_most_relevant_block_in(core->analysis, addr);
|
||||
if (!b) {
|
||||
RZ_LOG_ERROR("Cannot find function at 0x%08" PFMT64x "\n", addr);
|
||||
return NULL;
|
||||
}
|
||||
ut8 *block = malloc(b->size + 1);
|
||||
if (!block) {
|
||||
RZ_LOG_ERROR("Cannot allocate buffer\n");
|
||||
return NULL;
|
||||
}
|
||||
rz_cons_push();
|
||||
rz_io_read_at(core->io, b->addr, block, b->size);
|
||||
RzCoreDisasmOptions disasm_options = {
|
||||
.cbytes = 2,
|
||||
};
|
||||
rz_core_print_disasm(core, b->addr, block, b->size, 9999, NULL, &disasm_options);
|
||||
rz_cons_filter();
|
||||
const char *retstr = rz_str_get(rz_cons_get_buffer());
|
||||
char *opcodes = strdup(retstr);
|
||||
rz_cons_pop();
|
||||
rz_cons_echo(NULL);
|
||||
free(block);
|
||||
return opcodes;
|
||||
}
|
||||
|
||||
static inline RzGraphNode *graph_add_cached(RzCore *core, HtUP *cache, RzAnalysisBlock *bb, ut64 offset, RzGraph /*<RzGraphNodeInfo *>*/ *graph, GraphBodyFn body_fn) {
|
||||
|
|
|
|||
|
|
@ -1467,6 +1467,7 @@ static void print_color_node(RzCore *core, RzAnalysisBlock *bbi) {
|
|||
static char *basic_block_opcodes(RzCore *core, RzAnalysisBlock *bbi) {
|
||||
char *opcodes = NULL;
|
||||
RzConfigHold *hc = NULL;
|
||||
ut8 *block = NULL;
|
||||
|
||||
if (!(hc = rz_config_hold_new(core->config))) {
|
||||
return NULL;
|
||||
|
|
@ -1481,8 +1482,31 @@ static char *basic_block_opcodes(RzCore *core, RzAnalysisBlock *bbi) {
|
|||
rz_config_set_i(core->config, "asm.comments", 0);
|
||||
rz_config_set_i(core->config, "scr.color", COLOR_MODE_DISABLED);
|
||||
|
||||
opcodes = rz_core_cmd_strf(core, "pdb @ 0x%08" PFMT64x, bbi->addr);
|
||||
rz_cons_push();
|
||||
RzAnalysisBlock *b = rz_analysis_find_most_relevant_block_in(core->analysis, bbi->addr);
|
||||
if (!b) {
|
||||
RZ_LOG_ERROR("Cannot find function at 0x%08" PFMT64x "\n", bbi->addr);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
block = malloc(b->size + 1);
|
||||
if (!block) {
|
||||
RZ_LOG_ERROR("Cannot allocate buffer\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
rz_io_read_at(core->io, b->addr, block, b->size);
|
||||
RzCoreDisasmOptions disasm_options = {
|
||||
.cbytes = 2,
|
||||
};
|
||||
rz_core_print_disasm(core, b->addr, block, b->size, 9999, NULL, &disasm_options);
|
||||
rz_cons_filter();
|
||||
const char *retstr = rz_str_get(rz_cons_get_buffer());
|
||||
opcodes = strdup(retstr);
|
||||
exit:
|
||||
rz_cons_pop();
|
||||
rz_cons_echo(NULL);
|
||||
free(block);
|
||||
rz_config_hold_restore(hc);
|
||||
rz_config_hold_free(hc);
|
||||
return opcodes;
|
||||
|
|
|
|||
Loading…
Reference in a new issue