Skip to content
This repository has been archived by the owner on Jun 2, 2023. It is now read-only.

Commit

Permalink
#65 AdvHD: Add sanity check on address operands to further ensure the…
Browse files Browse the repository at this point in the history
… right disassembler gets picked
  • Loading branch information
www committed Aug 6, 2022
1 parent e612ac2 commit 2fa7ee2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions VNTextPatch.Shared/Scripts/AdvHd/AdvHdDisassemblerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,26 @@ private object ReadOperand(char type)
return _reader.ReadInt32();

case 'a':
AddressEncountered?.Invoke((int)_stream.Position);
return _reader.ReadInt32();
{
int offset = (int)_stream.Position;
int addr = _reader.ReadInt32();
if (addr < 0 || addr >= _stream.Length)
throw new InvalidDataException();

AddressEncountered?.Invoke(offset);
return addr;
}

case 'f':
return _reader.ReadSingle();

case 's':
{
int offset = (int)_stream.Position;
_reader.SkipZeroTerminatedSjisString();
int length = (int)_stream.Position - offset;
return new Range(offset, length, ScriptStringType.Internal);
}

default:
throw new ArgumentException();
Expand Down

0 comments on commit 2fa7ee2

Please sign in to comment.