Skip to content

Commit

Permalink
Show enums in palette
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinmo committed Mar 2, 2021
1 parent 8ca4448 commit 9019646
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
42 changes: 34 additions & 8 deletions palette/src/ida/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ void addStructs(QVector<Action>& result)
}
}

void addEnums(QVector<Action>& result) {
size_t cnt = get_enum_qty();
for (size_t i = 0; i < cnt; i++) {
enum_t n = getn_enum(i);
result.push_back(Action{ "struct:" + QString::number(n),
QString::fromStdString(get_nice_struc_name(n).c_str()), QString() });
}
}

class NamesManager {
QHash<ea_t, int> address_to_name;
QHash<tid_t, int> address_to_struct;
Expand Down Expand Up @@ -219,16 +228,18 @@ class NamesManager {
}
}

void struc_rename(tid_t id, const char* name) {
void update_struct(tid_t id, const char* name) {
if (result.empty()) return; // Not initialized yet

auto it = address_to_struct.find(id);
if (it == address_to_struct.end()) {
if (result.empty()) return; // Not initialized yet
result.push_back(Action{ "struct:" + QString::number(id), name, QString() });
address_to_struct.insert(id, result.size() - 1);
}

Action &action = result[it.value()];
action.name = QString::fromStdString(name);
}
else {
Action& action = result[it.value()];
action.name = QString::fromStdString(name);
}
}

void clear() {
Expand All @@ -253,6 +264,9 @@ class NamesManager {
// 2. Add structs from IDA
addStructs(result);

// 3. Add enums from IDA
addEnums(result);

init(&result);

return result;
Expand All @@ -278,8 +292,16 @@ class NamesManager {
{
auto struc = va_arg(va, struc_t*);
if (struc)
manager->struc_rename(
manager->update_struct(
struc->id, get_nice_struc_name(struc->id).c_str());
break;
}
case idb_event::struc_created:
case idb_event::enum_created:
case idb_event::enum_renamed:
{
auto tid = va_arg(va, tid_t);
manager->update_struct(tid, get_nice_struc_name(tid).c_str());
}
}
return 0;
Expand Down Expand Up @@ -343,7 +365,11 @@ class name_palette_handler : public action_handler_t

if (id.startsWith("struct:"))
{
open_structs_window(id.midRef(7).toULongLong());
auto tid = id.midRef(7).toULongLong();
if (get_enum_idx(tid) == -1)
open_structs_window(tid);
else
open_enums_window(tid);
}
else
{
Expand Down
1 change: 1 addition & 0 deletions palette/src/ida/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
#include <registry.hpp>
#include <moves.hpp>
#include <typeinf.hpp>
#include <enum.hpp>

0 comments on commit 9019646

Please sign in to comment.