Add a memory dump window

This commit is contained in:
Henrik Rydgård committed 2025-01-09 13:14:13 +01:00
1 parent 0881bd6a14
commit 08d251b5bc
5 files changed
+103 -3

No files matched your search

+49
View File
@@ -1,6 +1,7 @@
#include <cctype>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <sstream>
#include "ext/imgui/imgui.h"
@@ -9,6 +10,7 @@
#include "ext/xxhash.h"
#include "Common/StringUtils.h"
#include "Common/File/FileUtil.h"
#include "Core/Config.h"
#include "Core/MemMap.h"
#include "Core/Reporting.h"
@@ -838,3 +840,50 @@ void ImMemView::setHighlightType(MemBlockFlags flags) {
updateStatusBarText();
}
}
void ImMemDumpWindow::Draw(ImConfig &cfg) {
ImGui::SetNextWindowSize(ImVec2(200, 300), ImGuiCond_FirstUseEver);
if (!ImGui::Begin(Title(), &cfg.memDumpOpen)) {
ImGui::End();
return;
}
if (ImGui::Button("User RAM (0x08800000)")) {
address_ = 0x08800000;
size_ = 0x01800000; // 24MB
}
ImGui::InputScalar("Starting address: ", ImGuiDataType_U32, &address_, NULL, NULL, "%08X");
ImGui::InputScalar("Size: ", ImGuiDataType_U32, &size_, NULL, NULL, "%08X");
ImGui::InputText("Filename: ", filename_, ARRAY_SIZE(filename_));
if (ImGui::Button("Dump!")) {
uint32_t validSize = Memory::ValidSize(address_, size_);
if (validSize != size_) {
errorMsg_ = "Address range out of bounds";
if (Memory::IsValidAddress(address_)) {
size_ = validSize;
}
} else if (strlen(filename_) == 0) {
errorMsg_ = "Please specify a valid filename";
} else {
FILE *file = File::OpenCFile(Path(filename_), "wb");
if (!file) {
errorMsg_ = "Couldn't open file for writing";
} else {
const uint8_t *ptr = Memory::GetPointer(address_);
fwrite(ptr, 1, size_, file);
fclose(file);
errorMsg_.clear();
}
}
}
if (!errorMsg_.empty()) {
ImGui::TextUnformatted(errorMsg_.data(), errorMsg_.data() + errorMsg_.size());
}
ImGui::End();
}