def test_uptr_bytestore_load(): fn, _ = fncptr_from_c_script("test_uptr_bytestore_load.c", "test_fnc", argtypes=[ctypes.POINTER(ctypes.c_uint32)], restype=ctypes.c_uint32) # allocate memory through ctypes ui32 = ctypes.c_uint32() assert fn(ctypes.byref(ui32)) == 0x8d9f9c1d assert ui32.value == 0x8d9f9c1d
def test_getvarpartiref_nofix(): Arr = ctypes.ARRAY(ctypes.c_uint32, 3) fn, _ = fncptr_from_c_script("test_getvarpartiref_nofix.c", "test_fnc", argtypes=[ctypes.POINTER(Arr)], restype=ctypes.c_uint32) arr = Arr() arr[0] = 0xcafebabe arr[1] = 0xbecca arr[2] = 0xfaebee res = fn(ctypes.byref(arr)) assert res == 0xcafebabe, "result: %s" % hex(res)
def test_getelemiref(): Arr = ctypes.ARRAY(ctypes.c_int64, 5) fn, _ = fncptr_from_c_script("test_getelemiref.c", "test_fnc", argtypes=[ctypes.POINTER(Arr)], restype=ctypes.c_int64) arr = Arr() arr[0] = -23 arr[1] = 35 arr[2] = 42 arr[3] = 0 arr[4] = 152 res = fn(ctypes.byref(arr), 2) assert res == 42, "result: %d" % res
def test_getvarpartiref(): class Stt(ctypes.Structure): _fields_ = [('ui8', ctypes.c_uint8), ('ui64', ctypes.c_uint64), ('ui32s', ctypes.ARRAY(ctypes.c_uint32, 5))] fn, _ = fncptr_from_c_script("test_getvarpartiref.c", "test_fnc", argtypes=[ctypes.POINTER(Stt)], restype=ctypes.c_uint32) stt = Stt() stt.ui8 = 25 stt.ui64 = 0xabcdef0123456789 stt.ui32s[0] = 0xcafebabe res = fn(ctypes.byref(stt)) assert res == 0xcafebabe, "result: %s" % hex(res)
def test_double_div(): fnp, _ = fncptr_from_c_script("test_double_div.c", "test_fnc", restype=ctypes.c_double) assert within_err(fnp(), 1.1557282546316052)
def test_double_sub(): fnp, _ = fncptr_from_c_script("test_double_sub.c", "test_fnc", restype=ctypes.c_double) assert within_err(fnp(), 0.423313)
def test_double_mul(): fnp, _ = fncptr_from_c_script("test_double_mul.c", "test_fnc", restype=ctypes.c_double) assert fnp() == 8.53972942004
def test_xor(): fn, _ = fncptr_from_c_script("test_xor.c", "test_fnc", restype=ctypes.c_uint64) assert fn() == 0x58376ec3e83fa0e1
def test_double_add(): fnp, _ = fncptr_from_c_script("test_double_add.c", "test_fnc", restype=ctypes.c_double) assert fnp() == 5.859873
def test_constant_function(): fn, _ = fncptr_from_c_script("test_constfunc.c", 'test_fnc') assert fn() == 0
def test_and(): fn, _ = fncptr_from_c_script("test_and.c", "test_fnc", restype=ctypes.c_uint64) assert fn() == 0x8588901c10004b14
def test_srem(): fn, _ = fncptr_from_c_script("test_srem.c", "test_fnc", restype=ctypes.c_uint8) assert fn() == 0xff # -1
def test_factorial(): fn, _ = fncptr_from_c_script("test_fac.c", "fac", [ctypes.c_ulonglong]) assert fn(20) == 2432902008176640000
def test_commoninst_pin(): mu = mu_instance_via_ctyeps() fnp, _ = fncptr_from_c_script("test_commoninst_pin.c", 'test_pin') assert fnp() == 6
def test_shl(): fn, _ = fncptr_from_c_script("test_shl.c", "test_fnc", restype=ctypes.c_uint64) assert fn() == 0x7e707560c92d5400
def test_select(): fnp, _ = fncptr_from_c_script('test_select.c', 'test_fnc', [ctypes.c_byte]) assert fnp(0) == 20 assert fnp(1) == 10
def test_zext(): fn, _ = fncptr_from_c_script("test_zext.c", "test_fnc") assert fn() == 0x00000000a8324b55
def test_trunc(): fn, _ = fncptr_from_c_script("test_trunc.c", "test_fnc", restype=ctypes.c_uint32) assert fn() == 0x58324b55
def test_double_ordered_gt(): fnp, _ = fncptr_from_c_script("test_double_ordered_gt.c", "test_fnc") assert fnp() == 1
def test_multifunc(): fn, _ = fncptr_from_c_script("test_multifunc.c", "entry") assert fn() == 6765
def test_double_arg_pass(): fnp, _ = fncptr_from_c_script("test_double_arg_pass.c", "test_fnc", [ctypes.c_double, ctypes.c_double], ctypes.c_double) assert fnp(3.141593, 2.71828) == 5.859873
def test_ne_ref(): mu = mu_instance_via_ctyeps() fn, _ = fncptr_from_c_script("test_ne_ref.c", "test_fnc") assert fn() == 1
def test_milsum(): fn, _ = fncptr_from_c_script("test_milsum.c", "milsum", [ctypes.c_ulonglong]) assert fn(1000000) == 500000500000
def test_lshr(): fn, _ = fncptr_from_c_script("test_lshr.c", "test_fnc", restype=ctypes.c_uint64) assert fn() == 0x2367e707560c92
def test_fibonacci(): fn, _ = fncptr_from_c_script("test_fib.c", "fib", [ctypes.c_ulonglong]) assert fn(20) == 6765
def test_double_uitofp(): fnp, _ = fncptr_from_c_script("test_double_uitofp.c", "test_fnc", restype=ctypes.c_double) assert fnp() == 42.0
def test_ne_int(): fn, _ = fncptr_from_c_script("test_ne_int.c", "test_fnc") assert fn() == 1
def test_double_fptoui(): fnp, _ = fncptr_from_c_script("test_double_fptoui.c", "test_fnc", restype=ctypes.c_uint64) assert fnp() == 3
def test_ult(): fn, _ = fncptr_from_c_script("test_ult.c", "test_fnc", restype=ctypes.c_uint8) assert fn() == 0
def test_or(): fn, _ = fncptr_from_c_script("test_or.c", "test_fnc", restype=ctypes.c_uint64) assert fn() == 0xddbffedff83febf5