1
0
Fork 0

Merge pull request #3240 from HayFieldLaps/find-pattern-ranges

Find Pattern searches now begin at start of current region
This commit is contained in:
Duncan Ogilvie 2023-10-28 15:17:38 +02:00 committed by GitHub
commit b0392eda1c
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 59 additions and 15 deletions

View File

@ -1217,20 +1217,23 @@ void CPUDisassembly::findCallsSlot()
void CPUDisassembly::findPatternSlot()
{
HexEditDialog hexEdit(this);
hexEdit.showEntireBlock(true);
hexEdit.isDataCopiable(false);
if(sender() == mFindPatternRegion)
hexEdit.showStartFromSelection(true, ConfigBool("Disassembler", "FindPatternFromSelection"));
hexEdit.mHexEdit->setOverwriteMode(false);
hexEdit.setWindowTitle(tr("Find Pattern..."));
if(hexEdit.exec() != QDialog::Accepted)
return;
dsint addr = rvaToVa(getSelectionStart());
if(hexEdit.entireBlock())
addr = DbgMemFindBaseAddr(addr, 0);
QString command;
if(sender() == mFindPatternRegion)
{
bool startFromSelection = hexEdit.startFromSelection();
Config()->setBool("Disassembler", "FindPatternFromSelection", startFromSelection);
if(!startFromSelection)
addr = DbgMemFindBaseAddr(addr, 0);
command = QString("findall %1, %2").arg(ToHexString(addr), hexEdit.mHexEdit->pattern());
}
else if(sender() == mFindPatternModule)
@ -1775,18 +1778,18 @@ void CPUDisassembly::findCommandSlot()
LineEditDialog mLineEdit(this);
mLineEdit.enableCheckBox(refFindType == 0);
mLineEdit.setCheckBoxText(tr("Entire &Block"));
mLineEdit.setCheckBox(ConfigBool("Disassembler", "FindCommandEntireBlock"));
mLineEdit.setCheckBoxText(tr("Start from &Selection"));
mLineEdit.setCheckBox(ConfigBool("Disassembler", "FindCommandFromSelection"));
mLineEdit.setWindowTitle("Find Command");
if(mLineEdit.exec() != QDialog::Accepted)
return;
Config()->setBool("Disassembler", "FindCommandEntireBlock", mLineEdit.bChecked);
Config()->setBool("Disassembler", "FindCommandFromSelection", mLineEdit.bChecked);
char error[MAX_ERROR_SIZE] = "";
unsigned char dest[16];
int asmsize = 0;
duint va = rvaToVa(getInitialSelection());
if(mLineEdit.bChecked) // entire block
if(!mLineEdit.bChecked) // start search from selection
va = mMemPage->getBase();
if(!DbgFunctions()->Assemble(mMemPage->getBase() + mMemPage->getSize() / 2, dest, &asmsize, mLineEdit.editText.toUtf8().constData(), error))

View File

@ -1443,14 +1443,16 @@ void CPUDump::binarySaveToFileSlot()
void CPUDump::findPattern()
{
HexEditDialog hexEdit(this);
hexEdit.showEntireBlock(true);
hexEdit.isDataCopiable(false);
hexEdit.showStartFromSelection(true, ConfigBool("Gui", "CPUDumpStartFromSelect"));
hexEdit.mHexEdit->setOverwriteMode(false);
hexEdit.setWindowTitle(tr("Find Pattern..."));
if(hexEdit.exec() != QDialog::Accepted)
return;
bool startFromSelection = hexEdit.startFromSelection();
Config()->setBool("Gui", "CPUDumpStartFromSelect", startFromSelection);
dsint addr = rvaToVa(getSelectionStart());
if(hexEdit.entireBlock())
if(!startFromSelection)
addr = DbgMemFindBaseAddr(addr, 0);
QString addrText = ToPtrString(addr);
DbgCmdExec(QString("findall " + addrText + ", " + hexEdit.mHexEdit->pattern() + ", &data&"));

View File

@ -865,15 +865,19 @@ void CPUStack::binaryPasteIgnoreSizeSlot()
void CPUStack::findPattern()
{
HexEditDialog hexEdit(this);
hexEdit.showEntireBlock(true);
hexEdit.isDataCopiable(false);
hexEdit.showStartFromSelection(true, ConfigBool("Gui", "CPUStackStartFromSelect"));
hexEdit.mHexEdit->setOverwriteMode(false);
hexEdit.setWindowTitle(tr("Find Pattern..."));
if(hexEdit.exec() != QDialog::Accepted)
return;
dsint addr = rvaToVa(getSelectionStart());
if(hexEdit.entireBlock())
bool startFromSelection = hexEdit.startFromSelection();
Config()->setBool("Gui", "CPUStackStartFromSelect", startFromSelection);
if(!startFromSelection)
addr = DbgMemFindBaseAddr(addr, 0);
QString addrText = ToPtrString(addr);
DbgCmdExec(QString("findall " + addrText + ", " + hexEdit.mHexEdit->pattern() + ", &data&"));
emit displayReferencesWidget();

View File

@ -28,6 +28,7 @@ HexEditDialog::HexEditDialog(QWidget* parent) : QDialog(parent), ui(new Ui::HexE
ui->chkKeepSize->setChecked(ConfigBool("HexDump", "KeepSize"));
ui->chkKeepSize->hide();
ui->chkEntireBlock->hide();
ui->chkFromSelection->hide();
mDataInitialized = false;
stringEditorLock = false;
@ -112,6 +113,12 @@ void HexEditDialog::showKeepSize(bool show)
ui->chkKeepSize->setVisible(show);
}
void HexEditDialog::showStartFromSelection(bool show, bool checked)
{
ui->chkFromSelection->setVisible(show);
ui->chkFromSelection->setChecked(checked);
}
void HexEditDialog::isDataCopiable(bool copyDataEnabled)
{
if(copyDataEnabled == false)
@ -150,6 +157,11 @@ bool HexEditDialog::entireBlock()
return ui->chkEntireBlock->isChecked();
}
bool HexEditDialog::startFromSelection()
{
return ui->chkFromSelection->isChecked();
}
void HexEditDialog::updateStyle()
{
QString style = QString("QLineEdit { border-style: outset; border-width: 1px; border-color: %1; color: %1; background-color: %2 }").arg(ConfigColor("HexEditTextColor").name(), ConfigColor("HexEditBackgroundColor").name());

View File

@ -18,10 +18,12 @@ public:
void showEntireBlock(bool show, bool checked = false);
void showKeepSize(bool show);
void showStartFromSelection(bool show, bool checked = false);
void isDataCopiable(bool copyDataEnabled);
void updateCodepage();
bool entireBlock();
bool startFromSelection();
QHexEdit* mHexEdit;

View File

@ -472,6 +472,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkFromSelection">
<property name="text">
<string>Start from &amp;Selection</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">

View File

@ -612,12 +612,23 @@ void MemoryMapView::findPatternSlot()
hexEdit.setWindowTitle(tr("Find Pattern..."));
if(hexEdit.exec() != QDialog::Accepted)
return;
duint addr = getSelectionAddr();
entireBlockEnabled = hexEdit.entireBlock();
BridgeSettingSetUint("Gui", "MemoryMapEntireBlock", entireBlockEnabled);
if(entireBlockEnabled)
addr = 0;
DbgCmdExec(QString("findallmem %1, %2, &data&").arg(ToPtrString(addr)).arg(hexEdit.mHexEdit->pattern()));
{
DbgCmdExec(QString("findallmem 0, %2").arg(hexEdit.mHexEdit->pattern()));
}
else
{
QList<duint> selection = getSelection();
if(selection.isEmpty())
return;
duint addrFirst = getCellUserdata(selection.first(), ColAddress);
duint addrLast = getCellUserdata(selection.last(), ColAddress);
duint size = getCellUserdata(selection.last(), ColSize);
DbgCmdExec(QString("findallmem %1, %2, %3").arg(ToPtrString(addrFirst)).arg(hexEdit.mHexEdit->pattern()).arg(ToHexString(addrLast - addrFirst + size)));
}
emit showReferences();
}

View File

@ -254,7 +254,8 @@ Configuration::Configuration() : QObject(), noMoreMsgbox(false)
disassemblyBool.insert("KeepSize", false);
disassemblyBool.insert("FillNOPs", false);
disassemblyBool.insert("Uppercase", false);
disassemblyBool.insert("FindCommandEntireBlock", false);
disassemblyBool.insert("FindCommandFromSelection", true);
disassemblyBool.insert("FindPatternFromSelection", true);
disassemblyBool.insert("OnlyCipAutoComments", false);
disassemblyBool.insert("TabbedMnemonic", false);
disassemblyBool.insert("LongDataInstruction", false);
@ -292,6 +293,8 @@ Configuration::Configuration() : QObject(), noMoreMsgbox(false)
guiBool.insert("AutoFollowInStack", true);
guiBool.insert("EnableQtHighDpiScaling", true);
guiBool.insert("Topmost", false);
guiBool.insert("CPUDumpStartFromSelect", true);
guiBool.insert("CPUStackStartFromSelect", true);
//Named menu settings
insertMenuBuilderBools(&guiBool, "CPUDisassembly", 50); //CPUDisassembly
insertMenuBuilderBools(&guiBool, "CPUDump", 50); //CPUDump