Ejemplo n.º 1
0
        public void TestFromByteEnumerationWithWildcards(IEnumerable <Tuple <byte, bool> > input, int expectedLength, bool expectedHasWildcards)
        {
            var sut = BytePattern.From(input);

            Check.That(sut.Length).IsEqualTo(expectedLength);
            Check.That(sut.HasWildcards).IsEqualTo(expectedHasWildcards);
        }
Ejemplo n.º 2
0
        /// <summary>Reads a string from the address in the remote process with the given length and encoding. The string gets truncated at the first zero character.</summary>
        /// <param name="encoding">The encoding used by the string.</param>
        /// <param name="address">The address of the string.</param>
        /// <param name="length">The length of the string.</param>
        /// <returns>The string.</returns>
        public string ReadRemoteStringUntilFirstNullCharacter(Encoding encoding, IntPtr address, int length)
        {
            Contract.Requires(encoding != null);
            Contract.Requires(length >= 0);
            Contract.Ensures(Contract.Result <string>() != null);

            var data = ReadRemoteMemory(address, length * encoding.GetSimpleByteCountPerChar());

            // TODO We should cache the pattern per encoding.
            var index = PatternScanner.FindPattern(BytePattern.From(new byte[encoding.GetSimpleByteCountPerChar()]), data);

            if (index == -1)
            {
                index = data.Length;
            }

            try
            {
                return(Encoding.UTF8.GetString(data, 0, Math.Min(index, data.Length)));
            }
            catch
            {
                return(string.Empty);
            }
        }
Ejemplo n.º 3
0
        public void TestFromByteEnumeration(IEnumerable <byte> input, int expectedLength)
        {
            var sut = BytePattern.From(input);

            Check.That(sut.Length).IsEqualTo(expectedLength);
            Check.That(sut.HasWildcards).IsFalse();
        }