Merge pull request #5289 from sepalani/mem-find

MemoryWindow: Replace Search with Find Next/Previous buttons
This commit is contained in:
Léo Lam 2017-04-26 21:16:08 +02:00 committed by GitHub
commit 341fefd65a
2 changed files with 61 additions and 30 deletions

View File

@ -48,7 +48,8 @@ enum
IDM_DUMP_FAKEVMEM,
IDM_VALBOX,
IDM_DATA_TYPE_RBOX,
IDM_SEARCH,
IDM_FIND_NEXT,
IDM_FIND_PREVIOUS,
IDM_ASCII,
IDM_HEX,
IDM_MEMCHECK_OPTIONS_CHANGE
@ -60,7 +61,8 @@ EVT_BUTTON(IDM_DUMP_MEMORY, CMemoryWindow::OnDumpMemory)
EVT_BUTTON(IDM_DUMP_MEM2, CMemoryWindow::OnDumpMem2)
EVT_BUTTON(IDM_DUMP_FAKEVMEM, CMemoryWindow::OnDumpFakeVMEM)
EVT_RADIOBOX(IDM_DATA_TYPE_RBOX, CMemoryWindow::OnDataTypeChanged)
EVT_BUTTON(IDM_SEARCH, CMemoryWindow::OnSearch)
EVT_BUTTON(IDM_FIND_NEXT, CMemoryWindow::OnFindNext)
EVT_BUTTON(IDM_FIND_PREVIOUS, CMemoryWindow::OnFindPrevious)
EVT_RADIOBUTTON(IDM_MEMCHECK_OPTIONS_CHANGE, CMemoryWindow::OnMemCheckOptionChange)
EVT_CHECKBOX(IDM_MEMCHECK_OPTIONS_CHANGE, CMemoryWindow::OnMemCheckOptionChange)
END_EVENT_TABLE()
@ -98,7 +100,9 @@ CMemoryWindow::CMemoryWindow(wxWindow* parent, wxWindowID id, const wxPoint& pos
dump_sizer->Add(new wxButton(this, IDM_DUMP_FAKEVMEM, _("Dump FakeVMEM")), 0, wxEXPAND);
wxStaticBoxSizer* const sizerSearchType = new wxStaticBoxSizer(wxVERTICAL, this, _("Search"));
sizerSearchType->Add(btnSearch = new wxButton(this, IDM_SEARCH, _("Search")));
sizerSearchType->Add(m_btn_find_next = new wxButton(this, IDM_FIND_NEXT, _("Find Next")));
sizerSearchType->Add(m_btn_find_previous =
new wxButton(this, IDM_FIND_PREVIOUS, _("Find Previous")));
sizerSearchType->Add(m_rb_ascii = new wxRadioButton(this, IDM_ASCII, "Ascii", wxDefaultPosition,
wxDefaultSize, wxRB_GROUP));
sizerSearchType->Add(m_rb_hex = new wxRadioButton(this, IDM_HEX, _("Hex")));
@ -267,11 +271,22 @@ void CMemoryWindow::OnDataTypeChanged(wxCommandEvent& ev)
}
}
void CMemoryWindow::OnSearch(wxCommandEvent& event)
void CMemoryWindow::OnFindNext(wxCommandEvent& event)
{
wxBusyCursor hourglass_cursor;
Search(SearchType::FindNext);
}
void CMemoryWindow::OnFindPrevious(wxCommandEvent& event)
{
wxBusyCursor hourglass_cursor;
Search(SearchType::FindPrevious);
}
void CMemoryWindow::Search(SearchType search_type)
{
u8* ram_ptr = nullptr;
u32 ram_size = 0;
std::size_t ram_size = 0;
// NOTE: We're assuming the base address is zero.
switch (memview->GetMemoryType())
{
@ -357,8 +372,11 @@ void CMemoryWindow::OnSearch(wxCommandEvent& event)
{
addr = static_cast<u32>(addr_ul);
// Don't find the result we're already looking at
if (m_continue_search && addr == m_last_search_address)
if (m_continue_search && addr == m_last_search_address &&
search_type == SearchType::FindNext)
{
addr += 1;
}
}
}
}
@ -370,30 +388,33 @@ void CMemoryWindow::OnSearch(wxCommandEvent& event)
return;
}
u8* end = &ram_ptr[ram_size - search_bytes.size() + 1];
u8* ptr = &ram_ptr[addr];
while (true)
const u8* ptr;
const u8* end;
if (search_type == SearchType::FindNext)
{
ptr = std::find(ptr, end, search_bytes[0]);
if (ptr == end)
{
m_search_result_msg->SetLabel(_("No Match"));
break;
}
if (std::equal(search_bytes.begin(), search_bytes.end(), ptr))
{
m_search_result_msg->SetLabel(_("Match Found"));
u32 offset = static_cast<u32>(ptr - ram_ptr);
// NOTE: SetValue() generates a synthetic wxEVT_TEXT
addrbox->SetValue(wxString::Format("%08x", offset));
m_last_search_address = offset;
m_continue_search = true;
break;
}
++ptr;
const u8* begin = &ram_ptr[addr];
end = &ram_ptr[ram_size - search_bytes.size() + 1];
ptr = std::search(begin, end, search_bytes.begin(), search_bytes.end());
}
else
{
const u8* begin = ram_ptr;
end = &ram_ptr[addr + search_bytes.size() - 1];
ptr = std::find_end(begin, end, search_bytes.begin(), search_bytes.end());
}
if (ptr != end)
{
m_search_result_msg->SetLabel(_("Match Found"));
u32 offset = static_cast<u32>(ptr - ram_ptr);
// NOTE: SetValue() generates a synthetic wxEVT_TEXT
addrbox->SetValue(wxString::Format("%08x", offset));
m_last_search_address = offset;
m_continue_search = true;
return;
}
m_search_result_msg->SetLabel(_("No Match"));
}
void CMemoryWindow::OnMemCheckOptionChange(wxCommandEvent& event)

View File

@ -32,10 +32,17 @@ public:
void JumpToAddress(u32 _Address);
private:
enum class SearchType
{
FindNext,
FindPrevious
};
DECLARE_EVENT_TABLE()
void OnDataTypeChanged(wxCommandEvent& event);
void OnSearch(wxCommandEvent& event);
void OnFindNext(wxCommandEvent& event);
void OnFindPrevious(wxCommandEvent& event);
void OnAddrBoxChange(wxCommandEvent& event);
void OnValueChanged(wxCommandEvent&);
void SetMemoryValueFromValBox(wxCommandEvent& event);
@ -45,7 +52,10 @@ private:
void OnDumpFakeVMEM(wxCommandEvent& event);
void OnMemCheckOptionChange(wxCommandEvent& event);
wxButton* btnSearch;
void Search(SearchType search_type);
wxButton* m_btn_find_next;
wxButton* m_btn_find_previous;
wxRadioButton* m_rb_ascii;
wxRadioButton* m_rb_hex;