public XvcLicenseBlock GetBlockWithId(XvcLicenseBlockId id) { int idLen = (IsEkbFile ? 2 : 4); int szLen = 4; if (BlockId == id) { return(this); } XvcLicenseBlock block; if (BlockSize > (idLen + szLen) && BlockSize >= (idLen + szLen) + BlockDataAsBlock.BlockSize) { block = BlockDataAsBlock.GetBlockWithId(id); if (block != null) { return(block); } } if (NextBlockData.Length <= (idLen + szLen) || NextBlockData.Length < (idLen + szLen) + NextBlockDataAsBlock.BlockSize) { return(null); } block = NextBlockDataAsBlock.GetBlockWithId(id); if (block != null) { return(block); } return(null); }
public XvcLicenseBlock(byte[] data, bool isEkbFile = false) { IsEkbFile = isEkbFile; int idLen = (IsEkbFile ? 2 : 4); int szLen = 4; if (data.Length >= idLen) { BlockId = (XvcLicenseBlockId)(isEkbFile ? BitConverter.ToUInt16(data, 0) : BitConverter.ToUInt32(data, 0)); } if (isEkbFile && BlockId == (XvcLicenseBlockId)0x4b45) { // if its an ekb file and we read the magic of the EKB skip 2 bytes idLen = 4; BlockId = (XvcLicenseBlockId)BitConverter.ToUInt16(data, 2); } if (!isEkbFile && BlockId == (XvcLicenseBlockId)0x31424b45) { // if we're not an EKB file but we read the EKB magic act like its an EKB IsEkbFile = true; idLen = 4; BlockId = (XvcLicenseBlockId)BitConverter.ToUInt16(data, 2); } if (data.Length >= (idLen + szLen)) { BlockSize = BitConverter.ToUInt32(data, idLen); } if (data.Length < BlockSize + (idLen + szLen)) { return; } BlockData = new byte[BlockSize]; Array.Copy(data, (idLen + szLen), BlockData, 0, BlockSize); if (data.Length - (BlockSize + (idLen + szLen)) <= 0) { return; } NextBlockData = new byte[data.Length - (BlockSize + (idLen + szLen))]; Array.Copy(data, BlockSize + (idLen + szLen), NextBlockData, 0, NextBlockData.Length); idLen = (IsEkbFile ? 2 : 4); szLen = 4; MinBlockLength = idLen + szLen; }
public XvcLicenseBlock(byte[] data, bool isEkbFile = false) { IsEkbFile = isEkbFile; int idLen = (IsEkbFile ? 2 : 4); int szLen = 4; if (data.Length >= idLen) BlockId = (XvcLicenseBlockId)(isEkbFile ? BitConverter.ToUInt16(data, 0) : BitConverter.ToUInt32(data, 0)); if (isEkbFile && BlockId == (XvcLicenseBlockId)0x4b45) { // if its an ekb file and we read the magic of the EKB skip 2 bytes idLen = 4; BlockId = (XvcLicenseBlockId)BitConverter.ToUInt16(data, 2); } if (!isEkbFile && BlockId == (XvcLicenseBlockId)0x31424b45) { // if we're not an EKB file but we read the EKB magic act like its an EKB IsEkbFile = true; idLen = 4; BlockId = (XvcLicenseBlockId)BitConverter.ToUInt16(data, 2); } if (data.Length >= (idLen + szLen)) BlockSize = BitConverter.ToUInt32(data, idLen); if (data.Length < BlockSize + (idLen + szLen)) return; BlockData = new byte[BlockSize]; Array.Copy(data, (idLen + szLen), BlockData, 0, BlockSize); if (data.Length - (BlockSize + (idLen + szLen)) <= 0) return; NextBlockData = new byte[data.Length - (BlockSize + (idLen + szLen))]; Array.Copy(data, BlockSize + (idLen + szLen), NextBlockData, 0, NextBlockData.Length); idLen = (IsEkbFile ? 2 : 4); szLen = 4; MinBlockLength = idLen + szLen; }
public XvcLicenseBlock GetBlockWithId(XvcLicenseBlockId id) { int idLen = (IsEkbFile ? 2 : 4); int szLen = 4; if (BlockId == id) return this; XvcLicenseBlock block; if (BlockSize > (idLen + szLen) && BlockSize >= (idLen + szLen) + BlockDataAsBlock.BlockSize) { block = BlockDataAsBlock.GetBlockWithId(id); if (block != null) return block; } if (NextBlockData.Length <= (idLen + szLen) || NextBlockData.Length < (idLen + szLen) + NextBlockDataAsBlock.BlockSize) return null; block = NextBlockDataAsBlock.GetBlockWithId(id); if (block != null) return block; return null; }