예제 #1
0
        public bool Decode(byte[] data, int len, string key)
        {
            blf_ctx c;
            uint    xl, xr;
            int     i;

            if (len % 8 != 0)
            {
                return(false);
            }
            c   = new blf_ctx();
            c.S = new uint[4, 256];
            c.P = new uint[18];

            InitBlowfish(c, key, key.Length);
            for (i = 0; i < len; i += 8)
            {
                //    memcpy(&xl, data + i, sizeof(UINT32));
                //    memcpy(&xr, data + i + 4, sizeof(UINT32));
                xl = (uint)ConvertHelper.BytesToInt32(data, i, true);
                xr = (uint)ConvertHelper.BytesToInt32(data, i + 4, true);
                Blowfish_decipher(c, ref xl, ref xr);

                //memcpy(data + i, &xl, sizeof(UINT32));
                //memcpy(data + i + 4, &xr, sizeof(UINT32));
                byte[] byteXl = ConvertHelper.Int32ToBytes((int)xl, true);
                byte[] byteXr = ConvertHelper.Int32ToBytes((int)xr, true);
                Array.Copy(byteXl, 0, data, i, 4);
                Array.Copy(byteXr, 0, data, i + 4, 4);
            }
            return(true);
        }
예제 #2
0
        public static VideoData DecodeVideo(int len, byte[] data, byte[] before)
        {
            VideoData video    = new VideoData();
            int       tmpMagic = ConvertHelper.BytesToInt32(data, 0, true);

            video.NewFlag = (tmpMagic == MAGIC_NORMAL);
            int locIdx = 12;

            if (video.NewFlag)
            {
                video.Type       = (enumVideoZipType)data[locIdx++];
                video.Resolution = (enumVideoResolution)data[locIdx++];
                video.Video      = data[locIdx++];
                video.NeedPhoto  = data[locIdx++];
                video.IsKeyImg   = data[locIdx++];

                video.Time     = ConvertHelper.BytesToInt32(data, locIdx, true);
                locIdx        += 4;
                video.TakeTime = ConvertHelper.BytesToInt32(data, locIdx, true);
                locIdx        += 4;
                video.Length   = ConvertHelper.BytesToInt32(data, locIdx, true);
                locIdx        += 4;

                if (len >= locIdx)
                {
                    video.Data = new byte[len - locIdx];
                    Array.Copy(data, locIdx, video.Data, 0, len - locIdx);
                }
            }
            else
            {
                locIdx     = 0;
                video.Data = new byte[len - locIdx + before.Length];
                Array.Copy(before, video.Data, before.Length);
                Array.Copy(data, locIdx, video.Data, before.Length, len - locIdx);
            }
            //Console.WriteLine("{0}={1}", len, video.NewFlag);

            //try
            //{
            //    System.IO.MemoryStream ms2 = new System.IO.MemoryStream(video.Data);
            //    System.Drawing.Image img2 = System.Drawing.Image.FromStream(ms2);
            //    img2.Save("bbb.jpg");
            //}
            //catch (Exception e)
            //{
            //    Console.WriteLine(e.Message);
            //}

            return(video);
        }
예제 #3
0
        public static NormalDataStruct DecodeData(byte[] buff)
        {
            NormalDataStruct data = new NormalDataStruct();

            int locIdx = 4;

            data.MagicNumber = ConvertHelper.BytesToInt32(buff, 0, true);
            data.Code        = (enumCommandType)ConvertHelper.BytesToInt16(buff, locIdx, true);
            locIdx          += 2;

            data.contentLen = ConvertHelper.BytesToInt32(buff, locIdx, true);
            locIdx         += 4;

            data.FillField = ConvertHelper.BytesToInt16(buff, locIdx, true);
            locIdx        += 2;

            data.Content = new byte[data.contentLen];
            Array.Copy(buff, locIdx, data.Content, 0, data.contentLen);

            return(data);
        }
예제 #4
0
        public static WifiRespInfo DecodeWifiSearch(byte[] buff)
        {
            WifiRespInfo info = new WifiRespInfo();

            int locIdx = 4;

            info.Magic = ConvertHelper.BytesToInt32(buff, 0, true);
            info.Code  = (enumCommandType)buff[locIdx++];

            int wifiIDLen = buff[locIdx++];

            byte[] wifiIDByte = new byte[wifiIDLen];
            Array.Copy(buff, locIdx, wifiIDByte, 0, wifiIDLen);
            locIdx += wifiIDLen;
            info.ID = ConvertHelper.BytesToString(wifiIDByte, Encoding.ASCII);

            int wifiVersionLen = buff[locIdx++];

            byte[] wifiVersionByte = new byte[wifiVersionLen];
            Array.Copy(buff, locIdx, wifiVersionByte, 0, wifiVersionLen);
            locIdx      += wifiVersionLen;
            info.Version = ConvertHelper.BytesToString(wifiVersionByte, Encoding.ASCII);

            int wifiWebLen = buff[locIdx++];

            byte[] wifiWebByte = new byte[wifiWebLen];
            Array.Copy(buff, locIdx, wifiWebByte, 0, wifiWebLen);
            locIdx  += wifiWebLen;
            info.Web = ConvertHelper.BytesToString(wifiWebByte, Encoding.ASCII);

            int wifiNameLen = buff[locIdx++];

            byte[] wifiNameByte = new byte[wifiNameLen];
            Array.Copy(buff, locIdx, wifiNameByte, 0, wifiNameLen);
            locIdx   += wifiNameLen;
            info.Name = ConvertHelper.BytesToString(wifiNameByte, Encoding.ASCII);

            info.IP            = string.Format("{0}.{1}.{2}.{3}", buff[locIdx++], buff[locIdx++], buff[locIdx++], buff[locIdx++]);
            info.NetMask       = string.Format("{0}.{1}.{2}.{3}", buff[locIdx++], buff[locIdx++], buff[locIdx++], buff[locIdx++]);
            info.IsDhcp        = buff[locIdx++] == 1;
            info.IPStatic      = string.Format("{0}.{1}.{2}.{3}", buff[locIdx++], buff[locIdx++], buff[locIdx++], buff[locIdx++]);
            info.NetMaskStatic = string.Format("{0}.{1}.{2}.{3}", buff[locIdx++], buff[locIdx++], buff[locIdx++], buff[locIdx++]);
            info.NetGateStatic = string.Format("{0}.{1}.{2}.{3}", buff[locIdx++], buff[locIdx++], buff[locIdx++], buff[locIdx++]);
            info.DNS1          = string.Format("{0}.{1}.{2}.{3}", buff[locIdx++], buff[locIdx++], buff[locIdx++], buff[locIdx++]);
            info.DNS2          = string.Format("{0}.{1}.{2}.{3}", buff[locIdx++], buff[locIdx++], buff[locIdx++], buff[locIdx++]);
            byte[] wifiPort = new byte[2];
            info.Port = ConvertHelper.BytesToInt16(buff, locIdx, true);
            locIdx   += 2;

            info.IsHttps = buff[locIdx++] == 1;

            int wifiNOLen = buff[locIdx++];

            byte[] wifiNOByte = new byte[wifiNameLen];
            Array.Copy(buff, locIdx, wifiNOByte, 0, wifiNOLen);
            Array.Reverse(wifiNOByte);
            locIdx     += wifiNOLen;
            info.Number = ConvertHelper.BytesToString(wifiNOByte, Encoding.ASCII);

            info.Type = buff[locIdx++];

            return(info);
        }