Skip to content
This repository has been archived by the owner on Sep 10, 2019. It is now read-only.

Commit

Permalink
Fixed UString reading in out of memory page region
Browse files Browse the repository at this point in the history
  • Loading branch information
Stridemann committed May 8, 2018
2 parents 9120073 + 72765bc commit 9242aee
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/Framework/Memory.cs
Expand Up @@ -179,7 +179,39 @@ public string ReadStringU(long addr, int length = 256, bool replaceNull = true)
return String.Empty;
}
if (mem[0] == 0 && mem[1] == 0)
{
var checkByte = ReadByte(addr);
if(checkByte != 0)
{
//Reading an array of bytes gives us a 0 first byte and manual reading the first byte gives us not 0,
//mean that this was a reading out of memory region, we will try to read with step of 10 bytes,
//but perfectly we should read with a step of 2 bytes

const int step = 8;//should be 'even' number (2,4,6,8, etc) (or remove if (bytes[0] == 0) check)
//because each second byte of string is 0
string result = "";

for (int offset = 0; offset < length; offset += step)
{
var bytes = ReadMem(addr + offset, step);

if (replaceNull && bytes[0] == 0)//I suppose here should/can be out of memory page. Or this also can be end of a string
break;//we are not going to do RTrimNull here, because our string don't have end of string cymbol '\0' (zero byte) and here we have the end of string

var partialString = Encoding.Unicode.GetString(bytes);
result += partialString;

if(replaceNull && partialString.Contains('\0'))
{
return RTrimNull(result);
}
}
return result;
}

return string.Empty;
}

string @string = Encoding.Unicode.GetString(mem);
return replaceNull ? RTrimNull(@string) : @string;
}
Expand Down

0 comments on commit 9242aee

Please sign in to comment.