Debugger: Fixed out-of-range memory read bug in memory import logic
This commit is contained in:
parent
a27cf40e96
commit
079564cb25
6 changed files with 13 additions and 13 deletions
|
@ -915,9 +915,9 @@ uint32_t BaseMapper::CopyMemory(DebugMemoryType type, uint8_t* buffer)
|
|||
return size;
|
||||
}
|
||||
|
||||
void BaseMapper::WriteMemory(DebugMemoryType type, uint8_t* buffer)
|
||||
void BaseMapper::WriteMemory(DebugMemoryType type, uint8_t* buffer, int32_t length)
|
||||
{
|
||||
uint32_t size = GetMemorySize(type);
|
||||
int32_t size = std::min(length, (int32_t)GetMemorySize(type));
|
||||
switch(type) {
|
||||
default: break;
|
||||
case DebugMemoryType::ChrRam: memcpy(_chrRam, buffer, size); break;
|
||||
|
|
|
@ -214,7 +214,7 @@ public:
|
|||
uint32_t GetMemorySize(DebugMemoryType type);
|
||||
|
||||
uint32_t CopyMemory(DebugMemoryType type, uint8_t* buffer);
|
||||
void WriteMemory(DebugMemoryType type, uint8_t* buffer);
|
||||
void WriteMemory(DebugMemoryType type, uint8_t* buffer, int32_t length);
|
||||
|
||||
void GetAbsoluteAddressAndType(uint32_t relativeAddr, AddressTypeInfo *info);
|
||||
void GetPpuAbsoluteAddressAndType(uint32_t relativeAddr, PpuAddressTypeInfo *info);
|
||||
|
|
|
@ -20,7 +20,7 @@ MemoryDumper::MemoryDumper(shared_ptr<PPU> ppu, shared_ptr<MemoryManager> memory
|
|||
_disassembler = disassembler;
|
||||
}
|
||||
|
||||
void MemoryDumper::SetMemoryState(DebugMemoryType type, uint8_t *buffer)
|
||||
void MemoryDumper::SetMemoryState(DebugMemoryType type, uint8_t *buffer, int32_t length)
|
||||
{
|
||||
switch(type) {
|
||||
case DebugMemoryType::ChrRom:
|
||||
|
@ -30,25 +30,25 @@ void MemoryDumper::SetMemoryState(DebugMemoryType type, uint8_t *buffer)
|
|||
break;
|
||||
|
||||
case DebugMemoryType::InternalRam:
|
||||
for(int i = 0; i < 0x800; i++) {
|
||||
for(int i = 0; i < 0x800 && i < length; i++) {
|
||||
_memoryManager->DebugWrite(i, buffer[i]);
|
||||
}
|
||||
break;
|
||||
|
||||
case DebugMemoryType::PaletteMemory:
|
||||
for(int i = 0; i < 0x20; i++) {
|
||||
for(int i = 0; i < 0x20 && i < length; i++) {
|
||||
_ppu->WritePaletteRAM(i, buffer[i]);
|
||||
}
|
||||
break;
|
||||
|
||||
case DebugMemoryType::SpriteMemory: memcpy(_ppu->GetSpriteRam(), buffer, 0x100); break;
|
||||
case DebugMemoryType::SecondarySpriteMemory: memcpy(_ppu->GetSecondarySpriteRam(), buffer, 0x20); break;
|
||||
case DebugMemoryType::SpriteMemory: memcpy(_ppu->GetSpriteRam(), buffer, std::min(length, 0x100)); break;
|
||||
case DebugMemoryType::SecondarySpriteMemory: memcpy(_ppu->GetSecondarySpriteRam(), buffer, std::min(length, 0x20)); break;
|
||||
|
||||
case DebugMemoryType::ChrRam:
|
||||
case DebugMemoryType::WorkRam:
|
||||
case DebugMemoryType::SaveRam:
|
||||
case DebugMemoryType::NametableRam:
|
||||
_mapper->WriteMemory(type, buffer);
|
||||
_mapper->WriteMemory(type, buffer, length);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,5 +106,5 @@ public:
|
|||
void SetMemoryValue(DebugMemoryType memoryType, uint32_t address, uint8_t value, bool preventRebuildCache = false, bool disableSideEffects = true);
|
||||
void SetMemoryValueWord(DebugMemoryType memoryType, uint32_t address, uint16_t value, bool preventRebuildCache = false, bool disableSideEffects = true);
|
||||
void SetMemoryValues(DebugMemoryType memoryType, uint32_t address, uint8_t* data, int32_t length);
|
||||
void SetMemoryState(DebugMemoryType type, uint8_t *buffer);
|
||||
void SetMemoryState(DebugMemoryType type, uint8_t *buffer, int32_t length);
|
||||
};
|
|
@ -382,12 +382,12 @@ namespace Mesen.GUI
|
|||
return buffer;
|
||||
}
|
||||
|
||||
[DllImport(DLLPath, EntryPoint = "DebugSetMemoryState")] private static extern void DebugSetMemoryStateWrapper(DebugMemoryType type, IntPtr buffer);
|
||||
[DllImport(DLLPath, EntryPoint = "DebugSetMemoryState")] private static extern void DebugSetMemoryStateWrapper(DebugMemoryType type, IntPtr buffer, Int32 length);
|
||||
public static void DebugSetMemoryState(DebugMemoryType type, byte[] data)
|
||||
{
|
||||
GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
|
||||
try {
|
||||
InteropEmu.DebugSetMemoryStateWrapper(type, handle.AddrOfPinnedObject());
|
||||
InteropEmu.DebugSetMemoryStateWrapper(type, handle.AddrOfPinnedObject(), data.Length);
|
||||
} finally {
|
||||
handle.Free();
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ extern "C"
|
|||
DllExport void __stdcall DebugClearPpuViewerSettings(int32_t ppuViewerId) { return GetDebugger()->ClearPpuViewerSettings(ppuViewerId); }
|
||||
|
||||
DllExport void __stdcall DebugSetNextStatement(uint16_t addr) { GetDebugger()->SetNextStatement(addr); }
|
||||
DllExport void __stdcall DebugSetMemoryState(DebugMemoryType type, uint8_t *buffer) { GetDebugger()->GetMemoryDumper()->SetMemoryState(type, buffer); }
|
||||
DllExport void __stdcall DebugSetMemoryState(DebugMemoryType type, uint8_t *buffer, int32_t length) { GetDebugger()->GetMemoryDumper()->SetMemoryState(type, buffer, length); }
|
||||
|
||||
DllExport uint32_t __stdcall DebugGetMemorySize(DebugMemoryType type) { return GetDebugger()->GetMemoryDumper()->GetMemorySize(type); }
|
||||
DllExport uint32_t __stdcall DebugGetMemoryState(DebugMemoryType type, uint8_t *buffer) { return GetDebugger()->GetMemoryDumper()->GetMemoryState(type, buffer); }
|
||||
|
|
Loading…
Add table
Reference in a new issue