From a94a7d4495e2bb9710f0c17a47f84ddb02d1609c Mon Sep 17 00:00:00 2001 From: darkf Date: Wed, 24 Dec 2014 20:39:57 -0800 Subject: [PATCH 1/2] Add a memory ASCII string search --- rpcs3/Gui/MainFrame.cpp | 11 +++++ rpcs3/Gui/MainFrame.h | 1 + rpcs3/Gui/MemoryStringSearcher.cpp | 74 ++++++++++++++++++++++++++++++ rpcs3/Gui/MemoryStringSearcher.h | 19 ++++++++ rpcs3/rpcs3.vcxproj | 1 + rpcs3/rpcs3.vcxproj.filters | 3 ++ 6 files changed, 109 insertions(+) create mode 100644 rpcs3/Gui/MemoryStringSearcher.cpp create mode 100644 rpcs3/Gui/MemoryStringSearcher.h diff --git a/rpcs3/Gui/MainFrame.cpp b/rpcs3/Gui/MainFrame.cpp index 2235c8e63d..595d207423 100644 --- a/rpcs3/Gui/MainFrame.cpp +++ b/rpcs3/Gui/MainFrame.cpp @@ -20,6 +20,7 @@ #include "Gui/KernelExplorer.h" #include "Gui/MemoryViewer.h" #include "Gui/RSXDebugger.h" +#include "Gui/MemoryStringSearcher.h" #include "Gui/LLEModulesManager.h" #include @@ -51,6 +52,7 @@ enum IDs id_tools_kernel_explorer, id_tools_memory_viewer, id_tools_rsx_debugger, + id_tools_string_search, id_help_about, id_update_dbg, }; @@ -112,6 +114,7 @@ MainFrame::MainFrame() menu_tools->Append(id_tools_kernel_explorer, "&Kernel Explorer")->Enable(false); menu_tools->Append(id_tools_memory_viewer, "&Memory Viewer")->Enable(false); menu_tools->Append(id_tools_rsx_debugger, "&RSX Debugger")->Enable(false); + menu_tools->Append(id_tools_string_search, "&String Search")->Enable(false); wxMenu* menu_help = new wxMenu(); menubar->Append(menu_help, "&Help"); @@ -151,6 +154,7 @@ MainFrame::MainFrame() Bind(wxEVT_MENU, &MainFrame::OpenKernelExplorer, this, id_tools_kernel_explorer); Bind(wxEVT_MENU, &MainFrame::OpenMemoryViewer, this, id_tools_memory_viewer); Bind(wxEVT_MENU, &MainFrame::OpenRSXDebugger, this, id_tools_rsx_debugger); + Bind(wxEVT_MENU, &MainFrame::OpenStringSearch, this, id_tools_string_search); Bind(wxEVT_MENU, &MainFrame::AboutDialogHandler, this, id_help_about); @@ -720,6 +724,10 @@ void MainFrame::OpenRSXDebugger(wxCommandEvent& WXUNUSED(event)) (new RSXDebugger(this)) -> Show(); } +void MainFrame::OpenStringSearch(wxCommandEvent& WXUNUSED(event)) +{ + (new MemoryStringSearcher(this)) -> Show(); +} void MainFrame::AboutDialogHandler(wxCommandEvent& WXUNUSED(event)) { @@ -818,9 +826,12 @@ void MainFrame::UpdateUI(wxCommandEvent& event) wxMenuItem& kernel_explorer = *menubar.FindItem(id_tools_kernel_explorer); wxMenuItem& memory_viewer = *menubar.FindItem(id_tools_memory_viewer); wxMenuItem& rsx_debugger = *menubar.FindItem(id_tools_rsx_debugger); + wxMenuItem& string_search = *menubar.FindItem(id_tools_string_search); kernel_explorer.Enable(!is_stopped); memory_viewer.Enable(!is_stopped); rsx_debugger.Enable(!is_stopped); + string_search.Enable(!is_stopped); + //m_aui_mgr.Update(); diff --git a/rpcs3/Gui/MainFrame.h b/rpcs3/Gui/MainFrame.h index 359e932c6a..3de2d38e6a 100644 --- a/rpcs3/Gui/MainFrame.h +++ b/rpcs3/Gui/MainFrame.h @@ -45,6 +45,7 @@ private: void OpenKernelExplorer(wxCommandEvent& evt); void OpenMemoryViewer(wxCommandEvent& evt); void OpenRSXDebugger(wxCommandEvent& evt); + void OpenStringSearch(wxCommandEvent& evt); void OpenFnIdGenerator(wxCommandEvent& evt); void AboutDialogHandler(wxCommandEvent& event); void UpdateUI(wxCommandEvent& event); diff --git a/rpcs3/Gui/MemoryStringSearcher.cpp b/rpcs3/Gui/MemoryStringSearcher.cpp new file mode 100644 index 0000000000..8676d57371 --- /dev/null +++ b/rpcs3/Gui/MemoryStringSearcher.cpp @@ -0,0 +1,74 @@ +#include "stdafx_gui.h" +#include "rpcs3/Ini.h" +#include "Utilities/rPlatform.h" +#include "Utilities/Log.h" +#include "Emu/Memory/Memory.h" +#include "Emu/System.h" + +#include "MemoryStringSearcher.h" +#include "Emu/RSX/sysutil_video.h" +#include "Emu/RSX/GSManager.h" +//#include "Emu/RSX/GCM.h" + +#include + +MemoryStringSearcher::MemoryStringSearcher(wxWindow* parent) + : wxFrame(parent, wxID_ANY, "String Searcher", wxDefaultPosition, wxSize(545, 64)) + , exit(false) +{ + this->SetBackgroundColour(wxColour(240,240,240)); + //wxBoxSizer* s_panel = new wxBoxSizer(wxHORIZONTAL); + + //Tools + //wxBoxSizer* s_tools = new wxBoxSizer(wxVERTICAL); + + //Tabs + //wxNotebook* nb_rsx = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxSize(482,475)); + + s_panel = new wxBoxSizer(wxHORIZONTAL); + t_addr = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(482, -1)); + b_search = new wxButton(this, wxID_ANY, "Search", wxPoint(482, 0), wxSize(40, -1)); + b_search->Bind(wxEVT_BUTTON, &MemoryStringSearcher::Search, this); + s_panel->Add(t_addr); + s_panel->Add(b_search); +}; + +void MemoryStringSearcher::Search(wxCommandEvent& event) +{ + const wxString wstr = t_addr->GetValue(); + const char *str = wstr.c_str(); + const u32 len = wstr.length(); + + LOG_NOTICE(GENERAL, "Searching for string %s", str); + + // Search the address space for the string + u32 strIndex = 0; + u32 numFound = 0; + for (u32 addr = Memory.MainMem.GetStartAddr(); addr < Memory.MainMem.GetEndAddr(); addr++) { + if (!Memory.IsGoodAddr(addr)) { + strIndex = 0; + continue; + } + + u8 byte = vm::read8(addr); + if (byte == str[strIndex]) { + if (strIndex == len) { + // Found it + LOG_NOTICE(GENERAL, "Found @ %04x", addr - len); + numFound++; + strIndex = 0; + continue; + } + + strIndex++; + } + else + strIndex = 0; + + if (addr % (1024 * 1024 * 64) == 0) { // Log every 64mb + LOG_NOTICE(GENERAL, "Searching %04x ...", addr); + } + } + + LOG_NOTICE(GENERAL, "Search completed (found %d matches)", numFound); +} \ No newline at end of file diff --git a/rpcs3/Gui/MemoryStringSearcher.h b/rpcs3/Gui/MemoryStringSearcher.h new file mode 100644 index 0000000000..9af71fee89 --- /dev/null +++ b/rpcs3/Gui/MemoryStringSearcher.h @@ -0,0 +1,19 @@ +#pragma once +#include + +class MemoryStringSearcher : public wxFrame +{ + wxTextCtrl* t_addr; + wxBoxSizer* s_panel; + wxButton* b_search; + +public: + bool exit; + MemoryStringSearcher(wxWindow* parent); + ~MemoryStringSearcher() + { + exit = true; + } + + void MemoryStringSearcher::Search(wxCommandEvent& event); +}; diff --git a/rpcs3/rpcs3.vcxproj b/rpcs3/rpcs3.vcxproj index 946b6cb66e..44c219a587 100644 --- a/rpcs3/rpcs3.vcxproj +++ b/rpcs3/rpcs3.vcxproj @@ -175,6 +175,7 @@ + diff --git a/rpcs3/rpcs3.vcxproj.filters b/rpcs3/rpcs3.vcxproj.filters index 5fce1aa362..71062a8296 100644 --- a/rpcs3/rpcs3.vcxproj.filters +++ b/rpcs3/rpcs3.vcxproj.filters @@ -93,6 +93,9 @@ Gui + + Gui + From efd729d0b8e81c123f6c2e418b26c44649d901cb Mon Sep 17 00:00:00 2001 From: darkf Date: Thu, 25 Dec 2014 00:53:56 -0800 Subject: [PATCH 2/2] MemoryStringSearcher: drop superfluous qualifier --- rpcs3/Gui/MemoryStringSearcher.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpcs3/Gui/MemoryStringSearcher.h b/rpcs3/Gui/MemoryStringSearcher.h index 9af71fee89..f0928afe2d 100644 --- a/rpcs3/Gui/MemoryStringSearcher.h +++ b/rpcs3/Gui/MemoryStringSearcher.h @@ -15,5 +15,5 @@ public: exit = true; } - void MemoryStringSearcher::Search(wxCommandEvent& event); + void Search(wxCommandEvent& event); };