private static GetBytes ( int x, int numBytes ) : byte[] | ||
x | int | |
numBytes | int | |
Результат | byte[] |
/// <summary> /// Get an array of bytes to use as the default arguments for a /// command when no arguments are given; we have to specify the /// expected data/response size as the arguments instead. /// </summary> /// <param name="command">Command</param> /// <returns>byte[]</returns> public static byte[] GetCommandDefaultArgumentsBytes(CommandEnum command) { ByteStream bytes = new ByteStream(); bytes.BinaryWriter.Write(CommandHelper.GetCommandDataSize(command)); return(bytes.GetBytes()); }
/// <summary> /// Sends a request for a new chat room connection -- SNAC(01,04) /// </summary> /// <param name="chatRoom">A <see cref="ChatRoom"/> object</param> internal void RequestChatRoomConnection(ChatRoom chatRoom) { SNACHeader sh = new SNACHeader(); sh.FamilyServiceID = 0x0001; sh.FamilySubtypeID = 0x0004; ByteStream chatStream = new ByteStream(); chatStream.WriteUshort(chatRoom.Exchange); chatStream.WriteByte((byte)Encoding.ASCII.GetByteCount(chatRoom.FullName)); chatStream.WriteString(chatRoom.FullName, Encoding.ASCII); chatStream.WriteUshort(chatRoom.Instance); TlvBlock tlv = new TlvBlock(); tlv.WriteByteArray(0x0001, chatStream.GetBytes()); ByteStream mainStream = new ByteStream(); mainStream.WriteUshort(0x000E); mainStream.WriteTlvBlock(tlv); parent.StoreRequestID(sh.RequestID, chatRoom); DataPacket dp = Marshal.BuildDataPacket(parent, sh, mainStream); // This one is always sent on BOS dp.ParentConnection = parent.Connections.BOSConnection; SNACFunctions.BuildFLAP(dp); }
private byte[] GetSignedLedgerBytes(SignedLedger signedLedger) { using (var stream = new ByteStream()) { stream.Write(signedLedger); return(Zipper.Zip(stream.GetBytes())); } }
public byte[] ToBytes() { using (var stream = new ByteStream()) { stream.Write(this); return(stream.GetBytes()); } }
private byte[] GetLedgerStateChangeBytes(LedgerStateChange change) { using (var stream = new ByteStream()) { stream.Write(change); return(stream.GetBytes()); } }
private byte[] GetRaw(Account account) { using (var stream = new ByteStream()) { stream.Write(account); return(stream.GetBytes()); } }
public static byte[] ZipSignedLedger(SignedLedger signedLedger) { using (var stream = new ByteStream()) { stream.Write(signedLedger); return(Zipper.Zip(stream.GetBytes())); } }
public static void SaveLedger(SignedLedger signed, string path) { using (var stream = new ByteStream()) { stream.Write(signed); var bytes = stream.GetBytes(); File.WriteAllBytes(path, bytes); } }
private VendingMachineHash ComputeHash() { using (var stream = new ByteStream()) { stream.Write(this); var message = stream.GetBytes(); var hasher = HashFactory.Crypto.SHA3.CreateKeccak256(); return(new VendingMachineHash(hasher.ComputeBytes(message).GetBytes())); } }
/// <summary> /// Get command packet bytes to send. /// /// Packet is structured as: /// - Expected data/response size bytes /// - `12025` `ushort` constant (TODO: what is this for?) /// - Command `ushort` /// - Expected data/response size as integer /// - Arguments (when none given explicitly, is data size again) /// /// Returns the array of bytes to send to the Band. /// </summary> /// <returns>byte[]</returns> public byte[] GetBytes() { ByteStream bytes = new ByteStream(); bytes.BinaryWriter.Write(this.GetArgsSizeBytes()); bytes.BinaryWriter.Write((ushort)12025); bytes.BinaryWriter.Write((ushort)this.Command); bytes.BinaryWriter.Write(this.GetCommandDataSize()); bytes.BinaryWriter.Write(this.args); return(bytes.GetBytes()); }
public LedgerHash GetHash(Ledger ledger) { using (var stream = new ByteStream()) { stream.Write(ledger); var message = stream.GetBytes(); var hasher = HashFactory.Crypto.SHA3.CreateKeccak256(); var hash = hasher.ComputeBytes(message).GetBytes(); return(new LedgerHash(hash)); } }
internal override AccountHash GetHash(Account account) { using (var stream = new ByteStream()) { stream.Write1(account); var message = stream.GetBytes(); var hasher = HashFactory.Crypto.SHA3.CreateKeccak256(); var hash = hasher.ComputeBytes(message).GetBytes(); return(new AccountHash(hash)); } }
private LedgerMerkleRootHash GetHash() { using (var stream = new ByteStream()) { stream.Write(accounts.Hash); stream.Write(declarations.Hash); var message = stream.GetBytes(); var hasher = HashFactory.Crypto.SHA3.CreateKeccak256(); var hash = hasher.ComputeBytes(message).GetBytes(); return(new LedgerMerkleRootHash(hash)); } }
public void TestByteStreamStringWriting() { ByteStream stream = new ByteStream(); stream.WriteByte((byte)Encoding.ASCII.GetByteCount("Adrienne")); stream.WriteString("Adrienne", Encoding.ASCII); Assert.AreEqual(testData.Length, stream.GetByteCount()); byte[] data = stream.GetBytes(); for (int i = 0; i < testData.Length; i++) { Assert.AreEqual(testData[i], data[i]); } }
public void TestByteStreamNumberWriting() { ByteStream stream = new ByteStream(); stream.WriteByte(0x08); stream.WriteUshort(0x4164); stream.WriteUint(0x7269656e); stream.WriteByteArray(new byte[] { 0x6e, 0x65 }); Assert.AreEqual(testData.Length, stream.GetByteCount()); ByteStream testStream = new ByteStream(stream.GetBytes()); Assert.AreEqual("Adrienne", testStream.ReadString(testStream.ReadByte(), Encoding.ASCII)); }
/// <summary> /// Creates a SNAC header with the common ICQ properties /// </summary> private static ByteStream CreateMetaInfoHeader(Session sess, SNACHeader sh, MetaInfoRequestType type, ByteStream data) { ByteStream stream = new ByteStream(); int size = data.GetByteCount(); stream.WriteUshort(0x0001); stream.WriteUshort((ushort)(size + 12)); // size stream.WriteUshortLE((ushort)(size + 10)); // size stream.WriteUintLE(uint.Parse(sess.ScreenName)); stream.WriteUshortLE((ushort)MetaRequestType.MetaInfoRequest); stream.WriteUshortLE((ushort)sh.RequestID); stream.WriteUshortLE((ushort)type); stream.WriteByteArray(data.GetBytes()); return(stream); }
public void ZipTest() { using (CreateContext()) { var signed = CreateSignedLedger(); byte[] bytes; using (var stream = new ByteStream()) { stream.Write(signed); bytes = stream.GetBytes(); } var unzipped = Zipper.Unzip(Zipper.Zip(bytes)); Debug.Assert(bytes.IsEqual(unzipped)); } }
private static ByteStream CreateDirectoryHeader(DirectoryRequestType type, ByteStream data) { ByteStream stream = new ByteStream(); int size = data.GetByteCount(); stream.WriteUshortLE((ushort)(size + 26)); // size SNACHeader shsub = new SNACHeader(0x05b9, (ushort)type, 0x8000, 0); // Sub Snac Header stream.WriteSnacHeader(shsub); stream.WriteUshort(0x0006); // Snac Extra Bytes (length) stream.WriteUshort(0x0001); // TLV - T stream.WriteUshort(0x0002); // TLV - L stream.WriteUshort(0x0002); // TLV - V; Versions Nr stream.WriteUshort(0x0000); stream.WriteUshort((ushort)Encoding.Default.CodePage); stream.WriteUint((uint)2); stream.WriteByteArray(data.GetBytes()); return(stream); }
private byte[] ProcessDirectoryUpdateRequestUserDetails(int typecode, FullUserInfo ui) { List <TlvBlock> tlvlist = new List <TlvBlock>(); ByteStream bstream = null; switch (typecode) { case 0x96: // Home Address tlvlist.Add(new TlvBlock()); tlvlist[tlvlist.Count - 1].WriteString(0x64, ui.HomeAddress, Encoding.UTF8); tlvlist[tlvlist.Count - 1].WriteString(0x6e, ui.HomeCity, Encoding.UTF8); tlvlist[tlvlist.Count - 1].WriteString(0x78, ui.HomeState, Encoding.UTF8); tlvlist[tlvlist.Count - 1].WriteString(0x82, ui.HomeZip, Encoding.UTF8); tlvlist[tlvlist.Count - 1].WriteUint(0x8c, (uint)ui.HomeCountry); break; case 0xa0: // Origin Address tlvlist.Add(new TlvBlock()); tlvlist[tlvlist.Count - 1].WriteString(0x6e, ui.OriginCity, Encoding.UTF8); tlvlist[tlvlist.Count - 1].WriteString(0x78, ui.OriginState, Encoding.UTF8); tlvlist[tlvlist.Count - 1].WriteUint(0x8c, (uint)ui.OriginCountry); break; case 0xc8: // Phone Numbers tlvlist.Add(new TlvBlock()); tlvlist[tlvlist.Count - 1].WriteUshort(0x6e, 1); tlvlist[tlvlist.Count - 1].WriteString(0x64, ui.HomePhone, Encoding.ASCII); tlvlist.Add(new TlvBlock()); tlvlist[tlvlist.Count - 1].WriteUshort(0x6e, 2); tlvlist[tlvlist.Count - 1].WriteString(0x64, ui.WorkPhone, Encoding.ASCII); tlvlist.Add(new TlvBlock()); tlvlist[tlvlist.Count - 1].WriteUshort(0x6e, 3); tlvlist[tlvlist.Count - 1].WriteString(0x64, ui.MobilePhone, Encoding.ASCII); tlvlist.Add(new TlvBlock()); tlvlist[tlvlist.Count - 1].WriteUshort(0x6e, 4); tlvlist[tlvlist.Count - 1].WriteString(0x64, ui.HomeFax, Encoding.ASCII); tlvlist.Add(new TlvBlock()); tlvlist[tlvlist.Count - 1].WriteUshort(0x6e, 5); tlvlist[tlvlist.Count - 1].WriteString(0x64, ui.WorkFax, Encoding.ASCII); break; case 0x8c: // Emails if (ui.EmailAddresses != null) { foreach (string email in ui.EmailAddresses) { tlvlist.Add(new TlvBlock()); tlvlist[tlvlist.Count - 1].WriteUshort(0x78, 0); tlvlist[tlvlist.Count - 1].WriteString(0x64, email, Encoding.ASCII); } } break; case 0x118: // Work tlvlist.Add(new TlvBlock()); tlvlist[tlvlist.Count - 1].WriteString(0x64, ui.WorkPosition, Encoding.UTF8); tlvlist[tlvlist.Count - 1].WriteString(0x6e, ui.WorkCompany, Encoding.UTF8); tlvlist[tlvlist.Count - 1].WriteString(0x7d, ui.WorkDepartment, Encoding.UTF8); tlvlist[tlvlist.Count - 1].WriteString(0x78, ui.WorkWebsite, Encoding.ASCII); tlvlist[tlvlist.Count - 1].WriteUshort(0x82, (ushort)ui.WorkIndustry); tlvlist[tlvlist.Count - 1].WriteString(0xaa, ui.WorkAddress, Encoding.UTF8); tlvlist[tlvlist.Count - 1].WriteString(0xb4, ui.WorkCity, Encoding.UTF8); tlvlist[tlvlist.Count - 1].WriteString(0xbe, ui.WorkState, Encoding.UTF8); tlvlist[tlvlist.Count - 1].WriteString(0xc8, ui.WorkZip, Encoding.UTF8); tlvlist[tlvlist.Count - 1].WriteUint(0xd2, (uint)ui.WorkCountry); break; case 0x10e: // Education tlvlist.Add(new TlvBlock()); tlvlist[tlvlist.Count - 1].WriteUshort(0x64, (ushort)ui.StudyLevel); tlvlist[tlvlist.Count - 1].WriteString(0x6e, ui.StudyInstitute, Encoding.UTF8); tlvlist[tlvlist.Count - 1].WriteString(0x78, ui.StudyDegree, Encoding.UTF8); tlvlist[tlvlist.Count - 1].WriteUshort(0x8c, (ushort)ui.StudyYear); break; case 0x122: // Interests if (ui.InterestInfos != null) { foreach (FullUserInfo.InterestInfo info in ui.InterestInfos) { tlvlist.Add(new TlvBlock()); tlvlist[tlvlist.Count - 1].WriteUshort(0x6e, (ushort)info.Category); tlvlist[tlvlist.Count - 1].WriteString(0x64, info.Info, Encoding.UTF8); } } break; } switch (typecode) { case 0x96: // Home Address bstream = writeTlvList(tlvlist, 1); break; case 0xa0: // Origin Address bstream = writeTlvList(tlvlist, 1); break; case 0xc8: // Phone Numbers bstream = writeTlvList(tlvlist, 5); break; case 0x8c: // Emails bstream = writeTlvList(tlvlist, 4); break; case 0x118: // Work bstream = writeTlvList(tlvlist, 1); break; case 0x10e: // Education bstream = writeTlvList(tlvlist, 1); break; case 0x122: // Interests bstream = writeTlvList(tlvlist, 4); break; } return(bstream.GetBytes()); }