about summary refs log tree commit diff stats
path: root/test/arch/x86/unit/mn_strings.py
blob: 8ca148e576c1c482490c2361fa9c2e493e718e06 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#! /usr/bin/env python2
import sys

from asm_test import Asm_Test_32

class Test_SCAS(Asm_Test_32):
    MYSTRING = "test string"
    TXT = '''
    main:
       LEA EDI, DWORD PTR [mystr]
       XOR  ECX, ECX
       DEC  ECX
       REPNE SCASB
       NOT ECX
       DEC ECX
       RET

    mystr:
    .string "%s"
    ''' % MYSTRING

    def check(self):
        assert(self.myjit.cpu.ECX == len(self.MYSTRING))
        mystr = self.myjit.ir_arch.loc_db.get_name_location('mystr')
        assert(self.myjit.cpu.EDI == self.myjit.ir_arch.loc_db.get_location_offset(mystr) + len(self.MYSTRING)+1)


class Test_MOVS(Asm_Test_32):
    MYSTRING = "test string"
    TXT = '''
    main:
       LEA ESI, DWORD PTR [mystr]
       LEA EDI, DWORD PTR [buffer]
       MOV ECX, %d
       REPE  MOVSB
       RET

    mystr:
    .string "%s"
    buffer:
    .string "%s"
    ''' % (len(MYSTRING), MYSTRING, " "*len(MYSTRING))

    def check(self):
        assert(self.myjit.cpu.ECX == 0)
        buffer = self.myjit.ir_arch.loc_db.get_name_location('buffer')
        assert(self.myjit.cpu.EDI == self.myjit.ir_arch.loc_db.get_location_offset(buffer) + len(self.MYSTRING))
        mystr = self.myjit.ir_arch.loc_db.get_name_location('mystr')
        assert(self.myjit.cpu.ESI == self.myjit.ir_arch.loc_db.get_location_offset(mystr) + len(self.MYSTRING))


if __name__ == "__main__":
    [test(*sys.argv[1:])() for test in [Test_SCAS, Test_MOVS]]