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 }
/// <exception cref="System.IO.IOException"></exception> private void flushBytes(bool flushUnderlyingStream) { lock (@lock) { checkStatus(); int position = bytes.position(); if (position > 0) { bytes.flip(); @out.write(((byte[])bytes.array()), bytes.arrayOffset(), position); bytes.clear(); } if (flushUnderlyingStream) { @out.flush(); } } }
/// <exception cref="System.IO.IOException"/> private void writeChunkHead(Chunk chunk) { long messageLength = chunk.getMessageLength(); int headLength = messageLength > -1L ? ArangoDBConstants.CHUNK_MAX_HEADER_SIZE : ArangoDBConstants.CHUNK_MIN_HEADER_SIZE; int length = chunk.getContentLength() + headLength; java.nio.ByteBuffer buffer = java.nio.ByteBuffer.allocate(headLength).order(java.nio.ByteOrder .LITTLE_ENDIAN); buffer.putInt(length); buffer.putInt(chunk.getChunkX()); buffer.putLong(chunk.getMessageId()); if (messageLength > -1L) { buffer.putLong(messageLength); } this.outputStream.write((byte[])buffer.array()); }
public virtual void testWKB2() { // JSON -> GEOM -> WKB // String strPolygon1 = // "{\"xmin\":-1.16605115291E7,\"ymin\":4925189.941699997,\"xmax\":-1.16567772126E7,\"ymax\":4928658.771399997,\"spatialReference\":{\"wkid\":102100}}"; string strPolygon1 = "{\"rings\" : [ [ [-1.16605115291E7,4925189.941699997], [-1.16567772126E7,4925189.941699997], [-1.16567772126E7,4928658.771399997], [-1.16605115291E7,4928658.771399997], [-1.16605115291E7,4925189.941699997] ] ], \"spatialReference\" : {\"wkid\" : 102100}}"; org.codehaus.jackson.JsonFactory factory = new org.codehaus.jackson.JsonFactory(); org.codehaus.jackson.JsonParser parser = factory.createJsonParser(strPolygon1); parser.nextToken(); com.esri.core.geometry.MapGeometry mapGeom = com.esri.core.geometry.GeometryEngine .jsonToGeometry(parser); com.esri.core.geometry.Geometry geom = mapGeom.getGeometry(); // simplifying geom com.esri.core.geometry.OperatorSimplify operatorSimplify = (com.esri.core.geometry.OperatorSimplify )com.esri.core.geometry.OperatorFactoryLocal.getInstance().getOperator(com.esri.core.geometry.Operator.Type .Simplify); com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference .create(102100); geom = operatorSimplify.execute(geom, sr, true, null); com.esri.core.geometry.OperatorExportToWkb operatorExport = (com.esri.core.geometry.OperatorExportToWkb )com.esri.core.geometry.OperatorFactoryLocal.getInstance().getOperator(com.esri.core.geometry.Operator.Type .ExportToWkb); java.nio.ByteBuffer byteBuffer = operatorExport.execute(0, geom, null); byte[] wkb = ((byte[])byteBuffer.array()); // // checking WKB correctness // WKBReader jtsReader = new WKBReader(); // com.vividsolutions.jts.geom.Geometry jtsGeom = jtsReader.read(wkb); // System.out.println("jtsGeom = " + jtsGeom); // WKB -> GEOM -> JSON com.esri.core.geometry.OperatorImportFromWkb operatorImport = (com.esri.core.geometry.OperatorImportFromWkb )com.esri.core.geometry.OperatorFactoryLocal.getInstance().getOperator(com.esri.core.geometry.Operator.Type .ImportFromWkb); geom = operatorImport.execute(0, com.esri.core.geometry.Geometry.Type.Polygon, java.nio.ByteBuffer .wrap(wkb), null); NUnit.Framework.Assert.IsTrue(!geom.isEmpty()); }
public virtual void testWKB() { try { // JSON -> GEOM -> WKB string strPolygon1 = "{\"xmin\":-1.1663479012889031E7,\"ymin\":4919777.494405342,\"xmax\":-1.1658587043078788E7,\"ymax\":4924669.464215587,\"spatialReference\":{\"wkid\":102100}}"; // String strPolygon1 = // "{\"rings\":[[[-119.152450421001,38.4118009590513],[-119.318825070203,38.5271086243914],[-119.575687062955,38.7029101298904],[-119.889341639399,38.9222515603984],[-119.995254694357,38.9941061536377],[-119.995150114198,39.0634913594691],[-119.994541258334,39.1061318056708],[-119.995527335641,39.1587132866355],[-119.995304181493,39.3115454332125],[-119.996011479298,39.4435009764511],[-119.996165311172,39.7206108077274],[-119.996324660047,41.1775662656441],[-119.993459369715,41.9892049531992],[-119.351692186077,41.9888529749781],[-119.3109421304,41.9891353872811],[-118.185316829038,41.9966370981387],[-117.018864363596,41.9947941808341],[-116.992313337997,41.9947945094663],[-115.947544658193,41.9945994628997],[-115.024862911148,41.996506455953],[-114.269471632824,41.9959242345073],[-114.039072662345,41.9953908974688],[-114.038151248682,40.9976868405942],[-114.038108189376,40.1110466529553],[-114.039844684228,39.9087788600023],[-114.040105338584,39.5386849268845],[-114.044267501155,38.6789958815881],[-114.045090206153,38.5710950539539],[-114.047272999176,38.1376524399918],[-114.047260595159,37.5984784866001],[-114.043939384154,36.9965379371421],[-114.043716435713,36.8418489458647],[-114.037392074194,36.2160228969702],[-114.045105557286,36.1939778840226],[-114.107775185788,36.1210907070504],[-114.12902308363,36.041730493896],[-114.206768869568,36.0172554164834],[-114.233472615347,36.0183310595897],[-114.307587598189,36.0622330993643],[-114.303857056018,36.0871084040611],[-114.316095374696,36.1114380366653],[-114.344233941709,36.1374802520568],[-114.380803116644,36.1509912717765],[-114.443945697733,36.1210532841897],[-114.466613475422,36.1247112590539],[-114.530573568745,36.1550902046725],[-114.598935242024,36.1383354528834],[-114.621610747198,36.1419666834504],[-114.712761724737,36.1051810523675],[-114.728150311069,36.0859627711604],[-114.728966012834,36.0587530361083],[-114.717673567756,36.0367580437018],[-114.736212493583,35.9876483502758],[-114.699275906446,35.9116119537412],[-114.661600122152,35.8804735854242],[-114.662462095522,35.8709599070091],[-114.689867343369,35.8474424944766],[-114.682739704595,35.7647034175617],[-114.688820027649,35.7325957399896],[-114.665091345861,35.6930994107107],[-114.668486064922,35.6563989882404],[-114.654065925137,35.6465840800053],[-114.6398667219,35.6113485698329],[-114.653134321223,35.5848331056108],[-114.649792053474,35.5466373866597],[-114.672215155693,35.5157541647721],[-114.645396168451,35.4507608261463],[-114.589584275424,35.3583787306827],[-114.587889840369,35.30476812919],[-114.559583045727,35.2201828714608],[-114.561039964054,35.1743461616313],[-114.572255261053,35.1400677445931],[-114.582616239058,35.1325604694085],[-114.626440825485,35.1339067529872],[-114.6359090842,35.1186557767895],[-114.595631971944,35.0760579746697],[-114.633779872695,35.0418633504303],[-114.621068606189,34.9989144286133],[-115.626197382816,35.7956983148418],[-115.88576934392,36.0012259572723],[-117.160423771838,36.9595941441767],[-117.838686423167,37.457298239715],[-118.417419755966,37.8866767486211],[-119.152450421001,38.4118009590513]]], \"spatialReference\":{\"wkid\":4326}}"; org.codehaus.jackson.JsonFactory factory = new org.codehaus.jackson.JsonFactory(); org.codehaus.jackson.JsonParser parser = factory.createJsonParser(strPolygon1); parser.nextToken(); com.esri.core.geometry.MapGeometry mapGeom = com.esri.core.geometry.GeometryEngine .jsonToGeometry(parser); com.esri.core.geometry.Geometry geom = mapGeom.getGeometry(); com.esri.core.geometry.OperatorExportToWkb operatorExport = (com.esri.core.geometry.OperatorExportToWkb )com.esri.core.geometry.OperatorFactoryLocal.getInstance().getOperator(com.esri.core.geometry.Operator.Type .ExportToWkb); java.nio.ByteBuffer byteBuffer = operatorExport.execute(0, geom, null); byte[] wkb = ((byte[])byteBuffer.array()); // WKB -> GEOM -> JSON com.esri.core.geometry.OperatorImportFromWkb operatorImport = (com.esri.core.geometry.OperatorImportFromWkb )com.esri.core.geometry.OperatorFactoryLocal.getInstance().getOperator(com.esri.core.geometry.Operator.Type .ImportFromWkb); geom = operatorImport.execute(0, com.esri.core.geometry.Geometry.Type.Polygon, java.nio.ByteBuffer .wrap(wkb), null); // geom = operatorImport.execute(0, Geometry.Type.Polygon, // byteBuffer); string outputPolygon1 = com.esri.core.geometry.GeometryEngine.geometryToJson(-1, geom); } catch (org.codehaus.jackson.JsonParseException) { } catch (System.IO.IOException) { } }
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++)); } } }
public override int read(char[] buffer, int offset, int length) { lock (@lock) { if (!isOpen()) { throw new System.IO.IOException("InputStreamReader is closed"); } java.util.Arrays.checkOffsetAndCount(buffer.Length, offset, length); if (length == 0) { return(0); } java.nio.CharBuffer @out = java.nio.CharBuffer.wrap(buffer, offset, length); java.nio.charset.CoderResult result = java.nio.charset.CoderResult.UNDERFLOW; // bytes.remaining() indicates number of bytes in buffer // when 1-st time entered, it'll be equal to zero bool needInput = !bytes.hasRemaining(); while (@out.hasRemaining()) { // fill the buffer if needed if (needInput) { try { if (@in.available() == 0 && @out.position() > offset) { // we could return the result without blocking read break; } } catch (System.IO.IOException) { } // available didn't work so just try the read int desiredByteCount = bytes.capacity() - bytes.limit(); int off = bytes.arrayOffset() + bytes.limit(); int actualByteCount = @in.read(((byte[])bytes.array()), off, desiredByteCount); if (actualByteCount == -1) { endOfInput = true; break; } else { if (actualByteCount == 0) { break; } } bytes.limit(bytes.limit() + actualByteCount); needInput = false; } // decode bytes result = decoder.decode(bytes, @out, false); if (result.isUnderflow()) { // compact the buffer if no space left if (bytes.limit() == bytes.capacity()) { bytes.compact(); bytes.limit(bytes.position()); bytes.position(0); } needInput = true; } else { break; } } if (result == java.nio.charset.CoderResult.UNDERFLOW && endOfInput) { result = decoder.decode(bytes, @out, true); decoder.flush(@out); decoder.reset(); } if (result.isMalformed() || result.isUnmappable()) { result.throwException(); } return(@out.position() - offset == 0 ? -1 : @out.position() - offset); } }
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"); }