public PacketGenerator utf8(string a) { PacketGenerator tmp = dword((uint)a.Length); foreach (char c in a) { tmp = tmp.bit((byte)c); } return(tmp); }
public void sendPacket(int packetType, PacketGenerator pg, string nonce = "nonce") { byte[] toSend = new byte[7 + pg.getBytes().Length]; byte[] aPacketID = new byte[2] { (byte)(packetType>>8), (byte)packetType }; PacketUtils.byteArrayCopy(aPacketID, 0, toSend, 0, 2); int length = pg.getBytes().Length; byte[] aLength = new byte[3] { (byte)(length >> 16), (byte)(length >> 8), (byte)length }; PacketUtils.byteArrayCopy(aLength, 0, toSend, 2, 3); toSend[4] = 0x00; toSend[5] = 0xef; int[] bytesAsInts = pg.getBytes().Select(x => (int)x).ToArray(); int[] encryptedData = PacketUtils.RC4(bytesAsInts, PacketUtils.baseKey + nonce); PacketUtils.byteArrayCopy(encryptedData, 0, toSend, 6, encryptedData.Length - 1); byte[] toBeSent = bytesAsInts.Select(x => (byte)x).ToArray(); tcpClient.GetStream().Write(toBeSent, 0, toBeSent.Length); }
public void sendPacket(int packetType, PacketGenerator pg, string nonce = "nonce") { byte[] toSend = new byte[7 + pg.getBytes().Length]; byte[] aPacketID = new byte[2] { (byte)(packetType >> 8), (byte)packetType }; PacketUtils.byteArrayCopy(aPacketID, 0, toSend, 0, 2); int length = pg.getBytes().Length; byte[] aLength = new byte[3] { (byte)(length >> 16), (byte)(length >> 8), (byte)length }; PacketUtils.byteArrayCopy(aLength, 0, toSend, 2, 3); toSend[4] = 0x00; toSend[5] = 0xef; int[] bytesAsInts = pg.getBytes().Select(x => (int)x).ToArray(); int[] encryptedData = PacketUtils.RC4(bytesAsInts, PacketUtils.baseKey + nonce); PacketUtils.byteArrayCopy(encryptedData, 0, toSend, 6, encryptedData.Length - 1); byte[] toBeSent = bytesAsInts.Select(x => (byte)x).ToArray(); tcpClient.GetStream().Write(toBeSent, 0, toBeSent.Length); }
internal void answerEncryption() { PacketGenerator pg = new PacketGenerator().utf8(PacketUtils.getRandom()).dword(1); from.sendPacket((int)PacketType.ENCRYPTION, pg); }
private void sendLoginOK() { PacketGenerator pg = new PacketGenerator().qword(from.userID).qword(from.userID); }