Skip to content

Commit e33c57e

Browse files
author
joelpx
committed
test: stack analysis test added
1 parent ddebdaa commit e33c57e

6 files changed

Lines changed: 204 additions & 0 deletions

File tree

‎Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ all: check
2323

2424
check:
2525
@python3 test_plasma.py
26+
@cd tests/analyzer && ./run.sh
2627

2728

2829
# Verbose : print the diff at each test

‎tests/analyzer/run.sh‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/sh
2+
3+
color() {
4+
local color="$1"
5+
if [ "$3" == "" ]; then
6+
local prefix=""
7+
local txt="$2"
8+
else
9+
local prefix="$2 "
10+
local txt="$3"
11+
fi
12+
echo -en "${prefix}\x1b[;${color}m${txt}\x1b[0m"
13+
}
14+
15+
red() {
16+
color 31 "$1" "$2"
17+
}
18+
19+
green() {
20+
color 32 "$1" "$2"
21+
}
22+
23+
echo "analyzer tests..."
24+
25+
ls *.bin | while read file; do
26+
name=`basename $file .bin`
27+
echo -e "py ${name}.py\ndump .text 999\n exit" | \
28+
../../run_plasma.py -i -na -nc ${name}.bin >tmp
29+
30+
diff -q ${name}.rev tmp >/dev/null
31+
if [ $? -eq 0 ]; then
32+
green "$name" "[OK]\n"
33+
else
34+
red "$name" "[FAIL]\n"
35+
fi
36+
done
37+
38+
rm tmp

‎tests/analyzer/stack.S‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// gcc -nostdlib test.S -e _start
2+
3+
.intel_syntax noprefix
4+
.global main
5+
.global _start
6+
7+
.section .text
8+
9+
.macro ACCESS_VARS
10+
mov rax, [rbp - 4]
11+
mov rax, [rsp - 4 + 16]
12+
.endm
13+
14+
// --------------------------------------------------------
15+
// CALL TESTS
16+
// --------------------------------------------------------
17+
18+
__stdcall:
19+
push rbp
20+
mov rbp, rsp
21+
mov rax, [rbp + 4]
22+
pop rbp
23+
pop rax
24+
pop rax
25+
pop rax
26+
ret
27+
28+
__cdecl:
29+
push rbp
30+
mov rbp, rsp
31+
pop rbp
32+
ret
33+
34+
__jmp_func:
35+
jmp __stdcall
36+
37+
__noreturn:
38+
jmp __noreturn
39+
40+
// --------------------------------------------------------
41+
42+
_start:
43+
call main
44+
call __noreturn
45+
ret
46+
47+
main:
48+
push rbp
49+
mov rbp, rsp
50+
sub rsp, 16
51+
52+
ACCESS_VARS
53+
54+
push rax
55+
push rbx
56+
push rcx
57+
call __stdcall
58+
59+
ACCESS_VARS
60+
61+
push rax
62+
push rbx
63+
push rcx
64+
call __cdecl
65+
add rsp, 8*3
66+
67+
ACCESS_VARS
68+
69+
push rax
70+
push rbx
71+
push rcx
72+
call __jmp_func
73+
74+
ACCESS_VARS
75+
76+
pop rbp
77+
ret

‎tests/analyzer/stack.bin‎

1.13 KB
Binary file not shown.

‎tests/analyzer/stack.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env python3
2+
ep = api.entry_point()
3+
api.set_code(ep)

‎tests/analyzer/stack.rev‎

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
; ---------------------------------------------------------------------
2+
.text 0x4000d4 -> 0x40013f
3+
4+
; ---------------------------------------------------------------------
5+
; SUBROUTINE
6+
; ---------------------------------------------------------------------
7+
__stdcall:
8+
9+
long int var_4 = -0x4
10+
11+
.text 0x4000d4: push rbp
12+
.text 0x4000d5: rbp = rsp
13+
.text 0x4000d8: rax = var_4
14+
.text 0x4000dc: pop rbp
15+
.text 0x4000dd: pop rax
16+
.text 0x4000de: pop rax
17+
.text 0x4000df: pop rax
18+
.text 0x4000e0: ret
19+
; end function __stdcall
20+
21+
; ---------------------------------------------------------------------
22+
; SUBROUTINE
23+
; ---------------------------------------------------------------------
24+
__cdecl:
25+
.text 0x4000e1: push rbp
26+
.text 0x4000e2: rbp = rsp
27+
.text 0x4000e5: pop rbp
28+
.text 0x4000e6: ret
29+
; end function __cdecl
30+
31+
; ---------------------------------------------------------------------
32+
; SUBROUTINE
33+
; ---------------------------------------------------------------------
34+
__jmp_func:
35+
.text 0x4000e7: jmp __stdcall
36+
; end function __jmp_func
37+
38+
; ---------------------------------------------------------------------
39+
; SUBROUTINE
40+
; ---------------------------------------------------------------------
41+
__noreturn__ __noreturn:
42+
.text 0x4000e9: jmp __noreturn
43+
; end function __noreturn
44+
45+
_start:
46+
.text 0x4000eb: call (.text) main
47+
.text 0x4000f0: call (.text) __noreturn
48+
49+
.text 0x4000f5: .db c3
50+
51+
; ---------------------------------------------------------------------
52+
; SUBROUTINE
53+
; ---------------------------------------------------------------------
54+
main:
55+
56+
long int var_c = -0xc
57+
58+
.text 0x4000f6: push rbp
59+
.text 0x4000f7: rbp = rsp
60+
.text 0x4000fa: rsp -= 16
61+
.text 0x4000fe: rax = var_c
62+
.text 0x400102: rax = var_c
63+
.text 0x400107: push rax
64+
.text 0x400108: push rbx
65+
.text 0x400109: push rcx
66+
.text 0x40010a: call (.text) __stdcall
67+
.text 0x40010f: rax = var_c
68+
.text 0x400113: rax = var_c
69+
.text 0x400118: push rax
70+
.text 0x400119: push rbx
71+
.text 0x40011a: push rcx
72+
.text 0x40011b: call (.text) __cdecl
73+
.text 0x400120: rsp += 24
74+
.text 0x400124: rax = var_c
75+
.text 0x400128: rax = var_c
76+
.text 0x40012d: push rax
77+
.text 0x40012e: push rbx
78+
.text 0x40012f: push rcx
79+
.text 0x400130: call (.text) __jmp_func
80+
.text 0x400135: rax = var_c
81+
.text 0x400139: rax = var_c
82+
.text 0x40013e: pop rbp
83+
.text 0x40013f: ret
84+
; end function main
85+

0 commit comments

Comments
 (0)