Advertisement
SleepyMode

Untitled

Mar 10th, 2023
740
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.35 KB | None | 0 0
  1.             if (const auto e = jniEnv->ExceptionOccurred())
  2.             {
  3.                 std::printf("[!] An exception has occurred when calling LuaCompiler.loadString!\n");
  4.  
  5.                 const auto objectClass = jniEnv->GetObjectClass(e);
  6.                 const auto getMessageMethodId = jniEnv->GetMethodID(objectClass, "getMessage", "()Ljava/lang/String;");
  7.                 const auto message = reinterpret_cast<jstring>(jniEnv->CallObjectMethod(e, getMessageMethodId));
  8.                 if (message != nullptr)
  9.                 {
  10.                     const auto str = jniEnv->GetStringUTFChars(message, nullptr);
  11.                     std::printf("->Message: %s\n", str);
  12.                     jniEnv->ReleaseStringUTFChars(message, str);
  13.                 }
  14.                 else
  15.                 {
  16.                     const auto toStringMethodId = jniEnv->GetMethodID(objectClass, "toString", "()Ljava/lang/String;");
  17.                     const auto objectString = reinterpret_cast<jstring>(jniEnv->CallObjectMethod(e, toStringMethodId));
  18.                     if (objectString != nullptr)
  19.                     {
  20.                         const auto str = jniEnv->GetStringUTFChars(objectString, nullptr);
  21.                         std::printf("->ObjectString: %s\n", str);
  22.                         jniEnv->ReleaseStringUTFChars(objectString, str);
  23.                     }
  24.                     else
  25.                     {
  26.                         std::printf("[!] Exception::toString returned nullptr!\n");
  27.                     }
  28.                     jniEnv->DeleteLocalRef(objectString);
  29.  
  30.                     const auto getStackTraceMethodId = jniEnv->GetMethodID(objectClass, "getStackTrace", "()[Ljava/lang/StackTraceElement");
  31.                     const auto stackTrace = jniEnv->CallObjectMethod(e, getStackTraceMethodId);
  32.                     if (stackTrace != nullptr)
  33.                     {
  34.                         const auto stackTraceArray = reinterpret_cast<jobjectArray>(stackTrace);
  35.                         const auto arrayLength = jniEnv->GetArrayLength(stackTraceArray);
  36.  
  37.                         for (int i = 0; i < arrayLength; ++i)
  38.                         {
  39.                             const auto arrayElement = jniEnv->GetObjectArrayElement(stackTraceArray, i);
  40.                             if (arrayElement != nullptr)
  41.                             {
  42.                                 const static auto stackTraceElementClass = jniEnv->FindClass("java/lang/StackTraceElement");
  43.                                 const static auto getClassNameMethodId = jniEnv->GetMethodID(stackTraceElementClass, "getClassName", "()Ljava/lang/String;");
  44.                                 const static auto getMethodNameMethodId = jniEnv->GetMethodID(stackTraceElementClass, "getMethodName", "()Ljava/lang/String;");
  45.                                 const auto className = reinterpret_cast<jstring>(jniEnv->CallObjectMethod(arrayElement, getClassNameMethodId));
  46.                                 const auto methodName = reinterpret_cast<jstring>(jniEnv->CallObjectMethod(arrayElement, getMethodNameMethodId));
  47.  
  48.                                 if (className != nullptr)
  49.                                 {
  50.                                     const auto str = jniEnv->GetStringUTFChars(className, nullptr);
  51.                                     std::printf("->ClassName: %s\n", str);
  52.                                     jniEnv->ReleaseStringUTFChars(className, str);
  53.                                 }
  54.  
  55.                                 if (methodName != nullptr)
  56.                                 {
  57.                                     const auto str = jniEnv->GetStringUTFChars(methodName, nullptr);
  58.                                     std::printf("->MethodName: %s\n", str);
  59.                                     jniEnv->ReleaseStringUTFChars(methodName, str);
  60.                                 }
  61.  
  62.                                 jniEnv->DeleteLocalRef(className);
  63.                                 jniEnv->DeleteLocalRef(methodName);
  64.                             }
  65.                             else
  66.                             {
  67.                                 std::printf("[!] Stack trace index %d was null!\n", i);
  68.                             }
  69.                             jniEnv->DeleteLocalRef(arrayElement);
  70.                         }
  71.                     }
  72.                     jniEnv->DeleteLocalRef(stackTrace);
  73.  
  74.                     std::printf("[!] Exception has no message!\n");
  75.                 }
  76.                 jniEnv->DeleteLocalRef(message);
  77.                 jniEnv->DeleteLocalRef(objectClass);
  78.                 jniEnv->DeleteLocalRef(e);
  79.                 jniEnv->ExceptionClear();
  80.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement