Added the logic to the ScanRemoveWindow

This commit is contained in:
Nemoumbra
2023-07-08 22:40:11 +03:00
parent b8dbe02010
commit abd2b21d60
5 changed files with 104 additions and 19 deletions
+63 -13
View File
@@ -1,9 +1,7 @@
#include "ScanRemoveWindow.h"
#include "../resource.h"
bool ScanRemoveWindow::GetCheckState(HWND hwnd, int dlgItem) {
return SendMessage(GetDlgItem(hwnd, dlgItem), BM_GETCHECK, 0, 0) != 0;
}
@@ -13,7 +11,7 @@ bool ScanRemoveWindow::fetchDialogData(HWND hwnd)
char str[256], errorMessage[512];
PostfixExpression exp;
scan = GetCheckState(hwnd, IDC_SCANREMOVE_SCAN);
scan_ = GetCheckState(hwnd, IDC_SCANREMOVE_SCAN);
// Parse the address
GetWindowTextA(GetDlgItem(hwnd, IDC_SCANREMOVE_ADDRESS), str, 256);
@@ -24,7 +22,7 @@ bool ScanRemoveWindow::fetchDialogData(HWND hwnd)
MessageBoxA(hwnd, errorMessage, "Error", MB_OK);
return false;
}
if (cpu->parseExpression(exp, address) == false)
if (cpu->parseExpression(exp, address_) == false)
{
snprintf(errorMessage, sizeof(errorMessage), "Invalid expression \"%s\": %s", str, getExpressionError());
MessageBoxA(hwnd, errorMessage, "Error", MB_OK);
@@ -40,13 +38,19 @@ bool ScanRemoveWindow::fetchDialogData(HWND hwnd)
MessageBoxA(hwnd, errorMessage, "Error", MB_OK);
return false;
}
if (cpu->parseExpression(exp, size) == false)
if (cpu->parseExpression(exp, size_) == false)
{
snprintf(errorMessage, sizeof(errorMessage), "Invalid expression \"%s\": %s", str, getExpressionError());
MessageBoxA(hwnd, errorMessage, "Error", MB_OK);
return false;
}
// Now let's validate the range
if (!Memory::IsValidRange(address_, size_)) {
MessageBoxA(hwnd, "Invalid range", "Error", MB_OK);
return false;
}
return true;
}
@@ -74,15 +78,15 @@ INT_PTR ScanRemoveWindow::DlgFunc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lP
case WM_INITDIALOG:
// Set the radiobutton values
SendMessage(GetDlgItem(hwnd, IDC_SCANREMOVE_SCAN), BM_SETCHECK, scan ? BST_CHECKED : BST_UNCHECKED, 0);
SendMessage(GetDlgItem(hwnd, IDC_SCANREMOVE_REMOVE), BM_SETCHECK, scan ? BST_UNCHECKED : BST_CHECKED, 0);
SendMessage(GetDlgItem(hwnd, IDC_SCANREMOVE_SCAN), BM_SETCHECK, scan_ ? BST_CHECKED : BST_UNCHECKED, 0);
SendMessage(GetDlgItem(hwnd, IDC_SCANREMOVE_REMOVE), BM_SETCHECK, scan_ ? BST_UNCHECKED : BST_CHECKED, 0);
// Set the text in the textboxes
if (address != -1) {
snprintf(str, sizeof(str), "0x%08X", address);
if (address_ != -1) {
snprintf(str, sizeof(str), "0x%08X", address_);
SetWindowTextA(GetDlgItem(hwnd, IDC_SCANREMOVE_ADDRESS), str);
}
snprintf(str, sizeof(str), "0x%08X", size);
snprintf(str, sizeof(str), "0x%08X", size_);
SetWindowTextA(GetDlgItem(hwnd, IDC_SCANREMOVE_SIZE), str);
return TRUE;
@@ -93,7 +97,7 @@ INT_PTR ScanRemoveWindow::DlgFunc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lP
switch (HIWORD(wParam))
{
case BN_CLICKED:
scan = true;
scan_ = true;
break;
}
break;
@@ -101,7 +105,7 @@ INT_PTR ScanRemoveWindow::DlgFunc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lP
switch (HIWORD(wParam))
{
case BN_CLICKED:
scan = false;
scan_ = false;
break;
}
break;
@@ -138,5 +142,51 @@ INT_PTR ScanRemoveWindow::DlgFunc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lP
}
bool ScanRemoveWindow::exec() {
return DialogBoxParam(GetModuleHandle(0), MAKEINTRESOURCE(IDD_BREAKPOINT), parentHwnd, StaticDlgFunc, (LPARAM)this) != 0;
return DialogBoxParam(GetModuleHandle(0), MAKEINTRESOURCE(IDD_SCANREMOVE), parentHwnd, StaticDlgFunc, (LPARAM)this) != 0;
}
void ScanRemoveWindow::Scan() {
bool insertSymbols = MIPSAnalyst::ScanForFunctions(address_, address_ + size_ - 1, true);
MIPSAnalyst::FinalizeScan(insertSymbols);
}
void ScanRemoveWindow::Remove() {
u32 func_address = g_symbolMap->GetFunctionStart(address_);
if (func_address == SymbolMap::INVALID_ADDRESS) {
func_address = g_symbolMap->GetNextSymbolAddress(address_, SymbolType::ST_FUNCTION);
}
u32 counter = 0;
while (func_address < address_ + size_ && func_address != SymbolMap::INVALID_ADDRESS) {
g_symbolMap->RemoveFunction(func_address, true);
++counter;
func_address = g_symbolMap->GetNextSymbolAddress(address_, SymbolType::ST_FUNCTION);
}
if (counter) {
MIPSAnalyst::ForgetFunctions(address_, address_ + size_ - 1);
// The following was copied from hle.func.remove:
g_symbolMap->SortSymbols();
MIPSAnalyst::UpdateHashMap();
MIPSAnalyst::ApplyHashMap();
if (g_Config.bFuncReplacements) {
MIPSAnalyst::ReplaceFunctions();
}
// Clear cache for branch lines and such.
DisassemblyManager manager;
manager.clear();
}
}
void ScanRemoveWindow::eval() {
if (scan_) {
Scan();
}
else {
Remove();
}
}