Exemplo n.º 1
0
LabelDialog::LabelDialog(QWidget * pParent, medusa::Medusa& rCore, medusa::Address const& rAddress)
  : QDialog(pParent), m_rCore(rCore), m_rAddress(rAddress)
{
  this->setupUi(this);
  connect(ButtonBox, SIGNAL(accepted()), SLOT(SetLabel()));
  connect(ButtonBox, SIGNAL(rejected()), SLOT(close()));

  medusa::Label const& rCurLbl = rCore.GetDocument().GetLabelFromAddress(rAddress);
  LabelName->setText(QString::fromStdString(rCurLbl.GetName()));

  switch (rCurLbl.GetType() & medusa::Label::CellMask)
  {
  default:
  case medusa::Label::Data:     DataButton->setChecked(true);   break;
  case medusa::Label::Code:     CodeButton->setChecked(true);   break;
  case medusa::Label::String:   StringButton->setChecked(true); break;
  case medusa::Label::Function: FunctionButton->setChecked(true); break;
  }

  switch (rCurLbl.GetType() & medusa::Label::AccessMask)
  {
  default:
  case medusa::Label::Local:  LocalButton->setChecked(true);  break;
  case medusa::Label::Global: GlobalButton->setChecked(true); break;
  }
}
Exemplo n.º 2
0
MemoryAreaView::MemoryAreaView(QWidget * parent, medusa::Medusa &core)
  : QTreeView(parent)
  , View(medusa::Document::Subscriber::MemoryAreaUpdated, core.GetDocument())
  , _core(core)
{
  qRegisterMetaType<medusa::MemoryArea*>("MemoryArea");
  setEditTriggers(QAbstractItemView::NoEditTriggers);
  auto model = new QStandardItemModel(this);
  model->setColumnCount(4);
  model->setHeaderData(0, Qt::Horizontal, "Name");
  model->setHeaderData(1, Qt::Horizontal, "Address");
  model->setHeaderData(2, Qt::Horizontal, "Size");
  model->setHeaderData(3, Qt::Horizontal, "Access");
  setModel(model);
  connect(this, SIGNAL(doubleClicked(QModelIndex const&)), this, SLOT(onDoubleClickMemoryArea(QModelIndex const&)));
  connect(this, SIGNAL(memoryAreaAdded(medusa::MemoryArea const&)), this, SLOT(onAddMemoryArea(medusa::MemoryArea const&)));
}
Exemplo n.º 3
0
LabelView::LabelView(QWidget * parent, medusa::Medusa &core)
  : QTreeView(parent), View(medusa::Document::Subscriber::LabelUpdated, core.GetDocument())
  , _core(core)
{
  setUniformRowHeights(false);
  qRegisterMetaType<medusa::Address>("Address");
  qRegisterMetaType<medusa::Label>("Label");
  setEditTriggers(QAbstractItemView::NoEditTriggers);
  auto model = new QStandardItemModel(this);
  model->setColumnCount(3);
  model->setHeaderData(0, Qt::Horizontal, "Name");
  model->setHeaderData(1, Qt::Horizontal, "Type");
  model->setHeaderData(2, Qt::Horizontal, "Address");
  setModel(model);
  connect(this, SIGNAL(doubleClicked(QModelIndex const&)),  this, SLOT(onDoubleClickLabel(QModelIndex const&)));
  connect(this, SIGNAL(labelAdded(medusa::Address const&, medusa::Label const&)),   this, SLOT(onAddLabel(medusa::Address const&, medusa::Label const&)));
  connect(this, SIGNAL(labelRemoved(medusa::Address const&, medusa::Label const&)), this, SLOT(onRemoveLabel(medusa::Address const&, medusa::Label const&)));
}
Exemplo n.º 4
0
ControlFlowGraphScene::ControlFlowGraphScene(QObject * parent, medusa::Medusa& core, medusa::Address const& cfgAddr)
  : QGraphicsScene(parent)
  , _core(core)
{
  ogdf::Graph graph;
  ogdf::GraphAttributes graphAttr(graph, ogdf::GraphAttributes::nodeGraphics | ogdf::GraphAttributes::edgeGraphics);


  medusa::ControlFlowGraph cfg;
  core.BuildControlFlowGraph(cfgAddr, cfg);

  qreal maxBbWidth = 0.0, maxBbHeight = 0.0;

  QFontMetrics fm(font());
  std::map<ogdf::node,  BasicBlockItem*> nodes;
  std::map<ogdf::edge,  EdgeItem*      > edges;
  std::map<medusa::u64, ogdf::node     > usedBscBlock;
  auto addBscBlk = [&](medusa::u64 bbId) -> BasicBlockItem*
  {
    auto itBscBlk = usedBscBlock.find(bbId);
    if (itBscBlk != std::end(usedBscBlock))
      return nodes[ usedBscBlock[ bbId ] ];
      
    auto bbItem = new BasicBlockItem(this, _core, cfg.GetGraph()[bbId].GetAddresses());
    auto newNode = graph.newNode();
    auto rect = bbItem->boundingRect();
    graphAttr.width()[newNode]  = rect.width();
    graphAttr.height()[newNode] = rect.height();
    maxBbWidth  = std::max(maxBbWidth,  rect.width());
    maxBbHeight = std::max(maxBbHeight, rect.height());
    nodes[newNode]     = bbItem;
    usedBscBlock[bbId] = newNode;
    return bbItem;
  };

  auto const& g = cfg.GetGraph();

  auto vertexRange = boost::vertices(g);
  for (auto vertexIter = vertexRange.first; vertexIter != vertexRange.second; ++vertexIter)
    addBscBlk(*vertexIter);

  auto edgeRange = boost::edges(g);
  for (auto edgeIter = edgeRange.first; edgeIter != edgeRange.second; ++edgeIter)
  {
    auto srcBb     = addBscBlk(edgeIter->m_source);
    auto tgtBb     = addBscBlk(edgeIter->m_target);
    auto newEdge   = graph.newEdge(usedBscBlock[edgeIter->m_source], usedBscBlock[edgeIter->m_target]);
    auto edgeItem  = new EdgeItem(srcBb, tgtBb, g[*edgeIter].GetType());
    edges[newEdge] = edgeItem;
  }

  auto OHL = new ogdf::OptimalHierarchyLayout;
  OHL->nodeDistance(25.0);
  OHL->layerDistance(50.0);
  OHL->weightBalancing(0.0);
  OHL->weightSegments(0.0);

  ogdf::SugiyamaLayout SL;
  SL.setRanking(new ogdf::OptimalRanking);
  SL.setCrossMin(new ogdf::MedianHeuristic);
  SL.alignSiblings(false);
  SL.setLayout(OHL);
  SL.call(graphAttr);

  for (auto nodeIter = std::begin(nodes); nodeIter != std::end(nodes); ++nodeIter)
  {
    addItem(nodeIter->second);
    QRectF bbRect = nodeIter->second->boundingRect();
    qreal x = graphAttr.x(nodeIter->first) - (bbRect.width()  / 2);
    qreal y = graphAttr.y(nodeIter->first) - (bbRect.height() / 2);
    nodeIter->second->setPos(x, y);
  }

  for (auto edgeIter = std::begin(edges); edgeIter != std::end(edges); ++edgeIter)
  {
    auto const& bends = graphAttr.bends(edgeIter->first);
    edgeIter->second->setBends(bends);
    addItem(edgeIter->second);
  }

  setSceneRect(0, 0, graphAttr.boundingBox().width() + maxBbWidth, graphAttr.boundingBox().height() + maxBbHeight);
}