Commit Graph

281 Commits

Author SHA1 Message Date
Travis Finkenauer 8998a3a1d5 ppc: fix endian check (#1029)
* Remove `big_endian` field of `cs_struct`

Added a helper macro `MODE_IS_BIG_ENDIAN()` to check if
`CS_MODE_BIG_ENDIAN` is set.

Refactored `cs_open()` check for valid mode out of arch-specific code
into arch-independent code. Also added a valid mode check to
`cs_option()`.  The checks use a new global array
`arch_disallowed_mode_mask[]`, which is initialized in the arch-specific
`*_enable()` functions.

Fixes bug where endianness could not be set for ppc.

* Fix Mac OS brew for Travis CI
2017-10-20 23:33:24 +08:00
vit9696 a8c7e4a537 Merge #929 with some changes to get things compile (#930) 2017-05-25 16:01:48 +08:00
vit9696 4a757e129f Several changes for size reduction (#929)
* Support CAPSTONE_STATIC with __GNUC__ compilers

* Allow custom export rules

* Make CAPSTONE_SHARED the default visibility option with GNUC (avoids behaviour changes)

* Reduce capstone static build size (mainly for kernel usage)

* Allow basic cs_detail support in diet mode

* Fixed valid_bnd unused function warning

* Do not disable cs_detail generation in CAPSTONE_DIET, use CAPSTONE_NO_DETAIL for that.

* Reverted CAPSTONE_NO_DETAIL at least until capstone supports more flexible configuration

* Added a missing endif

* Disallow custom export rules
2017-05-24 13:07:11 +08:00
Fotis Loukos 0e7a2e7435 Minor fixes for the M68K port. 2017-04-14 17:00:40 +03:00
Fotis Loukos 0850d55211 Added support for the TMS320C64x architecture. 2017-04-14 17:00:40 +03:00
Nguyen Anh Quynh 4f8d7999bf Update cs.c
remove a dead code, suggested by @vit9696 on #867
2017-03-08 20:59:16 +08:00
Nguyen Anh Quynh e2d9ada4ee Update cs.c
remove a dead code, suggested by @vit9696 on #867
2017-03-08 20:57:33 +08:00
Satoshi Tanda 2df9a8eab7 suppress MSVC code analysis (PREfast) warnings
Signed-off-by: Satoshi Tanda <tanda.sat@gmail.com>
2016-09-28 07:33:39 -07:00
Satoshi Tanda f177f92a7c suppress MSVC code analysis (PREfast) warnings
Signed-off-by: Satoshi Tanda <tanda.sat@gmail.com>
2016-09-27 08:08:58 -07:00
Nguyen Anh Quynh dabc9f2990 x86: properly handle SSE/AVX instructions 2016-07-15 20:37:19 +08:00
tandasat f7fe640bd0 port #684 to the next branch 2016-05-16 20:32:36 -07:00
tandasat 2729f3bb33 fix #681 2016-05-16 08:32:58 -07:00
tandasat 59df5507c1 edit documents and comments 2016-05-14 16:04:28 -07:00
tandasat c45f1db564 Merge remote-tracking branch 'upstream/next' into next 2016-05-11 22:52:34 -07:00
tandasat 45e5eab646 port Windows driver support 2016-05-11 21:48:32 -07:00
tandasat 4d36deb1b6 fix #673 2016-05-07 08:44:04 +08:00
tandasat b3d38cfa71 fix #673 2016-05-06 17:03:57 -07:00
tandasat a6609fede8 address warnings with capstone_static_winkernel 2016-05-04 05:54:28 -07:00
Nguyen Anh Quynh 9f56f757fa Merge branch 'windriver' 2016-05-03 23:04:36 +08:00
Nguyen Anh Quynh 9d07c1cd18 arm: only reset IT block for ARM 2016-04-27 14:47:28 +08:00
Nguyen Anh Quynh 0c864409f3 arm: only reset IT block for ARM 2016-04-27 14:47:05 +08:00
Nguyen Anh Quynh c2cb0e7d9c arm: reset IT block before cs_disasm(). this fixes issue #643 2016-04-27 14:43:38 +08:00
Nguyen Anh Quynh 56aa0ac394 arm: reset IT block before cs_disasm(). this fixes issue #643 2016-04-27 14:43:10 +08:00
tandasat 1dd8987c2d enable winkernel default memmory mgmt 2016-04-23 15:51:24 -07:00
Koutheir Attouchi 201a0a1757 "vsnprintf()" is unsupported on Windows CE. The closest match is "_vsnprintf()". 2016-04-12 09:25:37 +02:00
tandasat 760940fdce Addressed compile/link errors when built on VS for drivers 2016-03-31 18:14:43 -07:00
Nguyen Anh Quynh 256090a8c8 add CS_OPT_UNSIGNED option to print immediate in unsigned form. only ARM is supported for now (issue #585) 2016-03-14 13:52:23 +08:00
Pb 0148b043b7 Fix instruction size define 2015-11-10 23:06:20 +01:00
Pb b8741bd545 OS X kernel support (see https://github.com/aquynh/capstone/pull/528) 2015-11-10 23:02:26 +01:00
Pb a21cc8c919 Fix instruction cache size define 2015-11-10 22:43:51 +01:00
Nguyen Anh Quynh 197e457a0b code style 2015-11-10 22:56:53 +08:00
Pb 2769c772ce Correct build settings for xnu kext. Changed calloc name to avoid potential conflicts 2015-11-06 14:44:55 +01:00
Pb 86ad3d6a67 Support of xnu memory allocator 2015-11-05 18:08:25 +01:00
Tyler J. Stachecki d07a21b255 Kill a shadowed declaration of a local variable.
The variable tmp was already defined in the frame.
Redefining it makes some code linters grumpy.

Signed-off-by: Tyler J. Stachecki <tstache1@binghamton.edu>
2015-10-24 18:51:33 +08:00
Tyler J. Stachecki 30d1167a93 Kill a shadowed declaration of a local variable.
The variable tmp was already defined in the frame.
Redefining it makes some code linters grumpy.

Signed-off-by: Tyler J. Stachecki <tstache1@binghamton.edu>
2015-10-23 20:59:20 -04:00
Daniel Collin 2ee675c10a This adds M68K support to Capstone 2015-10-02 20:47:00 +02:00
Nguyen Anh Quynh 8aba4cd913 add error code CS_ERR_X86_MASM 2015-08-09 10:52:18 -07:00
Nguyen Anh Quynh 0b96545f66 new option CS_OPT_MNEMONIC to customize instruction mnemonic 2015-04-26 22:54:41 +08:00
reverser bcf09f440d Add support to embed Capstone into OS X kernel extensions. 2015-04-10 23:28:12 +08:00
reverser 160e198584 Add support to embed Capstone 3.x branch into OS X kernel extensions. 2015-04-09 18:28:19 +01:00
Nguyen Anh Quynh 58eb07355e x86: avoid duplicating registers returned by cs_regs_access(). also add *CX registers to regs_read[], regs_write[] for REP* instructions 2015-04-02 15:18:33 +08:00
Nguyen Anh Quynh efffe787d1 Add new API and start to provide access information for instruction operands
- New API cs_regs_access() that provide registers being read & modified by instruction

- New field cs_x86_op.access provides access info (READ, WRITE) for each operand

- New field cs_x86.eflags provides EFLAGS affected by instruction

- Extend cs_detail.{regs_read, regs_write} from uint8_t to uint16_t type
2015-03-25 15:02:13 +08:00
Nguyen Anh Quynh bfcaba5851 2015 2015-03-04 17:45:23 +08:00
Félix Cloutier 3973d8b11e Silencing Clang warning bys casting values
Warnings were: "Implicit conversion loses integer precision: 'size_t' to 'cs_mode'/'cs_opt_value'"
2015-03-04 11:26:27 +08:00
Félix Cloutier c141af9052 Silencing Clang warning bys casting values
Warnings were: "Implicit conversion loses integer precision: 'size_t' to 'cs_mode'/'cs_opt_value'"
2015-03-02 22:11:55 -05:00
pancake 9c10ace558 Make pkg-config and source consistent with installation 2015-02-24 05:03:04 +01:00
Nguyen Anh Quynh 611b0c5c22 code style 2014-12-15 11:22:46 +08:00
Edward Williamson f1e497502c check malloc return value 2014-12-14 20:45:19 -05:00
Nguyen Anh Quynh ff7bba3d6d x86: print out immediate as positive number for logic arithmetic operations: AND, OR, XOR. only works for x86 Intel syntax so far. issue reported by Pancake 2014-11-03 16:32:06 +08:00
Nguyen Anh Quynh 6c0dd63fe7 fix an overflow bug in fill_insn() 2014-10-30 20:34:22 +08:00
flyingsymbols d91f964d40 * 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
2014-10-23 12:04:23 -04:00
Nguyen Anh Quynh 9090672e97 clean cs_disasm_iter() 2014-10-12 20:24:33 +08:00
Nguyen Anh Quynh 29ce6c3517 cs_disasm_iter: return false when handle is invalid and do not zero out detail pointer when handling skipdata mode. suggested by @hlide 2014-10-12 15:28:34 +08:00
Nguyen Anh Quynh 0a2eca7c6c modify API cs_disasm_iter() and add new API cs_malloc(). also adds sample code test_iter.c 2014-10-11 00:36:16 +08:00
hlide 993f362ad8 New API: cs_disasm_iter 2014-10-05 18:14:40 +02:00
Nguyen Anh Quynh 4d3ccf46fd simplify the way to calculate insn_cache in cs_disasm(). suggested by @hlide 2014-10-03 00:39:56 +08:00
danghvu 2fb7c8e46a Fix a bug with previous patch 2014-10-02 07:38:53 -05:00
Nguyen Anh Quynh f9d8a89c24 correct some comments in cs_disasm() 2014-10-02 12:37:32 +08:00
danghvu 0d1aad1e9f Increase cache size by golden ratio 2014-10-01 23:17:52 -05:00
Nguyen Anh Quynh 27a4a08bb2 fix a double-free bug introduced by the last change in cs_disasm() 2014-10-02 10:31:37 +08:00
Nguyen Anh Quynh ea3c089591 some simple optimizations for speed. this improves performance about 5% 2014-10-02 10:17:55 +08:00
Nguyen Anh Quynh 16f330c37a cs_disasm(): properly resize the cache when count in range [2, INSN_CACHE_SIZE] 2014-10-02 10:09:59 +08:00
Nguyen Anh Quynh 523ca99087 cs_disasm(): make sure cache_size is smaller than INSN_CACHE_SIZE to avoid integer overflow in malloc() 2014-10-01 10:46:37 +08:00
Nguyen Anh Quynh 50eeba2a86 avoid setting instruction cache size to @count when Capstone uses user-customized memory management, which might fail in resource scarce env such as kernel 2014-09-30 13:28:02 +08:00
Nguyen Anh Quynh ac98ca0129 set buffer size for instruction cache in cs_disasm() to @count if @count > 0. this avoids realloc() in cases where @count is pre-determined. thanks Dang Hoang Vu for the idea 2014-09-30 13:17:36 +08:00
Nguyen Anh Quynh 0beb0d494b api: get back the old API cs_disasm() & mark cs_disasm_ex() deprecated. cs_disasm_ex() will be removed in the future 2014-08-27 22:55:29 +08:00
Nguyen Anh Quynh 0c07cc9b06 zero-out instruction details, mnemonic & op_str so cs_insn doesnt have garbage in Diet mode 2014-08-27 22:31:54 +08:00
Nguyen Anh Quynh 4b6b15fcb1 fix more MSVC warnings 2014-08-26 15:57:04 +08:00
Nguyen Anh Quynh 0efef5dd48 solve some conflicts when merging -next into -v3 2014-08-25 17:01:45 +08:00
obs 876b6b6a33 use const when passing cs_insn pointers 2014-08-21 00:57:04 +02:00
Nguyen Anh Quynh 0b690387b3 x86: update core with upstream. this added bunch of new instructions & groups. also updated Python & Java bindings after the core change 2014-08-13 13:01:50 +08:00
Nguyen Anh Quynh 5d8067822b Merge branch 'next' of https://github.com/flyingsymbols/capstone into arm 2014-07-31 15:36:13 +08:00
flyingsymbols 298d413bbc * 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?
2014-07-15 04:33:40 -04:00
Nguyen Anh Quynh 027afdc179 Change the prototype of the callback in SKIPDATA option. Suggested by Ben Nagy.
Original prototype:
  typedef size_t (*cs_skipdata_cb_t)(const uint8_t *code, uint64_t offset, void* user_data);

Now we add @code_size argument to reflect the size of the input buffer @code.
Also, we change the data type of @offset to size_t because this argument indicates the
distance from currently examining bytes to @code, but not the address of the byte.

  typedef size_t (*cs_skipdata_cb_t)(const uint8_t *code, size_t code_size, size_t offset, void* user_data);
2014-07-10 15:46:10 +08:00
Nguyen Anh Quynh 0df7e93a3c Change the prototype of the callback in SKIPDATA option. Suggested by Ben Nagy.
Original prototype:
  typedef size_t (*cs_skipdata_cb_t)(const uint8_t *code, uint64_t offset, void* user_data);

Now we add @code_size argument to reflect the size of the input buffer @code.
Also, we change the data type of @offset to size_t because this argument indicates the
distance from currently examining bytes to @code, but not the address of the byte.

  typedef size_t (*cs_skipdata_cb_t)(const uint8_t *code, size_t code_size, size_t offset, void* user_data);
2014-07-10 15:42:16 +08:00
Nguyen Anh Quynh 650f96ce43 add new API cs_group_name() to return group name in string, given the group id 2014-07-08 08:59:27 +08:00
Nguyen Anh Quynh 25b7f760ce simplify code copying @mnemonic in fill_insn() 2014-07-02 12:24:15 +08:00
Nguyen Anh Quynh d392f6ef89 simplify code copying @mnemonic in fill_insn() 2014-07-02 12:22:39 +08:00
Nguyen Anh Quynh 22ea683583 only verify x86_prefix[0] for x86 arch. bug reported by @pancake 2014-07-02 09:09:08 +08:00
Nguyen Anh Quynh 1d3100ad5b only verify x86_prefix[0] for x86 arch. bug reported by @pancake 2014-07-02 09:08:10 +08:00
Nguyen Anh Quynh 5a7f409dec set @insn to NULL on error in cs_disasm_ex() 2014-06-19 11:15:54 +08:00
Nguyen Anh Quynh dab17fd0b1 set @insn to NULL on error in cs_disasm_ex() 2014-06-19 11:15:18 +08:00
Nguyen Anh Quynh 6c182aedcf fix a memleaking issue in cs_disasm_ex() where memory was not freed when input code is illegit 2014-06-18 21:50:25 +08:00
Nguyen Anh Quynh cae09bf543 replace offset_of with offsetof from stddef.h 2014-06-17 14:58:39 +08:00
Nguyen Anh Quynh 64091f77e0 resize total memory allocated for @insns to just the right size for cs_disasm_ex() 2014-06-16 18:37:11 +08:00
Nguyen Anh Quynh 495295ecd4 MCInst_Init() is arch-independent 2014-06-16 15:54:32 +08:00
Nguyen Anh Quynh db3c00c0ff consider tab as delimiter char in asm bufffer in fill_insn() 2014-06-13 11:16:53 +07:00
Nguyen Anh Quynh 69582d71ae initialize cs_insn.detail by properly zero-out right members for each arch 2014-06-09 17:50:01 +07:00
Nguyen Anh Quynh c88d9929ae cs_disasm_ex(): properly calculate insn_cache when reallocating total variable 2014-06-09 01:59:00 +08:00
Nguyen Anh Quynh ee5839420d cs_disasm_ex(): avoid multiple memcpy() by allocating memory for total, then directly work on that instead of using static array insn_cache[] 2014-06-09 00:13:31 +07:00
Nguyen Anh Quynh 5329a6ffd4 directly update cs_insn from MCInst interface to avoid multiple memcpy() 2014-06-08 23:35:52 +07:00
Nguyen Anh Quynh 7566a2d9dd copy mnemonic in the same loop of searching for mnemonic/opstring delimiter 2014-06-08 22:09:31 +08:00
Nguyen Anh Quynh 07e84a2094 do not need to verify handle->insn_id in fill_insn() 2014-06-08 19:27:22 +08:00
Nguyen Anh Quynh 6ddd715fac we have to consider \t in input buffer of fill_insn() 2014-06-08 19:11:38 +08:00
Nguyen Anh Quynh f8ea346310 properly copy buffer to op_str 2014-06-08 18:57:52 +08:00
Nguyen Anh Quynh 177dd9b223 simplify fill_insn(): do not check for \t in asm buffer 2014-06-08 00:17:10 +08:00
Nguyen Anh Quynh 22a5a761d8 x86: simplify byteReader_t 2014-06-07 23:41:20 +08:00
Nguyen Anh Quynh df1acfd106 nullify cs_insn.detail when detail is OFF 2014-06-07 15:39:32 +07:00
Nguyen Anh Quynh 30c065998b optimize memset() of MCInst_Init() 2014-06-07 13:30:59 +08:00
Nguyen Anh Quynh 99e69e1868 remove a redundant call to memset() in cs_disasm_ex() 2014-06-06 16:49:23 +08:00