mirror of
https://github.com/radareorg/radare2.git
synced 2025-01-31 18:43:28 +00:00
341 lines
5.9 KiB
Bash
Executable File
341 lines
5.9 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
AS=x86.olly
|
|
|
|
foo() {
|
|
A=$(rasm2 -a ${AS} -b ${BITS} "$1")
|
|
B=$(rasm2 -a x86.nz -b ${BITS} "$1")
|
|
D=$(rasm2 -b ${BITS} -a x86.olly -d "$A" |sed -e 's, ptr,,')
|
|
Q=$(echo "$D" | sed -e 's,dword ,,g' -e 's,\+0x0,,g' -e 's,\+0x4,+4,g' -e s,0x1,1,g -e 's,0x29[A|a],666,g' -e s,0x3,3, -e s,0x8,8, -e 's/,\ /,/' -e s,0x21,33,g -e s,0x2,2,)
|
|
Q2=$(echo "$1" | sed -e 's,dword ,,g' -e 's,\+0x0,,g' -e 's,\+0x4,+4,g' -e s,0x1,1,g -e 's,0x29[A|a],666,g' -e s,0x3,3, -e s,0x8,8, -e 's/,\ /,/' -e s,0x21,33,g -e s,0x2,2,)
|
|
if [ 0 = 1 ]; then
|
|
echo "D=$D"
|
|
echo "Q=$Q"
|
|
echo "Q2=$Q2"
|
|
echo A=rasm2 -a ${AS} -b ${BITS} "$1"
|
|
echo B=rasm2 -a x86.nz -b ${BITS} "$1"
|
|
echo "Q=$Q"
|
|
echo A=$A
|
|
echo B=$B
|
|
echo D=$D
|
|
fi
|
|
if [ "$Q" = "$Q2" ]; then
|
|
B=$A
|
|
#echo "QEQA"
|
|
fi
|
|
if [ "${A}" = "${B}" ]; then
|
|
printf "OK %12s.as %12s.nz %20s = $D\n" "$A" "$B" "$1"
|
|
else
|
|
printf "FAILED %12s.as %12s.nz %20s = $D\n" "$A" "$B" "$1"
|
|
fi
|
|
}
|
|
|
|
BITS=32
|
|
if [ -n "$1" ]; then
|
|
foo "$1"
|
|
exit 0
|
|
fi
|
|
|
|
BITS=64
|
|
foo "shl rdx, 5"
|
|
foo "xor rdx, rdx"
|
|
foo "inc rdx"
|
|
|
|
BITS=32
|
|
foo "shl edx, 5"
|
|
foo "inc edx"
|
|
# some may fail coz shorter length
|
|
foo 'push cs'
|
|
foo 'pop ds'
|
|
foo 'pop fs'
|
|
foo 'pop gs'
|
|
foo 'push fs'
|
|
foo 'push ds'
|
|
exit 1
|
|
foo 'mov eax,[eax+ebx*4+32]' # this is ok on x86.olly, but broken on x86.nz
|
|
foo 'lea eax, [ebp+24]'
|
|
foo 'lea eax, [ebx+24]'
|
|
foo 'lea ebx, [eax+24]'
|
|
foo 'lea ebx, [ebp+324]'
|
|
|
|
AS=x86.olly
|
|
foo 'xchg eax,eax'
|
|
foo 'xchg eax,esp'
|
|
foo 'xchg eax,ebx'
|
|
foo 'xchg ecx,ebp'
|
|
foo 'xchg ecx,ecx'
|
|
foo 'xchg ebx,ecx'
|
|
foo 'xchg ecx,ebx'
|
|
# exit 0
|
|
|
|
if true ; then
|
|
AS=x86.olly
|
|
#foo 'jl patata'
|
|
foo 'jl 0x8049300'
|
|
foo 'jl 0x8048010'
|
|
foo 'jle 0x8049300'
|
|
foo 'jle 0x8048010'
|
|
foo 'jg 0x8049300'
|
|
foo 'jge 0x8049300'
|
|
foo 'jge 0x8048010'
|
|
|
|
foo 'call 0x8049100'
|
|
foo 'jmp 0x8049200'
|
|
echo "UNSIGNED"
|
|
foo 'jb 0x8049300'
|
|
foo 'ja 0x8049300'
|
|
echo "SIGNED"
|
|
foo 'jl 0x8049300'
|
|
foo 'jg 0x8049300'
|
|
|
|
fi
|
|
|
|
AS=x86.olly
|
|
|
|
#BITS=64
|
|
#foo "test rdx, rsi"
|
|
#foo "test rax, rbx"
|
|
BITS=32
|
|
foo "test edx, esi"
|
|
foo "test eax, ebx"
|
|
|
|
|
|
foo "push [ebp+4]"
|
|
foo "push [esp+4]"
|
|
foo "push [ebx+4]"
|
|
foo "push [esi+4]"
|
|
foo "push [eax+8]"
|
|
# exit 0
|
|
|
|
foo "sub dword [eax], 1"
|
|
foo "add dword [eax], 1"
|
|
foo "add dword [ebx], 1"
|
|
foo "add dword [ebp+4], 1"
|
|
foo "add dword [ebp+8], 1"
|
|
|
|
foo "add dword [esp+8], 1"
|
|
foo "add dword [eax+8], 1"
|
|
foo "add eax, 1"
|
|
foo "add dword [ebx+8], 1"
|
|
|
|
#exit
|
|
|
|
foo "sub dword [ebx], 1"
|
|
foo "sub eax, 666"
|
|
foo "sub ebx, 666"
|
|
foo "sub ecx, 666"
|
|
foo "sub eax, 3"
|
|
foo "sub dword [eax], 666"
|
|
foo "sub dword [eax+4], 666"
|
|
|
|
|
|
foo "mov dword [ebp+4], 1"
|
|
foo "mov dword [esp+4], 1"
|
|
foo "sub dword [ebp+4], 1"
|
|
foo "mov dword [ebp+4], 1"
|
|
foo "mov dword [eax+4], 1"
|
|
foo "mov dword ptr [eax+4], 666"
|
|
foo "mov dword ptr [eax], 666"
|
|
|
|
|
|
echo "==> Running 32bit tests..."
|
|
foo "mov dword ptr [eax], 0x6f77206f"
|
|
foo "mov dword ptr [esp], 3"
|
|
foo "mov dword ptr [eax], 3"
|
|
|
|
foo "mov dword ptr [eax+4], 3"
|
|
foo "mov eax, 0x8049000"
|
|
#exit 0
|
|
|
|
foo "mov dword ptr[esi+4], 33"
|
|
foo "mov [eax+eax], eax"
|
|
foo "mov [ebx+eax], eax"
|
|
foo "mov [eax+ecx], eax"
|
|
foo "mov [ebx+eax], eax"
|
|
foo "mov [eax+eax], ebx"
|
|
foo "mov [eax+eax], ecx"
|
|
foo "mov [eax+eax], eax"
|
|
foo "mov [eax+2], ebx"
|
|
foo "mov [ebx+2], ebx"
|
|
|
|
#foo "leal eax, 0x804900"
|
|
foo "mov eax, [esp]"
|
|
foo "mov eax, [ebx]"
|
|
foo "mov eax, [esi]"
|
|
foo "mov eax, [ebp]"
|
|
foo "mov eax, [eax+4]"
|
|
foo "mov eax, [esp+4]"
|
|
foo "mov eax, esp"
|
|
|
|
foo "mov eax, 1"
|
|
foo "mov ebx, 1"
|
|
foo "mov ecx, 1"
|
|
foo "mov eax, [esp]"
|
|
foo "mov dword ptr [ebp+16], 0x6f77206f"
|
|
foo "mov dword ptr [eax+16], 0x6f77206f"
|
|
foo "mov dword ptr [ebp+450], 0x6f77206f"
|
|
foo "mov dword ptr [eax+450], 0x6f77206f"
|
|
#foo "mov [ebp+16], 0x6f77206f"
|
|
#exit 0
|
|
foo "mov [eax], eax"
|
|
foo "mov [ebx], eax"
|
|
foo "mov [eax], ebx"
|
|
foo "mov [eax+4], eax"
|
|
foo "mov [ebp+4], eax"
|
|
foo "mov [ebp+4], ebx"
|
|
foo "mov [ebp+4], ecx"
|
|
foo "mov [eax+4], ecx"
|
|
|
|
foo "mov eax, [eax]"
|
|
foo "mov eax, [ebx]"
|
|
foo "mov ebx, [eax]"
|
|
|
|
foo "mov eax, 3"
|
|
foo "mov ebx, eax"
|
|
foo "mov eax, eax"
|
|
foo "mov eax, ebx"
|
|
|
|
foo "mov [eax], eax"
|
|
foo "mov [eax], ebx"
|
|
foo "mov [ebx], eax"
|
|
foo "mov eax, [ebx]"
|
|
|
|
# XX can be compressed
|
|
# foo "mov [33], eax"
|
|
foo "mov [33], ecx"
|
|
foo "mov [33], edx"
|
|
foo "mov [33], ebx"
|
|
foo "mov [33], esp"
|
|
foo "mov [33], ebp"
|
|
foo "mov [33], esi"
|
|
foo "mov [33], edi"
|
|
|
|
|
|
foo "lea eax, [eax]"
|
|
foo "lea eax, [ecx]"
|
|
foo "lea eax, [esp]"
|
|
foo "lea eax, [eax+4]"
|
|
foo "lea ebx, [eax+4]"
|
|
foo "lea eax, [ebx+4]"
|
|
foo "lea ebx, [ebp]"
|
|
foo "lea eax, [4]"
|
|
foo "lea ebx, [4]"
|
|
|
|
|
|
#BITS=64
|
|
#foo "test rdx, rsi"
|
|
#foo "test rax, rbx"
|
|
BITS=32
|
|
foo "test edx, esi"
|
|
foo "test eax, ebx"
|
|
|
|
if true ; then
|
|
foo "pop [eax]"
|
|
foo "pop [esp]"
|
|
foo "pop [ebp]"
|
|
foo "pop [edi]"
|
|
foo "pop [esi]"
|
|
foo "pop [ecx]"
|
|
|
|
foo "push [eax]"
|
|
foo "push [esp]"
|
|
foo "push [ebp]"
|
|
foo "push [edi]"
|
|
foo "push [esi]"
|
|
foo "push [ecx]"
|
|
foo "pop [eax]"
|
|
foo "push [eax]"
|
|
foo "push [ebp+4]"
|
|
foo "push [eax+8]"
|
|
foo "pop [ebp+4]"
|
|
foo "pop [eax+4]"
|
|
fi
|
|
|
|
if true ; then
|
|
# foo "call 0x804800";
|
|
foo "jmp ecx"
|
|
foo "call ebx"
|
|
foo "ret"
|
|
|
|
foo "xor eax,eax"
|
|
foo "xor ebx,eax"
|
|
foo "xor eax,ebx"
|
|
foo "xor esp,esp"
|
|
foo "xor esi,ebp"
|
|
|
|
foo "add eax, 3"
|
|
foo "sub ebx, 3"
|
|
foo "sub ebx, -3"
|
|
|
|
foo "sub eax, ebx"
|
|
foo "sub eax, eax"
|
|
foo "sub ebx, eax"
|
|
|
|
foo "add [eax], eax"
|
|
foo "sub [ebx], eax"
|
|
foo "sub [ebx], eax"
|
|
foo "add [eax], eax"
|
|
|
|
foo "xor [eax], eax"
|
|
|
|
foo "inc eax"
|
|
foo "inc esi"
|
|
foo "dec esi"
|
|
foo "dec eax"
|
|
|
|
|
|
foo "sub esi,-334"
|
|
foo "add esi,-334"
|
|
|
|
|
|
foo "cmp eax, ebx"
|
|
foo "cmp eax, 33"
|
|
foo "cmp ebx, eax"
|
|
foo "cmp edx, esi"
|
|
foo "test edx, esi"
|
|
foo "test eax, ebx"
|
|
fi
|
|
|
|
exit 0
|
|
# olly doesnt supports 64bits
|
|
|
|
AS=x86.as
|
|
|
|
# 64 bit tests #
|
|
# ============ #
|
|
BITS=64
|
|
echo "==> Running 64bit tests..."
|
|
|
|
if true ; then
|
|
foo "mov eax, [esi]"
|
|
foo "test rcx, rcx"
|
|
foo "mov rax, 3"
|
|
foo "mov rbx, 3"
|
|
foo "mov rbx, rax"
|
|
foo "mov rsi, rbx"
|
|
foo "mov [rsi], rbx"
|
|
|
|
foo "xor rax, rax"
|
|
foo "xor [rax], rax"
|
|
foo "xor [rsi], rbx"
|
|
|
|
foo "call rbx"
|
|
foo "jmp rbx"
|
|
foo "ret"
|
|
foo "syscall"
|
|
foo "pop rax"
|
|
foo "mov rax, 33"
|
|
foo "add rax, rcx"
|
|
foo "add rax, 44"
|
|
foo "sub rax, rbx"
|
|
foo "sub rax, 44"
|
|
|
|
foo "cmp rax, rbx"
|
|
foo "cmp rax, 33"
|
|
foo "cmp rbx, rax"
|
|
foo "cmp rdx, rsi"
|
|
foo "test rdx, rsi"
|
|
foo "test rax, rbx"
|
|
foo "mov dword [ebp-12], 1"
|
|
fi
|