private static bool Pack(ref byte[] packBuf, MMTLVHeader tlvHeader, byte[] data) { TLVPack pack = new TLVPack(0, 1); pack.addByte(1, 190); pack.AddInt(2, (int)tlvHeader.Uin); pack.AddWord(3, tlvHeader.CmdId); pack.AddInt(4, tlvHeader.ServerId.Length); pack.addByteArray(5, tlvHeader.ServerId, tlvHeader.ServerId.Length); pack.addByteArray(6, tlvHeader.DeviceId, 0x10); pack.AddWord(7, tlvHeader.CompressVersion); pack.AddWord(8, tlvHeader.CompressAlogrithm); pack.AddWord(9, tlvHeader.CryptAlgorithm); pack.AddInt(10, (int)tlvHeader.CompressLen); pack.AddInt(11, (int)tlvHeader.CompressedLen); pack.addByteArray(12, data, data.Length); pack.AddInt(13, tlvHeader.Ret); pack.addByte(14, 0xed); pack.AddInt(15, (int)tlvHeader.CertVersion); pack.addByte(0x10, 0xed); packBuf = new byte[pack.getUsedSize() + 2]; packBuf[0] = 190; packBuf[packBuf.Length - 1] = 0xed; int apiSize = 0; apiSize = pack.getUsedSize(); if (pack.CopyTo(packBuf, 1, ref apiSize) != 0) { Log.e("MMPack", "tlvPack.CopyTo failed"); return(false); } return(true); }
public int getNestedTLVBuf(int aiType, TLVPack appoVal) { if (appoVal == null) { return(-4); } if (this.m_iUsedSize == this.m_ptHeader.getSize()) { return(-6); } FixedSizeTLVBody body = new FixedSizeTLVBody(); tVariableSizeTLVItem item = new tVariableSizeTLVItem(); TLVBody body2 = null; if (this.m_eDefaultMode == 0) { body2 = body; } else if (this.m_eDefaultMode == 1) { body2 = item; } else { return(-8); } if (body2.MapTo(this.m_pcBuf, this.m_iUsedSize, this.m_ptHeader.getSize())) { while ((body2.iType != aiType) && (body2.iNextOffset != 0)) { if (!body2.MapTo(this.m_pcBuf, this.m_iUsedSize, body2.iNextOffset)) { return(-5); } } if (body2.iType != aiType) { return(-6); } if ((body2.iLength > 0) && (0 > appoVal.CopyFrom(body2.pcValPtr, body2.iLength, body2.pcValPtrOffset))) { appoVal.m_pcBuf = null; appoVal.m_ptHeader.h_pcBuf = null; return(-5); } return(0); } return(-5); }
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); }
public static bool UnPack(byte[] packBuf, ref MMTLVHeader tlvHeader, ref byte[] cipherText) { if ((packBuf == null) || (packBuf.Length < 2)) { Log.e("MMPack", " UnPack failed: invlaide args"); return(false); } if ((190 != packBuf[0]) || (0xed != packBuf[packBuf.Length - 1])) { Log.e("MMPack", " UnPack failed: invalid args packBuf"); return(false); } TLVPack pack = new TLVPack(0, 1); if (pack.CopyFrom(packBuf, packBuf.Length - 2, 1) != 0) { return(false); } int apiVal = 0; if (pack.GetInt(2, ref apiVal) != 0) { Log.e("MMPack", " UnPack failed : uin"); return(false); } tlvHeader.Uin = (uint)apiVal; short aphVal = 0; if (pack.GetShort(3, ref aphVal) != 0) { Log.e("MMPack", " UnPack failed : cmdId"); return(false); } tlvHeader.CmdId = (ushort)aphVal; byte[] apoVal = null; if (pack.getByteArray(5, ref apoVal) != 0) { Log.e("MMPack", " UnPack failed : serverId"); return(false); } tlvHeader.ServerId = apoVal; byte[] buffer2 = null; if (pack.getByteArray(6, ref buffer2) != 0) { Log.e("MMPack", " UnPack failed : deviceId"); return(false); } tlvHeader.DeviceId = buffer2; short num3 = 0; if (pack.GetShort(7, ref num3) != 0) { Log.e("MMPack", " UnPack failed : compressVersion"); return(false); } tlvHeader.CompressVersion = num3; short num4 = 0; if (pack.GetShort(8, ref num4) != 0) { Log.e("MMPack", " UnPack failed : compressAlgorithm"); return(false); } tlvHeader.CompressAlogrithm = num4; short num5 = 0; if (pack.GetShort(9, ref num5) != 0) { Log.e("MMPack", " UnPack failed : cryptAlgorithm"); return(false); } tlvHeader.CryptAlgorithm = num5; uint apuVal = 0; if (pack.GetUInt(10, ref apuVal) != 0) { Log.e("MMPack", " UnPack failed : compressLen"); return(false); } tlvHeader.CompressLen = apuVal; uint num7 = 0; if (pack.GetUInt(11, ref num7) != 0) { Log.e("MMPack", " UnPack failed : compressedLen"); return(false); } tlvHeader.CompressedLen = num7; if (pack.getByteArray(12, ref cipherText) != 0) { Log.e("MMPack", " UnPack failed : cipherText"); return(false); } int num8 = 0; if (pack.GetInt(13, ref num8) != 0) { Log.e("MMPack", " UnPack failed : ret"); return(false); } tlvHeader.Ret = num8; uint num9 = 0; if (pack.GetUInt(15, ref num9) != 0) { Log.e("MMPack", " UnPack failed : certversion"); return(false); } tlvHeader.CertVersion = num9; return(true); }
public int SizeTLV(int aiType, TLVPack apoVal, int eTLVMode) { return(this.SizeNumber(aiType, apoVal.m_iUsedSize, eTLVMode)); }
public int SizeTLV(int aiType, TLVPack apoVal) { return(this.SizeNumber(aiType, apoVal.m_iUsedSize, 0)); }