def evaluateJava(sourcepath, testlist, timelimit, result): if (not (os.path.exists('files/temp'))): os.system('mkdir files/temp') os.system('rm files/temp/*') if (checkcodeJava(sourcepath) == 'true'): result['status'] = 'Malicious code' result['executiontime'] = -1 return source = sourcepath.split("/") filename = source[len(source) - 1] classname = filename.split(".")[0] os.system('chmod 777 files/temp/temp.java' ) #granting all permissions to the temp os.system( 'javac -d files/temp files/temp/temp.java') # compiling the java code testresult = list() exectime = list() #creating output file and comparing with the sample if a.out is generated if (os.path.exists('files/temp/' + classname + '.class')): for i in testlist: inputpath = i['input'] outputpath = i['output'] runcmd = 'java -mx64m -classpath files/temp ' + classname + ' < ' + inputpath + ' > files/temp/output.out' response = timechecker.execute(runcmd, timelimit) # response={'status':'ok/runtime exceeded/runtime error','executiontime':'time/-1'} if (response['run_status'] == "ok"): checkOutput('files/temp/output.out', outputpath, testresult) exectime.append(response['runtime']) else: testresult.append(response['run_status']) exectime.append(response['runtime']) result['status'] = testresult result['executiontime'] = exectime #status=error is a.out is not generated else: result['status'] = 'errors' result['executiontime'] = -1
def evaluateJava(sourcepath,testlist,timelimit,result): if(not(os.path.exists('files/temp'))): os.system('mkdir files/temp') os.system('rm files/temp/*') if(checkcodeJava(sourcepath)=='true'): result['status']='Malicious code' result['executiontime']=-1 return source=sourcepath.split("/") filename=source[len(source)-1] classname=filename.split(".")[0] os.system('chmod 777 files/temp/temp.java') #granting all permissions to the temp os.system('javac -d files/temp files/temp/temp.java') # compiling the java code testresult=list() exectime=list() #creating output file and comparing with the sample if a.out is generated if(os.path.exists('files/temp/'+classname+'.class')): for i in testlist: inputpath=i['input'] outputpath=i['output'] runcmd='java -mx64m -classpath files/temp '+classname+' < ' + inputpath + ' > files/temp/output.out' response=timechecker.execute(runcmd,timelimit) # response={'status':'ok/runtime exceeded/runtime error','executiontime':'time/-1'} if (response['run_status']=="ok"): checkOutput('files/temp/output.out',outputpath,testresult) exectime.append(response['runtime']) else: testresult.append(response['run_status']) exectime.append(response['runtime']) result['status']=testresult result['executiontime']=exectime #status=error is a.out is not generated else: result['status']='errors' result['executiontime']=-1
def evaluateCPP(sourcepath,testlist,timelimit,result): if(not(os.path.exists('files/temp'))): os.system('mkdir files/temp') os.system('rm files/temp/*') if(checkcodeCPP(sourcepath)=='true'): result['status']='Malicious code' result['executiontime']=-1 return os.system('chmod 777 files/temp/temp.cpp') #granting all permissions to the temp os.system('g++ -o files/temp/a.out files/temp/temp.cpp') # compiling the C++ code #creating output file and comparing with the sample if a.out is generated testresult=list() exectime=list() if(os.path.exists('files/temp/a.out')): for i in testlist: inputpath=i['input'] outputpath=i['output'] runcmd='./files/temp/./a.out <' + inputpath + '> files/temp/output.out' response=timechecker.execute(runcmd,timelimit) # response={'status':'ok/runtime exceeded/runtime error','executiontime':'time/-1'} if (response['run_status']=="ok"): checkOutput('files/temp/output.out',outputpath,testresult) exectime.append(response['runtime']) else: testresult.append(response['run_status']) exectime.append(response['runtime']) result['status']=testresult result['executiontime']=exectime #status=error is a.out is not generated else: result['status']='errors' result['executiontime']=-1