Skip to content
Snippets Groups Projects
Commit cac15f9a authored by Nguyen Anh Quynh's avatar Nguyen Anh Quynh
Browse files

Merge pull request #38 from iksteen/refactor-x64-label-tests

Split x64_rip_rel_abs.py into 3 separate unit tests.
parents 47d586b2 e2a1fcd4
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/python
# Ingmar Steen, 2016
# This is to test label addressing on X86_64
# Github issue: #34
# Author: Ingmar Steen
from keystone import *
import regress
class TestX64NasmLabel(regress.RegressTest):
def runTest(self):
# Initialize Keystone engine
ks = Ks(KS_ARCH_X86, KS_MODE_64)
# change the syntax to NASM
ks.syntax = KS_OPT_SYNTAX_NASM
# nasm uses abs for explicit absolute addressing
encoding, count = ks.asm(b"lea rax, [__data]\n__data:")
self.assertEqual(encoding, [ 0x48, 0x8d, 0x04, 0x25, 0x08, 0x00, 0x00, 0x00 ])
# verify that explicit absolute addressing is indeed absolute
encoding, count = ks.asm(b"nop\nnop\nlea rax, [__data]\n__data:")
self.assertEqual(encoding, [ 0x90, 0x90, 0x48, 0x8d, 0x04, 0x25, 0x0a, 0x00, 0x00, 0x00 ])
class TestX64AttLabel(regress.RegressTest):
def runTest(self):
# Initialize Keystone engine
ks = Ks(KS_ARCH_X86, KS_MODE_64)
# change the syntax to AT&T
ks.syntax = KS_OPT_SYNTAX_ATT
# nasm uses abs for explicit absolute addressing
encoding, count = ks.asm(b"lea __data, %rax\n__data:")
self.assertEqual(encoding, [ 0x48, 0x8d, 0x04, 0x25, 0x08, 0x00, 0x00, 0x00 ])
# verify that explicit absolute addressing is indeed absolute
encoding, count = ks.asm(b"nop\nnop\nlea __data, %rax\n__data:")
self.assertEqual(encoding, [ 0x90, 0x90, 0x48, 0x8d, 0x04, 0x25, 0x0a, 0x00, 0x00, 0x00 ])
class TestX64IntelLabel(regress.RegressTest):
def runTest(self):
# Initialize Keystone engine
ks = Ks(KS_ARCH_X86, KS_MODE_64)
# change the syntax to intel
ks.syntax = KS_OPT_SYNTAX_INTEL
# nasm uses abs for explicit absolute addressing
encoding, count = ks.asm(b"lea rax, [__data]\n__data:")
self.assertEqual(encoding, [ 0x48, 0x8d, 0x04, 0x25, 0x08, 0x00, 0x00, 0x00 ])
# verify that explicit absolute addressing is indeed absolute
encoding, count = ks.asm(b"nop\nnop\nlea rax, [__data]\n__data:")
self.assertEqual(encoding, [ 0x90, 0x90, 0x48, 0x8d, 0x04, 0x25, 0x0a, 0x00, 0x00, 0x00 ])
if __name__ == '__main__':
regress.main()
#!/usr/bin/python
# Ingmar Steen, 2016
# This is to test nasm syntax' explicit abs addressing
# Github issue: #32
# Author: Ingmar Steen
from keystone import *
import regress
class TestX64NasmLabelAbs(regress.RegressTest):
def runTest(self):
# Initialize Keystone engine
ks = Ks(KS_ARCH_X86, KS_MODE_64)
# change the syntax to NASM
ks.syntax = KS_OPT_SYNTAX_NASM
# nasm uses abs for explicit absolute addressing
encoding, count = ks.asm(b"lea rax, [abs __data]\n__data:")
self.assertEqual(encoding, [ 0x48, 0x8d, 0x04, 0x25, 0x08, 0x00, 0x00, 0x00 ])
# verify that explicit absolute addressing is indeed absolute
encoding, count = ks.asm(b"nop\nnop\nlea rax, [abs __data]\n__data:")
self.assertEqual(encoding, [ 0x90, 0x90, 0x48, 0x8d, 0x04, 0x25, 0x0a, 0x00, 0x00, 0x00 ])
if __name__ == '__main__':
regress.main()
#!/usr/bin/python
# Ingmar Steen, 2016
# This is to test RIP relative and absolute addressing
# This is to test RIP relative and absolute addressing using all
# available syntaxes.
# Github issue: #32
# Author: Ingmar Steen
......@@ -11,7 +12,7 @@ from keystone import *
import regress
class TestX64NasmRel(regress.RegressTest):
class TestX64NasmLabelRel(regress.RegressTest):
def runTest(self):
# Initialize Keystone engine
ks = Ks(KS_ARCH_X86, KS_MODE_64)
......@@ -27,23 +28,7 @@ class TestX64NasmRel(regress.RegressTest):
self.assertEqual(encoding, [ 0x90, 0x90, 0x48, 0x8d, 0x05, 0x00, 0x00, 0x00, 0x00 ])
class TestX64NasmAbs(regress.RegressTest):
def runTest(self):
# Initialize Keystone engine
ks = Ks(KS_ARCH_X86, KS_MODE_64)
# change the syntax to NASM
ks.syntax = KS_OPT_SYNTAX_NASM
# nasm uses abs for explicit absolute addressing
encoding, count = ks.asm(b"lea rax, [abs __data]\n__data:")
self.assertEqual(encoding, [ 0x48, 0x8d, 0x04, 0x25, 0x08, 0x00, 0x00, 0x00 ])
# verify that explicit absolute addressing is indeed absolute
encoding, count = ks.asm(b"nop\nnop\nlea rax, [abs __data]\n__data:")
self.assertEqual(encoding, [ 0x90, 0x90, 0x48, 0x8d, 0x04, 0x25, 0x0a, 0x00, 0x00, 0x00 ])
class TestX64AttRel(regress.RegressTest):
class TestX64AttLabelRel(regress.RegressTest):
def runTest(self):
# Initialize Keystone engine
ks = Ks(KS_ARCH_X86, KS_MODE_64)
......@@ -59,30 +44,14 @@ class TestX64AttRel(regress.RegressTest):
self.assertEqual(encoding, [ 0x90, 0x90, 0x48, 0x8d, 0x05, 0x00, 0x00, 0x00, 0x00 ])
class TestX64AttAbs(regress.RegressTest):
def runTest(self):
# Initialize Keystone engine
ks = Ks(KS_ARCH_X86, KS_MODE_64)
# change the syntax to AT&T
ks.syntax = KS_OPT_SYNTAX_ATT
# nasm uses abs for explicit absolute addressing
encoding, count = ks.asm(b"lea __data, %rax\n__data:")
self.assertEqual(encoding, [ 0x48, 0x8d, 0x04, 0x25, 0x08, 0x00, 0x00, 0x00 ])
# verify that explicit absolute addressing is indeed absolute
encoding, count = ks.asm(b"nop\nnop\nlea __data, %rax\n__data:")
self.assertEqual(encoding, [ 0x90, 0x90, 0x48, 0x8d, 0x04, 0x25, 0x0a, 0x00, 0x00, 0x00 ])
class TestX64IntelRel(regress.RegressTest):
class TestX64IntelLabelRel(regress.RegressTest):
def runTest(self):
# Initialize Keystone engine
ks = Ks(KS_ARCH_X86, KS_MODE_64)
# change the syntax to intel
ks.syntax = KS_OPT_SYNTAX_INTEL
# nasm uses rel for rip relative addressing
# intel uses rip + label for rip relative addressing
encoding, count = ks.asm(b"lea rax, [rip + __data]\n__data:")
self.assertEqual(encoding, [ 0x48, 0x8d, 0x05, 0x00, 0x00, 0x00, 0x00 ])
......@@ -91,21 +60,5 @@ class TestX64IntelRel(regress.RegressTest):
self.assertEqual(encoding, [ 0x90, 0x90, 0x48, 0x8d, 0x05, 0x00, 0x00, 0x00, 0x00 ])
class TestX64IntelAbs(regress.RegressTest):
def runTest(self):
# Initialize Keystone engine
ks = Ks(KS_ARCH_X86, KS_MODE_64)
# change the syntax to intel
ks.syntax = KS_OPT_SYNTAX_INTEL
# nasm uses abs for explicit absolute addressing
encoding, count = ks.asm(b"lea rax, [__data]\n__data:")
self.assertEqual(encoding, [ 0x48, 0x8d, 0x04, 0x25, 0x08, 0x00, 0x00, 0x00 ])
# verify that explicit absolute addressing is indeed absolute
encoding, count = ks.asm(b"nop\nnop\nlea rax, [__data]\n__data:")
self.assertEqual(encoding, [ 0x90, 0x90, 0x48, 0x8d, 0x04, 0x25, 0x0a, 0x00, 0x00, 0x00 ])
if __name__ == '__main__':
regress.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment