helloworld_jni_interface.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include <jni.h>
  2. int main(int argc, char **argv)
  3. {
  4. JavaVM *vm;
  5. JNIEnv *env;
  6. JavaVMInitArgs vm_args;
  7. jint res;
  8. jclass cls;
  9. jmethodID mid;
  10. jstring jstr;
  11. jobjectArray main_args;
  12. JavaVMOption* options = new JavaVMOption[5];
  13. options[0].optionString = "-Dpixy.home=/home/m2mazmud/pixy-master";
  14. options[1].optionString = "-Djava.class.path=/home/m2mazmud/pixy-master/lib:/home/m2mazmud/pixy-master/build/class";
  15. options[2].optionString = "-Xcheck:jni";
  16. options[3].optionString = "-Xms256m";
  17. options[4].optionString = "-Xmx1024m";
  18. vm_args.options = options;
  19. vm_args.nOptions = 5;
  20. vm_args.ignoreUnrecognized = JNI_TRUE;
  21. vm_args.version = JNI_VERSION_1_8;
  22. if (JNI_CreateJavaVM(&vm, (void **)&env, &vm_args) != JNI_OK) {
  23. printf("Failed to create Java VMn");
  24. return 1;
  25. }
  26. cls = (env)->FindClass( "at/ac/tuwien/infosys/www/pixy/Checker");
  27. if (cls == NULL) {
  28. printf("Failed to find Main classn");
  29. return 1;
  30. }
  31. mid = (env)->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V");
  32. if (mid == NULL) {
  33. printf("Failed to find main functionnnnn");
  34. return 1;
  35. }
  36. printf("Hehehehe\n"); fflush(stdout);
  37. jclass classString = (env)->FindClass("java/lang/String");
  38. jstr = (env)->NewStringUTF("");
  39. main_args = (env)->NewObjectArray( 8, classString, jstr);
  40. (env)->SetObjectArrayElement( main_args, 0, (env)->NewStringUTF( "-aAvLf"));
  41. (env)->SetObjectArrayElement( main_args, 1, (env)->NewStringUTF( "-s"));
  42. (env)->SetObjectArrayElement( main_args, 2, (env)->NewStringUTF( "/home/m2mazmud/pixy-master/config/sinks_xss.txt"));
  43. (env)->SetObjectArrayElement( main_args, 3, (env)->NewStringUTF( "-o"));
  44. (env)->SetObjectArrayElement( main_args, 4, (env)->NewStringUTF( "/home/m2mazmud/pixy-master/sample_mitigator/results"));
  45. (env)->SetObjectArrayElement( main_args, 5, (env)->NewStringUTF( "-y"));
  46. (env)->SetObjectArrayElement( main_args, 6, (env)->NewStringUTF( "xss"));
  47. if(argc>=1)
  48. (env)->SetObjectArrayElement( main_args, 7, (env)->NewStringUTF( argv[1]));
  49. (env)->CallStaticVoidMethod( cls, mid, main_args);
  50. if((env)->ExceptionOccurred()) {
  51. (env)->ExceptionDescribe();
  52. (env)->ExceptionClear();
  53. printf("Exception occurred\n"); fflush(stdout);
  54. }
  55. return 0;
  56. }