Esempio n. 1
0
        private void ProcessRows(MemoryMappedViewAccessor accessor)
        {
            UInt32 lastPos = 0;

            _BlockCount = accessor.ReadUInt16(8);
            _BlockSize = accessor.ReadUInt16(10);

            while (true)
            {
                UInt32 curPos = accessor.ReadUInt32(4) % _BlockCount;

                var bag = _MissingItems;
                _MissingItems = new ConcurrentBag<int>();

                int temp = 0;
                while (bag.TryTake(out temp))
                    readLineAndProcess(accessor, temp);

                if (lastPos == curPos)
                {
                    System.Threading.Thread.Sleep(1000);
                }
                else
                {
                    if (lastPos < curPos)
                    {
                        for (UInt32 x = lastPos; x < curPos; ++x)
                            readLineAndProcess(accessor, (int)x);
                    }
                    else
                    {
                        for (UInt32 x = lastPos; x < _BlockCount; ++x)
                            readLineAndProcess(accessor, (int)x);

                        for (UInt32 x = 0; x < curPos; ++x)
                            readLineAndProcess(accessor, (int)x);
                    }

                    lastPos = curPos;
                }
            };
        }
Esempio n. 2
0
        private void LoadHeaderAndStreams(PeHeaderReader pe, MemoryMappedViewAccessor mm)
        {
            var clrDataDir = pe.DataDirectories[PeHeaderReader.Image_Directory_Entry_Type.COM_DESCRIPTOR];
            if (Marshal.SizeOf(typeof(IMAGE_COR20_HEADER)) != clrDataDir.Size)
                throw new Exception("Size wrong.");

            mm.Read<IMAGE_COR20_HEADER>(pe.GetFileOffset(clrDataDir.VirtualAddress), out mHeader);
            if (mHeader.cb != clrDataDir.Size)
                throw new Exception("Size wrong.");

            var metaLoc = pe.GetFileOffset(mHeader.MetaData.VirtualAddress);
            mm.Read<MetaDataHeaderPart1>(metaLoc, out mMetaHeader);
            var versionBytes = new byte[mMetaHeader.VersionLength];

            metaLoc += Marshal.SizeOf(typeof(MetaDataHeaderPart1));
            mm.ReadArray<byte>(metaLoc, versionBytes, 0, versionBytes.Length);
            int versionSize = 0;
            while (versionSize < versionBytes.Length && versionBytes[versionSize] != 0)
                versionSize++;
            mVersionName = Encoding.ASCII.GetString(versionBytes, 0, versionSize);

            metaLoc += mMetaHeader.VersionLength;
            mMetaDataFlags = mm.ReadUInt16(metaLoc);
            metaLoc += 2;
            uint numberOfMetaStreams = mm.ReadUInt16(metaLoc);
            metaLoc += 2;

            for (int i = 0; i < numberOfMetaStreams; i++)
            {
                MetaDataStream mds;
                mm.Read<MetaDataStream>(metaLoc, out mds);
                metaLoc += Marshal.SizeOf(typeof(MetaDataStream));
                byte b;
                StringBuilder sb = new StringBuilder();
                while ((b = mm.ReadByte(metaLoc++)) != 0)
                {
                    sb.Append((char)b);
                }
                metaLoc += 3;
                metaLoc &= ~3;
                mMetaStreams.Add(sb.ToString(), mds);
            }
        }