public override void WriteCommandBytes(byte[] buffer, int offset) { SecurityBufferOffset = 0; SecurityBufferLength = (ushort)SecurityBuffer.Length; int paddedSecurityBufferLength = (int)Math.Ceiling((double)SecurityBufferLength / 8) * 8; if (SecurityBuffer.Length > 0) { SecurityBufferOffset = SMB2Header.Length + FixedSize; } NegotiateContextOffset = 0; NegotiateContextCount = (ushort)NegotiateContextList.Count; if (NegotiateContextList.Count > 0) { // NegotiateContextList must be 8-byte aligned NegotiateContextOffset = (uint)(SMB2Header.Length + FixedSize + paddedSecurityBufferLength); } LittleEndianWriter.WriteUInt16(buffer, offset + 0, StructureSize); LittleEndianWriter.WriteUInt16(buffer, offset + 2, (ushort)SecurityMode); LittleEndianWriter.WriteUInt16(buffer, offset + 4, (ushort)DialectRevision); LittleEndianWriter.WriteUInt16(buffer, offset + 6, NegotiateContextCount); LittleEndianWriter.WriteGuidBytes(buffer, offset + 8, ServerGuid); LittleEndianWriter.WriteUInt32(buffer, offset + 24, (uint)Capabilities); LittleEndianWriter.WriteUInt32(buffer, offset + 28, MaxTransactSize); LittleEndianWriter.WriteUInt32(buffer, offset + 32, MaxReadSize); LittleEndianWriter.WriteUInt32(buffer, offset + 36, MaxWriteSize); LittleEndianWriter.WriteInt64(buffer, offset + 40, SystemTime.ToFileTimeUtc()); LittleEndianWriter.WriteInt64(buffer, offset + 48, ServerStartTime.ToFileTimeUtc()); LittleEndianWriter.WriteUInt16(buffer, offset + 56, SecurityBufferOffset); LittleEndianWriter.WriteUInt16(buffer, offset + 58, SecurityBufferLength); LittleEndianWriter.WriteUInt32(buffer, offset + 60, NegotiateContextOffset); ByteWriter.WriteBytes(buffer, offset + FixedSize, SecurityBuffer); NegotiateContext.WriteNegotiateContextList(buffer, offset + FixedSize + paddedSecurityBufferLength, NegotiateContextList); }
public byte[] GetBytes() { byte[] buffer = new byte[22]; // the first byte of filetime should be 1 byte[] temp = BigEndianConverter.GetBytes(FileTime.ToFileTimeUtc()); Array.Copy(temp, 0, buffer, 0, 6); LittleEndianWriter.WriteGuidBytes(buffer, 6, Guid); return buffer; }
public byte[] GetBytes() { byte[] buffer = new byte[Length]; LittleEndianWriter.WriteGuidBytes(buffer, 0, ObjectId); LittleEndianWriter.WriteGuidBytes(buffer, 16, BirthVolumeId); LittleEndianWriter.WriteGuidBytes(buffer, 32, BirthObjectId); LittleEndianWriter.WriteGuidBytes(buffer, 48, DomainId); return(buffer); }
// Note: Changes must be saved by the caller method /// <returns>Index of property set GUID</returns> private int AddPropertySetGuid(Node node, Guid propertySetGuid) { byte[] oldBuffer = node.PC.GetBytesProperty(PropertyID.PidTagNameidStreamGuid); byte[] newBuffer = new byte[oldBuffer.Length + 16]; Array.Copy(oldBuffer, newBuffer, oldBuffer.Length); LittleEndianWriter.WriteGuidBytes(newBuffer, oldBuffer.Length, propertySetGuid); node.PC.SetBytesProperty(PropertyID.PidTagNameidStreamGuid, newBuffer); PropertySetGuidStreamCache = newBuffer; // update cache return(oldBuffer.Length / 16); }
public void WriteBytes(byte[] buffer, int offset) { LittleEndianWriter.WriteGuidBytes(buffer, offset + 0, PartitionTypeGuid); LittleEndianWriter.WriteGuidBytes(buffer, offset + 16, PartitionGuid); LittleEndianWriter.WriteUInt64(buffer, offset + 32, FirstLBA); LittleEndianWriter.WriteUInt64(buffer, offset + 40, LastLBA); LittleEndianWriter.WriteUInt64(buffer, offset + 48, AttributeFlags); while (PartitionName.Length < 36) { PartitionName += "\0"; } ByteWriter.WriteUTF16String(buffer, offset + 56, PartitionName, 36); }
public override void WriteCommandBytes(byte[] buffer, int offset) { LittleEndianWriter.WriteUInt16(buffer, offset + 0, StructureSize); LittleEndianWriter.WriteUInt16(buffer, offset + 2, DialectCount); LittleEndianWriter.WriteUInt16(buffer, offset + 4, (ushort)SecurityMode); LittleEndianWriter.WriteUInt16(buffer, offset + 6, Reserved); LittleEndianWriter.WriteUInt32(buffer, offset + 8, (uint)Capabilities); LittleEndianWriter.WriteGuidBytes(buffer, offset + 12, ClientGuid); LittleEndianWriter.WriteInt64(buffer, offset + 28, ClientStartTime.ToFileTimeUtc()); for (int index = 0; index < Dialects.Count; index++) { SMB2Dialect dialect = Dialects[index]; LittleEndianWriter.WriteUInt16(buffer, offset + 36 + index * 2, (ushort)dialect); } }
public byte[] GetBytes() { int length = 24; length += (DisplayName.Length + 1) * 2; length += (AddressType.Length + 1) * 2; length += (EmailAddress.Length + 1) * 2; byte[] buffer = new byte[length]; int offset = 4; LittleEndianWriter.WriteGuidBytes(buffer, ref offset, ProviderUID); LittleEndianWriter.WriteUInt16(buffer, ref offset, Version); byte temp = 0; temp |= (byte)((MAE & 0x03) << 5); temp |= (byte)((Format & 0x0F) << 1); if (PureMime) { temp |= 0x01; } ByteWriter.WriteByte(buffer, ref offset, temp); temp = 0; if (UTF16) { temp |= 0x80; } if (AvoidAddressBookLookup) { temp |= 0x10; } ByteWriter.WriteByte(buffer, ref offset, temp); if (UTF16) { WriteUnicodeString(buffer, ref offset, DisplayName); WriteUnicodeString(buffer, ref offset, AddressType); WriteUnicodeString(buffer, ref offset, EmailAddress); } else { throw new NotImplementedException("Encoding MBCS is not supported"); } return(buffer); }
public override byte[] GetBytes() { AuthLength = (ushort)AuthVerifier.Length; byte[] buffer = new byte[Length]; WriteCommonFieldsBytes(buffer); int offset = CommonFieldsLength; LittleEndianWriter.WriteUInt32(buffer, ref offset, AllocationHint); LittleEndianWriter.WriteUInt16(buffer, ref offset, ContextID); LittleEndianWriter.WriteUInt16(buffer, ref offset, OpNum); if ((Flags & PacketFlags.ObjectUUID) > 0) { LittleEndianWriter.WriteGuidBytes(buffer, ref offset, ObjectGuid); } ByteWriter.WriteBytes(buffer, ref offset, Data); ByteWriter.WriteBytes(buffer, ref offset, AuthVerifier); return(buffer); }
public byte[] GetBytes(int bytesPerSector) { byte[] buffer = new byte[bytesPerSector]; ByteWriter.WriteAnsiString(buffer, 0, Signature, 8); LittleEndianWriter.WriteUInt32(buffer, 8, Revision); LittleEndianWriter.WriteUInt32(buffer, 12, HeaderSize); LittleEndianWriter.WriteUInt64(buffer, 24, CurrentLBA); LittleEndianWriter.WriteUInt64(buffer, 32, BackupLBA); LittleEndianWriter.WriteUInt64(buffer, 40, FirstUsableLBA); LittleEndianWriter.WriteUInt64(buffer, 48, LastUsableLBA); LittleEndianWriter.WriteGuidBytes(buffer, 56, DiskGuid); LittleEndianWriter.WriteUInt64(buffer, 72, PartitionEntriesLBA); LittleEndianWriter.WriteUInt32(buffer, 80, NumberOfPartitionEntries); LittleEndianWriter.WriteUInt32(buffer, 84, SizeOfPartitionEntry); LittleEndianWriter.WriteUInt32(buffer, 88, PartitionArrayCRC32); CRC32 = ComputeCRC32(buffer); LittleEndianWriter.WriteUInt32(buffer, 16, CRC32); return(buffer); }
public override byte[] GetBytes(bool isUnicode) { ChallengeLength = 0; this.SMBParameters = new byte[ParametersLength]; LittleEndianWriter.WriteUInt16(this.SMBParameters, 0, DialectIndex); ByteWriter.WriteByte(this.SMBParameters, 2, (byte)SecurityMode); LittleEndianWriter.WriteUInt16(this.SMBParameters, 3, MaxMpxCount); LittleEndianWriter.WriteUInt16(this.SMBParameters, 5, MaxNumberVcs); LittleEndianWriter.WriteUInt32(this.SMBParameters, 7, MaxBufferSize); LittleEndianWriter.WriteUInt32(this.SMBParameters, 11, MaxRawSize); LittleEndianWriter.WriteUInt32(this.SMBParameters, 15, SessionKey); LittleEndianWriter.WriteUInt32(this.SMBParameters, 19, (uint)Capabilities); FileTimeHelper.WriteFileTime(this.SMBParameters, 23, SystemTime); LittleEndianWriter.WriteInt16(this.SMBParameters, 31, ServerTimeZone); ByteWriter.WriteByte(this.SMBParameters, 33, ChallengeLength); this.SMBData = new byte[16 + SecurityBlob.Length]; LittleEndianWriter.WriteGuidBytes(this.SMBData, 0, ServerGuid); ByteWriter.WriteBytes(this.SMBData, 16, SecurityBlob); return(base.GetBytes(isUnicode)); }
public override byte[] GetBytes(bool isUnicode) { this.SMBParameters = new byte[ParametersLength]; int parametersOffset = 4; ByteWriter.WriteByte(this.SMBParameters, ref parametersOffset, (byte)OpLockLevel); LittleEndianWriter.WriteUInt16(this.SMBParameters, ref parametersOffset, FID); LittleEndianWriter.WriteUInt32(this.SMBParameters, ref parametersOffset, (uint)CreateDisposition); FileTimeHelper.WriteFileTime(this.SMBParameters, ref parametersOffset, CreateTime); FileTimeHelper.WriteFileTime(this.SMBParameters, ref parametersOffset, LastAccessTime); FileTimeHelper.WriteFileTime(this.SMBParameters, ref parametersOffset, LastWriteTime); FileTimeHelper.WriteFileTime(this.SMBParameters, ref parametersOffset, LastChangeTime); LittleEndianWriter.WriteUInt32(this.SMBParameters, ref parametersOffset, (uint)ExtFileAttributes); LittleEndianWriter.WriteInt64(this.SMBParameters, ref parametersOffset, AllocationSize); LittleEndianWriter.WriteInt64(this.SMBParameters, ref parametersOffset, EndOfFile); LittleEndianWriter.WriteUInt16(this.SMBParameters, ref parametersOffset, (ushort)ResourceType); LittleEndianWriter.WriteUInt16(this.SMBParameters, ref parametersOffset, NMPipeStatus_or_FileStatusFlags); ByteWriter.WriteByte(this.SMBParameters, ref parametersOffset, Convert.ToByte(Directory)); LittleEndianWriter.WriteGuidBytes(this.SMBParameters, ref parametersOffset, VolumeGuid); LittleEndianWriter.WriteUInt64(this.SMBParameters, ref parametersOffset, FileID); LittleEndianWriter.WriteUInt32(this.SMBParameters, ref parametersOffset, (uint)MaximalAccessRights); LittleEndianWriter.WriteUInt32(this.SMBParameters, ref parametersOffset, (uint)GuestMaximalAccessRights); return(base.GetBytes(isUnicode)); }
public void WriteBytes(byte[] buffer, int offset) { LittleEndianWriter.WriteGuidBytes(buffer, offset + 0, InterfaceUUID); LittleEndianWriter.WriteUInt32(buffer, offset + 16, InterfaceVersion); }
public override void WriteBytes(byte[] buffer, int offset) { LittleEndianWriter.WriteGuidBytes(buffer, offset + 0, ObjectID); ByteWriter.WriteBytes(buffer, offset + 16, ExtendedInfo); }