* Fixed bug in Thumb2 pop caused by me incorrectly assuming that
ARM_SP == 13, ARM_LR == 14, and ARM_PC == 15, which is not the case * updated CMakeLists to include building arm regression test * added explicit casts for 64 bit visual studio 2012 build to get around truncation warnings from size_t conversion
This commit is contained in:
parent
11f8e7c596
commit
d91f964d40
|
@ -182,10 +182,16 @@ endif ()
|
||||||
|
|
||||||
if (CAPSTONE_BUILD_TESTS)
|
if (CAPSTONE_BUILD_TESTS)
|
||||||
foreach (TSRC ${TEST_SOURCES})
|
foreach (TSRC ${TEST_SOURCES})
|
||||||
STRING(REGEX REPLACE ".c$" "" TBIN ${TSRC})
|
STRING(REGEX REPLACE ".c$" "" TBIN ${TSRC})
|
||||||
add_executable(${TBIN} "tests/${TSRC}")
|
add_executable(${TBIN} "tests/${TSRC}")
|
||||||
target_link_libraries(${TBIN} ${default-target})
|
target_link_libraries(${TBIN} ${default-target})
|
||||||
endforeach ()
|
endforeach ()
|
||||||
|
if (CAPSTONE_ARM_SUPPORT)
|
||||||
|
set(ARM_REGRESS_TEST test_arm_regression.c)
|
||||||
|
STRING(REGEX REPLACE ".c$" "" ARM_REGRESS_BIN ${ARM_REGRESS_TEST})
|
||||||
|
add_executable(${ARM_REGRESS_BIN} "suite/arm/${ARM_REGRESS_TEST}")
|
||||||
|
target_link_libraries(${ARM_REGRESS_BIN} ${default-target})
|
||||||
|
endif()
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
## installation
|
## installation
|
||||||
|
|
|
@ -24,7 +24,7 @@ void SStream_Init(SStream *ss)
|
||||||
void SStream_concat0(SStream *ss, char *s)
|
void SStream_concat0(SStream *ss, char *s)
|
||||||
{
|
{
|
||||||
#ifndef CAPSTONE_DIET
|
#ifndef CAPSTONE_DIET
|
||||||
unsigned int len = strlen(s);
|
unsigned int len = (unsigned int) strlen(s);
|
||||||
|
|
||||||
memcpy(ss->buffer + ss->index, s, len);
|
memcpy(ss->buffer + ss->index, s, len);
|
||||||
ss->index += len;
|
ss->index += len;
|
||||||
|
|
|
@ -1272,8 +1272,7 @@ static DecodeStatus DecodeRegListOperand(MCInst *Inst, unsigned Val,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opcode == ARM_t2LDMIA_UPD && WritebackReg == ARM_SP) {
|
if (opcode == ARM_t2LDMIA_UPD && WritebackReg == ARM_SP) {
|
||||||
if (Val & (1 << ARM_SP)
|
if (Val & (1 << 13) || ((Val & (1 << 15)) && (Val & (1 << 14)))) {
|
||||||
|| ((Val & (1 << ARM_PC)) && (Val & (1 << ARM_LR)))) {
|
|
||||||
// invalid thumb2 pop
|
// invalid thumb2 pop
|
||||||
// needs no sp in reglist and not both pc and lr set at the same time
|
// needs no sp in reglist and not both pc and lr set at the same time
|
||||||
return MCDisassembler_Fail;
|
return MCDisassembler_Fail;
|
||||||
|
|
2
cs.c
2
cs.c
|
@ -437,7 +437,7 @@ size_t cs_disasm(csh ud, const uint8_t *buffer, size_t size, uint64_t offset, si
|
||||||
|
|
||||||
#ifdef CAPSTONE_USE_SYS_DYN_MEM
|
#ifdef CAPSTONE_USE_SYS_DYN_MEM
|
||||||
if (count > 0 && count <= INSN_CACHE_SIZE)
|
if (count > 0 && count <= INSN_CACHE_SIZE)
|
||||||
cache_size = count;
|
cache_size = (unsigned int) count;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// save the original offset for SKIPDATA
|
// save the original offset for SKIPDATA
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#if defined(_MSC_VER) && _MSC_VER < 1700
|
#if defined(_MSC_VER) && _MSC_VER <= 1700
|
||||||
#include "msvc/headers/inttypes.h"
|
#include "msvc/headers/inttypes.h"
|
||||||
#else
|
#else
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "../../inttypes.h"
|
#include "../../inttypes.h"
|
||||||
|
|
||||||
#include <capstone/capstone.h>
|
#include <capstone.h>
|
||||||
|
|
||||||
static csh handle;
|
static csh handle;
|
||||||
|
|
||||||
|
@ -192,6 +192,7 @@ static void test_invalids()
|
||||||
}
|
}
|
||||||
|
|
||||||
cs_option(handle, CS_OPT_DETAIL, CS_OPT_ON);
|
cs_option(handle, CS_OPT_DETAIL, CS_OPT_ON);
|
||||||
|
cs_option(handle, CS_OPT_SYNTAX, CS_OPT_SYNTAX_NOREGNAME);
|
||||||
|
|
||||||
for (j = 0; j < invalid->num_invalid_codes; ++j) {
|
for (j = 0; j < invalid->num_invalid_codes; ++j) {
|
||||||
struct invalid_code * invalid_code = NULL;
|
struct invalid_code * invalid_code = NULL;
|
||||||
|
@ -252,24 +253,36 @@ static void test_valids()
|
||||||
CS_ARCH_ARM,
|
CS_ARCH_ARM,
|
||||||
CS_MODE_THUMB,
|
CS_MODE_THUMB,
|
||||||
"Thumb",
|
"Thumb",
|
||||||
2,
|
3,
|
||||||
{{ (unsigned char *)"\x00\xf0\x26\xe8", 4, 0x352,
|
{{ (unsigned char *)"\x00\xf0\x26\xe8", 4, 0x352,
|
||||||
|
"0x352:\tblx\t#0x3a0\n"
|
||||||
|
"\top_count: 1\n"
|
||||||
|
"\t\toperands[0].type: IMM = 0x3a0\n",
|
||||||
|
|
||||||
"0x352:\tblx\t#0x3a0\n"
|
"thumb2 blx with misaligned immediate"
|
||||||
"\top_count: 1\n"
|
}, { (unsigned char *)"\x05\xdd", 2, 0x1f0,
|
||||||
"\t\toperands[0].type: IMM = 0x3a0\n",
|
"0x1f0:\tble\t#0x1fe\n"
|
||||||
|
"\top_count: 1\n"
|
||||||
|
"\t\toperands[0].type: IMM = 0x1fe\n"
|
||||||
|
"\tCode condition: 14\n",
|
||||||
|
|
||||||
"thumb2 blx with misaligned immediate"
|
"thumb b cc with thumb-aligned target"
|
||||||
|
}, { (unsigned char *)"\xbd\xe8\xf0\x8f", 4, 0,
|
||||||
|
"0x0:\tpop.w\t{r4, r5, r6, r7, r8, r9, r10, r11, pc}\n"
|
||||||
|
"\top_count: 9\n"
|
||||||
|
"\t\toperands[0].type: REG = r4\n"
|
||||||
|
"\t\toperands[1].type: REG = r5\n"
|
||||||
|
"\t\toperands[2].type: REG = r6\n"
|
||||||
|
"\t\toperands[3].type: REG = r7\n"
|
||||||
|
"\t\toperands[4].type: REG = r8\n"
|
||||||
|
"\t\toperands[5].type: REG = r9\n"
|
||||||
|
"\t\toperands[6].type: REG = r10\n"
|
||||||
|
"\t\toperands[7].type: REG = r11\n"
|
||||||
|
"\t\toperands[8].type: REG = pc\n",
|
||||||
|
|
||||||
}, { (unsigned char *)"\x05\xdd", 2, 0x1f0,
|
"thumb2 pop that should be valid"
|
||||||
|
},
|
||||||
"0x1f0:\tble\t#0x1fe\n"
|
}
|
||||||
"\top_count: 1\n"
|
|
||||||
"\t\toperands[0].type: IMM = 0x1fe\n"
|
|
||||||
"\tCode condition: 14\n",
|
|
||||||
|
|
||||||
"thumb b cc with thumb-aligned target"
|
|
||||||
}}
|
|
||||||
}};
|
}};
|
||||||
|
|
||||||
struct valid_instructions * valid = NULL;
|
struct valid_instructions * valid = NULL;
|
||||||
|
@ -293,6 +306,7 @@ static void test_valids()
|
||||||
}
|
}
|
||||||
|
|
||||||
cs_option(handle, CS_OPT_DETAIL, CS_OPT_ON);
|
cs_option(handle, CS_OPT_DETAIL, CS_OPT_ON);
|
||||||
|
cs_option(handle, CS_OPT_SYNTAX, CS_OPT_SYNTAX_NOREGNAME);
|
||||||
|
|
||||||
#define _this_printf(...) \
|
#define _this_printf(...) \
|
||||||
{ \
|
{ \
|
||||||
|
@ -349,10 +363,10 @@ static void test_valids()
|
||||||
|
|
||||||
if (memcmp(tmp_buf, valid_code->expected_out, max_len)) {
|
if (memcmp(tmp_buf, valid_code->expected_out, max_len)) {
|
||||||
printf(
|
printf(
|
||||||
" ERROR: '''\n%s''' does not match"
|
" ERROR: '''\n%s''' does not match"
|
||||||
" expected '''\n%s'''\n",
|
" expected '''\n%s'''\n",
|
||||||
tmp_buf, valid_code->expected_out
|
tmp_buf, valid_code->expected_out
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
printf(" SUCCESS: valid\n");
|
printf(" SUCCESS: valid\n");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue