Skip to content

Commit

Permalink
Merge branch 'master' into feature/netlist_traversal_decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
SJulianS authored May 13, 2024
2 parents 753ebea + 5d65ebc commit 4aba3f3
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 7 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ We want HAL to enable a common baseline for researchers and analysts to improve
- **Stability** is ensured via a rich test suite

HAL is actively developed by the Embedded Security group of the [Max Planck Institute for Security and Privacy](https://www.mpi-sp.org).
Apart from multiple research projects, it is also used in our university lecture [Introduction to Hardware Reverse Engineering](https://www.ei.ruhr-uni-bochum.de/studium/lehrveranstaltungen/832/).
Apart from multiple research projects, it is also used in our university lecture "Einführung ins Hardware Reverse Engineering" (Introduction to Hardware Reverse Engineering) at Ruhr University Bochum (RUB).

Note that we also have a set of **modern** state-of-the-art benchmark circuits for the evaluation of netlist reverse engineering techniques available in a seperate [repository](https://github.com/emsec/hal-benchmarks).

Expand All @@ -54,9 +54,6 @@ This repository contains a selection of curated plugins:
## Documentation
A comprehensive documentation of HAL's features from a user perspective is available in our [Wiki](https://github.com/emsec/hal/wiki). In addition, we provide a full [C++ API](https://emsec.github.io/hal/doc/) and [Python API](https://emsec.github.io/hal/pydoc/) documentation.

## Slack, Contact and Support
For all kinds of inquiries, please contact us using our dedicated e-mail address: ![email address image](https://raw.githubusercontent.com/emsec/hal/master/.github/email-address-image.gif "Mail")

<a name="build-instructions"></a>
# Build Instructions

Expand Down
2 changes: 2 additions & 0 deletions plugins/gui/include/gui/gui_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ namespace hal
{
public:
GridPlacement() {;}
GridPlacement(const QHash<hal::Node,QPoint>& data) : QHash<hal::Node,QPoint>(data) {;}

void setGatePosition(u32 gateId, std::pair<int,int>p, bool swap = false) {
QPoint pos = QPoint(gatePosition(gateId)->first, gatePosition(gateId)->second); //position of current gate to move
hal::Node nd = key(QPoint(p.first, p.second)); //find the node in the destination
Expand Down
3 changes: 3 additions & 0 deletions plugins/gui/include/gui/user_action/user_action.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ namespace hal
static QString setToText(const QSet<u32>& set);
static QSet<u32> setFromText(const QString& s);

static QString gridToText(const QHash<hal::Node,QPoint>& grid);
static QHash<hal::Node,QPoint> gridFromText(const QString& txt);

/**
* Utility function to write the parent object.
* (Also checks if it is even necessary)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "gui/graph_widget/layouters/standard_graph_layouter.h"

#include "hal_core/utilities/log.h"
#include "gui/implementations/qpoint_extension.h"
#include "gui/graph_widget/layouters/position_generator.h"
#include "gui/graph_widget/layouters/wait_to_be_seated.h"
Expand Down Expand Up @@ -27,7 +28,17 @@ namespace hal

void StandardGraphLayouter::add(const QSet<u32> modules, const QSet<u32> gates, const QSet<u32> nets, PlacementHint placement)
{
switch(placement.mode())
PlacementHint::PlacementModeType pmtype = placement.mode();

if ((pmtype == PlacementHint::PreferLeft || pmtype == PlacementHint::PreferRight) &&
(!placement.preferredOrigin().id() || placement.preferredOrigin().type() == Node::None))
{
log_warning("gui", "Ignoring placement hint {} since no valid reference node was provided.",
(pmtype == PlacementHint::PreferLeft ? "PreferLeft" : "PreferRight"));
pmtype = PlacementHint::Standard;
}

switch(pmtype)
{
case PlacementHint::Standard:
addCompact(modules, gates, nets);
Expand Down
18 changes: 16 additions & 2 deletions plugins/gui/src/user_action/action_add_items_to_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,23 @@ namespace hal
void ActionAddItemsToObject::writeToXml(QXmlStreamWriter& xmlOut) const
{
writeParentObjectToXml(xmlOut);
if (mPlacementHint.mode() != PlacementHint::Standard)

UserActionObjectType::ObjectType tp = UserActionObjectType::fromNodeType(mPlacementHint.preferredOrigin().type());
switch (mPlacementHint.mode())
{
UserActionObjectType::ObjectType tp = UserActionObjectType::fromNodeType(mPlacementHint.preferredOrigin().type());
case PlacementHint::Standard:
break;
case PlacementHint::PreferLeft:
case PlacementHint::PreferRight:
xmlOut.writeStartElement("placement");
xmlOut.writeAttribute("id", QString::number(mPlacementHint.preferredOrigin().id()));
xmlOut.writeAttribute("type", UserActionObjectType::toString(tp));
xmlOut.writeAttribute("mode", mPlacementHint.mode() == PlacementHint::PreferLeft ? "left" : "right");
xmlOut.writeEndElement();
break;
case PlacementHint::GridPosition:
xmlOut.writeTextElement("gridposition", gridToText(mPlacementHint.gridPosition()));
break;
}
if (!mModules.isEmpty())
xmlOut.writeTextElement("modules", setToText(mModules));
Expand All @@ -74,6 +83,11 @@ namespace hal
mPlacementHint = PlacementHint(mode, Node(id, UserActionObjectType::toNodeType(tp)));
xmlIn.skipCurrentElement(); // no text body to read
}
else if (xmlIn.name() == "gridposition")
{
GridPlacement gp(gridFromText(xmlIn.readElementText()));
mPlacementHint = PlacementHint(gp);
}
else if (xmlIn.name() == "modules")
mModules = setFromText(xmlIn.readElementText());
else if (xmlIn.name() == "gates")
Expand Down
40 changes: 40 additions & 0 deletions plugins/gui/src/user_action/user_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,46 @@ namespace hal
return retval;
}

QString UserAction::gridToText(const QHash<hal::Node,QPoint>& grid)
{
QString retval;
for (auto it = grid.constBegin(); it!= grid.constEnd(); ++it)
{
if (!retval.isEmpty()) retval += ',';
retval += QString("%1%2:%3:%4")
.arg(it.key().type()==hal::Node::Module?'M':'G')
.arg(it.key().id())
.arg(it.value().x())
.arg(it.value().y());
}
return retval;
}

QHash<hal::Node,QPoint> UserAction::gridFromText(const QString& txt)
{
QHash<hal::Node,QPoint> retval;
for (QString s : txt.split(','))
{
if (s.isEmpty()) continue;
hal::Node::NodeType tp = hal::Node::None;
switch (s.at(0).unicode())
{
case 'M':
tp = hal::Node::Module;
break;
case 'G':
tp = hal::Node::Gate;
break;
default:
continue;
}
QStringList num = s.mid(1).split(':');
if (num.size() != 3) continue;
retval.insert(hal::Node(num.at(0).toUInt(),tp),QPoint(num.at(1).toInt(),num.at(2).toInt()));
}
return retval;
}

void UserAction::writeParentObjectToXml(QXmlStreamWriter &xmlOut) const
{
if(mParentObject.type() != UserActionObjectType::None)
Expand Down

0 comments on commit 4aba3f3

Please sign in to comment.