Skip to content

Commit

Permalink
core: add label name in comment, ui_qt: add basic a context menu in d…
Browse files Browse the repository at this point in the history
…isasm view
  • Loading branch information
wisk committed Apr 22, 2012
1 parent 9e0c0d9 commit 584b473
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 9 deletions.
9 changes: 9 additions & 0 deletions src/arch/x86/x86_format_operand.cpp
Expand Up @@ -17,6 +17,8 @@ void X86Architecture::FormatOperand(std::ostringstream &rInsnBuf, Database const
rInsn.AddMark(Cell::Mark::LabelType, OprdLabel.GetLabel().length());
rInsn.AddMark(Cell::Mark::OperatorType, 1);
rInsnBuf << ValueName.str();
if (rInsn.GetComment().empty())
rInsn.SetComment(OprdLabel.GetName());
return;
}
}
Expand All @@ -29,6 +31,8 @@ void X86Architecture::FormatOperand(std::ostringstream &rInsnBuf, Database const
{
ValueName << OprdLabel.GetLabel();
rInsn.AddMark(Cell::Mark::LabelType, ValueName.str().length());
if (rInsn.GetComment().empty())
rInsn.SetComment(OprdLabel.GetName());
}
else
{
Expand Down Expand Up @@ -63,6 +67,8 @@ void X86Architecture::FormatOperand(std::ostringstream &rInsnBuf, Database const
{
ValueName << OprdLabel.GetLabel();
rInsn.AddMark(Cell::Mark::LabelType, ValueName.str().length());
if (rInsn.GetComment().empty())
rInsn.SetComment(OprdLabel.GetName());
}
else
{
Expand Down Expand Up @@ -155,6 +161,9 @@ void X86Architecture::FormatOperand(std::ostringstream &rInsnBuf, Database const
{
ValueName << Lbl.GetLabel();
MarkType = Cell::Mark::LabelType;

if (rInsn.GetComment().empty())
rInsn.SetComment(Lbl.GetName());
}
else
{
Expand Down
10 changes: 8 additions & 2 deletions src/core/architecture.cpp
Expand Up @@ -72,13 +72,16 @@ void Architecture::DefaultFormatInstruction(Database const& rDatabase,

if (rInsn.GetOperandReference(rDatabase, 0, rAddr, DstAddr))
{
OprdName = rDatabase.GetLabelFromAddress(DstAddr).GetLabel();
Label Lbl = rDatabase.GetLabelFromAddress(DstAddr);
OprdName = Lbl.GetLabel();
Cell::Mark::Type MarkType = Cell::Mark::LabelType;

if (OprdName.empty()) { OprdName = DstAddr.ToString(); MarkType = Cell::Mark::ImmediateType; }

oss << OprdName;
rInsn.AddMark(MarkType, OprdName.length());
if (rInsn.GetComment().empty())
rInsn.SetComment(Lbl.GetName());
}
else
{
Expand All @@ -97,7 +100,8 @@ void Architecture::DefaultFormatInstruction(Database const& rDatabase,
}

Address OprdAddr(Address::UnknownType, pOprd->GetSegValue(), pOprd->GetValue());
std::string LabelName = rDatabase.GetLabelFromAddress(OprdAddr).GetLabel();
Label Lbl = rDatabase.GetLabelFromAddress(OprdAddr);
std::string LabelName = Lbl.GetLabel();

if (LabelName.empty())
{
Expand All @@ -109,6 +113,8 @@ void Architecture::DefaultFormatInstruction(Database const& rDatabase,

oss << LabelName;
rInsn.AddMark(Cell::Mark::LabelType, LabelName.length());
if (rInsn.GetComment().empty())
rInsn.SetComment(Lbl.GetName());
}

else if (OprdType & O_REG)
Expand Down
10 changes: 5 additions & 5 deletions src/ldr/elf/elf_interpreter.hpp
Expand Up @@ -32,7 +32,7 @@ template<int n> class ElfInterpreter

Address GetEntryPoint(void)
{
return m_Ehdr.e_entry;
return Address(Address::FlatType, 0x0, m_Ehdr.e_entry, 0x10, n);;
}

void Map(void)
Expand Down Expand Up @@ -296,7 +296,7 @@ template<int n> class ElfInterpreter
typename TElfType::Addr FuncPlt;
rBinStrm.Read(FuncOff, FuncPlt);

Address FuncPltAddr(Address::FlatType, 0x0, FuncPlt, 0, sizeof(n) * 8);
Address FuncPltAddr(Address::FlatType, 0x0, FuncPlt, 0, n);
FuncPlt &= ~0xf;

Log::Write("ldr_elf")
Expand All @@ -306,7 +306,7 @@ template<int n> class ElfInterpreter
<< ", name=" << pDynSymStr + CurSym.st_name
<< LogEnd;

Address FuncAddr(Address::FlatType, 0x0, static_cast<TOffset>(pRel->r_offset), 0, sizeof(n) * 8);
Address FuncAddr(Address::FlatType, 0x0, static_cast<TOffset>(pRel->r_offset), 0, n);
std::string FuncName(pDynSymStr + CurSym.st_name);

m_rDatabase.AddLabel(FuncAddr, Label(FuncName, Label::LabelData | Label::LabelImported));
Expand Down Expand Up @@ -347,7 +347,7 @@ template<int n> class ElfInterpreter
<< ", name=" << pDynSymStr + CurSym.st_name
<< LogEnd;

Address FuncAddr(static_cast<TOffset>(pRela->r_offset));
Address FuncAddr(Address::FlatType, 0x0, static_cast<TOffset>(pRela->r_offset), 0x10, n);
std::string FuncName(pDynSymStr + CurSym.st_name);

m_rDatabase.AddLabel(FuncAddr, Label(FuncName, Label::LabelData | Label::LabelImported));
Expand Down Expand Up @@ -378,7 +378,7 @@ template<int n> class ElfInterpreter
<< ", name=" << pDynSymStr + CurSym.st_name
<< LogEnd;

Address SymAddr(static_cast<TOffset>(pRela->r_offset));
Address SymAddr(Address::FlatType, 0x0, static_cast<TOffset>(pRela->r_offset), 0x10, n);
std::string SymName(pDynSymStr + CurSym.st_name);

// TODO: Use ELFXX_ST_TYPE instead
Expand Down
26 changes: 24 additions & 2 deletions src/ui/qt/DisassemblyView.cpp
Expand Up @@ -20,6 +20,8 @@ DisassemblyView::DisassemblyView(QWidget * parent)
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
connect(&_cursorTimer, SIGNAL(timeout()), this, SLOT(updateCursor()));
_cursorTimer.setInterval(400);
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(QPoint const &)), this, SLOT(showContextMenu(QPoint const &)));
}

DisassemblyView::~DisassemblyView(void)
Expand Down Expand Up @@ -63,6 +65,21 @@ void DisassemblyView::updateCursor(void)
emit listingUpdated();
}

void DisassemblyView::showContextMenu(QPoint const & pos)
{
if (_db == nullptr) return;

QMenu menu;
QPoint globalPos = viewport()->mapToGlobal(pos);

medusa::Address selectedAddress;
if (!convertPositionToAddress(pos, selectedAddress)) return;

menu.addAction(QString::fromStdString(selectedAddress.ToString()));

QAction * selectedItem = menu.exec(globalPos);
}

void DisassemblyView::paintEvent(QPaintEvent * evt)
{
QPainter p(viewport());
Expand Down Expand Up @@ -691,13 +708,18 @@ void DisassemblyView::updateScrollbars(void)
horizontalScrollBar()->setMaximum(_lineLen);
}

bool DisassemblyView::convertMouseToAddress(QMouseEvent * evt, medusa::Address & addr)
bool DisassemblyView::convertPositionToAddress(QPoint const & pos, medusa::Address & addr)
{
int line = evt->pos().y() / _hChar + verticalScrollBar()->value();
int line = pos.y() / _hChar + verticalScrollBar()->value();
medusa::Database::View::LineInformation lineInfo;

if (!_db->GetView().GetLineInformation(line, lineInfo)) return false;

addr = lineInfo.GetAddress();
return true;
}

bool DisassemblyView::convertMouseToAddress(QMouseEvent * evt, medusa::Address & addr)
{
return convertPositionToAddress(evt->pos(), addr);
}
2 changes: 2 additions & 0 deletions src/ui/qt/DisassemblyView.hpp
Expand Up @@ -33,6 +33,7 @@ public slots:
void setFont(QFont const & font);
void listingUpdated(void);
void updateCursor(void);
void showContextMenu(QPoint const& pos);

protected:
virtual void paintEvent(QPaintEvent * evt);
Expand All @@ -58,6 +59,7 @@ public slots:
void setSelection(int x, int y);
void moveSelection(int x, int y);
void updateScrollbars(void);
bool convertPositionToAddress(QPoint const & pos, medusa::Address & addr);
bool convertMouseToAddress(QMouseEvent * evt, medusa::Address & addr);

medusa::Database const * _db;
Expand Down

0 comments on commit 584b473

Please sign in to comment.