Skip to content

Commit a62e112

Browse files
author
John Simpson
committed
Add changes submitted to main project by @nihilus for IDA 7 support.
See ALSchwalm#8
1 parent 3b7ed51 commit a62e112

File tree

3 files changed

+44
-38
lines changed

3 files changed

+44
-38
lines changed

src/dwarfexport.cpp

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
#include <fstream>
66
#include <ida.hpp>
77
#include <idp.hpp>
8+
#include <hexrays.hpp>
89
#include <kernwin.hpp>
910
#include <loader.hpp>
1011
#include <name.hpp>
1112
#include <string>
1213
#include <struct.hpp>
14+
#include <range.hpp>
15+
#include <segment.hpp>
1316

1417
#include "dwarfexport.h"
1518

@@ -73,7 +76,7 @@ static Dwarf_P_Die add_struct_type(Dwarf_P_Debug dbg, Dwarf_P_Die cu,
7376
for (int i = 0; i < member_count; ++i) {
7477
udt_member_t member;
7578
member.offset = i;
76-
type.find_udt_member(STRMEM_INDEX, &member);
79+
type.find_udt_member(&member, STRMEM_INDEX);
7780
auto member_type = member.type;
7881
auto member_die =
7982
dwarf_new_die(dbg, DW_TAG_member, die, NULL, NULL, NULL, &err);
@@ -149,7 +152,7 @@ static Dwarf_P_Die add_array_type(Dwarf_P_Debug dbg, Dwarf_P_Die cu,
149152
qstring name;
150153

151154
// Try to get size_t and use it for the index type
152-
if (parse_decl2(idati, "size_t x;", &name, &size_type, PT_SIL)) {
155+
if (parse_decl(&size_type, &name, NULL, "size_t x;", PT_SIL)) {
153156
auto index_die = get_or_add_type(dbg, cu, size_type, record);
154157
if (dwarf_add_AT_reference(dbg, subrange, DW_AT_type, index_die,
155158
&err) == nullptr) {
@@ -361,7 +364,7 @@ static void add_disassembler_func_info(std::shared_ptr<DwarfGenInfo> info,
361364
}
362365

363366
for (std::size_t i = 0; i < frame->memqty; ++i) {
364-
auto name = get_member_name2(frame->members[i].id);
367+
auto name = get_member_name(frame->members[i].id);
365368

366369
// Ignore these special 'variables'
367370
if (name == " s" || name == " r") {
@@ -387,7 +390,7 @@ static void add_disassembler_func_info(std::shared_ptr<DwarfGenInfo> info,
387390
auto member_struct = get_sptr(&frame->members[i]);
388391
if (member_struct) {
389392
tinfo_t type;
390-
if (guess_tinfo2(member_struct->id, &type) == GUESS_FUNC_OK) {
393+
if (guess_tinfo(&type, member_struct->id) == GUESS_FUNC_OK) {
391394
auto var_type_die = get_or_add_type(dbg, cu, type, record);
392395
if (dwarf_add_AT_reference(dbg, die, DW_AT_type, var_type_die, &err) ==
393396
nullptr) {
@@ -432,7 +435,7 @@ static void add_decompiler_func_info(std::shared_ptr<DwarfGenInfo> info,
432435
cfuncptr_t cfunc = decompile(func, &hf);
433436

434437
if (cfunc == nullptr) {
435-
dwarfexport_log("Failed to decompile function at ", func->startEA);
438+
dwarfexport_log("Failed to decompile function at ", func->start_ea);
436439
return;
437440
}
438441

@@ -450,11 +453,11 @@ static void add_decompiler_func_info(std::shared_ptr<DwarfGenInfo> info,
450453
const auto &eamap = cfunc->get_eamap();
451454
ea_t previous_line_addr = 0;
452455
for (std::size_t i = 0; i < sv.size(); ++i, ++linecount) {
453-
char buf[MAXSTR];
454-
const char *line = sv[i].line.c_str();
455-
tag_remove(line, buf, MAXSTR);
456+
qstring buf;
457+
qstring line = sv[i].line;
458+
tag_remove(&buf, line);
456459

457-
auto stripped_buf = std::string(buf);
460+
auto stripped_buf = std::string(buf.c_str());
458461
file << stripped_buf + "\n";
459462

460463
dwarfexport_log("Processing line: ", stripped_buf);
@@ -470,7 +473,7 @@ static void add_decompiler_func_info(std::shared_ptr<DwarfGenInfo> info,
470473
// for that.
471474
ea_t lowest_line_addr = 0, highest_line_addr = 0;
472475
for (; index < stripped_buf.size(); ++index) {
473-
if (!cfunc->get_line_item(line, index, true, nullptr, &item, nullptr)) {
476+
if (!cfunc->get_line_item(line.c_str(), index, true, nullptr, &item, nullptr)) {
474477
continue;
475478
}
476479

@@ -484,7 +487,7 @@ static void add_decompiler_func_info(std::shared_ptr<DwarfGenInfo> info,
484487

485488
// The address for this expression is outside of this function,
486489
// so something strange is happening. Just ignore it.
487-
if (addr == (ea_t)-1 || addr < func->startEA || addr > func->endEA) {
490+
if (addr == (ea_t)-1 || addr < func->start_ea || addr > func->end_ea) {
488491
continue;
489492
}
490493

@@ -495,8 +498,8 @@ static void add_decompiler_func_info(std::shared_ptr<DwarfGenInfo> info,
495498
const auto &expr_areaset = bounds.at(eamap.at(addr).at(0));
496499

497500
// TODO: the area set may not be sorted this way
498-
expr_lowest_addr = expr_areaset.getarea(0).startEA;
499-
expr_highest_addr = expr_areaset.lastarea().endEA - 1;
501+
expr_lowest_addr = expr_areaset.getrange(0).start_ea;
502+
expr_highest_addr = expr_areaset.lastrange().end_ea - 1;
500503
}
501504

502505
// In some situations, there are multiple lines that have the same
@@ -560,14 +563,14 @@ static Dwarf_P_Die add_function(std::shared_ptr<DwarfGenInfo> info,
560563
}
561564

562565
// Add function name
563-
auto name = get_long_name(func->startEA);
566+
auto name = get_long_name(func->start_ea);
564567
char *c_name = &*name.begin();
565568

566569
if (dwarf_add_AT_name(die, c_name, &err) == nullptr) {
567570
dwarfexport_error("dwarf_add_AT_name failed: ", dwarf_errmsg(err));
568571
}
569572

570-
auto mangled_name = get_true_name(func->startEA);
573+
auto mangled_name = get_name(func->start_ea);
571574
if (dwarf_add_AT_string(dbg, die, DW_AT_linkage_name, &mangled_name[0],
572575
&err) == nullptr) {
573576
dwarfexport_error("dwarf_add_AT_string failed: ", dwarf_errmsg(err));
@@ -577,7 +580,7 @@ static Dwarf_P_Die add_function(std::shared_ptr<DwarfGenInfo> info,
577580

578581
// Add ret type
579582
tinfo_t func_type_info;
580-
if (get_tinfo2(func->startEA, &func_type_info)) {
583+
if (get_tinfo(&func_type_info, func->start_ea)) {
581584
auto rettype = func_type_info.get_rettype();
582585
auto rettype_die = get_or_add_type(dbg, cu, rettype, record);
583586
if (dwarf_add_AT_reference(dbg, die, DW_AT_type, rettype_die, &err) ==
@@ -587,10 +590,10 @@ static Dwarf_P_Die add_function(std::shared_ptr<DwarfGenInfo> info,
587590
}
588591

589592
// Add function bounds
590-
dwarf_add_AT_targ_address(dbg, die, DW_AT_low_pc, func->startEA, 0, &err);
591-
dwarf_add_AT_targ_address(dbg, die, DW_AT_high_pc, func->endEA - 1, 0, &err);
593+
dwarf_add_AT_targ_address(dbg, die, DW_AT_low_pc, func->start_ea, 0, &err);
594+
dwarf_add_AT_targ_address(dbg, die, DW_AT_high_pc, func->end_ea - 1, 0, &err);
592595

593-
auto is_named = has_name(getFlags(func->startEA));
596+
auto is_named = has_name(get_flags(func->start_ea));
594597
if (has_decompiler && options.use_decompiler() &&
595598
(!options.only_decompile_named_funcs() ||
596599
(options.only_decompile_named_funcs() && is_named))) {
@@ -600,7 +603,7 @@ static Dwarf_P_Die add_function(std::shared_ptr<DwarfGenInfo> info,
600603
dwarf_add_AT_unsigned_const(dbg, die, DW_AT_decl_line, linecount, &err);
601604

602605
// The start of every function should have a line entry
603-
dwarf_add_line_entry(dbg, file_index, func->startEA, linecount, 0, true,
606+
dwarf_add_line_entry(dbg, file_index, func->start_ea, linecount, 0, true,
604607
false, &err);
605608

606609
add_decompiler_func_info(info, cu, die, func, file, linecount, file_index,
@@ -624,7 +627,7 @@ void add_structures(Dwarf_P_Debug dbg, Dwarf_P_Die cu, type_record_t &record) {
624627
auto tid = get_struc_by_idx(idx);
625628
tinfo_t type;
626629

627-
if (guess_tinfo2(tid, &type) == GUESS_FUNC_OK) {
630+
if (guess_tinfo(&type, tid) == GUESS_FUNC_OK) {
628631
get_or_add_type(dbg, cu, type, record);
629632
}
630633
}
@@ -646,26 +649,28 @@ void add_global_variables(Dwarf_P_Debug dbg, Dwarf_P_Die cu,
646649
continue;
647650
}
648651

649-
for (auto addr = seg->startEA; addr < seg->endEA; ++addr) {
650-
char name[MAXSTR];
651-
if (!get_name(BADADDR, addr, name, MAXSTR)) {
652+
for (auto addr = seg->start_ea; addr < seg->end_ea; ++addr) {
653+
qstring name;
654+
if (!get_name(&name, addr)) {
652655
continue;
653656
}
654657

655658
tinfo_t type;
656-
if (guess_tinfo2(addr, &type) != GUESS_FUNC_OK) {
659+
if (guess_tinfo(&type, addr) != GUESS_FUNC_OK) {
657660
continue;
658661
}
659662

660663
dwarfexport_log("Adding global variable");
661-
dwarfexport_log(" name = ", name);
664+
std::string lname(name.c_str());
665+
dwarfexport_log(" name = ", lname);
666+
662667
dwarfexport_log(" location = ", addr);
663668

664669
auto die =
665670
dwarf_new_die(dbg, DW_TAG_variable, cu, NULL, NULL, NULL, &err);
666671
auto var_type_die = get_or_add_type(dbg, cu, type, record);
667672

668-
if (dwarf_add_AT_name(die, name, &err) == NULL) {
673+
if (dwarf_add_AT_name(die, const_cast<char*>(name.c_str()), &err) == NULL) {
669674
dwarfexport_error("dwarf_add_AT_name failed: ", dwarf_errmsg(err));
670675
}
671676

@@ -729,23 +734,24 @@ void add_debug_info(std::shared_ptr<DwarfGenInfo> info,
729734
continue;
730735
}
731736

732-
char segname[MAXSTR];
733-
get_true_segm_name(seg, segname, sizeof(segname));
734-
dwarfexport_log("Adding functions from: ", segname);
737+
qstring segname;
738+
get_segm_name(&segname, seg);
739+
std::string lsegname(segname.c_str());
740+
dwarfexport_log("Adding functions from: ", lsegname);
735741

736-
func_t *f = get_func(seg->startEA);
742+
func_t *f = get_func(seg->start_ea);
737743
if (f == nullptr) {
738744
// In some cases, the start of the section may not actually be a function,
739745
// so get the first available function.
740-
f = get_next_func(seg->startEA);
746+
f = get_next_func(seg->start_ea);
741747

742748
if (f == nullptr) {
743749
dwarfexport_error("get_next_func() failed");
744750
}
745751
}
746752

747-
for (; f != nullptr; f = get_next_func(f->startEA)) {
748-
if (f->startEA > seg->endEA) {
753+
for (; f != nullptr; f = get_next_func(f->start_ea)) {
754+
if (f->start_ea > seg->end_ea) {
749755
break;
750756
}
751757

@@ -775,7 +781,7 @@ int idaapi init(void) {
775781
return PLUGIN_OK;
776782
}
777783

778-
void idaapi run(int) {
784+
bool idaapi run(size_t) {
779785
try {
780786
auto default_options =
781787
(has_decompiler) ? Options::ATTACH_DEBUG_INFO | Options::USE_DECOMPILER
@@ -799,7 +805,7 @@ void idaapi run(int) {
799805
"<Attach Debug Info:C>\n"
800806
"<Verbose:C>>\n";
801807

802-
if (AskUsingForm_c(dialog, options.filepath, &options.export_options) ==
808+
if (ask_form(dialog, options.filepath, &options.export_options) ==
803809
1) {
804810

805811
if (options.verbose()) {

src/dwarfexport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <fstream>
66
#include <hexrays.hpp>
77
#include <iostream>
8-
#include <libdwarf/libdwarf.h>
8+
#include <libdwarf.h>
99
#include <memory>
1010
#include <sstream>
1111
#include <stdexcept>

src/dwarfgen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ std::shared_ptr<DwarfGenInfo> generate_dwarf_object(const Options &options) {
118118
const char *isa_name = (info->mode == Mode::BIT32) ? "x86" : "x86_64";
119119

120120
const char *dwarf_version = "V2";
121-
int endian = (inf.mf) ? DW_DLC_TARGET_BIGENDIAN : DW_DLC_TARGET_LITTLEENDIAN;
121+
int endian = (inf.is_be()) ? DW_DLC_TARGET_BIGENDIAN : DW_DLC_TARGET_LITTLEENDIAN;
122122
Dwarf_Ptr errarg = 0;
123123

124124
decltype(&attached_info_callback) callback;

0 commit comments

Comments
 (0)