本文整理汇总了C#中ByteBuffer.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# ByteBuffer.ToArray方法的具体用法?C# ByteBuffer.ToArray怎么用?C# ByteBuffer.ToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ByteBuffer
的用法示例。
在下文中一共展示了ByteBuffer.ToArray方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Write
/// <summary>
/// ByteBuffer
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public virtual ByteBuffer Write( ByteBuffer data )
{
writer.Write ( data.ToArray ( ) );
return this;
}
示例2: PromptOB
public static String PromptOB(ByteBuffer bb, int maxlen)
{
return PromptBytes(bb.ToArray(), (int) bb.Position, (int) bb.Length, maxlen);
}
示例3: SendTORPacket
public void SendTORPacket(ByteBuffer buffer)
{
// here we receive a buffer prepared for length insertion
int length = (int)buffer.Position;
buffer.Position = 1;
buffer.WriteInt(length);
byte[] data = buffer.ToArray();
byte chk = (byte)(data[0] ^ data[1] ^ data[2] ^ data[3] ^ data[4]);
buffer.WriteByte(chk);
SendRegularPacket(buffer.ToArray());
}
示例4: ProcessPacket
public static void ProcessPacket(byte[] data, AsyncConnection connection)
{
AsyncConnectionData acd = (connection.AsyncState as AsyncConnectionData);
ByteBuffer buffer = new ByteBuffer(ByteOrder.LittleEndian, data, 6, data.Length - 6); // 1 opcode 4 len 1 chk
if (connection.State == 1)
{
buffer.ReadInt();
string rsaBytes = Encoding.UTF8.GetString(buffer.ReadBytes(1024));
byte[] rsa = new byte[512];
for (int i = 0; i < rsaBytes.Length; i += 2)
{
rsa[i / 2] = byte.Parse(rsaBytes.Substring(i, 2), NumberStyles.HexNumber);
}
uint resultSize = 0;
IntPtr ptr = TRSADecrypt(rsa, 512, ref resultSize);
byte[] decrypted = new byte[resultSize];
Marshal.Copy(ptr, decrypted, 0, (int)resultSize);
Console.WriteLine("Decrypted Size = " + resultSize);
Console.WriteLine(Utility.HexDump(decrypted));
// set salsa keys
ByteBuffer packetbuffer = new ByteBuffer(ByteOrder.LittleEndian, decrypted);
string username = packetbuffer.ReadString();
string hash = packetbuffer.ReadString();
byte[] key1 = packetbuffer.ReadBytes(32);
byte[] key2 = packetbuffer.ReadBytes(32); // decrypts client
byte[] iv1 = packetbuffer.ReadBytes(8);
byte[] iv2 = packetbuffer.ReadBytes(8); // decrypts client
connection.CipheredStream.EnableEncryption(key2, iv2, key1, iv1);
connection.SetState(2); // State 2 = Ready to decrypt
}
else
{
switch(data.Length)
{
case 14: // discarded client packet
break;
case 45:
byte[] response_45 = new byte[]
{
0x00, 0x48, 0x00, 0x00, 0x00, 0x48, 0xAF, 0xC5, 0x31, 0x67, 0xFF, 0xFF, 0xFF, 0xFF, 0x04, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x63, 0x61,
0x73, 0x74, 0x6C, 0x65, 0x68, 0x69, 0x6C, 0x6C, 0x74, 0x65, 0x73, 0x74, 0x00, 0x09, 0x00, 0x00,
0x00, 0x61, 0x66, 0x63, 0x31, 0x62, 0x62, 0x35, 0x61, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x6C, 0x6F,
0x67, 0x69, 0x6E, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
};
connection.SendRegularPacket(response_45);
break;
case 126: //omega packet
ByteBuffer pkt_omega = new ByteBuffer(ByteOrder.LittleEndian);
pkt_omega.WriteBytes(new byte[] {
0x00, 0x60, // Length
0x00, 0x00, 0x00, 0x60, // Length
0x84, 0xD0, 0xF2, 0x90, // PacketID (with client hack)
0x04, 0x00, 0x00, 0x00 // ObjectCode
});
pkt_omega.WriteString("swtor-game-lab-1.swtor.com:20063"); // Server Address
pkt_omega.WriteString("WIKRQEOYULPBIEHHADRWAAPNVRYGQHMNRXGHBUIV"); // Some key ?
Console.WriteLine(Utility.HexDump(pkt_omega.ToArray()));
connection.SendRegularPacket(pkt_omega.ToArray());
break;
default:
Console.WriteLine("recv packet, size = " + data.Length);
Console.WriteLine(Utility.HexDump(data));
break;
}
/*List<byte[]> packets = acd.Crypter.ProcessServerFromClient(data);
foreach (byte[] packet in packets)
{
ByteBuffer pkt = new ByteBuffer(ByteOrder.BigEndian, packet);
short opcode = pkt.ReadShort();
int length = pkt.ReadInt();
switch (opcode)
{
case 45:
// Client Selecting a Shard Server
Console.WriteLine(connection.GetHashCode() + " selecting shard.");
MemoryStream response_45 = new MemoryStream(new byte[]
{
0x00, 0x48, 0x0, 0x00, 0x00, 0x48, 0xAF, 0xC5, 0x31, 0x67, 0xFF, 0xFF, 0xFF, 0xFF, 0x04, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x63, 0x61,
0x73, 0x74, 0x6C, 0x65, 0x68, 0x69, 0x6C, 0x6C, 0x74, 0x65, 0x73, 0x74, 0x00, 0x09, 0x00, 0x00,
0x00, 0x61, 0x66, 0x63, 0x31, 0x62, 0x62, 0x35, 0x61, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x6C, 0x6F,
0x67, 0x69, 0x6E, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
});
SendPacket(connection, response_45);
break;
default:
Console.WriteLine("PKTRECV Opcode = " + opcode + " Size = " + length);
Console.WriteLine("Hex Dump = " + Utility.ToHexString(pkt, true));
Console.WriteLine("String Dump = " + Encoding.UTF8.GetString(pkt.ToArray()));
break;
//.........这里部分代码省略.........