Пример #1
0
        private int ensureSpace(int aiType, int aiReqSize)
        {
            int num = 0;

            if (this.m_eDefaultMode == 0)
            {
                num = (aiReqSize + 4) + 4;
            }
            else if (this.m_eDefaultMode == 1)
            {
                int    apuValue  = 0;
                byte[] apcBuffer = new byte[6];
                int    num3      = TLVUtil.DecodeVByte32(ref apuValue, apcBuffer, 0);
                aiType = apuValue;
                int num4 = TLVUtil.DecodeVByte32(ref apuValue, apcBuffer, 0);
                num = (num3 + num4) + aiReqSize;
            }
            else
            {
                return(-8);
            }
            if ((this.m_pcBuf == null) || (this.m_iUsedSize <= 0))
            {
                num += this.m_ptHeader.getSize();
            }
            if ((num < 0) || ((num + this.m_iUsedSize) < 0))
            {
                return(-3);
            }
            if (num > (this.m_iAllocSize - this.m_iUsedSize))
            {
                int num5 = this.m_iAllocSize + 0x400;
                while (num5 < (num + this.m_iUsedSize))
                {
                    num5 *= 2;
                }
                if (num5 < 0)
                {
                    num5 = num + this.m_iUsedSize;
                }
                byte[] dst  = new byte[num5];
                bool   flag = false;
                if ((this.m_pcBuf != null) || (this.m_iUsedSize > 0))
                {
                    Buffer.BlockCopy(this.m_pcBuf, 0, dst, 0, this.m_iUsedSize);
                }
                else
                {
                    flag = true;
                }
                this.m_iAllocSize       = num5;
                this.m_pcBuf            = dst;
                this.m_ptHeader.h_pcBuf = this.m_pcBuf;
                if (flag)
                {
                    this.clear();
                }
            }
            return(0);
        }
Пример #2
0
 public bool isValidTLVPack(byte[] apcBuf, int aiUsedSize, int offset)
 {
     if (apcBuf != null)
     {
         if (aiUsedSize < this.m_ptHeader.getSize())
         {
             return(false);
         }
         TLVPackHeader header = new TLVPackHeader {
             h_pcBuf = apcBuf,
             offset  = offset
         };
         if (header.getMagic() != 0x81)
         {
             return(false);
         }
         int aiSize = aiUsedSize - header.getSize();
         if (header.getUsedSize() != aiSize)
         {
             return(false);
         }
         byte[] buffer  = TLVUtil.getCheckSum(apcBuf, offset + header.getSize(), aiSize);
         byte[] buffer2 = header.getCheckSum();
         if ((buffer[0] != buffer2[0]) || (buffer[1] != buffer2[1]))
         {
             return(false);
         }
         if (aiSize == 0)
         {
             return(true);
         }
         FixedSizeTLVBody     body = new FixedSizeTLVBody();
         tVariableSizeTLVItem item = new tVariableSizeTLVItem();
         TLVBody body2             = null;
         if (header.getMode() == 0)
         {
             body2 = body;
         }
         else if (header.getMode() == 1)
         {
             body2 = item;
         }
         else
         {
             return(false);
         }
         if (body2.MapTo(apcBuf, offset + aiUsedSize, offset + header.getSize()))
         {
             while (body2.iNextOffset != 0)
             {
                 if (!body2.MapTo(apcBuf, offset + aiUsedSize, body2.iNextOffset))
                 {
                     return(false);
                 }
             }
             return(true);
         }
     }
     return(false);
 }
Пример #3
0
 public int addByteArray(int aiType, byte[] aoVal, int size)
 {
     if (0 > this.ensureSpace(aiType, size))
     {
         return(-2);
     }
     if (this.m_eDefaultMode == 0)
     {
         Buffer.BlockCopy(TLVUtil.int2byte(aiType, 4, true), 0, this.m_pcBuf, this.m_iUsedSize, 4);
         this.m_iUsedSize += 4;
         Buffer.BlockCopy(TLVUtil.int2byte(size, 4, true), 0, this.m_pcBuf, this.m_iUsedSize, 4);
         this.m_iUsedSize += 4;
     }
     else if (this.m_eDefaultMode == 1)
     {
         int num = TLVUtil.EncodeVByte32(aiType, this.m_pcBuf, this.m_iUsedSize);
         this.m_iUsedSize += num;
         int num2 = TLVUtil.EncodeVByte32(size, this.m_pcBuf, this.m_iUsedSize);
         this.m_iUsedSize += num2;
     }
     else
     {
         return(-8);
     }
     Buffer.BlockCopy(aoVal, 0, this.m_pcBuf, this.m_iUsedSize, size);
     this.m_iUsedSize += size;
     return(0);
 }
