2019-02-22 16:50:45 +00:00
|
|
|
#include "core/MainWindow.h"
|
2019-01-13 14:20:07 +00:00
|
|
|
#include "CutterSeekable.h"
|
|
|
|
|
|
|
|
#include <QPlainTextEdit>
|
|
|
|
|
2021-01-24 14:50:13 +00:00
|
|
|
CutterSeekable::CutterSeekable(QObject *parent) : QObject(parent)
|
2019-01-13 14:20:07 +00:00
|
|
|
{
|
|
|
|
connect(Core(), &CutterCore::seekChanged, this, &CutterSeekable::onCoreSeekChanged);
|
|
|
|
}
|
|
|
|
|
|
|
|
CutterSeekable::~CutterSeekable() {}
|
|
|
|
|
2019-06-18 13:02:41 +00:00
|
|
|
void CutterSeekable::setSynchronization(bool sync)
|
|
|
|
{
|
|
|
|
synchronized = sync;
|
|
|
|
onCoreSeekChanged(Core()->getOffset());
|
|
|
|
emit syncChanged();
|
|
|
|
}
|
|
|
|
|
2019-01-13 14:20:07 +00:00
|
|
|
void CutterSeekable::onCoreSeekChanged(RVA addr)
|
|
|
|
{
|
|
|
|
if (synchronized && widgetOffset != addr) {
|
2019-01-20 11:19:51 +00:00
|
|
|
updateSeek(addr, true);
|
2019-01-13 14:20:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-20 11:19:51 +00:00
|
|
|
void CutterSeekable::updateSeek(RVA addr, bool localOnly)
|
2019-01-13 14:20:07 +00:00
|
|
|
{
|
|
|
|
previousOffset = widgetOffset;
|
|
|
|
widgetOffset = addr;
|
2019-01-20 11:19:51 +00:00
|
|
|
if (synchronized && !localOnly) {
|
2019-01-13 14:20:07 +00:00
|
|
|
Core()->seek(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
emit seekableSeekChanged(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CutterSeekable::seekPrev()
|
|
|
|
{
|
|
|
|
if (synchronized) {
|
|
|
|
Core()->seekPrev();
|
|
|
|
} else {
|
|
|
|
this->seek(previousOffset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RVA CutterSeekable::getOffset()
|
|
|
|
{
|
|
|
|
return (synchronized) ? Core()->getOffset() : widgetOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CutterSeekable::toggleSynchronization()
|
|
|
|
{
|
2019-06-18 13:02:41 +00:00
|
|
|
setSynchronization(!synchronized);
|
2019-01-13 14:20:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CutterSeekable::isSynchronized()
|
|
|
|
{
|
|
|
|
return synchronized;
|
|
|
|
}
|
2019-12-14 12:57:36 +00:00
|
|
|
|
|
|
|
void CutterSeekable::seekToReference(RVA offset)
|
|
|
|
{
|
2021-01-24 14:50:13 +00:00
|
|
|
if (offset == RVA_INVALID) {
|
2019-12-14 12:57:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-01-24 14:50:13 +00:00
|
|
|
|
2019-12-14 12:57:36 +00:00
|
|
|
RVA target;
|
|
|
|
QList<XrefDescription> refs = Core()->getXRefs(offset, false, false);
|
2021-01-24 14:50:13 +00:00
|
|
|
|
2019-12-14 12:57:36 +00:00
|
|
|
if (refs.length()) {
|
|
|
|
if (refs.length() > 1) {
|
2020-06-07 08:39:58 +00:00
|
|
|
qWarning() << tr("More than one (%1) references here. Weird behaviour expected.")
|
2021-01-24 14:50:13 +00:00
|
|
|
.arg(refs.length());
|
2019-12-14 12:57:36 +00:00
|
|
|
}
|
2021-01-24 14:50:13 +00:00
|
|
|
|
2019-12-14 12:57:36 +00:00
|
|
|
target = refs.at(0).to;
|
|
|
|
if (target != RVA_INVALID) {
|
|
|
|
seek(target);
|
|
|
|
}
|
|
|
|
}
|
2020-06-07 08:39:58 +00:00
|
|
|
}
|