Пример #1
0
        private static IReadOnlyList <byte> ConvertHexToBinary(IReadOnlyList <byte> bytes)
        {
            var result = new List <byte>(bytes.Count / 2);

            var last   = '\0';
            var offset = 0;

            for (var i = 0; i < bytes.Count; i++)
            {
                var c = (char)bytes[i];
                if (!ReadHelper.IsHex(c))
                {
                    // TODO: do I need to assert this must be whitespace?
                    continue;
                }

                if (offset == 1)
                {
                    result.Add(HexToken.Convert(last, c));
                    offset = 0;
                }
                else
                {
                    offset++;
                }

                last = c;
            }

            return(result);
        }
Пример #2
0
        private static byte[] HexToBytes(string hex)
        {
            var result = new byte[hex.Length / 2];

            for (var i = 0; i < hex.Length; i += 2)
            {
                result[i / 2] = HexToken.Convert(hex[i], hex[i + 1]);
            }

            return(result);
        }
Пример #3
0
        public void Issue443()
        {
            const string hex =
                @"00 0F 4A 43 42 31 33 36 36 31 32 32 37 2E 70 64 66 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 50 44 46 20 43 41 52 4F 01 00 FF FF FF FF 00 00 00 00 00 04 DF 28 00 00 00 00 AF 51 7E 82 AF 52 D7 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 81 81 03 0D 00 00 25 50 44 46 2D 31 2E 31 0A 25 E2 E3 CF D3 0D 0A 31 20 30 20 6F 62 6A";

            var bytes = hex.Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(x => HexToken.Convert(x[0], x[1]));

            var str = OtherEncodings.BytesAsLatin1String(bytes.ToArray());

            var scanner = StringBytesTestConverter.Scanner(str);

            var result = FileHeaderParser.Parse(scanner.scanner, scanner.bytes, false, log);

            Assert.Equal(0, scanner.scanner.CurrentPosition);
            Assert.Equal(128, result.OffsetInFile);
            Assert.Equal(1.1m, result.Version);
            Assert.Equal("PDF-1.1", result.VersionString);
        }