aquynh/capstone — pull request #158 by flyingsymbols (2014-07-15 08:43:44+00:00)
Title: Fixed a few bugs in ARM disassembly (blx immediate needed alignment when transitioning to arm, thumb pop can't have sp in it)

* added a test file to suite for testing invalid and valid instruction sequences

* fixed and added a test for a thumb-2 invalid sequence that was incorrectly allowed before these changes (pop.w with sp argument included)
* fixed and added a test for a blx from thumb to ARM that had its immediate argument incorrect (misaligned)

* eliminated some warnings by explicitly casting so I could turn on
treat warnings as errors locally

General notes:
* probably worth turning on treat all warnings as errors in the msvc project files, had a subtle bug that resulted from a missing declaration causing differences in dll and static compilation modes

( code was working incorrectly in dll form because of missing declaration in arch/ARM/ARMMapping.h for new function ARM_blx_to_arm_mode. Something about the linking was confusing ld when making the dll, and the resulting offsets were wonky (e.g. the added ble test would show up as #0x1fc instead of #0x1fe like it should have )

* the invalid pop was being treated as a soft fail which then gets coerced
to a success because it is != MCDisassembler_Fail in Thumb_getInstruction
what are the semantics of a soft fail? Maybe we should be able to set up
whether or not we want a soft fail to be a real fail in the csh struct?

Here is expected output from the test_arm_regression.c file:

Should be invalid
-----------------
Thumb bde81eff: invalid thumb2 pop because sp used and because both pc and
lr are present at the same time
SUCCESS: invalid

Should be valid
---------------
Thumb 00f026e8 @ 0x0352: thumb2 blx with misaligned immediate
0x352: blx #0x3a0
op_count: 1
operands[0].type: IMM = 0x3a0
SUCCESS: valid
Thumb 05dd @ 0x01f0: thumb b cc with thumb-aligned target
0x1f0: ble #0x1fe
op_count: 1
operands[0].type: IMM = 0x1fe
Code condition: 14
SUCCESS: valid