| 5 |
| 6 | static const size_t kHelloBufferSize = 8192; |
| 7 |
| 8 | extern "C" JNIEXPORT jbyteArray JNICALL |
| 9 | Java_org_telegram_tgnet_ConnectionsManager_nativeTestGenerateClientHello(JNIEnv *env, jclass, jstring domain) { |
| 10 | const char *chars = env->GetStringUTFChars(domain, nullptr); |
| 11 | std::string domainStr(chars != nullptr ? chars : ""); |
| 12 | if (chars != nullptr) { |
| 13 | env->ReleaseStringUTFChars(domain, chars); |
| 14 | } |
| 15 |
| 16 | // getDefault() returns a const singleton, writeToBuffer() is non-const — take a copy. |
| 17 | TLSHello hello = TLSHello::getDefault(); |
| 18 | hello.setDomain(domainStr); |
| 19 |
| 20 | std::vector<uint8_t> buffer(kHelloBufferSize, 0); |
| 21 | uint32_t size = hello.writeToBuffer(buffer.data()); |
| 22 |
| 23 | jbyteArray result = env->NewByteArray(static_cast<jsize>(size)); |
| 24 | if (result == nullptr) { |
| 25 | return nullptr; |
| 26 | } |
| 27 | env->SetByteArrayRegion(result, 0, static_cast<jsize>(size), |
| 28 | reinterpret_cast<const jbyte *>(buffer.data())); |
| 29 | return result; |
| 30 | } |