Пример #4
0
        public int Detach(ref byte[] appcBufFather, ref int apiUsedSizeFather, ref int apiAllocSizeFather)
        {
            if (((appcBufFather == null) && (apiUsedSizeFather == 0)) && (apiAllocSizeFather == 0))
            {
                this.m_pcBuf = null;
                this.clear();
                return(0);
            }
            if (appcBufFather == null)
            {
                return(-4);
            }
            appcBufFather      = null;
            apiUsedSizeFather  = 0;
            apiAllocSizeFather = 0;
            appcBufFather      = this.m_pcBuf;
            apiUsedSizeFather  = this.m_iUsedSize;
            apiAllocSizeFather = this.m_iAllocSize;
            byte[] x = TLVUtil.getCheckSum(this.m_pcBuf, this.m_ptHeader.getSize(), this.m_iUsedSize - this.m_ptHeader.getSize());
            this.m_ptHeader.setCheckSum(x);
            int num = this.m_iUsedSize - this.m_ptHeader.getSize();

            this.m_ptHeader.setUsedSize(num);
            this.m_pcBuf = null;
            this.clear();
            return(0);
        }
Пример #5
0
        public static void appendIntTobuf(byte[] dstBuf, ref int dstOffset, int srcInt)
        {
            byte[] apcBuffer = new byte[4];
            int    count     = TLVUtil.EncodeVByte32(srcInt, apcBuffer, 0);

            Buffer.BlockCopy(apcBuffer, 0, dstBuf, dstOffset, count);
            dstOffset += count;
        }
Пример #6
0
 public static void getIntFrombuf(byte[] srcBuf, ref int srcOffset, ref int dstInt)
 {
     if (srcOffset < srcBuf.Length)
     {
         int num = TLVUtil.DecodeVByte32(ref dstInt, srcBuf, srcOffset);
         srcOffset += num;
     }
 }
Пример #7
0
        public int GetWord(int aiType, ref int apwVal)
        {
            byte[] apoVal = null;
            int    num    = this.getByteArray(aiType, ref apoVal);

            if (num < 0)
            {
                return(num);
            }
            apwVal = TLVUtil.byte2int(apoVal, 0, 4, this.m_eDefaultMode == 0);
            return(0);
        }
Пример #8
0
 public int SizeNumber(int aiType, int aiSizeOfType, int eTLVMode)
 {
     if (eTLVMode == 0)
     {
         return(8 + aiSizeOfType);
     }
     if (eTLVMode == 1)
     {
         byte[] apcBuffer = new byte[6];
         int    num       = TLVUtil.EncodeVByte32(aiType, apcBuffer, 0);
         int    num2      = TLVUtil.EncodeVByte32(aiSizeOfType, apcBuffer, 0);
         return((num + num2) + aiSizeOfType);
     }
     return(0x7fffffff);
 }
Пример #9
0
 public int SizeType(int aiType, int eTLVMode)
 {
     if (eTLVMode == 0)
     {
         return(4);
     }
     if (eTLVMode != 1)
     {
         return(0x7fffffff);
     }
     if (aiType == 0)
     {
         return(0x7fffffff);
     }
     byte[] apcBuffer = new byte[6];
     return(TLVUtil.EncodeVByte32(aiType, apcBuffer, 0));
 }
Пример #10
0
 public int SizeLength(int aiLen, int eTLVMode)
 {
     if (eTLVMode == 0)
     {
         return(4);
     }
     if (eTLVMode != 1)
     {
         return(0x7fffffff);
     }
     if (aiLen == -1)
     {
         return(0x7fffffff);
     }
     byte[] apcBuffer = new byte[6];
     return(TLVUtil.EncodeVByte32(aiLen, apcBuffer, 0));
 }
Пример #11
0
        public int GetBool(int aiType, ref bool apbVal)
        {
            byte[] apoVal = null;
            int    num    = this.getByteArray(aiType, ref apoVal);

            if (num < 0)
            {
                return(num);
            }
            if (TLVUtil.byte2int(apoVal, 0, 4, this.m_eDefaultMode == 0) == 0)
            {
                apbVal = false;
            }
            else
            {
                apbVal = true;
            }
            return(0);
        }
Пример #12
0
        public static int mmpkg_mini_head_ntoh(byte[] packBuf, out MMPKG_mini_header header)
        {
            header = null;
            if ((packBuf == null) || (packBuf.Length <= 2))
            {
                return(-1);
            }
            int offSet = 0;

            header = new MMPKG_mini_header();
            header.setHHeaderBits(packBuf);
            if ((header.len == 0) || (packBuf.Length < header.len))
            {
                return(-4);
            }
            offSet    += 2;
            header.ret = TLVUtil.byte2int(packBuf, offSet, 4, true);
            offSet    += 4;
            header.uin = (uint)TLVUtil.byte2int(packBuf, offSet, 4, true);
            offSet    += 4;
            if (header.server_id_len > 0)
            {
                header.server_id = new byte[header.server_id_len];
                Buffer.BlockCopy(packBuf, offSet, header.server_id, 0, header.server_id_len);
                offSet += header.server_id_len;
            }
            int dstInt = 0;

            getIntFrombuf(packBuf, ref offSet, ref dstInt);
            header.cmd_id = (ushort)dstInt;
            getIntFrombuf(packBuf, ref offSet, ref dstInt);
            header.compress_len = (uint)dstInt;
            getIntFrombuf(packBuf, ref offSet, ref dstInt);
            header.compressed_len = (uint)dstInt;
            getIntFrombuf(packBuf, ref offSet, ref dstInt);
            header.cert_version = (ushort)dstInt;
            dstInt = 0;
            getIntFrombuf(packBuf, ref offSet, ref dstInt);
            header.device_type = (ushort)dstInt;
            return(0);
        }
Пример #13
0
        public static int mmpkg_mini_head_hton(MMPKG_mini_header header, out byte[] outbuff)
        {
            outbuff = null;
            if (header == null)
            {
                return(-1);
            }
            int num = _mmpkg_validate(header);

            if (num != 0)
            {
                return(num);
            }
            byte[] dst       = new byte[header.getMaxSize()];
            int    dstOffset = 0;

            byte[] src = header.getHeaderBits();
            Buffer.BlockCopy(src, 0, dst, dstOffset, src.Length);
            dstOffset += src.Length;
            byte[] buffer3 = TLVUtil.int2byte(header.ret, 4, true);
            Buffer.BlockCopy(buffer3, 0, dst, dstOffset, buffer3.Length);
            dstOffset += buffer3.Length;
            buffer3    = TLVUtil.int2byte((int)header.uin, 4, true);
            Buffer.BlockCopy(buffer3, 0, dst, dstOffset, buffer3.Length);
            dstOffset += buffer3.Length;
            Buffer.BlockCopy(header.server_id, 0, dst, dstOffset, header.server_id.Length);
            dstOffset += header.server_id.Length;
            appendIntTobuf(dst, ref dstOffset, header.cmd_id);
            appendIntTobuf(dst, ref dstOffset, (int)header.compress_len);
            appendIntTobuf(dst, ref dstOffset, (int)header.compressed_len);
            appendIntTobuf(dst, ref dstOffset, header.cert_version);
            appendIntTobuf(dst, ref dstOffset, header.device_type);
            int count = dstOffset;

            outbuff = new byte[count];
            Buffer.BlockCopy(dst, 0, outbuff, 0, count);
            header.len = (byte)count;
            Buffer.BlockCopy(header.getHeaderBits(), 0, outbuff, 0, 1);
            return(0);
        }
Пример #14
0
        public int addNestedTLV(int aiType, TLVPack apoVal)
        {
            if (0 > this.ensureSpace(aiType, apoVal.m_iUsedSize))
            {
                return(-2);
            }
            int iUsedSize = this.m_iUsedSize;

            if (this.m_eDefaultMode == 0)
            {
                Buffer.BlockCopy(TLVUtil.int2byte(aiType, 4, true), 0, this.m_pcBuf, this.m_iUsedSize, 4);
                this.m_iUsedSize += 4;
                Buffer.BlockCopy(TLVUtil.int2byte(apoVal.m_iUsedSize, 4, true), 0, this.m_pcBuf, this.m_iUsedSize, 4);
                this.m_iUsedSize += 4;
            }
            else if (this.m_eDefaultMode == 1)
            {
                int num2 = TLVUtil.EncodeVByte32(aiType, this.m_pcBuf, this.m_iUsedSize);
                this.m_iUsedSize += num2;
                int num3 = TLVUtil.EncodeVByte32(apoVal.m_iUsedSize, this.m_pcBuf, this.m_iUsedSize);
                this.m_iUsedSize += num3;
            }
            else
            {
                return(-8);
            }
            if (apoVal.m_iUsedSize > 0)
            {
                int apiSize = 0;
                apiSize = this.m_iAllocSize - this.m_iUsedSize;
                int num5 = apoVal.CopyTo(this.m_pcBuf, this.m_iUsedSize, ref apiSize);
                if (num5 != 0)
                {
                    this.m_iUsedSize = iUsedSize;
                    return(num5);
                }
            }
            this.m_iUsedSize += apoVal.m_iUsedSize;
            return(0);
        }
