in ILRepack/ResReader.cs [203:297]
public ResReader(Stream stream)
{
_store = new BinaryReader(stream, Encoding.UTF8);
_bf = new BinaryFormatter(null, new StreamingContext(StreamingContextStates.File | StreamingContextStates.Persistence));
try
{
// Read ResourceManager header
// Check for magic number
int magicNum = _store.ReadInt32();
if (magicNum != ResourceManager.MagicNumber)
throw new ArgumentException("Resources_StreamNotValid");
// Assuming this is ResourceManager header V1 or greater, hopefully
// after the version number there is a number of bytes to skip
// to bypass the rest of the ResMgr header.
int resMgrHeaderVersion = _store.ReadInt32();
if (resMgrHeaderVersion > 1)
{
int numBytesToSkip = _store.ReadInt32();
_store.BaseStream.Seek(numBytesToSkip, SeekOrigin.Current);
}
else
{
SkipInt32(); // We don't care about numBytesToSkip.
// Read in type name for a suitable ResourceReader
// Note ResourceWriter & InternalResGen use different Strings.
String readerType = _store.ReadString();
// Skip over type name for a suitable ResourceSet
SkipString();
}
// Read RuntimeResourceSet header
// Do file version check
int version = _store.ReadInt32();
if (version != 2 && version != 1)
throw new ArgumentException("Arg_ResourceFileUnsupportedVersion");
_version = version;
_numResources = _store.ReadInt32();
// Read type positions into type positions array.
// But delay initialize the type table.
int numTypes = _store.ReadInt32();
_typeNamePositions = new int[numTypes];
for (int i = 0; i < numTypes; i++)
{
_typeNamePositions[i] = (int)_store.BaseStream.Position;
// Skip over the Strings in the file. Don't create types.
SkipString();
}
// Prepare to read in the array of name hashes
// Note that the name hashes array is aligned to 8 bytes so
// we can use pointers into it on 64 bit machines. (4 bytes
// may be sufficient, but let's plan for the future)
// Skip over alignment stuff. All public .resources files
// should be aligned No need to verify the byte values.
long pos = _store.BaseStream.Position;
int alignBytes = ((int)pos) & 7;
if (alignBytes != 0)
{
for (int i = 0; i < 8 - alignBytes; i++)
{
_store.ReadByte();
}
}
// Read in the array of name hashes
_nameHashes = new int[_numResources];
for (int i = 0; i < _numResources; i++)
_nameHashes[i] = _store.ReadInt32();
// Read in the array of relative positions for all the names.
_namePositions = new int[_numResources];
for (int i = 0; i < _numResources; i++)
_namePositions[i] = _store.ReadInt32();
// Read location of data section.
_dataSectionOffset = _store.ReadInt32();
// Store current location as start of name section
_nameSectionOffset = _store.BaseStream.Position;
}
catch (EndOfStreamException)
{
throw new BadImageFormatException("BadImageFormat_ResourcesHeaderCorrupted");
}
catch (IndexOutOfRangeException)
{
throw new BadImageFormatException("BadImageFormat_ResourcesHeaderCorrupted");
}
}