in ILRepack/ResReader.cs [509:549]
internal IEnumerator<Res> GetResources()
{
// Get the type information from the data section. Also,
// sort all of the data section's indexes to compute length of
// the serialized data for this type (making sure to subtract
// off the length of the type code).
KeyValuePair<int, string>[] dataPositionsAndNames = new KeyValuePair<int, string>[_numResources];
lock (this)
{
// Read all the positions of data within the data section.
for (int i = 0; i < _numResources; i++)
{
_store.BaseStream.Position = _nameSectionOffset + GetNamePosition(i);
// Skip over name of resource
int byteLen = Read7BitEncodedInt();
var bytes = _store.ReadBytes(byteLen);
if (bytes.Length != byteLen)
throw new FormatException("BadImageFormat_ResourceNameCorrupted_NameIndex");
dataPositionsAndNames[i] = new KeyValuePair<int, string>(_store.ReadInt32(), Encoding.Unicode.GetString(bytes, 0, byteLen));
}
Array.Sort(dataPositionsAndNames, (a,b) => a.Key-b.Key);
for (int i = 0; i < _numResources; i++)
{
int dataPos = dataPositionsAndNames[i].Key;
long nextData = (i < _numResources - 1) ? dataPositionsAndNames[i + 1].Key + _dataSectionOffset : _store.BaseStream.Length;
// Read type code then byte[]
_store.BaseStream.Position = _dataSectionOffset + dataPos;
int typeCode = Read7BitEncodedInt();
string resourceType = TypeNameFromTypeCode(typeCode);
int len = (int)(nextData - _store.BaseStream.Position);
byte[] bytes = _store.ReadBytes(len);
if (bytes.Length != len)
throw new FormatException("BadImageFormat_ResourceNameCorrupted");
yield return new Res(dataPositionsAndNames[i].Value, resourceType, bytes, typeCode, dataPos);
}
}
yield break;
}