Commit Graph

1492 Commits

Author SHA1 Message Date
Nguyen Anh Quynh
85cac968ef X86: X86_insn_reg_att uses a wrong mapping array of Intel syntax 2019-02-21 15:33:14 +08:00
Catena cyber
e5fa5f8735 Avoids leak in wasm details (#1372)
* Avoids leak in wasm details

Extending cs_detail in capstone.h

* Safety checks before allocating memory for brtable in WASM

* Revert "Avoids leak in wasm details"

This reverts commit 03f822b34a03f23554aaffb2951b62c62645e5e5.

* Refactoring brtable for WASM

* Fix undefined shift in WASM get_varuint64
2019-02-20 23:38:11 +08:00
david942j
b227acc29c New architecture: BPF (#1388)
* Basic changes of new arch - BPF

* Define some constants

* defined some API methods

* Able to print MISC instruction

* Follow Linux coding style

* Ability to show ALU insn names

* decode return

* Add suite/MC/BPF

* decode jump

* decode store

* decode load

* print instruction done

* try to implement BPF_reg_access

* Implements explicit accessed registers and fix some tiny bugs

* Fix unhandled ja case

* Added BPF_REG_OFF do fix wrong display in jump class

* Great I'm able to decode cBPF with eyes

* Fix: misunderstood the 16-byte instruction's imm

* Add ldxdw

* Add extended-all.cs

* Implements cstest/bpf_getdetail.c

* Fix memory leak

* Add BPF to fuzz

* Implemented regs_read and regs_write

* Fix missing write-access on ALU's dst

* Updated cstool/, test_basic.c, test_detail.c, and test_iter.c

* Updated docs

* Fix type of cs_bpf#operands

* Implements python bindings

* Fix some bugs found by self code review

* Remove dummy tests

* remove typeof

* Address comments

* Fix MSVC's warnings and add test_bpf.py to bindings/python/Makefile

* Fix: call is not offset
2019-02-18 17:39:51 +08:00
Nguyen Anh Quynh
fd433d897a x86: 8bit Imm operand has size = 1. this fixes issue #1389 2019-02-18 17:31:03 +08:00
Catena cyber
254c58b47a Fixes more undefined left shift of negative values (#1384) 2019-02-16 10:33:21 +08:00
Catena cyber
b43db80f9a Avoids overflow in getRegisterName for TMS320C64x (#1375)
* Avoids overflow in getRegisterName for TMS320C64x

* Revert "Avoids overflow in getRegisterName for TMS320C64x"

This reverts commit 18acee60cd.

* Checks register in DecodeMemOperandSc
2019-02-16 10:32:15 +08:00
Catena cyber
2426038f31 Multiply signed integer instead of left shift (#1382) 2019-02-15 22:35:04 +08:00
Nguyen Anh Quynh
b57ddf8bc5 merge master to next branch 2019-02-15 10:51:04 +08:00
Catena cyber
06f042c515 Fix undefined shift in WASM disassembler (#1380) 2019-02-15 08:18:03 +08:00
Nguyen Anh Quynh
f38aec3d72 arm64: fix CS_OPT_UNSIGNED option on memory operand offset 2019-02-13 22:12:00 +08:00
Nguyen Anh Quynh
b8ea017fcd x86: print imm with proper size for CS_OPT_UNSIGNED - ATT syntax 2019-02-13 22:01:39 +08:00
Nguyen Anh Quynh
b22426d8ac x86: print imm with proper size for CS_OPT_UNSIGNED 2019-02-13 21:48:38 +08:00
Nguyen Anh Quynh
7228b4a3a6 x86: ATT syntax print unsigned imm with 0x prefix 2019-02-13 01:26:56 +08:00
Nguyen Anh Quynh
988ad09d77 x86: ATT syntax print unsigned imm with 0x prefix 2019-02-13 01:26:04 +08:00
Nguyen Anh Quynh
8a7ebc3bd6 x86: do not print prefix 0 for memory operand for ATT syntax 2019-02-13 01:23:50 +08:00
Nguyen Anh Quynh
974b3b3cf1 x86: do not print prefix 0 for memory operand for ATT syntax 2019-02-13 01:04:57 +08:00
Nguyen Anh Quynh
432e507ce2 arm: lowercase for APSR_nzcv 2019-02-13 00:43:42 +08:00
Nguyen Anh Quynh
bc36e5fdfe arm: lowercase for APSR_nzcv 2019-02-13 00:43:22 +08:00
Nguyen Anh Quynh
bdb711390c arm64: support CS_OPT_UNSIGNED 2019-02-12 23:28:06 +08:00
Nguyen Anh Quynh
4ee7d45078 arm64: support CS_OPT_UNSIGNED 2019-02-12 23:27:29 +08:00
Nguyen Anh Quynh
ad38598a89 x86: support CS_OPT_UNSIGNED for ATT syntax 2019-02-12 23:15:39 +08:00
Nguyen Anh Quynh
00dc2e2e58 x86: support CS_OPT_UNSIGNED for ATT syntax 2019-02-12 23:14:30 +08:00
Nguyen Anh Quynh
6df9ab10ae TMS320C64x: remove unused variable 2019-02-10 18:04:56 +08:00
Nguyen Anh Quynh
cf05010186 TMS320C64x: remove unused variable 2019-02-10 18:03:30 +08:00
Catena cyber
2d2f3ae922 TMS320C64x instruction names (#1373)
* TMS320C64x instruction names

* Fix undefined shift in TMS320C64xDisassembler.c

* Adding spaces

* remove TMS320C64X_INS_ENDING naming
2019-02-07 22:37:46 +08:00
Catena cyber
bd110ef655 TMS320C64x instruction names (#1373)
* TMS320C64x instruction names

* Fix undefined shift in TMS320C64xDisassembler.c

* Adding spaces

* remove TMS320C64X_INS_ENDING naming
2019-02-07 22:36:07 +08:00
david942j
a512e2668f Fixed m68k has wrong type of read_imm_64 (#1369) 2019-02-06 00:07:54 +08:00
david942j
3ee4d90af0 Fixed TMS320C64x failed to print instructions (#1367) 2019-02-06 00:07:46 +08:00
david942j
18b33cbf53 Fixed m68k has wrong type of read_imm_64 (#1369) 2019-02-06 00:05:21 +08:00
david942j
a560a3a448 Fixed TMS320C64x failed to print instructions (#1367) 2019-02-05 23:34:33 +08:00
Spike
54cbc34349 fix wasm shift bug (#1362)
* fix bug in shift
2019-02-03 14:24:05 +08:00
Nguyen Anh Quynh
f9bd8785eb wasm: return CS_ERR_OPTION on unsupported option of cs_option() 2019-02-02 23:25:34 +08:00
Spike
55f242d498 Add webassembly arch (#1359)
* add wasm arch

* fix bug

* delete todo & add wasm into readme
2019-02-01 23:03:47 +08:00
Nguyen Anh Quynh
be24095038 arm: update writeback for STR_POST_REG (issue #1296) 2019-01-28 16:35:18 +08:00
Nguyen Anh Quynh
147eab3ff9 arm: update writeback for STR_POST_REG (issue #1296) 2019-01-28 16:34:44 +08:00
Nguyen Anh Quynh
dbab8d6494 arm: fix issue #746 for arm mode. reported by @HarDToBelieve 2019-01-27 22:37:43 +08:00
Nguyen Anh Quynh
66dd1cd0e3 arm: fix issue #746 for arm mode. reported by @HarDToBelieve 2019-01-27 22:37:13 +08:00
radare
f03310afe8 Add default case in MOS65XX instruction length helper (#1333) 2019-01-22 15:37:35 +08:00
Nguyen Anh Quynh
938b072655 MOS65XX: fix missing prototype for ‘MOS65XX_global_init' 2019-01-22 15:35:48 +08:00
Nguyen Anh Quynh
9afe61c8c0 MOS65XX: fix missing prototype for ‘MOS65XX_global_init' 2019-01-22 15:23:22 +08:00
JNA
5294fa9fb6 fix cmovcc eflags (#1349) 2019-01-22 14:13:05 +08:00
JNA
ad06af9643 fix cmovcc eflags (#1349) 2019-01-22 14:12:37 +08:00
JNA
43c8983096 fix cmovcc eflags (#1349) 2019-01-22 13:11:34 +07:00
Marius Melzer
7450461a5f Fix missing-prototypes warnings (#1348) 2019-01-22 09:01:13 +08:00
Nguyen Anh Quynh
a24eba1e0f X86: turn some print functions to static. see #1342 2019-01-22 09:01:13 +08:00
Marius Melzer
7d20c40060 Fix missing-prototypes warnings (#1348) 2019-01-22 08:43:02 +08:00
Nguyen Anh Quynh
48b08869c0 X86: turn some print functions to static. see #1342 2019-01-22 08:43:02 +08:00
Marius Melzer
c6612a3059 Fix missing-prototypes warnings (#1348) 2019-01-22 07:39:44 +07:00
Nguyen Anh Quynh
dddabb1bde X86: turn some print functions to static. see #1342 2019-01-21 20:21:18 +08:00
Erik Hemming
1200ad4486 Fix a couple of corner-cases with rarely used m68k instructions. (#1344)
* Bump the "cs_insn.bytes[]" size to 24 (from 16) to support M680x0 instructions with full EA (maximum 11 words)
Added a test for this in test_m68k.s

* Bump the "cs_detail.regs_read[]" size to 16 (from 12) to support M680x0 instructions with full REG_BITS (Dn+An = 16)

* m68k: use immediate mode syntax (#$0) for movem/fmovem instructions with empty register list

* update bindings to match changes to cs_insn and cs_detail
2019-01-21 17:42:28 +08:00
Erik Hemming
44ce36d1ad Fix a couple of corner-cases with rarely used m68k instructions. (#1344)
* Bump the "cs_insn.bytes[]" size to 24 (from 16) to support M680x0 instructions with full EA (maximum 11 words)
Added a test for this in test_m68k.s

* Bump the "cs_detail.regs_read[]" size to 16 (from 12) to support M680x0 instructions with full REG_BITS (Dn+An = 16)

* m68k: use immediate mode syntax (#$0) for movem/fmovem instructions with empty register list

* update bindings to match changes to cs_insn and cs_detail
2019-01-21 17:42:01 +08:00
Erik Hemming
652d5754e4 Fix a couple of corner-cases with rarely used m68k instructions. (#1344)
* Bump the "cs_insn.bytes[]" size to 24 (from 16) to support M680x0 instructions with full EA (maximum 11 words)
Added a test for this in test_m68k.s

* Bump the "cs_detail.regs_read[]" size to 16 (from 12) to support M680x0 instructions with full REG_BITS (Dn+An = 16)

* m68k: use immediate mode syntax (#$0) for movem/fmovem instructions with empty register list

* update bindings to match changes to cs_insn and cs_detail
2019-01-21 16:55:05 +08:00
Nguyen Anh Quynh
8a6c520e8f Merge branch 'master' into next 2019-01-04 17:24:16 +08:00
Nguyen Anh Quynh
3d8bba0a58 Merge branch 'master' into v4.1 2019-01-04 17:23:50 +08:00
Wolfgang Schwotzer
59d7387d37 M680X: Fix clang-analyzer issue #1329. (#1334) 2019-01-03 07:48:55 +08:00
radare
7de621bbf2 Add default case in MOS65XX instruction length helper (#1333) 2019-01-03 07:48:18 +08:00
Nguyen Anh Quynh
d4ce009086 Merge branch 'master' into next 2019-01-02 10:01:28 +08:00
Nguyen Anh Quynh
2e78e0c1b9 Merge branch 'master' into v4.1 2019-01-02 10:01:03 +08:00
Disconnect3d
6e29dfa2c0 Fix arm thb instruction shift value (#1330)
* Fixes #1317 - arm thb operand.shift.value

For a more detailed description, see issue #1317.

Release 4.0.0 introduced a new field for ARM operands:
`operand.mem.lshift`. This field was supposed to be a bug fix for #246.
The #246 issue has been fixed in the meantime and the proper shift value
was stored in `operand.shift.value`.

The 4.0.0 changes created a regression in which `operand.shift.value`
was not set for a `tbh [r0, r1, lsl #1]` instruction on ARM and the
value was set in a `operand.mem.lshift` field instead.

As the regression broke some of users codebase (e.g. in
[manticore](https://github.com/trailofbits/manticore/pull/1312) project), we fix it by setting
`operand.shift.value` back again.

As a result, the shift value is set in two fields: `operand.shift.value`
and `operand.mem.lshift`. As the `operand.shift` also stores a `.type`
field, we might want to deprecate `operand.mem.lshift` in the future.

* Add changelog stub
2019-01-02 09:51:22 +08:00
Nguyen Anh Quynh
23ff78bf05 Merge branch 'master' into next 2018-12-27 09:41:29 +08:00
Nguyen Anh Quynh
807dd33c0b Merge branch 'master' into v4.1 2018-12-27 09:41:01 +08:00
Nguyen Anh Quynh
454160598a arm: remove group ARM_REG_PC for thumb BX (#1323, 1126) 2018-12-27 09:40:19 +08:00
Nguyen Anh Quynh
44b2c29ab7 Merge branch 'master' into next 2018-12-20 02:58:23 +08:00
Nguyen Anh Quynh
09822dd129 x86: fix endbr32 & endbr64 in #1129 2018-12-20 02:54:44 +08:00
Nguyen Anh Quynh
a15bb088df Merge branch 'master' into next 2018-12-19 07:49:32 +07:00
Ammar
4e1b8c49f9 x86: correct access mode for cmp instruction (#1309)
cmp instruction does not modify its operands. Currently, cmp
variants that accept a memory operand have CS_AC_WRITE access mode
set. This commit removes CS_AC_WRITE mode from cmp variants that
have it.
2018-12-18 23:22:30 +08:00
Nguyen Anh Quynh
53b3e3f7c5 MOS65XX: lowercase for MOS65XX_AM_ACC 2018-12-18 22:46:23 +08:00
Nguyen Anh Quynh
ca984c3eb4 Merge branch 'master' into next 2018-12-18 22:44:57 +08:00
Nguyen Anh Quynh
8d4ba8d335 M680X: lowercase for registers & FCB instruction 2018-12-18 22:44:12 +08:00
Nguyen Anh Quynh
ce27eea732 TMS320C64x: lowercase for instruction mnemonics, registers & group names 2018-12-18 22:40:31 +08:00
Nguyen Anh Quynh
da6777f701 M680X: lowercase for instruction mnemonics & group names 2018-12-18 22:33:00 +08:00
Nguyen Anh Quynh
e4c8ea3e75 MOS65XX: lowercase for instruction mnemonic 2018-12-18 22:28:33 +08:00
mephi42
7ac73141c8 Update SystemZ to LLVM commit 5ad902a6 (#1306) 2018-12-16 21:48:51 +08:00
Nguyen Anh Quynh
7aa0fce4d8 mos65xx: fix warnings reported by CI 2018-12-16 20:47:52 +08:00
Nguyen Anh Quynh
96d1b894fa mos65xx: solve conflicts 2018-12-16 20:09:28 +08:00
Nguyen Anh Quynh
81baa7dccf fix conflicts 2018-12-08 09:52:08 +07:00
Sebastian Macke
82cd4c0747 Add support for the MOS65XX family such as the MOS 6502.
Signed-off-by: Sebastian Macke <sebastian@macke.de>
2018-12-06 22:53:33 +01:00
keenk
c5140afc7b Fix a few registry access mode mappings (#1295) 2018-11-26 14:05:29 +07:00
Nguyen Anh Quynh
c63838c40c PPC: print 16bit imm as unsigned 2018-11-25 21:12:05 +07:00
Dimitri Bohlender
27a202f858 Typo in register's name (#1282)
Fixed Minor typo, i.e. the friendly string representation of X86_REG_ST0 was "st(0"
2018-11-02 07:43:54 +08:00
Nguyen Anh Quynh
a7faa5b383 x86: fix instruction suffix of MOV to segment register for ATT syntax. issue #1240 2018-10-26 14:08:18 +08:00
Nguyen Anh Quynh
d1927ee0a4 x86: fix operand access of FSTP (#1255) 2018-10-25 23:22:48 +08:00
Nguyen Anh Quynh
c3dfecb946 x86: fix operand access of SETE & SETNE (#1262) 2018-10-10 14:07:07 +08:00
Nguyen Anh Quynh
6360b82a3f x86: fix operand access of fistp & fstp, in #1255 2018-10-02 12:22:13 +02:00
Nguyen Anh Quynh
0492f93c3d x86: fix operand access of CMP in #1253 2018-10-02 12:18:29 +02:00
keenk
9d140beb47 Add files via upload (#1256)
Correct register access flag for the movdqa instruction
2018-10-02 17:45:11 +08:00
Tim Brooks
5cac05846e Correct use of strncpy function (#1247)
The last argument should be the max size of the destination, not the
source buffer. A null byte is added to the end of the destination buffer
since strncpy only adds one if it does not truncate the source.
This fixes the -Wstringop-overflow warning on GCC.
2018-09-15 13:47:52 +08:00
Riccardo Schirone
5212dc571a arch/X86: fix strncpy usage (#1243)
The `n` parameter should be the size of the destination buffer, not the
source one.
2018-09-04 08:51:02 +07:00
Riccardo Schirone
702ac842e1 WIP: arch/TMS320C64x: fix underflow (#1220)
* arch/TMS320C64x: fix underflow

(patch coming from radare2)

* arch/TMS320C64x: fix spaces between if/for/while and parenthesis

* arch/TMS320C64x: switch back to ==
2018-07-30 21:48:26 +08:00
Riccardo Schirone
71b32ce5e7 WIP: arch/TMS320C64x: fix underflow (#1220)
* arch/TMS320C64x: fix underflow

(patch coming from radare2)

* arch/TMS320C64x: fix spaces between if/for/while and parenthesis

* arch/TMS320C64x: switch back to ==
2018-07-30 15:17:43 +08:00
Nguyen Anh Quynh
757310df51 evm: fix EVMMappingInsn.inc 2018-07-29 02:38:38 +08:00
Nguyen Anh Quynh
e0bce87ef1 evm: fix EVMMappingInsn.inc 2018-07-29 02:38:10 +08:00
Riccardo Schirone
c316ef189d arch/M68k: do not return reg_name if beyond limits (#1219)
* arch/M68k: do not return reg_name if beyond limits

(patch coming from radare2)

* arch: checks index when returning reg names
2018-07-24 16:25:47 +08:00
Nguyen Anh Quynh
af286d4914 sparc: fix issue #1221 on double printing imm operand 2018-07-24 14:53:00 +08:00
Riccardo Schirone
b512f388cf arch/M68k: do not return reg_name if beyond limits (#1219)
* arch/M68k: do not return reg_name if beyond limits

(patch coming from radare2)

* arch: checks index when returning reg names
2018-07-24 13:40:02 +08:00
Francesco Tamagni
f6e0fa42f2 Fix testAndBranch sign extend to 64 bit (#1213) 2018-07-20 14:50:41 +08:00
Francesco Tamagni
baa10210fc Fix testAndBranch sign extend to 64 bit (#1213) 2018-07-20 14:50:01 +08:00
Nguyen Anh Quynh
76c1c3c4e9 merge next to master 2018-07-20 12:36:50 +08:00
Nguyen Anh Quynh
9783ea8585 mips: compilable for MSVC 2013 2018-07-18 23:47:07 +08:00
Nguyen Anh Quynh
d64cfab1d8 mips: compilable for MSVC 2013 2018-07-18 23:46:36 +08:00
clslgrnc
91601ac1fd Init cs_detail (#1205)
* Update init of cs_detail for AArch64

as @aquynh requested in #1125

* Update init of cs_detail for ARM

as @aquynh requested in #1125

* Update init of cs_detail for EVM

as @aquynh requested in #1125

* Update init of cs_detail for M680X

as @aquynh requested in #1125

* Update init of cs_detail for M68K

as @aquynh requested in #1125

* Update init of cs_detail for Mips

as @aquynh requested in #1125

* Update init of cs_detail for PowerPC

as @aquynh requested in #1125

* Update init of cs_detail for Sparc

as @aquynh requested in #1125

* Update init of cs_detail for SystemZ

as @aquynh requested in #1125

* Update init of cs_detail for TMS320C64x

as @aquynh requested in #1125

* Update init of cs_detail for XCore

as @aquynh requested in #1125

* Comment on init of cs_detail

* wrap long lines
2018-07-12 11:01:34 +07:00
Nguyen Anh Quynh
8171df5568 x86: fix imm operand of RETF. see #1204 2018-07-11 23:20:00 +08:00
Martin
ec81ee223b readDisplacement fix (#1200) 2018-07-11 23:19:45 +08:00
Martin
bd89989f5d readDisplacement fix (#1200) 2018-07-11 22:18:38 +07:00
Nguyen Anh Quynh
7e93de0714 x86: fix imm operand of RETF. see #1204 2018-07-11 23:12:18 +08:00
Nguyen Anh Quynh
940cbdcfea Merge branch 'next' of github.com:aquynh/capstone into next 2018-07-05 11:34:32 +08:00
Nguyen Anh Quynh
68d4e771eb evm: default case for switch 2018-07-05 11:33:39 +08:00
Nguyen Anh Quynh
5c173ca0cd evm: cleanup group_name_maps[] 2018-07-05 11:32:42 +08:00
Nguyen Anh Quynh
ec57c1b4ec evm: fix bug introduced in some recent fixes 2018-07-05 11:32:19 +08:00
Nguyen Anh Quynh
76a86e5354 evm: cleanup 2018-07-05 11:32:05 +08:00
Nguyen Anh Quynh
6c4ece4472 evm: simplify EVM_get_insn_id() 2018-07-05 11:31:53 +08:00
Nguyen Anh Quynh
3a3cff2e91 evm: correct comments on evm_insn_find() 2018-07-05 11:31:39 +08:00
Nguyen Anh Quynh
dfb75a21a0 evm: fix header guard in EVMModule.c 2018-07-05 01:16:24 +08:00
Nguyen Anh Quynh
97f34c87c7 x86: X86_immediate_size() returns uint8 2018-07-04 23:02:22 +08:00
Nguyen Anh Quynh
795ffa39e7 coding style 2018-07-04 22:54:14 +08:00
Stephen Eckels
e9861a1192 Merges encoding to next (#1194)
* merge encoding branch into next branch

* added python bindings and updated test to support encoding

* fix python import

* fix py binding fields

* fix disp size printing

* fixed py binding, again

* Update CREDITS.TXT

* fixed formatting and a cast

* Changed param from int to uint8_t, fixed warnings
2018-07-04 22:47:55 +08:00
Nguyen Anh Quynh
1036de09bf Revert "Merges encoding branch (#1187)"
This reverts commit a1ed8fc6f6.
2018-07-03 11:55:29 +08:00
Catena cyber
e14b4c4b11 Initializes to 0 X86 immediateOffset (#1192) 2018-06-29 17:00:51 +08:00
Catena cyber
b1f2f1a394 Initializes to 0 X86 immediateOffset (#1192) 2018-06-29 16:59:30 +08:00
Stephen Eckels
699611072b Merges encoding branch (#1187)
* Added encoding field to instructions, as per encoding branch

The encoding branch appears to have added some useful fields
accessible from the public API, including the size and offsets
of displacements and immediates in instructions.  I needed access
to these fields, but the encoding branch is months behind the
active branches, so I took the minimum code from the old encoding
branch and put them into a more recent version of master.

It does seem that the most recent version does not have an offset
for the modRM byte in the InternalInstruction struct, so I did
not keep this field when bringing it to the more recent version.

I also added some of the changes made by user jellever, who added
support for accessing these new fields from the python bindings.

(cherry picked from commit d358c4b987cc77af90e24da15937e021c42f682f)

* Fixed bug with python bindings from adding encoding field

I had forgotten an import that resulted in failure when trying
to obtain instruction details.

(cherry picked from commit 44a15e378900efb624e7cdb952d32558ba0de684)

* promoted displacement to 64 bits

* Added modrm offset

* formatting from review fixed

* updated 32 bit C tests

* Added 64 and 16 bit C tests

* Updated python tests

* fixed formatting and size in py bindings

* Delete Solution.VC.db-shm

* Delete Solution.VC.db-wal

* Update test_x86.c

* fixed formatting and conditional prints

* fixed formatting
2018-06-28 21:37:34 +08:00
Catena cyber
950476606b Initialize X86 necessaryPrefixLocation (#1179)
* Initialize X86 necessaryPrefixLocation

* necessaryPrefixLocation initialization to -1

* Revert "necessaryPrefixLocation initialization to -1"

This reverts commit 04fc4b6702.
2018-06-25 19:46:58 +08:00
Catena cyber
27a169e305 Initialize X86 necessaryPrefixLocation (#1179)
* Initialize X86 necessaryPrefixLocation

* necessaryPrefixLocation initialization to -1

* Revert "necessaryPrefixLocation initialization to -1"

This reverts commit 04fc4b6702.
2018-06-25 19:46:04 +08:00
Travis Finkenauer
292116bd0d Declare global arch arrays with contents (next branch) (#1186)
* Declare global arch arrays with contents (#1171)

This eliminates the need for archs_enable() and eliminates the racey
initialization.

This makes the architecture-specific init and option functions
non-static so that they may be called from a different file.

Cherry-picked 853a2870

* Add cs_arch_disallowed_mode_mask global

Cherry-pick 94bce437:
mips: CS_MODE_MIPS32R6 implies CS_MODE_32

Cherry-pick 8998a3a1:
ppc: fix endian check (#1029)
Fixes bug where endianness could not be set for ppc.

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
`cs_arch_disallowed_mode_mask[]`.

* Make global arrays static

Make all_arch uint32_t to guarantee a certain number of bits (with
adequate room for growth).
2018-06-24 21:05:04 +08:00
Nguyen Anh Quynh
7566f79879 cleanup 2018-06-22 01:03:26 +08:00
Travis Finkenauer
ce597d5296 Declare global arch arrays with contents (#1171)
This eliminates the need for archs_enable() and eliminates the racey
initialization.

This makes the architecture-specific init, option, and destroy functions
non-static so that they may be called from a different file.
2018-06-21 14:52:35 +08:00
Catena cyber
9ecaeea75a SystemZ MIN_INT right print (#1182) 2018-06-16 23:09:25 +01:00
Catena cyber
204be7951d EVM fuzz fixes (#1181)
Sets id to instruction
Completes missing set and enforces number of instructions
2018-06-16 22:35:02 +01:00
Catena cyber
63ff398094 EVM initialize regs_read and regs_write (#1180) 2018-06-15 23:15:12 +01:00
vit9696
c2514aab00 Add Availability.h include to fix macOS SDK instrinsics 2018-06-15 22:14:48 +08:00
vit9696
f52aa1f39c Add Availability.h include to fix macOS SDK instrinsics (#1175) 2018-06-14 22:12:26 +01:00
vit9696
a31ffb343f Refactor confusing if for xacquire/xrelease (#1173)
Sync with https://github.com/llvm-mirror/llvm/blob/7cdce81/lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp#L362
2018-06-13 23:04:20 +01:00
vit9696
f8eae0ac15 Refactor confusing if for xacquire/xrelease (#1173)
Sync with https://github.com/llvm-mirror/llvm/blob/7cdce81/lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp#L362
2018-06-13 22:14:53 +08:00
Catena cyber
aad3aca3e7 Use printint functions from SStream (#1165)
in perticular, not to overflow -INT_MIN
2018-06-06 06:31:53 +08:00
Catena cyber
a33567db49 Fix ARM operand subtracted field (#1163) 2018-06-06 06:17:25 +08:00
Catena cyber
9217582b9f Fixes shift for ARM memory operand (#1162)
Shift is for same operand as index register
2018-06-06 06:09:53 +08:00
Catena cyber
62f1d9fe14 Fix ARM operand subtracted field (#1163) 2018-06-05 22:20:02 +08:00
Catena cyber
d15e310112 Fix integer overflow on systemz (#1164)
using fixed function from SStream.c
2018-06-05 14:03:55 +08:00
Catena cyber
8f7c495e05 Fix undefined shifts (#1158) 2018-06-03 22:29:58 +08:00
Catena cyber
17076b66d2 Fix undefined negative value shift (#1161)
Use multiply instead
2018-06-03 22:19:07 +08:00
Catena cyber
fbb90bcb35 Fix undefined shifts (#1158)
Use multiply instead
Found by oss-fuzz
2018-06-02 16:52:52 +08:00
Catena cyber
65c0be823c Fix undefined shifts (#1156)
* Fix undefined shifts

Found by oss-fuzz
uint8_t gets promoted to integer
and integers shift cannot overflow on sign bit

* Fix undefined shifts

shifting 31 bits the sign bit
2018-06-02 16:51:40 +08:00
Catena cyber
bf97c62001 Undefined shifts (#1154)
* Fix undefined shifts

uint8 gets promoted to signed integer

in ARM, MIPS, Sparc
in AArch64, PPC and Xcore

* fix undefined shift in powerpc

* Fix undefined shift in Mips

use mulitply instead
2018-06-02 16:49:36 +08:00
Catena cyber
6c796d996b We can read more registers from M68K (#1151) 2018-06-02 01:08:54 +08:00
Nguyen Anh Quynh
aeb4128cab x86: support new instructions endbr64 & endbr32 2018-06-01 22:57:53 +08:00
Nguyen Anh Quynh
e1494cf1f4 cleanup 2018-06-01 22:05:50 +08:00
clslgrnc
c3527b72e1 Improve init of cs_detail for x86 (#1125) 2018-06-01 22:03:55 +08:00
Catena cyber
f1f5fca1b5 M68K increment index after having written register (#1147) 2018-06-01 20:53:01 +08:00
Catena cyber
d937c94cac Fix buffer overflow in M68K (#1146) 2018-06-01 20:52:37 +08:00
Catena cyber
7c668dac9d Do not shift signed values in Mips disassembling (#1148)
* Do not shift signed values in Mips disassembling

* Do not shift signed values in Mips disassembling

Multiply instead
2018-06-01 20:51:46 +08:00
Nguyen Anh Quynh
538b7bfbd1 arm: BX & BLX write to PC. see #1126 2018-05-28 20:30:15 +08:00
Daniel Collin
d3080c4d0c Fixed incorrect size of code check (#1130)
Also added a sanity check that the code is at least 2 bytes before trying to disassemble.

Also removed some unused code while at it
2018-05-10 15:06:46 +08:00
clslgrnc
10adccccd3 Prevent buffer overflow in cs_regs_access on ud0 (#1122)
By setting instr->Opcode, ud0 is correctly found in insns, and insn->detail is correctly initialized by X86_get_insn_id.
2018-05-07 09:42:01 +08:00
Nguyen Anh Quynh
39480af183 indentation 2018-04-03 22:48:28 +08:00
Nguyen Anh Quynh
e5101ab48a indentation 2018-04-03 22:36:26 +08:00
Nguyen Anh Quynh
1da2ae94de EVM: add missing files 2018-03-31 17:32:22 +08:00
Alberto Garcia Illera
3c8e828b14 prefix cs_ to global variables to avoid link problems (#1108)
* prefix cs_ to global variables to avoid link problems

* force Capstone to be build using MT

* fix identation
2018-03-29 22:17:37 +08:00
Google AutoFuzz Team
c72e6d1a36 Fixing #1062
Adding a fix to commit 5b55115c42
2018-03-22 18:18:22 -07:00
Google AutoFuzz Team
4c8b187aee Fixing #1061
Updating the fix provided in commit 5b55115c42
2018-03-22 17:30:00 -07:00
Alberto Garcia Illera
d0525ca346 prefix cs_ to global variables to avoid link problems (#1102) 2018-03-19 22:23:09 +08:00
l0stb1t
04b461a76d Fixed #1060 #1061 #1062 (#1079) 2018-03-12 22:23:48 +07:00
Nguyen Anh Quynh
8cc43a72a3 m680x: compile on MSVC 2010 2018-02-14 14:57:34 +08:00
Jason Shirk
40040d47e2 Fix MSVC build (#1080) 2018-01-23 11:12:41 +08:00
Nguyen Anh Quynh
1b166ebdf4 m68k: update bindings after #1068 2018-01-06 20:16:58 +08:00
Kalmalyzer
9944bfde76 M68K: Branch targets are a separate addressing mode; PC relative displacements printed as target addresses (#1068)
* Branch targets are a separate addressing mode

Branch targets are relative displacements that identify code locations. These are neither .w nor .l nor immediates. This change removes the immediate #s before branch target addresses in disassembly, and represents the actual branch instructions more accurately in the cs_m68k_op datastructure.

M68K Python bindings have also been updated.

* m68k_inst.pc handles better; print target for PC relative offsets

Previous changes to branch operations relied on m68k_inst.pc pointing to (start of instruction + 2). This was not the case - it pointed to the end of the current instruction. This change makes it so that m68k_inst.pc points to (start of instruction), which is simple to work with.

It also changes printing of PC relative offsets to print the absolute target address, which is consistent with how most 68000 assemblers & disassemblers behave.
2018-01-06 20:13:41 +08:00
Nguyen Anh Quynh
cbdea7ce19 sparc: fix relative branch target for Sparc64 2017-12-27 14:24:18 +08:00
bezita
1790ccdb1e Fix EFLAGS for the stosb/stosd/stosq/stosw instructions (#1065) 2017-12-22 00:05:47 +08:00
Nguyen Anh Quynh
6c1c82bdd7 sparc: fix #1061 2017-12-15 10:12:54 +08:00
Nguyen Anh Quynh
030b52458a systemz: fix #1062 2017-12-15 10:11:40 +08:00
Nguyen Anh Quynh
d75eedd8bc arm: fix #1060 2017-12-15 10:10:04 +08:00
Jean-David Gadina
0efc9b9c5a Added an explicit cast to silence a compiler warning casting a parameter to an enum type (). (#1052) 2017-11-21 10:19:29 +03:00
Nguyen Anh Quynh
811d8ceee6 x86: fix att syntax when imm operand is 0 (#1046) 2017-11-17 10:27:35 +03:00
Nguyen Anh Quynh
a45e860114 x86: fix att syntax when imm operand is 0 (#1046) 2017-11-17 10:26:26 +03:00
Nguyen Anh Quynh
4c96c85a2b x86: fix immediate operand for AND instruction in ATT mode (issue #1047) 2017-11-11 03:00:05 +08:00
Richard Henderson
5423b215bf Constify backend data (#1040)
* Constify string literals

Use -Wwrite-strings to force string literals to be of
type "const char[]", then fix up all warning fallout.

* Constify common infrastructure

Step one in allowing backend data to be readonly.
Minimal changes to backends for now; just set all pointers
in common structs that aren't modified to const.

* Constify AArch64 backend

Section size changes within libcapstone.so are

-.rodata               602587
-.data.rel.ro          228416
-.data                1003746
+.rodata               769051
+.data.rel.ro          241120
+.data                 824578

* Constify ARM backend

Section size changes within libcapstone.so are

-.rodata               769051
-.data.rel.ro          241120
-.data                 824578
+.rodata               959835
+.data.rel.ro          245120
+.data                 629506

* Constify Mips backend

Section size changes within libcapstone.so are

-.rodata               959835
-.data.rel.ro          245120
-.data                 629506
+.rodata              1069851
+.data.rel.ro          256416
+.data                 508194

* Constify PowerPC backend

Section size changes within libcapstone.so are

-.rodata              1069851
-.data.rel.ro          256416
-.data                 508194
+.rodata              1142715
+.data.rel.ro          272224
+.data                 419490

* Constify Sparc backend

Section size changes within libcapstone.so are

-.rodata              1142715
-.data.rel.ro          272224
-.data                 419490
+.rodata              1175227
+.data.rel.ro          277536
+.data                 381666

* Constify SystemZ backend

Section size changes within libcapstone.so are

-.rodata              1175227
-.data.rel.ro          277536
-.data                 381666
+.rodata              1221883
+.data.rel.ro          278016
+.data                 334498

* Constify X86 backend

Section size changes within libcapstone.so are

-.rodata              1221883
-.data.rel.ro          278016
-.data                 334498
+.rodata              1533531
+.data.rel.ro          281184
+.data                  19714

* Constify XCore backend

Section size changes within libcapstone.so are

-.rodata              1533531
-.data.rel.ro          281184
-.data                  19714
+.rodata              1553026
+.data.rel.ro          281280
+.data                     40
2017-10-22 08:45:40 +08:00
Wolfgang Schwotzer
e8d1f1d4d2 M680X: Target ready for pull request (#1034)
* Added new M680X target. Supports M6800/1/2/3/9, HD6301

* M680X: Reformat for coding guide lines. Set alphabetical order in HACK.TXT

* M680X: Prepare for python binding. Move cs_m680x, m680x_insn to m680x_info. Chec
> k cpu type, no default.

* M680X: Add python bindings. Added python tests.

* M680X: Added cpu types to usage message.

* cstool: Avoid segfault for invalid <arch+mode>.

* Make test_m680x.c/test_m680x.py output comparable (diff params: -bu). Keep xprint.py untouched.

* M680X: Update CMake/make for m680x support. Update .gitignore.

* M680X: Reduce compiler warnings.

* M680X: Reduce compiler warnings.

* M680X: Reduce compiler warnings.

* M680X: Make test_m680x.c/test_m680x.py output comparable (diff params: -bu).

* M680X: Add ocaml bindings and tests.

* M680X: Add java bindings and tests.

* M680X: Added tests for all indexed addressing modes. C/Python/Ocaml

* M680X: Naming, use page1 for PAGE1 instructions (without prefix).

* M680X: Naming, use page1 for PAGE1 instructions (without prefix).

* M680X: Used M680X_FIRST_OP_IN_MNEM in tests C/python/java/ocaml.

* M680X: Added access property to cs_m680x_op.

* M680X: Added operand size.

* M680X: Remove compiler warnings.

* M680X: Added READ/WRITE access property per operator.

* M680X: Make reg_inherent_hdlr independent of CPU type.

* M680X: Add HD6309 support + bug fixes

* M680X: Remove errors and warning.

* M680X: Add Bcc/LBcc to group BRAREL (relative branch).

* M680X: Add group JUMP to BVS/BVC/LBVS/LBVC. Remove BRAREL from BRN/LBRN.

* M680X: Remove LBRN from group BRAREL.

* M680X: Refactored cpu_type initialization for better readability.

* M680X: Add two operands for insn having two reg. in mnemonic. e.g. ABX.

* M680X: Remove typo in cstool.c

* M680X: Some format improvements in changed_regs.

* M680X: Remove insn id string list from tests (C/python/java/ocaml).

* M680X: SEXW, set access of reg. D to WRITE.

* M680X: Sort changed_regs in increasing m680x_insn order.

* M680X: Add M68HC11 support + Reduced from two to one INDEXED operand.

* M680X: cstool, also write '(in mnemonic)' for second reg. operand.

* M680X: Add BRN/LBRN to group JUMP and BRAREL.

* M680X: For Bcc/LBcc/BRSET/BRCLR set reg. CC to read access.

* M680X: Correctly print negative immediate values with option CS_OPT_UNSIGNED.

* M680X: Rename some instruction handlers.

* M680X: Add M68HC05 support.

* M680X: Dont print prefix '<' for direct addr. mode.

* M680X: Add M68HC08 support + resorted tables + bug fixes.

* M680X: Add Freescale HCS08 support.

* M680X: Changed group names, avoid spaces.

* M680X: Refactoring, rename addessing mode handlers.

* M680X: indexed addr. mode, changed pre/post inc-/decrement representation.

* M680X: Rename some M6809/HD6309 specific functions.

* M680X: Add CPU12 (68HC12/HCS12) support.

* M680X: Correctly display illegal instruction as FCB .

* M680X: bugfix: BRA/BRN/BSR/LBRA/LBRN/LBSR does not read CC reg.

* M680X: bugfix: Correctly check for sufficient code size for M6809 indexed addressing.

* M680X: Better support for changing insn id within handler for addessing mode.

* M680X: Remove warnings.

* M680X: In set_changed_regs_read_write_counts use own access_mode.

* M680X: Split cpu specific tables into separate *.inc files.

* M680X: Remove warnings.

* M680X: Removed address_mode. Addressing mode is available in operand.type

* M680X: Bugfix: BSET/BCLR/BRSET/BRCLR correct read/modify CC reg.

* M680X: Remove register TMP1. It is first visible in CPU12X.

* M680X: Performance improvement + bug fixes.

* M680X: Performance improvement, make cpu_tables const static.

* M680X: Simplify operand decoding by using two handlers.

* M680X: Replace M680X_OP_INDEX by M680X_OP_CONSTANT + bugfix in java/python/ocaml bindings.

* M680X: Format with astyle.

* M680X: Update documentation.

* M680X: Corrected author for m680x specific files.

* M680X: Make max. number of architectures single source.
2017-10-21 21:44:36 +08:00
Travis Finkenauer
de99147c73 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
Daniel Collin
3b43ddb92c [M68K] Fixed invalid base reg (#1028)
This is one of those “how did this ever work?” changes. Problem was that as m68k_op was aliased with the imm value so when changing that to something big it would trash the values in the mem struct which would make things go really bad.

Now m68k_op_mem has been moved out of the union so this will not happen again. Also fixed instruction printing bug related to this (just happend to “work” due to the old union layout)
2017-10-13 09:06:01 +08:00
Nguyen Anh Quynh
ee33de3f29 Mips64: fix the last cherry-pick on selecting getInstruction() 2017-10-09 09:26:41 +08:00
Travis Finkenauer
69f9fabefa Mips: Fix selection of disasm handler (#1022) 2017-10-09 08:52:53 +08:00
Travis Finkenauer
2f4bc38eec Fix selection of mips disasm handler (#1022)
* Fix selection of mips disasm handler

handle->disasm was incorrectly set to Mips64_getInstruction if CS_MODE_MIPS32R6
was set but CS_MODE_32 was not set. Now, CS_MODE_32 is set automatically if
CS_MODE_MIPS32R6 is set.

* Align with current style
2017-10-09 08:44:01 +08:00
Richard Henderson
edb0cc57ac Fix pp field in readPrefix for VEX3 and EVEX (#1015) (#1016) 2017-09-19 08:46:59 +08:00
Richard Henderson
72cd9ee99e Fix pp field in readPrefix for VEX3 and EVEX (#1015) (#1016) 2017-09-19 07:46:00 +07:00
Matt Suiche
0441af5ce7 Resolve some casting issues with Visual Studio. 2017-09-05 22:20:57 +07:00
Matt Suiche
4e7f49228b - Resolve some casting issues with Visual Studio. (#1007) 2017-09-05 22:15:13 +07:00
Nguyen Anh Quynh
e87caa789a x86: fix an warning on unintialized vars 2017-08-16 09:01:58 +08:00
Andrew Calvano
166feea41c Bug fix for incorrect operand type in certain load/store instructions on AArch64. (#952) 2017-08-03 23:01:47 +07:00
Andrew Calvano
0c5ee0e4aa Bug fix for incorrect operand type in certain load/store instructions on AArch64. (#952) 2017-08-03 23:00:53 +08:00
Alfredo Beaumont
5fc444c073 Add name to relative branch group in supported architectures. (#982) 2017-08-01 16:49:43 +08:00
Fotis Loukos
104832daed Fixed bug in memory operand decoding. (#981)
Fixed bug #979. Decoding a memory operand with a register offset from
the B file would return an incorrect register.
2017-07-31 20:56:29 +08:00
Nguyen Anh Quynh
374a8525d8 Merge branch 'master' of https://github.com/aquynh/capstone 2017-07-31 01:06:24 +07:00
Nguyen Anh Quynh
f72bb9cfe2 arm: UADD8 updates flags. fix #980 2017-07-31 01:06:17 +07:00
Nguyen Anh Quynh
6cd9313c70 arm: UADD8 updates flags. fix #980 2017-07-31 01:05:28 +07:00
Alfredo Beaumont
f82395b959 Relative branch group (#964)
* Add a new group for relative branching instructions

* x86: Add relative branch group to appropiate instructions

* Rename RELATIVE_BRANCH to BRANCH_RELATIVE

* aarch64: Add relative branch group to appropiate instructions

* arm: Add relative branch group to appropiate instructions

* m68k: Add relative branch group to appropiate instructions

* mips: Add relative branch group to appropiate instructions
2017-07-30 19:05:03 +08:00
semihalf-oleksy-michalina
de6666c531 arm64: handling of system registers added in ARMv8.1/2 (#960)
* arm64: handling of system registers added in ARMv8.2

This commit adds handling of system registers added in ARMv8.2.
Those registers are accessed by mrs and msr instructions.
Changes based on https://static.docs.arm.com/ddi0487/b/DDI0487B_a_armv8_arm.pdf, chapters D7.2-5.

List of added registers:
id_mmfr4_el1
id_aa64mmfr2_el1
sctlr_el12
cpacr_el12
ttbr0_el12
ttbr1_el12
ttbr1_el2
tcr_el12
spsr_el12
elr_el12
afsr0_el12
afsr1_el12
esr_el12
far_el12
mair_el12
amair_el12
vbar_el12
cntkctl_el12
cnthv_ctl_el2
cnthv_cval_el2
cnthv_tval_el2
cntp_tval_el02
cntp_cval_el02
cntv_ctl_el02
ntv_cval_el02
cntv_tval_el02
lorid_el1
lorc_el1
lorea_el1
lorn_el1
lorsa_el1
contextidr_el12

sign-of: Michalina Oleksy (https://github.com/layika)

* arm64: handling of system registers added in ARMv8.1/2

v8.1:
PAN (https://static.docs.arm.com/ddi0487/b/DDI0487B_a_armv8_arm.pdf, page 358)
PAN (as pstate field)
contextdir_el2

v8.2:
UAO (https://static.docs.arm.com/ddi0487/b/DDI0487B_a_armv8_arm.pdf, page 403)
UAO (as pstate field)

* arm64: handling of system registers for statistical profiling

Added handling of system registers for statistical profiling extension based on https://static.docs.arm.com/ddi0586/a/DDI0586A_Statistical_Profiling_Extension.pdf

* Update AArch64BaseInfo.h

* arm64: An attempt to fix indentation
2017-07-29 18:27:32 +08:00
Nguyen Anh Quynh
490db4e5dd x86: MOV AL, [mem] has 2 operands. fix #959 2017-07-08 13:58:36 +07:00
Snarpix
a2948cca80 Fixes DATA REX_W CALL_PC_REL IMM32 issue (decoded as IMM16) (#883) 2017-06-28 07:07:26 +08:00
Francesco Tamagni
b8342f9b90 Add CS_MODE_MIPS2 to opt-in for COP3 instructions (#939)
* Add CS_MODE_MIPS2 to opt-in for COP3 instructions

* Fix indentation

* Get rid of `+`
2017-06-27 20:56:54 +08:00
Nguyen Anh Quynh
3bc180e3eb x86: wrong number of operands. fix #950 2017-06-23 00:54:09 +08:00
radare
7a4567612c Honor CS_OPT_UNSIGNED on x86 and add cstool -u (#945) 2017-06-16 02:13:28 +08:00
echotyh
572d864b2f Next (#918)
* Add FPUFLAGS information.

* Change the structure insn_op: from uint64_t eflags to union{ uint64_t eflags, uint64_t fpuflags; }.

* Adjust the  modified structure insn_op.

* Add missing flags.

* Change flags information acorrding to xed files and instruction manual.

* Rename fpuflags to fpu_flags.

* Updating flags information accoring to manual and xed files.

* Changing the name eflags to flags.

* Printing the FPU_FLAGS information when it belongs to group X86_GRP_FPU.

* Defining new flags.

* Updating flags information according to manual and xed files.

* Adding X86_GRP_FPU to all the instructions which have modified fpu_flags.

* Solving the conflict problem when do git commit.

* Rectify the annotation within the structure insn_op.

* Supplement fpu flags information for floating-point instructions which missed fpu flags before.

* Print fpu group information when an instructure belongs to X86_GRP_FPU.

* Add two new groups ARM64_GRP_BASE(base instructions) and ARM64_GRP_FPSIMD(SIMD&FP instructions).

* Revert "Add two new groups ARM64_GRP_BASE(base instructions) and ARM64_GRP_FPSIMD(SIMD&FP instructions)."

This reverts commit 8ab50e80a3.

* X86 clean up.

* Clean up arch/X86/X86MappingInsn.inc.

* Double check.

* Delete files.

* Clean up x86.

* Clean up reduce file

* Fix btr

* fix x86
2017-05-29 22:43:47 +08:00