Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (const auto e = jniEnv->ExceptionOccurred())
- {
- std::printf("[!] An exception has occurred when calling LuaCompiler.loadString!\n");
- const auto objectClass = jniEnv->GetObjectClass(e);
- const auto getMessageMethodId = jniEnv->GetMethodID(objectClass, "getMessage", "()Ljava/lang/String;");
- const auto message = reinterpret_cast<jstring>(jniEnv->CallObjectMethod(e, getMessageMethodId));
- if (message != nullptr)
- {
- const auto str = jniEnv->GetStringUTFChars(message, nullptr);
- std::printf("->Message: %s\n", str);
- jniEnv->ReleaseStringUTFChars(message, str);
- }
- else
- {
- const auto toStringMethodId = jniEnv->GetMethodID(objectClass, "toString", "()Ljava/lang/String;");
- const auto objectString = reinterpret_cast<jstring>(jniEnv->CallObjectMethod(e, toStringMethodId));
- if (objectString != nullptr)
- {
- const auto str = jniEnv->GetStringUTFChars(objectString, nullptr);
- std::printf("->ObjectString: %s\n", str);
- jniEnv->ReleaseStringUTFChars(objectString, str);
- }
- else
- {
- std::printf("[!] Exception::toString returned nullptr!\n");
- }
- jniEnv->DeleteLocalRef(objectString);
- const auto getStackTraceMethodId = jniEnv->GetMethodID(objectClass, "getStackTrace", "()[Ljava/lang/StackTraceElement");
- const auto stackTrace = jniEnv->CallObjectMethod(e, getStackTraceMethodId);
- if (stackTrace != nullptr)
- {
- const auto stackTraceArray = reinterpret_cast<jobjectArray>(stackTrace);
- const auto arrayLength = jniEnv->GetArrayLength(stackTraceArray);
- for (int i = 0; i < arrayLength; ++i)
- {
- const auto arrayElement = jniEnv->GetObjectArrayElement(stackTraceArray, i);
- if (arrayElement != nullptr)
- {
- const static auto stackTraceElementClass = jniEnv->FindClass("java/lang/StackTraceElement");
- const static auto getClassNameMethodId = jniEnv->GetMethodID(stackTraceElementClass, "getClassName", "()Ljava/lang/String;");
- const static auto getMethodNameMethodId = jniEnv->GetMethodID(stackTraceElementClass, "getMethodName", "()Ljava/lang/String;");
- const auto className = reinterpret_cast<jstring>(jniEnv->CallObjectMethod(arrayElement, getClassNameMethodId));
- const auto methodName = reinterpret_cast<jstring>(jniEnv->CallObjectMethod(arrayElement, getMethodNameMethodId));
- if (className != nullptr)
- {
- const auto str = jniEnv->GetStringUTFChars(className, nullptr);
- std::printf("->ClassName: %s\n", str);
- jniEnv->ReleaseStringUTFChars(className, str);
- }
- if (methodName != nullptr)
- {
- const auto str = jniEnv->GetStringUTFChars(methodName, nullptr);
- std::printf("->MethodName: %s\n", str);
- jniEnv->ReleaseStringUTFChars(methodName, str);
- }
- jniEnv->DeleteLocalRef(className);
- jniEnv->DeleteLocalRef(methodName);
- }
- else
- {
- std::printf("[!] Stack trace index %d was null!\n", i);
- }
- jniEnv->DeleteLocalRef(arrayElement);
- }
- }
- jniEnv->DeleteLocalRef(stackTrace);
- std::printf("[!] Exception has no message!\n");
- }
- jniEnv->DeleteLocalRef(message);
- jniEnv->DeleteLocalRef(objectClass);
- jniEnv->DeleteLocalRef(e);
- jniEnv->ExceptionClear();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement