Example #1
0
def processFile(flow, content, ext):
    try:
        url = flow.request.scheme + '://' + flow.request.host + ':' + str(
            flow.request.port) + flow.request.path
        name = os.path.splitext(flow.request.path_components[-1])[0] if len(
            flow.request.path_components) else 'index'

        hash = hashlib.md5(content).hexdigest()
        fileName = 'cache/' + flow.request.host + '/' + hash + '/' + name + '.' + ext
        instrumentedFileName = 'cache/' + flow.request.host + '/' + hash + '/' + name + '_jalangi_.' + ext
        if not os.path.exists('cache/' + flow.request.host + '/' + hash):
            os.makedirs('cache/' + flow.request.host + '/' + hash)
        if not useCache or not os.path.isfile(instrumentedFileName):
            print('Instrumenting: ' + fileName + ' from ' + url)
            with open(fileName, 'w') as file:
                file.write(sj.encode_input(content))
            sub_env = {'JALANGI_URL': url}
            sj.execute(
                sj.INSTRUMENTATION_SCRIPT + ' ' + jalangiArgs + ' ' +
                fileName + ' --out ' + instrumentedFileName + ' --outDir ' +
                os.path.dirname(instrumentedFileName), None, sub_env)
        else:
            print('Already instrumented: ' + fileName + ' from ' + url)
        with open(instrumentedFileName, "r") as file:
            data = file.read()
        return data
    except:
        print('Exception in processFile() @ proxy.py')
        exc_type, exc_value, exc_traceback = sys.exc_info()
        lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
        print(''.join(lines))
        return content
Example #2
0
def processFile (flow, content, ext):
    try:
        url = flow.request.scheme + '://' + flow.request.host + ':' + str(flow.request.port) + flow.request.path
        name = os.path.splitext(flow.request.path_components[-1])[0] if len(flow.request.path_components) else 'index'

        hash = hashlib.md5(content).hexdigest()
        fileName = 'cache/' + flow.request.host + '/' + hash + '/' + name + '.' + ext
        instrumentedFileName = 'cache/' + flow.request.host + '/' + hash + '/' + name + '_jalangi_.' + ext
        if not os.path.exists('cache/' + flow.request.host + '/' + hash):
            os.makedirs('cache/' + flow.request.host + '/' + hash)
        if not useCache or not os.path.isfile(instrumentedFileName):
            print('Instrumenting: ' + fileName + ' from ' + url)
            with open(fileName, 'w') as file:
                if content.startswith(codecs.BOM_UTF16):
                    file.write(content.decode('utf-16').encode('utf-8'))
                elif content.startswith(codecs.BOM_UTF16_BE):
                    file.write(content.decode('utf-16-be').encode('utf-8'))
                elif content.startswith(codecs.BOM_UTF16_LE):
                    file.write(content.decode('utf-16-le').encode('utf-8'))
                else:
                    file.write(content)
            sub_env = { 'JALANGI_URL': url }
            sj.execute(sj.INSTRUMENTATION_SCRIPT + ' ' + jalangiArgs + ' ' + fileName + ' --out ' + instrumentedFileName + ' --outDir ' + os.path.dirname(instrumentedFileName), sub_env)
        else:
            print('Already instrumented: ' + fileName + ' from ' + url)
        with open (instrumentedFileName, "r") as file:
            data = file.read()
        return data
    except:
        print('Exception in processFile() @ proxy.py')
        exc_type, exc_value, exc_traceback = sys.exc_info()
        lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
        print(''.join(lines))
        return content
def testDlint(file):
    sj.create_and_cd_jalangi_tmp()
    sj.execute(sj.INSTRUMENTATION_SCRIPT + ' --inlineIID --inlineSource ../' +
               file + '.js')
    out = sj.execute(sj.ANALYSIS_SCRIPT + analysesStr + ' ../' + file +
                     '_jalangi_.js')
    sj.cd_parent()
Example #4
0
def processFile (content, ext):
	try:
		fileName = hashlib.md5(content).hexdigest()
		if not os.path.isfile(fileName+'.'+ext):
			print "Storing and instrumenting "+fileName+"."+ext
			with open(fileName+"."+ext, "w") as text_file:
				text_file.write(content)
			sj.execute(sj.INSTRUMENTATION_SCRIPT+' --inlineIID --inlineSource '+analysis+' '+fileName+'.'+ext)
		with open (fileName+"_jalangi_."+ext, "r") as text_file:
			data = text_file.read()
		return data
	except:
		print "Execption in proxy.py"
		print sys.exc_info()
		return content
Example #5
0
def processFile (content, ext):
	try:
		fileName = hashlib.md5(content).hexdigest()
		if not os.path.isfile(fileName+'.'+ext):
			print "Storing and instrumenting "+fileName+"."+ext
			with open(fileName+"."+ext, "w") as text_file:
				text_file.write(content)
			sj.execute(sj.INSTRUMENTATION_SCRIPT+' --inlineIID --inlineSource '+extraArgs+' '+fileName+'.'+ext)
		with open (fileName+"_jalangi_."+ext, "r") as text_file:
			data = text_file.read()
		return data
	except:
		print "Exception in proxy.py"
		print sys.exc_info()
		return content
Example #6
0
def processFile (flow, content, ext):
    try:
        url = flow.request.scheme + '://' + flow.request.host + ':' + str(flow.request.port) + flow.request.path
        name = os.path.splitext(flow.request.path_components[-1])[0] if hasattr(flow.request,'path_components') and len(flow.request.path_components) else 'index'
        #+flow.request.host+"/"
        hash = hashlib.md5(content.encode('utf-8')).hexdigest()
        fileName = 'cache/' + flow.request.host + '/' + hash + '/' + name + '.' + ext
        instrumentedFileName = 'cache/' + flow.request.host + '/' + hash + '/' + name + '_jalangi_.' + ext
        if not os.path.exists("/home/anon/BenchInst/ "+flow.request.host + "/"):
            os.makedirs("/home/anon/BenchInst/ "+flow.request.host + "/")
        with open("/home/anon/BenchInst/ "+flow.request.host + "/"+name+"."+ext, 'w+') as file:
            file.write(content)
        if not os.path.exists('cache/' + flow.request.host + '/' + hash):
            os.makedirs('cache/' + flow.request.host + '/' + hash)
        if not useCache or not os.path.isfile(instrumentedFileName):
            print('Instrumenting: ' + fileName + ' from ' + url)
            with open(fileName, 'w') as file:
                file.write(content)
            sub_env = { 'JALANGI_URL': url }
            #print("here:",sj.INSTRUMENTATION_SCRIPT + ' ' + '--inlineIID --inlineSource --analysis src/js/sample_analyses/ChainedAnalyses.js --analysis src/js/runtime/analysisCallbackTemplate.js' + ' ' + fileName + ' --out ' + instrumentedFileName + ' --outDir ' + os.path.dirname(instrumentedFileName))
            if "FileSaver" not in name :
                sj.execute(sj.INSTRUMENTATION_SCRIPT + ' ' + jalangiArgs + ' ' + fileName + ' --out ' + instrumentedFileName + ' --outDir ' + os.path.dirname(instrumentedFileName), None, sub_env)
            '''else:
                with open(instrumentedFileName, 'w') as file:
                    file.write(content)'''
        else:
            print('Already instrumented: ' + fileName + ' from ' + url)
        with open (instrumentedFileName, 'r') as file:
            data = file.read()
        #print(data)
        return data
    except:
        print('Exception in processFile() @ proxy.py')
        exc_type, exc_value, exc_traceback = sys.exc_info()
        lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
        print(''.join(lines))
        return content
Example #7
0
import sj
import sys

# scripting jalangi sample 2
sj.create_and_cd_jalangi_tmp()
sj.execute(sj.INSTRUMENTATION_SCRIPT+' --inlineIID --inlineSource ../'+sys.argv[1]+'.js')
normal = sj.execute_return('../'+sys.argv[1]+'.js', savestderr=True)
ana = sj.execute_return(sj.ANALYSIS_SCRIPT+' --analysis ../src/js/sample_analyses/ChainedAnalyses.js --analysis ../src/js/runtime/analysisCallbackTemplate.js ../'+sys.argv[1]+'_jalangi_.js', savestderr=True)

if normal != ana:
    print "{} failed".format(sys.argv[1])
    print normal
    print ana
else:
    print "{} passed".format(sys.argv[1])
    print normal
    print ana
sj.cd_parent()
Example #8
0
import sj
import sys

# scripting jalangi sample 2
sj.create_and_cd_jalangi_tmp()
sj.execute(sj.INSTRUMENTATION_SCRIPT+' ../'+sys.argv[1]+'.js')
normal = sj.execute_return('../'+sys.argv[1]+'.js', savestderr=True)
ana = sj.execute_return(sj.ANALYSIS2_SCRIPT+' --analysis ../src/js/analyses2/ChainedAnalyses2.js --analysis ../src/js/analysis2CallbackTemplate.js ../'+sys.argv[1]+'_jalangi_.js', savestderr=True)

if normal != ana:
    print "{} failed".format(sys.argv[1])
    print normal
    print ana
else:
    print "{} passed".format('tests/unit/instrument-test.js')
    print normal
    print ana
