Skip to content

Commit

Permalink
Merge pull request #57 from stek29/cleanup
Browse files Browse the repository at this point in the history
Cleanup & fixes
  • Loading branch information
matrosov authored Mar 13, 2018
2 parents 0a502d7 + 7a2716e commit 0b8a1c3
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 76 deletions.
8 changes: 4 additions & 4 deletions src/HexRaysCodeXplorer/CodeXplorer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ static bool get_expr_name(citem_t *citem, qstring& rv)
cexpr_t *e = (cexpr_t *)citem;

// retrieve the name of the routine
e->print1(&rv, NULL);
print1wrapper(e, &rv, NULL);
tag_remove(&rv);

return true;
Expand Down Expand Up @@ -484,7 +484,7 @@ static bool idaapi show_offset_in_windbg_format(void *ud) {
show_string_in_custom_view(&vu, title, result);

#if defined (__LINUX__) || defined (__MAC__)
msg(result.c_str());
msg("%s", result.c_str());
#else
OpenClipboard(0);
EmptyClipboard();
Expand Down Expand Up @@ -705,7 +705,7 @@ int idaapi init(void)
for (unsigned i = 0; i < _countof(kActionDescs); ++i)
register_action(kActionDescs[i]);

install_hexrays_callback(callback, nullptr);
install_hexrays_callback((hexrays_cb_t*)callback, nullptr);
logmsg(INFO, "Hex-rays version %s has been detected\n", get_hexrays_version());
inited = true;

Expand Down Expand Up @@ -742,7 +742,7 @@ void idaapi term(void)
if (inited)
{
logmsg(INFO, "\nHexRaysCodeXplorer plugin by @REhints terminated.\n\n\n");
remove_hexrays_callback(callback, NULL);
remove_hexrays_callback((hexrays_cb_t*)callback, NULL);
term_hexrays_plugin();
}
}
Expand Down
45 changes: 45 additions & 0 deletions src/HexRaysCodeXplorer/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,16 @@
#pragma warning(push)
#pragma warning(disable:4309 4244 4267) // disable "truncation of constant value" warning from IDA SDK, conversion from 'ssize_t' to 'int', possible loss of data
#endif // __NT__
#ifndef USE_DANGEROUS_FUNCTIONS
#define USE_DANGEROUS_FUNCTIONS
#endif
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wsign-compare"
#pragma clang diagnostic ignored "-Wvarargs"
#pragma clang diagnostic ignored "-Wlogical-op-parentheses"
#pragma clang diagnostic ignored "-Wunused-private-field"
#endif
#include <hexrays.hpp>
#include <ida.hpp>
#include <idp.hpp>
Expand All @@ -66,6 +75,42 @@
#ifdef __NT__
#pragma warning(pop)
#endif // __NT__
#ifdef __clang__
#pragma clang diagnostic pop
#endif

template<typename T>
struct print1_accepts_qstring
{
template<typename U, void (U::*)(qstring *, const cfunc_t *) const> struct yay_sfinae {};
template<typename U> static char test(yay_sfinae<U, &U::print1>*);
template<typename U> static int test(...);
static const bool value = sizeof(test<T>(0)) == sizeof(char);
};

// For IDA7.1 and newer
template <class T>
void print1wrapper(std::true_type, const T *e, qstring *qbuf, const cfunc_t *func) {
e->print1(qbuf, func);
};

// For older SDKs
template <class T>
void print1wrapper(std::false_type, const T *e, qstring *qbuf, const cfunc_t *func) {
char lbuf[MAXSTR];
const size_t len = e->print1(lbuf, sizeof(lbuf) - 1, func);
qstring temp(lbuf, len);
qbuf->swap(temp);
};

template <class T>
void print1wrapper(const T *e, qstring *qbuf, const cfunc_t *func) {
return print1wrapper(
std::integral_constant<bool, print1_accepts_qstring<T>::value>(),
e, qbuf, func);
}



