about summary refs log tree commit diff stats
path: root/test/expression/modint.py
diff options
context:
space:
mode:
authorserpilliere <devnull@localhost>2014-06-03 10:27:56 +0200
committerserpilliere <devnull@localhost>2014-06-03 10:27:56 +0200
commited5c3668cc9f545b52674ad699fc2b0ed1ccb575 (patch)
tree07faf97d7e4d083173a1f7e1bfd249baed2d74f9 /test/expression/modint.py
parenta183e1ebd525453710306695daa8c410fd0cb2af (diff)
downloadmiasm-ed5c3668cc9f545b52674ad699fc2b0ed1ccb575.tar.gz
miasm-ed5c3668cc9f545b52674ad699fc2b0ed1ccb575.zip
Miasm v2
* API has changed, so old scripts need updates
* See example for API usage
* Use tcc or llvm for jit emulation
* Go to test and run test_all.py to check install

Enjoy !
Diffstat (limited to 'test/expression/modint.py')
-rw-r--r--test/expression/modint.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/test/expression/modint.py b/test/expression/modint.py
new file mode 100644
index 00000000..e7c19d0c
--- /dev/null
+++ b/test/expression/modint.py
@@ -0,0 +1,59 @@
+from miasm2.expression.modint import *
+
+a = uint8(0x42)
+b = uint8(0xFF)
+c = uint8(0x4)
+
+d = uint1(0)
+e = uint1(1)
+
+f = uint8(0x1)
+
+
+print a, b, c
+print a + b, a + c, b + c
+print a == a, a == b, a == 0x42, a == 0x78
+print a != b, a != a
+print d, e
+print d + e, d + d, e + e, e + e + e, e + 0x11
+
+assert(f == 1)
+assert(f + 1 == 2)
+assert(2 == f + 1)
+assert(f + 0xff == 0)
+assert(f & 0 == 0)
+assert(f & 0xff == f)
+assert(0xff & f == f)
+assert(f / 1 == f)
+assert(1 / f == f)
+assert(int(f) == 1)
+assert(long(f) == 1)
+assert(~f == 0xfe)
+assert(f << 1 == 2)
+assert(f << 8 == 0)
+assert(1 << f == 2)
+assert(0x80 << f == 0)
+assert(f % 2 == f)
+assert(f % 1 == 0)
+assert(2 % f == 0)
+assert(f * 2 == 2)
+assert(2 * f == 2)
+assert(f * f == 1)
+assert(f * uint8(0x80) == 0x80)
+assert(-f == 0xff)
+assert(f | f == f)
+assert(f | 0 == f)
+assert(2 | f == 3)
+assert(f >> 0 == f)
+assert(f >> 1 == 0)
+assert(0x10 >> f == 0x8)
+assert(0x100 >> f == 0x80)  # XXXX
+assert(0x1000 >> f == 0x0)  # XXXX
+assert(f ^ f == 0)
+assert(f ^ 0 == f)
+assert(0 ^ f == f)
+assert(1 ^ f == 0)
+
+print e + c, c + e, c - e, e - c
+print 1000 * a
+print hex(a)