sj.cd_parent()
Example #9
0
import sj

# scripting jalangi sample 1
sj.execute(sj.INSTRUMENTATION_SCRIPT+' tests/octane/deltablue.js')
sj.execute(sj.DIRECT_SCRIPT+' --smemory --analysis src/js/analyses/objectalloc/ObjectAllocationTrackerEngineIB.js tests/octane/deltablue_jalangi_.js')



# scripting jalangi sample 2
sj.create_and_cd_jalangi_tmp()
sj.execute(sj.INSTRUMENTATION_SCRIPT+' ../tests/unit/instrument-test.js')
normal = sj.execute_return('../tests/unit/instrument-test.js', savestderr=True)
sj.mkempty("inputs.js")
rec = sj.execute_return(sj.RECORD_SCRIPT+' ../tests/unit/instrument-test_jalangi_.js', savestderr=True)
rep = sj.execute_return(sj.REPLAY_SCRIPT, savestderr=True)

if normal != rec:
    print "{} failed".format('tests/unit/instrument-test.js')
    print normal
    print rec
    print rep
elif rec != rep:
    print "{} failed".format('tests/unit/instrument-test.js')
    print normal
    print rec
    print rep
else:
    print "{} passed".format('tests/unit/instrument-test.js')
sj.cd_parent()
Example #10
0
def testDlint (file):
    sj.create_and_cd_jalangi_tmp()
    sj.execute(sj.INSTRUMENTATION_SCRIPT+' --inlineIID --inlineSource ../'+file+'.js')
    out = sj.execute(sj.ANALYSIS_SCRIPT+ analysesStr+' ../'+file+'_jalangi_.js')
    sj.cd_parent()
Example #11
0
import sj
import sys

# scripting jalangi sample 2
sj.create_and_cd_jalangi_tmp()
sj.execute(sj.INSTRUMENTATION_SCRIPT + ' --inlineIID --inlineSource ../' +
           sys.argv[1] + '.js')
normal = sj.execute_return('../' + sys.argv[1] + '.js', savestderr=True)
ana = sj.execute_return(
    sj.ANALYSIS_SCRIPT +
    ' --analysis ../src/js/sample_analyses/ChainedAnalyses.js --analysis ../src/js/runtime/analysisCallbackTemplate.js ../'
    + sys.argv[1] + '_jalangi_.js',
    savestderr=True)

if normal != ana:
    print "{} failed".format(sys.argv[1])
    print normal
    print ana
else:
    print "{} passed".format(sys.argv[1])
    print normal
    print ana
sj.cd_parent()
Example #12
0
import sj

# scripting jalangi sample 1
sj.execute(sj.INSTRUMENTATION_SCRIPT + ' tests/octane/deltablue.js')
sj.execute(
    sj.DIRECT_SCRIPT +
    ' --smemory --analysis src/js/analyses/objectalloc/ObjectAllocationTrackerEngineIB.js tests/octane/deltablue_jalangi_.js'
)

# scripting jalangi sample 2
sj.create_and_cd_jalangi_tmp()
sj.execute(sj.INSTRUMENTATION_SCRIPT + ' ../tests/unit/instrument-test.js')
normal = sj.execute_return('../tests/unit/instrument-test.js', savestderr=True)
sj.mkempty("inputs.js")
rec = sj.execute_return(sj.RECORD_SCRIPT +
                        ' ../tests/unit/instrument-test_jalangi_.js',
                        savestderr=True)
rep = sj.execute_return(sj.REPLAY_SCRIPT, savestderr=True)

if normal != rec:
    print "{} failed".format('tests/unit/instrument-test.js')
    print normal
    print rec
    print rep
elif rec != rep:
    print "{} failed".format('tests/unit/instrument-test.js')
    print normal
    print rec
    print rep
else:
    print "{} passed".format('tests/unit/instrument-test.js')
Example #13
0
import sj
import sys

# scripting jalangi sample 2
sj.create_and_cd_jalangi_tmp()
sj.execute(sj.INSTRUMENTATION_SCRIPT + ' ../' + sys.argv[1] + '.js')
normal = sj.execute_return('../' + sys.argv[1] + '.js', savestderr=True)
ana = sj.execute_return(
    sj.ANALYSIS2_SCRIPT +
    ' --analysis ../src/js/analyses2/ChainedAnalyses2.js --analysis ../src/js/analysis2CallbackTemplate.js ../'
    + sys.argv[1] + '_jalangi_.js',
    savestderr=True)

if normal != ana:
    print "{} failed".format(sys.argv[1])
    print normal
    print ana
else:
    print "{} passed".format('tests/unit/instrument-test.js')
    print normal
    print ana
sj.cd_parent()