Exemplo n.º 1
0
        public static byte[] ConvertFromWindowsNewlines(byte[] bytes)
        {
            FileCategory category = PersistenceUtilities.IdentifyCategory(bytes);

            if (!PersistenceUtilities.IsBinary(category))
            {
                string asString = FileContent.DecodeString(bytes);
                // Only evil windows gets evil windows line breaks, and only if this is some sort of ASCII:
                asString = asString.Replace("\r\n", "\n");
                return(FileContent.EncodeString(asString));
            }

            return(bytes);
        }
Exemplo n.º 2
0
        private static void Decode(ProgramFile programFile, string input)
        {
            try
            {
                string decodedString;
                try
                {
                    // base64 encoding

                    // Fix for issue #429.  See comment up in EncodeBase64() method above for an explanation:
                    string massagedInput = input.Replace(',', '/');

                    byte[]       decodedBuffer = DecodeBase64ToBinary(massagedInput);
                    FileCategory whatKind      = PersistenceUtilities.IdentifyCategory(decodedBuffer);
                    if (whatKind == FileCategory.ASCII || whatKind == FileCategory.KERBOSCRIPT)
                    {
                        decodedString             = Encoding.ASCII.GetString(decodedBuffer);
                        programFile.StringContent = decodedString;
                    }
                    else
                    {
                        programFile.BinaryContent = decodedBuffer;
                    }
                }
                catch (FormatException)
                {
                    // standard encoding
                    decodedString             = PersistenceUtilities.DecodeLine(input);
                    programFile.StringContent = decodedString;
                }
            }
            catch (Exception e)
            {
                SafeHouse.Logger.Log(string.Format("Exception decoding: {0} | {1}", e, e.Message));
            }
        }