Skip to content

Commit 8478bd6

Browse files
WitherOrNotSamboyCoding
authored andcommitted
Fix incorrect address translation at segment boundary
1 parent 8d9ab31 commit 8478bd6

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

LibCpp2IL/NintendoSwitch/NsoFile.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics.CodeAnalysis;
44
using System.IO;
@@ -309,7 +309,7 @@ public NsoFile Decompress()
309309

310310
public override long MapVirtualAddressToRaw(ulong addr, bool throwOnError = true)
311311
{
312-
var segment = segments.FirstOrDefault(x => addr - NsoGlobalOffset >= x.MemoryOffset && addr - NsoGlobalOffset <= x.MemoryOffset + x.DecompressedSize);
312+
var segment = segments.FirstOrDefault(x => addr - NsoGlobalOffset >= x.MemoryOffset && addr - NsoGlobalOffset < x.MemoryOffset + x.DecompressedSize);
313313
if (segment == null)
314314
if (throwOnError)
315315
throw new InvalidOperationException($"NSO: Address 0x{addr:X} is not present in any of the segments. Known segment ends are (hex) {string.Join(", ", segments.Select(s => (s.MemoryOffset + s.DecompressedSize).ToString("X")))}");
@@ -321,7 +321,7 @@ public override long MapVirtualAddressToRaw(ulong addr, bool throwOnError = true
321321

322322
public override ulong MapRawAddressToVirtual(uint offset)
323323
{
324-
var segment = segments.FirstOrDefault(x => offset >= x.FileOffset && offset <= x.FileOffset + x.DecompressedSize);
324+
var segment = segments.FirstOrDefault(x => offset >= x.FileOffset && offset < x.FileOffset + x.DecompressedSize);
325325
if (segment == null)
326326
{
327327
return 0;

LibCpp2IL/PE/PE.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public override long MapVirtualAddressToRaw(ulong uiAddr, bool throwOnError = tr
9797
return VirtToRawInvalidOutOfBounds;
9898
}
9999

100-
var section = peSectionHeaders.FirstOrDefault(x => addr >= x.VirtualAddress && addr <= x.VirtualAddress + x.VirtualSize);
100+
var section = peSectionHeaders.FirstOrDefault(x => addr >= x.VirtualAddress && addr < x.VirtualAddress + x.VirtualSize);
101101

102102
if (section == null) return 0L;
103103

0 commit comments

Comments
 (0)