示例#1
0
        /// <summary>
        /// バイト配列からインスタンスを生成する。
        /// 配列末尾に不要なデータがあっても無視する。
        /// </summary>
        /// <param name="src">変換対象byte配列</param>
        /// <param name="offset">読み込み開始オフセット</param>
        public WoditorString(ref byte[] src, long offset = 0)
        {
            var innerOffset = offset;

            var lengthByte = new byte[4];

            for (var i = 0; i < 4; i++)
            {
                lengthByte[i] = src[innerOffset];
                innerOffset++;
            }

            var length = lengthByte.ToInt32(Endian.Woditor);
            // 文字列の末尾に '0' が付与されているため、一部の処理では無視する
            var removeZeroLength = length - 1;

            var chars = new byte[removeZeroLength];

            Array.Copy(src, innerOffset, chars, 0, removeZeroLength);

            String = ToEncoding.ToUnicode(chars);

            // 長さ
            ByteLength = (int)(innerOffset - offset) + length;

            // byte配列
            var copy = new byte[ByteLength];

            Array.Copy(src, offset, copy, 0, ByteLength);
            StringByte = copy;
        }
示例#2
0
        protected string ConvertByteToString(byte[] bytes)
        {
            if (bytes[0] == 0)
            {
                return("");
            }
            int num = 0;

            while (num < bytes.Length && bytes[num] != 0)
            {
                num++;
            }
            byte[] array = new byte[num];
            for (int i = 0; i < num; i++)
            {
                array[i] = bytes[i];
            }
            string result;

            try
            {
                result = ToEncoding.ToUnicode(array);
            }
            catch (Exception)
            {
                byte[] array2 = new byte[array.Length - 1];
                for (int j = 0; j < array.Length - 1; j++)
                {
                    array2[j] = array[j];
                }
                try
                {
                    result = ToEncoding.ToUnicode(array2);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Failed to read buf: {0}", Utils.HexDump(array, 16));
                    using (FileStream fileStream = File.Create("__debug.dat"))
                    {
                        fileStream.Write(array, 0, array.Length);
                    }
                    throw ex;
                }
            }
            return(result);
        }
 protected string ConvertByteToString(byte[] bytes)
 {
     if (bytes[0] != 0)
     {
         int i;
         for (i = 0; i < bytes.Length && bytes[i] != 0; i++)
         {
         }
         byte[] array = new byte[i];
         for (int j = 0; j < i; j++)
         {
             array[j] = bytes[j];
         }
         try
         {
             return(ToEncoding.ToUnicode(array));
         }
         catch (Exception)
         {
             byte[] array2 = new byte[array.Length - 1];
             for (int k = 0; k < array.Length - 1; k++)
             {
                 array2[k] = array[k];
             }
             try
             {
                 return(ToEncoding.ToUnicode(array2));
             }
             catch (Exception ex)
             {
                 Console.WriteLine("Failed to read buf: {0}", Utils.HexDump(array, 16));
                 using (FileStream fileStream = File.Create("__debug.dat"))
                 {
                     fileStream.Write(array, 0, array.Length);
                 }
                 throw ex;
             }
         }
     }
     return("");
 }