<commit_before>#!/usr/bin/python env
'''This module contains symbolic implementations of VEX operations.'''

import z3
import re
import sys
import s_irexpr

import logging
l = logging.getLogger("s_irop")
#l.setLevel(logging.DEBUG)

##########################
### Generic operations ###
##########################

def generic_Sub(args, size, state):
	#l.debug("OP: %s - %s" % (args[0], args[1]))
	#l.debug("Sizes: %s, %s = %s", args[0].size(), args[1].size(), (args[0] - args[1]).size())
	return args[0] - args[1]

def generic_Add(args, size, state):
	#l.debug("OP: %s - %s" % (args[0], args[1]))
	return args[0] + args[1]

def generic_Xor(args, size, state):
	return args[0] ^ args[1]

def generic_And(args, size, state):
	return args[0] & args[1]

def generic_Shl(args, size, state):
	return args[0] << z3.ZeroExt(args[0].size() - args[1].size(), args[1])

def generic_Shr(args, size, state):
	return z3.LShR(args[0], z3.ZeroExt(args[0].size() - args[1].size(), args[1]))

def generic_MullS(args, size, state):
	# TODO: not sure if this should be extended *before* or *after* multiplication
	return z3.SignExt(size, args[0] * args[1])

def generic_Sar(args, size, state):
	return args[0] >> z3.ZeroExt(args[0].size() - args[1].size(), args[1])

def generic_CmpEQ(args, size, state):
	print "WTF"
	return z3.If(args[0] == args[1], z3.BitVecVal(1, 1), z3.BitVecVal(0, 1))

def generic_narrow(args, from_size, to_size, part, state):
	if part == "":
		to_start = 0
	elif part == "HI":
		to_start = from_size / 2

	n = z3.Extract(to_start + to_size - 1, to_start, args[0])
	l.debug("Narrowed expression: %s" % n)
	return n

def generic_widen(args, from_size, to_size, signed, state):
	if signed == "U":
		return z3.ZeroExt(to_size - from_size, args[0])
	elif signed == "S":
		return z3.SignExt(to_size - from_size, args[0])

def generic_concat(args, state):
	return z3.Concat(args)

###########################
### Specific operations ###
###########################

op_handlers = { }

##################<commit_msg>wtf tracked down :-)<commit_after>#!/usr/bin/python env
'''This module contains symbolic implementations of VEX operations.'''

import z3
import re
import sys
import s_irexpr

import logging
l = logging.getLogger("s_irop")
#l.setLevel(logging.DEBUG)

##########################
### Generic operations ###
##########################

def generic_Sub(args, size, state):
	#l.debug("OP: %s - %s" % (args[0], args[1]))
	#l.debug("Sizes: %s, %s = %s", args[0].size(), args[1].size(), (args[0] - args[1]).size())
	return args[0] - args[1]

def generic_Add(args, size, state):
	#l.debug("OP: %s - %s" % (args[0], args[1]))
	return args[0] + args[1]

def generic_Xor(args, size, state):
	return args[0] ^ args[1]

def generic_And(args, size, state):
	return args[0] & args[1]

def generic_Shl(args, size, state):
	return args[0] << z3.ZeroExt(args[0].size() - args[1].size(), args[1])

def generic_Shr(args, size, state):
	return z3.LShR(args[0], z3.ZeroExt(args[0].size() - args[1].size(), args[1]))

def generic_MullS(args, size, state):
	# TODO: not sure if this should be extended *before* or *after* multiplication
	return z3.SignExt(size, args[0] * args[1])

def generic_Sar(args, size, state):
	return args[0] >> z3.ZeroExt(args[0].size() - args[1].size(), args[1])

def generic_CmpEQ(args, size, state):
	return z3.If(args[0] == args[1], z3.BitVecVal(1, 1), z3.BitVecVal(0, 1))

def generic_narrow(args, from_size, to_size, part, state):
	if part == "":
		to_start = 0
	elif part == "HI":
		to_start = from_size / 2

	n = z3.Extract(to_start + to_size - 1, to_start, args[0])
	l.debug("Narrowed expression: %s" % n)
	return n

def generic_widen(args, from_size, to_size, signed, state):
	if signed == "U":
		return z3.ZeroExt(to_size - from_size, args[0])
	elif signed == "S":
		return z3.SignExt(to_size - from_size, args[0])

def generic_concat(args, state):
	return z3.Concat(args)

###########################
### Specific operations ###
###########################

op_handlers = { }

##################
{'fraction_non_alphanumeric': 0.23794132272501242, 'fraction_numerical': 0.02734957732471407, 'mean_word_length': 5.208333333333333, 'pattern_counts': {'":': 8, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4113302', 'n_tokens_mistral': 1570, 'n_tokens_neox': 1547, 'n_words': 375}