Browse Source

Prolly not working jni commit

dettanym 3 years ago
parent
commit
6e2ba1be9b
4 changed files with 152 additions and 3 deletions
  1. 4 2
      Makefile
  2. 64 0
      helloworld_jni_interface.cpp
  3. 4 0
      jni_compiling_linking.sh
  4. 80 1
      systemMain.cpp

+ 4 - 2
Makefile

@@ -37,11 +37,13 @@ Protobuf%.o: Protobuf%.cpp
 	${CXX} -I./include ${CXX_FLAGS} -c $^ -o $@
 
 system%.o: system%.cpp
-	gcc -I./include ${CXX_FLAGS} -c $^ -o $@
+	gcc -I./include -I/usr/lib/jvm/java-8-openjdk-amd64/include/ -I/usr/lib/jvm/java-8-openjdk-amd64/include/linux/ ${CXX_FLAGS} -c $^ -o $@
 
 crypto.o: crypto.cpp 
 	gcc -I${Openssl_Path}/include ${CXX_FLAGS} -c $^ -o $@
 
 verifier:  systemMain.o systemSealerWrapper.o SgxSealer.o ProtobufLAInitiator.o SgxProtobufLAInitiator.o SgxProtobufLAInitiator_Transforms.o ProtobufLAMessages.pb.o crypto.o
 #	echo $(system_obj)
-	${CXX} ${CXX_FLAGS} -Wl,--no-undefined  -Wl,-rpath,$(SGX_SDK)/lib64  systemMain.o systemSealerWrapper.o SgxSealer.o ProtobufLAInitiator.o SgxProtobufLAInitiator.o SgxProtobufLAInitiator_Transforms.o ProtobufLAMessages.pb.o crypto.o -L./ -Wl,--whole-archive -l$(Trts_Library_Name) -Wl,--no-whole-archive  -L$(SGX_LIBRARY_PATH) -l$(Service_Library_Name) -l$(Crypto_Library_Name) -lsgx_tstdc  -lprotobuf  -L${Openssl_Path}/lib -lssl -lcrypto   -Wl,--verbose -o $@
+	${CXX} ${CXX_FLAGS} -Wl,--no-undefined  -Wl,-rpath,$(SGX_SDK)/lib64  systemMain.o systemSealerWrapper.o SgxSealer.o ProtobufLAInitiator.o SgxProtobufLAInitiator.o SgxProtobufLAInitiator_Transforms.o ProtobufLAMessages.pb.o crypto.o -L./ -Wl,--whole-archive -l$(Trts_Library_Name) -Wl,--no-whole-archive  -L$(SGX_LIBRARY_PATH) -l$(Service_Library_Name) -l$(Crypto_Library_Name) -lsgx_tstdc  -lprotobuf  -L${Openssl_Path}/lib -lssl -lcrypto -L/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server  -ljvm -Wl,--trace -o $@
+# -L/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server -ljvm 
+

+ 64 - 0
helloworld_jni_interface.cpp

@@ -0,0 +1,64 @@
+#include <jni.h>
+
+int main(int argc, char **argv)
+{
+    JavaVM         *vm;
+    JNIEnv         *env;
+    JavaVMInitArgs  vm_args;
+    jint            res;
+    jclass          cls;
+    jmethodID       mid;
+    jstring         jstr;
+    jobjectArray    main_args;
+    JavaVMOption* options = new JavaVMOption[5];
+    options[0].optionString = "-Dpixy.home=/home/miti/thesis/php_tainting/pixy-master";
+    options[1].optionString = "-Djava.class.path=/home/miti/thesis/php_tainting/pixy-master/lib:/home/miti/thesis/php_tainting/pixy-master/build/class";
+    options[2].optionString = "-Xcheck:jni";
+    options[3].optionString = "-Xms256m";
+    options[4].optionString = "-Xmx1024m";
+    vm_args.options            = options;
+    vm_args.nOptions           = 5;
+
+
+    vm_args.ignoreUnrecognized = JNI_TRUE;
+    vm_args.version  = JNI_VERSION_1_8;
+    if (JNI_CreateJavaVM(&vm, (void **)&env, &vm_args) != JNI_OK) {
+        printf("Failed to create Java VMn");
+        return 1;
+    }
+
+    cls = (env)->FindClass( "at/ac/tuwien/infosys/www/pixy/Checker");
+    if (cls == NULL) {
+        printf("Failed to find Main classn");
+        return 1;
+    }
+
+    mid = (env)->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V");
+    if (mid == NULL) {
+        printf("Failed to find main functionnnnn");
+        return 1;
+    }
+    printf("Hehehehe\n"); fflush(stdout);
+
+    jclass classString = (env)->FindClass("java/lang/String");
+    jstr      = (env)->NewStringUTF("");
+    main_args = (env)->NewObjectArray( 8, classString, jstr);
+
+    (env)->SetObjectArrayElement( main_args, 0, (env)->NewStringUTF( "-aAvLf"));
+    (env)->SetObjectArrayElement( main_args, 1, (env)->NewStringUTF( "-s"));
+    (env)->SetObjectArrayElement( main_args, 2, (env)->NewStringUTF( "/home/miti/thesis/php_tainting/pixy-master/config/sinks_xss.txt"));
+    (env)->SetObjectArrayElement( main_args, 3, (env)->NewStringUTF( "-o"));
+    (env)->SetObjectArrayElement( main_args, 4, (env)->NewStringUTF( "/home/miti/thesis/open_source_applications/sample_cs458site_analysis"));
+    (env)->SetObjectArrayElement( main_args, 5, (env)->NewStringUTF( "-y"));
+    (env)->SetObjectArrayElement( main_args, 6, (env)->NewStringUTF( "xss"));
+    if(argc>=1)
+      (env)->SetObjectArrayElement( main_args, 7, (env)->NewStringUTF( argv[1]));
+
+    (env)->CallStaticVoidMethod( cls, mid, main_args);
+    if((env)->ExceptionOccurred()) {
+      (env)->ExceptionClear();
+      printf("Exception occurred\n"); fflush(stdout);
+    }
+
+    return 0;
+}

+ 4 - 0
jni_compiling_linking.sh

@@ -0,0 +1,4 @@
+g++ helloworld_jni_interface.cpp -I/usr/lib/jvm/java-8-openjdk-amd64/include/ -I/usr/lib/jvm/java-8-openjdk-amd64/include/linux/ -L/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/jli -L/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server -ljli -ljvm 
+#LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/jli:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server ./a.out $1
+
+

+ 80 - 1
systemMain.cpp

@@ -2,11 +2,12 @@
 #include <string>
 #include <unistd.h>
 #include <errno.h>
-
+#include <jni.h>
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <stdio.h>
+#include <signal.h>
 
 #include "crypto.h"
 #include "ProtobufLAInitiator.h"
@@ -19,9 +20,87 @@ using namespace std;
 int __ImageBase=0;
 int verify_apache(std::string& path, std::string& keypair) {return 0; }
 
+void foo() //sigsegv_handler(int signo)
+{
+	printf("foo hehe ---------------------\n"); 
+	fflush(stdout); 
+}
+
+
+
+
 
 int main(int argc, char** argv)
 {
+
+//	signal(SIGSEGV, SIG_IGN);  //sigsegv_handler); 
+	
+    JavaVM         *vm;
+    JNIEnv         *env;
+    JavaVMInitArgs  vm_args;
+    jint            res;
+    jclass          cls;
+    jmethodID       mid;
+    jstring         jstr;
+    jobjectArray    main_args;
+    JavaVMOption* options = new JavaVMOption[7];
+    options[0].optionString = "-Dpixy.home=/home/m2mazmud/pixy-master";
+    options[1].optionString = "-Djava.class.path=/home/m2mazmud/pixy-master/lib:/home/m2mazmud/pixy-master/build/class";
+    options[2].optionString = "-Xcheck:jni";
+    options[3].optionString = "-Xms32m";
+    options[4].optionString = "-Xmx128m";
+    options[5].optionString = "-XX:MaxMetaspaceSize=128m"; 
+    options[6].optionString = "-Xss256k"; 
+    vm_args.options            = options;
+    vm_args.nOptions           = 7;
+
+	printf("Helloworld\n"); fflush(stdout);
+    vm_args.ignoreUnrecognized = JNI_TRUE;
+    vm_args.version  = JNI_VERSION_1_8;
+//	sleep(60); 
+
+	foo();
+    if (JNI_CreateJavaVM(&vm, (void **)&env, &vm_args) != JNI_OK) {
+        delete options;
+	printf("Failed to create Java VMn");
+        return 1;
+    }
+	delete options; 
+    cls = (env)->FindClass( "at/ac/tuwien/infosys/www/pixy/Checker");
+    if (cls == NULL) {
+        printf("Failed to find Main classn");
+        return 1;
+    }
+
+    mid = (env)->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V");
+    if (mid == NULL) {
+        printf("Failed to find main functionnnnn");
+        return 1;
+    }
+    printf("Hehehehe\n"); fflush(stdout);
+
+    jclass classString = (env)->FindClass("java/lang/String");
+    jstr      = (env)->NewStringUTF("");
+    main_args = (env)->NewObjectArray( 8, classString, jstr);
+
+    (env)->SetObjectArrayElement( main_args, 0, (env)->NewStringUTF( "-aAvLf"));
+    (env)->SetObjectArrayElement( main_args, 1, (env)->NewStringUTF( "-s"));
+    (env)->SetObjectArrayElement( main_args, 2, (env)->NewStringUTF( "/home/m2mazmud/pixy-master/config/sinks_xss.txt"));
+    (env)->SetObjectArrayElement( main_args, 3, (env)->NewStringUTF( "-o"));
+    (env)->SetObjectArrayElement( main_args, 4, (env)->NewStringUTF( "/home/m2mazmud/pixy-master/sample_mitigator/results"));
+    (env)->SetObjectArrayElement( main_args, 5, (env)->NewStringUTF( "-y"));
+    (env)->SetObjectArrayElement( main_args, 6, (env)->NewStringUTF( "xss"));
+    if(argc>=1)
+      (env)->SetObjectArrayElement( main_args, 7, (env)->NewStringUTF( argv[1]));
+
+    (env)->CallStaticVoidMethod( cls, mid, main_args);
+    if((env)->ExceptionOccurred()) {
+      (env)->ExceptionClear();
+      printf("Exception occurred\n"); fflush(stdout);
+    }
+
+
+
   uint8_t expected_apache_mr_signer[32] = {0};
   std::string apache_signature_keypair_private("1234567890");
   std::string apache_public_key;