Initial commit
This commit is contained in:
31
tests/common.sh
Normal file
31
tests/common.sh
Normal file
@@ -0,0 +1,31 @@
|
||||
|
||||
driver=$1
|
||||
bits=$2
|
||||
failed=0
|
||||
total=0
|
||||
|
||||
decode() {
|
||||
output=$($driver $1)
|
||||
result=$?
|
||||
total=$((total+1))
|
||||
if [ $result -ne 0 ] || [ "$output" != "$2" ]
|
||||
then
|
||||
failed=$((failed+1))
|
||||
echo "FAIL: decode $@"
|
||||
echo "======================================="
|
||||
echo "$output"
|
||||
echo "======================================="
|
||||
fi
|
||||
}
|
||||
decode32() { if [ $bits = 32 ]; then decode "$@"; fi }
|
||||
decode64() { if [ $bits = 64 ]; then decode "$@"; fi }
|
||||
|
||||
. $3
|
||||
|
||||
if [ $failed -ne 0 ]
|
||||
then
|
||||
echo "FAILED: ${failed}/${total} cases"
|
||||
exit 1
|
||||
else
|
||||
echo "PASS: ${total} cases passed"
|
||||
fi
|
||||
9
tests/decode-enter.sh
Normal file
9
tests/decode-enter.sh
Normal file
@@ -0,0 +1,9 @@
|
||||
decode 66c8000000 "[ENTER_2 IMM4:0x0]"
|
||||
decode 66c8000f00 "[ENTER_2 IMM4:0xf00]"
|
||||
decode 66c8000001 "[ENTER_2 IMM4:0x10000]"
|
||||
decode32 c8000000 "[ENTER_4 IMM4:0x0]"
|
||||
decode32 c8000f00 "[ENTER_4 IMM4:0xf00]"
|
||||
decode32 c8000001 "[ENTER_4 IMM4:0x10000]"
|
||||
decode64 c8000000 "[ENTER_8 IMM4:0x0]"
|
||||
decode64 c8000f00 "[ENTER_8 IMM4:0xf00]"
|
||||
decode64 c8000001 "[ENTER_8 IMM4:0x10000]"
|
||||
2
tests/decode-imul.sh
Normal file
2
tests/decode-imul.sh
Normal file
@@ -0,0 +1,2 @@
|
||||
decode 69C708010000 "[IMUL3 REG4:0 REG4:7 IMM4:0x108]"
|
||||
decode 6BC708 "[IMUL3 REG4:0 REG4:7 IMM4:0x8]"
|
||||
12
tests/decode-inc.sh
Normal file
12
tests/decode-inc.sh
Normal file
@@ -0,0 +1,12 @@
|
||||
decode32 40 "[INC REG4:0]"
|
||||
decode32 43 "[INC REG4:3]"
|
||||
decode32 6647 "[INC REG2:7]"
|
||||
decode fec0 "[INC REG1:0]"
|
||||
decode fec4 "[INC REG1:4]"
|
||||
decode ffc0 "[INC REG4:0]"
|
||||
decode ffc4 "[INC REG4:4]"
|
||||
decode 66ffc0 "[INC REG2:0]"
|
||||
decode 66ffc4 "[INC REG2:4]"
|
||||
decode64 48ffc0 "[INC REG8:0]"
|
||||
decode64 48ffc4 "[INC REG8:4]"
|
||||
decode64 49ffc7 "[INC REG8:15]"
|
||||
5
tests/decode-movsx.sh
Normal file
5
tests/decode-movsx.sh
Normal file
@@ -0,0 +1,5 @@
|
||||
decode 660fbec2 "[MOVSX REG2:0 REG1:2]"
|
||||
decode 0fbec2 "[MOVSX REG4:0 REG1:2]"
|
||||
decode 0fbfc2 "[MOVSX REG4:0 REG2:2]"
|
||||
decode64 480fbfc2 "[MOVSX REG8:0 REG2:2]"
|
||||
decode64 4863c2 "[MOVSX REG8:0 REG4:2]"
|
||||
12
tests/decode-ret.sh
Normal file
12
tests/decode-ret.sh
Normal file
@@ -0,0 +1,12 @@
|
||||
decode 66c3 "[RET_2]"
|
||||
decode 66c20000 "[RET_IMM_2 IMM2:0x0]"
|
||||
decode 66c20d00 "[RET_IMM_2 IMM2:0xd]"
|
||||
decode 66c20dff "[RET_IMM_2 IMM2:0xff0d]"
|
||||
decode32 c3 "[RET_4]"
|
||||
decode32 c20000 "[RET_IMM_4 IMM2:0x0]"
|
||||
decode32 c20d00 "[RET_IMM_4 IMM2:0xd]"
|
||||
decode32 c20dff "[RET_IMM_4 IMM2:0xff0d]"
|
||||
decode64 c3 "[RET_8]"
|
||||
decode64 c20000 "[RET_IMM_8 IMM2:0x0]"
|
||||
decode64 c20d00 "[RET_IMM_8 IMM2:0xd]"
|
||||
decode64 c20dff "[RET_IMM_8 IMM2:0xff0d]"
|
||||
1
tests/decode-sse-movq.sh
Normal file
1
tests/decode-sse-movq.sh
Normal file
@@ -0,0 +1 @@
|
||||
decode f30f7e5c2408 "[SSE_MOVQ_X2X REG8:3 MEM8:4:0x8]"
|
||||
1
tests/decode-sse-shufpd.sh
Normal file
1
tests/decode-sse-shufpd.sh
Normal file
@@ -0,0 +1 @@
|
||||
decode 660fc6c001 "[SSE_SHUFPD REG16:0 REG16:0 IMM1:0x1]"
|
||||
72
tests/driver.c
Normal file
72
tests/driver.c
Normal file
@@ -0,0 +1,72 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include <decode.h>
|
||||
|
||||
|
||||
static
|
||||
uint8_t
|
||||
parse_nibble(const char nibble)
|
||||
{
|
||||
if (nibble >= '0' && nibble <= '9')
|
||||
{
|
||||
return nibble - '0';
|
||||
}
|
||||
else if (nibble >= 'a' && nibble <= 'f')
|
||||
{
|
||||
return nibble - 'a' + 10;
|
||||
}
|
||||
else if (nibble >= 'A' && nibble <= 'F')
|
||||
{
|
||||
return nibble - 'A' + 10;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Invalid hexadecimal number: %x\n", nibble);
|
||||
exit(1);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
if (argc != 2)
|
||||
{
|
||||
printf("usage: %s [instruction bytes]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
void* code = mmap((void*) 0x1238000, 0x2000, PROT_READ|PROT_WRITE,
|
||||
MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED, -1, 0);
|
||||
|
||||
uint8_t* current_code = code;
|
||||
char* hex = argv[1];
|
||||
for (; *hex && *(hex + 1); hex += 2, current_code++)
|
||||
{
|
||||
*current_code = (parse_nibble(hex[0]) << 4) | parse_nibble(hex[1]);
|
||||
}
|
||||
|
||||
size_t length = (size_t) current_code - (size_t) code;
|
||||
|
||||
Instr instr;
|
||||
int result = decode(code, length, &instr);
|
||||
if (result < 0)
|
||||
{
|
||||
puts("Decode failed.");
|
||||
return -1;
|
||||
}
|
||||
else if ((size_t) result != length)
|
||||
{
|
||||
printf("Decode used %u bytes, not %u.\n", (unsigned int) result, (unsigned int) length);
|
||||
return -1;
|
||||
}
|
||||
|
||||
char buffer[128];
|
||||
instr_format(&instr, buffer);
|
||||
puts(buffer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
22
tests/meson.build
Normal file
22
tests/meson.build
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
sh = find_program('sh')
|
||||
|
||||
cases = [
|
||||
['enter', 'decode-enter.sh'],
|
||||
['imul', 'decode-imul.sh'],
|
||||
['inc', 'decode-inc.sh'],
|
||||
['movsx', 'decode-movsx.sh'],
|
||||
['ret', 'decode-ret.sh'],
|
||||
|
||||
['sse-shufpd', 'decode-sse-shufpd.sh'],
|
||||
['sse-movq', 'decode-sse-movq.sh'],
|
||||
]
|
||||
|
||||
test_driver = executable('test_driver', 'driver.c',
|
||||
dependencies: libx86decode,
|
||||
c_args: ['-D_GNU_SOURCE'])
|
||||
test_args = files('common.sh') + [test_driver.full_path(), '@0@'.format(pointer_size * 8)]
|
||||
|
||||
foreach case : cases
|
||||
test(case[0], sh, args: test_args + files(case[1]))
|
||||
endforeach
|
||||
Reference in New Issue
Block a user