From 209d0b1e69919ac80a21eba0add29cc1c5847811 Mon Sep 17 00:00:00 2001 From: Sidhub723 Date: Sun, 2 Apr 2023 14:30:07 +0530 Subject: [PATCH 1/9] Finding exact location of printing cmds --- librz/core/cconfig.c | 1 + librz/core/disasm.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/librz/core/cconfig.c b/librz/core/cconfig.c index 98290f44fec..4a9274a114b 100644 --- a/librz/core/cconfig.c +++ b/librz/core/cconfig.c @@ -3032,6 +3032,7 @@ RZ_API int rz_core_config_init(RzCore *core) { SETBPREF("asm.dwarf", "false", "Show dwarf comment at disassembly"); SETBPREF("asm.dwarf.abspath", "false", "Show absolute path in asm.dwarf"); SETBPREF("asm.dwarf.file", "true", "Show filename of asm.dwarf in pd"); + SETBPREF("asm.dwarf.lines","false","Show DWARF source line information at disassembly"); SETBPREF("asm.esil", "false", "Show ESIL instead of mnemonic"); SETBPREF("asm.nodup", "false", "Do not show dupped instructions (collapse disasm)"); SETBPREF("asm.emu", "false", "Run ESIL emulation analysis on disasm"); diff --git a/librz/core/disasm.c b/librz/core/disasm.c index 5dcb3f0daac..4b971fd5434 100644 --- a/librz/core/disasm.c +++ b/librz/core/disasm.c @@ -292,6 +292,7 @@ typedef struct { int _tabsoff; bool dwarfFile; bool dwarfAbspath; + bool dwarfShowLines; bool showpayloads; bool showrelocs; int cmtcount; @@ -721,6 +722,7 @@ static RzDisasmState *ds_init(RzCore *core) { ds->show_dwarf = rz_config_get_b(core->config, "asm.dwarf"); ds->dwarfFile = rz_config_get_b(ds->core->config, "asm.dwarf.file"); ds->dwarfAbspath = rz_config_get_b(ds->core->config, "asm.dwarf.abspath"); + ds->dwarfShowLines = rz_config_get_b(ds->core->config,"asm.dwarf.lines"); ds->show_lines_call = ds->show_lines ? rz_config_get_b(core->config, "asm.lines.call") : false; ds->show_lines_ret = ds->show_lines ? rz_config_get_b(core->config, "asm.lines.ret") : false; ds->show_size = rz_config_get_b(core->config, "asm.size"); @@ -3436,6 +3438,7 @@ static void ds_print_indent(RzDisasmState *ds) { } static void ds_print_optype(RzDisasmState *ds) { + // rz_cons_println("Line number 3441,inside ds_print_optype"); if (ds->show_optype) { const char *optype = rz_analysis_optype_to_string(ds->analysis_op.type); ds_print_color_reset(ds); @@ -3445,6 +3448,7 @@ static void ds_print_optype(RzDisasmState *ds) { } static void ds_print_opstr(RzDisasmState *ds) { + // rz_cons_println("Line number 3451,inside ds_print_opstr "); ds_print_indent(ds); if (ds->asm_instr) { rz_cons_strcat(ds->opstr); @@ -3602,13 +3606,16 @@ static int ds_print_shortcut(RzDisasmState *ds, ut64 addr, int pos) { if (shortcut) { if (ds->core->is_asmqjmps_letter) { rz_cons_printf("%s[o%s]", ch, shortcut); + rz_cons_println("Line 3606"); slen++; } else { rz_cons_printf("%s[%s]", ch, shortcut); + rz_cons_println("Line 3611"); } free(shortcut); } else { rz_cons_printf("%s[?]", ch); + rz_cons_println("Line 3616"); } if (ds->show_color) { if (ds->core->print->resetbg) { @@ -3665,6 +3672,7 @@ static bool ds_print_core_vmode(RzDisasmState *ds, int pos) { RzCore *core = ds->core; bool gotShortcut = false; int i, slen = 0; + // rz_cons_println("Line number 3673 in print_core_vmode"); if (!core->vmode) { return false; @@ -3812,6 +3820,7 @@ static void ds_align_comment(RzDisasmState *ds) { } static void ds_print_dwarf(RzDisasmState *ds) { + // rz_cons_println("Line number 3823,inside ds_print_dwarf "); if (ds->show_dwarf) { // TODO: cache value in ds int dwarfFile = (int)ds->dwarfFile + (int)ds->dwarfAbspath; @@ -4602,6 +4611,7 @@ static void ds_pre_emulation(RzDisasmState *ds) { } static void ds_print_esil_analysis_init(RzDisasmState *ds) { + // rz_cons_println("Line 4611 in esil_analysis_init"); RzCore *core = ds->core; const char *pc = rz_reg_get_name(core->analysis->reg, RZ_REG_NAME_PC); if (!pc) { @@ -5263,6 +5273,7 @@ static void ds_start_line_highlight(RzDisasmState *ds) { } static void ds_end_line_highlight(RzDisasmState *ds) { + // rz_cons_println("Line number 5275,inside ds_end_line_highlight "); if (ds->show_color && line_highlighted(ds)) { rz_cons_strcat(Color_RESET); } @@ -5393,8 +5404,11 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u if (!ds->l) { ds->l = core->blocksize; } + // rz_cons_println("Line number 5403, in core_print_disasm"); rz_cons_break_push(NULL, NULL); + // rz_cons_println("Line number 5405, in core_print_disasm"); for (idx = ret = 0; addrbytes * idx < len && ds->lines < ds->l; idx += inc, ds->index += inc, ds->lines++) { + // rz_cons_println("Line number 5403, in core_print_disasm, first if statement"); ds->at = ds->addr + idx; ds->vat = rz_core_pava(core, ds->at); if (rz_cons_is_breaked()) { @@ -5408,8 +5422,10 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u ds_free(ds); return 0; // break; } + // rz_cons_println("Line number 5420, in core_print_disasm"); if (core->print->flags & RZ_PRINT_FLAGS_UNALLOC) { if (!core->analysis->iob.is_valid_offset(core->analysis->iob.io, ds->at, 0)) { + // rz_cons_println("Line number 5424, in 2nd if statement, core_print_disasm"); //doesnt even come here?! ds_begin_line(ds); ds_print_labels(ds, f); ds_setup_print_pre(ds, false, false); @@ -5422,6 +5438,7 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u continue; } } + // rz_cons_println("Line number 5437, in core_print_disasm"); rz_core_seek_arch_bits(core, ds->at); // slow but safe ds->has_description = false; ds->hint = rz_core_hint_begin(core, ds->hint, ds->at); @@ -5443,11 +5460,14 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u f = ds->fcn = fcnIn(ds, ds->at, RZ_ANALYSIS_FCN_TYPE_NULL); ds_show_comments_right(ds); // TRY adding here + // rz_cons_println("Line number 5459,before 3rd if block in core_print_disasm"); RzType *link_type = rz_analysis_type_link_at(core->analysis, ds->addr + idx); if (link_type) { + // rz_cons_println("Line number 5462,inside 3rd if block, outside the nested if block in core_print_disasm"); //doesnt come here also! char *fmt = rz_type_as_format_pair(core->analysis->typedb, link_type); const char *typename = rz_type_identifier(link_type); if (fmt && typename) { + // rz_cons_println("Line number 5466,inside the 3rd if block, inside its nested if block in core_print_disasm"); //obciously doesnt come here too rz_cons_printf("(%s)\n", typename); rz_core_cmdf(core, "pf %s @ 0x%08" PFMT64x "\n", fmt, ds->addr + idx); const ut32 type_bitsize = rz_type_db_get_bitsize(core->analysis->typedb, link_type); @@ -5460,6 +5480,7 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u } free(link_type); } else { + // rz_cons_println("Line number 5479, in core_print_disasm"); if (idx >= 0) { ret = ds_disassemble(ds, buf + addrbytes * idx, len - addrbytes * idx); if (ret == -31337) { @@ -5493,8 +5514,11 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u ds->analysis_op.ptr = ds->hint->ptr; } } + // rz_cons_println("Line number 5513,before bbline in core_print_disasm"); ds_print_bbline(ds); + // rz_cons_println("Line number 5515,after bbline in core_print_disasm"); if (ds->at >= addr) { + // rz_cons_println("Line number 5517, in core_print_disasm"); rz_print_set_rowoff(core->print, ds->lines, ds->at - addr, calc_row_offsets); } skip_bytes_flag = handleMidFlags(core, ds, true); @@ -5510,7 +5534,9 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u ds_show_flags(ds, true); ds->at -= skip_bytes_flag; } + // rz_cons_println("Line number 5403, before ds->pdf in core_print_disasm"); if (ds->pdf) { + // rz_cons_println("Line number 5403,inside ds->pdf in core_print_disasm"); static bool sparse = false; RzAnalysisBlock *bb = rz_analysis_fcn_bbget_in(core->analysis, ds->pdf, ds->at); if (!bb) { @@ -5530,12 +5556,14 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u } sparse = false; } + // rz_cons_println("Line number 5555,outside the ds->pdf is statement in core_print_disasm"); ds_control_flow_comments(ds); ds_adistrick_comments(ds); /* XXX: This is really cpu consuming.. need to be fixed */ ds_show_functions(ds); - + // rz_cons_println("Line number 5560,after some commnds in core_print_disasm"); if (ds->show_comments && !ds->show_comment_right) { + // rz_cons_println("Line number 5562, inside show comments in core_print_disasm"); ds_show_refs(ds); ds_build_op_str(ds, false); ds_print_cmt_esil(ds); @@ -5552,11 +5580,12 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u ds_print_esil_analysis(ds); } if ((ds->analysis_op.type == RZ_ANALYSIS_OP_TYPE_CALL || ds->analysis_op.type & RZ_ANALYSIS_OP_TYPE_UCALL) && ds->show_calls) { + // rz_cons_println("Line number 5579, inside call hints if statement core_print_disasm"); ds_print_calls_hints(ds); } ds_show_comments_describe(ds); } - + // rz_cons_println("Line number 5584,outside show comments, before some printing stuff in core_print_disasm"); f = fcnIn(ds, ds->addr, 0); ds_begin_line(ds); ds_print_labels(ds, f); @@ -5565,6 +5594,7 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u core->print->resetbg = (ds->asm_highlight == UT64_MAX); ds_start_line_highlight(ds); ds_print_offset(ds); + // rz_cons_println("Line number 5593,after some of that printing stuff in core_print_disasm"); //// RzAnalysisFunction *fcn = f; if (fcn) { @@ -5577,6 +5607,7 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u } } //// + // rz_cons_println("Line number 5606,before print metainfos in core_print_disasm"); int mi_type; bool mi_found = ds_print_meta_infos(ds, buf, len, idx, &mi_type); if (ds->asm_hint_pos == 0) { @@ -5586,13 +5617,17 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u ds_print_core_vmode(ds, ds->asm_hint_pos); } } + // rz_cons_println("Line number 5616,after print metainfos, before some op_size print statements in core_print_disasm"); ds_print_op_size(ds); ds_print_trace(ds); ds_print_cycles(ds); ds_print_family(ds); ds_print_stackptr(ds); + // rz_cons_println("Line number 5622,after op_size print statements in core_print_disasm"); if (mi_found) { + // rz_cons_println("Line number 5624,inside mi_foudnd,before print_dwarf in core_print_disasm"); ds_print_dwarf(ds); + // rz_cons_println("Line number 5626,after print_dwarf in core_print_disasm"); ret = ds_print_middle(ds, ret); ds_print_asmop_payload(ds, buf + addrbytes * idx); @@ -5622,11 +5657,13 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u } } } else { + // rz_cons_println("Line number 5656,no mi_info found, else statement in core_print_disasm"); /* show cursor */ ds_print_show_cursor(ds); if (!ds->show_bytes_right) { ds_print_show_bytes(ds); } + // rz_cons_println("Line number 5662,before print stmts in core_print_disasm"); ds_print_lines_right(ds); ds_print_optype(ds); ds_build_op_str(ds, true); @@ -5634,6 +5671,7 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u ds_end_line_highlight(ds); ds_print_dwarf(ds); ret = ds_print_middle(ds, ret); + // rz_cons_println("Line number 5670,after print stmts in core_print_disasm"); ds_print_asmop_payload(ds, buf + addrbytes * idx); if (core->rasm->syntax != RZ_ASM_SYNTAX_INTEL) { From 617da9275bc850ed1fad57a226786995bd03566f Mon Sep 17 00:00:00 2001 From: Sidhub723 Date: Sun, 2 Apr 2023 21:15:44 +0530 Subject: [PATCH 2/9] Added support for display of line numbers,spacing is irregular --- librz/core/disasm.c | 134 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 126 insertions(+), 8 deletions(-) diff --git a/librz/core/disasm.c b/librz/core/disasm.c index 4b971fd5434..f5f9c1e3353 100644 --- a/librz/core/disasm.c +++ b/librz/core/disasm.c @@ -350,7 +350,8 @@ static void ds_print_sysregs(RzDisasmState *ds); static void ds_print_fcn_name(RzDisasmState *ds); static void ds_print_as_string(RzDisasmState *ds); static bool ds_print_core_vmode(RzDisasmState *ds, int pos); -static void ds_print_dwarf(RzDisasmState *ds); +// static void ds_print_dwarf(RzDisasmState *ds); +static void ds_print_dwarf(RzCore *core, RzCmdStateOutput *state, RzDisasmState *ds); static void ds_print_asmop_payload(RzDisasmState *ds, const ut8 *buf); static char *ds_esc_str(RzDisasmState *ds, const char *str, int len, const char **prefix_out, bool is_comment); static void ds_print_ptr(RzDisasmState *ds, int len, int idx); @@ -722,7 +723,7 @@ static RzDisasmState *ds_init(RzCore *core) { ds->show_dwarf = rz_config_get_b(core->config, "asm.dwarf"); ds->dwarfFile = rz_config_get_b(ds->core->config, "asm.dwarf.file"); ds->dwarfAbspath = rz_config_get_b(ds->core->config, "asm.dwarf.abspath"); - ds->dwarfShowLines = rz_config_get_b(ds->core->config,"asm.dwarf.lines"); + ds->dwarfShowLines = rz_config_get_b(ds->core->config, "asm.dwarf.lines"); ds->show_lines_call = ds->show_lines ? rz_config_get_b(core->config, "asm.lines.call") : false; ds->show_lines_ret = ds->show_lines ? rz_config_get_b(core->config, "asm.lines.ret") : false; ds->show_size = rz_config_get_b(core->config, "asm.size"); @@ -2718,6 +2719,7 @@ static void ds_control_flow_comments(RzDisasmState *ds) { } static void ds_print_lines_right(RzDisasmState *ds) { + // rz_cons_println("Line Number 2722, inside ds_print_lines_right"); if (ds->linesright && ds->show_lines_bb && ds->line) { ds_print_ref_lines(ds->line, ds->line_col, ds); } @@ -3819,8 +3821,124 @@ static void ds_align_comment(RzDisasmState *ds) { rz_cons_print(" "); } -static void ds_print_dwarf(RzDisasmState *ds) { +static void ds_print_dwarf(RzCore *core, RzCmdStateOutput *state, RzDisasmState *ds) { // rz_cons_println("Line number 3823,inside ds_print_dwarf "); + + bool binFileExists = true; + bool SourceLineInfoExists = true; + + RzBinFile *binfile = core->bin->cur; + if (!binfile || !binfile->o) { + rz_cons_printf("No file loaded.\n"); + binFileExists = false; + // return false; + } + RzBinSourceLineInfo *li = binfile->o->lines; + if (!li) { + rz_cons_printf("No source info available.\n"); + SourceLineInfoExists = false; + // return true; + } + if (ds->dwarfShowLines) { + // rz_cons_printf("Number of samples is li->samples_count=%ld",li->samples_count); + // const RzBinSourceLineSample *s = rz_bin_source_line_info_get_first_at(li, core->offset); + // for (size_t i = 0; (i < li->samples_count && s); i++,s = rz_bin_source_line_info_get_next(li, s)) { + // rz_cons_printf("The source line address is %llu",s->address); + // } + // rz_cmd_state_output_array_start(state); + // for (const RzBinSourceLineSample *s = rz_bin_source_line_info_get_first_at(li, core->offset);s; s = rz_bin_source_line_info_get_next(li, s)) { + // rz_core_bin_print_source_line_sample(core, s, state); + // rz_cons_printf("address after fetching next one purpotedly is %lld ",s->address); + // } + rz_cmd_state_output_array_start(state); + rz_cons_break_push(NULL, NULL); + RzBinSourceLineSample *temps = NULL; + // rz_cons_printf("The ds->vat data is %lld",ds->vat); + // rz_cons_printf("The address is samples if %lld",temps->address); + for(size_t i = 0; isamples_count;i++) { + if (rz_cons_is_breaked()) { + break; + } + temps = &li->samples[i] ; + // rz_cons_printf("The address of the [%ld]th sample is %lld",i,temps->address); + if(ds->vat == temps->address) { + // rz_cons_printf(/*"0x%08" PFMT64x */ "\t%s\t"/*temps->address,*/,temps->file ? temps->file : "-"); + rz_cons_printf("\tLine number%s",temps->file ? temps->file : "-"); + + if (temps->line) { + rz_cons_printf("%" PFMT32u "\n", temps->line); + } else { + rz_cons_print("-\n"); + } + } + + + + } + rz_cons_break_pop(); + rz_cmd_state_output_array_end(state); + + + + // rz_cons_break_push(NULL, NULL); + // RzBinSourceLineSample *temps = NULL; + + // for (size_t i = 0; i < li->samples_count; i++) { + // if (rz_cons_is_breaked()) { + // break; + // } + // temps = &li->samples[i] ; + // rz_cons_printf("The address in sample[%ld] is %llu",i,temps->address); + + // // rz_core_bin_print_source_line_sample(core, &li->samples[i], state); + // rz_cons_printf("0x%08" PFMT64x "\t%s\t", temps->address, temps->file ? temps->file : "-"); + // if (temps->line) { + // rz_cons_printf("%" PFMT32u "\n", temps->line); + // } else { + // rz_cons_print("-\n"); + // } + + // } + + + + + + // rz_cmd_state_output_array_start(state); + // // for (const RzBinSourceLineSample *s = rz_bin_source_line_info_get_first_at(li, core->offset);s; s = rz_bin_source_line_info_get_next(li, s)){ + // // /*core,s,state*/ + // // // rz_cons_printf("0x%08" PFMT64x "\t%s\t",s->address, s->file ? s->file : "-"); + // // // if (s->line) { + // // // rz_cons_printf("%" PFMT32u "\n", s->line); + // // // } else { + // // // rz_cons_print("-\n"); + // // // } + // // // rz_core_bin_print_source_line_sample(core, s, state); + + // // } + // rz_cons_break_push(NULL, NULL); + // const RzBinSourceLineSample *s = rz_bin_source_line_info_get_first_at(li, core->offset); + // for (size_t i = 0; i < li->samples_count; i++) { + // if (rz_cons_is_breaked()) { + // break; + // } + // // if(/*offset address is same as the curret offset of the line info li, then print it*/){ + // for (const RzBinSourceLineSample *s = rz_bin_source_line_info_get_first_at(li, core->offset);s; s = rz_bin_source_line_info_get_next(li, s)) { + + // rz_cons_printf("core->offset is equal to %llu and the address in sourcelinesample is %llu ",core->offset,s->address); + // if(core->offset == s->address) + // rz_core_bin_print_source_line_sample(core, s, state); + // } + // // if(core->offset == s->address){ + // // rz_cons_println("Offset address is equal to line info address"); + // // rz_core_bin_print_source_line_sample(core, &li->samples[i], state); + // // } + // } + // rz_cons_break_pop(); + // rz_cmd_state_output_array_end(state); + + } + if (ds->show_dwarf) { // TODO: cache value in ds int dwarfFile = (int)ds->dwarfFile + (int)ds->dwarfAbspath; @@ -5585,12 +5703,12 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u } ds_show_comments_describe(ds); } - // rz_cons_println("Line number 5584,outside show comments, before some printing stuff in core_print_disasm"); + // rz_cons_println("Line number 5584,outside show comments, before some offset printing stuff in core_print_disasm"); f = fcnIn(ds, ds->addr, 0); ds_begin_line(ds); ds_print_labels(ds, f); - ds_setup_print_pre(ds, false, false); - ds_print_lines_left(ds); + ds_setup_print_pre(ds, false, false); //prints the "arrow" lines + ds_print_lines_left(ds); //prints out a gap? core->print->resetbg = (ds->asm_highlight == UT64_MAX); ds_start_line_highlight(ds); ds_print_offset(ds); @@ -5626,7 +5744,7 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u // rz_cons_println("Line number 5622,after op_size print statements in core_print_disasm"); if (mi_found) { // rz_cons_println("Line number 5624,inside mi_foudnd,before print_dwarf in core_print_disasm"); - ds_print_dwarf(ds); + ds_print_dwarf(core, state, ds); // rz_cons_println("Line number 5626,after print_dwarf in core_print_disasm"); ret = ds_print_middle(ds, ret); @@ -5669,7 +5787,7 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u ds_build_op_str(ds, true); ds_print_opstr(ds); ds_end_line_highlight(ds); - ds_print_dwarf(ds); + ds_print_dwarf(core, state, ds); ret = ds_print_middle(ds, ret); // rz_cons_println("Line number 5670,after print stmts in core_print_disasm"); From 28fbeb435a2607f88f14099b70f92b47db6f3dee Mon Sep 17 00:00:00 2001 From: Sidhub723 Date: Sun, 2 Apr 2023 23:43:27 +0530 Subject: [PATCH 3/9] Spacing issue almost fixed,text color does not match --- librz/core/disasm.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/librz/core/disasm.c b/librz/core/disasm.c index f5f9c1e3353..488985d1ebd 100644 --- a/librz/core/disasm.c +++ b/librz/core/disasm.c @@ -3829,17 +3829,17 @@ static void ds_print_dwarf(RzCore *core, RzCmdStateOutput *state, RzDisasmState RzBinFile *binfile = core->bin->cur; if (!binfile || !binfile->o) { - rz_cons_printf("No file loaded.\n"); + // rz_cons_printf("No file loaded.\n"); binFileExists = false; // return false; } RzBinSourceLineInfo *li = binfile->o->lines; if (!li) { - rz_cons_printf("No source info available.\n"); + // rz_cons_printf("No source infooooooo available.\n"); SourceLineInfoExists = false; // return true; } - if (ds->dwarfShowLines) { + if (ds->dwarfShowLines && SourceLineInfoExists && binFileExists) { // rz_cons_printf("Number of samples is li->samples_count=%ld",li->samples_count); // const RzBinSourceLineSample *s = rz_bin_source_line_info_get_first_at(li, core->offset); // for (size_t i = 0; (i < li->samples_count && s); i++,s = rz_bin_source_line_info_get_next(li, s)) { @@ -3860,20 +3860,19 @@ static void ds_print_dwarf(RzCore *core, RzCmdStateOutput *state, RzDisasmState break; } temps = &li->samples[i] ; - // rz_cons_printf("The address of the [%ld]th sample is %lld",i,temps->address); + + ds_align_comment(ds); if(ds->vat == temps->address) { // rz_cons_printf(/*"0x%08" PFMT64x */ "\t%s\t"/*temps->address,*/,temps->file ? temps->file : "-"); - rz_cons_printf("\tLine number%s",temps->file ? temps->file : "-"); + rz_cons_printf("\tLine number%s",temps->file ? temps->file : "-"); - if (temps->line) { - rz_cons_printf("%" PFMT32u "\n", temps->line); - } else { - rz_cons_print("-\n"); - } + if (temps->line) { + rz_cons_printf("%" PFMT32u "\n", temps->line); + } else { + rz_cons_print("-\n"); + } } - - } rz_cons_break_pop(); rz_cmd_state_output_array_end(state); @@ -5787,8 +5786,10 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u ds_build_op_str(ds, true); ds_print_opstr(ds); ds_end_line_highlight(ds); + // rz_cons_printf("%s","After end_line_highlights"); ds_print_dwarf(core, state, ds); ret = ds_print_middle(ds, ret); + // rz_cons_printf("%s","After ds_print_middle"); // rz_cons_println("Line number 5670,after print stmts in core_print_disasm"); ds_print_asmop_payload(ds, buf + addrbytes * idx); @@ -5818,7 +5819,7 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u ds_print_fcn_name(ds); ds_print_demangled(ds); ds_print_color_reset(ds); - ds_print_comments_right(ds); + ds_print_comments_right(ds); ds_print_esil_analysis(ds); ds_show_refs(ds); } From 6dcf9d8b23479f92fe67e0f0a32b27b3f81ff538 Mon Sep 17 00:00:00 2001 From: Sidhub723 Date: Mon, 3 Apr 2023 04:17:44 +0530 Subject: [PATCH 4/9] Cleaned up unused code --- librz/core/disasm.c | 68 +-------------------------------------------- 1 file changed, 1 insertion(+), 67 deletions(-) diff --git a/librz/core/disasm.c b/librz/core/disasm.c index 488985d1ebd..974372b410d 100644 --- a/librz/core/disasm.c +++ b/librz/core/disasm.c @@ -3840,16 +3840,7 @@ static void ds_print_dwarf(RzCore *core, RzCmdStateOutput *state, RzDisasmState // return true; } if (ds->dwarfShowLines && SourceLineInfoExists && binFileExists) { - // rz_cons_printf("Number of samples is li->samples_count=%ld",li->samples_count); - // const RzBinSourceLineSample *s = rz_bin_source_line_info_get_first_at(li, core->offset); - // for (size_t i = 0; (i < li->samples_count && s); i++,s = rz_bin_source_line_info_get_next(li, s)) { - // rz_cons_printf("The source line address is %llu",s->address); - // } - // rz_cmd_state_output_array_start(state); - // for (const RzBinSourceLineSample *s = rz_bin_source_line_info_get_first_at(li, core->offset);s; s = rz_bin_source_line_info_get_next(li, s)) { - // rz_core_bin_print_source_line_sample(core, s, state); - // rz_cons_printf("address after fetching next one purpotedly is %lld ",s->address); - // } + rz_cmd_state_output_array_start(state); rz_cons_break_push(NULL, NULL); RzBinSourceLineSample *temps = NULL; @@ -3878,63 +3869,6 @@ static void ds_print_dwarf(RzCore *core, RzCmdStateOutput *state, RzDisasmState rz_cmd_state_output_array_end(state); - - // rz_cons_break_push(NULL, NULL); - // RzBinSourceLineSample *temps = NULL; - - // for (size_t i = 0; i < li->samples_count; i++) { - // if (rz_cons_is_breaked()) { - // break; - // } - // temps = &li->samples[i] ; - // rz_cons_printf("The address in sample[%ld] is %llu",i,temps->address); - - // // rz_core_bin_print_source_line_sample(core, &li->samples[i], state); - // rz_cons_printf("0x%08" PFMT64x "\t%s\t", temps->address, temps->file ? temps->file : "-"); - // if (temps->line) { - // rz_cons_printf("%" PFMT32u "\n", temps->line); - // } else { - // rz_cons_print("-\n"); - // } - - // } - - - - - - // rz_cmd_state_output_array_start(state); - // // for (const RzBinSourceLineSample *s = rz_bin_source_line_info_get_first_at(li, core->offset);s; s = rz_bin_source_line_info_get_next(li, s)){ - // // /*core,s,state*/ - // // // rz_cons_printf("0x%08" PFMT64x "\t%s\t",s->address, s->file ? s->file : "-"); - // // // if (s->line) { - // // // rz_cons_printf("%" PFMT32u "\n", s->line); - // // // } else { - // // // rz_cons_print("-\n"); - // // // } - // // // rz_core_bin_print_source_line_sample(core, s, state); - - // // } - // rz_cons_break_push(NULL, NULL); - // const RzBinSourceLineSample *s = rz_bin_source_line_info_get_first_at(li, core->offset); - // for (size_t i = 0; i < li->samples_count; i++) { - // if (rz_cons_is_breaked()) { - // break; - // } - // // if(/*offset address is same as the curret offset of the line info li, then print it*/){ - // for (const RzBinSourceLineSample *s = rz_bin_source_line_info_get_first_at(li, core->offset);s; s = rz_bin_source_line_info_get_next(li, s)) { - - // rz_cons_printf("core->offset is equal to %llu and the address in sourcelinesample is %llu ",core->offset,s->address); - // if(core->offset == s->address) - // rz_core_bin_print_source_line_sample(core, s, state); - // } - // // if(core->offset == s->address){ - // // rz_cons_println("Offset address is equal to line info address"); - // // rz_core_bin_print_source_line_sample(core, &li->samples[i], state); - // // } - // } - // rz_cons_break_pop(); - // rz_cmd_state_output_array_end(state); } From 6b751e0767cd4cec90095bf1f3f711c28b625340 Mon Sep 17 00:00:00 2001 From: Sidhub723 Date: Tue, 4 Apr 2023 15:27:18 +0530 Subject: [PATCH 5/9] clang-formated the changed --- librz/core/cconfig.c | 2 +- librz/core/disasm.c | 25 +++++++++---------------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/librz/core/cconfig.c b/librz/core/cconfig.c index 4a9274a114b..63e07becd4f 100644 --- a/librz/core/cconfig.c +++ b/librz/core/cconfig.c @@ -3032,7 +3032,7 @@ RZ_API int rz_core_config_init(RzCore *core) { SETBPREF("asm.dwarf", "false", "Show dwarf comment at disassembly"); SETBPREF("asm.dwarf.abspath", "false", "Show absolute path in asm.dwarf"); SETBPREF("asm.dwarf.file", "true", "Show filename of asm.dwarf in pd"); - SETBPREF("asm.dwarf.lines","false","Show DWARF source line information at disassembly"); + SETBPREF("asm.dwarf.lines", "false", "Show DWARF source line information at disassembly"); SETBPREF("asm.esil", "false", "Show ESIL instead of mnemonic"); SETBPREF("asm.nodup", "false", "Do not show dupped instructions (collapse disasm)"); SETBPREF("asm.emu", "false", "Run ESIL emulation analysis on disasm"); diff --git a/librz/core/disasm.c b/librz/core/disasm.c index 974372b410d..d914c090b11 100644 --- a/librz/core/disasm.c +++ b/librz/core/disasm.c @@ -3829,13 +3829,12 @@ static void ds_print_dwarf(RzCore *core, RzCmdStateOutput *state, RzDisasmState RzBinFile *binfile = core->bin->cur; if (!binfile || !binfile->o) { - // rz_cons_printf("No file loaded.\n"); + rz_cons_printf("No file loaded.\n"); binFileExists = false; // return false; } RzBinSourceLineInfo *li = binfile->o->lines; if (!li) { - // rz_cons_printf("No source infooooooo available.\n"); SourceLineInfoExists = false; // return true; } @@ -3844,18 +3843,16 @@ static void ds_print_dwarf(RzCore *core, RzCmdStateOutput *state, RzDisasmState rz_cmd_state_output_array_start(state); rz_cons_break_push(NULL, NULL); RzBinSourceLineSample *temps = NULL; - // rz_cons_printf("The ds->vat data is %lld",ds->vat); - // rz_cons_printf("The address is samples if %lld",temps->address); - for(size_t i = 0; isamples_count;i++) { + for (size_t i = 0; i < li->samples_count; i++) { if (rz_cons_is_breaked()) { break; } - temps = &li->samples[i] ; + temps = &li->samples[i]; ds_align_comment(ds); - if(ds->vat == temps->address) { - // rz_cons_printf(/*"0x%08" PFMT64x */ "\t%s\t"/*temps->address,*/,temps->file ? temps->file : "-"); - rz_cons_printf("\tLine number%s",temps->file ? temps->file : "-"); + if (ds->vat == temps->address) { + // rz_cons_printf(/*"0x%08" PFMT64x */ "\t%s\t"/*temps->address,*/,temps->file ? temps->file : "-"); + rz_cons_printf("\tLine number%s", temps->file ? temps->file : "-"); if (temps->line) { rz_cons_printf("%" PFMT32u "\n", temps->line); @@ -3863,13 +3860,9 @@ static void ds_print_dwarf(RzCore *core, RzCmdStateOutput *state, RzDisasmState rz_cons_print("-\n"); } } - } rz_cons_break_pop(); rz_cmd_state_output_array_end(state); - - - } if (ds->show_dwarf) { @@ -5640,8 +5633,8 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u f = fcnIn(ds, ds->addr, 0); ds_begin_line(ds); ds_print_labels(ds, f); - ds_setup_print_pre(ds, false, false); //prints the "arrow" lines - ds_print_lines_left(ds); //prints out a gap? + ds_setup_print_pre(ds, false, false); // prints the "arrow" lines + ds_print_lines_left(ds); // prints out a gap? core->print->resetbg = (ds->asm_highlight == UT64_MAX); ds_start_line_highlight(ds); ds_print_offset(ds); @@ -5753,7 +5746,7 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u ds_print_fcn_name(ds); ds_print_demangled(ds); ds_print_color_reset(ds); - ds_print_comments_right(ds); + ds_print_comments_right(ds); ds_print_esil_analysis(ds); ds_show_refs(ds); } From bd75206849e26d0a5ff5fd01748ec45a42ff9f65 Mon Sep 17 00:00:00 2001 From: Sidhub723 Date: Tue, 4 Apr 2023 15:36:51 +0530 Subject: [PATCH 6/9] Cleaned up comments --- librz/core/disasm.c | 49 ++++----------------------------------------- 1 file changed, 4 insertions(+), 45 deletions(-) diff --git a/librz/core/disasm.c b/librz/core/disasm.c index d914c090b11..585d0ac9c1e 100644 --- a/librz/core/disasm.c +++ b/librz/core/disasm.c @@ -2719,7 +2719,6 @@ static void ds_control_flow_comments(RzDisasmState *ds) { } static void ds_print_lines_right(RzDisasmState *ds) { - // rz_cons_println("Line Number 2722, inside ds_print_lines_right"); if (ds->linesright && ds->show_lines_bb && ds->line) { ds_print_ref_lines(ds->line, ds->line_col, ds); } @@ -3440,7 +3439,6 @@ static void ds_print_indent(RzDisasmState *ds) { } static void ds_print_optype(RzDisasmState *ds) { - // rz_cons_println("Line number 3441,inside ds_print_optype"); if (ds->show_optype) { const char *optype = rz_analysis_optype_to_string(ds->analysis_op.type); ds_print_color_reset(ds); @@ -3450,7 +3448,6 @@ static void ds_print_optype(RzDisasmState *ds) { } static void ds_print_opstr(RzDisasmState *ds) { - // rz_cons_println("Line number 3451,inside ds_print_opstr "); ds_print_indent(ds); if (ds->asm_instr) { rz_cons_strcat(ds->opstr); @@ -3608,16 +3605,13 @@ static int ds_print_shortcut(RzDisasmState *ds, ut64 addr, int pos) { if (shortcut) { if (ds->core->is_asmqjmps_letter) { rz_cons_printf("%s[o%s]", ch, shortcut); - rz_cons_println("Line 3606"); slen++; } else { rz_cons_printf("%s[%s]", ch, shortcut); - rz_cons_println("Line 3611"); } free(shortcut); } else { rz_cons_printf("%s[?]", ch); - rz_cons_println("Line 3616"); } if (ds->show_color) { if (ds->core->print->resetbg) { @@ -3674,7 +3668,6 @@ static bool ds_print_core_vmode(RzDisasmState *ds, int pos) { RzCore *core = ds->core; bool gotShortcut = false; int i, slen = 0; - // rz_cons_println("Line number 3673 in print_core_vmode"); if (!core->vmode) { return false; @@ -3822,19 +3815,19 @@ static void ds_align_comment(RzDisasmState *ds) { } static void ds_print_dwarf(RzCore *core, RzCmdStateOutput *state, RzDisasmState *ds) { - // rz_cons_println("Line number 3823,inside ds_print_dwarf "); bool binFileExists = true; bool SourceLineInfoExists = true; RzBinFile *binfile = core->bin->cur; if (!binfile || !binfile->o) { - rz_cons_printf("No file loaded.\n"); + // rz_cons_printf("No file loaded.\n"); binFileExists = false; // return false; } RzBinSourceLineInfo *li = binfile->o->lines; if (!li) { + // rz_cons_printf("No Source line information available"); SourceLineInfoExists = false; // return true; } @@ -4655,7 +4648,6 @@ static void ds_pre_emulation(RzDisasmState *ds) { } static void ds_print_esil_analysis_init(RzDisasmState *ds) { - // rz_cons_println("Line 4611 in esil_analysis_init"); RzCore *core = ds->core; const char *pc = rz_reg_get_name(core->analysis->reg, RZ_REG_NAME_PC); if (!pc) { @@ -5317,7 +5309,6 @@ static void ds_start_line_highlight(RzDisasmState *ds) { } static void ds_end_line_highlight(RzDisasmState *ds) { - // rz_cons_println("Line number 5275,inside ds_end_line_highlight "); if (ds->show_color && line_highlighted(ds)) { rz_cons_strcat(Color_RESET); } @@ -5448,11 +5439,8 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u if (!ds->l) { ds->l = core->blocksize; } - // rz_cons_println("Line number 5403, in core_print_disasm"); rz_cons_break_push(NULL, NULL); - // rz_cons_println("Line number 5405, in core_print_disasm"); for (idx = ret = 0; addrbytes * idx < len && ds->lines < ds->l; idx += inc, ds->index += inc, ds->lines++) { - // rz_cons_println("Line number 5403, in core_print_disasm, first if statement"); ds->at = ds->addr + idx; ds->vat = rz_core_pava(core, ds->at); if (rz_cons_is_breaked()) { @@ -5466,10 +5454,8 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u ds_free(ds); return 0; // break; } - // rz_cons_println("Line number 5420, in core_print_disasm"); if (core->print->flags & RZ_PRINT_FLAGS_UNALLOC) { if (!core->analysis->iob.is_valid_offset(core->analysis->iob.io, ds->at, 0)) { - // rz_cons_println("Line number 5424, in 2nd if statement, core_print_disasm"); //doesnt even come here?! ds_begin_line(ds); ds_print_labels(ds, f); ds_setup_print_pre(ds, false, false); @@ -5482,7 +5468,6 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u continue; } } - // rz_cons_println("Line number 5437, in core_print_disasm"); rz_core_seek_arch_bits(core, ds->at); // slow but safe ds->has_description = false; ds->hint = rz_core_hint_begin(core, ds->hint, ds->at); @@ -5504,14 +5489,11 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u f = ds->fcn = fcnIn(ds, ds->at, RZ_ANALYSIS_FCN_TYPE_NULL); ds_show_comments_right(ds); // TRY adding here - // rz_cons_println("Line number 5459,before 3rd if block in core_print_disasm"); RzType *link_type = rz_analysis_type_link_at(core->analysis, ds->addr + idx); if (link_type) { - // rz_cons_println("Line number 5462,inside 3rd if block, outside the nested if block in core_print_disasm"); //doesnt come here also! char *fmt = rz_type_as_format_pair(core->analysis->typedb, link_type); const char *typename = rz_type_identifier(link_type); if (fmt && typename) { - // rz_cons_println("Line number 5466,inside the 3rd if block, inside its nested if block in core_print_disasm"); //obciously doesnt come here too rz_cons_printf("(%s)\n", typename); rz_core_cmdf(core, "pf %s @ 0x%08" PFMT64x "\n", fmt, ds->addr + idx); const ut32 type_bitsize = rz_type_db_get_bitsize(core->analysis->typedb, link_type); @@ -5524,7 +5506,6 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u } free(link_type); } else { - // rz_cons_println("Line number 5479, in core_print_disasm"); if (idx >= 0) { ret = ds_disassemble(ds, buf + addrbytes * idx, len - addrbytes * idx); if (ret == -31337) { @@ -5558,11 +5539,8 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u ds->analysis_op.ptr = ds->hint->ptr; } } - // rz_cons_println("Line number 5513,before bbline in core_print_disasm"); ds_print_bbline(ds); - // rz_cons_println("Line number 5515,after bbline in core_print_disasm"); if (ds->at >= addr) { - // rz_cons_println("Line number 5517, in core_print_disasm"); rz_print_set_rowoff(core->print, ds->lines, ds->at - addr, calc_row_offsets); } skip_bytes_flag = handleMidFlags(core, ds, true); @@ -5578,9 +5556,7 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u ds_show_flags(ds, true); ds->at -= skip_bytes_flag; } - // rz_cons_println("Line number 5403, before ds->pdf in core_print_disasm"); if (ds->pdf) { - // rz_cons_println("Line number 5403,inside ds->pdf in core_print_disasm"); static bool sparse = false; RzAnalysisBlock *bb = rz_analysis_fcn_bbget_in(core->analysis, ds->pdf, ds->at); if (!bb) { @@ -5600,14 +5576,11 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u } sparse = false; } - // rz_cons_println("Line number 5555,outside the ds->pdf is statement in core_print_disasm"); ds_control_flow_comments(ds); ds_adistrick_comments(ds); /* XXX: This is really cpu consuming.. need to be fixed */ ds_show_functions(ds); - // rz_cons_println("Line number 5560,after some commnds in core_print_disasm"); if (ds->show_comments && !ds->show_comment_right) { - // rz_cons_println("Line number 5562, inside show comments in core_print_disasm"); ds_show_refs(ds); ds_build_op_str(ds, false); ds_print_cmt_esil(ds); @@ -5624,21 +5597,18 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u ds_print_esil_analysis(ds); } if ((ds->analysis_op.type == RZ_ANALYSIS_OP_TYPE_CALL || ds->analysis_op.type & RZ_ANALYSIS_OP_TYPE_UCALL) && ds->show_calls) { - // rz_cons_println("Line number 5579, inside call hints if statement core_print_disasm"); ds_print_calls_hints(ds); } ds_show_comments_describe(ds); } - // rz_cons_println("Line number 5584,outside show comments, before some offset printing stuff in core_print_disasm"); f = fcnIn(ds, ds->addr, 0); ds_begin_line(ds); ds_print_labels(ds, f); - ds_setup_print_pre(ds, false, false); // prints the "arrow" lines - ds_print_lines_left(ds); // prints out a gap? + ds_setup_print_pre(ds, false, false); + ds_print_lines_left(ds); core->print->resetbg = (ds->asm_highlight == UT64_MAX); ds_start_line_highlight(ds); ds_print_offset(ds); - // rz_cons_println("Line number 5593,after some of that printing stuff in core_print_disasm"); //// RzAnalysisFunction *fcn = f; if (fcn) { @@ -5650,8 +5620,6 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u } } } - //// - // rz_cons_println("Line number 5606,before print metainfos in core_print_disasm"); int mi_type; bool mi_found = ds_print_meta_infos(ds, buf, len, idx, &mi_type); if (ds->asm_hint_pos == 0) { @@ -5661,17 +5629,13 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u ds_print_core_vmode(ds, ds->asm_hint_pos); } } - // rz_cons_println("Line number 5616,after print metainfos, before some op_size print statements in core_print_disasm"); ds_print_op_size(ds); ds_print_trace(ds); ds_print_cycles(ds); ds_print_family(ds); ds_print_stackptr(ds); - // rz_cons_println("Line number 5622,after op_size print statements in core_print_disasm"); if (mi_found) { - // rz_cons_println("Line number 5624,inside mi_foudnd,before print_dwarf in core_print_disasm"); ds_print_dwarf(core, state, ds); - // rz_cons_println("Line number 5626,after print_dwarf in core_print_disasm"); ret = ds_print_middle(ds, ret); ds_print_asmop_payload(ds, buf + addrbytes * idx); @@ -5701,23 +5665,18 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u } } } else { - // rz_cons_println("Line number 5656,no mi_info found, else statement in core_print_disasm"); /* show cursor */ ds_print_show_cursor(ds); if (!ds->show_bytes_right) { ds_print_show_bytes(ds); } - // rz_cons_println("Line number 5662,before print stmts in core_print_disasm"); ds_print_lines_right(ds); ds_print_optype(ds); ds_build_op_str(ds, true); ds_print_opstr(ds); ds_end_line_highlight(ds); - // rz_cons_printf("%s","After end_line_highlights"); ds_print_dwarf(core, state, ds); ret = ds_print_middle(ds, ret); - // rz_cons_printf("%s","After ds_print_middle"); - // rz_cons_println("Line number 5670,after print stmts in core_print_disasm"); ds_print_asmop_payload(ds, buf + addrbytes * idx); if (core->rasm->syntax != RZ_ASM_SYNTAX_INTEL) { From dcc316fc242865d7850746c638b767eb97a2941d Mon Sep 17 00:00:00 2001 From: Sidhub723 Date: Sat, 8 Apr 2023 14:12:34 +0530 Subject: [PATCH 7/9] Fixed minor error in display of sourceline info --- librz/core/disasm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/librz/core/disasm.c b/librz/core/disasm.c index 585d0ac9c1e..fe48cd39aeb 100644 --- a/librz/core/disasm.c +++ b/librz/core/disasm.c @@ -3831,7 +3831,7 @@ static void ds_print_dwarf(RzCore *core, RzCmdStateOutput *state, RzDisasmState SourceLineInfoExists = false; // return true; } - if (ds->dwarfShowLines && SourceLineInfoExists && binFileExists) { + if (ds->dwarfShowLines && ds->show_dwarf && SourceLineInfoExists && binFileExists) { rz_cmd_state_output_array_start(state); rz_cons_break_push(NULL, NULL); From 76ce94c8373282a0257dcb64cd5e2f38b919deb7 Mon Sep 17 00:00:00 2001 From: Sidhub723 Date: Sun, 16 Apr 2023 01:07:03 +0530 Subject: [PATCH 8/9] Changed format of display of line info,removed unnecessary variable safety checks --- librz/core/disasm.c | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/librz/core/disasm.c b/librz/core/disasm.c index fe48cd39aeb..3d6043d2e0a 100644 --- a/librz/core/disasm.c +++ b/librz/core/disasm.c @@ -350,7 +350,6 @@ static void ds_print_sysregs(RzDisasmState *ds); static void ds_print_fcn_name(RzDisasmState *ds); static void ds_print_as_string(RzDisasmState *ds); static bool ds_print_core_vmode(RzDisasmState *ds, int pos); -// static void ds_print_dwarf(RzDisasmState *ds); static void ds_print_dwarf(RzCore *core, RzCmdStateOutput *state, RzDisasmState *ds); static void ds_print_asmop_payload(RzDisasmState *ds, const ut8 *buf); static char *ds_esc_str(RzDisasmState *ds, const char *str, int len, const char **prefix_out, bool is_comment); @@ -3820,35 +3819,39 @@ static void ds_print_dwarf(RzCore *core, RzCmdStateOutput *state, RzDisasmState bool SourceLineInfoExists = true; RzBinFile *binfile = core->bin->cur; - if (!binfile || !binfile->o) { - // rz_cons_printf("No file loaded.\n"); - binFileExists = false; - // return false; - } + // if (!binfile || !binfile->o) { + // // rz_cons_printf("No file loaded.\n"); + // binFileExists = false; + // // return false; + // } RzBinSourceLineInfo *li = binfile->o->lines; - if (!li) { - // rz_cons_printf("No Source line information available"); - SourceLineInfoExists = false; - // return true; - } - if (ds->dwarfShowLines && ds->show_dwarf && SourceLineInfoExists && binFileExists) { + // if (!li) { + // // rz_cons_printf("No Source line information available"); + // SourceLineInfoExists = false; + // // return true; + // } + if (ds->dwarfShowLines && ds->show_dwarf/* && SourceLineInfoExists && binFileExists*/) { rz_cmd_state_output_array_start(state); rz_cons_break_push(NULL, NULL); - RzBinSourceLineSample *temps = NULL; + RzBinSourceLineSample *linesampleinfo = NULL; + char *path = strdup(rz_config_get(core->config,"file.path")); + char *filename = strrchr(path,'/'); + // rz_cons_printf("The filename is :%s",filename); + for (size_t i = 0; i < li->samples_count; i++) { if (rz_cons_is_breaked()) { break; } - temps = &li->samples[i]; + linesampleinfo = &li->samples[i]; ds_align_comment(ds); - if (ds->vat == temps->address) { - // rz_cons_printf(/*"0x%08" PFMT64x */ "\t%s\t"/*temps->address,*/,temps->file ? temps->file : "-"); - rz_cons_printf("\tLine number%s", temps->file ? temps->file : "-"); + if (ds->vat == linesampleinfo->address) { + // rz_cons_printf("\tLine number%s", temps->file ? temps->file : "-"); + rz_cons_printf("\t ; %s:%s",filename,linesampleinfo->file ? linesampleinfo->file:""); - if (temps->line) { - rz_cons_printf("%" PFMT32u "\n", temps->line); + if (linesampleinfo->line) { + rz_cons_printf("%" PFMT32u "\n", linesampleinfo->line); } else { rz_cons_print("-\n"); } From 808eb27ba18464ff201ad9c925a29b8c387ba944 Mon Sep 17 00:00:00 2001 From: Sidhub723 Date: Sun, 16 Apr 2023 01:09:18 +0530 Subject: [PATCH 9/9] Cleaned up code for the previous commit --- librz/core/disasm.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/librz/core/disasm.c b/librz/core/disasm.c index 3d6043d2e0a..9008b09b51f 100644 --- a/librz/core/disasm.c +++ b/librz/core/disasm.c @@ -3817,39 +3817,25 @@ static void ds_print_dwarf(RzCore *core, RzCmdStateOutput *state, RzDisasmState bool binFileExists = true; bool SourceLineInfoExists = true; - RzBinFile *binfile = core->bin->cur; - // if (!binfile || !binfile->o) { - // // rz_cons_printf("No file loaded.\n"); - // binFileExists = false; - // // return false; - // } RzBinSourceLineInfo *li = binfile->o->lines; - // if (!li) { - // // rz_cons_printf("No Source line information available"); - // SourceLineInfoExists = false; - // // return true; - // } - if (ds->dwarfShowLines && ds->show_dwarf/* && SourceLineInfoExists && binFileExists*/) { + if (ds->dwarfShowLines && ds->show_dwarf/* && SourceLineInfoExists && binFileExists*/) { rz_cmd_state_output_array_start(state); rz_cons_break_push(NULL, NULL); RzBinSourceLineSample *linesampleinfo = NULL; char *path = strdup(rz_config_get(core->config,"file.path")); char *filename = strrchr(path,'/'); - // rz_cons_printf("The filename is :%s",filename); for (size_t i = 0; i < li->samples_count; i++) { if (rz_cons_is_breaked()) { break; } linesampleinfo = &li->samples[i]; - ds_align_comment(ds); if (ds->vat == linesampleinfo->address) { // rz_cons_printf("\tLine number%s", temps->file ? temps->file : "-"); rz_cons_printf("\t ; %s:%s",filename,linesampleinfo->file ? linesampleinfo->file:""); - if (linesampleinfo->line) { rz_cons_printf("%" PFMT32u "\n", linesampleinfo->line); } else {