Skip to content

Commit

Permalink
test: stack analysis test added
Browse files Browse the repository at this point in the history
  • Loading branch information
joelpx committed May 13, 2016
1 parent ddebdaa commit e33c57e
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ all: check

check:
@python3 test_plasma.py
@cd tests/analyzer && ./run.sh


# Verbose : print the diff at each test
Expand Down
38 changes: 38 additions & 0 deletions tests/analyzer/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/sh

color() {
local color="$1"
if [ "$3" == "" ]; then
local prefix=""
local txt="$2"
else
local prefix="$2 "
local txt="$3"
fi
echo -en "${prefix}\x1b[;${color}m${txt}\x1b[0m"
}

red() {
color 31 "$1" "$2"
}

green() {
color 32 "$1" "$2"
}

echo "analyzer tests..."

ls *.bin | while read file; do
name=`basename $file .bin`
echo -e "py ${name}.py\ndump .text 999\n exit" | \
../../run_plasma.py -i -na -nc ${name}.bin >tmp

diff -q ${name}.rev tmp >/dev/null
if [ $? -eq 0 ]; then
green "$name" "[OK]\n"
else
red "$name" "[FAIL]\n"
fi
done

rm tmp
77 changes: 77 additions & 0 deletions tests/analyzer/stack.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// gcc -nostdlib test.S -e _start

.intel_syntax noprefix
.global main
.global _start

.section .text

.macro ACCESS_VARS
mov rax, [rbp - 4]
mov rax, [rsp - 4 + 16]
.endm

// --------------------------------------------------------
// CALL TESTS
// --------------------------------------------------------

__stdcall:
push rbp
mov rbp, rsp
mov rax, [rbp + 4]
pop rbp
pop rax
pop rax
pop rax
ret

__cdecl:
push rbp
mov rbp, rsp
pop rbp
ret

__jmp_func:
jmp __stdcall

__noreturn:
jmp __noreturn

// --------------------------------------------------------

_start:
call main
call __noreturn
ret

main:
push rbp
mov rbp, rsp
sub rsp, 16

ACCESS_VARS

push rax
push rbx
push rcx
call __stdcall

ACCESS_VARS

push rax
push rbx
push rcx
call __cdecl
add rsp, 8*3

ACCESS_VARS

push rax
push rbx
push rcx
call __jmp_func

ACCESS_VARS

pop rbp
ret
Binary file added tests/analyzer/stack.bin
Binary file not shown.
3 changes: 3 additions & 0 deletions tests/analyzer/stack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env python3
ep = api.entry_point()
api.set_code(ep)
85 changes: 85 additions & 0 deletions tests/analyzer/stack.rev
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
; ---------------------------------------------------------------------
.text 0x4000d4 -> 0x40013f

; ---------------------------------------------------------------------
; SUBROUTINE
; ---------------------------------------------------------------------
__stdcall:

long int var_4 = -0x4

.text 0x4000d4: push rbp
.text 0x4000d5: rbp = rsp
.text 0x4000d8: rax = var_4
.text 0x4000dc: pop rbp
.text 0x4000dd: pop rax
.text 0x4000de: pop rax
.text 0x4000df: pop rax
.text 0x4000e0: ret
; end function __stdcall

; ---------------------------------------------------------------------
; SUBROUTINE
; ---------------------------------------------------------------------
__cdecl:
.text 0x4000e1: push rbp
.text 0x4000e2: rbp = rsp
.text 0x4000e5: pop rbp
.text 0x4000e6: ret
; end function __cdecl

; ---------------------------------------------------------------------
; SUBROUTINE
; ---------------------------------------------------------------------
__jmp_func:
.text 0x4000e7: jmp __stdcall
; end function __jmp_func

; ---------------------------------------------------------------------
; SUBROUTINE
; ---------------------------------------------------------------------
__noreturn__ __noreturn:
.text 0x4000e9: jmp __noreturn
; end function __noreturn

_start:
.text 0x4000eb: call (.text) main
.text 0x4000f0: call (.text) __noreturn

.text 0x4000f5: .db c3

; ---------------------------------------------------------------------
; SUBROUTINE
; ---------------------------------------------------------------------
main:

long int var_c = -0xc

.text 0x4000f6: push rbp
.text 0x4000f7: rbp = rsp
.text 0x4000fa: rsp -= 16
.text 0x4000fe: rax = var_c
.text 0x400102: rax = var_c
.text 0x400107: push rax
.text 0x400108: push rbx
.text 0x400109: push rcx
.text 0x40010a: call (.text) __stdcall
.text 0x40010f: rax = var_c
.text 0x400113: rax = var_c
.text 0x400118: push rax
.text 0x400119: push rbx
.text 0x40011a: push rcx
.text 0x40011b: call (.text) __cdecl
.text 0x400120: rsp += 24
.text 0x400124: rax = var_c
.text 0x400128: rax = var_c
.text 0x40012d: push rax
.text 0x40012e: push rbx
.text 0x40012f: push rcx
.text 0x400130: call (.text) __jmp_func
.text 0x400135: rax = var_c
.text 0x400139: rax = var_c
.text 0x40013e: pop rbp
.text 0x40013f: ret
; end function main

0 comments on commit e33c57e

Please sign in to comment.