in src/BinaryParsers/ElfBinary/Dwarf/DwarfCommonInformationEntry.cs [363:463]
private static ulong ReadEncodedAddress(DwarfMemoryReader data, DwarfExceptionHandlingEncoding encoding, DwarfExceptionHandlingFrameParsingInput input)
{
bool signExtendValue = false;
ulong baseAddress = 0;
switch (encoding & DwarfExceptionHandlingEncoding.Modifiers)
{
case DwarfExceptionHandlingEncoding.PcRelative:
signExtendValue = true;
baseAddress = (ulong)data.Position;
if (input.PcRelativeAddress != ulong.MaxValue)
{
baseAddress += input.PcRelativeAddress;
}
break;
case DwarfExceptionHandlingEncoding.TextRelative:
signExtendValue = true;
if (input.TextAddress != ulong.MaxValue)
{
baseAddress = input.TextAddress;
}
break;
case DwarfExceptionHandlingEncoding.DataRelative:
signExtendValue = true;
if (input.DataAddress != ulong.MaxValue)
{
baseAddress = input.DataAddress;
}
break;
case DwarfExceptionHandlingEncoding.FunctionRelative:
signExtendValue = true;
break;
case DwarfExceptionHandlingEncoding.Aligned:
{
int alignment = data.Position % input.DefaultAddressSize;
if (alignment > 0)
{
data.Position += input.DefaultAddressSize - alignment;
}
}
break;
}
ulong address = 0;
switch (encoding & DwarfExceptionHandlingEncoding.Mask)
{
case DwarfExceptionHandlingEncoding.Signed:
case DwarfExceptionHandlingEncoding.AbsolutePointer:
address = data.ReadUlong(input.DefaultAddressSize);
break;
case DwarfExceptionHandlingEncoding.UnsignedData2:
address = data.ReadUshort();
break;
case DwarfExceptionHandlingEncoding.UnsignedData4:
address = data.ReadUint();
break;
case DwarfExceptionHandlingEncoding.SignedData8:
case DwarfExceptionHandlingEncoding.UnsignedData8:
address = data.ReadUlong();
break;
case DwarfExceptionHandlingEncoding.Uleb128:
address = data.LEB128();
break;
case DwarfExceptionHandlingEncoding.Sleb128:
address = data.SLEB128();
break;
case DwarfExceptionHandlingEncoding.SignedData2:
address = (ulong)(long)(short)data.ReadUshort();
break;
case DwarfExceptionHandlingEncoding.SignedData4:
address = (ulong)(long)(int)data.ReadUint();
break;
}
if (signExtendValue && input.DefaultAddressSize < System.Runtime.InteropServices.Marshal.SizeOf(address.GetType()))
{
ulong sign_bit = 1UL << ((input.DefaultAddressSize * 8) - 1);
if ((sign_bit & address) != 0)
{
ulong mask = ~sign_bit + 1;
address |= mask;
}
}
return baseAddress + address;
}