Skip to content

Commit

Permalink
Make field offset reading use TryMapVATR to reduce exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeFZ committed Nov 9, 2024
1 parent e0e8d05 commit 3982e5f
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions Il2CppInspector.Common/IL2CPP/Il2CppInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,19 +203,21 @@ public Il2CppInspector(Il2CppBinary binary, Metadata metadata) {
for (var i = 0; i < TypeDefinitions.Length; i++) {
var def = TypeDefinitions[i];
var pFieldOffsets = Binary.FieldOffsetPointers[i];
if (pFieldOffsets != 0) {
bool available = true;

if (pFieldOffsets != 0)
{
// If the target address range is not mapped in the file, assume zeroes
try {
BinaryImage.Position = BinaryImage.MapVATR((ulong) pFieldOffsets);
if (BinaryImage.TryMapVATR((ulong)pFieldOffsets, out var fieldOffsetPosition))
{
BinaryImage.Position = fieldOffsetPosition;
var fieldOffsets = BinaryImage.ReadArray<uint>(def.FieldCount);
for (var fieldIndex = 0; fieldIndex < def.FieldCount; fieldIndex++)
offsets.Add(def.FieldIndex + fieldIndex, fieldOffsets[fieldIndex]);
}
catch (InvalidOperationException) {
available = false;
else
{
for (var fieldIndex = 0; fieldIndex < def.FieldCount; fieldIndex++)
offsets.Add(def.FieldIndex + fieldIndex, 0);
}

for (var f = 0; f < def.FieldCount; f++)
offsets.Add(def.FieldIndex + f, available? BinaryImage.ReadUInt32() : 0);
}
}

Expand Down

0 comments on commit 3982e5f

Please sign in to comment.