Пример #15
0
            public override bool MapTo(byte[] apcSrc, int aiSrcSize, int aiOffset)
            {
                if (((apcSrc == null) || (aiSrcSize <= 0)) || ((aiOffset < 0) || (aiOffset >= aiSrcSize)))
                {
                    return(false);
                }
                int apuValue = 0;
                int num2     = TLVUtil.DecodeVByte32(ref apuValue, apcSrc, aiOffset);
                int num3     = apuValue;
                int num4     = TLVUtil.DecodeVByte32(ref apuValue, apcSrc, aiOffset + num2);
                int num5     = apuValue;

                base.pcValPtrOffset = (aiOffset + num2) + num4;
                int num6 = ((aiOffset + num2) + num4) + num5;

                if (num5 < 0)
                {
                    return(false);
                }
                if (base.pcValPtrOffset > aiSrcSize)
                {
                    return(false);
                }
                if (num6 > aiSrcSize)
                {
                    return(false);
                }
                if (num6 == aiSrcSize)
                {
                    base.iNextOffset = 0;
                }
                else
                {
                    base.iNextOffset = num6;
                }
                base.iType    = num3;
                base.iLength  = num5;
                base.pcValPtr = apcSrc;
                return(true);
            }
Пример #16
0
 private void clear()
 {
     if (this.m_pcBuf == null)
     {
         this.m_iAllocSize = 0;
         this.m_iUsedSize  = 0;
         this.m_ptHeader   = null;
     }
     else if (this.m_iAllocSize < this.m_ptHeader.getSize())
     {
         this.m_ptHeader  = null;
         this.m_iUsedSize = 0;
     }
     else
     {
         TLVUtil.fillByteArray(this.m_pcBuf, 0);
         this.m_iUsedSize        = this.m_ptHeader.getSize();
         this.m_ptHeader.h_pcBuf = this.m_pcBuf;
         this.m_ptHeader.offset  = 0;
         this.m_ptHeader.setMagic(0x81).setCheckSum(new byte[2]).setUsedSize(0).setMode((byte)this.m_eDefaultMode);
     }
 }
Пример #17
0
            public override bool MapTo(byte[] apcSrc, int aiSrcSize, int aiOffset)
            {
                if (((apcSrc == null) || (aiSrcSize <= 0)) || ((aiOffset < 0) || (aiOffset >= aiSrcSize)))
                {
                    return(false);
                }
                int num  = TLVUtil.byte2int(apcSrc, aiOffset, 4, true);
                int num2 = TLVUtil.byte2int(apcSrc, aiOffset + 4, 4, true);

                base.pcValPtr       = apcSrc;
                base.pcValPtrOffset = (aiOffset + 4) + 4;
                int num3 = ((aiOffset + 4) + 4) + num2;

                if (num2 < 0)
                {
                    return(false);
                }
                if (base.pcValPtrOffset > aiSrcSize)
                {
                    return(false);
                }
                if (num3 > aiSrcSize)
                {
                    return(false);
                }
                if (num3 == aiSrcSize)
                {
                    base.iNextOffset = 0;
                }
                else
                {
                    base.iNextOffset = num3;
                }
                base.iType    = num;
                base.iLength  = num2;
                base.pcValPtr = apcSrc;
                return(true);
            }
Пример #18
0
        public int CopyTo(byte[] apcBuf, int offset, ref int apiSize)
        {
            if ((apcBuf == null) || (apiSize == 0))
            {
                return(-4);
            }
            if (apiSize < this.m_iUsedSize)
            {
                apiSize = this.m_iUsedSize;
                return(-7);
            }
            byte[] x = TLVUtil.getCheckSum(this.m_pcBuf, this.m_ptHeader.getSize(), this.m_iUsedSize - this.m_ptHeader.getSize());
            this.m_ptHeader.setCheckSum(x);
            int num2 = this.m_iUsedSize - this.m_ptHeader.getSize();

            this.m_ptHeader.setUsedSize(num2);
            if (this.m_iUsedSize > 0)
            {
                Buffer.BlockCopy(this.m_pcBuf, 0, apcBuf, offset, this.m_iUsedSize);
            }
            apiSize = this.m_iUsedSize;
            return(0);
        }
Пример #19
0
 public int AddInt(int aiType, int aiVal)
 {
     return(this.addByteArray(aiType, TLVUtil.int2byte(aiVal, 4, this.m_eDefaultMode == 0), 4));
 }