From c80394fd00906dbc627812295079129fefb7a4cb Mon Sep 17 00:00:00 2001 From: Subv Date: Sat, 2 Jan 2016 16:16:23 -0500 Subject: [PATCH] Memory/Utils: Added a function to retrieve a string from emulated memory. --- src/core/memory.cpp | 9 +++++++++ src/core/memory.h | 20 +++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/core/memory.cpp b/src/core/memory.cpp index fc79c3ee9..a04201971 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -149,6 +149,15 @@ u8* GetPointer(const VAddr vaddr) { return nullptr; } +std::string GetString(const VAddr vaddr, const u32 size) { + std::string string; + string.reserve(size); + for (u32 offset = 0; offset < size; ++offset) + string.push_back(Read8(vaddr + offset)); + return string; + +} + u8* GetPhysicalPointer(PAddr address) { return GetPointer(PhysicalToVirtualAddress(address)); } diff --git a/src/core/memory.h b/src/core/memory.h index 5af72b7a7..e6efd7b2d 100644 --- a/src/core/memory.h +++ b/src/core/memory.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include "common/common_types.h" @@ -131,14 +132,23 @@ void WriteBlock(VAddr addr, const u8* data, size_t size); u8* GetPointer(VAddr virtual_address); /** -* Converts a virtual address inside a region with 1:1 mapping to physical memory to a physical -* address. This should be used by services to translate addresses for use by the hardware. -*/ + * Reads a fixed-size string of the specified size starting at + * the specified address and returns a copy of it. + * @param vaddr Starting address of the string. + * @param size Size of the string. + * @return A copy of the string that was read. + */ +std::string GetString(const VAddr vaddr, const u32 size); + +/** + * Converts a virtual address inside a region with 1:1 mapping to physical memory to a physical + * address. This should be used by services to translate addresses for use by the hardware. + */ PAddr VirtualToPhysicalAddress(VAddr addr); /** -* Undoes a mapping performed by VirtualToPhysicalAddress(). -*/ + * Undoes a mapping performed by VirtualToPhysicalAddress(). + */ VAddr PhysicalToVirtualAddress(PAddr addr); /**