#include <cstring>
#include <cstdarg>
Expand Down
14 changes: 7 additions & 7 deletions src/HexRaysCodeXplorer/CtreeExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void ctree_dumper_t::parse_ctree_item(citem_t *item, qstring& rv) const
{
case cot_call:
if (e->x->op == cot_obj) {
if (get_func_name(&func_name, e->x->obj_ea) == NULL)
if (get_func_name(&func_name, e->x->obj_ea) == 0)
rv.cat_sprnt(" sub_%a", e->x->obj_ea);
else
rv.cat_sprnt(" %s", func_name.c_str());
Expand All @@ -139,7 +139,7 @@ void ctree_dumper_t::parse_ctree_item(citem_t *item, qstring& rv) const
rv.append(' ');
{
qstring qbuf;
e->print1(&qbuf, NULL);
print1wrapper(e, &qbuf, NULL);
tag_remove(&qbuf);
rv += qbuf;
}
Expand Down Expand Up @@ -262,14 +262,14 @@ void dump_ctrees_in_file(std::map<ea_t, ctree_dump_line> &data_to_dump, const qs
dump_line.cat_sprnt(";%08X", cdl.func_start);
dump_line.cat_sprnt(";%08X", cdl.func_end);
if ((cdl.func_name.length() > crypt_prefix_len) && (crypt_prefix_len > 0) && (cdl.func_name.find(crypto_prefix) == 0))
dump_line.cat_sprnt(";E", cdl.func_end);
dump_line.cat_sprnt(";E");
else
dump_line.cat_sprnt(";N", cdl.func_end);
dump_line.cat_sprnt(";N");

if ((cdl.heuristic_flag))
dump_line.cat_sprnt(";H", cdl.func_end);
dump_line.cat_sprnt(";H");
else
dump_line.cat_sprnt(";N", cdl.func_end);
dump_line.cat_sprnt(";N");

dump_line += "\n";

Expand Down Expand Up @@ -390,7 +390,7 @@ bool idaapi extract_all_ctrees(void *ud)
va_end(va);

qstring crypto_prefix = kDefaultPrefix;
if (!ask_str(&crypto_prefix, NULL, "Enter prefix of crypto function names", va))
if (!ask_str(&crypto_prefix, 0, "Enter prefix of crypto function names", va))
return false;

if(!crypto_prefix.empty()) {
Expand Down
2 changes: 1 addition & 1 deletion src/HexRaysCodeXplorer/CtreeGraphBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void callgraph_t::get_node_label(int n, qstring& rv) const
rv.append(' ');
{
qstring qbuf;
e->print1(&qbuf, nullptr);
print1wrapper(e, &qbuf, nullptr);
tag_remove(&qbuf);
rv += qbuf;
}
Expand Down
2 changes: 1 addition & 1 deletion src/HexRaysCodeXplorer/CtreeGraphBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class callgraph_t

callgraph_t();

const int count() const { return node_count; }
int count() const { return node_count; }

// node / func info
struct nodeinfo_t
Expand Down
2 changes: 1 addition & 1 deletion src/HexRaysCodeXplorer/GCCObjectFormatParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace GCC_RTTI {
#pragma pack(push, 1)

struct __vtable_info {
size_t ptrdiff;
ssize_t ptrdiff;
ea_t type_info;
ea_t origin[1];
};
Expand Down
7 changes: 5 additions & 2 deletions src/HexRaysCodeXplorer/GCCTypeInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
#include "offset.hpp"
#include "Utility.h"


#if __clang__
// Ignore "offset of on non-standard-layout type" warning
#pragma clang diagnostic ignored "-Winvalid-offsetof"
#endif


GCCTypeInfo::GCCTypeInfo()
Expand Down Expand Up @@ -156,4 +159,4 @@ GCCTypeInfo *GCCTypeInfo::parseTypeInfo(ea_t ea)
}
g_KnownTypes[ea] = result;
return result;
}
}
4 changes: 2 additions & 2 deletions src/HexRaysCodeXplorer/Linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
#define BOOL bool
#define TRUE true
#define FALSE false
#define LPCSTR char *const
#define LPCTSTR char *const
#define LPCSTR const char *
#define LPCTSTR const char *
#define LPSTR char *
#define WORD uint16_t
#define DWORD uint32_t
Expand Down
14 changes: 7 additions & 7 deletions src/HexRaysCodeXplorer/TypeExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int idaapi obj_fint_t::visit_expr(cexpr_t *e)

// get the variable name
qstring s;
e->print1(&s, NULL);
print1wrapper(e, &s, NULL);
tag_remove(&s);

// check for the target variable
Expand All @@ -84,7 +84,7 @@ int idaapi obj_fint_t::visit_expr(cexpr_t *e)

if (target_expr->op == cot_var) {
s.clear();
target_expr->print1(&s, NULL);
print1wrapper(target_expr, &s, NULL);
tag_remove(&s);

var_name = s;
Expand All @@ -99,7 +99,7 @@ int idaapi obj_fint_t::visit_expr(cexpr_t *e)

void idaapi reset_pointer_type(cfuncptr_t cfunc, const qstring &var_name) {
lvars_t * locals = cfunc->get_lvars();
if (!locals != NULL)
if (locals == NULL)
return;

qvector<lvar_t>::iterator locals_iter;
Expand Down Expand Up @@ -137,7 +137,7 @@ bool idaapi find_var(void *ud)
cexpr_t *highl_expr = (cexpr_t *)highlight;

qstring s;
highlight->print1(&s, NULL);
print1wrapper(highlight, &s, NULL);
tag_remove(&s);

// initialize type rebuilder
Expand Down Expand Up @@ -296,7 +296,7 @@ void idaapi dump_type_info(int file_id, const VTBL_info_t& vtbl_info, const qstr
qstring line;

line = key_hash + ";" + file_entry_key + ";";
line.cat_sprnt("%p;", vtbl_info.ea_begin);
line.cat_sprnt("%a;", vtbl_info.ea_begin);
line += file_entry_val + ";";

if (rtti_vftables.count(vtbl_info.ea_begin) != 0) {
Expand All @@ -311,7 +311,7 @@ void idaapi dump_type_info(int file_id, const VTBL_info_t& vtbl_info, const qstr

bool idaapi check_subtype(VTBL_info_t vtbl_info, qstring subtype_name) {
qstring search_str;
search_str.sprnt("_%p", vtbl_info.ea_begin);
search_str.sprnt("_%a", vtbl_info.ea_begin);

struc_t * struc_type = get_struc(get_struc_id(subtype_name.c_str()));
if (!struc_type)
Expand Down Expand Up @@ -399,7 +399,7 @@ bool idaapi extract_all_types(void *ud)
}
}
else {
info_msg.cat_sprnt(" : none\n", var_name.c_str());
info_msg.cat_sprnt(" : none\n");
logmsg(DEBUG, info_msg.c_str());
}
}
Expand Down
Loading

0 comments on commit 0b8a1c3

Please sign in to comment.